32 #include "bedrockprovisioning.h" |
32 #include "bedrockprovisioning.h" |
33 #include "secureuicontroller.h" |
33 #include "secureuicontroller.h" |
34 #include "LoadController.h" |
34 #include "LoadController.h" |
35 #include "ContentAgent.h" |
35 #include "ContentAgent.h" |
36 #include "lowmemoryhandler.h" |
36 #include "lowmemoryhandler.h" |
|
37 #include "webnetworkaccessmanager.h" |
37 #include <QWebFrame> |
38 #include <QWebFrame> |
38 #include <QWebHistory> |
39 #include <QWebHistory> |
39 #include <QGraphicsWebView> |
40 #include <QGraphicsWebView> |
40 #include <QFile> |
41 #include <QFile> |
41 #include <QDir> |
42 #include <QDir> |
43 #include <QCoreApplication> |
44 #include <QCoreApplication> |
44 #include <QWebSecurityOrigin> |
45 #include <QWebSecurityOrigin> |
45 #include <QWebDatabase> |
46 #include <QWebDatabase> |
46 #include <QWebSettings> |
47 #include <QWebSettings> |
47 #include <QtCore/QSettings> |
48 #include <QtCore/QSettings> |
|
49 #include <QUrl> |
|
50 #include <QDesktopServices> |
|
51 |
48 using namespace WRT; |
52 using namespace WRT; |
49 |
53 |
50 #ifdef ORBIT_UI |
54 #ifdef ORBIT_UI |
51 #include <shareui.h> |
55 #include <shareui.h> |
52 #include <qcontactemailaddress.h> |
56 #include <qcontactemailaddress.h> |
415 connect( page->networkAccessManager(), SIGNAL(showMessageBox(WRT::MessageBoxProxy*)), this, SIGNAL(showMessageBox(WRT::MessageBoxProxy*))); |
418 connect( page->networkAccessManager(), SIGNAL(showMessageBox(WRT::MessageBoxProxy*)), this, SIGNAL(showMessageBox(WRT::MessageBoxProxy*))); |
416 // Connect network reply errors |
419 // Connect network reply errors |
417 connect( page->networkAccessManager(), SIGNAL( networkErrorHappened(const QString &) ), this, SIGNAL( networkErrorHappened(const QString &) ) ); |
420 connect( page->networkAccessManager(), SIGNAL( networkErrorHappened(const QString &) ), this, SIGNAL( networkErrorHappened(const QString &) ) ); |
418 connect( page->networkAccessManager(), SIGNAL( networkErrorHappened(const QString &) ), this, SLOT( processNetworkErrorHappened(const QString &) ) ); |
421 connect( page->networkAccessManager(), SIGNAL( networkErrorHappened(const QString &) ), this, SLOT( processNetworkErrorHappened(const QString &) ) ); |
419 connect( page->networkAccessManager(), SIGNAL( networkErrorUrl(const QUrl &) ), this, SLOT( processNetworkErrorUrl(const QUrl &) ) ); |
422 connect( page->networkAccessManager(), SIGNAL( networkErrorUrl(const QUrl &) ), this, SLOT( processNetworkErrorUrl(const QUrl &) ) ); |
420 |
423 |
|
424 #ifdef QT_GEOLOCATION |
|
425 // Connect geolocation permission |
|
426 connect(page, SIGNAL(requestGeolocationPermission(QWebFrame*, QWebPage::PermissionDomain, QString)), |
|
427 this, SLOT(handleRequestGeolocationPermission(QWebFrame*, QWebPage::PermissionDomain, QString))); |
|
428 #endif // QT_GEOLOCATION |
|
429 |
421 connect(currentPage(), SIGNAL(pageScrollPositionZero()), this, SIGNAL(pageScrollPositionZero()) ); |
430 connect(currentPage(), SIGNAL(pageScrollPositionZero()), this, SIGNAL(pageScrollPositionZero()) ); |
422 connect(page, SIGNAL(scrollRequested(int, int, const QRect & )), this, SIGNAL(pageScrollRequested(int, int, const QRect & )) ); |
431 connect(page, SIGNAL(scrollRequested(int, int, const QRect & )), this, SIGNAL(pageScrollRequested(int, int, const QRect & )) ); |
423 |
432 |
424 Q_ASSERT ( d->m_currentPage >= 0 ); |
433 Q_ASSERT ( d->m_currentPage >= 0 ); |
425 |
434 |
477 emit (loadFinishedForBackgroundWindow(true,page)); |
486 emit (loadFinishedForBackgroundWindow(true,page)); |
478 } |
487 } |
479 } |
488 } |
480 } |
489 } |
481 |
490 |
|
491 #ifdef QT_GEOLOCATION |
|
492 void WebPageController::handleRequestGeolocationPermission(QWebFrame* frame, QWebPage::PermissionDomain permissionDomain, QString domain) |
|
493 { |
|
494 emit requestGeolocationPermission(dynamic_cast<QObject*>(frame), dynamic_cast<QObject*>(currentPage()), domain); |
|
495 |
|
496 qDebug() << "WebPageController::handleRequestGeolocationPermission"; |
|
497 } |
|
498 |
|
499 void WebPageController::setGeolocationPermission(QObject* _frame, QObject* _page, bool permissionGranted, bool saveSetting) |
|
500 { |
|
501 QWebFrame* frame = dynamic_cast<QWebFrame*>(_frame); |
|
502 WRT::WrtBrowserContainer* page = dynamic_cast<WRT::WrtBrowserContainer*>(_page); |
|
503 |
|
504 page->setGeolocationPermission(frame, QWebPage::GeolocationPermissionDomain, permissionGranted, saveSetting); |
|
505 } |
|
506 #endif // QT_GEOLOCATION |
|
507 |
482 void WebPageController::updateHistory() |
508 void WebPageController::updateHistory() |
483 { |
509 { |
484 HistoryManager::getSingleton()->addHistory(currentDocUrl(), currentDocTitle()); |
510 HistoryManager::getSingleton()->addHistory(currentDocUrl(), currentDocTitle()); |
485 emit(loadFinished(true)); |
511 emit(loadFinished(true)); |
486 } |
512 } |
836 #endif //// ORBIT_UI |
866 #endif //// ORBIT_UI |
837 } |
867 } |
838 #else |
868 #else |
839 void WebPageController::feedbackMail(const QString &mailAddress, const QString &mailBody) |
869 void WebPageController::feedbackMail(const QString &mailAddress, const QString &mailBody) |
840 { |
870 { |
841 return; // Not supported |
871 //format is: mailto:test@somewhere.com?body=TestBody |
|
872 |
|
873 QString emailString = "mailto:" + mailAddress + "?body=" + mailBody; |
|
874 QUrl url(emailString); |
|
875 QDesktopServices::openUrl(url); |
|
876 |
|
877 return; |
842 } |
878 } |
843 #endif |
879 #endif |
844 /*! |
880 /*! |
845 Load an item into the current page from a given /a historyIndex |
881 Load an item into the current page from a given /a historyIndex |
846 */ |
882 */ |
946 switch(state) { |
982 switch(state) { |
947 case SecureUIController::secureLoadFinished: |
983 case SecureUIController::secureLoadFinished: |
948 case SecureUIController::untrustedLoadFinished: |
984 case SecureUIController::untrustedLoadFinished: |
949 case SecureUIController::mixedLoadFinished: |
985 case SecureUIController::mixedLoadFinished: |
950 case SecureUIController::untrustedMixedLoadFinished: |
986 case SecureUIController::untrustedMixedLoadFinished: |
951 emit showSecureIcon(); |
987 emit showSecureIcon(true); |
952 break; |
988 break; |
953 case SecureUIController::unsecureLoadFinished: |
989 case SecureUIController::unsecureLoadFinished: |
954 emit hideSecureIcon(); |
990 emit showSecureIcon(false); |
955 break; |
991 break; |
956 default: |
992 default: |
957 break; |
993 break; |
958 } |
994 } |
959 } |
995 } |
998 return suggestList; |
1034 return suggestList; |
999 } |
1035 } |
1000 |
1036 |
1001 void WebPageController::loadLocalFile() |
1037 void WebPageController::loadLocalFile() |
1002 { |
1038 { |
1003 QString chromeBaseDir = BEDROCK_PROVISIONING::BedrockProvisioning::createBedrockProvisioning()->valueAsString("LocalPagesBaseDirectory"); |
1039 QString localPagesBaseDir = BEDROCK_PROVISIONING::BedrockProvisioning::createBedrockProvisioning()->valueAsString("LocalPagesBaseDirectory"); |
1004 QString startPage = BEDROCK_PROVISIONING::BedrockProvisioning::createBedrockProvisioning()->valueAsString("StartPage"); |
1040 QString startPage = BEDROCK_PROVISIONING::BedrockProvisioning::createBedrockProvisioning()->valueAsString("StartPage"); |
1005 QString startPagePath = chromeBaseDir + startPage; |
1041 QString startPagePath = localPagesBaseDir + startPage; |
1006 |
1042 |
1007 currentLoad(startPagePath); |
1043 currentLoad(startPagePath); |
1008 } |
1044 } |
1009 |
1045 |
1010 void WebPageController::loadInitialUrlFromOtherApp(QString url) |
1046 void WebPageController::loadInitialUrlFromOtherApp(QString url) |
1112 |
1148 |
1113 unsigned int pageCount = d->m_allPages.count(); |
1149 unsigned int pageCount = d->m_allPages.count(); |
1114 |
1150 |
1115 // Get index of current page |
1151 // Get index of current page |
1116 WRT::WrtBrowserContainer* theCurrentPage = currentPage(); |
1152 WRT::WrtBrowserContainer* theCurrentPage = currentPage(); |
|
1153 |
1117 int currentIndex = d->m_allPages.indexOf(theCurrentPage); |
1154 int currentIndex = d->m_allPages.indexOf(theCurrentPage); |
1118 |
1155 |
1119 for (int tIndex = 0; tIndex < pageCount; tIndex++) |
1156 for (int tIndex = 0; tIndex < pageCount; tIndex++) |
1120 { |
1157 { |
1121 // Don't save blank windows |
1158 // Don't save blank windows |
1498 |
1542 |
1499 if(diskCacheDir.isEmpty()) |
1543 if(diskCacheDir.isEmpty()) |
1500 return; |
1544 return; |
1501 |
1545 |
1502 //QDir dir1(d->m_historyDir +"/cwrtCache/http"); |
1546 //QDir dir1(d->m_historyDir +"/cwrtCache/http"); |
1503 QDir dir1(diskCacheDir + "/http"); |
1547 QDirIterator it(diskCacheDir, QDir::Files | QDir::NoDotAndDotDot, QDirIterator::Subdirectories); |
1504 |
1548 while (it.hasNext()) { |
1505 QFileInfoList fileList1(dir1.entryInfoList(QDir::Files)); |
1549 QFile::remove(it.next()); |
1506 |
1550 } |
1507 foreach (const QFileInfo fileInfo, fileList1) { |
|
1508 const QString filePath(fileInfo.absoluteFilePath()); |
|
1509 QFile file(filePath); |
|
1510 if(file.open(QIODevice::ReadOnly)) { |
|
1511 file.remove(); |
|
1512 file.close(); |
|
1513 } |
|
1514 } |
|
1515 |
|
1516 //QDir dir2(d->m_historyDir +"/cwrtCache/https"); |
|
1517 QDir dir2(diskCacheDir +"/https"); |
|
1518 |
|
1519 QFileInfoList fileList2(dir2.entryInfoList(QDir::Files)); |
|
1520 |
|
1521 foreach (const QFileInfo fileInfo, fileList2) { |
|
1522 const QString filePath(fileInfo.absoluteFilePath()); |
|
1523 QFile file(filePath); |
|
1524 if(file.open(QIODevice::ReadOnly)) { |
|
1525 file.remove(); |
|
1526 file.close(); |
|
1527 } |
|
1528 } |
|
1529 |
|
1530 //QDir dir3(d->m_historyDir +"/brCache/prepared"); |
|
1531 QDir dir3(diskCacheDir +"/cwrtCache/prepared"); |
|
1532 |
|
1533 QFileInfoList fileList3(dir3.entryInfoList(QDir::Files)); |
|
1534 |
|
1535 foreach (const QFileInfo fileInfo, fileList3) { |
|
1536 const QString filePath(fileInfo.absoluteFilePath()); |
|
1537 QFile file(filePath); |
|
1538 if(file.open(QIODevice::ReadOnly)) { |
|
1539 file.remove(); |
|
1540 file.close(); |
|
1541 } |
|
1542 } |
|
1543 |
|
1544 |
|
1545 } |
1551 } |
1546 |
1552 |
1547 void WebPageController::urlChanged(const QUrl& url) |
1553 void WebPageController::urlChanged(const QUrl& url) |
1548 { |
1554 { |
1549 //private slot |
1555 //private slot |
1572 } |
1578 } |
1573 } |
1579 } |
1574 return NULL; |
1580 return NULL; |
1575 } |
1581 } |
1576 |
1582 |
1577 void WebPageController::checkAndUpdatePageThumbnails() |
1583 void WebPageController::checkAndUpdatePageThumbnails(QSize &s) |
1578 { |
1584 { |
1579 // WebContentWidget* view = qobject_cast<WebContentWidget*> (webView()); |
1585 // WebContentWidget* view = qobject_cast<WebContentWidget*> (webView()); |
1580 QGraphicsWebView *view = webView(); |
1586 // QGraphicsWebView *view = webView(); |
1581 WRT::WrtBrowserContainer* savedPage = qobject_cast<WRT::WrtBrowserContainer*> (view->page()); |
1587 // WRT::WrtBrowserContainer* savedPage = qobject_cast<WRT::WrtBrowserContainer*> (view->page()); |
1582 if(!savedPage) return; |
1588 // if(!savedPage) return; |
1583 QSize currSize = view->size().toSize(); |
1589 // QSize currSize = view->size().toSize(); |
1584 |
1590 |
1585 bool needRestore = false; |
1591 bool needRestore = false; |
1586 |
1592 |
1587 for (int i = 0; i < allPages()->count(); i++) { |
1593 for (int i = 0; i < allPages()->count(); i++) { |
1588 WRT::WrtBrowserContainer* page = allPages()->at(i); |
1594 WRT::WrtBrowserContainer* page = allPages()->at(i); |
1589 QWebHistoryItem item = page->history()->currentItem(); |
1595 QWebHistoryItem item = page->history()->currentItem(); |
1590 WebPageData data = item.userData().value<WebPageData>(); |
1596 WebPageData data = item.userData().value<WebPageData>(); |
1591 |
1597 |
1592 // If not still a blank window, check whether we need to update the img |
1598 // If not still a blank window, check whether we need to update the img |
1593 if (!page->emptyWindow() ){ |
1599 if (!page->emptyWindow() ){ |
|
1600 /* |
1594 QImage img = data.m_thumbnail; |
1601 QImage img = data.m_thumbnail; |
1595 bool isSameMode = ( (img.size().width() > img.size().height()) == (currSize.width() > currSize.height()) ); |
1602 bool isSameMode = ( (img.size().width() > img.size().height()) == (currSize.width() > currSize.height()) ); |
1596 if (img.isNull() || !isSameMode) { |
1603 if (img.isNull() || !isSameMode) { |
1597 needRestore = true; |
1604 needRestore = true; |
1598 view->setPage(page); |
1605 view->setPage(page); |
1603 } |
1610 } |
1604 if (page->needUpdateThumbnail()) { |
1611 if (page->needUpdateThumbnail()) { |
1605 page->savePageDataToHistoryItem(page->mainFrame(), &item); |
1612 page->savePageDataToHistoryItem(page->mainFrame(), &item); |
1606 page->setUpdateThumbnail(false); |
1613 page->setUpdateThumbnail(false); |
1607 } |
1614 } |
|
1615 */ |
1608 } |
1616 } |
1609 } |
1617 } |
1610 |
1618 |
1611 // restore |
1619 // restore |
1612 if (needRestore) { |
1620 /* if (needRestore) { |
1613 view->setPage(savedPage); |
1621 view->setPage(savedPage); |
1614 savedPage->setWebWidget(view); |
1622 savedPage->setWebWidget(view); |
1615 } |
1623 }*/ |
1616 } |
1624 } |
1617 |
1625 |
1618 void WebPageController::updatePageThumbnails() |
1626 void WebPageController::updatePageThumbnails() |
1619 { |
1627 { |
1620 // update current page's thumbnail forcely since the scrolling position may change |
1628 // update current page's thumbnail forcely since the scrolling position may change |
1621 WRT::WrtBrowserContainer *page = currentPage(); |
1629 WRT::WrtBrowserContainer *page = currentPage(); |
1622 if(page) { |
|
1623 QWebHistoryItem item = page->history()->currentItem(); |
1630 QWebHistoryItem item = page->history()->currentItem(); |
1624 page->savePageDataToHistoryItem(page->mainFrame(), &item); |
1631 // page->savePageDataToHistoryItem(page->mainFrame(), &item); |
1625 page->setUpdateThumbnail(false); |
1632 page->setUpdateThumbnail(false); |
1626 checkAndUpdatePageThumbnails(); |
1633 // checkAndUpdatePageThumbnails(); |
1627 } |
|
1628 } |
1634 } |
1629 |
1635 |
1630 void WebPageController::resizeAndUpdatePageThumbnails(QSize& s) |
1636 void WebPageController::resizeAndUpdatePageThumbnails(QSize& s) |
1631 { |
1637 { |
1632 webView()->resize(s); // resize the view |
1638 // webView()->resize(s); // resize the view |
1633 |
1639 |
1634 checkAndUpdatePageThumbnails(); |
1640 checkAndUpdatePageThumbnails(s); |
1635 } |
1641 } |
1636 |
1642 |
1637 void WebPageController::urlTextChanged(QString str ) { |
1643 void WebPageController::urlTextChanged(QString str ) { |
1638 |
1644 |
1639 //qDebug() << __func__ << "Current Page" << currentPage() << "Url " << str; |
1645 //qDebug() << __func__ << "Current Page" << currentPage() << "Url " << str; |
1699 } |
1705 } |
1700 |
1706 |
1701 QString WebPageController::promptReserved() { |
1707 QString WebPageController::promptReserved() { |
1702 return m_promptReserved; |
1708 return m_promptReserved; |
1703 } |
1709 } |
|
1710 |
|
1711 void WebPageController::copy() { |
|
1712 WRT::WrtBrowserContainer * activePage = currentPage(); |
|
1713 if(activePage) |
|
1714 activePage->triggerAction(QWebPage::Copy); |
|
1715 } |
|
1716 |
|
1717 void WebPageController::cut() { |
|
1718 WRT::WrtBrowserContainer * activePage = currentPage(); |
|
1719 if(activePage) |
|
1720 activePage->triggerAction(QWebPage::Cut); |
|
1721 } |
|
1722 |
|
1723 void WebPageController::paste() { |
|
1724 WRT::WrtBrowserContainer * activePage = currentPage(); |
|
1725 if(activePage) |
|
1726 activePage->triggerAction(QWebPage::Paste); |
|
1727 } |
|
1728 |
|
1729 bool WebPageController::hasTextOnClipBoard() { |
|
1730 const QClipboard *clipboard = QApplication::clipboard(); |
|
1731 if (clipboard) { |
|
1732 const QMimeData *mimeData = clipboard->mimeData(); |
|
1733 if (mimeData) |
|
1734 return mimeData->hasText(); |
|
1735 } |
|
1736 return false; |
|
1737 } |
1704 |
1738 |
1705 /*! |
1739 /*! |
1706 \fn void WebPageController::pageCreated(WrtPage* newPage); |
1740 \fn void WebPageController::pageCreated(WrtPage* newPage); |
1707 emitted when a page is created |
1741 emitted when a page is created |
1708 */ |
1742 */ |