Title: [181421] trunk
Revision
181421
Author
commit-qu...@webkit.org
Date
2015-03-11 18:03:43 -0700 (Wed, 11 Mar 2015)

Log Message

[Content Extensions] Add resource type and load type triggers.
https://bugs.webkit.org/show_bug.cgi?id=142422

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

Source/WebCore:

New API tests.

* WebCore.xcodeproj/project.pbxproj:
* contentextensions/ContentExtensionCompiler.cpp:
(WebCore::ContentExtensions::compileRuleList):
* contentextensions/ContentExtensionParser.cpp:
(WebCore::ContentExtensions::getTypeFlags):
(WebCore::ContentExtensions::loadTrigger):
* contentextensions/ContentExtensionRule.h:
* contentextensions/ContentExtensionsBackend.cpp:
(WebCore::ContentExtensions::ContentExtensionsBackend::actionsForResourceLoad):
(WebCore::ContentExtensions::ContentExtensionsBackend::actionsForURL): Deleted.
* contentextensions/ContentExtensionsBackend.h:
* contentextensions/DFABytecode.h:
(WebCore::ContentExtensions::instructionSizeWithArguments):
* contentextensions/DFABytecodeCompiler.cpp:
(WebCore::ContentExtensions::DFABytecodeCompiler::emitAppendConditionalAction):
(WebCore::ContentExtensions::DFABytecodeCompiler::compileNode):
* contentextensions/DFABytecodeCompiler.h:
* contentextensions/DFABytecodeInterpreter.cpp:
(WebCore::ContentExtensions::DFABytecodeInterpreter::interpret):
* contentextensions/DFABytecodeInterpreter.h:
* loader/ResourceLoadInfo.cpp: Added.
(WebCore::toResourceType):
(WebCore::readResourceType):
(WebCore::readLoadType):
(WebCore::ResourceLoadInfo::isThirdParty):
(WebCore::ResourceLoadInfo::getResourceFlags):
* loader/ResourceLoadInfo.h: Added.
* loader/cache/CachedResourceLoader.cpp:
(WebCore::CachedResourceLoader::requestResource):
* page/UserContentController.cpp:
(WebCore::UserContentController::actionsForResourceLoad):
(WebCore::UserContentController::actionsForURL): Deleted.
* page/UserContentController.h:

Tools:

* TestWebKitAPI/Tests/WebCore/ContentExtensions.cpp:
(TestWebKitAPI::testRequest):
(TestWebKitAPI::mainDocumentRequest):
(TestWebKitAPI::TEST_F):
(TestWebKitAPI::testURL): Deleted.

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (181420 => 181421)


--- trunk/Source/WebCore/ChangeLog	2015-03-12 00:38:04 UTC (rev 181420)
+++ trunk/Source/WebCore/ChangeLog	2015-03-12 01:03:43 UTC (rev 181421)
@@ -1,3 +1,46 @@
+2015-03-11  Alex Christensen  <achristen...@webkit.org>
+
+        [Content Extensions] Add resource type and load type triggers.
+        https://bugs.webkit.org/show_bug.cgi?id=142422
+
+        Reviewed by Benjamin Poulain.
+
+        New API tests.
+
+        * WebCore.xcodeproj/project.pbxproj:
+        * contentextensions/ContentExtensionCompiler.cpp:
+        (WebCore::ContentExtensions::compileRuleList):
+        * contentextensions/ContentExtensionParser.cpp:
+        (WebCore::ContentExtensions::getTypeFlags):
+        (WebCore::ContentExtensions::loadTrigger):
+        * contentextensions/ContentExtensionRule.h:
+        * contentextensions/ContentExtensionsBackend.cpp:
+        (WebCore::ContentExtensions::ContentExtensionsBackend::actionsForResourceLoad):
+        (WebCore::ContentExtensions::ContentExtensionsBackend::actionsForURL): Deleted.
+        * contentextensions/ContentExtensionsBackend.h:
+        * contentextensions/DFABytecode.h:
+        (WebCore::ContentExtensions::instructionSizeWithArguments):
+        * contentextensions/DFABytecodeCompiler.cpp:
+        (WebCore::ContentExtensions::DFABytecodeCompiler::emitAppendConditionalAction):
+        (WebCore::ContentExtensions::DFABytecodeCompiler::compileNode):
+        * contentextensions/DFABytecodeCompiler.h:
+        * contentextensions/DFABytecodeInterpreter.cpp:
+        (WebCore::ContentExtensions::DFABytecodeInterpreter::interpret):
+        * contentextensions/DFABytecodeInterpreter.h:
+        * loader/ResourceLoadInfo.cpp: Added.
+        (WebCore::toResourceType):
+        (WebCore::readResourceType):
+        (WebCore::readLoadType):
+        (WebCore::ResourceLoadInfo::isThirdParty):
+        (WebCore::ResourceLoadInfo::getResourceFlags):
+        * loader/ResourceLoadInfo.h: Added.
+        * loader/cache/CachedResourceLoader.cpp:
+        (WebCore::CachedResourceLoader::requestResource):
+        * page/UserContentController.cpp:
+        (WebCore::UserContentController::actionsForResourceLoad):
+        (WebCore::UserContentController::actionsForURL): Deleted.
+        * page/UserContentController.h:
+
 2015-03-11  Tim Horton  <timothy_hor...@apple.com>
 
         Fix the build.

Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (181420 => 181421)


--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2015-03-12 00:38:04 UTC (rev 181420)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2015-03-12 01:03:43 UTC (rev 181421)
@@ -2053,6 +2053,8 @@
 		51EAC5681815ED3E004F1BA4 /* IDBTransactionCoordinator.h in Headers */ = {isa = PBXBuildFile; fileRef = 51EAC5661815ED3E004F1BA4 /* IDBTransactionCoordinator.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		51EAC5B218163F4E004F1BA4 /* IDBRecordIdentifier.h in Headers */ = {isa = PBXBuildFile; fileRef = 51EAC5B018163F4E004F1BA4 /* IDBRecordIdentifier.h */; };
 		51EC92650CE90DD400F90308 /* JSCustomSQLStatementErrorCallback.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 51EC925D0CE90DD400F90308 /* JSCustomSQLStatementErrorCallback.cpp */; };
+		51EE7B381AA50B0500F92B21 /* ResourceLoadInfo.h in Headers */ = {isa = PBXBuildFile; fileRef = 51EE7B371AA50B0500F92B21 /* ResourceLoadInfo.h */; settings = {ATTRIBUTES = (Private, ); }; };
+		51EE7B3A1AA5123100F92B21 /* ResourceLoadInfo.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 51EE7B391AA5123100F92B21 /* ResourceLoadInfo.cpp */; };
 		51FA2D78152132B300C1BA0B /* DOMWindowExtension.h in Headers */ = {isa = PBXBuildFile; fileRef = 517FBA18151AA71B00B57959 /* DOMWindowExtension.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		51FB5504113E3E9100821176 /* JSCloseEvent.h in Headers */ = {isa = PBXBuildFile; fileRef = 51FB5502113E3E9100821176 /* JSCloseEvent.h */; };
 		51FB5505113E3E9100821176 /* JSCloseEvent.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 51FB5503113E3E9100821176 /* JSCloseEvent.cpp */; };
@@ -9226,6 +9228,8 @@
 		51EAC5661815ED3E004F1BA4 /* IDBTransactionCoordinator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IDBTransactionCoordinator.h; sourceTree = "<group>"; };
 		51EAC5B018163F4E004F1BA4 /* IDBRecordIdentifier.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IDBRecordIdentifier.h; sourceTree = "<group>"; };
 		51EC925D0CE90DD400F90308 /* JSCustomSQLStatementErrorCallback.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSCustomSQLStatementErrorCallback.cpp; sourceTree = "<group>"; };
+		51EE7B371AA50B0500F92B21 /* ResourceLoadInfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ResourceLoadInfo.h; sourceTree = "<group>"; };
+		51EE7B391AA5123100F92B21 /* ResourceLoadInfo.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ResourceLoadInfo.cpp; sourceTree = "<group>"; };
 		51F6A3D50663BF04004D2919 /* HTMLCanvasElement.cpp */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.cpp.cpp; path = HTMLCanvasElement.cpp; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
 		51F6A3D60663BF04004D2919 /* HTMLCanvasElement.h */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.c.h; path = HTMLCanvasElement.h; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
 		51FB5502113E3E9100821176 /* JSCloseEvent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSCloseEvent.h; sourceTree = "<group>"; };
@@ -21453,6 +21457,8 @@
 				656D37270ADBA5DE00A4554D /* ResourceLoader.h */,
 				D0A3A7301405A39800FB8ED3 /* ResourceLoaderOptions.h */,
 				51AF503516F100F60095B2E8 /* ResourceLoaderTypes.h */,
+				51EE7B391AA5123100F92B21 /* ResourceLoadInfo.cpp */,
+				51EE7B371AA50B0500F92B21 /* ResourceLoadInfo.h */,
 				973E325410883B7C005BC493 /* ResourceLoadNotifier.cpp */,
 				973E325510883B7C005BC493 /* ResourceLoadNotifier.h */,
 				D0CE58F6125E4CC200F3F199 /* ResourceLoadScheduler.cpp */,
@@ -25133,6 +25139,7 @@
 				1AE2AEC80A1D297B00B42B25 /* JSHTMLQuoteElement.h in Headers */,
 				1AE2ABAD0A1CE90500B42B25 /* JSHTMLScriptElement.h in Headers */,
 				E1E6EEA80B628DB3005F2F70 /* JSHTMLSelectElement.h in Headers */,
+				51EE7B381AA50B0500F92B21 /* ResourceLoadInfo.h in Headers */,
 				AB4CB4EB0B8BDA3D009F40B0 /* JSHTMLSelectElementCustom.h in Headers */,
 				E446143C0CD689CC00FADA75 /* JSHTMLSourceElement.h in Headers */,
 				9752D38E1413104B003305BD /* JSHTMLSpanElement.h in Headers */,
@@ -30119,6 +30126,7 @@
 				A14832B1187F61E100DA63A6 /* WAKAppKitStubs.m in Sources */,
 				A14832B3187F629100DA63A6 /* WAKClipView.m in Sources */,
 				A14832B5187F62FC00DA63A6 /* WAKResponder.m in Sources */,
+				51EE7B3A1AA5123100F92B21 /* ResourceLoadInfo.cpp in Sources */,
 				A14832B7187F636C00DA63A6 /* WAKScrollView.mm in Sources */,
 				A14832B9187F63D500DA63A6 /* WAKView.mm in Sources */,
 				A14832BC187F648E00DA63A6 /* WAKWindow.mm in Sources */,

Modified: trunk/Source/WebCore/contentextensions/ContentExtensionCompiler.cpp (181420 => 181421)


--- trunk/Source/WebCore/contentextensions/ContentExtensionCompiler.cpp	2015-03-12 00:38:04 UTC (rev 181420)
+++ trunk/Source/WebCore/contentextensions/ContentExtensionCompiler.cpp	2015-03-12 01:03:43 UTC (rev 181421)
@@ -116,7 +116,8 @@
         const Trigger& trigger = contentExtensionRule.trigger();
         ASSERT(trigger.urlFilter.length());
 
-        String error = urlFilterParser.addPattern(trigger.urlFilter, trigger.urlFilterIsCaseSensitive, actionLocations[ruleIndex]);
+        // High bits are used for flags. This should match how they are used in DFABytecodeCompiler::compileNode.
+        String error = urlFilterParser.addPattern(trigger.urlFilter, trigger.urlFilterIsCaseSensitive, (static_cast<uint64_t>(trigger.flags) << 32) | static_cast<uint64_t>(actionLocations[ruleIndex]));
 
         if (!error.isNull()) {
             dataLogF("Error while parsing %s: %s\n", trigger.urlFilter.utf8().data(), error.utf8().data());

Modified: trunk/Source/WebCore/contentextensions/ContentExtensionParser.cpp (181420 => 181421)


--- trunk/Source/WebCore/contentextensions/ContentExtensionParser.cpp	2015-03-12 00:38:04 UTC (rev 181420)
+++ trunk/Source/WebCore/contentextensions/ContentExtensionParser.cpp	2015-03-12 01:03:43 UTC (rev 181421)
@@ -46,6 +46,38 @@
 
 namespace ContentExtensions {
 
+static bool getTypeFlags(ExecState& exec, const JSValue& typeValue, ResourceFlags& flags, uint16_t(*stringToType)(const String&))
+{
+    if (!typeValue.isObject())
+        return true;
+
+    JSObject* object = typeValue.toObject(&exec);
+    if (!isJSArray(object)) {
+        WTFLogAlways("Invalid trigger flags array");
+        return false;
+    }
+
+    JSArray* array = jsCast<JSArray*>(object);
+    
+    unsigned length = array->length();
+    for (unsigned i = 0; i < length; ++i) {
+        JSValue value = array->getIndex(&exec, i);
+        if (exec.hadException() || !value) {
+            WTFLogAlways("Invalid object in the trigger flags array.");
+            continue;
+        }
+        
+        String name = value.toWTFString(&exec);
+        uint16_t type = stringToType(name);
+        if (!type) {
+            WTFLogAlways("Invalid string in the trigger flags array.");
+            continue;
+        }
+        flags |= type;
+    }
+    return true;
+}
+    
 static bool loadTrigger(ExecState& exec, JSObject& ruleObject, Trigger& trigger)
 {
     JSValue triggerObject = ruleObject.get(&exec, Identifier(&exec, "trigger"));
@@ -67,10 +99,18 @@
     }
     trigger.urlFilter = urlFilter;
 
-    JSValue urlFilterCaseObject = triggerObject.get(&exec, Identifier(&exec, "url-filter-is-case-sensitive"));
-    if (urlFilterCaseObject && !exec.hadException() && urlFilterCaseObject.isBoolean())
-        trigger.urlFilterIsCaseSensitive = urlFilterCaseObject.toBoolean(&exec);
+    JSValue urlFilterCaseValue = triggerObject.get(&exec, Identifier(&exec, "url-filter-is-case-sensitive"));
+    if (urlFilterCaseValue && !exec.hadException() && urlFilterCaseValue.isBoolean())
+        trigger.urlFilterIsCaseSensitive = urlFilterCaseValue.toBoolean(&exec);
 
+    JSValue resourceTypeValue = triggerObject.get(&exec, Identifier(&exec, "resource-type"));
+    if (resourceTypeValue && !exec.hadException() && !getTypeFlags(exec, resourceTypeValue, trigger.flags, readResourceType))
+        return false;
+    
+    JSValue loadTypeValue = triggerObject.get(&exec, Identifier(&exec, "load-type"));
+    if (loadTypeValue && !exec.hadException() && !getTypeFlags(exec, loadTypeValue, trigger.flags, readLoadType))
+        return false;
+
     return true;
 }
 

Modified: trunk/Source/WebCore/contentextensions/ContentExtensionRule.h (181420 => 181421)


--- trunk/Source/WebCore/contentextensions/ContentExtensionRule.h	2015-03-12 00:38:04 UTC (rev 181420)
+++ trunk/Source/WebCore/contentextensions/ContentExtensionRule.h	2015-03-12 01:03:43 UTC (rev 181421)
@@ -29,6 +29,7 @@
 #if ENABLE(CONTENT_EXTENSIONS)
 
 #include "ContentExtensionActions.h"
+#include "ResourceLoadInfo.h"
 #include <wtf/text/WTFString.h>
 
 namespace WebCore {
@@ -43,6 +44,7 @@
 struct Trigger {
     String urlFilter;
     bool urlFilterIsCaseSensitive { false };
+    ResourceFlags flags { 0 };
 };
     
 struct Action {

Modified: trunk/Source/WebCore/contentextensions/ContentExtensionsBackend.cpp (181420 => 181421)


--- trunk/Source/WebCore/contentextensions/ContentExtensionsBackend.cpp	2015-03-12 00:38:04 UTC (rev 181420)
+++ trunk/Source/WebCore/contentextensions/ContentExtensionsBackend.cpp	2015-03-12 01:03:43 UTC (rev 181421)
@@ -30,6 +30,7 @@
 
 #include "CompiledContentExtension.h"
 #include "DFABytecodeInterpreter.h"
+#include "ResourceLoadInfo.h"
 #include "URL.h"
 #include <wtf/text/CString.h>
 
@@ -61,16 +62,17 @@
     m_contentExtensions.clear();
 }
 
-Vector<Action> ContentExtensionsBackend::actionsForURL(const URL& url)
+Vector<Action> ContentExtensionsBackend::actionsForResourceLoad(const ResourceLoadInfo& resourceLoadInfo) const
 {
-    const String& urlString = url.string();
+    const String& urlString = resourceLoadInfo.resourceURL.string();
     ASSERT_WITH_MESSAGE(urlString.containsOnlyASCII(), "A decoded URL should only contain ASCII characters. The matching algorithm assumes the input is ASCII.");
     const CString& urlCString = urlString.utf8();
 
     Vector<Action> finalActions;
+    ResourceFlags flags = resourceLoadInfo.getResourceFlags();
     for (auto& compiledContentExtension : m_contentExtensions.values()) {
         DFABytecodeInterpreter interpreter(compiledContentExtension->bytecode(), compiledContentExtension->bytecodeLength());
-        DFABytecodeInterpreter::Actions triggeredActions = interpreter.interpret(urlCString);
+        DFABytecodeInterpreter::Actions triggeredActions = interpreter.interpret(urlCString, flags);
         
         const SerializedActionByte* actions = compiledContentExtension->actions();
         const unsigned actionsLength = compiledContentExtension->actionsLength();

Modified: trunk/Source/WebCore/contentextensions/ContentExtensionsBackend.h (181420 => 181421)


--- trunk/Source/WebCore/contentextensions/ContentExtensionsBackend.h	2015-03-12 00:38:04 UTC (rev 181420)
+++ trunk/Source/WebCore/contentextensions/ContentExtensionsBackend.h	2015-03-12 01:03:43 UTC (rev 181421)
@@ -37,6 +37,8 @@
 
 class URL;
 
+struct ResourceLoadInfo;
+
 namespace ContentExtensions {
 
 class CompiledContentExtension;
@@ -57,7 +59,7 @@
     WEBCORE_EXPORT void removeAllContentExtensions();
 
     // - Internal WebCore Interface.
-    WEBCORE_EXPORT Vector<Action> actionsForURL(const URL&);
+    WEBCORE_EXPORT Vector<Action> actionsForResourceLoad(const ResourceLoadInfo&) const;
 
 private:
     HashMap<String, RefPtr<CompiledContentExtension>> m_contentExtensions;

Modified: trunk/Source/WebCore/contentextensions/DFABytecode.h (181420 => 181421)


--- trunk/Source/WebCore/contentextensions/DFABytecode.h	2015-03-12 00:38:04 UTC (rev 181420)
+++ trunk/Source/WebCore/contentextensions/DFABytecode.h	2015-03-12 01:03:43 UTC (rev 181421)
@@ -44,6 +44,11 @@
     // AppendAction has one argument:
     // The action to append (4 bytes).
     AppendAction,
+    
+    // TestFlagsAndAppendAction has two arguments:
+    // The flags to check before appending (2 bytes),
+    // The action to append (4bytes).
+    TestFlagsAndAppendAction,
 
     // Terminate has no arguments.
     Terminate,
@@ -60,6 +65,8 @@
         return sizeof(DFABytecodeInstruction) + sizeof(uint8_t) + sizeof(unsigned);
     case DFABytecodeInstruction::AppendAction:
         return sizeof(DFABytecodeInstruction) + sizeof(unsigned);
+    case DFABytecodeInstruction::TestFlagsAndAppendAction:
+        return sizeof(DFABytecodeInstruction) + sizeof(uint16_t) + sizeof(unsigned);
     case DFABytecodeInstruction::Terminate:
         return sizeof(DFABytecodeInstruction);
     case DFABytecodeInstruction::Jump:

Modified: trunk/Source/WebCore/contentextensions/DFABytecodeCompiler.cpp (181420 => 181421)


--- trunk/Source/WebCore/contentextensions/DFABytecodeCompiler.cpp	2015-03-12 00:38:04 UTC (rev 181420)
+++ trunk/Source/WebCore/contentextensions/DFABytecodeCompiler.cpp	2015-03-12 01:03:43 UTC (rev 181421)
@@ -53,6 +53,14 @@
     append<unsigned>(m_bytecode, action);
 }
 
+void DFABytecodeCompiler::emitTestFlagsAndAppendAction(uint16_t flags, unsigned action)
+{
+    ASSERT(flags);
+    append<DFABytecodeInstruction>(m_bytecode, DFABytecodeInstruction::TestFlagsAndAppendAction);
+    append<uint16_t>(m_bytecode, flags);
+    append<unsigned>(m_bytecode, action);
+}
+
 void DFABytecodeCompiler::emitJump(unsigned destinationNodeIndex)
 {
     append<DFABytecodeInstruction>(m_bytecode, DFABytecodeInstruction::Jump);
@@ -80,8 +88,13 @@
     // Record starting index for linking.
     m_nodeStartOffsets[index] = m_bytecode.size();
 
-    for (uint64_t action : node.actions)
-        emitAppendAction(static_cast<unsigned>(action));
+    for (uint64_t action : node.actions) {
+        // High bits are used to store flags. See compileRuleList.
+        if (action & 0xFFFF00000000)
+            emitTestFlagsAndAppendAction(static_cast<uint16_t>(action >> 32), static_cast<unsigned>(action));
+        else
+            emitAppendAction(static_cast<unsigned>(action));
+    }
     
     for (const auto& transition : node.transitions)
         emitCheckValue(transition.key, transition.value);

Modified: trunk/Source/WebCore/contentextensions/DFABytecodeCompiler.h (181420 => 181421)


--- trunk/Source/WebCore/contentextensions/DFABytecodeCompiler.h	2015-03-12 00:38:04 UTC (rev 181420)
+++ trunk/Source/WebCore/contentextensions/DFABytecodeCompiler.h	2015-03-12 01:03:43 UTC (rev 181421)
@@ -52,6 +52,7 @@
     void compileNode(unsigned);
 
     void emitAppendAction(unsigned);
+    void emitTestFlagsAndAppendAction(uint16_t flags, unsigned);
     void emitJump(unsigned destinationNodeIndex);
     void emitCheckValue(uint8_t value, unsigned destinationNodeIndex);
     void emitTerminate();

Modified: trunk/Source/WebCore/contentextensions/DFABytecodeInterpreter.cpp (181420 => 181421)


--- trunk/Source/WebCore/contentextensions/DFABytecodeInterpreter.cpp	2015-03-12 00:38:04 UTC (rev 181420)
+++ trunk/Source/WebCore/contentextensions/DFABytecodeInterpreter.cpp	2015-03-12 01:03:43 UTC (rev 181421)
@@ -41,7 +41,7 @@
     return *reinterpret_cast<const IntType*>(&bytecode[index]);
 }
 
-DFABytecodeInterpreter::Actions DFABytecodeInterpreter::interpret(const CString& urlCString)
+DFABytecodeInterpreter::Actions DFABytecodeInterpreter::interpret(const CString& urlCString, uint16_t flags)
 {
     const char* url = ""
     ASSERT(url);
@@ -86,6 +86,12 @@
             programCounter += instructionSizeWithArguments(DFABytecodeInstruction::AppendAction);
             break;
 
+        case DFABytecodeInstruction::TestFlagsAndAppendAction:
+            if (flags & getBits<uint16_t>(m_bytecode, m_bytecodeLength, programCounter + sizeof(DFABytecode)))
+                actions.add(static_cast<uint64_t>(getBits<unsigned>(m_bytecode, m_bytecodeLength, programCounter + sizeof(DFABytecode) + sizeof(uint16_t))));
+            programCounter += instructionSizeWithArguments(DFABytecodeInstruction::TestFlagsAndAppendAction);
+            break;
+
         default:
             RELEASE_ASSERT_NOT_REACHED(); // Invalid bytecode.
         }

Modified: trunk/Source/WebCore/contentextensions/DFABytecodeInterpreter.h (181420 => 181421)


--- trunk/Source/WebCore/contentextensions/DFABytecodeInterpreter.h	2015-03-12 00:38:04 UTC (rev 181420)
+++ trunk/Source/WebCore/contentextensions/DFABytecodeInterpreter.h	2015-03-12 01:03:43 UTC (rev 181421)
@@ -47,7 +47,7 @@
     
     typedef HashSet<uint64_t, DefaultHash<uint64_t>::Hash, WTF::UnsignedWithZeroKeyHashTraits<uint64_t>> Actions;
     
-    Actions interpret(const CString&);
+    Actions interpret(const CString&, uint16_t flags);
 
 private:
     const DFABytecode* m_bytecode;

Added: trunk/Source/WebCore/loader/ResourceLoadInfo.cpp (0 => 181421)


--- trunk/Source/WebCore/loader/ResourceLoadInfo.cpp	                        (rev 0)
+++ trunk/Source/WebCore/loader/ResourceLoadInfo.cpp	2015-03-12 01:03:43 UTC (rev 181421)
@@ -0,0 +1,117 @@
+/*
+ * Copyright (C) 2015 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "ResourceLoadInfo.h"
+
+#include "ContentExtensionActions.h"
+#include "SecurityOrigin.h"
+
+namespace WebCore {
+
+ResourceType toResourceType(CachedResource::Type type)
+{
+    switch (type) {
+    case CachedResource::MainResource:
+        return ResourceType::Document;
+    case CachedResource::SVGDocumentResource:
+        return ResourceType::SVGDocument;
+    case CachedResource::ImageResource:
+        return ResourceType::Image;
+    case CachedResource::CSSStyleSheet:
+#if ENABLE(XSLT)
+    case CachedResource::XSLStyleSheet:
+#endif
+        return ResourceType::StyleSheet;
+
+    case CachedResource::Script:
+        return ResourceType::Script;
+
+    case CachedResource::FontResource:
+#if ENABLE(SVG_FONTS)
+    case CachedResource::SVGFontResource:
+#endif
+        return ResourceType::Font;
+
+    case CachedResource::RawResource:
+        return ResourceType::Raw;
+
+#if ENABLE(VIDEO_TRACK)
+    case CachedResource::TextTrackResource:
+        return ResourceType::Media;
+#endif
+    default:
+        ASSERT_NOT_REACHED();
+    };
+}
+
+uint16_t readResourceType(const String& name)
+{
+    if (name == "document")
+        return static_cast<uint16_t>(ResourceType::Document);
+    if (name == "image")
+        return static_cast<uint16_t>(ResourceType::Image);
+    if (name == "style-sheet")
+        return static_cast<uint16_t>(ResourceType::StyleSheet);
+    if (name == "script")
+        return static_cast<uint16_t>(ResourceType::Script);
+    if (name == "font")
+        return static_cast<uint16_t>(ResourceType::Font);
+    if (name == "raw")
+        return static_cast<uint16_t>(ResourceType::Raw);
+    if (name == "svg-document")
+        return static_cast<uint16_t>(ResourceType::SVGDocument);
+    if (name == "media")
+        return static_cast<uint16_t>(ResourceType::Media);
+    return static_cast<uint16_t>(ResourceType::Invalid);
+}
+
+uint16_t readLoadType(const String& name)
+{
+    if (name == "first-party")
+        return static_cast<uint16_t>(LoadType::FirstParty);
+    if (name == "third-party")
+        return static_cast<uint16_t>(LoadType::ThirdParty);
+    return static_cast<uint16_t>(LoadType::Invalid);
+}
+
+bool ResourceLoadInfo::isThirdParty() const
+{
+    Ref<SecurityOrigin> mainDocumentSecurityOrigin = SecurityOrigin::create(mainDocumentURL);
+    Ref<SecurityOrigin> resourceSecurityOrigin = SecurityOrigin::create(resourceURL);
+
+    return !mainDocumentSecurityOrigin->canAccess(&resourceSecurityOrigin.get());
+}
+    
+ResourceFlags ResourceLoadInfo::getResourceFlags() const
+{
+    ResourceFlags flags = 0;
+    ASSERT(type != ResourceType::Invalid);
+    flags |= static_cast<ResourceFlags>(type);
+    flags |= isThirdParty() ? static_cast<ResourceFlags>(LoadType::ThirdParty) : static_cast<ResourceFlags>(LoadType::FirstParty);
+    return flags;
+}
+
+} // namespace WebCore

Copied: trunk/Source/WebCore/loader/ResourceLoadInfo.h (from rev 181420, trunk/Source/WebCore/contentextensions/DFABytecodeInterpreter.h) (0 => 181421)


--- trunk/Source/WebCore/loader/ResourceLoadInfo.h	                        (rev 0)
+++ trunk/Source/WebCore/loader/ResourceLoadInfo.h	2015-03-12 01:03:43 UTC (rev 181421)
@@ -0,0 +1,70 @@
+/*
+ * Copyright (C) 2015 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef ResourceLoadInfo_h
+#define ResourceLoadInfo_h
+
+#include "CachedResource.h"
+#include "URL.h"
+
+namespace WebCore {
+
+enum class ResourceType : uint16_t {
+    Invalid = 0x0000,
+    Document = 0x0001,
+    Image = 0x0002,
+    StyleSheet = 0x0004,
+    Script = 0x0008,
+    Font = 0x0010,
+    Raw = 0x0020,
+    SVGDocument = 0x0040,
+    Media = 0x0080,
+};
+
+enum class LoadType : uint16_t {
+    Invalid = 0x0000,
+    FirstParty = 0x0100,
+    ThirdParty = 0x0200,
+};
+
+typedef uint16_t ResourceFlags;
+
+ResourceType toResourceType(CachedResource::Type);
+uint16_t readResourceType(const String&);
+uint16_t readLoadType(const String&);
+
+struct ResourceLoadInfo {
+    URL resourceURL;
+    URL mainDocumentURL;
+    ResourceType type;
+
+    bool isThirdParty() const;
+    ResourceFlags getResourceFlags() const;
+};
+
+
+} // namespace WebCore
+
+#endif // ResourceLoadInfo_h

Modified: trunk/Source/WebCore/loader/cache/CachedResourceLoader.cpp (181420 => 181421)


--- trunk/Source/WebCore/loader/cache/CachedResourceLoader.cpp	2015-03-12 00:38:04 UTC (rev 181420)
+++ trunk/Source/WebCore/loader/cache/CachedResourceLoader.cpp	2015-03-12 01:03:43 UTC (rev 181421)
@@ -58,6 +58,7 @@
 #include "PingLoader.h"
 #include "PlatformStrategies.h"
 #include "RenderElement.h"
+#include "ResourceLoadInfo.h"
 #include "ResourceLoadScheduler.h"
 #include "ScriptController.h"
 #include "SecurityOrigin.h"
@@ -507,8 +508,14 @@
 #if ENABLE(CONTENT_EXTENSIONS)
     Vector<ContentExtensions::Action> actions;
 
-    if (frame() && frame()->page() && frame()->page()->userContentController())
-        actions = frame()->page()->userContentController()->actionsForURL(url);
+    URL mainDocumentURL;
+    if (frame() && frame()->mainFrame().document())
+        mainDocumentURL = frame()->mainFrame().document()->url();
+    
+    ResourceLoadInfo resourceLoadInfo = { url, mainDocumentURL, toResourceType(type) };
+    
+    if (frame() && frame()->mainFrame().page() && frame()->mainFrame().page()->userContentController())
+        actions = frame()->mainFrame().page()->userContentController()->actionsForResourceLoad(resourceLoadInfo);
 
     bool willBlockLoad = false;
     for (const auto& action : actions) {

Modified: trunk/Source/WebCore/page/UserContentController.cpp (181420 => 181421)


--- trunk/Source/WebCore/page/UserContentController.cpp	2015-03-12 00:38:04 UTC (rev 181420)
+++ trunk/Source/WebCore/page/UserContentController.cpp	2015-03-12 01:03:43 UTC (rev 181421)
@@ -30,6 +30,7 @@
 #include "Document.h"
 #include "MainFrame.h"
 #include "Page.h"
+#include "ResourceLoadInfo.h"
 #include "UserScript.h"
 #include "UserStyleSheet.h"
 
@@ -203,12 +204,12 @@
     m_contentExtensionBackend->removeAllContentExtensions();
 }
 
-Vector<ContentExtensions::Action> UserContentController::actionsForURL(const URL& url)
+Vector<ContentExtensions::Action> UserContentController::actionsForResourceLoad(const ResourceLoadInfo& resourceLoadInfo)
 {
     if (!m_contentExtensionBackend)
         return Vector<ContentExtensions::Action>();
 
-    return m_contentExtensionBackend->actionsForURL(url);
+    return m_contentExtensionBackend->actionsForResourceLoad(resourceLoadInfo);
 }
 
 #endif

Modified: trunk/Source/WebCore/page/UserContentController.h (181420 => 181421)


--- trunk/Source/WebCore/page/UserContentController.h	2015-03-12 00:38:04 UTC (rev 181420)
+++ trunk/Source/WebCore/page/UserContentController.h	2015-03-12 01:03:43 UTC (rev 181421)
@@ -44,6 +44,7 @@
 class UserScript;
 class UserStyleSheet;
 class UserMessageHandlerDescriptor;
+struct ResourceLoadInfo;
 
 namespace ContentExtensions {
 class CompiledContentExtension;
@@ -85,8 +86,7 @@
     WEBCORE_EXPORT void removeUserContentExtension(const String& name);
     WEBCORE_EXPORT void removeAllUserContentExtensions();
     
-    // FIXME: Consider putting this (and other future content extension predicates) in its own class.
-    Vector<ContentExtensions::Action> actionsForURL(const URL&);
+    Vector<ContentExtensions::Action> actionsForResourceLoad(const ResourceLoadInfo&);
 #endif
 
 private:

Modified: trunk/Tools/ChangeLog (181420 => 181421)


--- trunk/Tools/ChangeLog	2015-03-12 00:38:04 UTC (rev 181420)
+++ trunk/Tools/ChangeLog	2015-03-12 01:03:43 UTC (rev 181421)
@@ -1,3 +1,16 @@
+2015-03-11  Alex Christensen  <achristen...@webkit.org>
+
+        [Content Extensions] Add resource type and load type triggers.
+        https://bugs.webkit.org/show_bug.cgi?id=142422
+
+        Reviewed by Benjamin Poulain.
+
+        * TestWebKitAPI/Tests/WebCore/ContentExtensions.cpp:
+        (TestWebKitAPI::testRequest):
+        (TestWebKitAPI::mainDocumentRequest):
+        (TestWebKitAPI::TEST_F):
+        (TestWebKitAPI::testURL): Deleted.
+
 2015-03-10  Sam Weinig  <s...@webkit.org>
 
         Allow adding a button in input elements for auto fill related functionality

Modified: trunk/Tools/TestWebKitAPI/Tests/WebCore/ContentExtensions.cpp (181420 => 181421)


--- trunk/Tools/TestWebKitAPI/Tests/WebCore/ContentExtensions.cpp	2015-03-12 00:38:04 UTC (rev 181420)
+++ trunk/Tools/TestWebKitAPI/Tests/WebCore/ContentExtensions.cpp	2015-03-12 01:03:43 UTC (rev 181421)
@@ -29,6 +29,7 @@
 #include <_javascript_Core/InitializeThreading.h>
 #include <WebCore/ContentExtensionCompiler.h>
 #include <WebCore/ContentExtensionsBackend.h>
+#include <WebCore/ResourceLoadInfo.h>
 #include <WebCore/URL.h>
 #include <wtf/MainThread.h>
 #include <wtf/RunLoop.h>
@@ -92,9 +93,9 @@
     ContentExtensions::CompiledContentExtensionData m_data;
 };
 
-void static testURL(ContentExtensions::ContentExtensionsBackend contentExtensionsBackend, const URL& url, Vector<ContentExtensions::ActionType> expectedActions)
+void static testRequest(ContentExtensions::ContentExtensionsBackend contentExtensionsBackend, const ResourceLoadInfo& resourceLoadInfo, Vector<ContentExtensions::ActionType> expectedActions)
 {
-    auto actions = contentExtensionsBackend.actionsForURL(url);
+    auto actions = contentExtensionsBackend.actionsForResourceLoad(resourceLoadInfo);
     EXPECT_EQ(expectedActions.size(), actions.size());
     if (expectedActions.size() != actions.size())
         return;
@@ -103,6 +104,11 @@
         EXPECT_EQ(expectedActions[i], actions[i].type());
 }
 
+ResourceLoadInfo mainDocumentRequest(const char* url, ResourceType resourceType = ResourceType::Document)
+{
+    return { URL(URL(), url), URL(URL(), url), resourceType };
+}
+
 const char* basicFilter = "[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\".*webkit.org\"}}]";
 
 TEST_F(ContentExtensionTest, Basic)
@@ -113,7 +119,7 @@
     ContentExtensions::ContentExtensionsBackend backend;
     backend.addContentExtension("testFilter", extension);
 
-    testURL(backend, URL(ParsedURLString, "http://webkit.org/"), { ContentExtensions::ActionType::BlockLoad });
+    testRequest(backend, mainDocumentRequest("http://webkit.org/"), { ContentExtensions::ActionType::BlockLoad });
 }
 
 const char* patternsStartingWithGroupFilter = "[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"(http://whatwg\\\\.org/)?webkit\134\134.org\"}}]";
@@ -126,11 +132,11 @@
     ContentExtensions::ContentExtensionsBackend backend;
     backend.addContentExtension("PatternNestedGroupsFilter", extension);
 
-    testURL(backend, URL(URL(), "http://whatwg.org/webkit.org/"), { ContentExtensions::ActionType::BlockLoad });
-    testURL(backend, URL(URL(), "http://whatwg.org/webkit.org"), { ContentExtensions::ActionType::BlockLoad });
-    testURL(backend, URL(URL(), "http://webkit.org/"), { });
-    testURL(backend, URL(URL(), "http://whatwg.org/"), { });
-    testURL(backend, URL(URL(), "http://whatwg.org"), { });
+    testRequest(backend, mainDocumentRequest("http://whatwg.org/webkit.org/"), { ContentExtensions::ActionType::BlockLoad });
+    testRequest(backend, mainDocumentRequest("http://whatwg.org/webkit.org"), { ContentExtensions::ActionType::BlockLoad });
+    testRequest(backend, mainDocumentRequest("http://webkit.org/"), { });
+    testRequest(backend, mainDocumentRequest("http://whatwg.org/"), { });
+    testRequest(backend, mainDocumentRequest("http://whatwg.org"), { });
 }
 
 const char* patternNestedGroupsFilter = "[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"http://webkit\\\\.org/(foo(bar)*)+\"}}]";
@@ -143,18 +149,17 @@
     ContentExtensions::ContentExtensionsBackend backend;
     backend.addContentExtension("PatternNestedGroupsFilter", extension);
 
-    testURL(backend, URL(URL(), "http://webkit.org/foo"), { ContentExtensions::ActionType::BlockLoad });
-    testURL(backend, URL(URL(), "http://webkit.org/foobar"), { ContentExtensions::ActionType::BlockLoad });
-    testURL(backend, URL(URL(), "http://webkit.org/foobarbar"), { ContentExtensions::ActionType::BlockLoad });
-    testURL(backend, URL(URL(), "http://webkit.org/foofoobar"), { ContentExtensions::ActionType::BlockLoad });
-    testURL(backend, URL(URL(), "http://webkit.org/foobarfoobar"), { ContentExtensions::ActionType::BlockLoad });
-    testURL(backend, URL(URL(), "http://webkit.org/foob"), { ContentExtensions::ActionType::BlockLoad });
-    testURL(backend, URL(URL(), "http://webkit.org/foor"), { ContentExtensions::ActionType::BlockLoad });
+    testRequest(backend, mainDocumentRequest("http://webkit.org/foo"), { ContentExtensions::ActionType::BlockLoad });
+    testRequest(backend, mainDocumentRequest("http://webkit.org/foobar"), { ContentExtensions::ActionType::BlockLoad });
+    testRequest(backend, mainDocumentRequest("http://webkit.org/foobarbar"), { ContentExtensions::ActionType::BlockLoad });
+    testRequest(backend, mainDocumentRequest("http://webkit.org/foofoobar"), { ContentExtensions::ActionType::BlockLoad });
+    testRequest(backend, mainDocumentRequest("http://webkit.org/foobarfoobar"), { ContentExtensions::ActionType::BlockLoad });
+    testRequest(backend, mainDocumentRequest("http://webkit.org/foob"), { ContentExtensions::ActionType::BlockLoad });
+    testRequest(backend, mainDocumentRequest("http://webkit.org/foor"), { ContentExtensions::ActionType::BlockLoad });
 
-
-    testURL(backend, URL(URL(), "http://webkit.org/"), { });
-    testURL(backend, URL(URL(), "http://webkit.org/bar"), { });
-    testURL(backend, URL(URL(), "http://webkit.org/fobar"), { });
+    testRequest(backend, mainDocumentRequest("http://webkit.org/"), { });
+    testRequest(backend, mainDocumentRequest("http://webkit.org/bar"), { });
+    testRequest(backend, mainDocumentRequest("http://webkit.org/fobar"), { });
 }
 
 const char* matchPastEndOfStringFilter = "[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\".+\"}}]";
@@ -167,14 +172,14 @@
     ContentExtensions::ContentExtensionsBackend backend;
     backend.addContentExtension("MatchPastEndOfString", extension);
 
-    testURL(backend, URL(URL(), "http://webkit.org/"), { ContentExtensions::ActionType::BlockLoad });
-    testURL(backend, URL(URL(), "http://webkit.org/foo"), { ContentExtensions::ActionType::BlockLoad });
-    testURL(backend, URL(URL(), "http://webkit.org/foobar"), { ContentExtensions::ActionType::BlockLoad });
-    testURL(backend, URL(URL(), "http://webkit.org/foobarbar"), { ContentExtensions::ActionType::BlockLoad });
-    testURL(backend, URL(URL(), "http://webkit.org/foofoobar"), { ContentExtensions::ActionType::BlockLoad });
-    testURL(backend, URL(URL(), "http://webkit.org/foobarfoobar"), { ContentExtensions::ActionType::BlockLoad });
-    testURL(backend, URL(URL(), "http://webkit.org/foob"), { ContentExtensions::ActionType::BlockLoad });
-    testURL(backend, URL(URL(), "http://webkit.org/foor"), { ContentExtensions::ActionType::BlockLoad });
+    testRequest(backend, mainDocumentRequest("http://webkit.org/"), { ContentExtensions::ActionType::BlockLoad });
+    testRequest(backend, mainDocumentRequest("http://webkit.org/foo"), { ContentExtensions::ActionType::BlockLoad });
+    testRequest(backend, mainDocumentRequest("http://webkit.org/foobar"), { ContentExtensions::ActionType::BlockLoad });
+    testRequest(backend, mainDocumentRequest("http://webkit.org/foobarbar"), { ContentExtensions::ActionType::BlockLoad });
+    testRequest(backend, mainDocumentRequest("http://webkit.org/foofoobar"), { ContentExtensions::ActionType::BlockLoad });
+    testRequest(backend, mainDocumentRequest("http://webkit.org/foobarfoobar"), { ContentExtensions::ActionType::BlockLoad });
+    testRequest(backend, mainDocumentRequest("http://webkit.org/foob"), { ContentExtensions::ActionType::BlockLoad });
+    testRequest(backend, mainDocumentRequest("http://webkit.org/foor"), { ContentExtensions::ActionType::BlockLoad });
 }
 
 const char* startOfLineAssertionFilter = "[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"^foobar\"}}]";
@@ -187,14 +192,14 @@
     ContentExtensions::ContentExtensionsBackend backend;
     backend.addContentExtension("StartOfLineAssertion", extension);
 
-    testURL(backend, URL(URL(), "foobar://webkit.org/foobar"), { ContentExtensions::ActionType::BlockLoad });
-    testURL(backend, URL(URL(), "foobars:///foobar"), { ContentExtensions::ActionType::BlockLoad });
-    testURL(backend, URL(URL(), "foobarfoobar:///foobarfoobarfoobar"), { ContentExtensions::ActionType::BlockLoad });
+    testRequest(backend, mainDocumentRequest("foobar://webkit.org/foobar"), { ContentExtensions::ActionType::BlockLoad });
+    testRequest(backend, mainDocumentRequest("foobars:///foobar"), { ContentExtensions::ActionType::BlockLoad });
+    testRequest(backend, mainDocumentRequest("foobarfoobar:///foobarfoobarfoobar"), { ContentExtensions::ActionType::BlockLoad });
 
-    testURL(backend, URL(URL(), "http://webkit.org/foobarfoo"), { });
-    testURL(backend, URL(URL(), "http://webkit.org/foobarf"), { });
-    testURL(backend, URL(URL(), "http://foobar.org/"), { });
-    testURL(backend, URL(URL(), "http://foobar.org/"), { });
+    testRequest(backend, mainDocumentRequest("http://webkit.org/foobarfoo"), { });
+    testRequest(backend, mainDocumentRequest("http://webkit.org/foobarf"), { });
+    testRequest(backend, mainDocumentRequest("http://foobar.org/"), { });
+    testRequest(backend, mainDocumentRequest("http://foobar.org/"), { });
 }
 
 const char* endOfLineAssertionFilter = "[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\".*foobar$\"}}]";
@@ -207,12 +212,57 @@
     ContentExtensions::ContentExtensionsBackend backend;
     backend.addContentExtension("EndOfLineAssertion", extension);
 
-    testURL(backend, URL(URL(), "http://webkit.org/foobar"), { ContentExtensions::ActionType::BlockLoad });
-    testURL(backend, URL(URL(), "file:///foobar"), { ContentExtensions::ActionType::BlockLoad });
-    testURL(backend, URL(URL(), "file:///foobarfoobarfoobar"), { ContentExtensions::ActionType::BlockLoad });
+    testRequest(backend, mainDocumentRequest("http://webkit.org/foobar"), { ContentExtensions::ActionType::BlockLoad });
+    testRequest(backend, mainDocumentRequest("file:///foobar"), { ContentExtensions::ActionType::BlockLoad });
+    testRequest(backend, mainDocumentRequest("file:///foobarfoobarfoobar"), { ContentExtensions::ActionType::BlockLoad });
 
-    testURL(backend, URL(URL(), "http://webkit.org/foobarfoo"), { });
-    testURL(backend, URL(URL(), "http://webkit.org/foobarf"), { });
+    testRequest(backend, mainDocumentRequest("http://webkit.org/foobarfoo"), { });
+    testRequest(backend, mainDocumentRequest("http://webkit.org/foobarf"), { });
 }
+    
+const char* loadTypeFilter = "[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\".*webkit.org\",\"load-type\":[\"third-party\"]}},"
+    "{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\".*whatwg.org\",\"load-type\":[\"first-party\"]}},"
+    "{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\".*alwaysblock.pdf\"}}]";
 
+TEST_F(ContentExtensionTest, LoadType)
+{
+    auto extensionData = ContentExtensions::compileRuleList(loadTypeFilter);
+    auto extension = InMemoryCompiledContentExtension::create(WTF::move(extensionData));
+        
+    ContentExtensions::ContentExtensionsBackend backend;
+    backend.addContentExtension("LoadTypeFilter", extension);
+        
+    testRequest(backend, mainDocumentRequest("http://webkit.org"), { });
+    testRequest(backend, {URL(URL(), "http://webkit.org"), URL(URL(), "http://not_webkit.org"), ResourceType::Document}, { ContentExtensions::ActionType::BlockLoad });
+        
+    testRequest(backend, mainDocumentRequest("http://whatwg.org"), { ContentExtensions::ActionType::BlockLoad });
+    testRequest(backend, {URL(URL(), "http://whatwg.org"), URL(URL(), "http://not_whatwg.org"), ResourceType::Document}, { });
+    
+    testRequest(backend, mainDocumentRequest("http://foobar.org/alwaysblock.pdf"), { ContentExtensions::ActionType::BlockLoad });
+    testRequest(backend, {URL(URL(), "http://foobar.org/alwaysblock.pdf"), URL(URL(), "http://not_foobar.org/alwaysblock.pdf"), ResourceType::Document}, { ContentExtensions::ActionType::BlockLoad });
+}
+    
+const char* resourceTypeFilter = "[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\".*block_all_types.org\",\"resource-type\":[\"document\",\"image\",\"style-sheet\",\"script\",\"font\",\"raw\",\"svg-document\",\"media\"]}},"
+    "{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\".*block_only_images\",\"resource-type\":[\"image\"]}}]";
+    
+TEST_F(ContentExtensionTest, ResourceType)
+{
+    auto extensionData = ContentExtensions::compileRuleList(resourceTypeFilter);
+    auto extension = InMemoryCompiledContentExtension::create(WTF::move(extensionData));
+        
+    ContentExtensions::ContentExtensionsBackend backend;
+    backend.addContentExtension("ResourceTypeFilter", extension);
+
+    testRequest(backend, mainDocumentRequest("http://block_all_types.org", ResourceType::Document), { ContentExtensions::ActionType::BlockLoad });
+    testRequest(backend, mainDocumentRequest("http://block_all_types.org", ResourceType::Image), { ContentExtensions::ActionType::BlockLoad });
+    testRequest(backend, mainDocumentRequest("http://block_all_types.org", ResourceType::StyleSheet), { ContentExtensions::ActionType::BlockLoad });
+    testRequest(backend, mainDocumentRequest("http://block_all_types.org", ResourceType::Script), { ContentExtensions::ActionType::BlockLoad });
+    testRequest(backend, mainDocumentRequest("http://block_all_types.org", ResourceType::Font), { ContentExtensions::ActionType::BlockLoad });
+    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_only_images.org", ResourceType::Image), { ContentExtensions::ActionType::BlockLoad });
+    testRequest(backend, mainDocumentRequest("http://block_only_images.org", ResourceType::Document), { });
+}
+
 } // namespace TestWebKitAPI
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to