Changeset 187049 in webkit


Ignore:
Timestamp:
Jul 20, 2015 5:12:13 PM (9 years ago)
Author:
achristensen@apple.com
Message:

[Content Extensions] Cache actions with domains that match everything
https://bugs.webkit.org/show_bug.cgi?id=147050

Reviewed by Benjamin Poulain.

Source/WebCore:

If you have lots of rules with triggers like {"url-filter":".*","if-domain":*webkit.org?}
we will spend a lot of time adding unnecessary actions to HashSets when you are not on webkit.org.
Caching all the rules and only adding them to a collection once when the domain changes saves a lot of URL interpreting time.

We already had an optimization for the css-display-none actions with triggers that matched everything using a special bytecode operation.
This removes the need for a special bytecode operation by caching the triggers that match everything with and without domains,
then from those cached actions we compile a stylesheet, and create cached actions for every new domain we visit.

All functionality is covered by existing API tests.

  • contentextensions/CompiledContentExtension.cpp:

(WebCore::ContentExtensions::CompiledContentExtension::~CompiledContentExtension):
(WebCore::ContentExtensions::CompiledContentExtension::globalDisplayNoneSelectors): Deleted.

  • contentextensions/CompiledContentExtension.h:
  • contentextensions/ContentExtension.cpp:

(WebCore::ContentExtensions::ContentExtension::ContentExtension):
(WebCore::ContentExtensions::ContentExtension::findFirstIgnorePreviousRules):
(WebCore::ContentExtensions::ContentExtension::globalDisplayNoneStyleSheet):
(WebCore::ContentExtensions::ContentExtension::compileGlobalDisplayNoneStyleSheet):
(WebCore::ContentExtensions::ContentExtension::populateDomainCacheIfNeeded):
(WebCore::ContentExtensions::ContentExtension::cachedDomainActions):
(WebCore::ContentExtensions::ContentExtension::universalActionsWithDomains):

  • contentextensions/ContentExtension.h:

(WebCore::ContentExtensions::ContentExtension::compiledExtension):
(WebCore::ContentExtensions::ContentExtension::universalActionsWithoutDomains):

  • contentextensions/ContentExtensionCompiler.cpp:

(WebCore::ContentExtensions::compileRuleList):

  • contentextensions/ContentExtensionRule.cpp:

(WebCore::ContentExtensions::ContentExtensionRule::ContentExtensionRule):
(WebCore::ContentExtensions::Action::deserialize):
(WebCore::ContentExtensions::Action::deserializeType):
(WebCore::ContentExtensions::Action::serializedLength):

  • contentextensions/ContentExtensionRule.h:

(WebCore::ContentExtensions::Action::operator==):
(WebCore::ContentExtensions::Action::setExtensionIdentifier):
(WebCore::ContentExtensions::Action::extensionIdentifier):

  • 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::DFABytecodeInterpreter::interpretAppendAction):
(WebCore::ContentExtensions::DFABytecodeInterpreter::interpretTestFlagsAndAppendAction):
(WebCore::ContentExtensions::DFABytecodeInterpreter::actionsMatchingEverything):
(WebCore::ContentExtensions::DFABytecodeInterpreter::interpret):
(WebCore::ContentExtensions::DFABytecodeInterpreter::actionsForDefaultStylesheetFromDFARoot): Deleted.

  • contentextensions/DFABytecodeInterpreter.h:
  • loader/ResourceLoadInfo.h:

Source/WebKit2:

  • UIProcess/API/APIUserContentExtensionStore.h:
Location:
trunk/Source
Files:
16 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r187044 r187049  
     12015-07-20  Alex Christensen  <achristensen@webkit.org>
     2
     3        [Content Extensions] Cache actions with domains that match everything
     4        https://bugs.webkit.org/show_bug.cgi?id=147050
     5
     6        Reviewed by Benjamin Poulain.
     7
     8        If you have lots of rules with triggers like {"url-filter":".*","if-domain":["*webkit.org"]}
     9        we will spend a lot of time adding unnecessary actions to HashSets when you are not on webkit.org.
     10        Caching all the rules and only adding them to a collection once when the domain changes saves a lot of URL interpreting time.
     11
     12        We already had an optimization for the css-display-none actions with triggers that matched everything using a special bytecode operation.
     13        This removes the need for a special bytecode operation by caching the triggers that match everything with and without domains,
     14        then from those cached actions we compile a stylesheet, and create cached actions for every new domain we visit.
     15
     16        All functionality is covered by existing API tests.
     17
     18        * contentextensions/CompiledContentExtension.cpp:
     19        (WebCore::ContentExtensions::CompiledContentExtension::~CompiledContentExtension):
     20        (WebCore::ContentExtensions::CompiledContentExtension::globalDisplayNoneSelectors): Deleted.
     21        * contentextensions/CompiledContentExtension.h:
     22        * contentextensions/ContentExtension.cpp:
     23        (WebCore::ContentExtensions::ContentExtension::ContentExtension):
     24        (WebCore::ContentExtensions::ContentExtension::findFirstIgnorePreviousRules):
     25        (WebCore::ContentExtensions::ContentExtension::globalDisplayNoneStyleSheet):
     26        (WebCore::ContentExtensions::ContentExtension::compileGlobalDisplayNoneStyleSheet):
     27        (WebCore::ContentExtensions::ContentExtension::populateDomainCacheIfNeeded):
     28        (WebCore::ContentExtensions::ContentExtension::cachedDomainActions):
     29        (WebCore::ContentExtensions::ContentExtension::universalActionsWithDomains):
     30        * contentextensions/ContentExtension.h:
     31        (WebCore::ContentExtensions::ContentExtension::compiledExtension):
     32        (WebCore::ContentExtensions::ContentExtension::universalActionsWithoutDomains):
     33        * contentextensions/ContentExtensionCompiler.cpp:
     34        (WebCore::ContentExtensions::compileRuleList):
     35        * contentextensions/ContentExtensionRule.cpp:
     36        (WebCore::ContentExtensions::ContentExtensionRule::ContentExtensionRule):
     37        (WebCore::ContentExtensions::Action::deserialize):
     38        (WebCore::ContentExtensions::Action::deserializeType):
     39        (WebCore::ContentExtensions::Action::serializedLength):
     40        * contentextensions/ContentExtensionRule.h:
     41        (WebCore::ContentExtensions::Action::operator==):
     42        (WebCore::ContentExtensions::Action::setExtensionIdentifier):
     43        (WebCore::ContentExtensions::Action::extensionIdentifier):
     44        * contentextensions/ContentExtensionsBackend.cpp:
     45        (WebCore::ContentExtensions::ContentExtensionsBackend::actionsForResourceLoad):
     46        * contentextensions/DFABytecode.h:
     47        (WebCore::ContentExtensions::instructionSizeWithArguments):
     48        * contentextensions/DFABytecodeCompiler.cpp:
     49        (WebCore::ContentExtensions::DFABytecodeCompiler::emitAppendAction):
     50        * contentextensions/DFABytecodeInterpreter.cpp:
     51        (WebCore::ContentExtensions::DFABytecodeInterpreter::interpretAppendAction):
     52        (WebCore::ContentExtensions::DFABytecodeInterpreter::interpretTestFlagsAndAppendAction):
     53        (WebCore::ContentExtensions::DFABytecodeInterpreter::actionsMatchingEverything):
     54        (WebCore::ContentExtensions::DFABytecodeInterpreter::interpret):
     55        (WebCore::ContentExtensions::DFABytecodeInterpreter::actionsForDefaultStylesheetFromDFARoot): Deleted.
     56        * contentextensions/DFABytecodeInterpreter.h:
     57        * loader/ResourceLoadInfo.h:
     58
    1592015-07-20  Jeremy Jones  <jeremyj@apple.com>
    260
  • trunk/Source/WebCore/contentextensions/CompiledContentExtension.cpp

    r186383 r187049  
    3636{
    3737}
    38 
    39 Vector<String> CompiledContentExtension::globalDisplayNoneSelectors()
    40 {
    41     DFABytecodeInterpreter interpreter(filtersWithoutDomainsBytecode(), filtersWithoutDomainsBytecodeLength());
    42     DFABytecodeInterpreter::Actions actionLocations = interpreter.actionsForDefaultStylesheetFromDFARoot();
    43    
    44     Vector<Action> globalActions;
    45     for (uint64_t actionLocation : actionLocations)
    46         globalActions.append(Action::deserialize(actions(), actionsLength(), static_cast<unsigned>(actionLocation)));
    47    
    48     Vector<String> selectors;
    49     for (Action& action : globalActions) {
    50         if (action.type() == ActionType::CSSDisplayNoneSelector)
    51             selectors.append(action.stringArgument());
    52     }
    53    
    54     return selectors;
    55 }
    5638   
    5739} // namespace ContentExtensions
  • trunk/Source/WebCore/contentextensions/CompiledContentExtension.h

    r186383 r187049  
    4949    virtual const SerializedActionByte* actions() const = 0;
    5050    virtual unsigned actionsLength() const = 0;
    51     Vector<String> globalDisplayNoneSelectors();
    5251};
    5352
  • trunk/Source/WebCore/contentextensions/ContentExtension.cpp

    r186912 r187049  
    4545    : m_identifier(identifier)
    4646    , m_compiledExtension(WTF::move(compiledExtension))
    47     , m_parsedGlobalDisplayNoneStyleSheet(false)
    4847{
     48    DFABytecodeInterpreter withoutDomains(m_compiledExtension->filtersWithoutDomainsBytecode(), m_compiledExtension->filtersWithoutDomainsBytecodeLength());
     49    DFABytecodeInterpreter withDomains(m_compiledExtension->filtersWithDomainsBytecode(), m_compiledExtension->filtersWithDomainsBytecodeLength());
     50    for (uint64_t action : withoutDomains.actionsMatchingEverything()) {
     51        ASSERT(static_cast<uint32_t>(action) == action);
     52        m_universalActionsWithoutDomains.append(static_cast<uint32_t>(action));
     53    }
     54    for (uint64_t action : withDomains.actionsMatchingEverything()) {
     55        ASSERT((action & ~IfDomainFlag) == static_cast<uint32_t>(action));
     56        m_universalActionsWithDomains.append(action);
     57    }
     58   
     59    compileGlobalDisplayNoneStyleSheet();
     60    m_universalActionsWithoutDomains.shrinkToFit();
     61    m_universalActionsWithDomains.shrinkToFit();
    4962}
    5063
     64uint32_t ContentExtension::findFirstIgnorePreviousRules() const
     65{
     66    auto* actions = m_compiledExtension->actions();
     67    uint32_t actionsLength = m_compiledExtension->actionsLength();
     68    uint32_t currentActionIndex = 0;
     69    while (currentActionIndex < actionsLength) {
     70        if (Action::deserializeType(actions, actionsLength, currentActionIndex) == ActionType::IgnorePreviousRules)
     71            return currentActionIndex;
     72        currentActionIndex += Action::serializedLength(actions, actionsLength, currentActionIndex);
     73    }
     74    return std::numeric_limits<uint32_t>::max();
     75}
     76   
    5177StyleSheetContents* ContentExtension::globalDisplayNoneStyleSheet()
    5278{
    53     if (m_parsedGlobalDisplayNoneStyleSheet)
    54         return m_globalDisplayNoneStyleSheet.get();
     79    return m_globalDisplayNoneStyleSheet.get();
     80}
    5581
    56     m_parsedGlobalDisplayNoneStyleSheet = true;
     82void ContentExtension::compileGlobalDisplayNoneStyleSheet()
     83{
     84    uint32_t firstIgnorePreviousRules = findFirstIgnorePreviousRules();
     85   
     86    auto* actions = m_compiledExtension->actions();
     87    uint32_t actionsLength = m_compiledExtension->actionsLength();
    5788
    58     Vector<String> selectors = m_compiledExtension->globalDisplayNoneSelectors();
    59     if (selectors.isEmpty())
    60         return nullptr;
    61 
     89    auto inGlobalDisplayNoneStyleSheet = [&](const uint32_t location)
     90    {
     91        return location < firstIgnorePreviousRules && Action::deserializeType(actions, actionsLength, location) == ActionType::CSSDisplayNoneSelector;
     92    };
     93   
    6294    StringBuilder css;
    63     for (auto& selector : selectors) {
    64         css.append(selector);
    65         css.append("{");
    66         css.append(ContentExtensionsBackend::displayNoneCSSRule());
    67         css.append("}");
     95    for (uint32_t universalActionLocation : m_universalActionsWithoutDomains) {
     96        if (inGlobalDisplayNoneStyleSheet(universalActionLocation)) {
     97            if (!css.isEmpty())
     98                css.append(',');
     99            Action action = Action::deserialize(actions, actionsLength, universalActionLocation);
     100            ASSERT(action.type() == ActionType::CSSDisplayNoneSelector);
     101            css.append(action.stringArgument());
     102        }
    68103    }
     104    if (css.isEmpty())
     105        return;
     106    css.append("{");
     107    css.append(ContentExtensionsBackend::displayNoneCSSRule());
     108    css.append("}");
    69109
    70110    m_globalDisplayNoneStyleSheet = StyleSheetContents::create();
     
    73113        m_globalDisplayNoneStyleSheet = nullptr;
    74114
    75     return m_globalDisplayNoneStyleSheet.get();
     115    // These actions don't need to be applied individually any more. They will all be applied to every page as a precompiled style sheet.
     116    m_universalActionsWithoutDomains.removeAllMatching(inGlobalDisplayNoneStyleSheet);
    76117}
    77118
    78 const DFABytecodeInterpreter::Actions& ContentExtension::cachedDomainActions(const String& domain)
     119void ContentExtension::populateDomainCacheIfNeeded(const String& domain)
    79120{
    80121    if (m_cachedDomain != domain) {
     
    86127        for (uint64_t action : domainActions)
    87128            m_cachedDomainActions.add(action);
     129       
     130        m_cachedUniversalDomainActions.clear();
     131        for (uint64_t action : m_universalActionsWithDomains) {
     132            ASSERT_WITH_MESSAGE((action & ~IfDomainFlag) == static_cast<uint32_t>(action), "Universal actions with domains should not have flags.");
     133            if (!!(action & IfDomainFlag) == m_cachedDomainActions.contains(action))
     134                m_cachedUniversalDomainActions.append(static_cast<uint32_t>(action));
     135        }
     136        m_cachedDomainActions.shrinkToFit();
     137        m_cachedUniversalDomainActions.shrinkToFit();
    88138        m_cachedDomain = domain;
    89139    }
     140}
     141
     142const DFABytecodeInterpreter::Actions& ContentExtension::cachedDomainActions(const String& domain)
     143{
     144    populateDomainCacheIfNeeded(domain);
    90145    return m_cachedDomainActions;
     146}
     147
     148const Vector<uint32_t>& ContentExtension::universalActionsWithDomains(const String& domain)
     149{
     150    populateDomainCacheIfNeeded(domain);
     151    return m_cachedUniversalDomainActions;
    91152}
    92153   
  • trunk/Source/WebCore/contentextensions/ContentExtension.h

    r186912 r187049  
    5050    StyleSheetContents* globalDisplayNoneStyleSheet();
    5151    const DFABytecodeInterpreter::Actions& cachedDomainActions(const String& domain);
     52    const Vector<uint32_t>& universalActionsWithoutDomains() { return m_universalActionsWithoutDomains; }
     53    const Vector<uint32_t>& universalActionsWithDomains(const String& domain);
    5254
    5355private:
    5456    ContentExtension(const String& identifier, Ref<CompiledContentExtension>&&);
    55 
     57    uint32_t findFirstIgnorePreviousRules() const;
     58   
    5659    String m_identifier;
    5760    Ref<CompiledContentExtension> m_compiledExtension;
     61
    5862    RefPtr<StyleSheetContents> m_globalDisplayNoneStyleSheet;
    59     bool m_parsedGlobalDisplayNoneStyleSheet;
    60    
     63    void compileGlobalDisplayNoneStyleSheet();
     64
    6165    String m_cachedDomain;
     66    void populateDomainCacheIfNeeded(const String& domain);
    6267    DFABytecodeInterpreter::Actions m_cachedDomainActions;
     68    Vector<uint32_t> m_cachedUniversalDomainActions;
     69
     70    Vector<uint32_t> m_universalActionsWithoutDomains;
     71    Vector<uint64_t> m_universalActionsWithDomains;
    6372};
    6473
  • trunk/Source/WebCore/contentextensions/ContentExtensionCompiler.cpp

    r186957 r187049  
    252252    URLFilterParser filtersWithDomainParser(filtersWithDomains);
    253253   
    254     bool ignorePreviousRulesSeen = false;
    255254    for (unsigned ruleIndex = 0; ruleIndex < parsedRuleList.size(); ++ruleIndex) {
    256255        const ContentExtensionRule& contentExtensionRule = parsedRuleList[ruleIndex];
    257256        const Trigger& trigger = contentExtensionRule.trigger();
    258         const Action& action = contentExtensionRule.action();
    259257        ASSERT(trigger.urlFilter.length());
    260258
     
    268266            status = filtersWithoutDomainParser.addPattern(trigger.urlFilter, trigger.urlFilterIsCaseSensitive, actionLocationAndFlags);
    269267            if (status == URLFilterParser::MatchesEverything) {
    270                 if (!ignorePreviousRulesSeen
    271                     && trigger.domainCondition == Trigger::DomainCondition::None
    272                     && action.type() == ActionType::CSSDisplayNoneSelector
    273                     && !trigger.flags)
    274                     actionLocationAndFlags |= DisplayNoneStyleSheetFlag;
    275268                universalActionsWithoutDomains.add(actionLocationAndFlags);
    276269                status = URLFilterParser::Ok;
     
    301294        }
    302295        ASSERT(status == URLFilterParser::Ok);
    303        
    304         if (action.type() == ActionType::IgnorePreviousRules)
    305             ignorePreviousRulesSeen = true;
    306296    }
    307297    LOG_LARGE_STRUCTURES(parsedRuleList, parsedRuleList.capacity() * sizeof(ContentExtensionRule)); // Doesn't include strings.
  • trunk/Source/WebCore/contentextensions/ContentExtensionRule.cpp

    r183195 r187049  
    4040}
    4141
    42 Action Action::deserialize(const SerializedActionByte* actions, const unsigned actionsLength, unsigned location)
     42Action Action::deserialize(const SerializedActionByte* actions, const uint32_t actionsLength, uint32_t location)
    4343{
     44    RELEASE_ASSERT(location < actionsLength);
    4445    switch (static_cast<ActionType>(actions[location])) {
    4546    case ActionType::BlockCookies:
     
    5051        return Action(ActionType::IgnorePreviousRules, location);
    5152    case ActionType::CSSDisplayNoneSelector: {
    52         unsigned stringStartIndex = location + sizeof(ActionType) + sizeof(unsigned) + sizeof(bool);
     53        uint32_t headerLength = sizeof(ActionType) + sizeof(uint32_t) + sizeof(bool);
     54        uint32_t stringStartIndex = location + headerLength;
    5355        RELEASE_ASSERT(actionsLength >= stringStartIndex);
    54         unsigned selectorLength = *reinterpret_cast<const unsigned*>(&actions[location + sizeof(ActionType)]);
    55         bool wideCharacters = actions[location + sizeof(ActionType) + sizeof(unsigned)];
     56        uint32_t selectorLength = *reinterpret_cast<const unsigned*>(&actions[location + sizeof(ActionType)]);
     57        bool wideCharacters = actions[location + sizeof(ActionType) + sizeof(uint32_t)];
    5658       
    5759        if (wideCharacters) {
     
    6466    case ActionType::CSSDisplayNoneStyleSheet:
    6567    case ActionType::InvalidAction:
     68    default:
     69        RELEASE_ASSERT_NOT_REACHED();
     70    }
     71}
     72   
     73ActionType Action::deserializeType(const SerializedActionByte* actions, const uint32_t actionsLength, uint32_t location)
     74{
     75    RELEASE_ASSERT(location < actionsLength);
     76    ActionType type = static_cast<ActionType>(actions[location]);
     77    switch (type) {
     78    case ActionType::BlockCookies:
     79    case ActionType::BlockLoad:
     80    case ActionType::IgnorePreviousRules:
     81    case ActionType::CSSDisplayNoneSelector:
     82        return type;
     83    case ActionType::CSSDisplayNoneStyleSheet:
     84    case ActionType::InvalidAction:
     85    default:
     86        RELEASE_ASSERT_NOT_REACHED();
     87    }
     88}
     89   
     90uint32_t Action::serializedLength(const SerializedActionByte* actions, const uint32_t actionsLength, uint32_t location)
     91{
     92    RELEASE_ASSERT(location < actionsLength);
     93    switch (static_cast<ActionType>(actions[location])) {
     94    case ActionType::BlockCookies:
     95    case ActionType::BlockLoad:
     96    case ActionType::IgnorePreviousRules:
     97        return sizeof(ActionType);
     98    case ActionType::CSSDisplayNoneSelector: {
     99        uint32_t headerLength = sizeof(ActionType) + sizeof(uint32_t) + sizeof(bool);
     100        uint32_t stringStartIndex = location + headerLength;
     101        RELEASE_ASSERT(actionsLength >= stringStartIndex);
     102        uint32_t selectorLength = *reinterpret_cast<const unsigned*>(&actions[location + sizeof(ActionType)]);
     103        bool wideCharacters = actions[location + sizeof(ActionType) + sizeof(uint32_t)];
     104       
     105        if (wideCharacters)
     106            return headerLength + selectorLength * sizeof(UChar);
     107        return headerLength + selectorLength * sizeof(LChar);
     108    }
     109    case ActionType::CSSDisplayNoneStyleSheet:
     110    case ActionType::InvalidAction:
     111    default:
    66112        RELEASE_ASSERT_NOT_REACHED();
    67113    }
    68114}
    69115
    70 }
     116} // namespace ContentExtensions
    71117
    72118} // namespace WebCore
  • trunk/Source/WebCore/contentextensions/ContentExtensionRule.h

    r186957 r187049  
    158158    }
    159159
    160     static Action deserialize(const SerializedActionByte* actions, const unsigned actionsLength, uint32_t location);
     160    static Action deserialize(const SerializedActionByte* actions, const uint32_t actionsLength, uint32_t location);
     161    static ActionType deserializeType(const SerializedActionByte* actions, const uint32_t actionsLength, uint32_t location);
     162    static uint32_t serializedLength(const SerializedActionByte* actions, const uint32_t actionsLength, uint32_t location);
    161163
    162164    void setExtensionIdentifier(const String& extensionIdentifier) { m_extensionIdentifier = extensionIdentifier; }
  • trunk/Source/WebCore/contentextensions/ContentExtensionsBackend.cpp

    r186957 r187049  
    9393        DFABytecodeInterpreter::Actions withoutDomainsActions = withoutDomainsInterpreter.interpret(urlCString, flags);
    9494       
     95        String domain = resourceLoadInfo.mainDocumentURL.host();
    9596        DFABytecodeInterpreter withDomainsInterpreter(compiledExtension.filtersWithDomainsBytecode(), compiledExtension.filtersWithDomainsBytecodeLength());
    96         DFABytecodeInterpreter::Actions withDomainsActions = withDomainsInterpreter.interpretWithDomains(urlCString, flags, contentExtension->cachedDomainActions(resourceLoadInfo.mainDocumentURL.host()));
     97        DFABytecodeInterpreter::Actions withDomainsActions = withDomainsInterpreter.interpretWithDomains(urlCString, flags, contentExtension->cachedDomainActions(domain));
    9798       
    9899        const SerializedActionByte* actions = compiledExtension.actions();
     
    100101       
    101102        bool sawIgnorePreviousRules = false;
    102         if (!withoutDomainsActions.isEmpty() || !withDomainsActions.isEmpty()) {
     103        const Vector<uint32_t>& universalWithDomains = contentExtension->universalActionsWithDomains(domain);
     104        const Vector<uint32_t>& universalWithoutDomains = contentExtension->universalActionsWithoutDomains();
     105        if (!withoutDomainsActions.isEmpty() || !withDomainsActions.isEmpty() || !universalWithDomains.isEmpty() || !universalWithoutDomains.isEmpty()) {
    103106            Vector<uint32_t> actionLocations;
    104             actionLocations.reserveInitialCapacity(withoutDomainsActions.size() + withDomainsActions.size());
     107            actionLocations.reserveInitialCapacity(withoutDomainsActions.size() + withDomainsActions.size() + universalWithoutDomains.size() + universalWithDomains.size());
    105108            for (uint64_t actionLocation : withoutDomainsActions)
    106109                actionLocations.uncheckedAppend(static_cast<uint32_t>(actionLocation));
    107110            for (uint64_t actionLocation : withDomainsActions)
    108111                actionLocations.uncheckedAppend(static_cast<uint32_t>(actionLocation));
     112            for (uint32_t actionLocation : universalWithoutDomains)
     113                actionLocations.uncheckedAppend(actionLocation);
     114            for (uint32_t actionLocation : universalWithDomains)
     115                actionLocations.uncheckedAppend(actionLocation);
    109116            std::sort(actionLocations.begin(), actionLocations.end());
    110117
     
    127134#if CONTENT_EXTENSIONS_PERFORMANCE_REPORTING
    128135    double addedTimeEnd = monotonicallyIncreasingTime();
    129     WTFLogAlways("Time added: %f microseconds %s", (addedTimeEnd - addedTimeStart) * 1.0e6, resourceLoadInfo.resourceURL.string().utf8().data());
     136    dataLogF("Time added: %f microseconds %s \n", (addedTimeEnd - addedTimeStart) * 1.0e6, resourceLoadInfo.resourceURL.string().utf8().data());
    130137#endif
    131138    return finalActions;
  • trunk/Source/WebCore/contentextensions/DFABytecode.h

    r186649 r187049  
    5656    // The action to append (4 bytes).
    5757    AppendAction = 0x4,
    58     AppendActionDefaultStylesheet = 0x5,
    59     AppendActionWithIfDomain = 0x6,
     58    AppendActionWithIfDomain = 0x5,
    6059   
    6160    // TestFlagsAndAppendAction has two arguments:
    6261    // The flags to check before appending (2 bytes).
    6362    // The action to append (4 bytes).
    64     TestFlagsAndAppendAction = 0x7,
    65     TestFlagsAndAppendActionWithIfDomain = 0x8,
     63    TestFlagsAndAppendAction = 0x6,
     64    TestFlagsAndAppendActionWithIfDomain = 0x7,
    6665
    6766    // Terminate has no arguments.
    68     Terminate = 0x9,
     67    Terminate = 0x8,
    6968
    7069    // Jump has one argument:
    7170    // The distance to jump (1-4 bytes, signed).
    72     Jump = 0xA,
     71    Jump = 0x9,
    7372};
    7473
     
    111110        RELEASE_ASSERT_NOT_REACHED(); // Variable instruction size.
    112111    case DFABytecodeInstruction::AppendAction:
    113     case DFABytecodeInstruction::AppendActionDefaultStylesheet:
    114112    case DFABytecodeInstruction::AppendActionWithIfDomain:
    115113        return sizeof(DFABytecodeInstruction) + sizeof(uint32_t);
  • trunk/Source/WebCore/contentextensions/DFABytecodeCompiler.cpp

    r186649 r187049  
    8282    // High bits are used to store flags. See compileRuleList.
    8383    if (action & ActionFlagMask) {
    84         ASSERT(!(action & DisplayNoneStyleSheetFlag));
    8584        if (action & IfDomainFlag)
    8685            append<DFABytecodeInstruction>(m_bytecode, DFABytecodeInstruction::TestFlagsAndAppendActionWithIfDomain);
     
    9089        append<uint32_t>(m_bytecode, static_cast<uint32_t>(action));
    9190    } else {
    92         if (action & DisplayNoneStyleSheetFlag) {
    93             RELEASE_ASSERT(!(action & IfDomainFlag));
    94             append<DFABytecodeInstruction>(m_bytecode, DFABytecodeInstruction::AppendActionDefaultStylesheet);
    95         } else if (action & IfDomainFlag)
     91        if (action & IfDomainFlag)
    9692            append<DFABytecodeInstruction>(m_bytecode, DFABytecodeInstruction::AppendActionWithIfDomain);
    9793        else
  • trunk/Source/WebCore/contentextensions/DFABytecodeInterpreter.cpp

    r186912 r187049  
    9797{
    9898    ASSERT(getInstruction(m_bytecode, m_bytecodeLength, programCounter) == DFABytecodeInstruction::AppendAction
    99         || getInstruction(m_bytecode, m_bytecodeLength, programCounter) == DFABytecodeInstruction::AppendActionWithIfDomain
    100         || getInstruction(m_bytecode, m_bytecodeLength, programCounter) == DFABytecodeInstruction::AppendActionDefaultStylesheet);
     99        || getInstruction(m_bytecode, m_bytecodeLength, programCounter) == DFABytecodeInstruction::AppendActionWithIfDomain);
    101100    uint64_t action = (ifDomain ? IfDomainFlag : 0) | static_cast<uint64_t>(getBits<uint32_t>(m_bytecode, m_bytecodeLength, programCounter + sizeof(DFABytecodeInstruction)));
    102101    if (!m_domainActions || matchesDomain(action, *m_domainActions))
     
    105104    programCounter += instructionSizeWithArguments(DFABytecodeInstruction::AppendAction);
    106105    ASSERT(instructionSizeWithArguments(DFABytecodeInstruction::AppendAction) == instructionSizeWithArguments(DFABytecodeInstruction::AppendActionWithIfDomain));
    107     ASSERT(instructionSizeWithArguments(DFABytecodeInstruction::AppendAction) == instructionSizeWithArguments(DFABytecodeInstruction::AppendActionDefaultStylesheet));
    108106}
    109107
     
    129127}
    130128
    131 DFABytecodeInterpreter::Actions DFABytecodeInterpreter::actionsForDefaultStylesheetFromDFARoot()
     129DFABytecodeInterpreter::Actions DFABytecodeInterpreter::actionsMatchingEverything()
    132130{
    133131    Actions actions;
     
    139137    while (programCounter < dfaBytecodeLength) {
    140138        DFABytecodeInstruction instruction = getInstruction(m_bytecode, m_bytecodeLength, programCounter);
    141         if (instruction == DFABytecodeInstruction::AppendActionDefaultStylesheet)
     139        if (instruction == DFABytecodeInstruction::AppendAction)
    142140            interpretAppendAction(programCounter, actions, false);
    143         else if (instruction == DFABytecodeInstruction::AppendAction)
    144             programCounter += instructionSizeWithArguments(DFABytecodeInstruction::AppendAction);
     141        else if (instruction == DFABytecodeInstruction::AppendActionWithIfDomain)
     142            interpretAppendAction(programCounter, actions, true);
    145143        else if (instruction == DFABytecodeInstruction::TestFlagsAndAppendAction)
    146144            programCounter += instructionSizeWithArguments(DFABytecodeInstruction::TestFlagsAndAppendAction);
    147         else {
    148             // actionsForDefaultStylesheetFromDFARoot should only be called on the DFA without domains,
    149             // which should never have any actions with if-domain.
    150             ASSERT(instruction != DFABytecodeInstruction::TestFlagsAndAppendActionWithIfDomain);
    151             ASSERT(instruction != DFABytecodeInstruction::AppendActionWithIfDomain);
     145        else if (instruction == DFABytecodeInstruction::TestFlagsAndAppendActionWithIfDomain)
     146            programCounter += instructionSizeWithArguments(DFABytecodeInstruction::TestFlagsAndAppendActionWithIfDomain);
     147        else
    152148            break;
    153         }
    154149    }
    155150    return actions;
     
    180175        programCounter += sizeof(uint32_t);
    181176
    182         // Skip the default stylesheet actions on the DFA root. These are accessed via actionsForDefaultStylesheetFromDFARoot.
     177        // Skip the actions without flags on the DFA root. These are accessed via actionsMatchingEverything.
    183178        if (!dfaStart) {
    184179            while (programCounter < dfaBytecodeLength) {
    185180                DFABytecodeInstruction instruction = getInstruction(m_bytecode, m_bytecodeLength, programCounter);
    186                 if (instruction == DFABytecodeInstruction::AppendActionDefaultStylesheet)
    187                     programCounter += instructionSizeWithArguments(DFABytecodeInstruction::AppendActionDefaultStylesheet);
    188                 else if (instruction == DFABytecodeInstruction::AppendAction)
    189                     interpretAppendAction(programCounter, actions, false);
     181                if (instruction == DFABytecodeInstruction::AppendAction)
     182                    programCounter += instructionSizeWithArguments(DFABytecodeInstruction::AppendAction);
     183                else if (instruction == DFABytecodeInstruction::AppendActionWithIfDomain)
     184                    programCounter += instructionSizeWithArguments(DFABytecodeInstruction::AppendActionWithIfDomain);
    190185                else if (instruction == DFABytecodeInstruction::TestFlagsAndAppendAction)
    191186                    interpretTestFlagsAndAppendAction(programCounter, flags, actions, false);
     187                else if (instruction == DFABytecodeInstruction::TestFlagsAndAppendActionWithIfDomain)
     188                    interpretTestFlagsAndAppendAction(programCounter, flags, actions, true);
    192189                else
    193190                    break;
     
    197194        } else {
    198195            ASSERT_WITH_MESSAGE(getInstruction(m_bytecode, m_bytecodeLength, programCounter) != DFABytecodeInstruction::AppendAction
    199                 && getInstruction(m_bytecode, m_bytecodeLength, programCounter) != DFABytecodeInstruction::TestFlagsAndAppendAction,
     196                && getInstruction(m_bytecode, m_bytecodeLength, programCounter) != DFABytecodeInstruction::AppendActionWithIfDomain
     197                && getInstruction(m_bytecode, m_bytecodeLength, programCounter) != DFABytecodeInstruction::TestFlagsAndAppendAction
     198                && getInstruction(m_bytecode, m_bytecodeLength, programCounter) != DFABytecodeInstruction::TestFlagsAndAppendActionWithIfDomain,
    200199                "Triggers that match everything should only be in the first DFA.");
    201200        }
  • trunk/Source/WebCore/contentextensions/DFABytecodeInterpreter.h

    r186912 r187049  
    5252    Actions interpret(const CString&, uint16_t flags);
    5353    Actions interpretWithDomains(const CString&, uint16_t flags, const DFABytecodeInterpreter::Actions& domainActions);
    54     Actions actionsForDefaultStylesheetFromDFARoot();
     54    Actions actionsMatchingEverything();
    5555
    5656private:
  • trunk/Source/WebCore/loader/ResourceLoadInfo.h

    r185621 r187049  
    6363const uint64_t ActionFlagMask = 0x0000FFFF00000000;
    6464const uint64_t IfDomainFlag = 0x0001000000000000;
    65 const uint64_t DisplayNoneStyleSheetFlag = 0x0002000000000000;
    6665
    6766ResourceType toResourceType(CachedResource::Type);
  • trunk/Source/WebKit2/ChangeLog

    r187047 r187049  
     12015-07-20  Alex Christensen  <achristensen@webkit.org>
     2
     3        [Content Extensions] Cache actions with domains that match everything
     4        https://bugs.webkit.org/show_bug.cgi?id=147050
     5
     6        Reviewed by Benjamin Poulain.
     7
     8        * UIProcess/API/APIUserContentExtensionStore.h:
     9
    1102015-07-20  Gordon Sheridan  <gordon_sheridan@apple.com>
    211
  • trunk/Source/WebKit2/UIProcess/API/APIUserContentExtensionStore.h

    r186649 r187049  
    5252    // This should be incremented every time a functional change is made to the bytecode, file format, etc.
    5353    // to prevent crashing while loading old data.
    54     const static uint32_t CurrentContentExtensionFileVersion = 5;
     54    const static uint32_t CurrentContentExtensionFileVersion = 6;
    5555
    5656    static UserContentExtensionStore& defaultStore();
Note: See TracChangeset for help on using the changeset viewer.