Diff
Modified: trunk/Source/WebCore/ChangeLog (181780 => 181781)
--- trunk/Source/WebCore/ChangeLog 2015-03-20 05:06:40 UTC (rev 181780)
+++ trunk/Source/WebCore/ChangeLog 2015-03-20 05:22:22 UTC (rev 181781)
@@ -1,3 +1,33 @@
+2015-03-19 Andy Estes <[email protected]>
+
+ [Content Filtering] Move ContentFilter to from platform/ to loader/
+ https://bugs.webkit.org/show_bug.cgi?id=142897
+
+ Reviewed by Dan Bernstein.
+
+ ContentFilterCollection never contained any platform code, so it doesn't make sense for it to be in platform.
+ Move it to loader/, since ContentFilters are owned by DocumentLoaders, and just call it ContentFilter. Extract
+ the abstract part of ContentFilter into a new base class called PlatformContentFilter that each of the
+ individual filters inherit from.
+
+ * WebCore.xcodeproj/project.pbxproj:
+ * loader/ContentFilter.cpp: Renamed from Source/WebCore/platform/ContentFilter.cpp.
+ (WebCore::ContentFilter::types): Moved from ContentFilterCollection.
+ (WebCore::ContentFilter::createIfNeeded): Ditto.
+ (WebCore::ContentFilter::ContentFilter): Ditto.
+ (WebCore::ContentFilter::addData): Ditto.
+ (WebCore::ContentFilter::finishedAddingData): Ditto.
+ (WebCore::ContentFilter::needsMoreData): Ditto.
+ (WebCore::ContentFilter::didBlockData): Ditto.
+ (WebCore::ContentFilter::getReplacementData): Ditto.
+ (WebCore::ContentFilter::unblockHandler): Ditto.
+ * loader/ContentFilter.h: Copied from Source/WebCore/platform/ContentFilter.h.
+ (WebCore::ContentFilter::type): Replaced a use of ContentFilterCollection.
+ * platform/PlatformContentFilter.h: Renamed from Source/WebCore/platform/ContentFilter.h.
+ * platform/cocoa/NetworkExtensionContentFilter.h: Inherited from PlatformContentFilter.
+ * platform/cocoa/ParentalControlsContentFilter.h: Ditto.
+ * testing/MockContentFilter.h: Ditto.
+
2015-03-19 Dean Jackson <[email protected]>
CSS Animations with triggers should map scroll position to duration
Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (181780 => 181781)
--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2015-03-20 05:06:40 UTC (rev 181780)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2015-03-20 05:22:22 UTC (rev 181781)
@@ -1045,7 +1045,6 @@
2917B5621473496C0052C9D0 /* LayerFlushScheduler.h in Headers */ = {isa = PBXBuildFile; fileRef = 2917B55F1473496C0052C9D0 /* LayerFlushScheduler.h */; settings = {ATTRIBUTES = (Private, ); }; };
2917B5631473496C0052C9D0 /* LayerFlushSchedulerClient.h in Headers */ = {isa = PBXBuildFile; fileRef = 2917B5601473496C0052C9D0 /* LayerFlushSchedulerClient.h */; settings = {ATTRIBUTES = (Private, ); }; };
2917B566147349950052C9D0 /* LayerFlushSchedulerMac.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2917B565147349950052C9D0 /* LayerFlushSchedulerMac.cpp */; };
- 2919A1E916B3376600787213 /* ContentFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 2919A1E816B3376600787213 /* ContentFilter.h */; };
2934940A16C02C0700901318 /* PlatformSpeechSynthesisVoice.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2527CC9316BF92EC009DDAC0 /* PlatformSpeechSynthesisVoice.cpp */; };
2934940B16C02C0A00901318 /* PlatformSpeechSynthesisUtterance.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2527CC9516BF95DD009DDAC0 /* PlatformSpeechSynthesisUtterance.cpp */; };
293EAE1F1356B2FE0067ACF9 /* RuntimeApplicationChecks.h in Headers */ = {isa = PBXBuildFile; fileRef = 293EAE1E1356B2FE0067ACF9 /* RuntimeApplicationChecks.h */; settings = {ATTRIBUTES = (Private, ); }; };
@@ -3819,7 +3818,9 @@
A14832CD187F682E00DA63A6 /* WebCoreThreadSafe.h in Headers */ = {isa = PBXBuildFile; fileRef = A148329F187F508700DA63A6 /* WebCoreThreadSafe.h */; };
A14832CE187F683400DA63A6 /* WebCoreThreadSystemInterface.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A14832A0187F508700DA63A6 /* WebCoreThreadSystemInterface.cpp */; };
A14832CF187F684700DA63A6 /* WebCoreThreadSystemInterface.h in Headers */ = {isa = PBXBuildFile; fileRef = A14832A1187F508700DA63A6 /* WebCoreThreadSystemInterface.h */; settings = {ATTRIBUTES = (Private, ); }; };
- A15D329D1AA7CF3B009A234A /* ContentFilter.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A15D329C1AA7CF3B009A234A /* ContentFilter.cpp */; };
+ A149786E1ABAF33800CEF7E4 /* ContentFilter.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A149786C1ABAF33800CEF7E4 /* ContentFilter.cpp */; };
+ A149786F1ABAF33800CEF7E4 /* ContentFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = A149786D1ABAF33800CEF7E4 /* ContentFilter.h */; };
+ A14978711ABAF3A500CEF7E4 /* PlatformContentFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = A14978701ABAF3A500CEF7E4 /* PlatformContentFilter.h */; };
A17C81220F2A5CF7005DAAEB /* HTMLElementFactory.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A17C81200F2A5CF7005DAAEB /* HTMLElementFactory.cpp */; };
A17C81230F2A5CF7005DAAEB /* HTMLElementFactory.h in Headers */ = {isa = PBXBuildFile; fileRef = A17C81210F2A5CF7005DAAEB /* HTMLElementFactory.h */; };
A18890AE1AA13F250026C301 /* ParentalControlsContentFilter.mm in Sources */ = {isa = PBXBuildFile; fileRef = A18890AC1AA13F250026C301 /* ParentalControlsContentFilter.mm */; };
@@ -8124,7 +8125,6 @@
2917B55F1473496C0052C9D0 /* LayerFlushScheduler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = LayerFlushScheduler.h; path = ca/LayerFlushScheduler.h; sourceTree = "<group>"; };
2917B5601473496C0052C9D0 /* LayerFlushSchedulerClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = LayerFlushSchedulerClient.h; path = ca/LayerFlushSchedulerClient.h; sourceTree = "<group>"; };
2917B565147349950052C9D0 /* LayerFlushSchedulerMac.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = LayerFlushSchedulerMac.cpp; path = ca/mac/LayerFlushSchedulerMac.cpp; sourceTree = "<group>"; };
- 2919A1E816B3376600787213 /* ContentFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ContentFilter.h; sourceTree = "<group>"; };
293EAE1E1356B2FE0067ACF9 /* RuntimeApplicationChecks.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RuntimeApplicationChecks.h; sourceTree = "<group>"; };
293EAE201356B32E0067ACF9 /* RuntimeApplicationChecks.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RuntimeApplicationChecks.cpp; sourceTree = "<group>"; };
29489FC512C00F0300D83F0F /* AccessibilityScrollView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AccessibilityScrollView.h; sourceTree = "<group>"; };
@@ -11076,7 +11076,9 @@
A14832A9187F508700DA63A6 /* WKView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = WKView.h; path = ios/wak/WKView.h; sourceTree = "<group>"; };
A14832AA187F508700DA63A6 /* WKView.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = WKView.mm; path = ios/wak/WKView.mm; sourceTree = "<group>"; };
A14832AB187F508700DA63A6 /* WKViewPrivate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = WKViewPrivate.h; path = ios/wak/WKViewPrivate.h; sourceTree = "<group>"; };
- A15D329C1AA7CF3B009A234A /* ContentFilter.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ContentFilter.cpp; sourceTree = "<group>"; };
+ A149786C1ABAF33800CEF7E4 /* ContentFilter.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ContentFilter.cpp; sourceTree = "<group>"; };
+ A149786D1ABAF33800CEF7E4 /* ContentFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ContentFilter.h; sourceTree = "<group>"; };
+ A14978701ABAF3A500CEF7E4 /* PlatformContentFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PlatformContentFilter.h; sourceTree = "<group>"; };
A17C81200F2A5CF7005DAAEB /* HTMLElementFactory.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = HTMLElementFactory.cpp; sourceTree = "<group>"; };
A17C81210F2A5CF7005DAAEB /* HTMLElementFactory.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HTMLElementFactory.h; sourceTree = "<group>"; };
A18890AC1AA13F250026C301 /* ParentalControlsContentFilter.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ParentalControlsContentFilter.mm; sourceTree = "<group>"; };
@@ -21415,6 +21417,8 @@
7E4DE10B198B10810051CB02 /* cocoa */,
5126E6B60A2E3AEF005C29FA /* icon */,
93A1EAA20A5634D8006960A0 /* mac */,
+ A149786C1ABAF33800CEF7E4 /* ContentFilter.cpp */,
+ A149786D1ABAF33800CEF7E4 /* ContentFilter.h */,
E1424C91164B52C800F32D40 /* CookieJar.cpp */,
E1424C92164B52C800F32D40 /* CookieJar.h */,
E1C416160F6563180092D2FB /* CrossOriginAccessControl.cpp */,
@@ -21574,8 +21578,6 @@
C330A22113EC196B0000B45B /* ColorChooser.h */,
C37CDEBC149EF2030042090D /* ColorChooserClient.h */,
BCC8CFCA0986CD2400140BF2 /* ColorData.gperf */,
- A15D329C1AA7CF3B009A234A /* ContentFilter.cpp */,
- 2919A1E816B3376600787213 /* ContentFilter.h */,
A14090FC1AA51E480091191A /* ContentFilterUnblockHandler.h */,
41D015C90F4B5C71004A662F /* ContentType.cpp */,
41D015C80F4B5C71004A662F /* ContentType.h */,
@@ -21642,6 +21644,7 @@
98EB1F941313FE0500D0E1EA /* NotImplemented.h */,
4B2708C50AF19EE40065127F /* Pasteboard.h */,
C5F765B414E1D414006C899B /* PasteboardStrategy.h */,
+ A14978701ABAF3A500CEF7E4 /* PlatformContentFilter.h */,
E1424C89164B3B4E00F32D40 /* PlatformCookieJar.h */,
BC5C76291497FE1400BC4775 /* PlatformEvent.h */,
A723F77A1484CA4C008C6DBE /* PlatformExportMacros.h */,
@@ -23851,7 +23854,6 @@
E1A1470811102B1500EEC0F3 /* ContainerNodeAlgorithms.h in Headers */,
BC5EB9810E82072500B25965 /* ContentData.h in Headers */,
57B791A414C6A62900F202D1 /* ContentDistributor.h in Headers */,
- 2919A1E916B3376600787213 /* ContentFilter.h in Headers */,
97C471DC12F925BD0086354B /* ContentSecurityPolicy.h in Headers */,
41D015CA0F4B5C71004A662F /* ContentType.h in Headers */,
97627B8E14FB3CEE002CDCA1 /* ContextDestructionObserver.h in Headers */,
@@ -25699,6 +25701,7 @@
52F10866162B6DA8009AC81E /* MixedContentChecker.h in Headers */,
CE1252491A16C3BC00864480 /* MobileGestaltSPI.h in Headers */,
CDF2B0111820540600F2B424 /* MockBox.h in Headers */,
+ A14978711ABAF3A500CEF7E4 /* PlatformContentFilter.h in Headers */,
CDF2B0131820540600F2B424 /* MockMediaPlayerMediaSource.h in Headers */,
CDF2B0151820540600F2B424 /* MockMediaSourcePrivate.h in Headers */,
CDF2B0171820540700F2B424 /* MockSourceBufferPrivate.h in Headers */,
@@ -25930,6 +25933,7 @@
550A0BCA085F6039007353D6 /* QualifiedName.h in Headers */,
CE12523D1A1676CD00864480 /* QuartzCoreSPI.h in Headers */,
442AF7A9102CDDEA008FD4D3 /* QuickLook.h in Headers */,
+ A149786F1ABAF33800CEF7E4 /* ContentFilter.h in Headers */,
CE1252391A166FA000864480 /* QuickLookSPI.h in Headers */,
A10DBF4718F92317000D70C6 /* QuickLookHandleClient.h in Headers */,
072AE1E8183C0741000A5988 /* QuickTimePluginReplacement.h in Headers */,
@@ -27724,6 +27728,7 @@
F55B3DB71251F12D003EF269 /* DateTimeInputType.cpp in Sources */,
F55B3DB91251F12D003EF269 /* DateTimeLocalInputType.cpp in Sources */,
0F6A12BD1A00923700C6DE72 /* DebugPageOverlays.cpp in Sources */,
+ A149786E1ABAF33800CEF7E4 /* ContentFilter.cpp in Sources */,
45FEA5CF156DDE8C00654101 /* Decimal.cpp in Sources */,
A8C228A211D5722E00D5A7D3 /* DecodedDataDocumentParser.cpp in Sources */,
4162A450101145AE00DFF3ED /* DedicatedWorkerGlobalScope.cpp in Sources */,
@@ -29190,7 +29195,6 @@
CDB859F7160D48A400E5B07F /* MediaKeyEvent.cpp in Sources */,
CDA98DD816025BEF00FEA3B1 /* MediaKeyMessageEvent.cpp in Sources */,
CD1B4A65160786AE00282DF9 /* MediaKeyNeededEvent.cpp in Sources */,
- A15D329D1AA7CF3B009A234A /* ContentFilter.cpp in Sources */,
6C568CB019DAFEA000430CA2 /* MaskImageOperation.cpp in Sources */,
CDA98E0D1603FE4A00FEA3B1 /* MediaKeys.cpp in Sources */,
7C93F34D1AA6BF0700A98BAB /* ContentExtensionCompiler.cpp in Sources */,
Copied: trunk/Source/WebCore/loader/ContentFilter.cpp (from rev 181780, trunk/Source/WebCore/platform/ContentFilter.cpp) (0 => 181781)
--- trunk/Source/WebCore/loader/ContentFilter.cpp (rev 0)
+++ trunk/Source/WebCore/loader/ContentFilter.cpp 2015-03-20 05:22:22 UTC (rev 181781)
@@ -0,0 +1,135 @@
+/*
+ * Copyright (C) 2013 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 "ContentFilter.h"
+
+#if ENABLE(CONTENT_FILTERING)
+
+#include "NetworkExtensionContentFilter.h"
+#include "ParentalControlsContentFilter.h"
+#include <wtf/NeverDestroyed.h>
+
+namespace WebCore {
+
+Vector<ContentFilter::Type>& ContentFilter::types()
+{
+ static NeverDestroyed<Vector<ContentFilter::Type>> types {
+ Vector<ContentFilter::Type> {
+ type<ParentalControlsContentFilter>(),
+#if HAVE(NETWORK_EXTENSION)
+ type<NetworkExtensionContentFilter>()
+#endif
+ }
+ };
+ return types;
+}
+
+std::unique_ptr<ContentFilter> ContentFilter::createIfNeeded(const ResourceResponse& response)
+{
+ Container filters;
+ for (auto& type : types()) {
+ if (type.canHandleResponse(response))
+ filters.append(type.create(response));
+ }
+
+ if (filters.isEmpty())
+ return nullptr;
+
+ return std::make_unique<ContentFilter>(WTF::move(filters));
+}
+
+ContentFilter::ContentFilter(Container contentFilters)
+ : m_contentFilters { WTF::move(contentFilters) }
+{
+ ASSERT(!m_contentFilters.isEmpty());
+}
+
+void ContentFilter::addData(const char* data, int length)
+{
+ ASSERT(needsMoreData());
+
+ for (auto& contentFilter : m_contentFilters)
+ contentFilter->addData(data, length);
+}
+
+void ContentFilter::finishedAddingData()
+{
+ ASSERT(needsMoreData());
+
+ for (auto& contentFilter : m_contentFilters)
+ contentFilter->finishedAddingData();
+
+ ASSERT(!needsMoreData());
+}
+
+bool ContentFilter::needsMoreData() const
+{
+ for (auto& contentFilter : m_contentFilters) {
+ if (contentFilter->needsMoreData())
+ return true;
+ }
+
+ return false;
+}
+
+bool ContentFilter::didBlockData() const
+{
+ for (auto& contentFilter : m_contentFilters) {
+ if (contentFilter->didBlockData())
+ return true;
+ }
+
+ return false;
+}
+
+const char* ContentFilter::getReplacementData(int& length) const
+{
+ ASSERT(!needsMoreData());
+
+ for (auto& contentFilter : m_contentFilters) {
+ if (contentFilter->didBlockData())
+ return contentFilter->getReplacementData(length);
+ }
+
+ return m_contentFilters[0]->getReplacementData(length);
+}
+
+ContentFilterUnblockHandler ContentFilter::unblockHandler() const
+{
+ ASSERT(didBlockData());
+
+ for (auto& contentFilter : m_contentFilters) {
+ if (contentFilter->didBlockData())
+ return contentFilter->unblockHandler();
+ }
+
+ ASSERT_NOT_REACHED();
+ return { };
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(CONTENT_FILTERING)
Copied: trunk/Source/WebCore/loader/ContentFilter.h (from rev 181780, trunk/Source/WebCore/platform/ContentFilter.h) (0 => 181781)
--- trunk/Source/WebCore/loader/ContentFilter.h (rev 0)
+++ trunk/Source/WebCore/loader/ContentFilter.h 2015-03-20 05:22:22 UTC (rev 181781)
@@ -0,0 +1,76 @@
+/*
+ * Copyright (C) 2013 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 ContentFilter_h
+#define ContentFilter_h
+
+#if ENABLE(CONTENT_FILTERING)
+
+#include "PlatformContentFilter.h"
+#include <wtf/Vector.h>
+
+namespace WebCore {
+
+class ResourceResponse;
+
+class ContentFilter final : public PlatformContentFilter {
+public:
+ template <typename T> static void addType() { types().append(type<T>()); }
+ static std::unique_ptr<ContentFilter> createIfNeeded(const ResourceResponse&);
+
+ void addData(const char* data, int length) override;
+ void finishedAddingData() override;
+ bool needsMoreData() const override;
+ bool didBlockData() const override;
+ const char* getReplacementData(int& length) const override;
+ ContentFilterUnblockHandler unblockHandler() const override;
+
+private:
+ struct Type {
+ const std::function<bool(const ResourceResponse&)> canHandleResponse;
+ const std::function<std::unique_ptr<PlatformContentFilter>(const ResourceResponse&)> create;
+ };
+ template <typename T> static Type type();
+ WEBCORE_EXPORT static Vector<Type>& types();
+
+ using Container = Vector<std::unique_ptr<PlatformContentFilter>>;
+ friend std::unique_ptr<ContentFilter> std::make_unique<ContentFilter>(Container&&);
+ explicit ContentFilter(Container);
+
+ Container m_contentFilters;
+};
+
+template <typename T>
+ContentFilter::Type ContentFilter::type()
+{
+ static_assert(std::is_base_of<PlatformContentFilter, T>::value, "Type must be a PlatformContentFilter.");
+ return { T::canHandleResponse, T::create };
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(CONTENT_FILTERING)
+
+#endif // ContentFilter_h
Deleted: trunk/Source/WebCore/platform/ContentFilter.cpp (181780 => 181781)
--- trunk/Source/WebCore/platform/ContentFilter.cpp 2015-03-20 05:06:40 UTC (rev 181780)
+++ trunk/Source/WebCore/platform/ContentFilter.cpp 2015-03-20 05:22:22 UTC (rev 181781)
@@ -1,153 +0,0 @@
-/*
- * Copyright (C) 2013 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 "ContentFilter.h"
-
-#if ENABLE(CONTENT_FILTERING)
-
-#include "NetworkExtensionContentFilter.h"
-#include "ParentalControlsContentFilter.h"
-#include <wtf/NeverDestroyed.h>
-#include <wtf/Vector.h>
-
-namespace WebCore {
-
-Vector<ContentFilter::Type>& ContentFilter::types()
-{
- static NeverDestroyed<Vector<ContentFilter::Type>> types {
- Vector<ContentFilter::Type> {
- type<ParentalControlsContentFilter>(),
-#if HAVE(NETWORK_EXTENSION)
- type<NetworkExtensionContentFilter>()
-#endif
- }
- };
- return types;
-}
-
-class ContentFilterCollection final : public ContentFilter {
-public:
- using Container = Vector<std::unique_ptr<ContentFilter>>;
-
- explicit ContentFilterCollection(Container);
-
- void addData(const char* data, int length) override;
- void finishedAddingData() override;
- bool needsMoreData() const override;
- bool didBlockData() const override;
- const char* getReplacementData(int& length) const override;
- ContentFilterUnblockHandler unblockHandler() const override;
-
-private:
- Container m_contentFilters;
-};
-
-std::unique_ptr<ContentFilter> ContentFilter::createIfNeeded(const ResourceResponse& response)
-{
- ContentFilterCollection::Container filters;
- for (auto& type : types()) {
- if (type.canHandleResponse(response))
- filters.append(type.create(response));
- }
-
- if (filters.isEmpty())
- return nullptr;
-
- return std::make_unique<ContentFilterCollection>(WTF::move(filters));
-}
-
-ContentFilterCollection::ContentFilterCollection(Container contentFilters)
- : m_contentFilters { WTF::move(contentFilters) }
-{
- ASSERT(!m_contentFilters.isEmpty());
-}
-
-void ContentFilterCollection::addData(const char* data, int length)
-{
- ASSERT(needsMoreData());
-
- for (auto& contentFilter : m_contentFilters)
- contentFilter->addData(data, length);
-}
-
-void ContentFilterCollection::finishedAddingData()
-{
- ASSERT(needsMoreData());
-
- for (auto& contentFilter : m_contentFilters)
- contentFilter->finishedAddingData();
-
- ASSERT(!needsMoreData());
-}
-
-bool ContentFilterCollection::needsMoreData() const
-{
- for (auto& contentFilter : m_contentFilters) {
- if (contentFilter->needsMoreData())
- return true;
- }
-
- return false;
-}
-
-bool ContentFilterCollection::didBlockData() const
-{
- for (auto& contentFilter : m_contentFilters) {
- if (contentFilter->didBlockData())
- return true;
- }
-
- return false;
-}
-
-const char* ContentFilterCollection::getReplacementData(int& length) const
-{
- ASSERT(!needsMoreData());
-
- for (auto& contentFilter : m_contentFilters) {
- if (contentFilter->didBlockData())
- return contentFilter->getReplacementData(length);
- }
-
- return m_contentFilters[0]->getReplacementData(length);
-}
-
-ContentFilterUnblockHandler ContentFilterCollection::unblockHandler() const
-{
- ASSERT(didBlockData());
-
- for (auto& contentFilter : m_contentFilters) {
- if (contentFilter->didBlockData())
- return contentFilter->unblockHandler();
- }
-
- ASSERT_NOT_REACHED();
- return { };
-}
-
-} // namespace WebCore
-
-#endif // ENABLE(CONTENT_FILTERING)
Deleted: trunk/Source/WebCore/platform/ContentFilter.h (181780 => 181781)
--- trunk/Source/WebCore/platform/ContentFilter.h 2015-03-20 05:06:40 UTC (rev 181780)
+++ trunk/Source/WebCore/platform/ContentFilter.h 2015-03-20 05:22:22 UTC (rev 181781)
@@ -1,65 +0,0 @@
-/*
- * Copyright (C) 2013 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 ContentFilter_h
-#define ContentFilter_h
-
-#if ENABLE(CONTENT_FILTERING)
-
-#include "ContentFilterUnblockHandler.h"
-#include <wtf/Vector.h>
-
-namespace WebCore {
-
-class ResourceResponse;
-
-class ContentFilter {
-public:
- template <typename T> static void addType() { types().append(type<T>()); }
-
- static std::unique_ptr<ContentFilter> createIfNeeded(const ResourceResponse&);
-
- virtual ~ContentFilter() { }
- virtual void addData(const char* data, int length) = 0;
- virtual void finishedAddingData() = 0;
- virtual bool needsMoreData() const = 0;
- virtual bool didBlockData() const = 0;
- virtual const char* getReplacementData(int& length) const = 0;
- virtual ContentFilterUnblockHandler unblockHandler() const = 0;
-
-private:
- struct Type {
- const std::function<bool(const ResourceResponse&)> canHandleResponse;
- const std::function<std::unique_ptr<ContentFilter>(const ResourceResponse&)> create;
- };
- template <typename T> static Type type() { return { T::canHandleResponse, T::create }; }
- WEBCORE_EXPORT static Vector<Type>& types();
-};
-
-} // namespace WebCore
-
-#endif // ENABLE(CONTENT_FILTERING)
-
-#endif // ContentFilter_h
Copied: trunk/Source/WebCore/platform/PlatformContentFilter.h (from rev 181780, trunk/Source/WebCore/platform/ContentFilter.h) (0 => 181781)
--- trunk/Source/WebCore/platform/PlatformContentFilter.h (rev 0)
+++ trunk/Source/WebCore/platform/PlatformContentFilter.h 2015-03-20 05:22:22 UTC (rev 181781)
@@ -0,0 +1,55 @@
+/*
+ * 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 PlatformContentFilter_h
+#define PlatformContentFilter_h
+
+#include "ContentFilterUnblockHandler.h"
+#include <wtf/text/WTFString.h>
+
+namespace WebCore {
+
+class ResourceResponse;
+
+class PlatformContentFilter {
+ WTF_MAKE_FAST_ALLOCATED;
+ WTF_MAKE_NONCOPYABLE(PlatformContentFilter);
+
+protected:
+ PlatformContentFilter() = default;
+
+public:
+ virtual ~PlatformContentFilter() { }
+ virtual void addData(const char* data, int length) = 0;
+ virtual void finishedAddingData() = 0;
+ virtual bool needsMoreData() const = 0;
+ virtual bool didBlockData() const = 0;
+ virtual const char* getReplacementData(int& length) const = 0;
+ virtual ContentFilterUnblockHandler unblockHandler() const = 0;
+};
+
+} // namespace WebCore
+
+#endif // PlatformContentFilter_h
Modified: trunk/Source/WebCore/platform/cocoa/NetworkExtensionContentFilter.h (181780 => 181781)
--- trunk/Source/WebCore/platform/cocoa/NetworkExtensionContentFilter.h 2015-03-20 05:06:40 UTC (rev 181780)
+++ trunk/Source/WebCore/platform/cocoa/NetworkExtensionContentFilter.h 2015-03-20 05:22:22 UTC (rev 181781)
@@ -26,7 +26,7 @@
#ifndef NetworkExtensionContentFilter_h
#define NetworkExtensionContentFilter_h
-#include "ContentFilter.h"
+#include "PlatformContentFilter.h"
#include "SharedBuffer.h"
#include <objc/NSObjCRuntime.h>
#include <wtf/Compiler.h>
@@ -45,9 +45,7 @@
namespace WebCore {
-class NetworkExtensionContentFilter final : public ContentFilter {
- WTF_MAKE_FAST_ALLOCATED;
- WTF_MAKE_NONCOPYABLE(NetworkExtensionContentFilter);
+class NetworkExtensionContentFilter final : public PlatformContentFilter {
friend std::unique_ptr<NetworkExtensionContentFilter> std::make_unique<NetworkExtensionContentFilter>(const ResourceResponse&);
public:
Modified: trunk/Source/WebCore/platform/cocoa/ParentalControlsContentFilter.h (181780 => 181781)
--- trunk/Source/WebCore/platform/cocoa/ParentalControlsContentFilter.h 2015-03-20 05:06:40 UTC (rev 181780)
+++ trunk/Source/WebCore/platform/cocoa/ParentalControlsContentFilter.h 2015-03-20 05:22:22 UTC (rev 181781)
@@ -26,7 +26,7 @@
#ifndef ParentalControlsContentFilter_h
#define ParentalControlsContentFilter_h
-#include "ContentFilter.h"
+#include "PlatformContentFilter.h"
#include <wtf/Compiler.h>
#include <wtf/RetainPtr.h>
@@ -35,9 +35,7 @@
namespace WebCore {
-class ParentalControlsContentFilter final : public ContentFilter {
- WTF_MAKE_FAST_ALLOCATED;
- WTF_MAKE_NONCOPYABLE(ParentalControlsContentFilter);
+class ParentalControlsContentFilter final : public PlatformContentFilter {
friend std::unique_ptr<ParentalControlsContentFilter> std::make_unique<ParentalControlsContentFilter>(const ResourceResponse&);
public:
Modified: trunk/Source/WebCore/testing/MockContentFilter.cpp (181780 => 181781)
--- trunk/Source/WebCore/testing/MockContentFilter.cpp 2015-03-20 05:06:40 UTC (rev 181780)
+++ trunk/Source/WebCore/testing/MockContentFilter.cpp 2015-03-20 05:22:22 UTC (rev 181781)
@@ -28,6 +28,7 @@
#if ENABLE(CONTENT_FILTERING)
+#include "ContentFilter.h"
#include <mutex>
#include <wtf/text/CString.h>
Modified: trunk/Source/WebCore/testing/MockContentFilter.h (181780 => 181781)
--- trunk/Source/WebCore/testing/MockContentFilter.h 2015-03-20 05:06:40 UTC (rev 181780)
+++ trunk/Source/WebCore/testing/MockContentFilter.h 2015-03-20 05:22:22 UTC (rev 181781)
@@ -26,14 +26,12 @@
#ifndef MockContentFilter_h
#define MockContentFilter_h
-#include "ContentFilter.h"
#include "MockContentFilterSettings.h"
+#include "PlatformContentFilter.h"
namespace WebCore {
-class MockContentFilter final : public ContentFilter {
- WTF_MAKE_FAST_ALLOCATED;
- WTF_MAKE_NONCOPYABLE(MockContentFilter);
+class MockContentFilter final : public PlatformContentFilter {
friend std::unique_ptr<MockContentFilter> std::make_unique<MockContentFilter>(const ResourceResponse&);
public: