Diff
Modified: trunk/LayoutTests/ChangeLog (181875 => 181876)
--- trunk/LayoutTests/ChangeLog 2015-03-23 22:31:07 UTC (rev 181875)
+++ trunk/LayoutTests/ChangeLog 2015-03-23 22:34:53 UTC (rev 181876)
@@ -1,3 +1,14 @@
+2015-03-23 Brady Eidson <[email protected]>
+
+ Content extensions should apply css selectors
+ https://bugs.webkit.org/show_bug.cgi?id=142604
+
+ Reviewed by Alex Christensen.
+
+ * http/tests/contentextensions/css-display-none-expected.txt:
+ * http/tests/contentextensions/css-display-none.html:
+ * http/tests/contentextensions/css-display-none.html.json:
+
2015-03-23 Dean Jackson <[email protected]>
ES7: Implement Array.prototype.includes
Modified: trunk/LayoutTests/http/tests/contentextensions/css-display-none-expected.txt (181875 => 181876)
--- trunk/LayoutTests/http/tests/contentextensions/css-display-none-expected.txt 2015-03-23 22:31:07 UTC (rev 181875)
+++ trunk/LayoutTests/http/tests/contentextensions/css-display-none-expected.txt 2015-03-23 22:34:53 UTC (rev 181876)
@@ -4,11 +4,5 @@
RenderBlock {HTML} at (0,0) size 800x600
RenderBody {BODY} at (8,8) size 784x576
RenderBlock {P} at (0,0) size 784x18
- RenderText {#text} at (0,0) size 492x18
- text run at (0,0) width 492: "This text should not be visible once the css selector is applied (not done yet)."
- RenderBlock {P} at (0,34) size 784x18
- RenderText {#text} at (0,0) size 522x18
- text run at (0,0) width 522: "This text should also not be visible once the css selector is applied (not done yet)."
- RenderBlock {P} at (0,68) size 784x18
RenderText {#text} at (0,0) size 173x18
text run at (0,0) width 173: "This text should be visible."
Modified: trunk/LayoutTests/http/tests/contentextensions/css-display-none.html (181875 => 181876)
--- trunk/LayoutTests/http/tests/contentextensions/css-display-none.html 2015-03-23 22:31:07 UTC (rev 181875)
+++ trunk/LayoutTests/http/tests/contentextensions/css-display-none.html 2015-03-23 22:34:53 UTC (rev 181876)
@@ -1,5 +1,9 @@
+<head>
+<meta charset="UTF-8"></meta>
+</head>
<body>
-<p class="hidden">This text should not be visible once the css selector is applied (not done yet).</p>
-<p class="hidden_Ž">This text should also not be visible once the css selector is applied (not done yet).</p>
+<p class="hidden_global">This text should not be visible once the global css selector is applied.</p>
+<p class="hidden">This text should not be visible once the particular css selector is applied.</p>
+<p class="hidden_Ž">This text should not be visible once the particular css selector with non-ascii characters is applied.</p>
<p class="not_hidden">This text should be visible.</p>
</body>
Modified: trunk/LayoutTests/http/tests/contentextensions/css-display-none.html.json (181875 => 181876)
--- trunk/LayoutTests/http/tests/contentextensions/css-display-none.html.json 2015-03-23 22:31:07 UTC (rev 181875)
+++ trunk/LayoutTests/http/tests/contentextensions/css-display-none.html.json 2015-03-23 22:34:53 UTC (rev 181876)
@@ -16,5 +16,14 @@
"trigger": {
"url-filter": ".*css-display-none.html"
}
+ },
+ {
+ "action": {
+ "type": "css-display-none",
+ "selector": ".hidden_global"
+ },
+ "trigger": {
+ "url-filter": ".*"
+ }
}
]
Modified: trunk/Source/WebCore/ChangeLog (181875 => 181876)
--- trunk/Source/WebCore/ChangeLog 2015-03-23 22:31:07 UTC (rev 181875)
+++ trunk/Source/WebCore/ChangeLog 2015-03-23 22:34:53 UTC (rev 181876)
@@ -1,3 +1,54 @@
+2015-03-23 Brady Eidson <[email protected]>
+
+ Content extensions should apply css selectors
+ https://bugs.webkit.org/show_bug.cgi?id=142604
+
+ Reviewed by Alex Christensen.
+
+ 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:
+
2015-03-23 Anders Carlsson <[email protected]>
-[_WKWebsiteDataStore removeDataOfTypes:modifiedSince:completionHandler:] doesn't remove cookies
Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (181875 => 181876)
--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2015-03-23 22:31:07 UTC (rev 181875)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2015-03-23 22:34:53 UTC (rev 181876)
@@ -1988,6 +1988,8 @@
51AF503616F100F60095B2E8 /* ResourceLoaderTypes.h in Headers */ = {isa = PBXBuildFile; fileRef = 51AF503516F100F60095B2E8 /* ResourceLoaderTypes.h */; settings = {ATTRIBUTES = (Private, ); }; };
51B07A441823248B00AA8D1A /* IDBPendingDeleteCall.h in Headers */ = {isa = PBXBuildFile; fileRef = 51B07A431823248B00AA8D1A /* IDBPendingDeleteCall.h */; settings = {ATTRIBUTES = (Private, ); }; };
51B2417B0D931F3F00E83F5C /* LegacyWebArchiveMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 51B2417A0D931F3F00E83F5C /* LegacyWebArchiveMac.mm */; };
+ 51B45D201AB8D1E200117CD2 /* ContentExtension.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 51B45D1E1AB8D1E200117CD2 /* ContentExtension.cpp */; };
+ 51B45D211AB8D1E200117CD2 /* ContentExtension.h in Headers */ = {isa = PBXBuildFile; fileRef = 51B45D1F1AB8D1E200117CD2 /* ContentExtension.h */; settings = {ATTRIBUTES = (Private, ); }; };
51B58FD4195A964D002990B0 /* PlatformGamepad.h in Headers */ = {isa = PBXBuildFile; fileRef = 515E5FEF195101470086CA5E /* PlatformGamepad.h */; settings = {ATTRIBUTES = (Private, ); }; };
51BE37E00DAEE00E001085FC /* StorageArea.h in Headers */ = {isa = PBXBuildFile; fileRef = 51BE37DE0DAEE00E001085FC /* StorageArea.h */; settings = {ATTRIBUTES = (Private, ); }; };
51C0AA390F2AA10A001648C2 /* CachedFrame.h in Headers */ = {isa = PBXBuildFile; fileRef = 51C0AA380F2AA10A001648C2 /* CachedFrame.h */; settings = {ATTRIBUTES = (Private, ); }; };
@@ -6307,7 +6309,7 @@
E4E9B11B18145692003ACCDF /* SimpleLineLayoutFunctions.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E4E9B11A18145692003ACCDF /* SimpleLineLayoutFunctions.cpp */; };
E4E9B11D1814569C003ACCDF /* SimpleLineLayoutFunctions.h in Headers */ = {isa = PBXBuildFile; fileRef = E4E9B11C1814569C003ACCDF /* SimpleLineLayoutFunctions.h */; };
E4F9EEF2156D9FFA00D23E7E /* StyleSheetContents.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E4F9EEF0156D84C400D23E7E /* StyleSheetContents.cpp */; };
- E4F9EEF3156DA00700D23E7E /* StyleSheetContents.h in Headers */ = {isa = PBXBuildFile; fileRef = E4F9EEF1156D84C400D23E7E /* StyleSheetContents.h */; };
+ E4F9EEF3156DA00700D23E7E /* StyleSheetContents.h in Headers */ = {isa = PBXBuildFile; fileRef = E4F9EEF1156D84C400D23E7E /* StyleSheetContents.h */; settings = {ATTRIBUTES = (Private, ); }; };
E51A81DF17298D7700BFCA61 /* JSPerformance.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E51A81DE17298D7700BFCA61 /* JSPerformance.cpp */; };
E526AF3F1727F8F200E41781 /* Performance.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E526AF3E1727F8F200E41781 /* Performance.cpp */; };
E55F497A151B888000BB67DB /* LengthFunctions.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E55F4979151B888000BB67DB /* LengthFunctions.cpp */; };
@@ -9156,6 +9158,8 @@
51AF503516F100F60095B2E8 /* ResourceLoaderTypes.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ResourceLoaderTypes.h; sourceTree = "<group>"; };
51B07A431823248B00AA8D1A /* IDBPendingDeleteCall.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IDBPendingDeleteCall.h; sourceTree = "<group>"; };
51B2417A0D931F3F00E83F5C /* LegacyWebArchiveMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = LegacyWebArchiveMac.mm; sourceTree = "<group>"; };
+ 51B45D1E1AB8D1E200117CD2 /* ContentExtension.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ContentExtension.cpp; sourceTree = "<group>"; };
+ 51B45D1F1AB8D1E200117CD2 /* ContentExtension.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ContentExtension.h; sourceTree = "<group>"; };
51BE37DE0DAEE00E001085FC /* StorageArea.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StorageArea.h; sourceTree = "<group>"; };
51C0AA380F2AA10A001648C2 /* CachedFrame.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CachedFrame.h; sourceTree = "<group>"; };
51C0AA400F2AA15E001648C2 /* CachedFrame.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; lineEnding = 0; path = CachedFrame.cpp; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.cpp; };
@@ -15483,6 +15487,8 @@
26F0C8901A2D79CB002794F8 /* contentextensions */ = {
isa = PBXGroup;
children = (
+ 51B45D1E1AB8D1E200117CD2 /* ContentExtension.cpp */,
+ 51B45D1F1AB8D1E200117CD2 /* ContentExtension.h */,
7C93F3471AA6BA5E00A98BAB /* CompiledContentExtension.cpp */,
7C93F3481AA6BA5E00A98BAB /* CompiledContentExtension.h */,
5CDFA6C71AA4F2DA00EA8746 /* ContentExtensionActions.h */,
@@ -25902,6 +25908,7 @@
84730D921248F0B300D3A9C9 /* PointLightSource.h in Headers */,
97059978107D975200A50A7C /* PolicyCallback.h in Headers */,
9705997A107D975200A50A7C /* PolicyChecker.h in Headers */,
+ 51B45D211AB8D1E200117CD2 /* ContentExtension.h in Headers */,
FD45A957175D414C00C21EC8 /* PolygonShape.h in Headers */,
5174E20A10A1F44F00F95E6F /* PopStateEvent.h in Headers */,
0668E18B0ADD9624004128E0 /* PopupMenu.h in Headers */,
@@ -30302,6 +30309,7 @@
0B9056F80F2685F30095FF6A /* WorkerThreadableLoader.cpp in Sources */,
97AABD2C14FA09D5007457AE /* WorkerThreadableWebSocketChannel.cpp in Sources */,
93309E23099E64920056E581 /* WrapContentsInDummySpanCommand.cpp in Sources */,
+ 51B45D201AB8D1E200117CD2 /* ContentExtension.cpp in Sources */,
A833C7CC0A2CF07400D57664 /* XLinkNames.cpp in Sources */,
00B9318713BA8DB30035A948 /* XMLDocumentParser.cpp in Sources */,
00B9318913BA8DBC0035A948 /* XMLDocumentParserLibxml2.cpp in Sources */,
Added: trunk/Source/WebCore/contentextensions/ContentExtension.cpp (0 => 181876)
--- trunk/Source/WebCore/contentextensions/ContentExtension.cpp (rev 0)
+++ trunk/Source/WebCore/contentextensions/ContentExtension.cpp 2015-03-23 22:34:53 UTC (rev 181876)
@@ -0,0 +1,79 @@
+/*
+ * Copyright (C) 2015 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "ContentExtension.h"
+
+#include "CompiledContentExtension.h"
+#include "StyleSheetContents.h"
+#include "UserContentController.h"
+#include <wtf/text/StringBuilder.h>
+
+#if ENABLE(CONTENT_EXTENSIONS)
+
+namespace WebCore {
+namespace ContentExtensions {
+
+RefPtr<ContentExtension> ContentExtension::create(const String& identifier, Ref<CompiledContentExtension>&& compiledExtension)
+{
+ return adoptRef(*new ContentExtension(identifier, WTF::move(compiledExtension)));
+}
+
+ContentExtension::ContentExtension(const String& identifier, Ref<CompiledContentExtension>&& compiledExtension)
+ : m_identifier(identifier)
+ , m_compiledExtension(WTF::move(compiledExtension))
+ , m_parsedGlobalDisplayNoneStyleSheet(false)
+{
+}
+
+StyleSheetContents* ContentExtension::globalDisplayNoneStyleSheet()
+{
+ if (m_parsedGlobalDisplayNoneStyleSheet)
+ return m_globalDisplayNoneStyleSheet.get();
+
+ m_parsedGlobalDisplayNoneStyleSheet = true;
+
+ Vector<String> selectors = m_compiledExtension->globalDisplayNoneSelectors();
+ if (selectors.isEmpty())
+ return nullptr;
+
+ StringBuilder css;
+ for (auto& selector : selectors) {
+ css.append(selector);
+ css.append(UserContentController::displayNoneCSSRule());
+ }
+
+ m_globalDisplayNoneStyleSheet = StyleSheetContents::create();
+ m_globalDisplayNoneStyleSheet->setIsUserStyleSheet(true);
+ if (!m_globalDisplayNoneStyleSheet->parseString(css.toString()))
+ m_globalDisplayNoneStyleSheet = nullptr;
+
+ return m_globalDisplayNoneStyleSheet.get();
+}
+
+} // namespace ContentExtensions
+} // namespace WebCore
+
+#endif // ENABLE(CONTENT_EXTENSIONS)
Copied: trunk/Source/WebCore/contentextensions/ContentExtension.h (from rev 181875, trunk/Source/WebCore/contentextensions/ContentExtensionsBackend.h) (0 => 181876)
--- trunk/Source/WebCore/contentextensions/ContentExtension.h (rev 0)
+++ trunk/Source/WebCore/contentextensions/ContentExtension.h 2015-03-23 22:34:53 UTC (rev 181876)
@@ -0,0 +1,64 @@
+/*
+ * Copyright (C) 2015 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef ContentExtension_h
+#define ContentExtension_h
+
+#include <wtf/Ref.h>
+#include <wtf/RefCounted.h>
+#include <wtf/RefPtr.h>
+
+#if ENABLE(CONTENT_EXTENSIONS)
+
+#include "StyleSheetContents.h"
+
+namespace WebCore {
+
+namespace ContentExtensions {
+
+class CompiledContentExtension;
+
+class ContentExtension : public RefCounted<ContentExtension> {
+public:
+ static RefPtr<ContentExtension> create(const String& identifier, Ref<CompiledContentExtension>&&);
+
+ const String& identifier() const { return m_identifier; }
+ const CompiledContentExtension& compiledExtension() const { return m_compiledExtension.get(); }
+ StyleSheetContents* globalDisplayNoneStyleSheet();
+
+private:
+ ContentExtension(const String& identifier, Ref<CompiledContentExtension>&&);
+
+ String m_identifier;
+ Ref<CompiledContentExtension> m_compiledExtension;
+ RefPtr<StyleSheetContents> m_globalDisplayNoneStyleSheet;
+ bool m_parsedGlobalDisplayNoneStyleSheet;
+};
+
+} // namespace ContentExtensions
+} // namespace WebCore
+
+#endif // ENABLE(CONTENT_EXTENSIONS)
+#endif // ContentExtension_h
Modified: trunk/Source/WebCore/contentextensions/ContentExtensionsBackend.cpp (181875 => 181876)
--- trunk/Source/WebCore/contentextensions/ContentExtensionsBackend.cpp 2015-03-23 22:31:07 UTC (rev 181875)
+++ trunk/Source/WebCore/contentextensions/ContentExtensionsBackend.cpp 2015-03-23 22:34:53 UTC (rev 181876)
@@ -29,6 +29,7 @@
#if ENABLE(CONTENT_EXTENSIONS)
#include "CompiledContentExtension.h"
+#include "ContentExtension.h"
#include "DFABytecodeInterpreter.h"
#include "ResourceLoadInfo.h"
#include "URL.h"
@@ -49,7 +50,8 @@
return;
}
- m_contentExtensions.set(identifier, compiledContentExtension);
+ RefPtr<ContentExtension> extension = ContentExtension::create(identifier, adoptRef(*compiledContentExtension.leakRef()));
+ m_contentExtensions.set(identifier, WTF::move(extension));
}
void ContentExtensionsBackend::removeContentExtension(const String& identifier)
@@ -70,12 +72,13 @@
Vector<Action> finalActions;
ResourceFlags flags = resourceLoadInfo.getResourceFlags();
- for (auto& compiledContentExtension : m_contentExtensions) {
- DFABytecodeInterpreter interpreter(compiledContentExtension.value->bytecode(), compiledContentExtension.value->bytecodeLength());
+ for (auto& contentExtension : m_contentExtensions.values()) {
+ const CompiledContentExtension& compiledExtension = contentExtension->compiledExtension();
+ DFABytecodeInterpreter interpreter(compiledExtension.bytecode(), compiledExtension.bytecodeLength());
DFABytecodeInterpreter::Actions triggeredActions = interpreter.interpret(urlCString, flags);
- const SerializedActionByte* actions = compiledContentExtension.value->actions();
- const unsigned actionsLength = compiledContentExtension.value->actionsLength();
+ const SerializedActionByte* actions = compiledExtension.actions();
+ const unsigned actionsLength = compiledExtension.actionsLength();
if (!triggeredActions.isEmpty()) {
Vector<unsigned> actionLocations;
@@ -96,13 +99,19 @@
finalActions.append(action);
}
- if (!sawIgnorePreviousRules)
- finalActions.append(Action(ActionType::CSSDisplayNoneStyleSheet, compiledContentExtension.key));
+ if (!sawIgnorePreviousRules && contentExtension->globalDisplayNoneStyleSheet())
+ finalActions.append(Action(ActionType::CSSDisplayNoneStyleSheet, contentExtension->identifier()));
}
}
return finalActions;
}
+StyleSheetContents* ContentExtensionsBackend::globalDisplayNoneStyleSheet(const String& identifier) const
+{
+ const auto& contentExtension = m_contentExtensions.get(identifier);
+ return contentExtension ? contentExtension->globalDisplayNoneStyleSheet() : nullptr;
+}
+
} // namespace ContentExtensions
} // namespace WebCore
Modified: trunk/Source/WebCore/contentextensions/ContentExtensionsBackend.h (181875 => 181876)
--- trunk/Source/WebCore/contentextensions/ContentExtensionsBackend.h 2015-03-23 22:31:07 UTC (rev 181875)
+++ trunk/Source/WebCore/contentextensions/ContentExtensionsBackend.h 2015-03-23 22:34:53 UTC (rev 181876)
@@ -28,6 +28,7 @@
#if ENABLE(CONTENT_EXTENSIONS)
+#include "ContentExtension.h"
#include "ContentExtensionRule.h"
#include <wtf/HashMap.h>
#include <wtf/text/StringHash.h>
@@ -60,9 +61,10 @@
// - Internal WebCore Interface.
WEBCORE_EXPORT Vector<Action> actionsForResourceLoad(const ResourceLoadInfo&) const;
+ StyleSheetContents* globalDisplayNoneStyleSheet(const String& identifier) const;
private:
- HashMap<String, RefPtr<CompiledContentExtension>> m_contentExtensions;
+ HashMap<String, RefPtr<ContentExtension>> m_contentExtensions;
};
} // namespace ContentExtensions
Modified: trunk/Source/WebCore/contentextensions/DFABytecodeInterpreter.cpp (181875 => 181876)
--- trunk/Source/WebCore/contentextensions/DFABytecodeInterpreter.cpp 2015-03-23 22:31:07 UTC (rev 181875)
+++ trunk/Source/WebCore/contentextensions/DFABytecodeInterpreter.cpp 2015-03-23 22:34:53 UTC (rev 181876)
@@ -62,8 +62,9 @@
bool urlIndexIsAfterEndOfString = false;
Actions actions;
- // FIXME: Skip the actions from the root once they are used through actionsFromDFARoot. Change AppendAction to AppendActions to make this faster.
-
+ while (static_cast<DFABytecodeInstruction>(m_bytecode[programCounter]) == DFABytecodeInstruction::AppendAction)
+ programCounter += instructionSizeWithArguments(DFABytecodeInstruction::AppendAction);
+
// This should always terminate if interpreting correctly compiled bytecode.
while (true) {
ASSERT(programCounter <= m_bytecodeLength);
Modified: trunk/Source/WebCore/dom/DocumentStyleSheetCollection.cpp (181875 => 181876)
--- trunk/Source/WebCore/dom/DocumentStyleSheetCollection.cpp 2015-03-23 22:31:07 UTC (rev 181875)
+++ trunk/Source/WebCore/dom/DocumentStyleSheetCollection.cpp 2015-03-23 22:34:53 UTC (rev 181876)
@@ -191,6 +191,18 @@
m_document.styleResolverChanged(RecalcStyleImmediately);
}
+void DocumentStyleSheetCollection::maybeAddContentExtensionSheet(const String& identifier, StyleSheetContents& sheet)
+{
+ ASSERT(sheet.isUserStyleSheet());
+
+ if (m_contentExtensionSheets.contains(identifier))
+ return;
+
+ Ref<CSSStyleSheet> cssSheet = CSSStyleSheet::create(sheet, &m_document);
+ m_contentExtensionSheets.set(identifier, &cssSheet.get());
+ m_userStyleSheets.append(adoptRef(cssSheet.leakRef()));
+}
+
// This method is called whenever a top-level stylesheet has finished loading.
void DocumentStyleSheetCollection::removePendingSheet(RemovePendingSheetNotificationType notification)
{
Modified: trunk/Source/WebCore/dom/DocumentStyleSheetCollection.h (181875 => 181876)
--- trunk/Source/WebCore/dom/DocumentStyleSheetCollection.h 2015-03-23 22:31:07 UTC (rev 181875)
+++ trunk/Source/WebCore/dom/DocumentStyleSheetCollection.h 2015-03-23 22:34:53 UTC (rev 181876)
@@ -30,6 +30,7 @@
#include <memory>
#include <wtf/FastMalloc.h>
+#include <wtf/HashMap.h>
#include <wtf/ListHashSet.h>
#include <wtf/RefPtr.h>
#include <wtf/Vector.h>
@@ -69,6 +70,7 @@
WEBCORE_EXPORT void addAuthorSheet(Ref<StyleSheetContents>&& authorSheet);
WEBCORE_EXPORT void addUserSheet(Ref<StyleSheetContents>&& userSheet);
+ void maybeAddContentExtensionSheet(const String& identifier, StyleSheetContents&);
enum UpdateFlag { NoUpdate = 0, OptimizedUpdate, FullUpdate };
@@ -146,6 +148,7 @@
Vector<RefPtr<CSSStyleSheet>> m_userStyleSheets;
Vector<RefPtr<CSSStyleSheet>> m_authorStyleSheets;
+ HashMap<String, RefPtr<CSSStyleSheet>> m_contentExtensionSheets;
bool m_hadActiveLoadingStylesheet;
UpdateFlag m_pendingUpdateType;
Modified: trunk/Source/WebCore/loader/DocumentLoader.cpp (181875 => 181876)
--- trunk/Source/WebCore/loader/DocumentLoader.cpp 2015-03-23 22:31:07 UTC (rev 181875)
+++ trunk/Source/WebCore/loader/DocumentLoader.cpp 2015-03-23 22:34:53 UTC (rev 181876)
@@ -840,6 +840,19 @@
m_writer.setEncoding(encoding, userChosen);
}
+
+#if ENABLE(CONTENT_EXTENSIONS)
+ DocumentStyleSheetCollection& styleSheetCollection = m_frame->document()->styleSheetCollection();
+
+ for (auto& pendingStyleSheet : m_pendingNamedContentExtensionStyleSheets)
+ styleSheetCollection.maybeAddContentExtensionSheet(pendingStyleSheet.key, *pendingStyleSheet.value);
+ for (auto& pendingStyleSheet : m_pendingUnnamedContentExtensionStyleSheets)
+ styleSheetCollection.addUserSheet(*pendingStyleSheet);
+
+ m_pendingNamedContentExtensionStyleSheets.clear();
+ m_pendingUnnamedContentExtensionStyleSheets.clear();
+#endif
+
ASSERT(m_frame->document()->parsing());
m_writer.addData(bytes, length);
}
@@ -1441,6 +1454,7 @@
ResourceRequest request(m_request);
static NeverDestroyed<ResourceLoaderOptions> mainResourceLoadOptions(SendCallbacks, SniffContent, BufferData, AllowStoredCredentials, AskClientForAllCredentials, SkipSecurityCheck, UseDefaultOriginRestrictionsForType, IncludeCertificateInfo);
CachedResourceRequest cachedResourceRequest(request, mainResourceLoadOptions);
+ cachedResourceRequest.setInitiator(*this);
m_mainResource = m_cachedResourceLoader->requestMainResource(cachedResourceRequest);
if (!m_mainResource) {
setRequest(ResourceRequest());
@@ -1572,4 +1586,18 @@
applicationCacheHost()->stopDeferringEvents();
}
+#if ENABLE(CONTENT_EXTENSIONS)
+void DocumentLoader::addPendingContentExtensionSheet(const String& identifier, StyleSheetContents& sheet)
+{
+ ASSERT(!m_gotFirstByte);
+ m_pendingNamedContentExtensionStyleSheets.set(identifier, &sheet);
+}
+
+void DocumentLoader::addPendingContentExtensionSheet(StyleSheetContents& sheet)
+{
+ ASSERT(!m_gotFirstByte);
+ m_pendingUnnamedContentExtensionStyleSheets.add(&sheet);
+}
+#endif
+
} // namespace WebCore
Modified: trunk/Source/WebCore/loader/DocumentLoader.h (181875 => 181876)
--- trunk/Source/WebCore/loader/DocumentLoader.h 2015-03-23 22:31:07 UTC (rev 181875)
+++ trunk/Source/WebCore/loader/DocumentLoader.h 2015-03-23 22:34:53 UTC (rev 181876)
@@ -41,6 +41,7 @@
#include "ResourceRequest.h"
#include "ResourceResponse.h"
#include "StringWithDirection.h"
+#include "StyleSheetContents.h"
#include "SubstituteData.h"
#include "Timer.h"
#include <wtf/HashSet.h>
@@ -267,6 +268,11 @@
QuickLookHandle* quickLookHandle() const { return m_quickLookHandle.get(); }
#endif
+#if ENABLE(CONTENT_EXTENSIONS)
+ void addPendingContentExtensionSheet(const String& identifier, StyleSheetContents&);
+ void addPendingContentExtensionSheet(StyleSheetContents&);
+#endif
+
protected:
WEBCORE_EXPORT DocumentLoader(const ResourceRequest&, const SubstituteData&);
@@ -424,6 +430,12 @@
#if USE(QUICK_LOOK)
std::unique_ptr<QuickLookHandle> m_quickLookHandle;
#endif
+
+#if ENABLE(CONTENT_EXTENSIONS)
+ HashMap<String, RefPtr<StyleSheetContents>> m_pendingNamedContentExtensionStyleSheets;
+ HashSet<RefPtr<StyleSheetContents>> m_pendingUnnamedContentExtensionStyleSheets;
+#endif
+
};
inline void DocumentLoader::recordMemoryCacheLoadForFutureClientNotification(const ResourceRequest& request)
Modified: trunk/Source/WebCore/loader/cache/CachedResourceLoader.cpp (181875 => 181876)
--- trunk/Source/WebCore/loader/cache/CachedResourceLoader.cpp 2015-03-23 22:31:07 UTC (rev 181875)
+++ trunk/Source/WebCore/loader/cache/CachedResourceLoader.cpp 2015-03-23 22:34:53 UTC (rev 181876)
@@ -64,7 +64,9 @@
#include "SecurityOrigin.h"
#include "SessionID.h"
#include "Settings.h"
+#include "StyleSheetContents.h"
#include "UserContentController.h"
+#include "UserStyleSheet.h"
#include <wtf/text/CString.h>
#include <wtf/text/WTFString.h>
@@ -506,17 +508,21 @@
return nullptr;
#if ENABLE(CONTENT_EXTENSIONS)
- Vector<ContentExtensions::Action> actions;
-
URL mainDocumentURL;
if (frame() && frame()->mainFrame().document())
mainDocumentURL = frame()->mainFrame().document()->url();
-
+
ResourceLoadInfo resourceLoadInfo = { url, mainDocumentURL, toResourceType(type) };
-
- if (frame() && frame()->mainFrame().page() && frame()->mainFrame().page()->userContentController())
- actions = frame()->mainFrame().page()->userContentController()->actionsForResourceLoad(resourceLoadInfo);
+ Vector<ContentExtensions::Action> actions;
+ UserContentController* userContentController = nullptr;
+ if (frame() && frame()->mainFrame().page())
+ userContentController = frame()->mainFrame().page()->userContentController();
+
+ if (userContentController)
+ actions = userContentController->actionsForResourceLoad(resourceLoadInfo);
+
+ StringBuilder css;
bool willBlockLoad = false;
for (const auto& action : actions) {
switch (action.type()) {
@@ -527,17 +533,38 @@
request.mutableResourceRequest().setAllowCookies(false);
break;
case ContentExtensions::ActionType::CSSDisplayNoneSelector:
- // action.cssSelector() is the css to use here.
- // FIXME: That css selector should be used to apply display:none.
+ css.append(action.stringArgument());
+ css.append(UserContentController::displayNoneCSSRule());
break;
- case ContentExtensions::ActionType::CSSDisplayNoneStyleSheet:
- // FIXME: Apply cached stylesheet here
+ case ContentExtensions::ActionType::CSSDisplayNoneStyleSheet: {
+ StyleSheetContents* styleSheetContents = userContentController->globalDisplayNoneStyleSheet(action.stringArgument());
+ RELEASE_ASSERT(styleSheetContents);
+
+ if (type == CachedResource::MainResource && request.initiatingDocumentLoader())
+ request.initiatingDocumentLoader()->addPendingContentExtensionSheet(action.stringArgument(), *styleSheetContents);
+ else if (m_document)
+ m_document->styleSheetCollection().maybeAddContentExtensionSheet(action.stringArgument(), *styleSheetContents);
+
break;
+ }
case ContentExtensions::ActionType::IgnorePreviousRules:
case ContentExtensions::ActionType::InvalidAction:
RELEASE_ASSERT_NOT_REACHED();
}
}
+
+ if (css.length()) {
+ Ref<StyleSheetContents> styleSheet = StyleSheetContents::create();
+ styleSheet->setIsUserStyleSheet(true);
+
+ if (styleSheet->parseString(css.toString())) {
+ if (type == CachedResource::MainResource && request.initiatingDocumentLoader())
+ request.initiatingDocumentLoader()->addPendingContentExtensionSheet(styleSheet);
+ else if (m_document)
+ m_document->styleSheetCollection().addUserSheet(WTF::move(styleSheet));
+ }
+ }
+
if (willBlockLoad)
return nullptr;
#endif
Modified: trunk/Source/WebCore/loader/cache/CachedResourceRequest.cpp (181875 => 181876)
--- trunk/Source/WebCore/loader/cache/CachedResourceRequest.cpp 2015-03-23 22:31:07 UTC (rev 181875)
+++ trunk/Source/WebCore/loader/cache/CachedResourceRequest.cpp 2015-03-23 22:34:53 UTC (rev 181876)
@@ -75,6 +75,11 @@
m_initiatorName = name;
}
+void CachedResourceRequest::setInitiator(DocumentLoader& documentLoader)
+{
+ m_initiatingDocumentLoader = &documentLoader;
+}
+
const AtomicString& CachedResourceRequest::initiatorName() const
{
if (m_initiatorElement)
Modified: trunk/Source/WebCore/loader/cache/CachedResourceRequest.h (181875 => 181876)
--- trunk/Source/WebCore/loader/cache/CachedResourceRequest.h 2015-03-23 22:31:07 UTC (rev 181875)
+++ trunk/Source/WebCore/loader/cache/CachedResourceRequest.h 2015-03-23 22:34:53 UTC (rev 181876)
@@ -26,6 +26,7 @@
#ifndef CachedResourceRequest_h
#define CachedResourceRequest_h
+#include "DocumentLoader.h"
#include "Element.h"
#include "ResourceLoadPriority.h"
#include "ResourceLoaderOptions.h"
@@ -60,6 +61,9 @@
void setInitiator(const AtomicString& name);
const AtomicString& initiatorName() const;
+ void setInitiator(DocumentLoader&);
+ DocumentLoader* initiatingDocumentLoader() const { return m_initiatingDocumentLoader.get(); }
+
private:
ResourceRequest m_resourceRequest;
String m_charset;
@@ -69,6 +73,7 @@
DeferOption m_defer;
RefPtr<Element> m_initiatorElement;
AtomicString m_initiatorName;
+ RefPtr<DocumentLoader> m_initiatingDocumentLoader;
};
} // namespace WebCore
Modified: trunk/Source/WebCore/page/UserContentController.cpp (181875 => 181876)
--- trunk/Source/WebCore/page/UserContentController.cpp 2015-03-23 22:31:07 UTC (rev 181875)
+++ trunk/Source/WebCore/page/UserContentController.cpp 2015-03-23 22:34:53 UTC (rev 181876)
@@ -33,6 +33,7 @@
#include "ResourceLoadInfo.h"
#include "UserScript.h"
#include "UserStyleSheet.h"
+#include <wtf/NeverDestroyed.h>
#if ENABLE(USER_MESSAGE_HANDLERS)
#include "UserMessageHandlerDescriptor.h"
@@ -212,6 +213,20 @@
return m_contentExtensionBackend->actionsForResourceLoad(resourceLoadInfo);
}
+StyleSheetContents* UserContentController::globalDisplayNoneStyleSheet(const String& identifier) const
+{
+ if (!m_contentExtensionBackend)
+ return nullptr;
+
+ return m_contentExtensionBackend->globalDisplayNoneStyleSheet(identifier);
+}
+
+const String& UserContentController::displayNoneCSSRule()
+{
+ static NeverDestroyed<const String> rule(ASCIILiteral("{display:none !important;}\n"));
+ return rule;
+}
+
#endif
void UserContentController::removeAllUserContent()
Modified: trunk/Source/WebCore/page/UserContentController.h (181875 => 181876)
--- trunk/Source/WebCore/page/UserContentController.h 2015-03-23 22:31:07 UTC (rev 181875)
+++ trunk/Source/WebCore/page/UserContentController.h 2015-03-23 22:34:53 UTC (rev 181876)
@@ -40,6 +40,7 @@
class DOMWrapperWorld;
class Page;
+class StyleSheetContents;
class URL;
class UserScript;
class UserStyleSheet;
@@ -87,6 +88,8 @@
WEBCORE_EXPORT void removeAllUserContentExtensions();
Vector<ContentExtensions::Action> actionsForResourceLoad(const ResourceLoadInfo&);
+ StyleSheetContents* globalDisplayNoneStyleSheet(const String& identifier) const;
+ static const String& displayNoneCSSRule();
#endif
private: