summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorKai Koehne <kai.koehne@theqtcompany.com>2015-09-25 13:27:58 +0200
committerKai Koehne <kai.koehne@theqtcompany.com>2015-10-19 08:37:17 +0000
commit38a426f21c0d6e47bdc05e5541b79c48cf967a0c (patch)
tree34769fbf91f69a27316fa09a9183f137e874c008 /src
parentd9d1cc3ec8931cecc0b0dcb5d5d184cdb53ff434 (diff)
Do not require to subclass/install QWebEngineCookieStoreClient
The class has only setters and getters, except for the virtual acceptCookie method. By replacing this method with a setCookieFilter callback we can avoid the need of users to subclass the client. Change-Id: Id78c01fc103b8d9cc267594527239b598e8975f1 Reviewed-by: Allan Sandfeld Jensen <allan.jensen@theqtcompany.com>
Diffstat (limited to 'src')
-rw-r--r--src/core/api/qwebenginecallback_p.h6
-rw-r--r--src/core/api/qwebenginecookiestoreclient.cpp59
-rw-r--r--src/core/api/qwebenginecookiestoreclient.h16
-rw-r--r--src/core/api/qwebenginecookiestoreclient_p.h1
-rw-r--r--src/core/browser_context_adapter.cpp9
-rw-r--r--src/core/browser_context_adapter.h3
-rw-r--r--src/webengine/api/qquickwebengineprofile.cpp10
-rw-r--r--src/webengine/api/qquickwebengineprofile_p.h2
-rw-r--r--src/webenginewidgets/api/qwebengineprofile.cpp13
-rw-r--r--src/webenginewidgets/api/qwebengineprofile.h1
10 files changed, 73 insertions, 47 deletions
diff --git a/src/core/api/qwebenginecallback_p.h b/src/core/api/qwebenginecallback_p.h
index 44d9ceb14..f0c25fe9e 100644
--- a/src/core/api/qwebenginecallback_p.h
+++ b/src/core/api/qwebenginecallback_p.h
@@ -98,6 +98,12 @@ public:
FOR_EACH_TYPE(DEFINE_INVOKE_FOR_TYPE)
#undef DEFINE_INVOKE_FOR_TYPE
+ template <typename A>
+ void invokeDirectly(const QWebEngineCallback<A> &callback, const A &argument)
+ {
+ return callback.d.data()->operator()(std::forward<const A&>(argument));
+ }
+
private:
struct CallbackSharedDataPointerBase {
virtual ~CallbackSharedDataPointerBase() { }
diff --git a/src/core/api/qwebenginecookiestoreclient.cpp b/src/core/api/qwebenginecookiestoreclient.cpp
index 3a003ff3e..167b3f68c 100644
--- a/src/core/api/qwebenginecookiestoreclient.cpp
+++ b/src/core/api/qwebenginecookiestoreclient.cpp
@@ -175,8 +175,16 @@ void QWebEngineCookieStoreClientPrivate::onCookieChanged(const QNetworkCookie &c
bool QWebEngineCookieStoreClientPrivate::canSetCookie(const QUrl &firstPartyUrl, const QByteArray &cookieLine, const QUrl &url)
{
- Q_Q(QWebEngineCookieStoreClient);
- return q->acceptCookie(firstPartyUrl, cookieLine, url);
+ if (filterCallback) {
+ QWebEngineCookieStoreClient::FilterRequest request;
+ request.accepted = true;
+ request.firstPartyUrl = firstPartyUrl;
+ request.cookieLine = cookieLine;
+ request.cookieSource = url;
+ callbackDirectory.invokeDirectly<const QWebEngineCookieStoreClient::FilterRequest&>(filterCallback, request);
+ return request.accepted;
+ }
+ return true;
}
/*!
@@ -185,8 +193,7 @@ bool QWebEngineCookieStoreClientPrivate::canSetCookie(const QUrl &firstPartyUrl,
\since 5.6
\brief The QWebEngineCookieStoreClient class provides access to Chromium's cookies.
- By subclassing the QWebEngineCookieStoreClient and installing it on the profile, the user can
- access HTTP cookies of Chromium.
+ The class allows to access HTTP cookies of Chromium for a specific profile.
It can be used to synchronize cookies of Chromium and the QNetworkAccessManager, as well as
to set, delete, and intercept cookies during navigation.
Because cookie operations are asynchronous, the user can choose to provide a callback function
@@ -196,6 +203,27 @@ bool QWebEngineCookieStoreClientPrivate::canSetCookie(const QUrl &firstPartyUrl,
*/
/*!
+ \class QWebEngineCookieStoreClient::FilterRequest
+ \inmodule QtWebEngineCore
+ \since 5.6
+
+ The structure specifies properties of a cookie, and whether it should accepted or not. It is
+ used as an argument to a filter installed via setCookieFilter().
+*/
+
+/*!
+ \variable QWebEngineCookieStoreClient::FilterRequest::accepted
+ Whether the cookie shall be accepted. The default is \c true.
+ \variable QWebEngineCookieStoreClient::FilterRequest::firstPartyUrl
+ URL of page that triggered the setting of the cookie.
+ \variable QWebEngineCookieStoreClient::FilterRequest::cookieLine
+ Content of the cookie.
+ \variable QWebEngineCookieStoreClient::FilterRequest::cookieSource
+ URL of site that sets the cookie.
+*/
+
+
+/*!
\fn void QWebEngineCookieStoreClient::cookieAdded(const QNetworkCookie &cookie)
This signal is emitted whenever a new \a cookie is added to the cookie store.
@@ -355,20 +383,21 @@ void QWebEngineCookieStoreClient::deleteAllCookies()
}
/*!
- This virtual function is called before a new cookie is added to the cookie store.
- By overriding this function and returning \c false the user can decide to deny
- from \a firstPartyUrl the cookie \a cookieLine with the source \a cookieSource.
- The request's \a firstPartyUrl can be used to identify a third-party cookie.
- This function should not be used to execute heavy tasks since it is running on the
+ \fn void QWebEngineCookieStoreClient::setCookieFilter(FunctorOrLambda filterCallback)
+
+ Installs a cookie filter that can reject cookies before they are added to the cookie store.
+ The \a filterCallback must be a lambda or functor taking FilterRequest structure. If the
+ cookie is to be rejected, the filter can set FilterRequest::accepted to \c false.
+
+ The callback should not be used to execute heavy tasks since it is running on the
IO thread and therefore blocks the Chromium networking.
-*/
-bool QWebEngineCookieStoreClient::acceptCookie(const QUrl &firstPartyUrl, const QByteArray &cookieLine, const QUrl &cookieSource)
+ \sa deleteAllCookiesWithCallback(), getAllCookies()
+*/
+void QWebEngineCookieStoreClient::setCookieFilter(const QWebEngineCallback<const QWebEngineCookieStoreClient::FilterRequest&> &filter)
{
- Q_UNUSED(firstPartyUrl);
- Q_UNUSED(cookieLine);
- Q_UNUSED(cookieSource);
- return true;
+ Q_D(QWebEngineCookieStoreClient);
+ d->filterCallback = filter;
}
QT_END_NAMESPACE
diff --git a/src/core/api/qwebenginecookiestoreclient.h b/src/core/api/qwebenginecookiestoreclient.h
index 3a6f54ea7..8bdb988e2 100644
--- a/src/core/api/qwebenginecookiestoreclient.h
+++ b/src/core/api/qwebenginecookiestoreclient.h
@@ -46,6 +46,7 @@
#include <QtNetwork/qnetworkcookie.h>
namespace QtWebEngineCore {
+class BrowserContextAdapter;
class CookieMonsterDelegateQt;
}
@@ -54,8 +55,15 @@ QT_BEGIN_NAMESPACE
class QWebEngineCookieStoreClientPrivate;
class QWEBENGINE_EXPORT QWebEngineCookieStoreClient : public QObject {
Q_OBJECT
+
public:
- explicit QWebEngineCookieStoreClient(QObject *parent = 0);
+ struct FilterRequest {
+ bool accepted;
+
+ QUrl firstPartyUrl;
+ QByteArray cookieLine;
+ QUrl cookieSource;
+ };
virtual ~QWebEngineCookieStoreClient();
#ifdef Q_QDOC
@@ -63,24 +71,26 @@ public:
void deleteSessionCookiesWithCallback(FunctorOrLambda resultCallback);
void deleteAllCookiesWithCallback(FunctorOrLambda resultCallback);
void getAllCookies(FunctorOrLambda resultCallback);
+ void setCookieFilter(FunctorOrLambda filterCallback);
#else
void setCookieWithCallback(const QNetworkCookie &cookie, const QWebEngineCallback<bool> &resultCallback, const QUrl &origin = QUrl());
void deleteSessionCookiesWithCallback(const QWebEngineCallback<int> &resultCallback);
void deleteAllCookiesWithCallback(const QWebEngineCallback<int> &resultCallback);
void getAllCookies(const QWebEngineCallback<const QByteArray&> &resultCallback);
+ void setCookieFilter(const QWebEngineCallback<const FilterRequest&> &filterCallback);
#endif
void setCookie(const QNetworkCookie &cookie, const QUrl &origin = QUrl());
void deleteCookie(const QNetworkCookie &cookie, const QUrl &origin = QUrl());
void deleteSessionCookies();
void deleteAllCookies();
- virtual bool acceptCookie(const QUrl &firstPartyUrl, const QByteArray &cookieLine, const QUrl &cookieSource);
-
Q_SIGNALS:
void cookieAdded(const QNetworkCookie &cookie);
void cookieRemoved(const QNetworkCookie &cookie);
private:
+ explicit QWebEngineCookieStoreClient(QObject *parent = 0);
+ friend class QtWebEngineCore::BrowserContextAdapter;
friend class QtWebEngineCore::CookieMonsterDelegateQt;
Q_DISABLE_COPY(QWebEngineCookieStoreClient)
Q_DECLARE_PRIVATE(QWebEngineCookieStoreClient)
diff --git a/src/core/api/qwebenginecookiestoreclient_p.h b/src/core/api/qwebenginecookiestoreclient_p.h
index a5b0a7068..43652fba6 100644
--- a/src/core/api/qwebenginecookiestoreclient_p.h
+++ b/src/core/api/qwebenginecookiestoreclient_p.h
@@ -74,6 +74,7 @@ class QWEBENGINE_PRIVATE_EXPORT QWebEngineCookieStoreClientPrivate {
public:
Q_DECLARE_PUBLIC(QWebEngineCookieStoreClient)
QtWebEngineCore::CallbackDirectory callbackDirectory;
+ QWebEngineCallback<const QWebEngineCookieStoreClient::FilterRequest&> filterCallback;
QList<CookieData> m_pendingUserCookies;
quint64 m_nextCallbackId;
bool m_deleteSessionCookiesPending;
diff --git a/src/core/browser_context_adapter.cpp b/src/core/browser_context_adapter.cpp
index fc5dc8c21..b5fdf2ce0 100644
--- a/src/core/browser_context_adapter.cpp
+++ b/src/core/browser_context_adapter.cpp
@@ -138,16 +138,11 @@ DownloadManagerDelegateQt *BrowserContextAdapter::downloadManagerDelegate()
QWebEngineCookieStoreClient *BrowserContextAdapter::cookieStoreClient()
{
+ if (!m_cookieStoreClient)
+ m_cookieStoreClient.reset(new QWebEngineCookieStoreClient);
return m_cookieStoreClient.data();
}
-void BrowserContextAdapter::setCookieStoreClient(QWebEngineCookieStoreClient *client)
-{
- m_cookieStoreClient = client;
- if (m_browserContext->url_request_getter_.get())
- m_browserContext->url_request_getter_->updateStorageSettings();
-}
-
QWebEngineUrlRequestInterceptor *BrowserContextAdapter::requestInterceptor()
{
return m_requestInterceptor.data();
diff --git a/src/core/browser_context_adapter.h b/src/core/browser_context_adapter.h
index 6d42f0b06..818dfda3d 100644
--- a/src/core/browser_context_adapter.h
+++ b/src/core/browser_context_adapter.h
@@ -74,7 +74,6 @@ public:
DownloadManagerDelegateQt *downloadManagerDelegate();
QWebEngineCookieStoreClient *cookieStoreClient();
- void setCookieStoreClient(QWebEngineCookieStoreClient *client);
QWebEngineUrlRequestInterceptor* requestInterceptor();
void setRequestInterceptor(QWebEngineUrlRequestInterceptor *interceptor);
@@ -165,7 +164,7 @@ private:
QScopedPointer<WebEngineVisitedLinksManager> m_visitedLinksManager;
QScopedPointer<DownloadManagerDelegateQt> m_downloadManagerDelegate;
QScopedPointer<UserScriptControllerHost> m_userScriptController;
- QPointer<QWebEngineCookieStoreClient> m_cookieStoreClient;
+ QScopedPointer<QWebEngineCookieStoreClient> m_cookieStoreClient;
QPointer<QWebEngineUrlRequestInterceptor> m_requestInterceptor;
QString m_dataPath;
diff --git a/src/webengine/api/qquickwebengineprofile.cpp b/src/webengine/api/qquickwebengineprofile.cpp
index b06345b83..a678fe5fa 100644
--- a/src/webengine/api/qquickwebengineprofile.cpp
+++ b/src/webengine/api/qquickwebengineprofile.cpp
@@ -419,16 +419,16 @@ QQuickWebEngineProfile *QQuickWebEngineProfile::defaultProfile()
return profile;
}
-QQuickWebEngineSettings *QQuickWebEngineProfile::settings() const
+QWebEngineCookieStoreClient *QQuickWebEngineProfile::cookieStoreClient() const
{
const Q_D(QQuickWebEngineProfile);
- return d->settings();
+ return d->browserContext()->cookieStoreClient();
}
-void QQuickWebEngineProfile::setCookieStoreClient(QWebEngineCookieStoreClient* client)
+QQuickWebEngineSettings *QQuickWebEngineProfile::settings() const
{
- Q_D(QQuickWebEngineProfile);
- d->browserContext()->setCookieStoreClient(client);
+ const Q_D(QQuickWebEngineProfile);
+ return d->settings();
}
QT_END_NAMESPACE
diff --git a/src/webengine/api/qquickwebengineprofile_p.h b/src/webengine/api/qquickwebengineprofile_p.h
index af5762032..2cd43caad 100644
--- a/src/webengine/api/qquickwebengineprofile_p.h
+++ b/src/webengine/api/qquickwebengineprofile_p.h
@@ -122,7 +122,7 @@ public:
static QQuickWebEngineProfile *defaultProfile();
- Q_REVISION(1) Q_INVOKABLE void setCookieStoreClient(QWebEngineCookieStoreClient* client);
+ Q_REVISION(1) Q_INVOKABLE QWebEngineCookieStoreClient *cookieStoreClient() const;
signals:
void storageNameChanged();
diff --git a/src/webenginewidgets/api/qwebengineprofile.cpp b/src/webenginewidgets/api/qwebengineprofile.cpp
index 0d9e400ed..2edebdfeb 100644
--- a/src/webenginewidgets/api/qwebengineprofile.cpp
+++ b/src/webenginewidgets/api/qwebengineprofile.cpp
@@ -443,19 +443,6 @@ QWebEngineCookieStoreClient* QWebEngineProfile::cookieStoreClient()
return d->browserContext()->cookieStoreClient();
}
-/*!
- Registers a cookie store client singleton \a client to access Chromium's cookies.
-
- The profile does not take ownership of the pointer.
-
- \sa QWebEngineCookieStoreClient
-*/
-
-void QWebEngineProfile::setCookieStoreClient(QWebEngineCookieStoreClient *client)
-{
- Q_D(QWebEngineProfile);
- d->browserContext()->setCookieStoreClient(client);
-}
/*!
Registers a request interceptor singleton \a interceptor to intercept URL requests.
diff --git a/src/webenginewidgets/api/qwebengineprofile.h b/src/webenginewidgets/api/qwebengineprofile.h
index 4bed186fb..7e03c065c 100644
--- a/src/webenginewidgets/api/qwebengineprofile.h
+++ b/src/webenginewidgets/api/qwebengineprofile.h
@@ -100,7 +100,6 @@ public:
void setHttpCacheMaximumSize(int maxSize);
QWebEngineCookieStoreClient* cookieStoreClient();
- void setCookieStoreClient(QWebEngineCookieStoreClient *client);
void setRequestInterceptor(QWebEngineUrlRequestInterceptor *interceptor);
void clearAllVisitedLinks();