Disable content blockers in NetworkLoadChecker except for ping loads
authoryouenn@apple.com <youenn@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 27 Jun 2018 18:23:06 +0000 (18:23 +0000)
committeryouenn@apple.com <youenn@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 27 Jun 2018 18:23:06 +0000 (18:23 +0000)
https://bugs.webkit.org/show_bug.cgi?id=187083
<rdar://problem/41440083>

Reviewed by Chris Dumez.

Source/WebCore:

Add internals API to reload a frame without content extensions.

Test: http/tests/contentextensions/reload-without-contentextensions.html

* testing/Internals.cpp:
(WebCore::Internals::reloadWithoutContentExtensions):
* testing/Internals.h:
* testing/Internals.idl:

Source/WebKit:

* NetworkProcess/NetworkLoadChecker.cpp:
(WebKit::NetworkLoadChecker::processContentExtensionRulesForLoad):
* NetworkProcess/NetworkLoadChecker.h:
(WebKit::NetworkLoadChecker::enableContentExtensionsCheck):
* NetworkProcess/PingLoad.cpp:

LayoutTests:

* http/tests/contentextensions/reload-without-contentextensions-expected.txt: Added.
* http/tests/contentextensions/reload-without-contentextensions.html: Added.
* http/tests/contentextensions/reload-without-contentextensions.html.json: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@233269 268f45cc-cd09-0410-ab3c-d52691b4dbfc

12 files changed:
LayoutTests/ChangeLog
LayoutTests/http/tests/contentextensions/reload-without-contentextensions-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/contentextensions/reload-without-contentextensions.html [new file with mode: 0644]
LayoutTests/http/tests/contentextensions/reload-without-contentextensions.html.json [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/testing/Internals.cpp
Source/WebCore/testing/Internals.h
Source/WebCore/testing/Internals.idl
Source/WebKit/ChangeLog
Source/WebKit/NetworkProcess/NetworkLoadChecker.cpp
Source/WebKit/NetworkProcess/NetworkLoadChecker.h
Source/WebKit/NetworkProcess/PingLoad.cpp

index 42abfdb..a81e298 100644 (file)
@@ -1,3 +1,15 @@
+2018-06-27  Youenn Fablet  <youenn@apple.com>
+
+        Disable content blockers in NetworkLoadChecker except for ping loads
+        https://bugs.webkit.org/show_bug.cgi?id=187083
+        <rdar://problem/41440083>
+
+        Reviewed by Chris Dumez.
+
+        * http/tests/contentextensions/reload-without-contentextensions-expected.txt: Added.
+        * http/tests/contentextensions/reload-without-contentextensions.html: Added.
+        * http/tests/contentextensions/reload-without-contentextensions.html.json: Added.
+
 2018-06-27  Simon Fraser  <simon.fraser@apple.com>
 
         https://hackernoon.com/ uses lots of layer backing store
diff --git a/LayoutTests/http/tests/contentextensions/reload-without-contentextensions-expected.txt b/LayoutTests/http/tests/contentextensions/reload-without-contentextensions-expected.txt
new file mode 100644 (file)
index 0000000..072a31a
--- /dev/null
@@ -0,0 +1,2 @@
+CONSOLE MESSAGE: Content blocker prevented frame displaying http://127.0.0.1:8000/contentextensions/reload-without-contentextensions.html from loading a resource from http://localhost:8000/resources/square128.png
+PASS
diff --git a/LayoutTests/http/tests/contentextensions/reload-without-contentextensions.html b/LayoutTests/http/tests/contentextensions/reload-without-contentextensions.html
new file mode 100644 (file)
index 0000000..dd0b23d
--- /dev/null
@@ -0,0 +1,39 @@
+<body>
+<script>
+if (window.testRunner) {
+    testRunner.dumpAsText();
+    testRunner.waitUntilDone();
+}
+
+function done(message)
+{
+    document.body.innerHTML = message;
+    if (window.testRunner)
+        testRunner.notifyDone();
+}
+
+if (!window.internals)
+    done("FAIL: need internals API");
+
+async function doTest(shouldFail)
+{
+    const result = await fetch("resources/subresource-redirect.php", { mode : "no-cors" }).then(() => {
+        return !shouldFail;
+    }, () => {
+        return shouldFail;
+    });
+    if (!result) {
+        done("FAIL: reloaded = " + localStorage.reloaded);
+        return;
+    }
+    if (!!localStorage.reloaded) {
+        done("PASS");
+        return;
+    }
+    localStorage.reloaded = true;
+    internals.reloadWithoutContentExtensions();
+}
+
+doTest(!localStorage.reloaded);
+</script>
+</body>
diff --git a/LayoutTests/http/tests/contentextensions/reload-without-contentextensions.html.json b/LayoutTests/http/tests/contentextensions/reload-without-contentextensions.html.json
new file mode 100644 (file)
index 0000000..8549148
--- /dev/null
@@ -0,0 +1,10 @@
+[
+    {
+        "action": {
+            "type": "block"
+        },
+        "trigger": {
+            "url-filter": ".*square"
+        }
+    }
+]
index 2cf35ee..65a75bb 100644 (file)
@@ -1,3 +1,20 @@
+2018-06-27  Youenn Fablet  <youenn@apple.com>
+
+        Disable content blockers in NetworkLoadChecker except for ping loads
+        https://bugs.webkit.org/show_bug.cgi?id=187083
+        <rdar://problem/41440083>
+
+        Reviewed by Chris Dumez.
+
+        Add internals API to reload a frame without content extensions.
+
+        Test: http/tests/contentextensions/reload-without-contentextensions.html
+
+        * testing/Internals.cpp:
+        (WebCore::Internals::reloadWithoutContentExtensions):
+        * testing/Internals.h:
+        * testing/Internals.idl:
+
 2018-06-27  Simon Fraser  <simon.fraser@apple.com>
 
         https://hackernoon.com/ uses lots of layer backing store
index 080896b..9597b4a 100644 (file)
@@ -4608,5 +4608,11 @@ String Internals::ongoingLoadsDescriptions() const
     builder.append(']');
     return builder.toString();
 }
+
+void Internals::reloadWithoutContentExtensions()
+{
+    if (auto* frame = this->frame())
+        frame->loader().reload(ReloadOption::DisableContentBlockers);
+}
     
 } // namespace WebCore
index 14e1b57..24bc810 100644 (file)
@@ -705,6 +705,8 @@ public:
     void setCaptureExtraNetworkLoadMetricsEnabled(bool);
     String ongoingLoadsDescriptions() const;
 
+    void reloadWithoutContentExtensions();
+
 private:
     explicit Internals(Document&);
     Document* contextDocument() const;
index 33e8aa5..827ee12 100644 (file)
@@ -638,4 +638,6 @@ enum EventThrottlingBehavior {
 
     DOMString ongoingLoadsDescriptions();
     void setCaptureExtraNetworkLoadMetricsEnabled(boolean value);
+
+    void reloadWithoutContentExtensions();
 };
index 774416b..56933c5 100644 (file)
@@ -1,3 +1,17 @@
+2018-06-27  Youenn Fablet  <youenn@apple.com>
+
+        Disable content blockers in NetworkLoadChecker except for ping loads
+        https://bugs.webkit.org/show_bug.cgi?id=187083
+        <rdar://problem/41440083>
+
+        Reviewed by Chris Dumez.
+
+        * NetworkProcess/NetworkLoadChecker.cpp:
+        (WebKit::NetworkLoadChecker::processContentExtensionRulesForLoad):
+        * NetworkProcess/NetworkLoadChecker.h:
+        (WebKit::NetworkLoadChecker::enableContentExtensionsCheck):
+        * NetworkProcess/PingLoad.cpp:
+
 2018-06-27  Simon Fraser  <simon.fraser@apple.com>
 
         https://hackernoon.com/ uses lots of layer backing store
index a6f96a6..b5c98f3 100644 (file)
@@ -384,7 +384,7 @@ ContentSecurityPolicy* NetworkLoadChecker::contentSecurityPolicy()
 void NetworkLoadChecker::processContentExtensionRulesForLoad(ResourceRequest&& request, ContentExtensionCallback&& callback)
 {
     // FIXME: Enable content blockers for navigation loads.
-    if (!m_userContentControllerIdentifier || m_options.mode == FetchOptions::Mode::Navigate) {
+    if (!m_checkContentExtensions || !m_userContentControllerIdentifier || m_options.mode == FetchOptions::Mode::Navigate) {
         ContentExtensions::BlockedStatus status;
         callback(ContentExtensionResult { WTFMove(request), status });
         return;
index b41910f..629373b 100644 (file)
@@ -72,6 +72,8 @@ public:
     WebCore::NetworkLoadInformation takeNetworkLoadInformation() { return WTFMove(m_loadInformation); }
     void storeRedirectionIfNeeded(const WebCore::ResourceRequest&, const WebCore::ResourceResponse&);
 
+    void enableContentExtensionsCheck() { m_checkContentExtensions = true; }
+
 private:
     WebCore::ContentSecurityPolicy* contentSecurityPolicy();
     bool isChecking() const { return !!m_corsPreflightChecker; }
@@ -133,6 +135,7 @@ private:
     WebCore::PreflightPolicy m_preflightPolicy;
     String m_dntHeaderValue;
     String m_referrer;
+    bool m_checkContentExtensions { false };
     bool m_shouldCaptureExtraNetworkLoadMetrics { false };
     WebCore::NetworkLoadInformation m_loadInformation;
 };
index 0ef5141..10ca19f 100644 (file)
@@ -44,7 +44,7 @@ PingLoad::PingLoad(NetworkResourceLoadParameters&& parameters, NetworkConnection
     , m_timeoutTimer(*this, &PingLoad::timeoutTimerFired)
     , m_networkLoadChecker(makeUniqueRef<NetworkLoadChecker>(connection, m_parameters.webPageID, m_parameters.webFrameID, m_parameters.identifier, FetchOptions { m_parameters.options}, m_parameters.sessionID, WTFMove(m_parameters.originalRequestHeaders), URL { m_parameters.request.url() }, m_parameters.sourceOrigin.copyRef(), m_parameters.preflightPolicy, m_parameters.request.httpReferrer()))
 {
-
+    m_networkLoadChecker->enableContentExtensionsCheck();
     if (m_parameters.cspResponseHeaders)
         m_networkLoadChecker->setCSPResponseHeaders(WTFMove(m_parameters.cspResponseHeaders.value()));
 #if ENABLE(CONTENT_EXTENSIONS)