[Content Extensions] Rename "Domain" to "Condition" where appropriate
authorachristensen@apple.com <achristensen@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 7 Mar 2017 20:54:09 +0000 (20:54 +0000)
committerachristensen@apple.com <achristensen@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 7 Mar 2017 20:54:09 +0000 (20:54 +0000)
https://bugs.webkit.org/show_bug.cgi?id=169297

Reviewed by Brady Eidson.

Source/WebCore:

In r184116 I added the ability for a content blocker author to add conditions to the triggers,
if-domain and unless-domain which look at the domain of the main document URL.
I plan to add more conditions soon to run regexes on the entire URL, but to make that patch more
manageable, I took the non-behavior-changing parts and put them in this patch.

No change in behavior except some error messages were made more generic.

* contentextensions/CompiledContentExtension.h:
* contentextensions/ContentExtension.cpp:
(WebCore::ContentExtensions::ContentExtension::ContentExtension):
(WebCore::ContentExtensions::ContentExtension::compileGlobalDisplayNoneStyleSheet):
(WebCore::ContentExtensions::ContentExtension::populateConditionCacheIfNeeded):
Pass the main document URL instead of just the domain.  No change in behavior yet.
(WebCore::ContentExtensions::ContentExtension::cachedConditionedActions):
(WebCore::ContentExtensions::ContentExtension::universalActionsWithConditions):
(WebCore::ContentExtensions::ContentExtension::populateDomainCacheIfNeeded): Deleted.
(WebCore::ContentExtensions::ContentExtension::cachedDomainActions): Deleted.
(WebCore::ContentExtensions::ContentExtension::universalActionsWithDomains): Deleted.
* contentextensions/ContentExtension.h:
(WebCore::ContentExtensions::ContentExtension::universalActionsWithoutConditions):
(WebCore::ContentExtensions::ContentExtension::universalActionsWithoutDomains): Deleted.
* contentextensions/ContentExtensionCompiler.cpp:
(WebCore::ContentExtensions::serializeActions):
(WebCore::ContentExtensions::compileRuleList):
* contentextensions/ContentExtensionCompiler.h:
* contentextensions/ContentExtensionError.cpp:
(WebCore::ContentExtensions::contentExtensionErrorCategory):
* contentextensions/ContentExtensionError.h:
* contentextensions/ContentExtensionParser.cpp:
(WebCore::ContentExtensions::getStringList):
Don't pass the error type as a parameter.  It's always JSONInvalidConditionList.
(WebCore::ContentExtensions::getDomainList):
(WebCore::ContentExtensions::loadTrigger):
* contentextensions/ContentExtensionRule.h:
(WebCore::ContentExtensions::Trigger::~Trigger):
(WebCore::ContentExtensions::Trigger::isEmpty):
(WebCore::ContentExtensions::Trigger::operator==):
(WebCore::ContentExtensions::TriggerHash::hash):
Use bitwise xor instead of bitwise or to have fewer hash collisions.
Also, before we were accidentally doing the same hash operation here for IfDomain and UnlessDomain.
This caused unnecessary hash collisions.  This is fixed, but should not change any behavior.
* contentextensions/ContentExtensionsBackend.cpp:
(WebCore::ContentExtensions::ContentExtensionsBackend::actionsForResourceLoad):
* contentextensions/DFABytecode.h:
(WebCore::ContentExtensions::instructionSizeWithArguments):
* contentextensions/DFABytecodeCompiler.cpp:
(WebCore::ContentExtensions::DFABytecodeCompiler::emitAppendAction):
* contentextensions/DFABytecodeInterpreter.cpp:
(WebCore::ContentExtensions::matchesCondition):
(WebCore::ContentExtensions::DFABytecodeInterpreter::interpretAppendAction):
(WebCore::ContentExtensions::DFABytecodeInterpreter::interpretTestFlagsAndAppendAction):
(WebCore::ContentExtensions::DFABytecodeInterpreter::actionsMatchingEverything):
(WebCore::ContentExtensions::DFABytecodeInterpreter::interpretWithConditions):
(WebCore::ContentExtensions::DFABytecodeInterpreter::interpret):
(WebCore::ContentExtensions::matchesDomain): Deleted.
(WebCore::ContentExtensions::DFABytecodeInterpreter::interpretWithDomains): Deleted.
* contentextensions/DFABytecodeInterpreter.h:
* loader/ResourceLoadInfo.h:

Source/WebKit2:

* Shared/WebCompiledContentExtension.cpp:
(WebKit::WebCompiledContentExtension::filtersWithoutConditionsBytecode):
(WebKit::WebCompiledContentExtension::filtersWithoutConditionsBytecodeLength):
(WebKit::WebCompiledContentExtension::filtersWithConditionsBytecode):
(WebKit::WebCompiledContentExtension::filtersWithConditionsBytecodeLength):
(WebKit::WebCompiledContentExtension::conditionedFiltersBytecode):
(WebKit::WebCompiledContentExtension::conditionedFiltersBytecodeLength):
(WebKit::WebCompiledContentExtension::filtersWithoutDomainsBytecode): Deleted.
(WebKit::WebCompiledContentExtension::filtersWithoutDomainsBytecodeLength): Deleted.
(WebKit::WebCompiledContentExtension::filtersWithDomainsBytecode): Deleted.
(WebKit::WebCompiledContentExtension::filtersWithDomainsBytecodeLength): Deleted.
(WebKit::WebCompiledContentExtension::domainFiltersBytecode): Deleted.
(WebKit::WebCompiledContentExtension::domainFiltersBytecodeLength): Deleted.
* Shared/WebCompiledContentExtension.h:
* Shared/WebCompiledContentExtensionData.cpp:
(WebKit::WebCompiledContentExtensionData::encode):
(WebKit::WebCompiledContentExtensionData::decode):
* Shared/WebCompiledContentExtensionData.h:
(WebKit::WebCompiledContentExtensionData::WebCompiledContentExtensionData):
* UIProcess/API/APIUserContentExtensionStore.cpp:
(API::ContentExtensionMetaData::fileSize):
(API::encodeContentExtensionMetaData):
(API::decodeContentExtensionMetaData):
(API::compiledToFile):
(API::createExtension):
(API::UserContentExtensionStore::lookupContentExtension):
(API::UserContentExtensionStore::compileContentExtension):
(API::UserContentExtensionStore::removeContentExtension):
* UIProcess/API/APIUserContentExtensionStore.h:

Tools:

* TestWebKitAPI/Tests/WebCore/ContentExtensions.cpp:
(TestWebKitAPI::InMemoryCompiledContentExtension::create):
(TestWebKitAPI::TEST_F):

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

25 files changed:
Source/WebCore/ChangeLog
Source/WebCore/contentextensions/CompiledContentExtension.h
Source/WebCore/contentextensions/ContentExtension.cpp
Source/WebCore/contentextensions/ContentExtension.h
Source/WebCore/contentextensions/ContentExtensionCompiler.cpp
Source/WebCore/contentextensions/ContentExtensionCompiler.h
Source/WebCore/contentextensions/ContentExtensionError.cpp
Source/WebCore/contentextensions/ContentExtensionError.h
Source/WebCore/contentextensions/ContentExtensionParser.cpp
Source/WebCore/contentextensions/ContentExtensionRule.h
Source/WebCore/contentextensions/ContentExtensionsBackend.cpp
Source/WebCore/contentextensions/DFABytecode.h
Source/WebCore/contentextensions/DFABytecodeCompiler.cpp
Source/WebCore/contentextensions/DFABytecodeInterpreter.cpp
Source/WebCore/contentextensions/DFABytecodeInterpreter.h
Source/WebCore/loader/ResourceLoadInfo.h
Source/WebKit2/ChangeLog
Source/WebKit2/Shared/WebCompiledContentExtension.cpp
Source/WebKit2/Shared/WebCompiledContentExtension.h
Source/WebKit2/Shared/WebCompiledContentExtensionData.cpp
Source/WebKit2/Shared/WebCompiledContentExtensionData.h
Source/WebKit2/UIProcess/API/APIUserContentExtensionStore.cpp
Source/WebKit2/UIProcess/API/APIUserContentExtensionStore.h
Tools/ChangeLog
Tools/TestWebKitAPI/Tests/WebCore/ContentExtensions.cpp

index 2bdb6e4..aa72c66 100644 (file)
@@ -1,3 +1,69 @@
+2017-03-07  Alex Christensen  <achristensen@webkit.org>
+
+        [Content Extensions] Rename "Domain" to "Condition" where appropriate
+        https://bugs.webkit.org/show_bug.cgi?id=169297
+
+        Reviewed by Brady Eidson.
+
+        In r184116 I added the ability for a content blocker author to add conditions to the triggers,
+        if-domain and unless-domain which look at the domain of the main document URL.
+        I plan to add more conditions soon to run regexes on the entire URL, but to make that patch more
+        manageable, I took the non-behavior-changing parts and put them in this patch.
+
+        No change in behavior except some error messages were made more generic.
+
+        * contentextensions/CompiledContentExtension.h:
+        * contentextensions/ContentExtension.cpp:
+        (WebCore::ContentExtensions::ContentExtension::ContentExtension):
+        (WebCore::ContentExtensions::ContentExtension::compileGlobalDisplayNoneStyleSheet):
+        (WebCore::ContentExtensions::ContentExtension::populateConditionCacheIfNeeded):
+        Pass the main document URL instead of just the domain.  No change in behavior yet.
+        (WebCore::ContentExtensions::ContentExtension::cachedConditionedActions):
+        (WebCore::ContentExtensions::ContentExtension::universalActionsWithConditions):
+        (WebCore::ContentExtensions::ContentExtension::populateDomainCacheIfNeeded): Deleted.
+        (WebCore::ContentExtensions::ContentExtension::cachedDomainActions): Deleted.
+        (WebCore::ContentExtensions::ContentExtension::universalActionsWithDomains): Deleted.
+        * contentextensions/ContentExtension.h:
+        (WebCore::ContentExtensions::ContentExtension::universalActionsWithoutConditions):
+        (WebCore::ContentExtensions::ContentExtension::universalActionsWithoutDomains): Deleted.
+        * contentextensions/ContentExtensionCompiler.cpp:
+        (WebCore::ContentExtensions::serializeActions):
+        (WebCore::ContentExtensions::compileRuleList):
+        * contentextensions/ContentExtensionCompiler.h:
+        * contentextensions/ContentExtensionError.cpp:
+        (WebCore::ContentExtensions::contentExtensionErrorCategory):
+        * contentextensions/ContentExtensionError.h:
+        * contentextensions/ContentExtensionParser.cpp:
+        (WebCore::ContentExtensions::getStringList):
+        Don't pass the error type as a parameter.  It's always JSONInvalidConditionList.
+        (WebCore::ContentExtensions::getDomainList):
+        (WebCore::ContentExtensions::loadTrigger):
+        * contentextensions/ContentExtensionRule.h:
+        (WebCore::ContentExtensions::Trigger::~Trigger):
+        (WebCore::ContentExtensions::Trigger::isEmpty):
+        (WebCore::ContentExtensions::Trigger::operator==):
+        (WebCore::ContentExtensions::TriggerHash::hash):
+        Use bitwise xor instead of bitwise or to have fewer hash collisions.
+        Also, before we were accidentally doing the same hash operation here for IfDomain and UnlessDomain.
+        This caused unnecessary hash collisions.  This is fixed, but should not change any behavior.
+        * contentextensions/ContentExtensionsBackend.cpp:
+        (WebCore::ContentExtensions::ContentExtensionsBackend::actionsForResourceLoad):
+        * contentextensions/DFABytecode.h:
+        (WebCore::ContentExtensions::instructionSizeWithArguments):
+        * contentextensions/DFABytecodeCompiler.cpp:
+        (WebCore::ContentExtensions::DFABytecodeCompiler::emitAppendAction):
+        * contentextensions/DFABytecodeInterpreter.cpp:
+        (WebCore::ContentExtensions::matchesCondition):
+        (WebCore::ContentExtensions::DFABytecodeInterpreter::interpretAppendAction):
+        (WebCore::ContentExtensions::DFABytecodeInterpreter::interpretTestFlagsAndAppendAction):
+        (WebCore::ContentExtensions::DFABytecodeInterpreter::actionsMatchingEverything):
+        (WebCore::ContentExtensions::DFABytecodeInterpreter::interpretWithConditions):
+        (WebCore::ContentExtensions::DFABytecodeInterpreter::interpret):
+        (WebCore::ContentExtensions::matchesDomain): Deleted.
+        (WebCore::ContentExtensions::DFABytecodeInterpreter::interpretWithDomains): Deleted.
+        * contentextensions/DFABytecodeInterpreter.h:
+        * loader/ResourceLoadInfo.h:
+
 2017-03-07  Michael Catanzaro  <mcatanzaro@igalia.com>
 
         [FreeType] FontPlatformData::fallbacks() returns unprepared FcPatterns
index 47b3d62..5c34e31 100644 (file)
@@ -38,12 +38,12 @@ class WEBCORE_EXPORT CompiledContentExtension : public ThreadSafeRefCounted<Comp
 public:
     virtual ~CompiledContentExtension();
 
-    virtual const DFABytecode* filtersWithoutDomainsBytecode() const = 0;
-    virtual unsigned filtersWithoutDomainsBytecodeLength() const = 0;
-    virtual const DFABytecode* filtersWithDomainsBytecode() const = 0;
-    virtual unsigned filtersWithDomainsBytecodeLength() const = 0;
-    virtual const DFABytecode* domainFiltersBytecode() const = 0;
-    virtual unsigned domainFiltersBytecodeLength() const = 0;
+    virtual const DFABytecode* filtersWithoutConditionsBytecode() const = 0;
+    virtual unsigned filtersWithoutConditionsBytecodeLength() const = 0;
+    virtual const DFABytecode* filtersWithConditionsBytecode() const = 0;
+    virtual unsigned filtersWithConditionsBytecodeLength() const = 0;
+    virtual const DFABytecode* conditionedFiltersBytecode() const = 0;
+    virtual unsigned conditionedFiltersBytecodeLength() const = 0;
     virtual const SerializedActionByte* actions() const = 0;
     virtual unsigned actionsLength() const = 0;
 };
index dacbefe..aa292ed 100644 (file)
@@ -45,20 +45,20 @@ ContentExtension::ContentExtension(const String& identifier, Ref<CompiledContent
     : m_identifier(identifier)
     , m_compiledExtension(WTFMove(compiledExtension))
 {
-    DFABytecodeInterpreter withoutDomains(m_compiledExtension->filtersWithoutDomainsBytecode(), m_compiledExtension->filtersWithoutDomainsBytecodeLength());
-    DFABytecodeInterpreter withDomains(m_compiledExtension->filtersWithDomainsBytecode(), m_compiledExtension->filtersWithDomainsBytecodeLength());
-    for (uint64_t action : withoutDomains.actionsMatchingEverything()) {
+    DFABytecodeInterpreter withoutConditions(m_compiledExtension->filtersWithoutConditionsBytecode(), m_compiledExtension->filtersWithoutConditionsBytecodeLength());
+    DFABytecodeInterpreter withConditions(m_compiledExtension->filtersWithConditionsBytecode(), m_compiledExtension->filtersWithConditionsBytecodeLength());
+    for (uint64_t action : withoutConditions.actionsMatchingEverything()) {
         ASSERT(static_cast<uint32_t>(action) == action);
-        m_universalActionsWithoutDomains.append(static_cast<uint32_t>(action));
+        m_universalActionsWithoutConditions.append(static_cast<uint32_t>(action));
     }
-    for (uint64_t action : withDomains.actionsMatchingEverything()) {
-        ASSERT((action & ~IfDomainFlag) == static_cast<uint32_t>(action));
-        m_universalActionsWithDomains.append(action);
+    for (uint64_t action : withConditions.actionsMatchingEverything()) {
+        ASSERT((action & ~IfConditionFlag) == static_cast<uint32_t>(action));
+        m_universalActionsWithConditions.append(action);
     }
     
     compileGlobalDisplayNoneStyleSheet();
-    m_universalActionsWithoutDomains.shrinkToFit();
-    m_universalActionsWithDomains.shrinkToFit();
+    m_universalActionsWithoutConditions.shrinkToFit();
+    m_universalActionsWithConditions.shrinkToFit();
 }
 
 uint32_t ContentExtension::findFirstIgnorePreviousRules() const
@@ -92,7 +92,7 @@ void ContentExtension::compileGlobalDisplayNoneStyleSheet()
     };
     
     StringBuilder css;
-    for (uint32_t universalActionLocation : m_universalActionsWithoutDomains) {
+    for (uint32_t universalActionLocation : m_universalActionsWithoutConditions) {
         if (inGlobalDisplayNoneStyleSheet(universalActionLocation)) {
             if (!css.isEmpty())
                 css.append(',');
@@ -113,41 +113,42 @@ void ContentExtension::compileGlobalDisplayNoneStyleSheet()
         m_globalDisplayNoneStyleSheet = nullptr;
 
     // These actions don't need to be applied individually any more. They will all be applied to every page as a precompiled style sheet.
-    m_universalActionsWithoutDomains.removeAllMatching(inGlobalDisplayNoneStyleSheet);
+    m_universalActionsWithoutConditions.removeAllMatching(inGlobalDisplayNoneStyleSheet);
 }
 
-void ContentExtension::populateDomainCacheIfNeeded(const String& domain)
+void ContentExtension::populateConditionCacheIfNeeded(const URL& topURL)
 {
+    String domain = topURL.host();
     if (m_cachedDomain != domain) {
-        DFABytecodeInterpreter interpreter(m_compiledExtension->domainFiltersBytecode(), m_compiledExtension->domainFiltersBytecodeLength());
+        DFABytecodeInterpreter interpreter(m_compiledExtension->conditionedFiltersBytecode(), m_compiledExtension->conditionedFiltersBytecodeLength());
         const uint16_t allLoadTypesAndResourceTypes = LoadTypeMask | ResourceTypeMask;
         auto domainActions = interpreter.interpret(domain.utf8(), allLoadTypesAndResourceTypes);
         
-        m_cachedDomainActions.clear();
+        m_cachedConditionedActions.clear();
         for (uint64_t action : domainActions)
-            m_cachedDomainActions.add(action);
+            m_cachedConditionedActions.add(action);
         
-        m_cachedUniversalDomainActions.clear();
-        for (uint64_t action : m_universalActionsWithDomains) {
-            ASSERT_WITH_MESSAGE((action & ~IfDomainFlag) == static_cast<uint32_t>(action), "Universal actions with domains should not have flags.");
-            if (!!(action & IfDomainFlag) == m_cachedDomainActions.contains(action))
-                m_cachedUniversalDomainActions.append(static_cast<uint32_t>(action));
+        m_cachedUniversalConditionedActions.clear();
+        for (uint64_t action : m_universalActionsWithConditions) {
+        ASSERT_WITH_MESSAGE((action & ~IfConditionFlag) == static_cast<uint32_t>(action), "Universal actions with domains should not have flags.");
+            if (!!(action & IfConditionFlag) == m_cachedConditionedActions.contains(action))
+                m_cachedUniversalConditionedActions.append(static_cast<uint32_t>(action));
         }
-        m_cachedUniversalDomainActions.shrinkToFit();
+        m_cachedUniversalConditionedActions.shrinkToFit();
         m_cachedDomain = domain;
     }
 }
 
-const DFABytecodeInterpreter::Actions& ContentExtension::cachedDomainActions(const String& domain)
+const DFABytecodeInterpreter::Actions& ContentExtension::cachedConditionedActions(const URL& topURL)
 {
-    populateDomainCacheIfNeeded(domain);
-    return m_cachedDomainActions;
+    populateConditionCacheIfNeeded(topURL);
+    return m_cachedConditionedActions;
 }
 
-const Vector<uint32_t>& ContentExtension::universalActionsWithDomains(const String& domain)
+const Vector<uint32_t>& ContentExtension::universalActionsWithConditions(const URL& topURL)
 {
-    populateDomainCacheIfNeeded(domain);
-    return m_cachedUniversalDomainActions;
+    populateConditionCacheIfNeeded(topURL);
+    return m_cachedUniversalConditionedActions;
 }
     
 } // namespace ContentExtensions
index 5e7c11b..84539ca 100644 (file)
@@ -46,9 +46,9 @@ public:
     const String& identifier() const { return m_identifier; }
     const CompiledContentExtension& compiledExtension() const { return m_compiledExtension.get(); }
     StyleSheetContents* globalDisplayNoneStyleSheet();
-    const DFABytecodeInterpreter::Actions& cachedDomainActions(const String& domain);
-    const Vector<uint32_t>& universalActionsWithoutDomains() { return m_universalActionsWithoutDomains; }
-    const Vector<uint32_t>& universalActionsWithDomains(const String& domain);
+    const DFABytecodeInterpreter::Actions& cachedConditionedActions(const URL& topURL);
+    const Vector<uint32_t>& universalActionsWithoutConditions() { return m_universalActionsWithoutConditions; }
+    const Vector<uint32_t>& universalActionsWithConditions(const URL& topURL);
 
 private:
     ContentExtension(const String& identifier, Ref<CompiledContentExtension>&&);
@@ -61,12 +61,12 @@ private:
     void compileGlobalDisplayNoneStyleSheet();
 
     String m_cachedDomain;
-    void populateDomainCacheIfNeeded(const String& domain);
-    DFABytecodeInterpreter::Actions m_cachedDomainActions;
-    Vector<uint32_t> m_cachedUniversalDomainActions;
+    void populateConditionCacheIfNeeded(const URL& topURL);
+    DFABytecodeInterpreter::Actions m_cachedConditionedActions;
+    Vector<uint32_t> m_cachedUniversalConditionedActions;
 
-    Vector<uint32_t> m_universalActionsWithoutDomains;
-    Vector<uint64_t> m_universalActionsWithDomains;
+    Vector<uint32_t> m_universalActionsWithoutConditions;
+    Vector<uint64_t> m_universalActionsWithConditions;
 };
 
 } // namespace ContentExtensions
index e53c6c7..d20d6d0 100644 (file)
@@ -125,9 +125,9 @@ static Vector<unsigned> serializeActions(const Vector<ContentExtensionRule>& rul
         } else
             ignorePreviousRuleActionsMap.clear();
 
-        // Anything with domain is just pushed.
-        // We could try to merge domains but that case is not common in practice.
-        if (!rule.trigger().domains.isEmpty()) {
+        // Anything with condition is just pushed.
+        // We could try to merge conditions but that case is not common in practice.
+        if (!rule.trigger().conditions.isEmpty()) {
             actionLocations.append(actions.size());
 
             if (actionType == ActionType::CSSDisplayNoneSelector)
@@ -222,15 +222,15 @@ std::error_code compileRuleList(ContentExtensionCompilationClient& client, Strin
     LOG_LARGE_STRUCTURES(actions, actions.capacity() * sizeof(SerializedActionByte));
     actions.clear();
 
-    UniversalActionSet universalActionsWithoutDomains;
-    UniversalActionSet universalActionsWithDomains;
+    UniversalActionSet universalActionsWithoutConditions;
+    UniversalActionSet universalActionsWithConditions;
 
     // FIXME: These don't all need to be in memory at the same time.
-    CombinedURLFilters filtersWithoutDomains;
-    CombinedURLFilters filtersWithDomains;
-    CombinedURLFilters domainFilters;
-    URLFilterParser filtersWithoutDomainParser(filtersWithoutDomains);
-    URLFilterParser filtersWithDomainParser(filtersWithDomains);
+    CombinedURLFilters filtersWithoutConditions;
+    CombinedURLFilters filtersWithConditions;
+    CombinedURLFilters conditionFilters;
+    URLFilterParser filtersWithoutConditionParser(filtersWithoutConditions);
+    URLFilterParser filtersWithConditionParser(filtersWithConditions);
     
     for (unsigned ruleIndex = 0; ruleIndex < parsedRuleList.size(); ++ruleIndex) {
         const ContentExtensionRule& contentExtensionRule = parsedRuleList[ruleIndex];
@@ -242,11 +242,11 @@ std::error_code compileRuleList(ContentExtensionCompilationClient& client, Strin
         ASSERT(!(~ActionFlagMask & (static_cast<uint64_t>(trigger.flags) << 32)));
         uint64_t actionLocationAndFlags = (static_cast<uint64_t>(trigger.flags) << 32) | static_cast<uint64_t>(actionLocations[ruleIndex]);
         URLFilterParser::ParseStatus status = URLFilterParser::Ok;
-        if (trigger.domains.isEmpty()) {
-            ASSERT(trigger.domainCondition == Trigger::DomainCondition::None);
-            status = filtersWithoutDomainParser.addPattern(trigger.urlFilter, trigger.urlFilterIsCaseSensitive, actionLocationAndFlags);
+        if (trigger.conditions.isEmpty()) {
+            ASSERT(trigger.conditionType == Trigger::ConditionType::None);
+            status = filtersWithoutConditionParser.addPattern(trigger.urlFilter, trigger.urlFilterIsCaseSensitive, actionLocationAndFlags);
             if (status == URLFilterParser::MatchesEverything) {
-                universalActionsWithoutDomains.add(actionLocationAndFlags);
+                universalActionsWithoutConditions.add(actionLocationAndFlags);
                 status = URLFilterParser::Ok;
             }
             if (status != URLFilterParser::Ok) {
@@ -254,24 +254,27 @@ std::error_code compileRuleList(ContentExtensionCompilationClient& client, Strin
                 return ContentExtensionError::JSONInvalidRegex;
             }
         } else {
-            if (trigger.domainCondition == Trigger::DomainCondition::IfDomain)
-                actionLocationAndFlags |= IfDomainFlag;
-            else {
-                ASSERT(trigger.domainCondition == Trigger::DomainCondition::UnlessDomain);
-                ASSERT(!(actionLocationAndFlags & IfDomainFlag));
+            switch (trigger.conditionType) {
+            case Trigger::ConditionType::IfDomain:
+                actionLocationAndFlags |= IfConditionFlag;
+                break;
+            case Trigger::ConditionType::None:
+            case Trigger::ConditionType::UnlessDomain:
+                ASSERT(!(actionLocationAndFlags & IfConditionFlag));
+                break;
             }
             
-            status = filtersWithDomainParser.addPattern(trigger.urlFilter, trigger.urlFilterIsCaseSensitive, actionLocationAndFlags);
+            status = filtersWithConditionParser.addPattern(trigger.urlFilter, trigger.urlFilterIsCaseSensitive, actionLocationAndFlags);
             if (status == URLFilterParser::MatchesEverything) {
-                universalActionsWithDomains.add(actionLocationAndFlags);
+                universalActionsWithConditions.add(actionLocationAndFlags);
                 status = URLFilterParser::Ok;
             }
             if (status != URLFilterParser::Ok) {
                 dataLogF("Error while parsing %s: %s\n", trigger.urlFilter.utf8().data(), URLFilterParser::statusString(status).utf8().data());
                 return ContentExtensionError::JSONInvalidRegex;
             }
-            for (const String& domain : trigger.domains)
-                domainFilters.addDomain(actionLocationAndFlags, domain);
+            for (const String& condition : trigger.conditions)
+                conditionFilters.addDomain(actionLocationAndFlags, condition);
         }
         ASSERT(status == URLFilterParser::Ok);
     }
@@ -285,15 +288,15 @@ std::error_code compileRuleList(ContentExtensionCompilationClient& client, Strin
     dataLogF("    Time spent partitioning the rules into groups: %f\n", (patternPartitioningEnd - patternPartitioningStart));
 #endif
 
-    LOG_LARGE_STRUCTURES(filtersWithoutDomains, filtersWithoutDomains.memoryUsed());
-    LOG_LARGE_STRUCTURES(filtersWithDomains, filtersWithDomains.memoryUsed());
-    LOG_LARGE_STRUCTURES(domainFilters, domainFilters.memoryUsed());
+    LOG_LARGE_STRUCTURES(filtersWithoutConditions, filtersWithoutConditions.memoryUsed());
+    LOG_LARGE_STRUCTURES(filtersWithConditions, filtersWithConditions.memoryUsed());
+    LOG_LARGE_STRUCTURES(conditionFilters, conditionFilters.memoryUsed());
 
 #if CONTENT_EXTENSIONS_PERFORMANCE_REPORTING
-    unsigned machinesWithoutDomainsCount = 0;
-    unsigned totalBytecodeSizeForMachinesWithoutDomains = 0;
-    unsigned machinesWithDomainsCount = 0;
-    unsigned totalBytecodeSizeForMachinesWithDomains = 0;
+    unsigned machinesWithoutConditionsCount = 0;
+    unsigned totalBytecodeSizeForMachinesWithoutConditions = 0;
+    unsigned machinesWithConditionsCount = 0;
+    unsigned totalBytecodeSizeForMachinesWithConditions = 0;
     double totalNFAToByteCodeBuildTimeStart = monotonicallyIncreasingTime();
 #endif
 
@@ -301,19 +304,19 @@ std::error_code compileRuleList(ContentExtensionCompilationClient& client, Strin
     // larger maxNFASizes use too much memory when compiling.
     const unsigned maxNFASize = 75000;
     
-    bool firstNFAWithoutDomainsSeen = false;
+    bool firstNFAWithoutConditionsSeen = false;
 
-    auto lowerFiltersWithoutDomainsDFAToBytecode = [&](DFA&& dfa)
+    auto lowerFiltersWithoutConditionsDFAToBytecode = [&](DFA&& dfa)
     {
 #if CONTENT_EXTENSIONS_STATE_MACHINE_DEBUGGING
-        dataLogF("filtersWithoutDomains DFA\n");
+        dataLogF("filtersWithoutConditions DFA\n");
         dfa.debugPrintDot();
 #endif
         ASSERT_WITH_MESSAGE(!dfa.nodes[dfa.root].hasActions(), "All actions on the DFA root should come from regular expressions that match everything.");
 
-        if (!firstNFAWithoutDomainsSeen) {
+        if (!firstNFAWithoutConditionsSeen) {
             // Put all the universal actions on the first DFA.
-            addUniversalActionsToDFA(dfa, universalActionsWithoutDomains);
+            addUniversalActionsToDFA(dfa, universalActionsWithoutConditions);
         }
 
         Vector<DFABytecode> bytecode;
@@ -321,19 +324,19 @@ std::error_code compileRuleList(ContentExtensionCompilationClient& client, Strin
         compiler.compile();
         LOG_LARGE_STRUCTURES(bytecode, bytecode.capacity() * sizeof(uint8_t));
 #if CONTENT_EXTENSIONS_PERFORMANCE_REPORTING
-        ++machinesWithoutDomainsCount;
-        totalBytecodeSizeForMachinesWithoutDomains += bytecode.size();
+        ++machinesWithoutConditionsCount;
+        totalBytecodeSizeForMachinesWithoutConditions += bytecode.size();
 #endif
-        client.writeFiltersWithoutDomainsBytecode(WTFMove(bytecode));
+        client.writeFiltersWithoutConditionsBytecode(WTFMove(bytecode));
 
-        firstNFAWithoutDomainsSeen = true;
+        firstNFAWithoutConditionsSeen = true;
     };
 
     const unsigned smallDFASize = 100;
-    DFACombiner smallFiltersWithoutDomainsDFACombiner;
-    filtersWithoutDomains.processNFAs(maxNFASize, [&](NFA&& nfa) {
+    DFACombiner smallFiltersWithoutConditionsDFACombiner;
+    filtersWithoutConditions.processNFAs(maxNFASize, [&](NFA&& nfa) {
 #if CONTENT_EXTENSIONS_STATE_MACHINE_DEBUGGING
-        dataLogF("filtersWithoutDomains NFA\n");
+        dataLogF("filtersWithoutConditions NFA\n");
         nfa.debugPrintDot();
 #endif
 
@@ -342,43 +345,43 @@ std::error_code compileRuleList(ContentExtensionCompilationClient& client, Strin
         LOG_LARGE_STRUCTURES(dfa, dfa.memoryUsed());
 
         if (dfa.graphSize() < smallDFASize)
-            smallFiltersWithoutDomainsDFACombiner.addDFA(WTFMove(dfa));
+            smallFiltersWithoutConditionsDFACombiner.addDFA(WTFMove(dfa));
         else {
             dfa.minimize();
-            lowerFiltersWithoutDomainsDFAToBytecode(WTFMove(dfa));
+            lowerFiltersWithoutConditionsDFAToBytecode(WTFMove(dfa));
         }
     });
 
 
-    smallFiltersWithoutDomainsDFACombiner.combineDFAs(smallDFASize, [&](DFA&& dfa) {
+    smallFiltersWithoutConditionsDFACombiner.combineDFAs(smallDFASize, [&](DFA&& dfa) {
         LOG_LARGE_STRUCTURES(dfa, dfa.memoryUsed());
-        lowerFiltersWithoutDomainsDFAToBytecode(WTFMove(dfa));
+        lowerFiltersWithoutConditionsDFAToBytecode(WTFMove(dfa));
     });
 
-    ASSERT(filtersWithoutDomains.isEmpty());
+    ASSERT(filtersWithoutConditions.isEmpty());
 
-    if (!firstNFAWithoutDomainsSeen) {
+    if (!firstNFAWithoutConditionsSeen) {
         // Our bytecode interpreter expects to have at least one DFA, so if we haven't seen any
         // create a dummy one and add any universal actions.
 
         DFA dummyDFA = DFA::empty();
-        addUniversalActionsToDFA(dummyDFA, universalActionsWithoutDomains);
+        addUniversalActionsToDFA(dummyDFA, universalActionsWithoutConditions);
 
         Vector<DFABytecode> bytecode;
         DFABytecodeCompiler compiler(dummyDFA, bytecode);
         compiler.compile();
         LOG_LARGE_STRUCTURES(bytecode, bytecode.capacity() * sizeof(uint8_t));
-        client.writeFiltersWithoutDomainsBytecode(WTFMove(bytecode));
+        client.writeFiltersWithoutConditionsBytecode(WTFMove(bytecode));
     }
-    LOG_LARGE_STRUCTURES(universalActionsWithoutDomains, universalActionsWithoutDomains.capacity() * sizeof(unsigned));
-    universalActionsWithoutDomains.clear();
+    LOG_LARGE_STRUCTURES(universalActionsWithoutConditions, universalActionsWithoutConditions.capacity() * sizeof(unsigned));
+    universalActionsWithoutConditions.clear();
     
-    bool firstNFAWithDomainsSeen = false;
-    auto lowerFiltersWithDomainsDFAToBytecode = [&](DFA&& dfa)
+    bool firstNFAWithConditionsSeen = false;
+    auto lowerFiltersWithConditionsDFAToBytecode = [&](DFA&& dfa)
     {
-        if (!firstNFAWithDomainsSeen) {
+        if (!firstNFAWithConditionsSeen) {
             // Put all the universal actions on the first DFA.
-            addUniversalActionsToDFA(dfa, universalActionsWithDomains);
+            addUniversalActionsToDFA(dfa, universalActionsWithConditions);
         }
 
         Vector<DFABytecode> bytecode;
@@ -386,89 +389,89 @@ std::error_code compileRuleList(ContentExtensionCompilationClient& client, Strin
         compiler.compile();
         LOG_LARGE_STRUCTURES(bytecode, bytecode.capacity() * sizeof(uint8_t));
 #if CONTENT_EXTENSIONS_PERFORMANCE_REPORTING
-        ++machinesWithDomainsCount;
-        totalBytecodeSizeForMachinesWithDomains += bytecode.size();
+        ++machinesWithConditionsCount;
+        totalBytecodeSizeForMachinesWithConditions += bytecode.size();
 #endif
-        client.writeFiltersWithDomainsBytecode(WTFMove(bytecode));
+        client.writeFiltersWithConditionsBytecode(WTFMove(bytecode));
 
-        firstNFAWithDomainsSeen = true;
+        firstNFAWithConditionsSeen = true;
     };
 
-    DFACombiner smallFiltersWithDomainsDFACombiner;
-    filtersWithDomains.processNFAs(maxNFASize, [&](NFA&& nfa) {
+    DFACombiner smallFiltersWithConditionsDFACombiner;
+    filtersWithConditions.processNFAs(maxNFASize, [&](NFA&& nfa) {
 #if CONTENT_EXTENSIONS_STATE_MACHINE_DEBUGGING
-        dataLogF("filtersWithDomains NFA\n");
+        dataLogF("filtersWithConditions NFA\n");
         nfa.debugPrintDot();
 #endif
         LOG_LARGE_STRUCTURES(nfa, nfa.memoryUsed());
         DFA dfa = NFAToDFA::convert(nfa);
 #if CONTENT_EXTENSIONS_STATE_MACHINE_DEBUGGING
-        dataLogF("filtersWithDomains PRE MINIMIZING DFA\n");
+        dataLogF("filtersWithConditions PRE MINIMIZING DFA\n");
         dfa.debugPrintDot();
 #endif
         LOG_LARGE_STRUCTURES(dfa, dfa.memoryUsed());
 
-        ASSERT_WITH_MESSAGE(!dfa.nodes[dfa.root].hasActions(), "Filters with domains that match everything are not allowed right now.");
+        ASSERT_WITH_MESSAGE(!dfa.nodes[dfa.root].hasActions(), "Filters with Conditions that match everything are not allowed right now.");
 
         if (dfa.graphSize() < smallDFASize)
-            smallFiltersWithDomainsDFACombiner.addDFA(WTFMove(dfa));
+            smallFiltersWithConditionsDFACombiner.addDFA(WTFMove(dfa));
         else {
             dfa.minimize();
-            lowerFiltersWithDomainsDFAToBytecode(WTFMove(dfa));
+            lowerFiltersWithConditionsDFAToBytecode(WTFMove(dfa));
         }
     });
-    smallFiltersWithDomainsDFACombiner.combineDFAs(smallDFASize, [&](DFA&& dfa) {
+    smallFiltersWithConditionsDFACombiner.combineDFAs(smallDFASize, [&](DFA&& dfa) {
         LOG_LARGE_STRUCTURES(dfa, dfa.memoryUsed());
-        lowerFiltersWithDomainsDFAToBytecode(WTFMove(dfa));
+        lowerFiltersWithConditionsDFAToBytecode(WTFMove(dfa));
     });
-    ASSERT(filtersWithDomains.isEmpty());
+    ASSERT(filtersWithConditions.isEmpty());
     
-    if (!firstNFAWithDomainsSeen) {
+    if (!firstNFAWithConditionsSeen) {
         // Our bytecode interpreter expects to have at least one DFA, so if we haven't seen any
         // create a dummy one and add any universal actions.
 
         DFA dummyDFA = DFA::empty();
-        addUniversalActionsToDFA(dummyDFA, universalActionsWithDomains);
+        addUniversalActionsToDFA(dummyDFA, universalActionsWithConditions);
         
         Vector<DFABytecode> bytecode;
         DFABytecodeCompiler compiler(dummyDFA, bytecode);
         compiler.compile();
         LOG_LARGE_STRUCTURES(bytecode, bytecode.capacity() * sizeof(uint8_t));
-        client.writeFiltersWithDomainsBytecode(WTFMove(bytecode));
+        client.writeFiltersWithConditionsBytecode(WTFMove(bytecode));
     }
-    LOG_LARGE_STRUCTURES(universalActionsWithDomains, universalActionsWithDomains.capacity() * sizeof(unsigned));
-    universalActionsWithDomains.clear();
+    LOG_LARGE_STRUCTURES(universalActionsWithConditions, universalActionsWithConditions.capacity() * sizeof(unsigned));
+    universalActionsWithConditions.clear();
 
-    domainFilters.processNFAs(maxNFASize, [&](NFA&& nfa) {
+    conditionFilters.processNFAs(maxNFASize, [&](NFA&& nfa) {
 #if CONTENT_EXTENSIONS_STATE_MACHINE_DEBUGGING
-        dataLogF("domainFilters NFA\n");
+        dataLogF("conditionFilters NFA\n");
         nfa.debugPrintDot();
 #endif
         LOG_LARGE_STRUCTURES(nfa, nfa.memoryUsed());
         DFA dfa = NFAToDFA::convert(nfa);
 #if CONTENT_EXTENSIONS_STATE_MACHINE_DEBUGGING
-        dataLogF("domainFilters DFA\n");
+        dataLogF("conditionFilters DFA\n");
         dfa.debugPrintDot();
 #endif
         LOG_LARGE_STRUCTURES(dfa, dfa.memoryUsed());
         // Minimizing this DFA would not be effective because all actions are unique
         // and because of the tree-like structure of this DFA.
-        ASSERT_WITH_MESSAGE(!dfa.nodes[dfa.root].hasActions(), "There should not be any domains that match everything.");
+        ASSERT_WITH_MESSAGE(!dfa.nodes[dfa.root].hasActions(), "There should not be any conditions that match everything.");
 
         Vector<DFABytecode> bytecode;
         DFABytecodeCompiler compiler(dfa, bytecode);
         compiler.compile();
         LOG_LARGE_STRUCTURES(bytecode, bytecode.capacity() * sizeof(uint8_t));
-        client.writeDomainFiltersBytecode(WTFMove(bytecode));
+        client.writeConditionedFiltersBytecode(WTFMove(bytecode));
     });
-    ASSERT(domainFilters.isEmpty());    
+    ASSERT(conditionFilters.isEmpty());
     
 #if CONTENT_EXTENSIONS_PERFORMANCE_REPORTING
     double totalNFAToByteCodeBuildTimeEnd = monotonicallyIncreasingTime();
     dataLogF("    Time spent building and compiling the DFAs: %f\n", (totalNFAToByteCodeBuildTimeEnd - totalNFAToByteCodeBuildTimeStart));
 
-    dataLogF("    Number of machines without domain filters: %d (total bytecode size = %d)\n", machinesWithoutDomainsCount, totalBytecodeSizeForMachinesWithoutDomains);
-    dataLogF("    Number of machines with domain filters: %d (total bytecode size = %d)\n", machinesWithDomainsCount, totalBytecodeSizeForMachinesWithDomains);
+    dataLogF("    Number of machines without condition filters: %d (total bytecode size = %d)\n", machinesWithoutConditionsCount, totalBytecodeSizeForMachinesWithoutConditions);
+    dataLogF("    Number of machines with condition filters: %d (total bytecode size = %d)\n", machinesWithConditionsCount, totalBytecodeSizeForMachinesWithConditions);
 #endif
 
     client.finalize();
index 3928f95..ab96972 100644 (file)
@@ -41,9 +41,9 @@ public:
     
     // Functions should be called in this order. All except writeActions and finalize can be called multiple times, though.
     virtual void writeActions(Vector<SerializedActionByte>&&) = 0;
-    virtual void writeFiltersWithoutDomainsBytecode(Vector<DFABytecode>&&) = 0;
-    virtual void writeFiltersWithDomainsBytecode(Vector<DFABytecode>&&) = 0;
-    virtual void writeDomainFiltersBytecode(Vector<DFABytecode>&&) = 0;
+    virtual void writeFiltersWithoutConditionsBytecode(Vector<DFABytecode>&&) = 0;
+    virtual void writeFiltersWithConditionsBytecode(Vector<DFABytecode>&&) = 0;
+    virtual void writeConditionedFiltersBytecode(Vector<DFABytecode>&&) = 0;
     virtual void finalize() = 0;
 };
 
index 52e9cf2..98fcdb5 100644 (file)
@@ -77,14 +77,14 @@ const std::error_category& contentExtensionErrorCategory()
                 return "Invalid css-display-none action type. Requires a selector.";
             case ContentExtensionError::JSONInvalidRegex:
                 return "Invalid or unsupported regular expression.";
-            case ContentExtensionError::JSONInvalidDomainList:
-                return "Invalid domain list.";
+            case ContentExtensionError::JSONInvalidConditionList:
+                return "Invalid list of if-domain or unless-domain conditions.";
             case ContentExtensionError::JSONTooManyRules:
                 return "Too many rules in JSON array.";
             case ContentExtensionError::JSONDomainNotLowerCaseASCII:
                 return "Domains must be lower case ASCII. Use punycode to encode non-ASCII characters.";
-            case ContentExtensionError::JSONUnlessAndIfDomain:
-                return "A trigger cannot have both unless- and if-domain.";
+            case ContentExtensionError::JSONMultipleConditions:
+                return "A trigger cannot have more than one condition (if-domain or unless-domain)";
             }
 
             return std::string();
index 35462ba..724bc0c 100644 (file)
@@ -49,9 +49,9 @@ enum class ContentExtensionError {
     JSONInvalidTriggerFlagsArray,
     JSONInvalidObjectInTriggerFlagsArray,
     JSONInvalidStringInTriggerFlagsArray,
-    JSONInvalidDomainList,
+    JSONInvalidConditionList,
     JSONDomainNotLowerCaseASCII,
-    JSONUnlessAndIfDomain,
+    JSONMultipleConditions,
     JSONTooManyRules,
     
     JSONInvalidAction,
index 21a986d..804bd5c 100644 (file)
@@ -59,8 +59,9 @@ static bool containsOnlyASCIIWithNoUppercase(const String& domain)
     return true;
 }
     
-static Expected<Vector<String>, std::error_code> getStringList(ExecState& exec, const JSObject* arrayObject, ContentExtensionError error)
+static Expected<Vector<String>, std::error_code> getStringList(ExecState& exec, const JSObject* arrayObject)
 {
+    static const ContentExtensionError error = ContentExtensionError::JSONInvalidConditionList;
     VM& vm = exec.vm();
     auto scope = DECLARE_THROW_SCOPE(vm);
 
@@ -68,24 +69,24 @@ static Expected<Vector<String>, std::error_code> getStringList(ExecState& exec,
         return makeUnexpected(error);
     const JSArray* array = jsCast<const JSArray*>(arrayObject);
     
-    Vector<String> domains;
+    Vector<String> strings;
     unsigned length = array->length();
     for (unsigned i = 0; i < length; ++i) {
         const JSValue value = array->getIndex(&exec, i);
         if (scope.exception() || !value.isString())
             return makeUnexpected(error);
         
-        const String& domain = asString(value)->value(&exec);
-        if (domain.isEmpty())
+        const String& string = asString(value)->value(&exec);
+        if (string.isEmpty())
             return makeUnexpected(error);
-        domains.append(domain);
+        strings.append(string);
     }
-    return WTFMove(domains);
+    return WTFMove(strings);
 }
 
 static Expected<Vector<String>, std::error_code> getDomainList(ExecState& exec, const JSObject* arrayObject)
 {
-    auto strings = getStringList(exec, arrayObject, ContentExtensionError::JSONInvalidDomainList);
+    auto strings = getStringList(exec, arrayObject);
     if (!strings.hasValue())
         return strings;
     for (auto& domain : strings.value()) {
@@ -173,27 +174,27 @@ static Expected<Trigger, std::error_code> loadTrigger(ExecState& exec, const JSO
         auto ifDomain = getDomainList(exec, asObject(ifDomainValue));
         if (!ifDomain.hasValue())
             return makeUnexpected(ifDomain.error());
-        trigger.domains = WTFMove(ifDomain.value());
-        if (trigger.domains.isEmpty())
-            return makeUnexpected(ContentExtensionError::JSONInvalidDomainList);
-        ASSERT(trigger.domainCondition == Trigger::DomainCondition::None);
-        trigger.domainCondition = Trigger::DomainCondition::IfDomain;
+        trigger.conditions = WTFMove(ifDomain.value());
+        if (trigger.conditions.isEmpty())
+            return makeUnexpected(ContentExtensionError::JSONInvalidConditionList);
+        ASSERT(trigger.conditionType == Trigger::ConditionType::None);
+        trigger.conditionType = Trigger::ConditionType::IfDomain;
     } else if (!ifDomainValue.isUndefined())
-        return makeUnexpected(ContentExtensionError::JSONInvalidDomainList);
-    
+        return makeUnexpected(ContentExtensionError::JSONInvalidConditionList);
+
     const JSValue unlessDomainValue = triggerObject.get(&exec, Identifier::fromString(&exec, "unless-domain"));
     if (!scope.exception() && unlessDomainValue.isObject()) {
-        if (trigger.domainCondition != Trigger::DomainCondition::None)
-            return makeUnexpected(ContentExtensionError::JSONUnlessAndIfDomain);
+        if (trigger.conditionType != Trigger::ConditionType::None)
+            return makeUnexpected(ContentExtensionError::JSONMultipleConditions);
         auto unlessDomain = getDomainList(exec, asObject(unlessDomainValue));
         if (!unlessDomain.hasValue())
             return makeUnexpected(unlessDomain.error());
-        trigger.domains = WTFMove(unlessDomain.value());
-        if (trigger.domains.isEmpty())
-            return makeUnexpected(ContentExtensionError::JSONInvalidDomainList);
-        trigger.domainCondition = Trigger::DomainCondition::UnlessDomain;
+        trigger.conditions = WTFMove(unlessDomain.value());
+        if (trigger.conditions.isEmpty())
+            return makeUnexpected(ContentExtensionError::JSONInvalidConditionList);
+        trigger.conditionType = Trigger::ConditionType::UnlessDomain;
     } else if (!unlessDomainValue.isUndefined())
-        return makeUnexpected(ContentExtensionError::JSONInvalidDomainList);
+        return makeUnexpected(ContentExtensionError::JSONInvalidConditionList);
 
     return WTFMove(trigger);
 }
index 0234003..4d69c2b 100644 (file)
@@ -44,16 +44,16 @@ struct Trigger {
     String urlFilter;
     bool urlFilterIsCaseSensitive { false };
     ResourceFlags flags { 0 };
-    Vector<String> domains;
-    enum class DomainCondition {
+    Vector<String> conditions;
+    enum class ConditionType {
         None,
         IfDomain,
         UnlessDomain,
-    } domainCondition { DomainCondition::None };
+    } conditionType { ConditionType::None };
 
     ~Trigger()
     {
-        ASSERT(domains.isEmpty() == (domainCondition == DomainCondition::None));
+        ASSERT(conditions.isEmpty() == (conditionType == ConditionType::None));
     }
 
     bool isEmpty() const
@@ -61,8 +61,8 @@ struct Trigger {
         return urlFilter.isEmpty()
             && !urlFilterIsCaseSensitive
             && !flags
-            && domains.isEmpty()
-            && domainCondition == DomainCondition::None;
+            && conditions.isEmpty()
+            && conditionType == ConditionType::None;
     }
 
     bool operator==(const Trigger& other) const
@@ -70,8 +70,8 @@ struct Trigger {
         return urlFilter == other.urlFilter
             && urlFilterIsCaseSensitive == other.urlFilterIsCaseSensitive
             && flags == other.flags
-            && domains == other.domains
-            && domainCondition == other.domainCondition;
+            && conditions == other.conditions
+            && conditionType == other.conditionType;
     }
 };
 
@@ -83,13 +83,10 @@ struct TriggerHash {
             hash ^= StringHash::hash(trigger.urlFilter);
         hash = WTF::pairIntHash(hash, DefaultHash<ResourceFlags>::Hash::hash(trigger.flags));
 
-        for (const String& domain : trigger.domains)
-            hash ^= StringHash::hash(domain);
+        for (const String& condition : trigger.conditions)
+            hash ^= StringHash::hash(condition);
 
-        if (trigger.domainCondition == Trigger::DomainCondition::IfDomain)
-            hash |= 1 << 16;
-        else if (trigger.domainCondition == Trigger::DomainCondition::IfDomain)
-            hash |= 1 << 31;
+        hash ^= 1 << static_cast<unsigned>(trigger.conditionType);
         return hash;
     }
 
index 83ea96e..fcdafae 100644 (file)
@@ -91,29 +91,29 @@ Vector<Action> ContentExtensionsBackend::actionsForResourceLoad(const ResourceLo
         RELEASE_ASSERT(contentExtension);
         const CompiledContentExtension& compiledExtension = contentExtension->compiledExtension();
         
-        DFABytecodeInterpreter withoutDomainsInterpreter(compiledExtension.filtersWithoutDomainsBytecode(), compiledExtension.filtersWithoutDomainsBytecodeLength());
-        DFABytecodeInterpreter::Actions withoutDomainsActions = withoutDomainsInterpreter.interpret(urlCString, flags);
+        DFABytecodeInterpreter withoutConditionsInterpreter(compiledExtension.filtersWithoutConditionsBytecode(), compiledExtension.filtersWithoutConditionsBytecodeLength());
+        DFABytecodeInterpreter::Actions withoutConditionsActions = withoutConditionsInterpreter.interpret(urlCString, flags);
         
-        String domain = resourceLoadInfo.mainDocumentURL.host();
-        DFABytecodeInterpreter withDomainsInterpreter(compiledExtension.filtersWithDomainsBytecode(), compiledExtension.filtersWithDomainsBytecodeLength());
-        DFABytecodeInterpreter::Actions withDomainsActions = withDomainsInterpreter.interpretWithDomains(urlCString, flags, contentExtension->cachedDomainActions(domain));
+        URL topURL = resourceLoadInfo.mainDocumentURL;
+        DFABytecodeInterpreter withConditionsInterpreter(compiledExtension.filtersWithConditionsBytecode(), compiledExtension.filtersWithConditionsBytecodeLength());
+        DFABytecodeInterpreter::Actions withConditionsActions = withConditionsInterpreter.interpretWithConditions(urlCString, flags, contentExtension->cachedConditionedActions(topURL));
         
         const SerializedActionByte* actions = compiledExtension.actions();
         const unsigned actionsLength = compiledExtension.actionsLength();
         
         bool sawIgnorePreviousRules = false;
-        const Vector<uint32_t>& universalWithDomains = contentExtension->universalActionsWithDomains(domain);
-        const Vector<uint32_t>& universalWithoutDomains = contentExtension->universalActionsWithoutDomains();
-        if (!withoutDomainsActions.isEmpty() || !withDomainsActions.isEmpty() || !universalWithDomains.isEmpty() || !universalWithoutDomains.isEmpty()) {
+        const Vector<uint32_t>& universalWithConditions = contentExtension->universalActionsWithConditions(topURL);
+        const Vector<uint32_t>& universalWithoutConditions = contentExtension->universalActionsWithoutConditions();
+        if (!withoutConditionsActions.isEmpty() || !withConditionsActions.isEmpty() || !universalWithConditions.isEmpty() || !universalWithoutConditions.isEmpty()) {
             Vector<uint32_t> actionLocations;
-            actionLocations.reserveInitialCapacity(withoutDomainsActions.size() + withDomainsActions.size() + universalWithoutDomains.size() + universalWithDomains.size());
-            for (uint64_t actionLocation : withoutDomainsActions)
+            actionLocations.reserveInitialCapacity(withoutConditionsActions.size() + withConditionsActions.size() + universalWithoutConditions.size() + universalWithConditions.size());
+            for (uint64_t actionLocation : withoutConditionsActions)
                 actionLocations.uncheckedAppend(static_cast<uint32_t>(actionLocation));
-            for (uint64_t actionLocation : withDomainsActions)
+            for (uint64_t actionLocation : withConditionsActions)
                 actionLocations.uncheckedAppend(static_cast<uint32_t>(actionLocation));
-            for (uint32_t actionLocation : universalWithoutDomains)
+            for (uint32_t actionLocation : universalWithoutConditions)
                 actionLocations.uncheckedAppend(actionLocation);
-            for (uint32_t actionLocation : universalWithDomains)
+            for (uint32_t actionLocation : universalWithConditions)
                 actionLocations.uncheckedAppend(actionLocation);
             std::sort(actionLocations.begin(), actionLocations.end());
 
index 50981c2..ad34d13 100644 (file)
@@ -62,13 +62,13 @@ enum class DFABytecodeInstruction : uint8_t {
     // AppendAction has one argument:
     // The action to append (4 bytes).
     AppendAction = 0x6,
-    AppendActionWithIfDomain = 0x7,
+    AppendActionWithIfCondition = 0x7,
     
     // TestFlagsAndAppendAction has two arguments:
     // The flags to check before appending (2 bytes).
     // The action to append (4 bytes).
     TestFlagsAndAppendAction = 0x8,
-    TestFlagsAndAppendActionWithIfDomain = 0x9,
+    TestFlagsAndAppendActionWithIfCondition = 0x9,
 
     // Terminate has no arguments.
     Terminate = 0xA,
@@ -118,10 +118,10 @@ static inline size_t instructionSizeWithArguments(DFABytecodeInstruction instruc
     case DFABytecodeInstruction::Jump:
         RELEASE_ASSERT_NOT_REACHED(); // Variable instruction size.
     case DFABytecodeInstruction::AppendAction:
-    case DFABytecodeInstruction::AppendActionWithIfDomain:
+    case DFABytecodeInstruction::AppendActionWithIfCondition:
         return sizeof(DFABytecodeInstruction) + sizeof(uint32_t);
     case DFABytecodeInstruction::TestFlagsAndAppendAction:
-    case DFABytecodeInstruction::TestFlagsAndAppendActionWithIfDomain:
+    case DFABytecodeInstruction::TestFlagsAndAppendActionWithIfCondition:
         return sizeof(DFABytecodeInstruction) + sizeof(uint16_t) + sizeof(uint32_t);
     case DFABytecodeInstruction::Terminate:
         return sizeof(DFABytecodeInstruction);
index c9c5f8b..300aa64 100644 (file)
@@ -81,15 +81,15 @@ void DFABytecodeCompiler::emitAppendAction(uint64_t action)
 {
     // High bits are used to store flags. See compileRuleList.
     if (action & ActionFlagMask) {
-        if (action & IfDomainFlag)
-            append<DFABytecodeInstruction>(m_bytecode, DFABytecodeInstruction::TestFlagsAndAppendActionWithIfDomain);
+        if (action & IfConditionFlag)
+            append<DFABytecodeInstruction>(m_bytecode, DFABytecodeInstruction::TestFlagsAndAppendActionWithIfCondition);
         else
             append<DFABytecodeInstruction>(m_bytecode, DFABytecodeInstruction::TestFlagsAndAppendAction);
         append<uint16_t>(m_bytecode, static_cast<uint16_t>(action >> 32));
         append<uint32_t>(m_bytecode, static_cast<uint32_t>(action));
     } else {
-        if (action & IfDomainFlag)
-            append<DFABytecodeInstruction>(m_bytecode, DFABytecodeInstruction::AppendActionWithIfDomain);
+        if (action & IfConditionFlag)
+            append<DFABytecodeInstruction>(m_bytecode, DFABytecodeInstruction::AppendActionWithIfCondition);
         else
             append<DFABytecodeInstruction>(m_bytecode, DFABytecodeInstruction::AppendAction);
         append<uint32_t>(m_bytecode, static_cast<uint32_t>(action));
index a0da084..708d8e3 100644 (file)
@@ -86,29 +86,29 @@ static inline int32_t getJumpDistance(const DFABytecode* bytecode, uint32_t byte
     }
 }
 
-static inline bool matchesDomain(uint64_t actionAndFlags, const DFABytecodeInterpreter::Actions& domainActions)
+static inline bool matchesCondition(uint64_t actionAndFlags, const DFABytecodeInterpreter::Actions& conditionActions)
 {
-    bool ifDomain = actionAndFlags & IfDomainFlag;
-    bool domain = domainActions.contains(actionAndFlags);
-    return ifDomain == domain;
+    bool ifCondition = actionAndFlags & IfConditionFlag;
+    bool condition = conditionActions.contains(actionAndFlags);
+    return ifCondition == condition;
 }
 
-void DFABytecodeInterpreter::interpretAppendAction(uint32_t& programCounter, Actions& actions, bool ifDomain)
+void DFABytecodeInterpreter::interpretAppendAction(uint32_t& programCounter, Actions& actions, bool ifCondition)
 {
     ASSERT(getInstruction(m_bytecode, m_bytecodeLength, programCounter) == DFABytecodeInstruction::AppendAction
-        || getInstruction(m_bytecode, m_bytecodeLength, programCounter) == DFABytecodeInstruction::AppendActionWithIfDomain);
-    uint64_t action = (ifDomain ? IfDomainFlag : 0) | static_cast<uint64_t>(getBits<uint32_t>(m_bytecode, m_bytecodeLength, programCounter + sizeof(DFABytecodeInstruction)));
-    if (!m_domainActions || matchesDomain(action, *m_domainActions))
+        || getInstruction(m_bytecode, m_bytecodeLength, programCounter) == DFABytecodeInstruction::AppendActionWithIfCondition);
+    uint64_t action = (ifCondition ? IfConditionFlag : 0) | static_cast<uint64_t>(getBits<uint32_t>(m_bytecode, m_bytecodeLength, programCounter + sizeof(DFABytecodeInstruction)));
+    if (!m_conditionActions || matchesCondition(action, *m_conditionActions))
         actions.add(action);
     
     programCounter += instructionSizeWithArguments(DFABytecodeInstruction::AppendAction);
-    ASSERT(instructionSizeWithArguments(DFABytecodeInstruction::AppendAction) == instructionSizeWithArguments(DFABytecodeInstruction::AppendActionWithIfDomain));
+    ASSERT(instructionSizeWithArguments(DFABytecodeInstruction::AppendAction) == instructionSizeWithArguments(DFABytecodeInstruction::AppendActionWithIfCondition));
 }
 
-void DFABytecodeInterpreter::interpretTestFlagsAndAppendAction(uint32_t& programCounter, uint16_t flags, Actions& actions, bool ifDomain)
+void DFABytecodeInterpreter::interpretTestFlagsAndAppendAction(uint32_t& programCounter, uint16_t flags, Actions& actions, bool ifCondition)
 {
     ASSERT(getInstruction(m_bytecode, m_bytecodeLength, programCounter) == DFABytecodeInstruction::TestFlagsAndAppendAction
-        || getInstruction(m_bytecode, m_bytecodeLength, programCounter) == DFABytecodeInstruction::TestFlagsAndAppendActionWithIfDomain);
+        || getInstruction(m_bytecode, m_bytecodeLength, programCounter) == DFABytecodeInstruction::TestFlagsAndAppendActionWithIfCondition);
     uint16_t flagsToCheck = getBits<uint16_t>(m_bytecode, m_bytecodeLength, programCounter + sizeof(DFABytecodeInstruction));
 
     uint16_t loadTypeFlags = flagsToCheck & LoadTypeMask;
@@ -118,12 +118,12 @@ void DFABytecodeInterpreter::interpretTestFlagsAndAppendAction(uint32_t& program
     bool resourceTypeMatches = resourceTypeFlags ? (resourceTypeFlags & flags) : true;
     
     if (loadTypeMatches && resourceTypeMatches) {
-        uint64_t actionAndFlags = (ifDomain ? IfDomainFlag : 0) | (static_cast<uint64_t>(flagsToCheck) << 32) | static_cast<uint64_t>(getBits<uint32_t>(m_bytecode, m_bytecodeLength, programCounter + sizeof(DFABytecodeInstruction) + sizeof(uint16_t)));
-        if (!m_domainActions || matchesDomain(actionAndFlags, *m_domainActions))
+        uint64_t actionAndFlags = (ifCondition ? IfConditionFlag : 0) | (static_cast<uint64_t>(flagsToCheck) << 32) | static_cast<uint64_t>(getBits<uint32_t>(m_bytecode, m_bytecodeLength, programCounter + sizeof(DFABytecodeInstruction) + sizeof(uint16_t)));
+        if (!m_conditionActions || matchesCondition(actionAndFlags, *m_conditionActions))
             actions.add(actionAndFlags);
     }
     programCounter += instructionSizeWithArguments(DFABytecodeInstruction::TestFlagsAndAppendAction);
-    ASSERT(instructionSizeWithArguments(DFABytecodeInstruction::TestFlagsAndAppendAction) == instructionSizeWithArguments(DFABytecodeInstruction::TestFlagsAndAppendActionWithIfDomain));
+    ASSERT(instructionSizeWithArguments(DFABytecodeInstruction::TestFlagsAndAppendAction) == instructionSizeWithArguments(DFABytecodeInstruction::TestFlagsAndAppendActionWithIfCondition));
 }
 
 template<bool caseSensitive>
@@ -157,24 +157,24 @@ DFABytecodeInterpreter::Actions DFABytecodeInterpreter::actionsMatchingEverythin
         DFABytecodeInstruction instruction = getInstruction(m_bytecode, m_bytecodeLength, programCounter);
         if (instruction == DFABytecodeInstruction::AppendAction)
             interpretAppendAction(programCounter, actions, false);
-        else if (instruction == DFABytecodeInstruction::AppendActionWithIfDomain)
+        else if (instruction == DFABytecodeInstruction::AppendActionWithIfCondition)
             interpretAppendAction(programCounter, actions, true);
         else if (instruction == DFABytecodeInstruction::TestFlagsAndAppendAction)
             programCounter += instructionSizeWithArguments(DFABytecodeInstruction::TestFlagsAndAppendAction);
-        else if (instruction == DFABytecodeInstruction::TestFlagsAndAppendActionWithIfDomain)
-            programCounter += instructionSizeWithArguments(DFABytecodeInstruction::TestFlagsAndAppendActionWithIfDomain);
+        else if (instruction == DFABytecodeInstruction::TestFlagsAndAppendActionWithIfCondition)
+            programCounter += instructionSizeWithArguments(DFABytecodeInstruction::TestFlagsAndAppendActionWithIfCondition);
         else
             break;
     }
     return actions;
 }
     
-DFABytecodeInterpreter::Actions DFABytecodeInterpreter::interpretWithDomains(const CString& urlCString, uint16_t flags, const DFABytecodeInterpreter::Actions& domainActions)
+DFABytecodeInterpreter::Actions DFABytecodeInterpreter::interpretWithConditions(const CString& urlCString, uint16_t flags, const DFABytecodeInterpreter::Actions& conditionActions)
 {
-    ASSERT(!m_domainActions);
-    m_domainActions = &domainActions;
+    ASSERT(!m_conditionActions);
+    m_conditionActions = &conditionActions;
     DFABytecodeInterpreter::Actions actions = interpret(urlCString, flags);
-    m_domainActions = nullptr;
+    m_conditionActions = nullptr;
     return actions;
 }
 
@@ -199,11 +199,11 @@ DFABytecodeInterpreter::Actions DFABytecodeInterpreter::interpret(const CString&
                 DFABytecodeInstruction instruction = getInstruction(m_bytecode, m_bytecodeLength, programCounter);
                 if (instruction == DFABytecodeInstruction::AppendAction)
                     programCounter += instructionSizeWithArguments(DFABytecodeInstruction::AppendAction);
-                else if (instruction == DFABytecodeInstruction::AppendActionWithIfDomain)
-                    programCounter += instructionSizeWithArguments(DFABytecodeInstruction::AppendActionWithIfDomain);
+                else if (instruction == DFABytecodeInstruction::AppendActionWithIfCondition)
+                    programCounter += instructionSizeWithArguments(DFABytecodeInstruction::AppendActionWithIfCondition);
                 else if (instruction == DFABytecodeInstruction::TestFlagsAndAppendAction)
                     interpretTestFlagsAndAppendAction(programCounter, flags, actions, false);
-                else if (instruction == DFABytecodeInstruction::TestFlagsAndAppendActionWithIfDomain)
+                else if (instruction == DFABytecodeInstruction::TestFlagsAndAppendActionWithIfCondition)
                     interpretTestFlagsAndAppendAction(programCounter, flags, actions, true);
                 else
                     break;
@@ -212,9 +212,9 @@ DFABytecodeInterpreter::Actions DFABytecodeInterpreter::interpret(const CString&
                 return actions;
         } else {
             ASSERT_WITH_MESSAGE(getInstruction(m_bytecode, m_bytecodeLength, programCounter) != DFABytecodeInstruction::AppendAction
-                && getInstruction(m_bytecode, m_bytecodeLength, programCounter) != DFABytecodeInstruction::AppendActionWithIfDomain
+                && getInstruction(m_bytecode, m_bytecodeLength, programCounter) != DFABytecodeInstruction::AppendActionWithIfCondition
                 && getInstruction(m_bytecode, m_bytecodeLength, programCounter) != DFABytecodeInstruction::TestFlagsAndAppendAction
-                && getInstruction(m_bytecode, m_bytecodeLength, programCounter) != DFABytecodeInstruction::TestFlagsAndAppendActionWithIfDomain,
+                && getInstruction(m_bytecode, m_bytecodeLength, programCounter) != DFABytecodeInstruction::TestFlagsAndAppendActionWithIfCondition,
                 "Triggers that match everything should only be in the first DFA.");
         }
         
@@ -329,7 +329,7 @@ DFABytecodeInterpreter::Actions DFABytecodeInterpreter::interpret(const CString&
                 interpretAppendAction(programCounter, actions, false);
                 break;
                     
-            case DFABytecodeInstruction::AppendActionWithIfDomain:
+            case DFABytecodeInstruction::AppendActionWithIfCondition:
                 interpretAppendAction(programCounter, actions, true);
                 break;
                     
@@ -337,7 +337,7 @@ DFABytecodeInterpreter::Actions DFABytecodeInterpreter::interpret(const CString&
                 interpretTestFlagsAndAppendAction(programCounter, flags, actions, false);
                 break;
             
-            case DFABytecodeInstruction::TestFlagsAndAppendActionWithIfDomain:
+            case DFABytecodeInstruction::TestFlagsAndAppendActionWithIfCondition:
                 interpretTestFlagsAndAppendAction(programCounter, flags, actions, true);
                 break;
                     
index 4c69e26..63003b4 100644 (file)
@@ -48,19 +48,19 @@ public:
     typedef HashSet<uint64_t, DefaultHash<uint64_t>::Hash, WTF::UnsignedWithZeroKeyHashTraits<uint64_t>> Actions;
     
     Actions interpret(const CString&, uint16_t flags);
-    Actions interpretWithDomains(const CString&, uint16_t flags, const DFABytecodeInterpreter::Actions& domainActions);
+    Actions interpretWithConditions(const CString&, uint16_t flags, const DFABytecodeInterpreter::Actions& conditionActions);
     Actions actionsMatchingEverything();
 
 private:
-    void interpretAppendAction(unsigned& programCounter, Actions&, bool ifDomain);
-    void interpretTestFlagsAndAppendAction(unsigned& programCounter, uint16_t flags, Actions&, bool ifDomain);
+    void interpretAppendAction(unsigned& programCounter, Actions&, bool ifCondition);
+    void interpretTestFlagsAndAppendAction(unsigned& programCounter, uint16_t flags, Actions&, bool ifCondition);
 
     template<bool caseSensitive>
     void interpetJumpTable(const char* url, uint32_t& urlIndex, uint32_t& programCounter, bool& urlIndexIsAfterEndOfString);
 
     const DFABytecode* m_bytecode;
     const unsigned m_bytecodeLength;
-    const DFABytecodeInterpreter::Actions* m_domainActions { nullptr };
+    const DFABytecodeInterpreter::Actions* m_conditionActions { nullptr };
 };
 
 } // namespace ContentExtensions    
index eaf4a6c..9b6330e 100644 (file)
@@ -56,11 +56,13 @@ typedef uint16_t ResourceFlags;
 
 // The first 32 bits of a uint64_t action are used for the action location.
 // The next 16 bits are used for the flags (ResourceType and LoadType).
-// The next bit is used to mark actions that are from a rule with an if-domain condition.
-// The next bit is used to mark actions that in the default stylesheet.
+// The next bit is used to mark actions that are from a rule with an if-domain.
+//     Actions from rules with unless-domain conditions are distinguished from
+//     rules with if-domain conditions by not having this bit set.
+//     Actions from rules with no conditions are put in the DFA without conditions.
 // The values -1 and -2 are used for removed and empty values in HashTables.
 const uint64_t ActionFlagMask = 0x0000FFFF00000000;
-const uint64_t IfDomainFlag = 0x0001000000000000;
+const uint64_t IfConditionFlag = 0x0001000000000000;
 
 ResourceType toResourceType(CachedResource::Type);
 uint16_t readResourceType(const String&);
index 18cfe4b..4ba0aba 100644 (file)
@@ -1,3 +1,40 @@
+2017-03-07  Alex Christensen  <achristensen@webkit.org>
+
+        [Content Extensions] Rename "Domain" to "Condition" where appropriate
+        https://bugs.webkit.org/show_bug.cgi?id=169297
+
+        Reviewed by Brady Eidson.
+
+        * Shared/WebCompiledContentExtension.cpp:
+        (WebKit::WebCompiledContentExtension::filtersWithoutConditionsBytecode):
+        (WebKit::WebCompiledContentExtension::filtersWithoutConditionsBytecodeLength):
+        (WebKit::WebCompiledContentExtension::filtersWithConditionsBytecode):
+        (WebKit::WebCompiledContentExtension::filtersWithConditionsBytecodeLength):
+        (WebKit::WebCompiledContentExtension::conditionedFiltersBytecode):
+        (WebKit::WebCompiledContentExtension::conditionedFiltersBytecodeLength):
+        (WebKit::WebCompiledContentExtension::filtersWithoutDomainsBytecode): Deleted.
+        (WebKit::WebCompiledContentExtension::filtersWithoutDomainsBytecodeLength): Deleted.
+        (WebKit::WebCompiledContentExtension::filtersWithDomainsBytecode): Deleted.
+        (WebKit::WebCompiledContentExtension::filtersWithDomainsBytecodeLength): Deleted.
+        (WebKit::WebCompiledContentExtension::domainFiltersBytecode): Deleted.
+        (WebKit::WebCompiledContentExtension::domainFiltersBytecodeLength): Deleted.
+        * Shared/WebCompiledContentExtension.h:
+        * Shared/WebCompiledContentExtensionData.cpp:
+        (WebKit::WebCompiledContentExtensionData::encode):
+        (WebKit::WebCompiledContentExtensionData::decode):
+        * Shared/WebCompiledContentExtensionData.h:
+        (WebKit::WebCompiledContentExtensionData::WebCompiledContentExtensionData):
+        * UIProcess/API/APIUserContentExtensionStore.cpp:
+        (API::ContentExtensionMetaData::fileSize):
+        (API::encodeContentExtensionMetaData):
+        (API::decodeContentExtensionMetaData):
+        (API::compiledToFile):
+        (API::createExtension):
+        (API::UserContentExtensionStore::lookupContentExtension):
+        (API::UserContentExtensionStore::compileContentExtension):
+        (API::UserContentExtensionStore::removeContentExtension):
+        * UIProcess/API/APIUserContentExtensionStore.h:
+
 2017-03-07  Brent Fulgham  <bfulgham@apple.com>
 
         [Mac][WK2] Expand sandbox to support access to audio component registrar
index 8aa8ce9..f7b56f7 100644 (file)
@@ -44,34 +44,34 @@ WebCompiledContentExtension::~WebCompiledContentExtension()
 {
 }
 
-const WebCore::ContentExtensions::DFABytecode* WebCompiledContentExtension::filtersWithoutDomainsBytecode() const
+const WebCore::ContentExtensions::DFABytecode* WebCompiledContentExtension::filtersWithoutConditionsBytecode() const
 {
-    return static_cast<const WebCore::ContentExtensions::DFABytecode*>(m_data.data->data()) + m_data.filtersWithoutDomainsBytecodeOffset;
+    return static_cast<const WebCore::ContentExtensions::DFABytecode*>(m_data.data->data()) + m_data.filtersWithoutConditionsBytecodeOffset;
 }
 
-unsigned WebCompiledContentExtension::filtersWithoutDomainsBytecodeLength() const
+unsigned WebCompiledContentExtension::filtersWithoutConditionsBytecodeLength() const
 {
-    return m_data.filtersWithoutDomainsBytecodeSize;
+    return m_data.filtersWithoutConditionsBytecodeSize;
 }
 
-const WebCore::ContentExtensions::DFABytecode* WebCompiledContentExtension::filtersWithDomainsBytecode() const
+const WebCore::ContentExtensions::DFABytecode* WebCompiledContentExtension::filtersWithConditionsBytecode() const
 {
-    return static_cast<const WebCore::ContentExtensions::DFABytecode*>(m_data.data->data()) + m_data.filtersWithDomainsBytecodeOffset;
+    return static_cast<const WebCore::ContentExtensions::DFABytecode*>(m_data.data->data()) + m_data.filtersWithConditionsBytecodeOffset;
 }
 
-unsigned WebCompiledContentExtension::filtersWithDomainsBytecodeLength() const
+unsigned WebCompiledContentExtension::filtersWithConditionsBytecodeLength() const
 {
-    return m_data.filtersWithDomainsBytecodeSize;
+    return m_data.filtersWithConditionsBytecodeSize;
 }
 
-const WebCore::ContentExtensions::DFABytecode* WebCompiledContentExtension::domainFiltersBytecode() const
+const WebCore::ContentExtensions::DFABytecode* WebCompiledContentExtension::conditionedFiltersBytecode() const
 {
-    return static_cast<const WebCore::ContentExtensions::DFABytecode*>(m_data.data->data()) + m_data.domainFiltersBytecodeOffset;
+    return static_cast<const WebCore::ContentExtensions::DFABytecode*>(m_data.data->data()) + m_data.conditionedFiltersBytecodeOffset;
 }
 
-unsigned WebCompiledContentExtension::domainFiltersBytecodeLength() const
+unsigned WebCompiledContentExtension::conditionedFiltersBytecodeLength() const
 {
-    return m_data.domainFiltersBytecodeSize;
+    return m_data.conditionedFiltersBytecodeSize;
 }
 
 const WebCore::ContentExtensions::SerializedActionByte* WebCompiledContentExtension::actions() const
index 53dd6fb..2cad95e 100644 (file)
@@ -23,8 +23,7 @@
  * THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#ifndef WebCompiledContentExtension_h
-#define WebCompiledContentExtension_h
+#pragma once
 
 #if ENABLE(CONTENT_EXTENSIONS)
 
@@ -44,15 +43,15 @@ public:
 private:
     WebCompiledContentExtension(WebCompiledContentExtensionData&&);
 
-    const WebCore::ContentExtensions::DFABytecode* filtersWithoutDomainsBytecode() const override;
-    unsigned filtersWithoutDomainsBytecodeLength() const override;
-    const WebCore::ContentExtensions::DFABytecode* filtersWithDomainsBytecode() const override;
-    unsigned filtersWithDomainsBytecodeLength() const override;
-    const WebCore::ContentExtensions::DFABytecode* domainFiltersBytecode() const override;
-    unsigned domainFiltersBytecodeLength() const override;
+    const WebCore::ContentExtensions::DFABytecode* filtersWithoutConditionsBytecode() const final;
+    unsigned filtersWithoutConditionsBytecodeLength() const final;
+    const WebCore::ContentExtensions::DFABytecode* filtersWithConditionsBytecode() const final;
+    unsigned filtersWithConditionsBytecodeLength() const final;
+    const WebCore::ContentExtensions::DFABytecode* conditionedFiltersBytecode() const final;
+    unsigned conditionedFiltersBytecodeLength() const final;
     
-    const WebCore::ContentExtensions::SerializedActionByte* actions() const override;
-    unsigned actionsLength() const override;
+    const WebCore::ContentExtensions::SerializedActionByte* actions() const final;
+    unsigned actionsLength() const final;
     
     WebCompiledContentExtensionData m_data;
 };
@@ -60,4 +59,3 @@ private:
 } // namespace WebKit
 
 #endif // ENABLE(CONTENT_EXTENSIONS)
-#endif // WebCompiledContentExtension_h
index 6c7d156..ac21f13 100644 (file)
@@ -40,12 +40,12 @@ void WebCompiledContentExtensionData::encode(IPC::Encoder& encoder) const
 
     encoder << actionsOffset;
     encoder << actionsSize;
-    encoder << filtersWithoutDomainsBytecodeOffset;
-    encoder << filtersWithoutDomainsBytecodeSize;
-    encoder << filtersWithDomainsBytecodeOffset;
-    encoder << filtersWithDomainsBytecodeSize;
-    encoder << domainFiltersBytecodeOffset;
-    encoder << domainFiltersBytecodeSize;
+    encoder << filtersWithoutConditionsBytecodeOffset;
+    encoder << filtersWithoutConditionsBytecodeSize;
+    encoder << filtersWithConditionsBytecodeOffset;
+    encoder << filtersWithConditionsBytecodeSize;
+    encoder << conditionedFiltersBytecodeOffset;
+    encoder << conditionedFiltersBytecodeSize;
 }
 
 bool WebCompiledContentExtensionData::decode(IPC::Decoder& decoder, WebCompiledContentExtensionData& compiledContentExtensionData)
@@ -59,17 +59,17 @@ bool WebCompiledContentExtensionData::decode(IPC::Decoder& decoder, WebCompiledC
         return false;
     if (!decoder.decode(compiledContentExtensionData.actionsSize))
         return false;
-    if (!decoder.decode(compiledContentExtensionData.filtersWithoutDomainsBytecodeOffset))
+    if (!decoder.decode(compiledContentExtensionData.filtersWithoutConditionsBytecodeOffset))
         return false;
-    if (!decoder.decode(compiledContentExtensionData.filtersWithoutDomainsBytecodeSize))
+    if (!decoder.decode(compiledContentExtensionData.filtersWithoutConditionsBytecodeSize))
         return false;
-    if (!decoder.decode(compiledContentExtensionData.filtersWithDomainsBytecodeOffset))
+    if (!decoder.decode(compiledContentExtensionData.filtersWithConditionsBytecodeOffset))
         return false;
-    if (!decoder.decode(compiledContentExtensionData.filtersWithDomainsBytecodeSize))
+    if (!decoder.decode(compiledContentExtensionData.filtersWithConditionsBytecodeSize))
         return false;
-    if (!decoder.decode(compiledContentExtensionData.domainFiltersBytecodeOffset))
+    if (!decoder.decode(compiledContentExtensionData.conditionedFiltersBytecodeOffset))
         return false;
-    if (!decoder.decode(compiledContentExtensionData.domainFiltersBytecodeSize))
+    if (!decoder.decode(compiledContentExtensionData.conditionedFiltersBytecodeSize))
         return false;
 
     return true;
index f62cb32..9e37b28 100644 (file)
@@ -23,8 +23,7 @@
  * THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#ifndef WebCompiledContentExtensionData_h
-#define WebCompiledContentExtensionData_h
+#pragma once
 
 #if ENABLE(CONTENT_EXTENSIONS)
 
@@ -41,21 +40,19 @@ namespace WebKit {
 
 class WebCompiledContentExtensionData {
 public:
-    WebCompiledContentExtensionData()
-    {
-    }
-    
-    WebCompiledContentExtensionData(RefPtr<SharedMemory>&& data, NetworkCache::Data fileData, unsigned actionsOffset, unsigned actionsSize, unsigned filtersWithoutDomainsBytecodeOffset, unsigned filtersWithoutDomainsBytecodeSize, unsigned filtersWithDomainsBytecodeOffset, unsigned filtersWithDomainsBytecodeSize, unsigned domainFiltersBytecodeOffset, unsigned domainFiltersBytecodeSize)
+    WebCompiledContentExtensionData() = default;
+
+    WebCompiledContentExtensionData(RefPtr<SharedMemory>&& data, NetworkCache::Data fileData, unsigned actionsOffset, unsigned actionsSize, unsigned filtersWithoutConditionsBytecodeOffset, unsigned filtersWithoutConditionsBytecodeSize, unsigned filtersWithConditionsBytecodeOffset, unsigned filtersWithConditionsBytecodeSize, unsigned conditionedFiltersBytecodeOffset, unsigned conditionedFiltersBytecodeSize)
         : data(WTFMove(data))
         , fileData(fileData)
         , actionsOffset(actionsOffset)
         , actionsSize(actionsSize)
-        , filtersWithoutDomainsBytecodeOffset(filtersWithoutDomainsBytecodeOffset)
-        , filtersWithoutDomainsBytecodeSize(filtersWithoutDomainsBytecodeSize)
-        , filtersWithDomainsBytecodeOffset(filtersWithDomainsBytecodeOffset)
-        , filtersWithDomainsBytecodeSize(filtersWithDomainsBytecodeSize)
-        , domainFiltersBytecodeOffset(domainFiltersBytecodeOffset)
-        , domainFiltersBytecodeSize(domainFiltersBytecodeSize)
+        , filtersWithoutConditionsBytecodeOffset(filtersWithoutConditionsBytecodeOffset)
+        , filtersWithoutConditionsBytecodeSize(filtersWithoutConditionsBytecodeSize)
+        , filtersWithConditionsBytecodeOffset(filtersWithConditionsBytecodeOffset)
+        , filtersWithConditionsBytecodeSize(filtersWithConditionsBytecodeSize)
+        , conditionedFiltersBytecodeOffset(conditionedFiltersBytecodeOffset)
+        , conditionedFiltersBytecodeSize(conditionedFiltersBytecodeSize)
     {
     }
 
@@ -66,15 +63,14 @@ public:
     NetworkCache::Data fileData;
     unsigned actionsOffset { 0 };
     unsigned actionsSize { 0 };
-    unsigned filtersWithoutDomainsBytecodeOffset { 0 };
-    unsigned filtersWithoutDomainsBytecodeSize { 0 };
-    unsigned filtersWithDomainsBytecodeOffset { 0 };
-    unsigned filtersWithDomainsBytecodeSize { 0 };
-    unsigned domainFiltersBytecodeOffset { 0 };
-    unsigned domainFiltersBytecodeSize { 0 };
+    unsigned filtersWithoutConditionsBytecodeOffset { 0 };
+    unsigned filtersWithoutConditionsBytecodeSize { 0 };
+    unsigned filtersWithConditionsBytecodeOffset { 0 };
+    unsigned filtersWithConditionsBytecodeSize { 0 };
+    unsigned conditionedFiltersBytecodeOffset { 0 };
+    unsigned conditionedFiltersBytecodeSize { 0 };
 };
 
 }
 
 #endif // ENABLE(CONTENT_EXTENSIONS)
-#endif // WebCompiledContentExtensionData_h
index 3a740fd..9e2b0f5 100644 (file)
@@ -83,17 +83,17 @@ const size_t ContentExtensionFileHeaderSize = sizeof(uint32_t) + 4 * sizeof(uint
 struct ContentExtensionMetaData {
     uint32_t version { UserContentExtensionStore::CurrentContentExtensionFileVersion };
     uint64_t actionsSize { 0 };
-    uint64_t filtersWithoutDomainsBytecodeSize { 0 };
-    uint64_t filtersWithDomainBytecodeSize { 0 };
-    uint64_t domainFiltersBytecodeSize { 0 };
+    uint64_t filtersWithoutConditionsBytecodeSize { 0 };
+    uint64_t filtersWithConditionsBytecodeSize { 0 };
+    uint64_t conditionedFiltersBytecodeSize { 0 };
     
     size_t fileSize() const
     {
         return ContentExtensionFileHeaderSize
             + actionsSize
-            + filtersWithoutDomainsBytecodeSize
-            + filtersWithDomainBytecodeSize
-            + domainFiltersBytecodeSize;
+            + filtersWithoutConditionsBytecodeSize
+            + filtersWithConditionsBytecodeSize
+            + conditionedFiltersBytecodeSize;
     }
 };
 
@@ -103,9 +103,9 @@ static Data encodeContentExtensionMetaData(const ContentExtensionMetaData& metaD
 
     encoder << metaData.version;
     encoder << metaData.actionsSize;
-    encoder << metaData.filtersWithoutDomainsBytecodeSize;
-    encoder << metaData.filtersWithDomainBytecodeSize;
-    encoder << metaData.domainFiltersBytecodeSize;
+    encoder << metaData.filtersWithoutConditionsBytecodeSize;
+    encoder << metaData.filtersWithConditionsBytecodeSize;
+    encoder << metaData.conditionedFiltersBytecodeSize;
 
     ASSERT(encoder.bufferSize() == ContentExtensionFileHeaderSize);
     return Data(encoder.buffer(), encoder.bufferSize());
@@ -125,11 +125,11 @@ static bool decodeContentExtensionMetaData(ContentExtensionMetaData& metaData, c
             return false;
         if (!decoder.decode(metaData.actionsSize))
             return false;
-        if (!decoder.decode(metaData.filtersWithoutDomainsBytecodeSize))
+        if (!decoder.decode(metaData.filtersWithoutConditionsBytecodeSize))
             return false;
-        if (!decoder.decode(metaData.filtersWithDomainBytecodeSize))
+        if (!decoder.decode(metaData.filtersWithConditionsBytecodeSize))
             return false;
-        if (!decoder.decode(metaData.domainFiltersBytecodeSize))
+        if (!decoder.decode(metaData.conditionedFiltersBytecodeSize))
             return false;
         success = true;
         return false;
@@ -174,37 +174,37 @@ static std::error_code compiledToFile(String&& json, const String& finalFilePath
             , m_metaData(metaData)
         {
             ASSERT(!metaData.actionsSize);
-            ASSERT(!metaData.filtersWithoutDomainsBytecodeSize);
-            ASSERT(!metaData.filtersWithDomainBytecodeSize);
-            ASSERT(!metaData.domainFiltersBytecodeSize);
+            ASSERT(!metaData.filtersWithoutConditionsBytecodeSize);
+            ASSERT(!metaData.filtersWithConditionsBytecodeSize);
+            ASSERT(!metaData.conditionedFiltersBytecodeSize);
         }
         
-        void writeFiltersWithoutDomainsBytecode(Vector<DFABytecode>&& bytecode) override
+        void writeFiltersWithoutConditionsBytecode(Vector<DFABytecode>&& bytecode) override
         {
-            ASSERT(!m_filtersWithDomainBytecodeWritten);
-            ASSERT(!m_domainFiltersBytecodeWritten);
-            m_filtersWithoutDomainsBytecodeWritten += bytecode.size();
+            ASSERT(!m_filtersWithConditionBytecodeWritten);
+            ASSERT(!m_conditionFiltersBytecodeWritten);
+            m_filtersWithoutConditionsBytecodeWritten += bytecode.size();
             writeToFile(Data(bytecode.data(), bytecode.size()));
         }
         
-        void writeFiltersWithDomainsBytecode(Vector<DFABytecode>&& bytecode) override
+        void writeFiltersWithConditionsBytecode(Vector<DFABytecode>&& bytecode) override
         {
-            ASSERT(!m_domainFiltersBytecodeWritten);
-            m_filtersWithDomainBytecodeWritten += bytecode.size();
+            ASSERT(!m_conditionFiltersBytecodeWritten);
+            m_filtersWithConditionBytecodeWritten += bytecode.size();
             writeToFile(Data(bytecode.data(), bytecode.size()));
         }
         
-        void writeDomainFiltersBytecode(Vector<DFABytecode>&& bytecode) override
+        void writeConditionedFiltersBytecode(Vector<DFABytecode>&& bytecode) override
         {
-            m_domainFiltersBytecodeWritten += bytecode.size();
+            m_conditionFiltersBytecodeWritten += bytecode.size();
             writeToFile(Data(bytecode.data(), bytecode.size()));
         }
 
         void writeActions(Vector<SerializedActionByte>&& actions) override
         {
-            ASSERT(!m_filtersWithoutDomainsBytecodeWritten);
-            ASSERT(!m_filtersWithDomainBytecodeWritten);
-            ASSERT(!m_domainFiltersBytecodeWritten);
+            ASSERT(!m_filtersWithoutConditionsBytecodeWritten);
+            ASSERT(!m_filtersWithConditionBytecodeWritten);
+            ASSERT(!m_conditionFiltersBytecodeWritten);
             ASSERT(!m_actionsWritten);
             m_actionsWritten += actions.size();
             writeToFile(Data(actions.data(), actions.size()));
@@ -213,9 +213,9 @@ static std::error_code compiledToFile(String&& json, const String& finalFilePath
         void finalize() override
         {
             m_metaData.actionsSize = m_actionsWritten;
-            m_metaData.filtersWithoutDomainsBytecodeSize = m_filtersWithoutDomainsBytecodeWritten;
-            m_metaData.filtersWithDomainBytecodeSize = m_filtersWithDomainBytecodeWritten;
-            m_metaData.domainFiltersBytecodeSize = m_domainFiltersBytecodeWritten;
+            m_metaData.filtersWithoutConditionsBytecodeSize = m_filtersWithoutConditionsBytecodeWritten;
+            m_metaData.filtersWithConditionsBytecodeSize = m_filtersWithConditionBytecodeWritten;
+            m_metaData.conditionedFiltersBytecodeSize = m_conditionFiltersBytecodeWritten;
             
             Data header = encodeContentExtensionMetaData(m_metaData);
             if (!m_fileError && WebCore::seekFile(m_fileHandle, 0ll, WebCore::FileSeekOrigin::SeekFromBeginning) == -1) {
@@ -238,9 +238,9 @@ static std::error_code compiledToFile(String&& json, const String& finalFilePath
         
         WebCore::PlatformFileHandle m_fileHandle;
         ContentExtensionMetaData& m_metaData;
-        size_t m_filtersWithoutDomainsBytecodeWritten { 0 };
-        size_t m_filtersWithDomainBytecodeWritten { 0 };
-        size_t m_domainFiltersBytecodeWritten { 0 };
+        size_t m_filtersWithoutConditionsBytecodeWritten { 0 };
+        size_t m_filtersWithConditionBytecodeWritten { 0 };
+        size_t m_conditionFiltersBytecodeWritten { 0 };
         size_t m_actionsWritten { 0 };
         bool m_fileError { false };
     };
@@ -289,22 +289,22 @@ static RefPtr<API::UserContentExtension> createExtension(const String& identifie
         metaData.actionsSize,
         ContentExtensionFileHeaderSize
             + metaData.actionsSize,
-        metaData.filtersWithoutDomainsBytecodeSize,
+        metaData.filtersWithoutConditionsBytecodeSize,
         ContentExtensionFileHeaderSize
             + metaData.actionsSize
-            + metaData.filtersWithoutDomainsBytecodeSize,
-        metaData.filtersWithDomainBytecodeSize,
+            + metaData.filtersWithoutConditionsBytecodeSize,
+        metaData.filtersWithConditionsBytecodeSize,
         ContentExtensionFileHeaderSize
             + metaData.actionsSize
-            + metaData.filtersWithoutDomainsBytecodeSize
-            + metaData.filtersWithDomainBytecodeSize,
-        metaData.domainFiltersBytecodeSize
+            + metaData.filtersWithoutConditionsBytecodeSize
+            + metaData.filtersWithConditionsBytecodeSize,
+        metaData.conditionedFiltersBytecodeSize
     );
     auto compiledContentExtension = WebKit::WebCompiledContentExtension::create(WTFMove(compiledContentExtensionData));
     return API::UserContentExtension::create(identifier, WTFMove(compiledContentExtension));
 }
 
-void UserContentExtensionStore::lookupContentExtension(const WTF::String& identifier, std::function<void(RefPtr<API::UserContentExtension>, std::error_code)> completionHandler)
+void UserContentExtensionStore::lookupContentExtension(const WTF::String& identifier, Function<void(RefPtr<API::UserContentExtension>, std::error_code)> completionHandler)
 {
     m_readQueue->dispatch([protectedThis = makeRef(*this), identifier = identifier.isolatedCopy(), storePath = m_storePath.isolatedCopy(), completionHandler = WTFMove(completionHandler)]() mutable {
         auto path = constructedPath(storePath, identifier);
@@ -332,7 +332,7 @@ void UserContentExtensionStore::lookupContentExtension(const WTF::String& identi
     });
 }
 
-void UserContentExtensionStore::compileContentExtension(const WTF::String& identifier, WTF::String&& json, std::function<void(RefPtr<API::UserContentExtension>, std::error_code)> completionHandler)
+void UserContentExtensionStore::compileContentExtension(const WTF::String& identifier, WTF::String&& json, Function<void(RefPtr<API::UserContentExtension>, std::error_code)> completionHandler)
 {
     m_compileQueue->dispatch([protectedThis = makeRef(*this), identifier = identifier.isolatedCopy(), json = json.isolatedCopy(), storePath = m_storePath.isolatedCopy(), completionHandler = WTFMove(completionHandler)] () mutable {
         auto path = constructedPath(storePath, identifier);
@@ -354,7 +354,7 @@ void UserContentExtensionStore::compileContentExtension(const WTF::String& ident
     });
 }
 
-void UserContentExtensionStore::removeContentExtension(const WTF::String& identifier, std::function<void(std::error_code)> completionHandler)
+void UserContentExtensionStore::removeContentExtension(const WTF::String& identifier, Function<void(std::error_code)> completionHandler)
 {
     m_removeQueue->dispatch([protectedThis = makeRef(*this), identifier = identifier.isolatedCopy(), storePath = m_storePath.isolatedCopy(), completionHandler = WTFMove(completionHandler)]() mutable {
         auto path = constructedPath(storePath, identifier);
index caf0f6e..b7a73ac 100644 (file)
@@ -23,8 +23,7 @@
  * THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#ifndef APIUserContentExtensionStore_h
-#define APIUserContentExtensionStore_h
+#pragma once
 
 #if ENABLE(CONTENT_EXTENSIONS)
 
@@ -60,9 +59,9 @@ public:
     explicit UserContentExtensionStore(const WTF::String& storePath);
     virtual ~UserContentExtensionStore();
 
-    void compileContentExtension(const WTF::String& identifier, WTF::String&& json, std::function<void(RefPtr<API::UserContentExtension>, std::error_code)>);
-    void lookupContentExtension(const WTF::String& identifier, std::function<void(RefPtr<API::UserContentExtension>, std::error_code)>);
-    void removeContentExtension(const WTF::String& identifier, std::function<void(std::error_code)>);
+    void compileContentExtension(const WTF::String& identifier, WTF::String&& json, Function<void(RefPtr<API::UserContentExtension>, std::error_code)>);
+    void lookupContentExtension(const WTF::String& identifier, Function<void(RefPtr<API::UserContentExtension>, std::error_code)>);
+    void removeContentExtension(const WTF::String& identifier, Function<void(std::error_code)>);
 
     // For testing only.
     void synchronousRemoveAllContentExtensions();
@@ -91,4 +90,3 @@ namespace std {
 }
 
 #endif // ENABLE(CONTENT_EXTENSIONS)
-#endif // APIUserContentExtensionStore_h
index b7ca767..ad30611 100644 (file)
@@ -1,3 +1,14 @@
+2017-03-07  Alex Christensen  <achristensen@webkit.org>
+
+        [Content Extensions] Rename "Domain" to "Condition" where appropriate
+        https://bugs.webkit.org/show_bug.cgi?id=169297
+
+        Reviewed by Brady Eidson.
+
+        * TestWebKitAPI/Tests/WebCore/ContentExtensions.cpp:
+        (TestWebKitAPI::InMemoryCompiledContentExtension::create):
+        (TestWebKitAPI::TEST_F):
+
 2017-03-07  Jonathan Bedard  <jbedard@apple.com>
 
         webkitpy: Refactor setup_test_run for IOSPort and IOSSimulator
index 40950c2..cbb93d2 100644 (file)
@@ -83,9 +83,9 @@ public:
 
 struct CompiledContentExtensionData {
     Vector<ContentExtensions::SerializedActionByte> actions;
-    Vector<ContentExtensions::DFABytecode> filtersWithoutDomains;
-    Vector<ContentExtensions::DFABytecode> filtersWithDomains;
-    Vector<ContentExtensions::DFABytecode> domainFilters;
+    Vector<ContentExtensions::DFABytecode> filtersWithoutConditions;
+    Vector<ContentExtensions::DFABytecode> filtersWithConditions;
+    Vector<ContentExtensions::DFABytecode> conditionedFilters;
 };
 
 class InMemoryContentExtensionCompilationClient final : public ContentExtensions::ContentExtensionCompilationClient {
@@ -94,43 +94,43 @@ public:
         : m_data(data)
     {
         EXPECT_EQ(data.actions.size(), 0ull);
-        EXPECT_EQ(data.filtersWithoutDomains.size(), 0ull);
-        EXPECT_EQ(data.filtersWithDomains.size(), 0ull);
-        EXPECT_EQ(data.domainFilters.size(), 0ull);
+        EXPECT_EQ(data.filtersWithoutConditions.size(), 0ull);
+        EXPECT_EQ(data.filtersWithConditions.size(), 0ull);
+        EXPECT_EQ(data.conditionedFilters.size(), 0ull);
     }
 
-    void writeActions(Vector<ContentExtensions::SerializedActionByte>&& actions) override
+    void writeActions(Vector<ContentExtensions::SerializedActionByte>&& actions) final
     {
         EXPECT_FALSE(finalized);
         EXPECT_EQ(m_data.actions.size(), 0ull);
-        EXPECT_EQ(m_data.filtersWithoutDomains.size(), 0ull);
-        EXPECT_EQ(m_data.filtersWithDomains.size(), 0ull);
-        EXPECT_EQ(m_data.domainFilters.size(), 0ull);
+        EXPECT_EQ(m_data.filtersWithoutConditions.size(), 0ull);
+        EXPECT_EQ(m_data.filtersWithConditions.size(), 0ull);
+        EXPECT_EQ(m_data.conditionedFilters.size(), 0ull);
         m_data.actions.appendVector(actions);
     }
     
-    void writeFiltersWithoutDomainsBytecode(Vector<ContentExtensions::DFABytecode>&& bytecode) override
+    void writeFiltersWithoutConditionsBytecode(Vector<ContentExtensions::DFABytecode>&& bytecode) final
     {
         EXPECT_FALSE(finalized);
-        EXPECT_EQ(m_data.filtersWithDomains.size(), 0ull);
-        EXPECT_EQ(m_data.domainFilters.size(), 0ull);
-        m_data.filtersWithoutDomains.appendVector(bytecode);
+        EXPECT_EQ(m_data.filtersWithConditions.size(), 0ull);
+        EXPECT_EQ(m_data.conditionedFilters.size(), 0ull);
+        m_data.filtersWithoutConditions.appendVector(bytecode);
     }
     
-    void writeFiltersWithDomainsBytecode(Vector<ContentExtensions::DFABytecode>&& bytecode) override
+    void writeFiltersWithConditionsBytecode(Vector<ContentExtensions::DFABytecode>&& bytecode) final
     {
         EXPECT_FALSE(finalized);
-        EXPECT_EQ(m_data.domainFilters.size(), 0ull);
-        m_data.filtersWithDomains.appendVector(bytecode);
+        EXPECT_EQ(m_data.conditionedFilters.size(), 0ull);
+        m_data.filtersWithConditions.appendVector(bytecode);
     }
     
-    void writeDomainFiltersBytecode(Vector<ContentExtensions::DFABytecode>&& bytecode) override
+    void writeConditionedFiltersBytecode(Vector<ContentExtensions::DFABytecode>&& bytecode) final
     {
         EXPECT_FALSE(finalized);
-        m_data.domainFilters.appendVector(bytecode);
+        m_data.conditionedFilters.appendVector(bytecode);
     }
     
-    void finalize() override
+    void finalize() final
     {
         finalized = true;
     }
@@ -156,23 +156,23 @@ public:
         return InMemoryCompiledContentExtension::create(WTFMove(extensionData));
     }
 
-    static RefPtr<InMemoryCompiledContentExtension> create(CompiledContentExtensionData&& data)
+    static Ref<InMemoryCompiledContentExtension> create(CompiledContentExtensionData&& data)
     {
-        return adoptRef(new InMemoryCompiledContentExtension(WTFMove(data)));
+        return adoptRef(*new InMemoryCompiledContentExtension(WTFMove(data)));
     }
 
     virtual ~InMemoryCompiledContentExtension()
     {
     }
 
-    const ContentExtensions::SerializedActionByte* actions() const override { return m_data.actions.data(); }
-    unsigned actionsLength() const override { return m_data.actions.size(); }
-    const ContentExtensions::DFABytecode* filtersWithoutDomainsBytecode() const override { return m_data.filtersWithoutDomains.data(); }
-    unsigned filtersWithoutDomainsBytecodeLength() const override { return m_data.filtersWithoutDomains.size(); }
-    const ContentExtensions::DFABytecode* filtersWithDomainsBytecode() const override { return m_data.filtersWithDomains.data(); }
-    unsigned filtersWithDomainsBytecodeLength() const override { return m_data.filtersWithDomains.size(); }
-    const ContentExtensions::DFABytecode* domainFiltersBytecode() const override { return m_data.domainFilters.data(); }
-    unsigned domainFiltersBytecodeLength() const override { return m_data.domainFilters.size(); }
+    const ContentExtensions::SerializedActionByte* actions() const final { return m_data.actions.data(); }
+    unsigned actionsLength() const final { return m_data.actions.size(); }
+    const ContentExtensions::DFABytecode* filtersWithoutConditionsBytecode() const final { return m_data.filtersWithoutConditions.data(); }
+    unsigned filtersWithoutConditionsBytecodeLength() const final { return m_data.filtersWithoutConditions.size(); }
+    const ContentExtensions::DFABytecode* filtersWithConditionsBytecode() const final { return m_data.filtersWithConditions.data(); }
+    unsigned filtersWithConditionsBytecodeLength() const final { return m_data.filtersWithConditions.size(); }
+    const ContentExtensions::DFABytecode* conditionedFiltersBytecode() const final { return m_data.conditionedFilters.data(); }
+    unsigned conditionedFiltersBytecodeLength() const final { return m_data.conditionedFilters.size(); }
 
 private:
     InMemoryCompiledContentExtension(CompiledContentExtensionData&& data)
@@ -1326,34 +1326,30 @@ TEST_F(ContentExtensionTest, InvalidJSON)
     checkCompilerError(rules50000.utf8().data(), { });
     checkCompilerError(rules50001.utf8().data(), ContentExtensions::ContentExtensionError::JSONTooManyRules);
     
-    checkCompilerError("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"webkit.org\",\"if-domain\":{}}}]", ContentExtensions::ContentExtensionError::JSONInvalidDomainList);
-    checkCompilerError("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"webkit.org\",\"if-domain\":[5]}}]", ContentExtensions::ContentExtensionError::JSONInvalidDomainList);
+    checkCompilerError("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"webkit.org\",\"if-domain\":{}}}]", ContentExtensions::ContentExtensionError::JSONInvalidConditionList);
+    checkCompilerError("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"webkit.org\",\"if-domain\":[5]}}]", ContentExtensions::ContentExtensionError::JSONInvalidConditionList);
     checkCompilerError("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"webkit.org\",\"if-domain\":[\"a\"]}}]", { });
-    checkCompilerError("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"webkit.org\",\"if-domain\":\"a\"}}]", ContentExtensions::ContentExtensionError::JSONInvalidDomainList);
-    checkCompilerError("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"webkit.org\",\"if-domain\":false}}]", ContentExtensions::ContentExtensionError::JSONInvalidDomainList);
-    checkCompilerError("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"webkit.org\",\"if-domain\":null}}]", ContentExtensions::ContentExtensionError::JSONInvalidDomainList);
-    checkCompilerError("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"webkit.org\",\"unless-domain\":{}}}]", ContentExtensions::ContentExtensionError::JSONInvalidDomainList);
-    checkCompilerError("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"webkit.org\",\"unless-domain\":[5]}}]", ContentExtensions::ContentExtensionError::JSONInvalidDomainList);
-    checkCompilerError("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"webkit.org\",\"unless-domain\":[\"\"]}}]", ContentExtensions::ContentExtensionError::JSONInvalidDomainList);
-    checkCompilerError("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"webkit.org\",\"unless-domain\":\"a\"}}]", ContentExtensions::ContentExtensionError::JSONInvalidDomainList);
-    checkCompilerError("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"webkit.org\",\"unless-domain\":null}}]", ContentExtensions::ContentExtensionError::JSONInvalidDomainList);
-    checkCompilerError("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"webkit.org\",\"unless-domain\":false}}]", ContentExtensions::ContentExtensionError::JSONInvalidDomainList);
+    checkCompilerError("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"webkit.org\",\"if-domain\":\"a\"}}]", ContentExtensions::ContentExtensionError::JSONInvalidConditionList);
+    checkCompilerError("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"webkit.org\",\"if-domain\":false}}]", ContentExtensions::ContentExtensionError::JSONInvalidConditionList);
+    checkCompilerError("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"webkit.org\",\"if-domain\":null}}]", ContentExtensions::ContentExtensionError::JSONInvalidConditionList);
+    checkCompilerError("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"webkit.org\",\"unless-domain\":{}}}]", ContentExtensions::ContentExtensionError::JSONInvalidConditionList);
+    checkCompilerError("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"webkit.org\",\"unless-domain\":[5]}}]", ContentExtensions::ContentExtensionError::JSONInvalidConditionList);
+    checkCompilerError("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"webkit.org\",\"unless-domain\":[\"\"]}}]", ContentExtensions::ContentExtensionError::JSONInvalidConditionList);
+    checkCompilerError("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"webkit.org\",\"unless-domain\":\"a\"}}]", ContentExtensions::ContentExtensionError::JSONInvalidConditionList);
+    checkCompilerError("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"webkit.org\",\"unless-domain\":null}}]", ContentExtensions::ContentExtensionError::JSONInvalidConditionList);
+    checkCompilerError("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"webkit.org\",\"unless-domain\":false}}]", ContentExtensions::ContentExtensionError::JSONInvalidConditionList);
     checkCompilerError("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"webkit.org\",\"unless-domain\":[\"A\"]}}]", ContentExtensions::ContentExtensionError::JSONDomainNotLowerCaseASCII);
     checkCompilerError("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"webkit.org\",\"unless-domain\":[\"\\u00DC\"]}}]", ContentExtensions::ContentExtensionError::JSONDomainNotLowerCaseASCII);
     checkCompilerError("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"webkit.org\",\"unless-domain\":[\"0\"]}}]", { });
     checkCompilerError("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"webkit.org\",\"unless-domain\":[\"a\"]}}]", { });
 
-    checkCompilerError("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"webkit.org\",\"if-domain\":[],\"unless-domain\":[\"a\"]}}]", ContentExtensions::ContentExtensionError::JSONInvalidDomainList);
-    checkCompilerError("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"webkit.org\",\"unless-domain\":[]}}]", ContentExtensions::ContentExtensionError::JSONInvalidDomainList);
-    checkCompilerError("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"webkit.org\",\"if-domain\":5}}]", ContentExtensions::ContentExtensionError::JSONInvalidDomainList);
-    checkCompilerError("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"webkit.org\",\"unless-domain\":5}}]", ContentExtensions::ContentExtensionError::JSONInvalidDomainList);
-    checkCompilerError("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"webkit.org\",\"if-domain\":5,\"unless-domain\":5}}]", ContentExtensions::ContentExtensionError::JSONInvalidDomainList);
-    checkCompilerError("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"webkit.org\",\"if-domain\":[]}}]", ContentExtensions::ContentExtensionError::JSONInvalidDomainList);
-    
-    checkCompilerError("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"webkit.org\",\"if-domain\":[\"a\"],\"unless-domain\":[]}}]", ContentExtensions::ContentExtensionError::JSONUnlessAndIfDomain);
-    checkCompilerError("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"webkit.org\",\"if-domain\":[\"a\"],\"unless-domain\":[\"a\"]}}]", ContentExtensions::ContentExtensionError::JSONUnlessAndIfDomain);
-
-    checkCompilerError("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"webkit.org\", \"unexpected-identifier-should-be-ignored\":5}}]", { });
+    checkCompilerError("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"webkit.org\",\"if-domain\":[],\"unless-domain\":[\"a\"]}}]", ContentExtensions::ContentExtensionError::JSONInvalidConditionList);
+    checkCompilerError("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"webkit.org\",\"unless-domain\":[]}}]", ContentExtensions::ContentExtensionError::JSONInvalidConditionList);
+    checkCompilerError("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"webkit.org\",\"if-domain\":5}}]", ContentExtensions::ContentExtensionError::JSONInvalidConditionList);
+    checkCompilerError("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"webkit.org\",\"unless-domain\":5}}]", ContentExtensions::ContentExtensionError::JSONInvalidConditionList);
+    checkCompilerError("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"webkit.org\",\"if-domain\":5,\"unless-domain\":5}}]", ContentExtensions::ContentExtensionError::JSONInvalidConditionList);
+    checkCompilerError("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"webkit.org\",\"if-domain\":[]}}]", ContentExtensions::ContentExtensionError::JSONInvalidConditionList);
+    checkCompilerError("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"webkit.org\",\"if-domain\":[\"a\"],\"unless-domain\":[]}}]", ContentExtensions::ContentExtensionError::JSONMultipleConditions);
 
     checkCompilerError("[{\"action\":5,\"trigger\":{\"url-filter\":\"webkit.org\"}}]",
         ContentExtensions::ContentExtensionError::JSONInvalidAction);