From de20021f10f0bb7c5c9039626ca3730b2238dac6 Mon Sep 17 00:00:00 2001 From: David Rosca Date: Thu, 22 Oct 2015 14:44:41 +0200 Subject: [PATCH] Fix build with latest QtWebEngine 5.6 --- src/lib/cookies/cookiejar.cpp | 78 ++++++++++++------- src/lib/cookies/cookiejar.h | 12 ++- src/lib/cookies/cookiemanager.cpp | 4 +- src/lib/network/networkmanager.cpp | 4 +- .../schemehandlers/qupzillaschemehandler.cpp | 2 +- src/lib/webengine/webpage.cpp | 17 ++-- src/lib/webengine/webpage.h | 3 +- 7 files changed, 75 insertions(+), 45 deletions(-) diff --git a/src/lib/cookies/cookiejar.cpp b/src/lib/cookies/cookiejar.cpp index 6473d51e0..f5f41c764 100644 --- a/src/lib/cookies/cookiejar.cpp +++ b/src/lib/cookies/cookiejar.cpp @@ -23,15 +23,25 @@ #include "qztools.h" #include +#include #include #include //#define COOKIE_DEBUG CookieJar::CookieJar(QObject* parent) - : QWebEngineCookieStoreClient(parent) + : QObject(parent) + , m_client(mApp->webProfile()->cookieStoreClient()) { loadSettings(); + + connect(m_client, &QWebEngineCookieStoreClient::cookieAdded, this, &CookieJar::cookieAdded); + connect(m_client, &QWebEngineCookieStoreClient::cookieRemoved, this, &CookieJar::cookieRemoved); + + m_client->setCookieFilter([this](const QWebEngineCookieStoreClient::FilterRequest &req) { + QWebEngineCookieStoreClient::FilterRequest &r = const_cast(req); + r.accepted = acceptCookie(r.firstPartyUrl, r.cookieLine, r.cookieSource); + }); } void CookieJar::loadSettings() @@ -51,7 +61,44 @@ void CookieJar::setAllowCookies(bool allow) m_allowCookies = allow; } -bool CookieJar::acceptCookie(const QUrl &firstPartyUrl, const QByteArray &cookieLine, const QUrl &cookieSource) +void CookieJar::getAllCookies(const QWebEngineCallback callback) +{ + m_client->getAllCookies(callback); +} + +void CookieJar::deleteAllCookies() +{ + m_client->deleteAllCookies(); +} + +bool CookieJar::matchDomain(QString cookieDomain, QString siteDomain) const +{ + // According to RFC 6265 + + // Remove leading dot + if (cookieDomain.startsWith(QLatin1Char('.'))) { + cookieDomain = cookieDomain.mid(1); + } + + if (siteDomain.startsWith(QLatin1Char('.'))) { + siteDomain = siteDomain.mid(1); + } + + return QzTools::matchDomain(cookieDomain, siteDomain); +} + +bool CookieJar::listMatchesDomain(const QStringList &list, const QString &cookieDomain) const +{ + foreach (const QString &d, list) { + if (matchDomain(d, cookieDomain)) { + return true; + } + } + + return false; +} + +bool CookieJar::acceptCookie(const QUrl &firstPartyUrl, const QByteArray &cookieLine, const QUrl &cookieSource) const { const QList cookies = QNetworkCookie::parseCookies(cookieLine); Q_ASSERT(cookies.size() == 1); @@ -101,30 +148,3 @@ bool CookieJar::rejectCookie(const QString &domain, const QNetworkCookie &cookie return false; } - -bool CookieJar::matchDomain(QString cookieDomain, QString siteDomain) const -{ - // According to RFC 6265 - - // Remove leading dot - if (cookieDomain.startsWith(QLatin1Char('.'))) { - cookieDomain = cookieDomain.mid(1); - } - - if (siteDomain.startsWith(QLatin1Char('.'))) { - siteDomain = siteDomain.mid(1); - } - - return QzTools::matchDomain(cookieDomain, siteDomain); -} - -bool CookieJar::listMatchesDomain(const QStringList &list, const QString &cookieDomain) const -{ - foreach (const QString &d, list) { - if (matchDomain(d, cookieDomain)) { - return true; - } - } - - return false; -} diff --git a/src/lib/cookies/cookiejar.h b/src/lib/cookies/cookiejar.h index f0e74815d..42229ccef 100644 --- a/src/lib/cookies/cookiejar.h +++ b/src/lib/cookies/cookiejar.h @@ -26,7 +26,7 @@ class AutoSaver; -class QUPZILLA_EXPORT CookieJar : public QWebEngineCookieStoreClient +class QUPZILLA_EXPORT CookieJar : public QObject { Q_OBJECT @@ -36,13 +36,20 @@ public: void loadSettings(); void setAllowCookies(bool allow); - bool acceptCookie(const QUrl &firstPartyUrl, const QByteArray &cookieLine, const QUrl &cookieSource) Q_DECL_OVERRIDE; + + void getAllCookies(const QWebEngineCallback callback); + void deleteAllCookies(); + +signals: + void cookieAdded(const QNetworkCookie &cookie); + void cookieRemoved(const QNetworkCookie &cookie); protected: bool matchDomain(QString cookieDomain, QString siteDomain) const; bool listMatchesDomain(const QStringList &list, const QString &cookieDomain) const; private: + bool acceptCookie(const QUrl &firstPartyUrl, const QByteArray &cookieLine, const QUrl &cookieSource) const; bool rejectCookie(const QString &domain, const QNetworkCookie &cookie, const QString &cookieDomain) const; bool m_allowCookies; @@ -51,6 +58,7 @@ private: QStringList m_whitelist; QStringList m_blacklist; + QWebEngineCookieStoreClient *m_client; }; #endif // COOKIEJAR_H diff --git a/src/lib/cookies/cookiemanager.cpp b/src/lib/cookies/cookiemanager.cpp index c8c0542da..1544df652 100644 --- a/src/lib/cookies/cookiemanager.cpp +++ b/src/lib/cookies/cookiemanager.cpp @@ -84,8 +84,8 @@ CookieManager::CookieManager() connect(removeShortcut, SIGNAL(activated()), this, SLOT(deletePressed())); connect(ui->search, SIGNAL(textChanged(QString)), this, SLOT(filterString(QString))); - connect (mApp->cookieJar(), &CookieJar::cookieAdded, this, &CookieManager::addCookie); - connect (mApp->cookieJar(), &CookieJar::cookieRemoved, this, &CookieManager::removeCookie); + connect(mApp->cookieJar(), &CookieJar::cookieAdded, this, &CookieManager::addCookie); + connect(mApp->cookieJar(), &CookieJar::cookieRemoved, this, &CookieManager::removeCookie); // Load cookies mApp->cookieJar()->getAllCookies([this](const QByteArray &res) { diff --git a/src/lib/network/networkmanager.cpp b/src/lib/network/networkmanager.cpp index 33fc078a2..809c95148 100644 --- a/src/lib/network/networkmanager.cpp +++ b/src/lib/network/networkmanager.cpp @@ -43,14 +43,14 @@ NetworkManager::NetworkManager(QObject *parent) : QNetworkAccessManager(parent) { // Create scheme handlers - mApp->webProfile()->installUrlSchemeHandler(new QupZillaSchemeHandler(this)); + mApp->webProfile()->installUrlSchemeHandler(QByteArrayLiteral("qupzilla"), new QupZillaSchemeHandler(this)); // Create url interceptor m_urlInterceptor = new NetworkUrlInterceptor(this); mApp->webProfile()->setRequestInterceptor(m_urlInterceptor); // Create cookie jar - mApp->webProfile()->setCookieStoreClient(mApp->cookieJar()); + mApp->cookieJar(); connect(this, &QNetworkAccessManager::authenticationRequired, this, [this](QNetworkReply *reply, QAuthenticator *auth) { authentication(reply->url(), auth); diff --git a/src/lib/network/schemehandlers/qupzillaschemehandler.cpp b/src/lib/network/schemehandlers/qupzillaschemehandler.cpp index 0f10887f1..031e56818 100644 --- a/src/lib/network/schemehandlers/qupzillaschemehandler.cpp +++ b/src/lib/network/schemehandlers/qupzillaschemehandler.cpp @@ -39,7 +39,7 @@ static QString authorString(const char* name, const QString &mail) } QupZillaSchemeHandler::QupZillaSchemeHandler(QObject *parent) - : QWebEngineUrlSchemeHandler(QByteArrayLiteral("qupzilla"), parent) + : QWebEngineUrlSchemeHandler(parent) { } diff --git a/src/lib/webengine/webpage.cpp b/src/lib/webengine/webpage.cpp index 4989ed3fd..40ad90499 100644 --- a/src/lib/webengine/webpage.cpp +++ b/src/lib/webengine/webpage.cpp @@ -54,6 +54,7 @@ #include #include #include +#include #include #include #include @@ -316,9 +317,16 @@ void WebPage::windowCloseRequested() view()->closeView(); } -void WebPage::fullScreenRequested(bool fullScreen) +void WebPage::fullScreenRequested(const QWebEngineFullScreenRequest &fullScreenRequest) { - view()->requestFullScreen(fullScreen); + view()->requestFullScreen(fullScreenRequest.toggleOn()); + + const bool accepted = fullScreenRequest.toggleOn() == view()->isFullScreen(); + + if (accepted) + fullScreenRequest.accept(); + else + fullScreenRequest.reject(); } void WebPage::featurePermissionRequested(const QUrl &origin, const QWebEnginePage::Feature &feature) @@ -351,11 +359,6 @@ void WebPage::renderProcessTerminated(QWebEnginePage::RenderProcessTerminationSt }); } -bool WebPage::isFullScreen() -{ - return view()->isFullScreen(); -} - bool WebPage::acceptNavigationRequest(const QUrl &url, QWebEnginePage::NavigationType type, bool isMainFrame) { if (!mApp->plugins()->acceptNavigationRequest(this, url, type, isMainFrame)) diff --git a/src/lib/webengine/webpage.h b/src/lib/webengine/webpage.h index 6bcd1de47..158890bce 100644 --- a/src/lib/webengine/webpage.h +++ b/src/lib/webengine/webpage.h @@ -74,12 +74,11 @@ private slots: void urlChanged(const QUrl &url); void watchedFileChanged(const QString &file); void windowCloseRequested(); - void fullScreenRequested(bool fullScreen); + void fullScreenRequested(const QWebEngineFullScreenRequest &fullScreenRequest); void featurePermissionRequested(const QUrl &origin, const QWebEnginePage::Feature &feature); void renderProcessTerminated(RenderProcessTerminationStatus terminationStatus, int exitCode); private: - bool isFullScreen() Q_DECL_OVERRIDE; bool acceptNavigationRequest(const QUrl &url, NavigationType type, bool isMainFrame) Q_DECL_OVERRIDE; bool certificateError(const QWebEngineCertificateError &error) Q_DECL_OVERRIDE; QStringList chooseFiles(FileSelectionMode mode, const QStringList &oldFiles, const QStringList &acceptedMimeTypes) Q_DECL_OVERRIDE;