Title: [244794] trunk
Revision
244794
Author
[email protected]
Date
2019-04-30 12:42:34 -0700 (Tue, 30 Apr 2019)

Log Message

Add WKContentRuleList ping resource-type
https://bugs.webkit.org/show_bug.cgi?id=197325
<rdar://problem/49841404>

Reviewed by Geoff Garen.

Source/WebCore:

Tests: http/tests/contentextensions/block-ping-resource-type-ping.html and http/tests/contentextensions/block-ping-resource-type-raw.html

* contentextensions/ContentExtensionsBackend.cpp:
(WebCore::ContentExtensions::ContentExtensionsBackend::processContentRuleListsForLoad):
* contentextensions/ContentExtensionsBackend.h:
* loader/PingLoader.cpp:
(WebCore::processContentRuleListsForLoad):
(WebCore::PingLoader::sendPing):
* loader/ResourceLoadInfo.cpp:
(WebCore::ContentExtensions::readResourceType):
(WebCore::ContentExtensions::ResourceLoadInfo::getResourceFlags const):
* loader/ResourceLoadInfo.h:
* page/UserContentProvider.cpp:
(WebCore::UserContentProvider::processContentRuleListsForLoad):
* page/UserContentProvider.h:

LayoutTests:

* http/tests/contentextensions/block-ping-resource-type-raw--expected.txt: Copied from LayoutTests/http/tests/contentextensions/block-ping-expected.txt.
* http/tests/contentextensions/block-ping-resource-type-raw.html: Copied from LayoutTests/http/tests/contentextensions/block-ping.html.
* http/tests/contentextensions/block-ping-resource-type-raw.html.json: Copied from LayoutTests/http/tests/contentextensions/block-ping.html.json.
* http/tests/contentextensions/block-ping-resource-type-ping-expected.txt: Copied from LayoutTests/http/tests/contentextensions/block-ping-expected.txt.
* http/tests/contentextensions/block-ping-resource-type-ping.html: Copied from LayoutTests/http/tests/contentextensions/block-ping.html.
* http/tests/contentextensions/block-ping-resource-type-ping.html.json: Copied from LayoutTests/http/tests/contentextensions/block-ping.html.json.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (244793 => 244794)


--- trunk/LayoutTests/ChangeLog	2019-04-30 19:29:46 UTC (rev 244793)
+++ trunk/LayoutTests/ChangeLog	2019-04-30 19:42:34 UTC (rev 244794)
@@ -1,3 +1,18 @@
+2019-04-30  Alex Christensen  <[email protected]>
+
+        Add WKContentRuleList ping resource-type
+        https://bugs.webkit.org/show_bug.cgi?id=197325
+        <rdar://problem/49841404>
+
+        Reviewed by Geoff Garen.
+
+        * http/tests/contentextensions/block-ping-resource-type-raw--expected.txt: Copied from LayoutTests/http/tests/contentextensions/block-ping-expected.txt.
+        * http/tests/contentextensions/block-ping-resource-type-raw.html: Copied from LayoutTests/http/tests/contentextensions/block-ping.html.
+        * http/tests/contentextensions/block-ping-resource-type-raw.html.json: Copied from LayoutTests/http/tests/contentextensions/block-ping.html.json.
+        * http/tests/contentextensions/block-ping-resource-type-ping-expected.txt: Copied from LayoutTests/http/tests/contentextensions/block-ping-expected.txt.
+        * http/tests/contentextensions/block-ping-resource-type-ping.html: Copied from LayoutTests/http/tests/contentextensions/block-ping.html.
+        * http/tests/contentextensions/block-ping-resource-type-ping.html.json: Copied from LayoutTests/http/tests/contentextensions/block-ping.html.json.
+
 2019-04-30  Shawn Roberts  <[email protected]>
 
         Fixing typo in https://trac.webkit.org/changeset/244780/webkit.

Copied: trunk/LayoutTests/http/tests/contentextensions/block-ping-resource-type-ping-expected.txt (from rev 244759, trunk/LayoutTests/http/tests/contentextensions/block-ping-expected.txt) (0 => 244794)


--- trunk/LayoutTests/http/tests/contentextensions/block-ping-resource-type-ping-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/http/tests/contentextensions/block-ping-resource-type-ping-expected.txt	2019-04-30 19:42:34 UTC (rev 244794)
@@ -0,0 +1,13 @@
+CONSOLE MESSAGE: line 34: Content blocker prevented frame displaying http://127.0.0.1:8000/contentextensions/block-ping-resource-type-ping.html from loading a resource from http://127.0.0.1:8000/contentextensions/resources/save-ping.php?test=contentextensions-block-ping-resource-type-ping
+ALERT: PASS: successfully loaded ping url with fetch
+This test follows a link with a ping attribute where the ping URL matches a 'block' rule.  
+
+--------
+Frame: 'link_frame'
+--------
+Link with ping was clicked.
+
+--------
+Frame: 'result_frame'
+--------
+Ping not received - timed out.

Copied: trunk/LayoutTests/http/tests/contentextensions/block-ping-resource-type-ping.html (from rev 244759, trunk/LayoutTests/http/tests/contentextensions/block-ping.html) (0 => 244794)


--- trunk/LayoutTests/http/tests/contentextensions/block-ping-resource-type-ping.html	                        (rev 0)
+++ trunk/LayoutTests/http/tests/contentextensions/block-ping-resource-type-ping.html	2019-04-30 19:42:34 UTC (rev 244794)
@@ -0,0 +1,62 @@
+<head>
+<script>
+if (window.testRunner && window.internals) {
+    testRunner.dumpAsText();
+    testRunner.dumpChildFramesAsText();
+    internals.settings.setHyperlinkAuditingEnabled(true);
+    testRunner.waitUntilDone();
+}
+
+function loadLinkWithPing() {
+    var iframe = document.getElementById("link_frame");
+    var iframeDoc = iframe.contentDocument || iframe.contentWindow.document;
+    iframeDoc.write('' +
+        '<img src="" ' +
+            '_onerror_="parent.clickOnLinkWithPing();">' +
+        '<a id="a" ' +
+            'href="" ' + // check-ping.html calls showPingResult()
+            'ping="resources/save-ping.php?test=contentextensions-block-ping-resource-type-ping"> ' +
+            'Link with ping' +
+        '</a>'
+        
+    );
+}
+
+function clickOnLinkWithPing() {
+    var iframe = document.getElementById("link_frame");
+    var iframeDoc = iframe.contentDocument;
+    if (window.eventSender) {
+        var a = iframeDoc.getElementById("a");
+        var x = iframe.offsetLeft + a.offsetLeft + 2;
+        var y = iframe.offsetTop + a.offsetTop + 2;
+        eventSender.mouseMoveTo(x, y);
+        eventSender.mouseDown();
+        eventSender.mouseUp();
+    }
+}
+
+function showPingResult() {
+    var iframe = document.getElementById("result_frame");
+    iframe._onload_ = function() {
+        fetch("resources/save-ping.php?test=contentextensions-block-ping-resource-type-ping").then(()=>{
+            fetch("resources/delete-ping.php?test=contentextensions-block-ping-resource-type-ping").then(()=>{
+                alert("PASS: successfully loaded ping url with fetch");
+                if (window.testRunner) { testRunner.notifyDone(); }
+            })
+        }).catch(error => { alert("FAIL:" + error); if (window.testRunner) { testRunner.notifyDone(); } });
+    }
+    iframe.src = ""
+    // Why timeout_ms=1000:
+    // To pass the test, the ping shouldn't arrive, so we need to
+    // timeout at some point. We don't have to wait too long because
+    // the console message can tell us whether the ping was blocked.
+}
+</script>
+</head>
+
+<body _onload_="loadLinkWithPing();">
+This test follows a link with a ping attribute where the ping URL matches a 'block' rule.
+<iframe id="link_frame" name="link_frame"><!-- Will contain link with ping --></iframe>
+<iframe id="result_frame" name="result_frame"><!-- Will contain ping data received by server --></iframe>
+</body>
+

Copied: trunk/LayoutTests/http/tests/contentextensions/block-ping-resource-type-ping.html.json (from rev 244759, trunk/LayoutTests/http/tests/contentextensions/block-ping.html.json) (0 => 244794)


--- trunk/LayoutTests/http/tests/contentextensions/block-ping-resource-type-ping.html.json	                        (rev 0)
+++ trunk/LayoutTests/http/tests/contentextensions/block-ping-resource-type-ping.html.json	2019-04-30 19:42:34 UTC (rev 244794)
@@ -0,0 +1,11 @@
+[
+    {
+        "trigger": {
+            "url-filter": "save-ping.php",
+            "resource-type": ["ping"]
+        },
+        "action": {
+            "type": "block"
+        }
+    }
+]

Copied: trunk/LayoutTests/http/tests/contentextensions/block-ping-resource-type-raw-expected.txt (from rev 244759, trunk/LayoutTests/http/tests/contentextensions/block-ping-expected.txt) (0 => 244794)


--- trunk/LayoutTests/http/tests/contentextensions/block-ping-resource-type-raw-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/http/tests/contentextensions/block-ping-resource-type-raw-expected.txt	2019-04-30 19:42:34 UTC (rev 244794)
@@ -0,0 +1,16 @@
+CONSOLE MESSAGE: line 34: Content blocker prevented frame displaying http://127.0.0.1:8000/contentextensions/block-ping-resource-type-raw.html from loading a resource from http://127.0.0.1:8000/contentextensions/resources/save-ping.php?test=contentextensions-block-ping-resource-type-raw
+CONSOLE MESSAGE: line 41: Content blocker prevented frame displaying http://127.0.0.1:8000/contentextensions/block-ping-resource-type-raw.html from loading a resource from http://127.0.0.1:8000/contentextensions/resources/save-ping.php?test=contentextensions-block-ping-resource-type-raw
+CONSOLE MESSAGE: line 41: Resource blocked by content blocker
+CONSOLE MESSAGE: line 41: Fetch API cannot load http://127.0.0.1:8000/contentextensions/resources/save-ping.php?test=contentextensions-block-ping-resource-type-raw due to access control checks.
+ALERT: PASS:TypeError: Resource blocked by content blocker
+This test follows a link with a ping attribute where the ping URL matches a 'block' rule.  
+
+--------
+Frame: 'link_frame'
+--------
+Link with ping was clicked.
+
+--------
+Frame: 'result_frame'
+--------
+Ping not received - timed out.

Copied: trunk/LayoutTests/http/tests/contentextensions/block-ping-resource-type-raw.html (from rev 244759, trunk/LayoutTests/http/tests/contentextensions/block-ping.html) (0 => 244794)


--- trunk/LayoutTests/http/tests/contentextensions/block-ping-resource-type-raw.html	                        (rev 0)
+++ trunk/LayoutTests/http/tests/contentextensions/block-ping-resource-type-raw.html	2019-04-30 19:42:34 UTC (rev 244794)
@@ -0,0 +1,62 @@
+<head>
+<script>
+if (window.testRunner && window.internals) {
+    testRunner.dumpAsText();
+    testRunner.dumpChildFramesAsText();
+    internals.settings.setHyperlinkAuditingEnabled(true);
+    testRunner.waitUntilDone();
+}
+
+function loadLinkWithPing() {
+    var iframe = document.getElementById("link_frame");
+    var iframeDoc = iframe.contentDocument || iframe.contentWindow.document;
+    iframeDoc.write('' +
+        '<img src="" ' +
+            '_onerror_="parent.clickOnLinkWithPing();">' +
+        '<a id="a" ' +
+            'href="" ' + // check-ping.html calls showPingResult()
+            'ping="resources/save-ping.php?test=contentextensions-block-ping-resource-type-raw"> ' +
+            'Link with ping' +
+        '</a>'
+        
+    );
+}
+
+function clickOnLinkWithPing() {
+    var iframe = document.getElementById("link_frame");
+    var iframeDoc = iframe.contentDocument;
+    if (window.eventSender) {
+        var a = iframeDoc.getElementById("a");
+        var x = iframe.offsetLeft + a.offsetLeft + 2;
+        var y = iframe.offsetTop + a.offsetTop + 2;
+        eventSender.mouseMoveTo(x, y);
+        eventSender.mouseDown();
+        eventSender.mouseUp();
+    }
+}
+
+function showPingResult() {
+    var iframe = document.getElementById("result_frame");
+    iframe._onload_ = function() {
+        fetch("resources/save-ping.php?test=contentextensions-block-ping-resource-type-raw").then(()=>{
+            fetch("resources/delete-ping.php?test=contentextensions-block-ping-resource-type-raw").then(()=>{
+                alert("FAIL: successfully loaded ping url with fetch");
+                if (window.testRunner) { testRunner.notifyDone(); }
+            })
+        }).catch(error => { alert("PASS:" + error); if (window.testRunner) { testRunner.notifyDone(); } });
+    }
+    iframe.src = ""
+    // Why timeout_ms=1000:
+    // To pass the test, the ping shouldn't arrive, so we need to
+    // timeout at some point. We don't have to wait too long because
+    // the console message can tell us whether the ping was blocked.
+}
+</script>
+</head>
+
+<body _onload_="loadLinkWithPing();">
+This test follows a link with a ping attribute where the ping URL matches a 'block' rule.
+<iframe id="link_frame" name="link_frame"><!-- Will contain link with ping --></iframe>
+<iframe id="result_frame" name="result_frame"><!-- Will contain ping data received by server --></iframe>
+</body>
+

Copied: trunk/LayoutTests/http/tests/contentextensions/block-ping-resource-type-raw.html.json (from rev 244759, trunk/LayoutTests/http/tests/contentextensions/block-ping.html.json) (0 => 244794)


--- trunk/LayoutTests/http/tests/contentextensions/block-ping-resource-type-raw.html.json	                        (rev 0)
+++ trunk/LayoutTests/http/tests/contentextensions/block-ping-resource-type-raw.html.json	2019-04-30 19:42:34 UTC (rev 244794)
@@ -0,0 +1,11 @@
+[
+    {
+        "trigger": {
+            "url-filter": "save-ping.php",
+            "resource-type": ["raw"]
+        },
+        "action": {
+            "type": "block"
+        }
+    }
+]

Modified: trunk/Source/WebCore/ChangeLog (244793 => 244794)


--- trunk/Source/WebCore/ChangeLog	2019-04-30 19:29:46 UTC (rev 244793)
+++ trunk/Source/WebCore/ChangeLog	2019-04-30 19:42:34 UTC (rev 244794)
@@ -1,3 +1,27 @@
+2019-04-30  Alex Christensen  <[email protected]>
+
+        Add WKContentRuleList ping resource-type
+        https://bugs.webkit.org/show_bug.cgi?id=197325
+        <rdar://problem/49841404>
+
+        Reviewed by Geoff Garen.
+
+        Tests: http/tests/contentextensions/block-ping-resource-type-ping.html and http/tests/contentextensions/block-ping-resource-type-raw.html
+
+        * contentextensions/ContentExtensionsBackend.cpp:
+        (WebCore::ContentExtensions::ContentExtensionsBackend::processContentRuleListsForLoad):
+        * contentextensions/ContentExtensionsBackend.h:
+        * loader/PingLoader.cpp:
+        (WebCore::processContentRuleListsForLoad):
+        (WebCore::PingLoader::sendPing):
+        * loader/ResourceLoadInfo.cpp:
+        (WebCore::ContentExtensions::readResourceType):
+        (WebCore::ContentExtensions::ResourceLoadInfo::getResourceFlags const):
+        * loader/ResourceLoadInfo.h:
+        * page/UserContentProvider.cpp:
+        (WebCore::UserContentProvider::processContentRuleListsForLoad):
+        * page/UserContentProvider.h:
+
 2019-04-30  Justin Fan  <[email protected]>
 
         [WebGPU] Move 'gpu' API entry point from DOMWindow to Navigator

Modified: trunk/Source/WebCore/contentextensions/ContentExtensionsBackend.cpp (244793 => 244794)


--- trunk/Source/WebCore/contentextensions/ContentExtensionsBackend.cpp	2019-04-30 19:29:46 UTC (rev 244793)
+++ trunk/Source/WebCore/contentextensions/ContentExtensionsBackend.cpp	2019-04-30 19:42:34 UTC (rev 244794)
@@ -150,7 +150,7 @@
     return contentExtension ? contentExtension->globalDisplayNoneStyleSheet() : nullptr;
 }
 
-ContentRuleListResults ContentExtensionsBackend::processContentRuleListsForLoad(const URL& url, ResourceType resourceType, DocumentLoader& initiatingDocumentLoader)
+ContentRuleListResults ContentExtensionsBackend::processContentRuleListsForLoad(const URL& url, OptionSet<ResourceType> resourceType, DocumentLoader& initiatingDocumentLoader)
 {
     if (m_contentExtensions.isEmpty())
         return { };

Modified: trunk/Source/WebCore/contentextensions/ContentExtensionsBackend.h (244793 => 244794)


--- trunk/Source/WebCore/contentextensions/ContentExtensionsBackend.h	2019-04-30 19:29:46 UTC (rev 244793)
+++ trunk/Source/WebCore/contentextensions/ContentExtensionsBackend.h	2019-04-30 19:42:34 UTC (rev 244794)
@@ -62,7 +62,7 @@
     WEBCORE_EXPORT Vector<ActionsFromContentRuleList> actionsForResourceLoad(const ResourceLoadInfo&) const;
     WEBCORE_EXPORT StyleSheetContents* globalDisplayNoneStyleSheet(const String& identifier) const;
 
-    ContentRuleListResults processContentRuleListsForLoad(const URL&, ResourceType, DocumentLoader& initiatingDocumentLoader);
+    ContentRuleListResults processContentRuleListsForLoad(const URL&, OptionSet<ResourceType>, DocumentLoader& initiatingDocumentLoader);
     WEBCORE_EXPORT ContentRuleListResults processContentRuleListsForPingLoad(const URL&, const URL& mainDocumentURL);
 
     static const String& displayNoneCSSRule();

Modified: trunk/Source/WebCore/loader/PingLoader.cpp (244793 => 244794)


--- trunk/Source/WebCore/loader/PingLoader.cpp	2019-04-30 19:29:46 UTC (rev 244793)
+++ trunk/Source/WebCore/loader/PingLoader.cpp	2019-04-30 19:42:34 UTC (rev 244794)
@@ -63,7 +63,7 @@
 #if ENABLE(CONTENT_EXTENSIONS)
 
 // Returns true if we should block the load.
-static bool processContentRuleListsForLoad(const Frame& frame, ResourceRequest& request, ContentExtensions::ResourceType resourceType)
+static bool processContentRuleListsForLoad(const Frame& frame, ResourceRequest& request, OptionSet<ContentExtensions::ResourceType> resourceType)
 {
     auto* documentLoader = frame.loader().documentLoader();
     if (!documentLoader)
@@ -119,7 +119,7 @@
 
     ResourceRequest request(pingURL);
 #if ENABLE(CONTENT_EXTENSIONS)
-    if (processContentRuleListsForLoad(frame, request, ContentExtensions::ResourceType::Raw))
+    if (processContentRuleListsForLoad(frame, request, { ContentExtensions::ResourceType::Raw, ContentExtensions::ResourceType::Ping }))
         return;
 #endif
 

Modified: trunk/Source/WebCore/loader/ResourceLoadInfo.cpp (244793 => 244794)


--- trunk/Source/WebCore/loader/ResourceLoadInfo.cpp	2019-04-30 19:29:46 UTC (rev 244793)
+++ trunk/Source/WebCore/loader/ResourceLoadInfo.cpp	2019-04-30 19:42:34 UTC (rev 244794)
@@ -102,6 +102,8 @@
         return static_cast<uint16_t>(ResourceType::Media);
     if (name == "popup")
         return static_cast<uint16_t>(ResourceType::Popup);
+    if (name == "ping")
+        return static_cast<uint16_t>(ResourceType::Ping);
     return static_cast<uint16_t>(ResourceType::Invalid);
 }
 
@@ -126,7 +128,7 @@
 {
     ResourceFlags flags = 0;
     ASSERT(type != ResourceType::Invalid);
-    flags |= static_cast<ResourceFlags>(type);
+    flags |= type.toRaw();
     flags |= isThirdParty() ? static_cast<ResourceFlags>(LoadType::ThirdParty) : static_cast<ResourceFlags>(LoadType::FirstParty);
     return flags;
 }

Modified: trunk/Source/WebCore/loader/ResourceLoadInfo.h (244793 => 244794)


--- trunk/Source/WebCore/loader/ResourceLoadInfo.h	2019-04-30 19:29:46 UTC (rev 244793)
+++ trunk/Source/WebCore/loader/ResourceLoadInfo.h	2019-04-30 19:42:34 UTC (rev 244794)
@@ -28,6 +28,7 @@
 #if ENABLE(CONTENT_EXTENSIONS)
 
 #include "CachedResource.h"
+#include <wtf/OptionSet.h>
 #include <wtf/URL.h>
 
 namespace WebCore {
@@ -45,8 +46,10 @@
     Media = 0x0080,
     PlugInStream = 0x0100,
     Popup = 0x0200,
+    // 0x0400 and 0x0800 are used by LoadType.
+    Ping = 0x1000,
 };
-const uint16_t ResourceTypeMask = 0x03FF;
+const uint16_t ResourceTypeMask = 0x13FF;
 
 enum class LoadType : uint16_t {
     Invalid = 0x0000,
@@ -55,6 +58,8 @@
 };
 const uint16_t LoadTypeMask = 0x0C00;
 
+static_assert(!(ResourceTypeMask & LoadTypeMask), "ResourceTypeMask and LoadTypeMask should be mutually exclusive because they are stored in the same uint16_t");
+
 typedef uint16_t ResourceFlags;
 
 // The first 32 bits of a uint64_t action are used for the action location.
@@ -74,7 +79,7 @@
 struct ResourceLoadInfo {
     URL resourceURL;
     URL mainDocumentURL;
-    ResourceType type;
+    OptionSet<ResourceType> type;
 
     bool isThirdParty() const;
     ResourceFlags getResourceFlags() const;

Modified: trunk/Source/WebCore/page/UserContentProvider.cpp (244793 => 244794)


--- trunk/Source/WebCore/page/UserContentProvider.cpp	2019-04-30 19:29:46 UTC (rev 244793)
+++ trunk/Source/WebCore/page/UserContentProvider.cpp	2019-04-30 19:42:34 UTC (rev 244794)
@@ -102,7 +102,7 @@
     return true;
 }
     
-ContentRuleListResults UserContentProvider::processContentRuleListsForLoad(const URL& url, ContentExtensions::ResourceType resourceType, DocumentLoader& initiatingDocumentLoader)
+ContentRuleListResults UserContentProvider::processContentRuleListsForLoad(const URL& url, OptionSet<ContentExtensions::ResourceType> resourceType, DocumentLoader& initiatingDocumentLoader)
 {
     if (!contentExtensionsEnabled(initiatingDocumentLoader))
         return { };

Modified: trunk/Source/WebCore/page/UserContentProvider.h (244793 => 244794)


--- trunk/Source/WebCore/page/UserContentProvider.h	2019-04-30 19:29:46 UTC (rev 244793)
+++ trunk/Source/WebCore/page/UserContentProvider.h	2019-04-30 19:42:34 UTC (rev 244794)
@@ -88,7 +88,7 @@
 #if ENABLE(CONTENT_EXTENSIONS)
     // FIXME: These don't really belong here. They should probably bundled up in the ContentExtensionsBackend
     // which should always exist.
-    ContentRuleListResults processContentRuleListsForLoad(const URL&, ContentExtensions::ResourceType, DocumentLoader& initiatingDocumentLoader);
+    ContentRuleListResults processContentRuleListsForLoad(const URL&, OptionSet<ContentExtensions::ResourceType>, DocumentLoader& initiatingDocumentLoader);
     Vector<ContentExtensions::ActionsFromContentRuleList> actionsForResourceLoad(const ContentExtensions::ResourceLoadInfo&, DocumentLoader& initiatingDocumentLoader);
     WEBCORE_EXPORT void forEachContentExtension(const Function<void(const String&, ContentExtensions::ContentExtension&)>&, DocumentLoader& initiatingDocumentLoader);
 #endif
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to