summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeter Varga <pvarga@inf.u-szeged.hu>2018-05-16 09:36:24 +0200
committerPeter Varga <pvarga@inf.u-szeged.hu>2018-05-17 08:32:30 +0000
commitbab4ababd097fd90b227a5a1bca63343b97af091 (patch)
tree3765bf3196f10453a38d973fd8ed2916c33ddd9d
parent8476245d1a197d05f988ef87f17b7ccbbcbba878 (diff)
Keep settings synchronized when RVH swaps
There can be more than one RenderViewHost assigned to a single WebContents. This is the case when starting a page load results changing processes. When applying settings during the load it updates only the old RVH. This fix applies the settings to the new RVH too after the swap. Task-number: QTBUG-66656 Change-Id: I833415b2a34f58e2a9a18c209a025c82b73aa65a Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
-rw-r--r--src/core/web_contents_delegate_qt.cpp11
-rw-r--r--src/core/web_contents_delegate_qt.h1
-rw-r--r--tests/auto/widgets/qwebenginesettings/tst_qwebenginesettings.cpp35
3 files changed, 47 insertions, 0 deletions
diff --git a/src/core/web_contents_delegate_qt.cpp b/src/core/web_contents_delegate_qt.cpp
index aae7f4a43..7f3ced8aa 100644
--- a/src/core/web_contents_delegate_qt.cpp
+++ b/src/core/web_contents_delegate_qt.cpp
@@ -527,6 +527,17 @@ void WebContentsDelegateQt::ActivateContents(content::WebContents* contents)
contents->Focus();
}
+void WebContentsDelegateQt::RenderViewHostChanged(content::RenderViewHost *old_host, content::RenderViewHost *new_host)
+{
+ Q_ASSERT(new_host);
+
+ // The old RVH can be nullptr if it was shut down.
+ if (!old_host)
+ return;
+
+ new_host->UpdateWebkitPreferences(old_host->GetWebkitPreferences());
+}
+
void WebContentsDelegateQt::RequestToLockMouse(content::WebContents *web_contents, bool user_gesture, bool last_unlocked_by_target)
{
Q_UNUSED(user_gesture);
diff --git a/src/core/web_contents_delegate_qt.h b/src/core/web_contents_delegate_qt.h
index 2ef87ccd8..43badf60e 100644
--- a/src/core/web_contents_delegate_qt.h
+++ b/src/core/web_contents_delegate_qt.h
@@ -139,6 +139,7 @@ public:
void WasShown() override;
void DidFirstVisuallyNonEmptyPaint() override;
void ActivateContents(content::WebContents* contents) override;
+ void RenderViewHostChanged(content::RenderViewHost *old_host, content::RenderViewHost *new_host) override;
void didFailLoad(const QUrl &url, int errorCode, const QString &errorDescription);
void overrideWebPreferences(content::WebContents *, content::WebPreferences*);
diff --git a/tests/auto/widgets/qwebenginesettings/tst_qwebenginesettings.cpp b/tests/auto/widgets/qwebenginesettings/tst_qwebenginesettings.cpp
index 845520628..150b3c554 100644
--- a/tests/auto/widgets/qwebenginesettings/tst_qwebenginesettings.cpp
+++ b/tests/auto/widgets/qwebenginesettings/tst_qwebenginesettings.cpp
@@ -37,6 +37,7 @@ private Q_SLOTS:
void defaultFontFamily();
void javascriptClipboard_data();
void javascriptClipboard();
+ void setInAcceptNavigationRequest();
};
void tst_QWebEngineSettings::resetAttributes()
@@ -162,6 +163,40 @@ void tst_QWebEngineSettings::javascriptClipboard()
(pasteResult ? QString("AnotherText") : QString("OriginalText")));
}
+class NavigationRequestOverride : public QWebEnginePage
+{
+protected:
+ virtual bool acceptNavigationRequest(const QUrl &url, NavigationType type, bool isMainFrame)
+ {
+ Q_UNUSED(type);
+
+ if (isMainFrame && url.scheme().startsWith("data"))
+ settings()->setAttribute(QWebEngineSettings::JavascriptEnabled, true);
+
+ return true;
+ }
+};
+
+void tst_QWebEngineSettings::setInAcceptNavigationRequest()
+{
+ NavigationRequestOverride page;
+ QSignalSpy loadFinishedSpy(&page, SIGNAL(loadFinished(bool)));
+ QWebEngineSettings::globalSettings()->setAttribute(QWebEngineSettings::JavascriptEnabled, false);
+ QVERIFY(!page.settings()->testAttribute(QWebEngineSettings::JavascriptEnabled));
+
+ page.load(QUrl("about:blank"));
+ QVERIFY(loadFinishedSpy.wait());
+ QVERIFY(!page.settings()->testAttribute(QWebEngineSettings::JavascriptEnabled));
+
+ page.setHtml("<html><body>"
+ "<script>document.write('PASS')</script>"
+ "<noscript>FAIL</noscript>"
+ "</body></html>");
+ QVERIFY(loadFinishedSpy.wait());
+ QVERIFY(page.settings()->testAttribute(QWebEngineSettings::JavascriptEnabled));
+ QCOMPARE(toPlainTextSync(&page), QStringLiteral("PASS"));
+}
+
QTEST_MAIN(tst_QWebEngineSettings)
#include "tst_qwebenginesettings.moc"