⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 181876 in webkit


Ignore:
Timestamp:
Mar 23, 2015, 3:34:53 PM (11 years ago)
Author:
beidson@apple.com
Message:

Content extensions should apply css selectors
https://bugs.webkit.org/show_bug.cgi?id=142604

Reviewed by Alex Christensen.

Source/WebCore:

Tests: http/tests/contentextensions/css-display-none.html

  • WebCore.xcodeproj/project.pbxproj:
  • contentextensions/ContentExtension.cpp:

(WebCore::ContentExtensions::ContentExtension::create):
(WebCore::ContentExtensions::ContentExtension::ContentExtension):
(WebCore::ContentExtensions::ContentExtension::globalDisplayNoneStyleSheet):

  • contentextensions/ContentExtension.h:

(WebCore::ContentExtensions::ContentExtension::identifier):
(WebCore::ContentExtensions::ContentExtension::compiledExtension):

  • contentextensions/ContentExtensionsBackend.cpp:

(WebCore::ContentExtensions::ContentExtensionsBackend::addContentExtension):
(WebCore::ContentExtensions::ContentExtensionsBackend::actionsForResourceLoad):
(WebCore::ContentExtensions::ContentExtensionsBackend::globalDisplayNoneStyleSheet):

  • contentextensions/ContentExtensionsBackend.h:
  • contentextensions/DFABytecodeInterpreter.cpp:

(WebCore::ContentExtensions::DFABytecodeInterpreter::interpret):

  • dom/DocumentStyleSheetCollection.cpp:

(WebCore::DocumentStyleSheetCollection::maybeAddContentExtensionSheet):

  • dom/DocumentStyleSheetCollection.h:
  • loader/DocumentLoader.cpp:

(WebCore::DocumentLoader::commitData):
(WebCore::DocumentLoader::startLoadingMainResource):
(WebCore::DocumentLoader::addPendingContentExtensionSheet):

  • loader/DocumentLoader.h:
  • loader/cache/CachedResourceLoader.cpp:

(WebCore::CachedResourceLoader::requestResource):

  • loader/cache/CachedResourceRequest.cpp:

(WebCore::CachedResourceRequest::setInitiator):

  • loader/cache/CachedResourceRequest.h:

(WebCore::CachedResourceRequest::initiatingDocumentLoader):

  • page/UserContentController.cpp:

(WebCore::UserContentController::globalDisplayNoneStyleSheet):
(WebCore::UserContentController::displayNoneCSSRule):

  • page/UserContentController.h:

LayoutTests:

  • http/tests/contentextensions/css-display-none-expected.txt:
  • http/tests/contentextensions/css-display-none.html:
  • http/tests/contentextensions/css-display-none.html.json:
Location:
trunk
Files:
1 added
18 edited
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r181871 r181876  
     12015-03-23  Brady Eidson  <beidson@apple.com>
     2
     3        Content extensions should apply css selectors
     4        https://bugs.webkit.org/show_bug.cgi?id=142604
     5
     6        Reviewed by Alex Christensen.
     7
     8        * http/tests/contentextensions/css-display-none-expected.txt:
     9        * http/tests/contentextensions/css-display-none.html:
     10        * http/tests/contentextensions/css-display-none.html.json:
     11
    1122015-03-23  Dean Jackson  <dino@apple.com>
    213
  • trunk/LayoutTests/http/tests/contentextensions/css-display-none-expected.txt

    r181031 r181876  
    55    RenderBody {BODY} at (8,8) size 784x576
    66      RenderBlock {P} at (0,0) size 784x18
    7         RenderText {#text} at (0,0) size 492x18
    8           text run at (0,0) width 492: "This text should not be visible once the css selector is applied (not done yet)."
    9       RenderBlock {P} at (0,34) size 784x18
    10         RenderText {#text} at (0,0) size 522x18
    11           text run at (0,0) width 522: "This text should also not be visible once the css selector is applied (not done yet)."
    12       RenderBlock {P} at (0,68) size 784x18
    137        RenderText {#text} at (0,0) size 173x18
    148          text run at (0,0) width 173: "This text should be visible."
  • trunk/LayoutTests/http/tests/contentextensions/css-display-none.html

    r181031 r181876  
     1<head>
     2<meta charset="UTF-8"></meta>
     3</head>
    14<body>
    2 <p class="hidden">This text should not be visible once the css selector is applied (not done yet).</p>
    3 <p class="hidden_Ž">This text should also not be visible once the css selector is applied (not done yet).</p>
     5<p class="hidden_global">This text should not be visible once the global css selector is applied.</p>
     6<p class="hidden">This text should not be visible once the particular css selector is applied.</p>
     7<p class="hidden_Ž">This text should not be visible once the particular css selector with non-ascii characters is applied.</p>
    48<p class="not_hidden">This text should be visible.</p>
    59</body>
  • trunk/LayoutTests/http/tests/contentextensions/css-display-none.html.json

    r181031 r181876  
    1717            "url-filter": ".*css-display-none.html"
    1818        }
     19    },
     20    {
     21        "action": {
     22            "type": "css-display-none",
     23            "selector": ".hidden_global"
     24        },
     25        "trigger": {
     26            "url-filter": ".*"
     27        }
    1928    }
    2029]
  • trunk/Source/WebCore/ChangeLog

    r181875 r181876  
     12015-03-23  Brady Eidson  <beidson@apple.com>
     2
     3        Content extensions should apply css selectors
     4        https://bugs.webkit.org/show_bug.cgi?id=142604
     5
     6        Reviewed by Alex Christensen.
     7
     8        Tests: http/tests/contentextensions/css-display-none.html
     9
     10        * WebCore.xcodeproj/project.pbxproj:
     11
     12        * contentextensions/ContentExtension.cpp:
     13        (WebCore::ContentExtensions::ContentExtension::create):
     14        (WebCore::ContentExtensions::ContentExtension::ContentExtension):
     15        (WebCore::ContentExtensions::ContentExtension::globalDisplayNoneStyleSheet):
     16        * contentextensions/ContentExtension.h:
     17        (WebCore::ContentExtensions::ContentExtension::identifier):
     18        (WebCore::ContentExtensions::ContentExtension::compiledExtension):
     19
     20        * contentextensions/ContentExtensionsBackend.cpp:
     21        (WebCore::ContentExtensions::ContentExtensionsBackend::addContentExtension):
     22        (WebCore::ContentExtensions::ContentExtensionsBackend::actionsForResourceLoad):
     23        (WebCore::ContentExtensions::ContentExtensionsBackend::globalDisplayNoneStyleSheet):
     24        * contentextensions/ContentExtensionsBackend.h:
     25
     26        * contentextensions/DFABytecodeInterpreter.cpp:
     27        (WebCore::ContentExtensions::DFABytecodeInterpreter::interpret):
     28
     29        * dom/DocumentStyleSheetCollection.cpp:
     30        (WebCore::DocumentStyleSheetCollection::maybeAddContentExtensionSheet):
     31        * dom/DocumentStyleSheetCollection.h:
     32
     33        * loader/DocumentLoader.cpp:
     34        (WebCore::DocumentLoader::commitData):
     35        (WebCore::DocumentLoader::startLoadingMainResource):
     36        (WebCore::DocumentLoader::addPendingContentExtensionSheet):
     37        * loader/DocumentLoader.h:
     38
     39        * loader/cache/CachedResourceLoader.cpp:
     40        (WebCore::CachedResourceLoader::requestResource):
     41
     42        * loader/cache/CachedResourceRequest.cpp:
     43        (WebCore::CachedResourceRequest::setInitiator):
     44        * loader/cache/CachedResourceRequest.h:
     45        (WebCore::CachedResourceRequest::initiatingDocumentLoader):
     46
     47        * page/UserContentController.cpp:
     48        (WebCore::UserContentController::globalDisplayNoneStyleSheet):
     49        (WebCore::UserContentController::displayNoneCSSRule):
     50        * page/UserContentController.h:
     51
    1522015-03-23  Anders Carlsson  <andersca@apple.com>
    253
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r181781 r181876  
    19891989                51B07A441823248B00AA8D1A /* IDBPendingDeleteCall.h in Headers */ = {isa = PBXBuildFile; fileRef = 51B07A431823248B00AA8D1A /* IDBPendingDeleteCall.h */; settings = {ATTRIBUTES = (Private, ); }; };
    19901990                51B2417B0D931F3F00E83F5C /* LegacyWebArchiveMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 51B2417A0D931F3F00E83F5C /* LegacyWebArchiveMac.mm */; };
     1991                51B45D201AB8D1E200117CD2 /* ContentExtension.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 51B45D1E1AB8D1E200117CD2 /* ContentExtension.cpp */; };
     1992                51B45D211AB8D1E200117CD2 /* ContentExtension.h in Headers */ = {isa = PBXBuildFile; fileRef = 51B45D1F1AB8D1E200117CD2 /* ContentExtension.h */; settings = {ATTRIBUTES = (Private, ); }; };
    19911993                51B58FD4195A964D002990B0 /* PlatformGamepad.h in Headers */ = {isa = PBXBuildFile; fileRef = 515E5FEF195101470086CA5E /* PlatformGamepad.h */; settings = {ATTRIBUTES = (Private, ); }; };
    19921994                51BE37E00DAEE00E001085FC /* StorageArea.h in Headers */ = {isa = PBXBuildFile; fileRef = 51BE37DE0DAEE00E001085FC /* StorageArea.h */; settings = {ATTRIBUTES = (Private, ); }; };
     
    63086310                E4E9B11D1814569C003ACCDF /* SimpleLineLayoutFunctions.h in Headers */ = {isa = PBXBuildFile; fileRef = E4E9B11C1814569C003ACCDF /* SimpleLineLayoutFunctions.h */; };
    63096311                E4F9EEF2156D9FFA00D23E7E /* StyleSheetContents.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E4F9EEF0156D84C400D23E7E /* StyleSheetContents.cpp */; };
    6310                 E4F9EEF3156DA00700D23E7E /* StyleSheetContents.h in Headers */ = {isa = PBXBuildFile; fileRef = E4F9EEF1156D84C400D23E7E /* StyleSheetContents.h */; };
     6312                E4F9EEF3156DA00700D23E7E /* StyleSheetContents.h in Headers */ = {isa = PBXBuildFile; fileRef = E4F9EEF1156D84C400D23E7E /* StyleSheetContents.h */; settings = {ATTRIBUTES = (Private, ); }; };
    63116313                E51A81DF17298D7700BFCA61 /* JSPerformance.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E51A81DE17298D7700BFCA61 /* JSPerformance.cpp */; };
    63126314                E526AF3F1727F8F200E41781 /* Performance.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E526AF3E1727F8F200E41781 /* Performance.cpp */; };
     
    91579159                51B07A431823248B00AA8D1A /* IDBPendingDeleteCall.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IDBPendingDeleteCall.h; sourceTree = "<group>"; };
    91589160                51B2417A0D931F3F00E83F5C /* LegacyWebArchiveMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = LegacyWebArchiveMac.mm; sourceTree = "<group>"; };
     9161                51B45D1E1AB8D1E200117CD2 /* ContentExtension.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ContentExtension.cpp; sourceTree = "<group>"; };
     9162                51B45D1F1AB8D1E200117CD2 /* ContentExtension.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ContentExtension.h; sourceTree = "<group>"; };
    91599163                51BE37DE0DAEE00E001085FC /* StorageArea.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StorageArea.h; sourceTree = "<group>"; };
    91609164                51C0AA380F2AA10A001648C2 /* CachedFrame.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CachedFrame.h; sourceTree = "<group>"; };
     
    1548415488                        isa = PBXGroup;
    1548515489                        children = (
     15490                                51B45D1E1AB8D1E200117CD2 /* ContentExtension.cpp */,
     15491                                51B45D1F1AB8D1E200117CD2 /* ContentExtension.h */,
    1548615492                                7C93F3471AA6BA5E00A98BAB /* CompiledContentExtension.cpp */,
    1548715493                                7C93F3481AA6BA5E00A98BAB /* CompiledContentExtension.h */,
     
    2590325909                                97059978107D975200A50A7C /* PolicyCallback.h in Headers */,
    2590425910                                9705997A107D975200A50A7C /* PolicyChecker.h in Headers */,
     25911                                51B45D211AB8D1E200117CD2 /* ContentExtension.h in Headers */,
    2590525912                                FD45A957175D414C00C21EC8 /* PolygonShape.h in Headers */,
    2590625913                                5174E20A10A1F44F00F95E6F /* PopStateEvent.h in Headers */,
     
    3030330310                                97AABD2C14FA09D5007457AE /* WorkerThreadableWebSocketChannel.cpp in Sources */,
    3030430311                                93309E23099E64920056E581 /* WrapContentsInDummySpanCommand.cpp in Sources */,
     30312                                51B45D201AB8D1E200117CD2 /* ContentExtension.cpp in Sources */,
    3030530313                                A833C7CC0A2CF07400D57664 /* XLinkNames.cpp in Sources */,
    3030630314                                00B9318713BA8DB30035A948 /* XMLDocumentParser.cpp in Sources */,
  • trunk/Source/WebCore/contentextensions/ContentExtension.h

    r181875 r181876  
    11/*
    2  * Copyright (C) 2014, 2015 Apple Inc. All rights reserved.
     2 * Copyright (C) 2015 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2424 */
    2525
    26 #ifndef ContentExtensionsBackend_h
    27 #define ContentExtensionsBackend_h
     26#ifndef ContentExtension_h
     27#define ContentExtension_h
     28
     29#include <wtf/Ref.h>
     30#include <wtf/RefCounted.h>
     31#include <wtf/RefPtr.h>
    2832
    2933#if ENABLE(CONTENT_EXTENSIONS)
    3034
    31 #include "ContentExtensionRule.h"
    32 #include <wtf/HashMap.h>
    33 #include <wtf/text/StringHash.h>
    34 #include <wtf/text/WTFString.h>
     35#include "StyleSheetContents.h"
    3536
    3637namespace WebCore {
    37 
    38 class URL;
    39 
    40 struct ResourceLoadInfo;
    4138
    4239namespace ContentExtensions {
     
    4441class CompiledContentExtension;
    4542
    46 // The ContentExtensionsBackend is the internal model of all the content extensions.
    47 //
    48 // It provides two services:
    49 // 1) It stores the rules for each content extension.
    50 // 2) It provides APIs for the WebCore interfaces to use those rules efficiently.
    51 class ContentExtensionsBackend {
     43class ContentExtension : public RefCounted<ContentExtension> {
    5244public:
    53     // - Rule management interface. This can be used by upper layer.
     45    static RefPtr<ContentExtension> create(const String& identifier, Ref<CompiledContentExtension>&&);
    5446
    55     // Set a list of rules for a given name. If there were existing rules for the name, they are overriden.
    56     // The identifier cannot be empty.
    57     WEBCORE_EXPORT void addContentExtension(const String& identifier, RefPtr<CompiledContentExtension>);
    58     WEBCORE_EXPORT void removeContentExtension(const String& identifier);
    59     WEBCORE_EXPORT void removeAllContentExtensions();
    60 
    61     // - Internal WebCore Interface.
    62     WEBCORE_EXPORT Vector<Action> actionsForResourceLoad(const ResourceLoadInfo&) const;
     47    const String& identifier() const { return m_identifier; }
     48    const CompiledContentExtension& compiledExtension() const { return m_compiledExtension.get(); }
     49    StyleSheetContents* globalDisplayNoneStyleSheet();
    6350
    6451private:
    65     HashMap<String, RefPtr<CompiledContentExtension>> m_contentExtensions;
     52    ContentExtension(const String& identifier, Ref<CompiledContentExtension>&&);
     53
     54    String m_identifier;
     55    Ref<CompiledContentExtension> m_compiledExtension;
     56    RefPtr<StyleSheetContents> m_globalDisplayNoneStyleSheet;
     57    bool m_parsedGlobalDisplayNoneStyleSheet;
    6658};
    6759
    6860} // namespace ContentExtensions
    69 
    7061} // namespace WebCore
    7162
    7263#endif // ENABLE(CONTENT_EXTENSIONS)
    73 
    74 #endif // ContentExtensionsBackend_h
     64#endif // ContentExtension_h
  • trunk/Source/WebCore/contentextensions/ContentExtensionsBackend.cpp

    r181754 r181876  
    3030
    3131#include "CompiledContentExtension.h"
     32#include "ContentExtension.h"
    3233#include "DFABytecodeInterpreter.h"
    3334#include "ResourceLoadInfo.h"
     
    5051    }
    5152
    52     m_contentExtensions.set(identifier, compiledContentExtension);
     53    RefPtr<ContentExtension> extension = ContentExtension::create(identifier, adoptRef(*compiledContentExtension.leakRef()));
     54    m_contentExtensions.set(identifier, WTF::move(extension));
    5355}
    5456
     
    7173    Vector<Action> finalActions;
    7274    ResourceFlags flags = resourceLoadInfo.getResourceFlags();
    73     for (auto& compiledContentExtension : m_contentExtensions) {
    74         DFABytecodeInterpreter interpreter(compiledContentExtension.value->bytecode(), compiledContentExtension.value->bytecodeLength());
     75    for (auto& contentExtension : m_contentExtensions.values()) {
     76        const CompiledContentExtension& compiledExtension = contentExtension->compiledExtension();
     77        DFABytecodeInterpreter interpreter(compiledExtension.bytecode(), compiledExtension.bytecodeLength());
    7578        DFABytecodeInterpreter::Actions triggeredActions = interpreter.interpret(urlCString, flags);
    7679       
    77         const SerializedActionByte* actions = compiledContentExtension.value->actions();
    78         const unsigned actionsLength = compiledContentExtension.value->actionsLength();
     80        const SerializedActionByte* actions = compiledExtension.actions();
     81        const unsigned actionsLength = compiledExtension.actionsLength();
    7982       
    8083        if (!triggeredActions.isEmpty()) {
     
    97100            }
    98101
    99             if (!sawIgnorePreviousRules)
    100                 finalActions.append(Action(ActionType::CSSDisplayNoneStyleSheet, compiledContentExtension.key));
     102            if (!sawIgnorePreviousRules && contentExtension->globalDisplayNoneStyleSheet())
     103                finalActions.append(Action(ActionType::CSSDisplayNoneStyleSheet, contentExtension->identifier()));
    101104        }
    102105    }
    103106    return finalActions;
     107}
     108
     109StyleSheetContents* ContentExtensionsBackend::globalDisplayNoneStyleSheet(const String& identifier) const
     110{
     111    const auto& contentExtension = m_contentExtensions.get(identifier);
     112    return contentExtension ? contentExtension->globalDisplayNoneStyleSheet() : nullptr;
    104113}
    105114
  • trunk/Source/WebCore/contentextensions/ContentExtensionsBackend.h

    r181421 r181876  
    2929#if ENABLE(CONTENT_EXTENSIONS)
    3030
     31#include "ContentExtension.h"
    3132#include "ContentExtensionRule.h"
    3233#include <wtf/HashMap.h>
     
    6162    // - Internal WebCore Interface.
    6263    WEBCORE_EXPORT Vector<Action> actionsForResourceLoad(const ResourceLoadInfo&) const;
     64    StyleSheetContents* globalDisplayNoneStyleSheet(const String& identifier) const;
    6365
    6466private:
    65     HashMap<String, RefPtr<CompiledContentExtension>> m_contentExtensions;
     67    HashMap<String, RefPtr<ContentExtension>> m_contentExtensions;
    6668};
    6769
  • trunk/Source/WebCore/contentextensions/DFABytecodeInterpreter.cpp

    r181726 r181876  
    6363    Actions actions;
    6464   
    65     // FIXME: Skip the actions from the root once they are used through actionsFromDFARoot. Change AppendAction to AppendActions to make this faster.
    66    
     65    while (static_cast<DFABytecodeInstruction>(m_bytecode[programCounter]) == DFABytecodeInstruction::AppendAction)
     66        programCounter += instructionSizeWithArguments(DFABytecodeInstruction::AppendAction);
     67
    6768    // This should always terminate if interpreting correctly compiled bytecode.
    6869    while (true) {
  • trunk/Source/WebCore/dom/DocumentStyleSheetCollection.cpp

    r180867 r181876  
    190190    m_userStyleSheets.append(CSSStyleSheet::create(WTF::move(userSheet), &m_document));
    191191    m_document.styleResolverChanged(RecalcStyleImmediately);
     192}
     193
     194void DocumentStyleSheetCollection::maybeAddContentExtensionSheet(const String& identifier, StyleSheetContents& sheet)
     195{
     196    ASSERT(sheet.isUserStyleSheet());
     197
     198    if (m_contentExtensionSheets.contains(identifier))
     199        return;
     200
     201    Ref<CSSStyleSheet> cssSheet = CSSStyleSheet::create(sheet, &m_document);
     202    m_contentExtensionSheets.set(identifier, &cssSheet.get());
     203    m_userStyleSheets.append(adoptRef(cssSheet.leakRef()));
    192204}
    193205
  • trunk/Source/WebCore/dom/DocumentStyleSheetCollection.h

    r180867 r181876  
    3131#include <memory>
    3232#include <wtf/FastMalloc.h>
     33#include <wtf/HashMap.h>
    3334#include <wtf/ListHashSet.h>
    3435#include <wtf/RefPtr.h>
     
    7071    WEBCORE_EXPORT void addAuthorSheet(Ref<StyleSheetContents>&& authorSheet);
    7172    WEBCORE_EXPORT void addUserSheet(Ref<StyleSheetContents>&& userSheet);
     73    void maybeAddContentExtensionSheet(const String& identifier, StyleSheetContents&);
    7274
    7375    enum UpdateFlag { NoUpdate = 0, OptimizedUpdate, FullUpdate };
     
    147149    Vector<RefPtr<CSSStyleSheet>> m_userStyleSheets;
    148150    Vector<RefPtr<CSSStyleSheet>> m_authorStyleSheets;
     151    HashMap<String, RefPtr<CSSStyleSheet>> m_contentExtensionSheets;
    149152
    150153    bool m_hadActiveLoadingStylesheet;
  • trunk/Source/WebCore/loader/DocumentLoader.cpp

    r181791 r181876  
    841841        m_writer.setEncoding(encoding, userChosen);
    842842    }
     843
     844#if ENABLE(CONTENT_EXTENSIONS)
     845    DocumentStyleSheetCollection& styleSheetCollection = m_frame->document()->styleSheetCollection();
     846
     847    for (auto& pendingStyleSheet : m_pendingNamedContentExtensionStyleSheets)
     848        styleSheetCollection.maybeAddContentExtensionSheet(pendingStyleSheet.key, *pendingStyleSheet.value);
     849    for (auto& pendingStyleSheet : m_pendingUnnamedContentExtensionStyleSheets)
     850        styleSheetCollection.addUserSheet(*pendingStyleSheet);
     851
     852    m_pendingNamedContentExtensionStyleSheets.clear();
     853    m_pendingUnnamedContentExtensionStyleSheets.clear();
     854#endif
     855
    843856    ASSERT(m_frame->document()->parsing());
    844857    m_writer.addData(bytes, length);
     
    14421455    static NeverDestroyed<ResourceLoaderOptions> mainResourceLoadOptions(SendCallbacks, SniffContent, BufferData, AllowStoredCredentials, AskClientForAllCredentials, SkipSecurityCheck, UseDefaultOriginRestrictionsForType, IncludeCertificateInfo);
    14431456    CachedResourceRequest cachedResourceRequest(request, mainResourceLoadOptions);
     1457    cachedResourceRequest.setInitiator(*this);
    14441458    m_mainResource = m_cachedResourceLoader->requestMainResource(cachedResourceRequest);
    14451459    if (!m_mainResource) {
     
    15731587}
    15741588
     1589#if ENABLE(CONTENT_EXTENSIONS)
     1590void DocumentLoader::addPendingContentExtensionSheet(const String& identifier, StyleSheetContents& sheet)
     1591{
     1592    ASSERT(!m_gotFirstByte);
     1593    m_pendingNamedContentExtensionStyleSheets.set(identifier, &sheet);
     1594}
     1595
     1596void DocumentLoader::addPendingContentExtensionSheet(StyleSheetContents& sheet)
     1597{
     1598    ASSERT(!m_gotFirstByte);
     1599    m_pendingUnnamedContentExtensionStyleSheets.add(&sheet);
     1600}
     1601#endif
     1602
    15751603} // namespace WebCore
  • trunk/Source/WebCore/loader/DocumentLoader.h

    r178859 r181876  
    4242#include "ResourceResponse.h"
    4343#include "StringWithDirection.h"
     44#include "StyleSheetContents.h"
    4445#include "SubstituteData.h"
    4546#include "Timer.h"
     
    268269#endif
    269270
     271#if ENABLE(CONTENT_EXTENSIONS)
     272        void addPendingContentExtensionSheet(const String& identifier, StyleSheetContents&);
     273        void addPendingContentExtensionSheet(StyleSheetContents&);
     274#endif
     275
    270276    protected:
    271277        WEBCORE_EXPORT DocumentLoader(const ResourceRequest&, const SubstituteData&);
     
    425431        std::unique_ptr<QuickLookHandle> m_quickLookHandle;
    426432#endif
     433
     434#if ENABLE(CONTENT_EXTENSIONS)
     435        HashMap<String, RefPtr<StyleSheetContents>> m_pendingNamedContentExtensionStyleSheets;
     436        HashSet<RefPtr<StyleSheetContents>> m_pendingUnnamedContentExtensionStyleSheets;
     437#endif
     438
    427439    };
    428440
  • trunk/Source/WebCore/loader/cache/CachedResourceLoader.cpp

    r181754 r181876  
    6565#include "SessionID.h"
    6666#include "Settings.h"
     67#include "StyleSheetContents.h"
    6768#include "UserContentController.h"
     69#include "UserStyleSheet.h"
    6870#include <wtf/text/CString.h>
    6971#include <wtf/text/WTFString.h>
     
    507509
    508510#if ENABLE(CONTENT_EXTENSIONS)
    509     Vector<ContentExtensions::Action> actions;
    510 
    511511    URL mainDocumentURL;
    512512    if (frame() && frame()->mainFrame().document())
    513513        mainDocumentURL = frame()->mainFrame().document()->url();
    514    
     514
    515515    ResourceLoadInfo resourceLoadInfo = { url, mainDocumentURL, toResourceType(type) };
    516    
    517     if (frame() && frame()->mainFrame().page() && frame()->mainFrame().page()->userContentController())
    518         actions = frame()->mainFrame().page()->userContentController()->actionsForResourceLoad(resourceLoadInfo);
    519 
     516
     517    Vector<ContentExtensions::Action> actions;
     518    UserContentController* userContentController = nullptr;
     519    if (frame() && frame()->mainFrame().page())
     520        userContentController = frame()->mainFrame().page()->userContentController();
     521
     522    if (userContentController)
     523        actions = userContentController->actionsForResourceLoad(resourceLoadInfo);
     524
     525    StringBuilder css;
    520526    bool willBlockLoad = false;
    521527    for (const auto& action : actions) {
     
    528534            break;
    529535        case ContentExtensions::ActionType::CSSDisplayNoneSelector:
    530             // action.cssSelector() is the css to use here.
    531             // FIXME: That css selector should be used to apply display:none.
     536            css.append(action.stringArgument());
     537            css.append(UserContentController::displayNoneCSSRule());
    532538            break;
    533         case ContentExtensions::ActionType::CSSDisplayNoneStyleSheet:
    534             // FIXME: Apply cached stylesheet here
     539        case ContentExtensions::ActionType::CSSDisplayNoneStyleSheet: {
     540            StyleSheetContents* styleSheetContents = userContentController->globalDisplayNoneStyleSheet(action.stringArgument());
     541            RELEASE_ASSERT(styleSheetContents);
     542
     543            if (type == CachedResource::MainResource && request.initiatingDocumentLoader())
     544                request.initiatingDocumentLoader()->addPendingContentExtensionSheet(action.stringArgument(), *styleSheetContents);
     545            else if (m_document)
     546                m_document->styleSheetCollection().maybeAddContentExtensionSheet(action.stringArgument(), *styleSheetContents);
     547
    535548            break;
     549        }
    536550        case ContentExtensions::ActionType::IgnorePreviousRules:
    537551        case ContentExtensions::ActionType::InvalidAction:
     
    539553        }
    540554    }
     555
     556    if (css.length()) {
     557        Ref<StyleSheetContents> styleSheet = StyleSheetContents::create();
     558        styleSheet->setIsUserStyleSheet(true);
     559
     560        if (styleSheet->parseString(css.toString())) {
     561            if (type == CachedResource::MainResource && request.initiatingDocumentLoader())
     562                request.initiatingDocumentLoader()->addPendingContentExtensionSheet(styleSheet);
     563            else if (m_document)
     564                m_document->styleSheetCollection().addUserSheet(WTF::move(styleSheet));
     565        }
     566    }
     567
    541568    if (willBlockLoad)
    542569        return nullptr;
  • trunk/Source/WebCore/loader/cache/CachedResourceRequest.cpp

    r179584 r181876  
    7676}
    7777
     78void CachedResourceRequest::setInitiator(DocumentLoader& documentLoader)
     79{
     80    m_initiatingDocumentLoader = &documentLoader;
     81}
     82
    7883const AtomicString& CachedResourceRequest::initiatorName() const
    7984{
  • trunk/Source/WebCore/loader/cache/CachedResourceRequest.h

    r179584 r181876  
    2727#define CachedResourceRequest_h
    2828
     29#include "DocumentLoader.h"
    2930#include "Element.h"
    3031#include "ResourceLoadPriority.h"
     
    6162    const AtomicString& initiatorName() const;
    6263
     64    void setInitiator(DocumentLoader&);
     65    DocumentLoader* initiatingDocumentLoader() const { return m_initiatingDocumentLoader.get(); }
     66
    6367private:
    6468    ResourceRequest m_resourceRequest;
     
    7074    RefPtr<Element> m_initiatorElement;
    7175    AtomicString m_initiatorName;
     76    RefPtr<DocumentLoader> m_initiatingDocumentLoader;
    7277};
    7378
  • trunk/Source/WebCore/page/UserContentController.cpp

    r181421 r181876  
    3434#include "UserScript.h"
    3535#include "UserStyleSheet.h"
     36#include <wtf/NeverDestroyed.h>
    3637
    3738#if ENABLE(USER_MESSAGE_HANDLERS)
     
    213214}
    214215
     216StyleSheetContents* UserContentController::globalDisplayNoneStyleSheet(const String& identifier) const
     217{
     218    if (!m_contentExtensionBackend)
     219        return nullptr;
     220
     221    return m_contentExtensionBackend->globalDisplayNoneStyleSheet(identifier);
     222}
     223
     224const String& UserContentController::displayNoneCSSRule()
     225{
     226    static NeverDestroyed<const String> rule(ASCIILiteral("{display:none !important;}\n"));
     227    return rule;
     228}
     229
    215230#endif
    216231
  • trunk/Source/WebCore/page/UserContentController.h

    r181421 r181876  
    4141class DOMWrapperWorld;
    4242class Page;
     43class StyleSheetContents;
    4344class URL;
    4445class UserScript;
     
    8889   
    8990    Vector<ContentExtensions::Action> actionsForResourceLoad(const ResourceLoadInfo&);
     91    StyleSheetContents* globalDisplayNoneStyleSheet(const String& identifier) const;
     92    static const String& displayNoneCSSRule();
    9093#endif
    9194
Note: See TracChangeset for help on using the changeset viewer.