From fc85caff572d617b6b54770959e8d5338e8ace48 Mon Sep 17 00:00:00 2001 From: David Rosca Date: Thu, 24 Sep 2015 23:00:27 +0200 Subject: [PATCH] Add QWebPage::view() that returns WebView * --- src/lib/autofill/autofill.cpp | 8 +-- src/lib/autofill/autofill.h | 3 +- .../html5permissionsmanager.cpp | 7 +-- src/lib/webengine/webpage.cpp | 52 +++++++------------ src/lib/webengine/webpage.h | 7 ++- src/lib/webengine/webview.cpp | 2 +- src/lib/webengine/webview.h | 2 +- 7 files changed, 31 insertions(+), 50 deletions(-) diff --git a/src/lib/autofill/autofill.cpp b/src/lib/autofill/autofill.cpp index ce8319adb..e877b2789 100644 --- a/src/lib/autofill/autofill.cpp +++ b/src/lib/autofill/autofill.cpp @@ -177,16 +177,12 @@ void AutoFill::removeAllEntries() m_manager->removeAllEntries(); } -void AutoFill::saveForm(QWebEnginePage *page, const QUrl &frameUrl, const PageFormData &formData) +void AutoFill::saveForm(WebPage *page, const QUrl &frameUrl, const PageFormData &formData) { // Don't save in private browsing if (mApp->isPrivate() || !page) return; - WebView* webView = qobject_cast(page->view()); - if (!webView) - return; - if (!isStoringEnabled(frameUrl)) return; @@ -214,7 +210,7 @@ void AutoFill::saveForm(QWebEnginePage *page, const QUrl &frameUrl, const PageFo } AutoFillNotification* aWidget = new AutoFillNotification(frameUrl, formData, updateData); - webView->addNotification(aWidget); + page->view()->addNotification(aWidget); } // Returns all saved passwords on this page diff --git a/src/lib/autofill/autofill.h b/src/lib/autofill/autofill.h index 6182e7290..92e992823 100644 --- a/src/lib/autofill/autofill.h +++ b/src/lib/autofill/autofill.h @@ -26,6 +26,7 @@ class QUrl; class QWebEnginePage; class QNetworkRequest; +class WebPage; class BrowserWindow; class PasswordManager; struct PageFormData; @@ -69,7 +70,7 @@ public: void removeEntry(const PasswordEntry &entry); void removeAllEntries(); - void saveForm(QWebEnginePage *page, const QUrl &frameUrl, const PageFormData &formData); + void saveForm(WebPage *page, const QUrl &frameUrl, const PageFormData &formData); QVector completePage(QWebEnginePage *page, const QUrl &frameUrl); QByteArray exportPasswords(); diff --git a/src/lib/tools/html5permissions/html5permissionsmanager.cpp b/src/lib/tools/html5permissions/html5permissionsmanager.cpp index 439b6837b..5f0a09808 100644 --- a/src/lib/tools/html5permissions/html5permissionsmanager.cpp +++ b/src/lib/tools/html5permissions/html5permissionsmanager.cpp @@ -51,11 +51,8 @@ void HTML5PermissionsManager::requestPermissions(WebPage* page, const QUrl &orig } // Ask user for permission - WebView* view = qobject_cast(page->view()); - if (view) { - HTML5PermissionsNotification* notif = new HTML5PermissionsNotification(origin, page, feature); - view->addNotification(notif); - } + HTML5PermissionsNotification* notif = new HTML5PermissionsNotification(origin, page, feature); + page->view()->addNotification(notif); } void HTML5PermissionsManager::rememberPermissions(const QUrl &origin, const QWebEnginePage::Feature &feature, diff --git a/src/lib/webengine/webpage.cpp b/src/lib/webengine/webpage.cpp index b1422ec7a..9867437be 100644 --- a/src/lib/webengine/webpage.cpp +++ b/src/lib/webengine/webpage.cpp @@ -102,22 +102,22 @@ WebPage::~WebPage() } } +WebView *WebPage::view() const +{ + return static_cast(QWebEnginePage::view()); +} + void WebPage::scheduleAdjustPage() { - WebView* webView = qobject_cast(view()); - if (!webView) { - return; - } - - if (webView->isLoading()) { + if (view()->isLoading()) { m_adjustingScheduled = true; } else { - const QSize originalSize = webView->size(); + const QSize originalSize = view()->size(); QSize newSize(originalSize.width() - 1, originalSize.height() - 1); - webView->resize(newSize); - webView->resize(originalSize); + view()->resize(newSize); + view()->resize(originalSize); } } @@ -311,12 +311,7 @@ void WebPage::setupWebChannel() void WebPage::windowCloseRequested() { - WebView* webView = qobject_cast(view()); - if (!webView) { - return; - } - - webView->closeView(); + view()->closeView(); } void WebPage::authentication(const QUrl &requestUrl, QAuthenticator* auth) @@ -455,12 +450,8 @@ void WebPage::proxyAuthentication(const QUrl &requestUrl, QAuthenticator* auth, void WebPage::doWebSearch(const QString &text) { - WebView* webView = qobject_cast(view()); - - if (webView) { - const LoadRequest searchRequest = mApp->searchEnginesManager()->searchResult(text); - webView->load(searchRequest); - } + const LoadRequest searchRequest = mApp->searchEnginesManager()->searchResult(text); + view()->load(searchRequest); } void WebPage::featurePermissionRequested(const QUrl &origin, const QWebEnginePage::Feature &feature) @@ -839,8 +830,7 @@ bool WebPage::javaScriptPrompt(const QUrl &securityOrigin, const QString &msg, c return false; } - WebView* webView = qobject_cast(view()); - ResizableFrame* widget = new ResizableFrame(webView->overlayWidget()); + ResizableFrame* widget = new ResizableFrame(view()->overlayWidget()); widget->setObjectName("jsFrame"); Ui_jsPrompt* ui = new Ui_jsPrompt(); @@ -868,7 +858,7 @@ bool WebPage::javaScriptPrompt(const QUrl &securityOrigin, const QString &msg, c *result = x; delete widget; - webView->setFocus(); + view()->setFocus(); return _result; #endif @@ -883,8 +873,7 @@ bool WebPage::javaScriptConfirm(const QUrl &securityOrigin, const QString &msg) return false; } - WebView* webView = qobject_cast(view()); - ResizableFrame* widget = new ResizableFrame(webView->overlayWidget()); + ResizableFrame* widget = new ResizableFrame(view()->overlayWidget()); widget->setObjectName("jsFrame"); Ui_jsConfirm* ui = new Ui_jsConfirm(); @@ -908,7 +897,7 @@ bool WebPage::javaScriptConfirm(const QUrl &securityOrigin, const QString &msg) bool result = ui->buttonBox->clickedButtonRole() == QDialogButtonBox::AcceptRole; delete widget; - webView->setFocus(); + view()->setFocus(); return result; #endif @@ -937,18 +926,17 @@ void WebPage::javaScriptAlert(const QUrl &securityOrigin, const QString &msg) m_blockAlerts = dialog.isChecked(); #else - WebView* webView = qobject_cast(view()); - ResizableFrame* widget = new ResizableFrame(webView->overlayWidget()); + ResizableFrame* widget = new ResizableFrame(view()->overlayWidget()); widget->setObjectName("jsFrame"); Ui_jsAlert* ui = new Ui_jsAlert(); ui->setupUi(widget); ui->message->setText(msg); ui->buttonBox->button(QDialogButtonBox::Ok)->setFocus(); - widget->resize(webView->size()); + widget->resize(view()->size()); widget->show(); - connect(webView, SIGNAL(viewportResized(QSize)), widget, SLOT(slotResize(QSize))); + connect(view(), SIGNAL(viewportResized(QSize)), widget, SLOT(slotResize(QSize))); QEventLoop eLoop; m_runningLoop = &eLoop; @@ -963,7 +951,7 @@ void WebPage::javaScriptAlert(const QUrl &securityOrigin, const QString &msg) delete widget; - webView->setFocus(); + view()->setFocus(); #endif } diff --git a/src/lib/webengine/webpage.h b/src/lib/webengine/webpage.h index e6a76ee68..70d589a97 100644 --- a/src/lib/webengine/webpage.h +++ b/src/lib/webengine/webpage.h @@ -28,10 +28,8 @@ class QEventLoop; class QWebEngineDownloadItem; -class BrowserWindow; +class WebView; class AdBlockRule; -class SpeedDial; -class NetworkManagerProxy; class DelayedFileWatcher; class QUPZILLA_EXPORT WebPage : public QWebEnginePage @@ -50,6 +48,8 @@ public: WebPage(QObject* parent = 0); ~WebPage(); + WebView *view() const; + void setSSLCertificate(const QSslCertificate &cert); QSslCertificate sslCertificate(); @@ -113,7 +113,6 @@ private: static QTime s_lastUnsupportedUrlTime; static QStringList s_ignoredSslErrors; - NetworkManagerProxy* m_networkProxy; DelayedFileWatcher* m_fileWatcher; QEventLoop* m_runningLoop; diff --git a/src/lib/webengine/webview.cpp b/src/lib/webengine/webview.cpp index fdec29bcc..94db5cc7a 100644 --- a/src/lib/webengine/webview.cpp +++ b/src/lib/webengine/webview.cpp @@ -123,7 +123,7 @@ WebPage* WebView::page() const return m_page; } -void WebView::setPage(QWebEnginePage* page) +void WebView::setPage(WebPage *page) { if (m_page == page) { return; diff --git a/src/lib/webengine/webview.h b/src/lib/webengine/webview.h index bcf732801..b6edd83fd 100644 --- a/src/lib/webengine/webview.h +++ b/src/lib/webengine/webview.h @@ -41,7 +41,7 @@ public: bool isTitleEmpty() const; WebPage* page() const; - void setPage(QWebEnginePage* page); + void setPage(WebPage* page); void load(const QUrl &url); void load(const LoadRequest &request);