[Content Filtering] Move ContentFilter to from platform/ to loader/
authoraestes@apple.com <aestes@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 20 Mar 2015 05:22:22 +0000 (05:22 +0000)
committeraestes@apple.com <aestes@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 20 Mar 2015 05:22:22 +0000 (05:22 +0000)
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.

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

Source/WebCore/ChangeLog
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/loader/ContentFilter.cpp [moved from Source/WebCore/platform/ContentFilter.cpp with 75% similarity]
Source/WebCore/loader/ContentFilter.h [new file with mode: 0644]
Source/WebCore/platform/PlatformContentFilter.h [moved from Source/WebCore/platform/ContentFilter.h with 69% similarity]
Source/WebCore/platform/cocoa/NetworkExtensionContentFilter.h
Source/WebCore/platform/cocoa/ParentalControlsContentFilter.h
Source/WebCore/testing/MockContentFilter.cpp
Source/WebCore/testing/MockContentFilter.h

index e52155f61719b7c0b8c8c92d964716b483c75341..76559668c756ce280c5d598112a5f06281257c0b 100644 (file)
@@ -1,3 +1,33 @@
+2015-03-19  Andy Estes  <aestes@apple.com>
+
+        [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  <dino@apple.com>
 
         CSS Animations with triggers should map scroll position to duration
index 648aff6c730ed952e62b9106baa3837983f5e3ab..8fdfbd844a3d895baa4261db06474e69ea061ce0 100644 (file)
                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, ); }; };
                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 */; };
                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>"; };
                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>"; };
                                7E4DE10B198B10810051CB02 /* cocoa */,
                                5126E6B60A2E3AEF005C29FA /* icon */,
                                93A1EAA20A5634D8006960A0 /* mac */,
+                               A149786C1ABAF33800CEF7E4 /* ContentFilter.cpp */,
+                               A149786D1ABAF33800CEF7E4 /* ContentFilter.h */,
                                E1424C91164B52C800F32D40 /* CookieJar.cpp */,
                                E1424C92164B52C800F32D40 /* CookieJar.h */,
                                E1C416160F6563180092D2FB /* CrossOriginAccessControl.cpp */,
                                C330A22113EC196B0000B45B /* ColorChooser.h */,
                                C37CDEBC149EF2030042090D /* ColorChooserClient.h */,
                                BCC8CFCA0986CD2400140BF2 /* ColorData.gperf */,
-                               A15D329C1AA7CF3B009A234A /* ContentFilter.cpp */,
-                               2919A1E816B3376600787213 /* ContentFilter.h */,
                                A14090FC1AA51E480091191A /* ContentFilterUnblockHandler.h */,
                                41D015C90F4B5C71004A662F /* ContentType.cpp */,
                                41D015C80F4B5C71004A662F /* ContentType.h */,
                                98EB1F941313FE0500D0E1EA /* NotImplemented.h */,
                                4B2708C50AF19EE40065127F /* Pasteboard.h */,
                                C5F765B414E1D414006C899B /* PasteboardStrategy.h */,
+                               A14978701ABAF3A500CEF7E4 /* PlatformContentFilter.h */,
                                E1424C89164B3B4E00F32D40 /* PlatformCookieJar.h */,
                                BC5C76291497FE1400BC4775 /* PlatformEvent.h */,
                                A723F77A1484CA4C008C6DBE /* PlatformExportMacros.h */,
                                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 */,
                                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 */,
                                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 */,
                                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 */,
                                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 */,
similarity index 75%
rename from Source/WebCore/platform/ContentFilter.cpp
rename to Source/WebCore/loader/ContentFilter.cpp
index 7d5c2d390e6b12ffdfb0f4e3906d72ad6dc23c68..728bef95b374971f2ce2b87856f0c7524ae04524 100644 (file)
@@ -31,7 +31,6 @@
 #include "NetworkExtensionContentFilter.h"
 #include "ParentalControlsContentFilter.h"
 #include <wtf/NeverDestroyed.h>
-#include <wtf/Vector.h>
 
 namespace WebCore {
 
@@ -48,26 +47,9 @@ Vector<ContentFilter::Type>& ContentFilter::types()
     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;
+    Container filters;
     for (auto& type : types()) {
         if (type.canHandleResponse(response))
             filters.append(type.create(response));
@@ -76,16 +58,16 @@ std::unique_ptr<ContentFilter> ContentFilter::createIfNeeded(const ResourceRespo
     if (filters.isEmpty())
         return nullptr;
 
-    return std::make_unique<ContentFilterCollection>(WTF::move(filters));
+    return std::make_unique<ContentFilter>(WTF::move(filters));
 }
 
-ContentFilterCollection::ContentFilterCollection(Container contentFilters)
+ContentFilter::ContentFilter(Container contentFilters)
     : m_contentFilters { WTF::move(contentFilters) }
 {
     ASSERT(!m_contentFilters.isEmpty());
 }
 
-void ContentFilterCollection::addData(const char* data, int length)
+void ContentFilter::addData(const char* data, int length)
 {
     ASSERT(needsMoreData());
 
@@ -93,7 +75,7 @@ void ContentFilterCollection::addData(const char* data, int length)
         contentFilter->addData(data, length);
 }
     
-void ContentFilterCollection::finishedAddingData()
+void ContentFilter::finishedAddingData()
 {
     ASSERT(needsMoreData());
 
@@ -103,7 +85,7 @@ void ContentFilterCollection::finishedAddingData()
     ASSERT(!needsMoreData());
 }
 
-bool ContentFilterCollection::needsMoreData() const
+bool ContentFilter::needsMoreData() const
 {
     for (auto& contentFilter : m_contentFilters) {
         if (contentFilter->needsMoreData())
@@ -113,7 +95,7 @@ bool ContentFilterCollection::needsMoreData() const
     return false;
 }
 
-bool ContentFilterCollection::didBlockData() const
+bool ContentFilter::didBlockData() const
 {
     for (auto& contentFilter : m_contentFilters) {
         if (contentFilter->didBlockData())
@@ -123,7 +105,7 @@ bool ContentFilterCollection::didBlockData() const
     return false;
 }
 
-const char* ContentFilterCollection::getReplacementData(int& length) const
+const char* ContentFilter::getReplacementData(int& length) const
 {
     ASSERT(!needsMoreData());
 
@@ -135,7 +117,7 @@ const char* ContentFilterCollection::getReplacementData(int& length) const
     return m_contentFilters[0]->getReplacementData(length);
 }
 
-ContentFilterUnblockHandler ContentFilterCollection::unblockHandler() const
+ContentFilterUnblockHandler ContentFilter::unblockHandler() const
 {
     ASSERT(didBlockData());
 
diff --git a/Source/WebCore/loader/ContentFilter.h b/Source/WebCore/loader/ContentFilter.h
new file mode 100644 (file)
index 0000000..622a491
--- /dev/null
@@ -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
similarity index 69%
rename from Source/WebCore/platform/ContentFilter.h
rename to Source/WebCore/platform/PlatformContentFilter.h
index 1bfe136a2987f6300f75ea769bdba23920fe7672..b0be01949d3e25a8484541bfeddc58caf88488f3 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2013 Apple Inc. All rights reserved.
+ * 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
  * THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#ifndef ContentFilter_h
-#define ContentFilter_h
-
-#if ENABLE(CONTENT_FILTERING)
+#ifndef PlatformContentFilter_h
+#define PlatformContentFilter_h
 
 #include "ContentFilterUnblockHandler.h"
-#include <wtf/Vector.h>
+#include <wtf/text/WTFString.h>
 
 namespace WebCore {
 
 class ResourceResponse;
 
-class ContentFilter {
-public:
-    template <typename T> static void addType() { types().append(type<T>()); }
+class PlatformContentFilter {
+    WTF_MAKE_FAST_ALLOCATED;
+    WTF_MAKE_NONCOPYABLE(PlatformContentFilter);
 
-    static std::unique_ptr<ContentFilter> createIfNeeded(const ResourceResponse&);
+protected:
+    PlatformContentFilter() = default;
 
-    virtual ~ContentFilter() { }
+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;
-
-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
+#endif // PlatformContentFilter_h
index 9208c2d920273e22709d56c899067b3a12af40e3..26dfe5d810b9edc9a76a94993c2c8da590d92f9f 100644 (file)
@@ -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 @@ OBJC_CLASS NSMutableData;
 
 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:
index fdd82576797455cba72a0cc9547852e37274cc77..ea0a4e2eea46329cdb56204db0db9404cf65b18d 100644 (file)
@@ -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 @@ OBJC_CLASS WebFilterEvaluator;
 
 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:
index 71eed0cf7681ad8229a3b4ed8f7d5516ab0b5cf1..b4b9b358323d93d9a20521257aa2974ada686b72 100644 (file)
@@ -28,6 +28,7 @@
 
 #if ENABLE(CONTENT_FILTERING)
 
+#include "ContentFilter.h"
 #include <mutex>
 #include <wtf/text/CString.h>
 
index 9cb876029e2147290cf121b214357fc8770fef65..112ebd981e8eae71cc848b29f3ca3af361678de5 100644 (file)
 #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: