Title: [186807] trunk
Revision
186807
Author
commit-qu...@webkit.org
Date
2015-07-14 10:36:54 -0700 (Tue, 14 Jul 2015)

Log Message

[Content Extensions] Fix if-domain and unless-domain when loading main documents.
https://bugs.webkit.org/show_bug.cgi?id=146868

Patch by Alex Christensen <achristen...@webkit.org> on 2015-07-14
Reviewed by Benjamin Poulain.

Source/WebCore:

Tests: http/tests/contentextensions/block-everything-if-domain.html
       http/tests/contentextensions/block-everything-unless-domain-iframe.html
       http/tests/contentextensions/block-everything-unless-domain-redirect.php
       http/tests/contentextensions/block-everything-unless-domain.html

* contentextensions/ContentExtensionsBackend.cpp:
(WebCore::ContentExtensions::ContentExtensionsBackend::processContentExtensionRulesForLoad):
If we are loading a new main document, use that main document url as the main document url for domain comparison.

LayoutTests:

* http/tests/contentextensions/block-everything-if-domain-expected.txt: Added.
* http/tests/contentextensions/block-everything-if-domain.html: Added.
* http/tests/contentextensions/block-everything-if-domain.html.json: Added.
* http/tests/contentextensions/block-everything-unless-domain-expected.txt: Added.
* http/tests/contentextensions/block-everything-unless-domain-iframe-expected.txt: Added.
* http/tests/contentextensions/block-everything-unless-domain-iframe.html: Added.
* http/tests/contentextensions/block-everything-unless-domain-iframe.html.json: Added.
* http/tests/contentextensions/block-everything-unless-domain-redirect-expected.txt: Added.
* http/tests/contentextensions/block-everything-unless-domain-redirect.php: Added.
* http/tests/contentextensions/block-everything-unless-domain-redirect.php.json: Added.
* http/tests/contentextensions/block-everything-unless-domain.html: Added.
* http/tests/contentextensions/block-everything-unless-domain.html.json: Added.
* http/tests/contentextensions/main-resource-redirect-blocked-expected.txt:
* http/tests/contentextensions/resources/block-everything-unless-domain-helper.html: Added.
* http/tests/contentextensions/resources/should-load.html: Added.
* http/tests/contentextensions/resources/should-not-load.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (186806 => 186807)


--- trunk/LayoutTests/ChangeLog	2015-07-14 17:26:11 UTC (rev 186806)
+++ trunk/LayoutTests/ChangeLog	2015-07-14 17:36:54 UTC (rev 186807)
@@ -1,3 +1,27 @@
+2015-07-14  Alex Christensen  <achristen...@webkit.org>
+
+        [Content Extensions] Fix if-domain and unless-domain when loading main documents.
+        https://bugs.webkit.org/show_bug.cgi?id=146868
+
+        Reviewed by Benjamin Poulain.
+
+        * http/tests/contentextensions/block-everything-if-domain-expected.txt: Added.
+        * http/tests/contentextensions/block-everything-if-domain.html: Added.
+        * http/tests/contentextensions/block-everything-if-domain.html.json: Added.
+        * http/tests/contentextensions/block-everything-unless-domain-expected.txt: Added.
+        * http/tests/contentextensions/block-everything-unless-domain-iframe-expected.txt: Added.
+        * http/tests/contentextensions/block-everything-unless-domain-iframe.html: Added.
+        * http/tests/contentextensions/block-everything-unless-domain-iframe.html.json: Added.
+        * http/tests/contentextensions/block-everything-unless-domain-redirect-expected.txt: Added.
+        * http/tests/contentextensions/block-everything-unless-domain-redirect.php: Added.
+        * http/tests/contentextensions/block-everything-unless-domain-redirect.php.json: Added.
+        * http/tests/contentextensions/block-everything-unless-domain.html: Added.
+        * http/tests/contentextensions/block-everything-unless-domain.html.json: Added.
+        * http/tests/contentextensions/main-resource-redirect-blocked-expected.txt:
+        * http/tests/contentextensions/resources/block-everything-unless-domain-helper.html: Added.
+        * http/tests/contentextensions/resources/should-load.html: Added.
+        * http/tests/contentextensions/resources/should-not-load.html: Added.
+
 2015-07-05  Sam Weinig  <s...@webkit.org>
 
         DOM4: prepend, append, before, after & replace

Added: trunk/LayoutTests/http/tests/contentextensions/block-everything-if-domain-expected.txt (0 => 186807)


--- trunk/LayoutTests/http/tests/contentextensions/block-everything-if-domain-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/http/tests/contentextensions/block-everything-if-domain-expected.txt	2015-07-14 17:36:54 UTC (rev 186807)
@@ -0,0 +1,6 @@
+CONSOLE MESSAGE: Content blocker prevented frame displaying http://127.0.0.1:8000/contentextensions/block-everything-if-domain.html from loading a resource from http://127.0.0.1:8000/contentextensions/block-everything-if-domain.html
+layer at (0,0) size 800x600
+  RenderView at (0,0) size 800x600
+layer at (0,0) size 800x600
+  RenderBlock {HTML} at (0,0) size 800x600
+    RenderBody {BODY} at (8,8) size 784x584

Added: trunk/LayoutTests/http/tests/contentextensions/block-everything-if-domain.html (0 => 186807)


--- trunk/LayoutTests/http/tests/contentextensions/block-everything-if-domain.html	                        (rev 0)
+++ trunk/LayoutTests/http/tests/contentextensions/block-everything-if-domain.html	2015-07-14 17:36:54 UTC (rev 186807)
@@ -0,0 +1 @@
+about:blank should load instead of this.

Added: trunk/LayoutTests/http/tests/contentextensions/block-everything-if-domain.html.json (0 => 186807)


--- trunk/LayoutTests/http/tests/contentextensions/block-everything-if-domain.html.json	                        (rev 0)
+++ trunk/LayoutTests/http/tests/contentextensions/block-everything-if-domain.html.json	2015-07-14 17:36:54 UTC (rev 186807)
@@ -0,0 +1,11 @@
+[
+    {
+        "action": {
+            "type": "block"
+        },
+        "trigger": {
+            "url-filter": ".*",
+            "if-domain": ["127.0.0.1"]
+        }
+    }
+]

Added: trunk/LayoutTests/http/tests/contentextensions/block-everything-unless-domain-expected.txt (0 => 186807)


--- trunk/LayoutTests/http/tests/contentextensions/block-everything-unless-domain-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/http/tests/contentextensions/block-everything-unless-domain-expected.txt	2015-07-14 17:36:54 UTC (rev 186807)
@@ -0,0 +1,5 @@
+CONSOLE MESSAGE: line 18: http://127.0.0.1:8000/contentextensions/resources/block-everything-unless-domain-helper.html
+CONSOLE MESSAGE: line 5: helper loaded
+CONSOLE MESSAGE: line 7: Content blocker prevented frame displaying http://localhost:8000/contentextensions/resources/should-not-load.html from loading a resource from http://localhost:8000/contentextensions/resources/should-not-load.html
+CONSOLE MESSAGE: line 15: successfully blocked load from localhost
+

Added: trunk/LayoutTests/http/tests/contentextensions/block-everything-unless-domain-iframe-expected.txt (0 => 186807)


--- trunk/LayoutTests/http/tests/contentextensions/block-everything-unless-domain-iframe-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/http/tests/contentextensions/block-everything-unless-domain-iframe-expected.txt	2015-07-14 17:36:54 UTC (rev 186807)
@@ -0,0 +1,8 @@
+CONSOLE MESSAGE: line 15: The page loaded successfully.
+CONSOLE MESSAGE: line 3: This page should load.
+
+
+--------
+Frame: 'iframe'
+--------
+This page should load.

Added: trunk/LayoutTests/http/tests/contentextensions/block-everything-unless-domain-iframe.html (0 => 186807)


--- trunk/LayoutTests/http/tests/contentextensions/block-everything-unless-domain-iframe.html	                        (rev 0)
+++ trunk/LayoutTests/http/tests/contentextensions/block-everything-unless-domain-iframe.html	2015-07-14 17:36:54 UTC (rev 186807)
@@ -0,0 +1,23 @@
+<head>
+<script>
+if (window.testRunner) {
+	testRunner.dumpAsText();
+	testRunner.dumpChildFramesAsText();
+	testRunner.waitUntilDone();
+}
+function iframeLoaded()
+{
+	if (window.testRunner)
+		testRunner.notifyDone();
+}
+function bodyLoaded()
+{
+    console.log("The page loaded successfully.");
+    document.getElementById("iframe")._onload_ = iframeLoaded;
+	document.getElementById("iframe").src = ""
+}
+</script>
+</head>
+<body _onload_="bodyLoaded()">
+<iframe id="iframe"></iframe>
+</body>

Added: trunk/LayoutTests/http/tests/contentextensions/block-everything-unless-domain-iframe.html.json (0 => 186807)


--- trunk/LayoutTests/http/tests/contentextensions/block-everything-unless-domain-iframe.html.json	                        (rev 0)
+++ trunk/LayoutTests/http/tests/contentextensions/block-everything-unless-domain-iframe.html.json	2015-07-14 17:36:54 UTC (rev 186807)
@@ -0,0 +1,11 @@
+[
+    {
+        "action": {
+            "type": "block"
+        },
+        "trigger": {
+            "url-filter": ".*",
+            "unless-domain": ["127.0.0.1"]
+        }
+    }
+]

Added: trunk/LayoutTests/http/tests/contentextensions/block-everything-unless-domain-redirect-expected.txt (0 => 186807)


--- trunk/LayoutTests/http/tests/contentextensions/block-everything-unless-domain-redirect-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/http/tests/contentextensions/block-everything-unless-domain-redirect-expected.txt	2015-07-14 17:36:54 UTC (rev 186807)
@@ -0,0 +1 @@
+CONSOLE MESSAGE: Content blocker prevented frame displaying http://localhost/contentextensions/resources/should-not-load.html from loading a resource from http://localhost/contentextensions/resources/should-not-load.html

Added: trunk/LayoutTests/http/tests/contentextensions/block-everything-unless-domain-redirect.php (0 => 186807)


--- trunk/LayoutTests/http/tests/contentextensions/block-everything-unless-domain-redirect.php	                        (rev 0)
+++ trunk/LayoutTests/http/tests/contentextensions/block-everything-unless-domain-redirect.php	2015-07-14 17:36:54 UTC (rev 186807)
@@ -0,0 +1,4 @@
+<?php
+  header('Location: http://localhost/contentextensions/resources/should-not-load.html');
+  header('HTTP/1.0 302 Found');
+?>

Added: trunk/LayoutTests/http/tests/contentextensions/block-everything-unless-domain-redirect.php.json (0 => 186807)


--- trunk/LayoutTests/http/tests/contentextensions/block-everything-unless-domain-redirect.php.json	                        (rev 0)
+++ trunk/LayoutTests/http/tests/contentextensions/block-everything-unless-domain-redirect.php.json	2015-07-14 17:36:54 UTC (rev 186807)
@@ -0,0 +1,11 @@
+[
+    {
+        "action": {
+            "type": "block"
+        },
+        "trigger": {
+            "url-filter": ".*",
+            "unless-domain": ["127.0.0.1"]
+        }
+    }
+]

Added: trunk/LayoutTests/http/tests/contentextensions/block-everything-unless-domain.html (0 => 186807)


--- trunk/LayoutTests/http/tests/contentextensions/block-everything-unless-domain.html	                        (rev 0)
+++ trunk/LayoutTests/http/tests/contentextensions/block-everything-unless-domain.html	2015-07-14 17:36:54 UTC (rev 186807)
@@ -0,0 +1,31 @@
+<script>
+if (window.testRunner) {
+    testRunner.waitUntilDone();
+    testRunner.dumpAsText();
+    testRunner.setCanOpenWindows(true);
+    testRunner.setCloseRemainingWindowsWhenComplete(true);
+}
+
+var maxEventLoopRuns = 50;
+function helperLoaded () {
+    if (!maxEventLoopRuns) {
+        console.log("blocking load failed");
+        testRunner.notifyDone();
+    } else if (helper.location == "about:blank") {
+        console.log("successfully blocked load from localhost");
+        testRunner.notifyDone();
+    } else {
+        console.log(helper.location);
+        setTimeout(helperLoaded, 1);
+        maxEventLoopRuns--;
+    }
+}
+
+var helper = window.open("resources/block-everything-unless-domain-helper.html");
+if (helper)
+    helper.addEventListener('load', helperLoaded);
+else {
+    console.log("opening window failed");
+    testRunner.notifyDone();
+}
+</script>

Added: trunk/LayoutTests/http/tests/contentextensions/block-everything-unless-domain.html.json (0 => 186807)


--- trunk/LayoutTests/http/tests/contentextensions/block-everything-unless-domain.html.json	                        (rev 0)
+++ trunk/LayoutTests/http/tests/contentextensions/block-everything-unless-domain.html.json	2015-07-14 17:36:54 UTC (rev 186807)
@@ -0,0 +1,11 @@
+[
+    {
+        "action": {
+            "type": "block"
+        },
+        "trigger": {
+            "url-filter": ".*",
+            "unless-domain": ["127.0.0.1"]
+        }
+    }
+]

Modified: trunk/LayoutTests/http/tests/contentextensions/main-resource-redirect-blocked-expected.txt (186806 => 186807)


--- trunk/LayoutTests/http/tests/contentextensions/main-resource-redirect-blocked-expected.txt	2015-07-14 17:26:11 UTC (rev 186806)
+++ trunk/LayoutTests/http/tests/contentextensions/main-resource-redirect-blocked-expected.txt	2015-07-14 17:36:54 UTC (rev 186807)
@@ -1 +1 @@
-CONSOLE MESSAGE: Content blocker prevented frame displaying about:blank from loading a resource from http://127.0.0.1:8000/contentextensions/resources/main-resource-redirect-blocked-target.html
+CONSOLE MESSAGE: Content blocker prevented frame displaying http://127.0.0.1:8000/contentextensions/resources/main-resource-redirect-blocked-target.html from loading a resource from http://127.0.0.1:8000/contentextensions/resources/main-resource-redirect-blocked-target.html

Added: trunk/LayoutTests/http/tests/contentextensions/resources/block-everything-unless-domain-helper.html (0 => 186807)


--- trunk/LayoutTests/http/tests/contentextensions/resources/block-everything-unless-domain-helper.html	                        (rev 0)
+++ trunk/LayoutTests/http/tests/contentextensions/resources/block-everything-unless-domain-helper.html	2015-07-14 17:36:54 UTC (rev 186807)
@@ -0,0 +1,13 @@
+<head>
+<script>
+function bodyLoaded()
+{
+    console.log("helper loaded");
+    var anchor = document.getElementById("anchor");
+	anchor.click();
+}
+</script>
+</head>
+<body _onload_="bodyLoaded()">
+<a id="anchor" href="" this should take you to a document that doesn't load with the content extension.</a>
+</body>

Added: trunk/LayoutTests/http/tests/contentextensions/resources/should-load.html (0 => 186807)


--- trunk/LayoutTests/http/tests/contentextensions/resources/should-load.html	                        (rev 0)
+++ trunk/LayoutTests/http/tests/contentextensions/resources/should-load.html	2015-07-14 17:36:54 UTC (rev 186807)
@@ -0,0 +1,4 @@
+This page should load.
+<script>
+    console.log("This page should load.");
+</script>

Added: trunk/LayoutTests/http/tests/contentextensions/resources/should-not-load.html (0 => 186807)


--- trunk/LayoutTests/http/tests/contentextensions/resources/should-not-load.html	                        (rev 0)
+++ trunk/LayoutTests/http/tests/contentextensions/resources/should-not-load.html	2015-07-14 17:36:54 UTC (rev 186807)
@@ -0,0 +1,4 @@
+This page should not load.
+<script>
+    console.log("This page should not load.");
+</script>

Modified: trunk/Source/WebCore/ChangeLog (186806 => 186807)


--- trunk/Source/WebCore/ChangeLog	2015-07-14 17:26:11 UTC (rev 186806)
+++ trunk/Source/WebCore/ChangeLog	2015-07-14 17:36:54 UTC (rev 186807)
@@ -1,3 +1,19 @@
+2015-07-14  Alex Christensen  <achristen...@webkit.org>
+
+        [Content Extensions] Fix if-domain and unless-domain when loading main documents.
+        https://bugs.webkit.org/show_bug.cgi?id=146868
+
+        Reviewed by Benjamin Poulain.
+
+        Tests: http/tests/contentextensions/block-everything-if-domain.html
+               http/tests/contentextensions/block-everything-unless-domain-iframe.html
+               http/tests/contentextensions/block-everything-unless-domain-redirect.php
+               http/tests/contentextensions/block-everything-unless-domain.html
+
+        * contentextensions/ContentExtensionsBackend.cpp:
+        (WebCore::ContentExtensions::ContentExtensionsBackend::processContentExtensionRulesForLoad):
+        If we are loading a new main document, use that main document url as the main document url for domain comparison.
+
 2015-07-05  Sam Weinig  <s...@webkit.org>
 
         DOM4: prepend, append, before, after & replace

Modified: trunk/Source/WebCore/contentextensions/ContentExtensionsBackend.cpp (186806 => 186807)


--- trunk/Source/WebCore/contentextensions/ContentExtensionsBackend.cpp	2015-07-14 17:26:11 UTC (rev 186806)
+++ trunk/Source/WebCore/contentextensions/ContentExtensionsBackend.cpp	2015-07-14 17:36:54 UTC (rev 186807)
@@ -167,10 +167,14 @@
     Document* currentDocument = nullptr;
     URL mainDocumentURL;
 
-    if (initiatingDocumentLoader.frame()) {
-        currentDocument = initiatingDocumentLoader.frame()->document();
+    if (Frame* frame = initiatingDocumentLoader.frame()) {
+        currentDocument = frame->document();
 
-        if (Document* mainDocument = initiatingDocumentLoader.frame()->mainFrame().document())
+        if (initiatingDocumentLoader.isLoadingMainResource()
+            && frame->isMainFrame()
+            && resourceType == ResourceType::Document)
+            mainDocumentURL = request.url();
+        else if (Document* mainDocument = frame->mainFrame().document())
             mainDocumentURL = mainDocument->url();
     }
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to