Apply ContentExtension actions after redirects.
authorbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 26 Mar 2015 17:45:12 +0000 (17:45 +0000)
committerbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 26 Mar 2015 17:45:12 +0000 (17:45 +0000)
<rdar://problem/20062613> and https://bugs.webkit.org/show_bug.cgi?id=143055

Reviewed by Alex Christensen.

Source/WebCore:

Tests: http/tests/contentextensions/loading/main-resource-redirect-blocked.php
       http/tests/contentextensions/subresource-redirect-blocked.html

This patch moves the "run a URL against the content extension" code from CachedResourceLoader to
the ContentExtensionsBackend.

That allows it to be shared between the CachedResourceLoader where loads are initiated and
ResourceLoader where redirects are handled.

* contentextensions/ContentExtension.cpp:
(WebCore::ContentExtensions::ContentExtension::globalDisplayNoneStyleSheet):

* contentextensions/ContentExtensionsBackend.cpp:
(WebCore::ContentExtensions::ContentExtensionsBackend::processContentExtensionRulesForLoad):
(WebCore::ContentExtensions::ContentExtensionsBackend::displayNoneCSSRule):
* contentextensions/ContentExtensionsBackend.h:

* loader/NetscapePlugInStreamLoader.cpp:
(WebCore::NetscapePlugInStreamLoader::NetscapePlugInStreamLoader):

* loader/ResourceLoadInfo.h:

* loader/ResourceLoader.cpp:
(WebCore::ResourceLoader::ResourceLoader):
(WebCore::ResourceLoader::willSendRequest):
* loader/ResourceLoader.h:

* loader/SubresourceLoader.cpp:
(WebCore::SubresourceLoader::SubresourceLoader):

* loader/cache/CachedResourceLoader.cpp:
(WebCore::CachedResourceLoader::requestResource):

* page/UserContentController.cpp:
(WebCore::UserContentController::processContentExtensionRulesForLoad):
(WebCore::UserContentController::actionsForResourceLoad): Deleted.
(WebCore::UserContentController::globalDisplayNoneStyleSheet): Deleted.
(WebCore::UserContentController::displayNoneCSSRule): Deleted.
* page/UserContentController.h:

Tools:

* WebKitTestRunner/InjectedBundle/InjectedBundlePage.cpp:
(WTR::InjectedBundlePage::didFailProvisionalLoadWithErrorForFrame): Dump the fact that the load error is kWKErrorCodeCannotShowURL
  which is specifically interesting to a new test.

LayoutTests:

* http/tests/contentextensions/loading/main-resource-redirect-blocked-expected.txt: Added.
* http/tests/contentextensions/loading/main-resource-redirect-blocked.php: Added.
* http/tests/contentextensions/loading/main-resource-redirect-blocked.php.json: Added.
* http/tests/contentextensions/loading/resources/main-resource-redirect-blocked-target.html: Added.
* http/tests/contentextensions/resources/subresource-redirect.php: Added.
* http/tests/contentextensions/subresource-redirect-blocked-expected.txt: Added.
* http/tests/contentextensions/subresource-redirect-blocked.html: Added.
* http/tests/contentextensions/subresource-redirect-blocked.html.json: Added.

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

23 files changed:
LayoutTests/ChangeLog
LayoutTests/http/tests/contentextensions/loading/main-resource-redirect-blocked-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/contentextensions/loading/main-resource-redirect-blocked.php [new file with mode: 0644]
LayoutTests/http/tests/contentextensions/loading/main-resource-redirect-blocked.php.json [new file with mode: 0644]
LayoutTests/http/tests/contentextensions/loading/resources/main-resource-redirect-blocked-target.html [new file with mode: 0644]
LayoutTests/http/tests/contentextensions/resources/subresource-redirect.php [new file with mode: 0644]
LayoutTests/http/tests/contentextensions/subresource-redirect-blocked-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/contentextensions/subresource-redirect-blocked.html [new file with mode: 0644]
LayoutTests/http/tests/contentextensions/subresource-redirect-blocked.html.json [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/contentextensions/ContentExtension.cpp
Source/WebCore/contentextensions/ContentExtensionsBackend.cpp
Source/WebCore/contentextensions/ContentExtensionsBackend.h
Source/WebCore/loader/NetscapePlugInStreamLoader.cpp
Source/WebCore/loader/ResourceLoadInfo.h
Source/WebCore/loader/ResourceLoader.cpp
Source/WebCore/loader/ResourceLoader.h
Source/WebCore/loader/SubresourceLoader.cpp
Source/WebCore/loader/cache/CachedResourceLoader.cpp
Source/WebCore/page/UserContentController.cpp
Source/WebCore/page/UserContentController.h
Tools/ChangeLog
Tools/WebKitTestRunner/InjectedBundle/InjectedBundlePage.cpp

index 3f494e5..b28fda1 100644 (file)
@@ -1,3 +1,19 @@
+2015-03-26  Brady Eidson  <beidson@apple.com>
+
+        Apply ContentExtension actions after redirects.
+        <rdar://problem/20062613> and https://bugs.webkit.org/show_bug.cgi?id=143055
+
+        Reviewed by Alex Christensen.
+
+        * http/tests/contentextensions/loading/main-resource-redirect-blocked-expected.txt: Added.
+        * http/tests/contentextensions/loading/main-resource-redirect-blocked.php: Added.
+        * http/tests/contentextensions/loading/main-resource-redirect-blocked.php.json: Added.
+        * http/tests/contentextensions/loading/resources/main-resource-redirect-blocked-target.html: Added.
+        * http/tests/contentextensions/resources/subresource-redirect.php: Added.
+        * http/tests/contentextensions/subresource-redirect-blocked-expected.txt: Added.
+        * http/tests/contentextensions/subresource-redirect-blocked.html: Added.
+        * http/tests/contentextensions/subresource-redirect-blocked.html.json: Added.
+
 2015-03-26  Michael Saboff  <msaboff@apple.com>
 
         js/promises-tests/promises-tests-2-3-3.html sometimes crashes under DFG::SpeculativeJIT::compile
diff --git a/LayoutTests/http/tests/contentextensions/loading/main-resource-redirect-blocked-expected.txt b/LayoutTests/http/tests/contentextensions/loading/main-resource-redirect-blocked-expected.txt
new file mode 100644 (file)
index 0000000..0a6a792
--- /dev/null
@@ -0,0 +1,3 @@
+main frame - didStartProvisionalLoadForFrame
+main frame - didFailProvisionalLoadWithError
+main frame - (kWKErrorCodeCannotShowURL)
diff --git a/LayoutTests/http/tests/contentextensions/loading/main-resource-redirect-blocked.php b/LayoutTests/http/tests/contentextensions/loading/main-resource-redirect-blocked.php
new file mode 100644 (file)
index 0000000..9784e66
--- /dev/null
@@ -0,0 +1,4 @@
+<?php
+  header('Location: resources/main-resource-redirect-blocked-target.html');
+  header('HTTP/1.0 302 Found');
+?>
diff --git a/LayoutTests/http/tests/contentextensions/loading/main-resource-redirect-blocked.php.json b/LayoutTests/http/tests/contentextensions/loading/main-resource-redirect-blocked.php.json
new file mode 100644 (file)
index 0000000..1283e7e
--- /dev/null
@@ -0,0 +1,10 @@
+[
+    {
+        "action": {
+            "type": "block"
+        },
+        "trigger": {
+            "url-filter": ".*main-resource-redirect-blocked-target.html"
+        }
+    }
+]
diff --git a/LayoutTests/http/tests/contentextensions/loading/resources/main-resource-redirect-blocked-target.html b/LayoutTests/http/tests/contentextensions/loading/resources/main-resource-redirect-blocked-target.html
new file mode 100644 (file)
index 0000000..7f7a891
--- /dev/null
@@ -0,0 +1 @@
+This page should never actually load.
\ No newline at end of file
diff --git a/LayoutTests/http/tests/contentextensions/resources/subresource-redirect.php b/LayoutTests/http/tests/contentextensions/resources/subresource-redirect.php
new file mode 100644 (file)
index 0000000..9b4035f
--- /dev/null
@@ -0,0 +1,4 @@
+<?php
+  header('Location: http://127.0.0.1:8000/resources/square128.png');
+  header('HTTP/1.0 302 Found');
+?>
diff --git a/LayoutTests/http/tests/contentextensions/subresource-redirect-blocked-expected.txt b/LayoutTests/http/tests/contentextensions/subresource-redirect-blocked-expected.txt
new file mode 100644 (file)
index 0000000..995b5c9
--- /dev/null
@@ -0,0 +1,13 @@
+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
+      RenderText {#text} at (0,0) size 155x18
+        text run at (0,0) width 155: "This page has an image."
+      RenderBR {BR} at (154,14) size 1x0
+      RenderText {#text} at (0,18) size 415x18
+        text run at (0,18) width 415: "The image load should be blocked by the content extension filter"
+      RenderBR {BR} at (414,32) size 1x0
+      RenderImage {IMG} at (0,36) size 20x20
+      RenderText {#text} at (0,0) size 0x0
diff --git a/LayoutTests/http/tests/contentextensions/subresource-redirect-blocked.html b/LayoutTests/http/tests/contentextensions/subresource-redirect-blocked.html
new file mode 100644 (file)
index 0000000..81e8094
--- /dev/null
@@ -0,0 +1,3 @@
+This page has an image.<br>
+The image load should be blocked by the content extension filter<br>
+<img src="resources/subresource-redirect.php">
diff --git a/LayoutTests/http/tests/contentextensions/subresource-redirect-blocked.html.json b/LayoutTests/http/tests/contentextensions/subresource-redirect-blocked.html.json
new file mode 100644 (file)
index 0000000..8549148
--- /dev/null
@@ -0,0 +1,10 @@
+[
+    {
+        "action": {
+            "type": "block"
+        },
+        "trigger": {
+            "url-filter": ".*square"
+        }
+    }
+]
index 4e2a7ef..2b00b0f 100644 (file)
@@ -1,3 +1,50 @@
+2015-03-26  Brady Eidson  <beidson@apple.com>
+
+        Apply ContentExtension actions after redirects.
+        <rdar://problem/20062613> and https://bugs.webkit.org/show_bug.cgi?id=143055
+
+        Reviewed by Alex Christensen.
+
+        Tests: http/tests/contentextensions/loading/main-resource-redirect-blocked.php
+               http/tests/contentextensions/subresource-redirect-blocked.html
+
+        This patch moves the "run a URL against the content extension" code from CachedResourceLoader to
+        the ContentExtensionsBackend.
+
+        That allows it to be shared between the CachedResourceLoader where loads are initiated and 
+        ResourceLoader where redirects are handled.
+
+        * contentextensions/ContentExtension.cpp:
+        (WebCore::ContentExtensions::ContentExtension::globalDisplayNoneStyleSheet):
+
+        * contentextensions/ContentExtensionsBackend.cpp:
+        (WebCore::ContentExtensions::ContentExtensionsBackend::processContentExtensionRulesForLoad):
+        (WebCore::ContentExtensions::ContentExtensionsBackend::displayNoneCSSRule):
+        * contentextensions/ContentExtensionsBackend.h:
+
+        * loader/NetscapePlugInStreamLoader.cpp:
+        (WebCore::NetscapePlugInStreamLoader::NetscapePlugInStreamLoader):
+
+        * loader/ResourceLoadInfo.h:
+
+        * loader/ResourceLoader.cpp:
+        (WebCore::ResourceLoader::ResourceLoader):
+        (WebCore::ResourceLoader::willSendRequest):
+        * loader/ResourceLoader.h:
+
+        * loader/SubresourceLoader.cpp:
+        (WebCore::SubresourceLoader::SubresourceLoader):
+
+        * loader/cache/CachedResourceLoader.cpp:
+        (WebCore::CachedResourceLoader::requestResource):
+
+        * page/UserContentController.cpp:
+        (WebCore::UserContentController::processContentExtensionRulesForLoad):
+        (WebCore::UserContentController::actionsForResourceLoad): Deleted.
+        (WebCore::UserContentController::globalDisplayNoneStyleSheet): Deleted.
+        (WebCore::UserContentController::displayNoneCSSRule): Deleted.
+        * page/UserContentController.h:
+
 2015-03-26  Myles C. Maxfield  <mmaxfield@apple.com>
 
         Crash when laying out (char)0
index 7c3b966..a78ac03 100644 (file)
@@ -27,8 +27,8 @@
 #include "ContentExtension.h"
 
 #include "CompiledContentExtension.h"
+#include "ContentExtensionsBackend.h"
 #include "StyleSheetContents.h"
-#include "UserContentController.h"
 #include <wtf/text/StringBuilder.h>
 
 #if ENABLE(CONTENT_EXTENSIONS)
@@ -62,7 +62,7 @@ StyleSheetContents* ContentExtension::globalDisplayNoneStyleSheet()
     StringBuilder css;
     for (auto& selector : selectors) {
         css.append(selector);
-        css.append(UserContentController::displayNoneCSSRule());
+        css.append(ContentExtensionsBackend::displayNoneCSSRule());
     }
 
     m_globalDisplayNoneStyleSheet = StyleSheetContents::create();
index 377388a..470ba67 100644 (file)
 #include "CompiledContentExtension.h"
 #include "ContentExtension.h"
 #include "DFABytecodeInterpreter.h"
+#include "Document.h"
+#include "DocumentLoader.h"
+#include "Frame.h"
+#include "MainFrame.h"
 #include "ResourceLoadInfo.h"
 #include "URL.h"
+#include "UserContentController.h"
+#include <wtf/NeverDestroyed.h>
 #include <wtf/text/CString.h>
 
 namespace WebCore {
@@ -110,6 +116,73 @@ StyleSheetContents* ContentExtensionsBackend::globalDisplayNoneStyleSheet(const
     return contentExtension ? contentExtension->globalDisplayNoneStyleSheet() : nullptr;
 }
 
+void ContentExtensionsBackend::processContentExtensionRulesForLoad(ResourceRequest& request, ResourceType resourceType, DocumentLoader& initiatingDocumentLoader)
+{
+    Document* currentDocument = nullptr;
+    URL mainDocumentURL;
+
+    if (initiatingDocumentLoader.frame()) {
+        currentDocument = initiatingDocumentLoader.frame()->document();
+
+        if (Document* mainDocument = initiatingDocumentLoader.frame()->mainFrame().document())
+            mainDocumentURL = mainDocument->url();
+    }
+
+    ResourceLoadInfo resourceLoadInfo = { request.url(), mainDocumentURL, resourceType };
+    Vector<ContentExtensions::Action> actions = actionsForResourceLoad(resourceLoadInfo);
+
+    StringBuilder css;
+    bool willBlockLoad = false;
+    for (const auto& action : actions) {
+        switch (action.type()) {
+        case ContentExtensions::ActionType::BlockLoad:
+            willBlockLoad = true;
+            break;
+        case ContentExtensions::ActionType::BlockCookies:
+            request.setAllowCookies(false);
+            break;
+        case ContentExtensions::ActionType::CSSDisplayNoneSelector:
+            css.append(action.stringArgument());
+            css.append(displayNoneCSSRule());
+            break;
+        case ContentExtensions::ActionType::CSSDisplayNoneStyleSheet: {
+            StyleSheetContents* styleSheetContents = globalDisplayNoneStyleSheet(action.stringArgument());
+            if (styleSheetContents) {
+                if (resourceType == ResourceType::Document)
+                    initiatingDocumentLoader.addPendingContentExtensionSheet(action.stringArgument(), *styleSheetContents);
+                else if (currentDocument)
+                    currentDocument->styleSheetCollection().maybeAddContentExtensionSheet(action.stringArgument(), *styleSheetContents);
+            }
+            break;
+        }
+        case ContentExtensions::ActionType::IgnorePreviousRules:
+        case ContentExtensions::ActionType::InvalidAction:
+            RELEASE_ASSERT_NOT_REACHED();
+        }
+    }
+
+    if (css.length()) {
+        Ref<StyleSheetContents> styleSheet = StyleSheetContents::create();
+        styleSheet->setIsUserStyleSheet(true);
+
+        if (styleSheet->parseString(css.toString())) {
+            if (resourceType == ResourceType::Document)
+                initiatingDocumentLoader.addPendingContentExtensionSheet(styleSheet);
+            else if (currentDocument)
+                currentDocument->styleSheetCollection().addUserSheet(WTF::move(styleSheet));
+        }
+    }
+
+    if (willBlockLoad)
+        request = ResourceRequest();
+}
+
+const String& ContentExtensionsBackend::displayNoneCSSRule()
+{
+    static NeverDestroyed<const String> rule(ASCIILiteral("{display:none !important;}\n"));
+    return rule;
+}
+
 } // namespace ContentExtensions
 
 } // namespace WebCore
index 711ba0c..0202729 100644 (file)
@@ -36,6 +36,8 @@
 
 namespace WebCore {
 
+class DocumentLoader;
+class ResourceRequest;
 class URL;
 
 struct ResourceLoadInfo;
@@ -63,6 +65,10 @@ public:
     WEBCORE_EXPORT Vector<Action> actionsForResourceLoad(const ResourceLoadInfo&) const;
     StyleSheetContents* globalDisplayNoneStyleSheet(const String& identifier) const;
 
+    void processContentExtensionRulesForLoad(ResourceRequest&, ResourceType, DocumentLoader& initiatingDocumentLoader);
+
+    static const String& displayNoneCSSRule();
+
 private:
     HashMap<String, RefPtr<ContentExtension>> m_contentExtensions;
 };
index 42a3390..ee1a62f 100644 (file)
 #include "FrameLoaderClient.h"
 #include <wtf/Ref.h>
 
+#if ENABLE(CONTENT_EXTENSIONS)
+#include "ResourceLoadInfo.h"
+#endif
+
 namespace WebCore {
 
 NetscapePlugInStreamLoader::NetscapePlugInStreamLoader(Frame* frame, NetscapePlugInStreamLoaderClient* client)
     : ResourceLoader(frame, ResourceLoaderOptions(SendCallbacks, SniffContent, DoNotBufferData, AllowStoredCredentials, AskClientForAllCredentials, SkipSecurityCheck, UseDefaultOriginRestrictionsForType, DoNotIncludeCertificateInfo))
     , m_client(client)
 {
+#if ENABLE(CONTENT_EXTENSIONS)
+    m_resourceType = ResourceType::PlugInStream;
+#endif
 }
 
 NetscapePlugInStreamLoader::~NetscapePlugInStreamLoader()
index ab41c63..0d3f955 100644 (file)
@@ -41,12 +41,13 @@ enum class ResourceType : uint16_t {
     Raw = 0x0020,
     SVGDocument = 0x0040,
     Media = 0x0080,
+    PlugInStream = 0x0100,
 };
 
 enum class LoadType : uint16_t {
     Invalid = 0x0000,
-    FirstParty = 0x0100,
-    ThirdParty = 0x0200,
+    FirstParty = 0x0200,
+    ThirdParty = 0x0400,
 };
 
 typedef uint16_t ResourceFlags;
index 334e960..f5daf99 100644 (file)
 #include "SharedBuffer.h"
 #include <wtf/Ref.h>
 
+#if ENABLE(CONTENT_EXTENSIONS)
+#include "ResourceLoadInfo.h"
+#include "UserContentController.h"
+#endif
+
 namespace WebCore {
 
 ResourceLoader::ResourceLoader(Frame* frame, ResourceLoaderOptions options)
@@ -64,6 +69,9 @@ ResourceLoader::ResourceLoader(Frame* frame, ResourceLoaderOptions options)
     , m_defersLoading(frame->page()->defersLoading())
     , m_options(options)
     , m_isQuickLookResource(false)
+#if ENABLE(CONTENT_EXTENSIONS)
+    , m_resourceType(ResourceType::Invalid)
+#endif
 {
 }
 
@@ -267,7 +275,19 @@ void ResourceLoader::willSendRequest(ResourceRequest& request, const ResourceRes
     Ref<ResourceLoader> protect(*this);
 
     ASSERT(!m_reachedTerminalState);
-    
+
+#if ENABLE(CONTENT_EXTENSIONS)
+    ASSERT(m_resourceType != ResourceType::Invalid);
+
+    if (frameLoader() && frameLoader()->frame().page() && frameLoader()->frame().page()->userContentController() && m_documentLoader)
+        frameLoader()->frame().page()->userContentController()->processContentExtensionRulesForLoad(request, m_resourceType, *m_documentLoader);
+
+    if (request.isNull()) {
+        didFail(cannotShowURLError());
+        return;
+    }
+#endif
+
     // We need a resource identifier for all requests, even if FrameLoader is never going to see it (such as with CORS preflight requests).
     bool createdResourceIdentifier = false;
     if (!m_identifier) {
index 50b2617..00ed6fe 100644 (file)
@@ -52,6 +52,10 @@ class URL;
 class QuickLookHandle;
 #endif
 
+#if ENABLE(CONTENT_EXTENSIONS)
+enum class ResourceType : uint16_t;
+#endif
+
 class ResourceLoader : public RefCounted<ResourceLoader>, protected ResourceHandleClient {
 public:
     virtual ~ResourceLoader() = 0;
@@ -224,6 +228,11 @@ private:
     ResourceRequest m_deferredRequest;
     ResourceLoaderOptions m_options;
     bool m_isQuickLookResource;
+
+#if ENABLE(CONTENT_EXTENSIONS)
+protected:
+    ResourceType m_resourceType;
+#endif
 };
 
 inline const ResourceResponse& ResourceLoader::response() const
index 1c36f16..b726c94 100644 (file)
 #include <RuntimeApplicationChecksIOS.h>
 #endif
 
+#if ENABLE(CONTENT_EXTENSIONS)
+#include "ResourceLoadInfo.h"
+#endif
+
 namespace WebCore {
 
 DEFINE_DEBUG_ONLY_GLOBAL(WTF::RefCountedLeakCounter, subresourceLoaderCounter, ("SubresourceLoader"));
@@ -76,6 +80,9 @@ SubresourceLoader::SubresourceLoader(Frame* frame, CachedResource* resource, con
 #ifndef NDEBUG
     subresourceLoaderCounter.increment();
 #endif
+#if ENABLE(CONTENT_EXTENSIONS)
+    m_resourceType = toResourceType(resource->type());
+#endif
 }
 
 SubresourceLoader::~SubresourceLoader()
index f5078cd..f3c2af0 100644 (file)
@@ -508,63 +508,10 @@ CachedResourceHandle<CachedResource> CachedResourceLoader::requestResource(Cache
         return nullptr;
 
 #if ENABLE(CONTENT_EXTENSIONS)
-    URL mainDocumentURL;
-    if (frame() && frame()->mainFrame().document())
-        mainDocumentURL = frame()->mainFrame().document()->url();
-
-    ResourceLoadInfo resourceLoadInfo = { url, mainDocumentURL, toResourceType(type) };
-
-    Vector<ContentExtensions::Action> actions;
-    UserContentController* userContentController = nullptr;
-    if (frame() && frame()->mainFrame().page())
-        userContentController = frame()->mainFrame().page()->userContentController();
-
-    if (userContentController)
-        actions = userContentController->actionsForResourceLoad(resourceLoadInfo);
-
-    StringBuilder css;
-    bool willBlockLoad = false;
-    for (const auto& action : actions) {
-        switch (action.type()) {
-        case ContentExtensions::ActionType::BlockLoad:
-            willBlockLoad = true;
-            break;
-        case ContentExtensions::ActionType::BlockCookies:
-            request.mutableResourceRequest().setAllowCookies(false);
-            break;
-        case ContentExtensions::ActionType::CSSDisplayNoneSelector:
-            css.append(action.stringArgument());
-            css.append(UserContentController::displayNoneCSSRule());
-            break;
-        case ContentExtensions::ActionType::CSSDisplayNoneStyleSheet: {
-            StyleSheetContents* styleSheetContents = userContentController->globalDisplayNoneStyleSheet(action.stringArgument());
-            if (styleSheetContents) {
-                if (type == CachedResource::MainResource && request.initiatingDocumentLoader())
-                    request.initiatingDocumentLoader()->addPendingContentExtensionSheet(action.stringArgument(), *styleSheetContents);
-                else if (m_document)
-                    m_document->styleSheetCollection().maybeAddContentExtensionSheet(action.stringArgument(), *styleSheetContents);
-            }
-            break;
-        }
-        case ContentExtensions::ActionType::IgnorePreviousRules:
-        case ContentExtensions::ActionType::InvalidAction:
-            RELEASE_ASSERT_NOT_REACHED();
-        }
-    }
-
-    if (css.length()) {
-        Ref<StyleSheetContents> styleSheet = StyleSheetContents::create();
-        styleSheet->setIsUserStyleSheet(true);
-
-        if (styleSheet->parseString(css.toString())) {
-            if (type == CachedResource::MainResource && request.initiatingDocumentLoader())
-                request.initiatingDocumentLoader()->addPendingContentExtensionSheet(styleSheet);
-            else if (m_document)
-                m_document->styleSheetCollection().addUserSheet(WTF::move(styleSheet));
-        }
-    }
+    if (frame() && frame()->mainFrame().page() && frame()->mainFrame().page()->userContentController() && m_documentLoader)
+        frame()->mainFrame().page()->userContentController()->processContentExtensionRulesForLoad(request.mutableResourceRequest(), toResourceType(type), *m_documentLoader);
 
-    if (willBlockLoad)
+    if (request.mutableResourceRequest().isNull())
         return nullptr;
 #endif
 
index e40cca9..9cadedb 100644 (file)
@@ -33,7 +33,6 @@
 #include "ResourceLoadInfo.h"
 #include "UserScript.h"
 #include "UserStyleSheet.h"
-#include <wtf/NeverDestroyed.h>
 
 #if ENABLE(USER_MESSAGE_HANDLERS)
 #include "UserMessageHandlerDescriptor.h"
@@ -205,26 +204,12 @@ void UserContentController::removeAllUserContentExtensions()
     m_contentExtensionBackend->removeAllContentExtensions();
 }
 
-Vector<ContentExtensions::Action> UserContentController::actionsForResourceLoad(const ResourceLoadInfo& resourceLoadInfo)
+void UserContentController::processContentExtensionRulesForLoad(ResourceRequest& request, ResourceType resourceType, DocumentLoader& initiatingDocumentLoader)
 {
     if (!m_contentExtensionBackend)
-        return Vector<ContentExtensions::Action>();
-
-    return m_contentExtensionBackend->actionsForResourceLoad(resourceLoadInfo);
-}
-
-StyleSheetContents* UserContentController::globalDisplayNoneStyleSheet(const String& identifier) const
-{
-    if (!m_contentExtensionBackend)
-        return nullptr;
-
-    return m_contentExtensionBackend->globalDisplayNoneStyleSheet(identifier);
-}
+        return;
 
-const String& UserContentController::displayNoneCSSRule()
-{
-    static NeverDestroyed<const String> rule(ASCIILiteral("{display:none !important;}\n"));
-    return rule;
+    m_contentExtensionBackend->processContentExtensionRulesForLoad(request, resourceType, initiatingDocumentLoader);
 }
 
 #endif
index 34bf683..ed5cebb 100644 (file)
 namespace WebCore {
 
 class DOMWrapperWorld;
+class DocumentLoader;
 class Page;
+class ResourceRequest;
 class StyleSheetContents;
 class URL;
 class UserScript;
 class UserStyleSheet;
 class UserMessageHandlerDescriptor;
+
+enum class ResourceType : uint16_t;
+
 struct ResourceLoadInfo;
 
 namespace ContentExtensions {
@@ -86,10 +91,8 @@ public:
     WEBCORE_EXPORT void addUserContentExtension(const String& name, RefPtr<ContentExtensions::CompiledContentExtension>);
     WEBCORE_EXPORT void removeUserContentExtension(const String& name);
     WEBCORE_EXPORT void removeAllUserContentExtensions();
-    
-    Vector<ContentExtensions::Action> actionsForResourceLoad(const ResourceLoadInfo&);
-    StyleSheetContents* globalDisplayNoneStyleSheet(const String& identifier) const;
-    static const String& displayNoneCSSRule();
+
+    void processContentExtensionRulesForLoad(ResourceRequest&, ResourceType, DocumentLoader& initiatingDocumentLoader);
 #endif
 
 private:
index 160d248..3c5c9af 100644 (file)
@@ -1,3 +1,14 @@
+2015-03-26  Brady Eidson  <beidson@apple.com>
+
+        Apply ContentExtension actions after redirects.
+        <rdar://problem/20062613> and https://bugs.webkit.org/show_bug.cgi?id=143055
+
+        Reviewed by Alex Christensen.
+
+        * WebKitTestRunner/InjectedBundle/InjectedBundlePage.cpp:
+        (WTR::InjectedBundlePage::didFailProvisionalLoadWithErrorForFrame): Dump the fact that the load error is kWKErrorCodeCannotShowURL
+          which is specifically interesting to a new test.
+
 2015-03-26  Csaba Osztrogon√°c  <ossy@webkit.org>
 
         [EFL] Disable building libseccomp on AArch64
index 06b968b..6aa7948 100644 (file)
@@ -685,14 +685,17 @@ void InjectedBundlePage::didReceiveServerRedirectForProvisionalLoadForFrame(WKBu
     dumpLoadEvent(frame, "didReceiveServerRedirectForProvisionalLoadForFrame");
 }
 
-void InjectedBundlePage::didFailProvisionalLoadWithErrorForFrame(WKBundleFrameRef frame, WKErrorRef)
+void InjectedBundlePage::didFailProvisionalLoadWithErrorForFrame(WKBundleFrameRef frame, WKErrorRef error)
 {
     auto& injectedBundle = InjectedBundle::singleton();
     if (!injectedBundle.isTestRunning())
         return;
 
-    if (injectedBundle.testRunner()->shouldDumpFrameLoadCallbacks())
+    if (injectedBundle.testRunner()->shouldDumpFrameLoadCallbacks()) {
         dumpLoadEvent(frame, "didFailProvisionalLoadWithError");
+        if (WKErrorGetErrorCode(error) == kWKErrorCodeCannotShowURL)
+            dumpLoadEvent(frame, "(kWKErrorCodeCannotShowURL)");
+    }
 
     frameDidChangeLocation(frame);
 }