diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2017-09-01 13:10:34 +0200 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2018-01-19 07:42:58 +0000 |
commit | 757004ecf484289f576870b4f251c3e7551294c5 (patch) | |
tree | 3f45d9230b87239d16ca7584c07b54b068c11697 /tests/quicktestbrowser | |
parent | 71d6dc0c326523103dff867d7184e7bc7e49c71d (diff) |
Reinstate cookie filter API
Expose API to block cookies for specific domains, or third party cookies
in general.
Task-number: QTBUG-62897
Change-Id: I7f0e3f346368a2ef2fbd77f3197ee2dea50d57ce
Reviewed-by: Peter Varga <pvarga@inf.u-szeged.hu>
Diffstat (limited to 'tests/quicktestbrowser')
-rw-r--r-- | tests/quicktestbrowser/BrowserWindow.qml | 8 | ||||
-rw-r--r-- | tests/quicktestbrowser/main.cpp | 22 |
2 files changed, 29 insertions, 1 deletions
diff --git a/tests/quicktestbrowser/BrowserWindow.qml b/tests/quicktestbrowser/BrowserWindow.qml index 2d8807e8c..22f98e1c5 100644 --- a/tests/quicktestbrowser/BrowserWindow.qml +++ b/tests/quicktestbrowser/BrowserWindow.qml @@ -66,6 +66,7 @@ ApplicationWindow { property alias javaScriptEnabled: javaScriptEnabled.checked; property alias errorPageEnabled: errorPageEnabled.checked; property alias pluginsEnabled: pluginsEnabled.checked; + property alias thirdPartyCookiesEnabled: thirdPartyCookiesEnabled.checked; } // Make sure the Qt.WindowFullscreenButtonHint is set on OS X. @@ -241,6 +242,13 @@ ApplicationWindow { checked: true } MenuItem { + id: thirdPartyCookiesEnabled + text: "Third party cookies enabled" + checkable: true + checked: true + onToggled: applicationRoot.thirdPartyCookiesEnabled = checked + } + MenuItem { id: offTheRecordEnabled text: "Off The Record" checkable: true diff --git a/tests/quicktestbrowser/main.cpp b/tests/quicktestbrowser/main.cpp index 3f513f6a6..d56841974 100644 --- a/tests/quicktestbrowser/main.cpp +++ b/tests/quicktestbrowser/main.cpp @@ -70,7 +70,27 @@ int main(int argc, char **argv) Utils utils; appEngine.rootContext()->setContextProperty("utils", &utils); appEngine.load(QUrl("qrc:/ApplicationRoot.qml")); - QMetaObject::invokeMethod(appEngine.rootObjects().first(), "load", Q_ARG(QVariant, startupUrl())); + + QObject *rootObject = appEngine.rootObjects().first(); + + QQuickWebEngineProfile *profile = new QQuickWebEngineProfile(rootObject); + + const QMetaObject *rootMeta = rootObject->metaObject(); + int index = rootMeta->indexOfProperty("thirdPartyCookiesEnabled"); + Q_ASSERT(index != -1); + QMetaProperty thirdPartyCookiesProperty = rootMeta->property(index); + profile->cookieStore()->setCookieFilter( + [rootObject,&thirdPartyCookiesProperty](QWebEngineCookieStore::FilterRequest &request) + { + request.accepted = !request.thirdParty || thirdPartyCookiesProperty.read(rootObject).toBool(); + }); + + index = rootMeta->indexOfProperty("testProfile"); + Q_ASSERT(index != -1); + QMetaProperty profileProperty = rootMeta->property(index); + profileProperty.write(rootObject, qVariantFromValue(profile)); + + QMetaObject::invokeMethod(rootObject, "load", Q_ARG(QVariant, startupUrl())); return app.exec(); } |