Title: [182564] trunk
Revision
182564
Author
achristen...@apple.com
Date
2015-04-08 13:26:41 -0700 (Wed, 08 Apr 2015)

Log Message

Block popups from content extensions.
https://bugs.webkit.org/show_bug.cgi?id=143497

Reviewed by Brady Eidson.

Source/WebCore:

Test: http/tests/contentextensions/popups.html

* loader/ResourceLoadInfo.cpp:
(WebCore::readResourceType):
* loader/ResourceLoadInfo.h:
* page/DOMWindow.cpp:
(WebCore::DOMWindow::open):
* page/UserContentController.cpp:
(WebCore::UserContentController::actionsForResourceLoad):
* page/UserContentController.h:
Check content extensions before opening a window.

Tools:

* TestWebKitAPI/Tests/WebCore/ContentExtensions.cpp:
(TestWebKitAPI::TEST_F):
Added popup test.

LayoutTests:

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

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (182563 => 182564)


--- trunk/LayoutTests/ChangeLog	2015-04-08 20:24:40 UTC (rev 182563)
+++ trunk/LayoutTests/ChangeLog	2015-04-08 20:26:41 UTC (rev 182564)
@@ -1,3 +1,14 @@
+2015-04-08  Alex Christensen  <achristen...@webkit.org>
+
+        Block popups from content extensions.
+        https://bugs.webkit.org/show_bug.cgi?id=143497
+
+        Reviewed by Brady Eidson.
+
+        * http/tests/contentextensions/popups-expected.txt: Added.
+        * http/tests/contentextensions/popups.html: Added.
+        * http/tests/contentextensions/popups.html.json: Added.
+
 2015-04-08  Michael Catanzaro  <mcatanz...@igalia.com>
 
         [GTK] Unreviewed test expectation sanity-check

Added: trunk/LayoutTests/http/tests/contentextensions/popups-expected.txt (0 => 182564)


--- trunk/LayoutTests/http/tests/contentextensions/popups-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/http/tests/contentextensions/popups-expected.txt	2015-04-08 20:26:41 UTC (rev 182564)
@@ -0,0 +1,4 @@
+ALERT: about:blank successfully blocked
+ALERT: data url should not be blocked
+ALERT: data url should not be blocked
+

Added: trunk/LayoutTests/http/tests/contentextensions/popups.html (0 => 182564)


--- trunk/LayoutTests/http/tests/contentextensions/popups.html	                        (rev 0)
+++ trunk/LayoutTests/http/tests/contentextensions/popups.html	2015-04-08 20:26:41 UTC (rev 182564)
@@ -0,0 +1,18 @@
+<html> 
+<body>
+<script> 
+if (window.testRunner) {
+    testRunner.dumpAsText();
+    testRunner.setCanOpenWindows(true);
+    testRunner.setCloseRemainingWindowsWhenComplete(true);
+}
+
+win = window.open("about:blank");
+alert(win ? "FAIL" : "about:blank successfully blocked");
+win = window.open("data:text/html, hello");
+alert(win ? "data url should not be blocked" : "FAIL");
+win = window.open("data:text/html, about");
+alert(win ? "data url should not be blocked" : "FAIL");
+</script> 
+</body> 
+</html>

Added: trunk/LayoutTests/http/tests/contentextensions/popups.html.json (0 => 182564)


--- trunk/LayoutTests/http/tests/contentextensions/popups.html.json	                        (rev 0)
+++ trunk/LayoutTests/http/tests/contentextensions/popups.html.json	2015-04-08 20:26:41 UTC (rev 182564)
@@ -0,0 +1,11 @@
+[
+    {
+        "action": {
+            "type": "block"
+        },
+        "trigger": {
+            "url-filter": "about",
+            "resource-type":["popup"]
+        }
+    }
+]

Modified: trunk/Source/WebCore/ChangeLog (182563 => 182564)


--- trunk/Source/WebCore/ChangeLog	2015-04-08 20:24:40 UTC (rev 182563)
+++ trunk/Source/WebCore/ChangeLog	2015-04-08 20:26:41 UTC (rev 182564)
@@ -1,3 +1,22 @@
+2015-04-08  Alex Christensen  <achristen...@webkit.org>
+
+        Block popups from content extensions.
+        https://bugs.webkit.org/show_bug.cgi?id=143497
+
+        Reviewed by Brady Eidson.
+
+        Test: http/tests/contentextensions/popups.html
+
+        * loader/ResourceLoadInfo.cpp:
+        (WebCore::readResourceType):
+        * loader/ResourceLoadInfo.h:
+        * page/DOMWindow.cpp:
+        (WebCore::DOMWindow::open):
+        * page/UserContentController.cpp:
+        (WebCore::UserContentController::actionsForResourceLoad):
+        * page/UserContentController.h:
+        Check content extensions before opening a window.
+
 2015-04-08  Bem Jones-Bey  <bjone...@adobe.com>
 
         [CSS Shapes] Properly handle negative reference box widths and center coordinates

Modified: trunk/Source/WebCore/loader/ResourceLoadInfo.cpp (182563 => 182564)


--- trunk/Source/WebCore/loader/ResourceLoadInfo.cpp	2015-04-08 20:24:40 UTC (rev 182563)
+++ trunk/Source/WebCore/loader/ResourceLoadInfo.cpp	2015-04-08 20:26:41 UTC (rev 182564)
@@ -85,6 +85,8 @@
         return static_cast<uint16_t>(ResourceType::SVGDocument);
     if (name == "media")
         return static_cast<uint16_t>(ResourceType::Media);
+    if (name == "popup")
+        return static_cast<uint16_t>(ResourceType::Popup);
     return static_cast<uint16_t>(ResourceType::Invalid);
 }
 

Modified: trunk/Source/WebCore/loader/ResourceLoadInfo.h (182563 => 182564)


--- trunk/Source/WebCore/loader/ResourceLoadInfo.h	2015-04-08 20:24:40 UTC (rev 182563)
+++ trunk/Source/WebCore/loader/ResourceLoadInfo.h	2015-04-08 20:26:41 UTC (rev 182564)
@@ -42,12 +42,13 @@
     SVGDocument = 0x0040,
     Media = 0x0080,
     PlugInStream = 0x0100,
+    Popup = 0x0200,
 };
 
 enum class LoadType : uint16_t {
     Invalid = 0x0000,
-    FirstParty = 0x0200,
-    ThirdParty = 0x0400,
+    FirstParty = 0x0400,
+    ThirdParty = 0x0800,
 };
 
 typedef uint16_t ResourceFlags;

Modified: trunk/Source/WebCore/page/DOMWindow.cpp (182563 => 182564)


--- trunk/Source/WebCore/page/DOMWindow.cpp	2015-04-08 20:24:40 UTC (rev 182563)
+++ trunk/Source/WebCore/page/DOMWindow.cpp	2015-04-08 20:26:41 UTC (rev 182564)
@@ -35,6 +35,8 @@
 #include "CSSRuleList.h"
 #include "Chrome.h"
 #include "ChromeClient.h"
+#include "ContentExtensionActions.h"
+#include "ContentExtensionRule.h"
 #include "Crypto.h"
 #include "DOMApplicationCache.h"
 #include "DOMSelection.h"
@@ -81,6 +83,7 @@
 #include "PageTransitionEvent.h"
 #include "Performance.h"
 #include "PlatformScreen.h"
+#include "ResourceLoadInfo.h"
 #include "RuntimeEnabledFeatures.h"
 #include "ScheduledAction.h"
 #include "Screen.h"
@@ -2121,24 +2124,39 @@
     DOMWindow& activeWindow, DOMWindow& firstWindow)
 {
     if (!isCurrentlyDisplayedInFrame())
-        return 0;
+        return nullptr;
     Document* activeDocument = activeWindow.document();
     if (!activeDocument)
-        return 0;
+        return nullptr;
     Frame* firstFrame = firstWindow.frame();
     if (!firstFrame)
-        return 0;
+        return nullptr;
 
+#if ENABLE(CONTENT_EXTENSIONS)
+    if (firstFrame
+        && firstFrame->document()
+        && firstFrame->mainFrame().page()
+        && firstFrame->mainFrame().page()->userContentController()
+        && firstFrame->mainFrame().document()) {
+        ResourceLoadInfo resourceLoadInfo = {firstFrame->document()->completeURL(urlString), firstFrame->mainFrame().document()->url(), ResourceType::Popup};
+        Vector<ContentExtensions::Action> actions = firstFrame->mainFrame().page()->userContentController()->actionsForResourceLoad(resourceLoadInfo);
+        for (const ContentExtensions::Action& action : actions) {
+            if (action.type() == ContentExtensions::ActionType::BlockLoad)
+                return nullptr;
+        }
+    }
+#endif
+
     if (!firstWindow.allowPopUp()) {
         // Because FrameTree::find() returns true for empty strings, we must check for empty frame names.
         // Otherwise, illegitimate window.open() calls with no name will pass right through the popup blocker.
         if (frameName.isEmpty() || !m_frame->tree().find(frameName))
-            return 0;
+            return nullptr;
     }
 
     // Get the target frame for the special cases of _top and _parent.
     // In those cases, we schedule a location change right now and return early.
-    Frame* targetFrame = 0;
+    Frame* targetFrame = nullptr;
     if (frameName == "_top")
         targetFrame = &m_frame->tree().top();
     else if (frameName == "_parent") {
@@ -2149,7 +2167,7 @@
     }
     if (targetFrame) {
         if (!activeDocument->canNavigate(targetFrame))
-            return 0;
+            return nullptr;
 
         URL completedURL = firstFrame->document()->completeURL(urlString);
 
@@ -2169,7 +2187,7 @@
 
     WindowFeatures windowFeatures(windowFeaturesString);
     RefPtr<Frame> result = createWindow(urlString, frameName, windowFeatures, activeWindow, firstFrame, m_frame);
-    return result ? result->document()->domWindow() : 0;
+    return result ? result->document()->domWindow() : nullptr;
 }
 
 void DOMWindow::showModalDialog(const String& urlString, const String& dialogFeaturesString, DOMWindow& activeWindow, DOMWindow& firstWindow, std::function<void (DOMWindow&)> prepareDialogFunction)

Modified: trunk/Source/WebCore/page/UserContentController.cpp (182563 => 182564)


--- trunk/Source/WebCore/page/UserContentController.cpp	2015-04-08 20:24:40 UTC (rev 182563)
+++ trunk/Source/WebCore/page/UserContentController.cpp	2015-04-08 20:26:41 UTC (rev 182564)
@@ -212,6 +212,13 @@
     m_contentExtensionBackend->processContentExtensionRulesForLoad(request, resourceType, initiatingDocumentLoader);
 }
 
+Vector<ContentExtensions::Action> UserContentController::actionsForResourceLoad(const ResourceLoadInfo& resourceLoadInfo)
+{
+    if (!m_contentExtensionBackend)
+        return Vector<ContentExtensions::Action>();
+    
+    return m_contentExtensionBackend->actionsForResourceLoad(resourceLoadInfo);
+}
 #endif
 
 void UserContentController::removeAllUserContent()

Modified: trunk/Source/WebCore/page/UserContentController.h (182563 => 182564)


--- trunk/Source/WebCore/page/UserContentController.h	2015-04-08 20:24:40 UTC (rev 182563)
+++ trunk/Source/WebCore/page/UserContentController.h	2015-04-08 20:26:41 UTC (rev 182564)
@@ -93,6 +93,7 @@
     WEBCORE_EXPORT void removeAllUserContentExtensions();
 
     void processContentExtensionRulesForLoad(ResourceRequest&, ResourceType, DocumentLoader& initiatingDocumentLoader);
+    Vector<ContentExtensions::Action> actionsForResourceLoad(const ResourceLoadInfo&);
 #endif
 
 private:

Modified: trunk/Tools/ChangeLog (182563 => 182564)


--- trunk/Tools/ChangeLog	2015-04-08 20:24:40 UTC (rev 182563)
+++ trunk/Tools/ChangeLog	2015-04-08 20:26:41 UTC (rev 182564)
@@ -1,3 +1,14 @@
+2015-04-08  Alex Christensen  <achristen...@webkit.org>
+
+        Block popups from content extensions.
+        https://bugs.webkit.org/show_bug.cgi?id=143497
+
+        Reviewed by Brady Eidson.
+
+        * TestWebKitAPI/Tests/WebCore/ContentExtensions.cpp:
+        (TestWebKitAPI::TEST_F):
+        Added popup test.
+
 2015-04-08  Alex Christensen  <achristen...@webkit.org> and Patrick Gansterer  <par...@webkit.org>
 
         Add CMake build system for WinCairo port.

Modified: trunk/Tools/TestWebKitAPI/Tests/WebCore/ContentExtensions.cpp (182563 => 182564)


--- trunk/Tools/TestWebKitAPI/Tests/WebCore/ContentExtensions.cpp	2015-04-08 20:24:40 UTC (rev 182563)
+++ trunk/Tools/TestWebKitAPI/Tests/WebCore/ContentExtensions.cpp	2015-04-08 20:26:41 UTC (rev 182564)
@@ -457,7 +457,7 @@
 
 TEST_F(ContentExtensionTest, ResourceType)
 {
-    auto backend = makeBackend("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"block_all_types.org\",\"resource-type\":[\"document\",\"image\",\"style-sheet\",\"script\",\"font\",\"raw\",\"svg-document\",\"media\"]}},"
+    auto backend = makeBackend("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"block_all_types.org\",\"resource-type\":[\"document\",\"image\",\"style-sheet\",\"script\",\"font\",\"raw\",\"svg-document\",\"media\",\"popup\"]}},"
         "{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"block_only_images\",\"resource-type\":[\"image\"]}}]");
 
     testRequest(backend, mainDocumentRequest("http://block_all_types.org", ResourceType::Document), { ContentExtensions::ActionType::BlockLoad });
@@ -468,6 +468,7 @@
     testRequest(backend, mainDocumentRequest("http://block_all_types.org", ResourceType::Raw), { ContentExtensions::ActionType::BlockLoad });
     testRequest(backend, mainDocumentRequest("http://block_all_types.org", ResourceType::SVGDocument), { ContentExtensions::ActionType::BlockLoad });
     testRequest(backend, mainDocumentRequest("http://block_all_types.org", ResourceType::Media), { ContentExtensions::ActionType::BlockLoad });
+    testRequest(backend, mainDocumentRequest("http://block_all_types.org", ResourceType::Popup), { ContentExtensions::ActionType::BlockLoad });
     testRequest(backend, mainDocumentRequest("http://block_only_images.org", ResourceType::Image), { ContentExtensions::ActionType::BlockLoad });
     testRequest(backend, mainDocumentRequest("http://block_only_images.org", ResourceType::Document), { });
 }
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to