Title: [140875] trunk/Source
Revision
140875
Author
[email protected]
Date
2013-01-25 16:10:46 -0800 (Fri, 25 Jan 2013)

Log Message

Wrap content filtering code in an object
https://bugs.webkit.org/show_bug.cgi?id=107914

Reviewed by Alexey Proskuryakov.

Source/WebCore:

Content filtering code currently requires explicit and somewhat complex
lifetime management of the WebFilterEvaluator object for correct
behavior. Simplify this by wrapping WebFilterEvaluator in an object and
have MainResourceLoader implicitly manage its lifetime by holding it in
an OwnPtr.

This change has benefits other than the simplified lifetime management.
It removes direct calls into WebKitSystemInterface from the loader, and
it allows us to keep a strong reference to the replacement data
returned from wkFilterAddData() and wkFilterDataComplete() rather than
relying on it being autoreleased.

* WebCore.exp.in: Updated to match changes in WebCoreSystemInterface.
* WebCore.xcodeproj/project.pbxproj: Added new files.
* loader/MainResourceLoader.cpp:
(WebCore::MainResourceLoader::MainResourceLoader): Removed unneeded initialization.
(WebCore::MainResourceLoader::~MainResourceLoader): Removed an unneeded ASSERT().
(WebCore::MainResourceLoader::cancel): Removed unneeded wkFilterRelease().
(WebCore::MainResourceLoader::responseReceived): Created a
ContentFilter object rather than calling wkFilterCreateInstance().
(WebCore::MainResourceLoader::dataReceived): Rewrote content filtering
logic in terms of the wrapper object. Removed any explicit lifetime
management.
(WebCore::MainResourceLoader::didFinishLoading): Ditto.
(WebCore::MainResourceLoader::notifyFinished): Removed unneeded wkFilterRelease().
* loader/MainResourceLoader.h:
* platform/ContentFilter.h: Added.
* platform/mac/ContentFilterMac.mm: Added.
(WebCore::ContentFilter::create):
(WebCore::ContentFilter::ContentFilter):
(WebCore::ContentFilter::isEnabled): Returned the result of wkFilterIsManagedSession().
(WebCore::ContentFilter::addData): Called wkFilterAddData() and stored
the resulting NSData in m_replacementData.
(WebCore::ContentFilter::finishedAddingData): Called wkFilterDataComplete()
and stored the resulting NSData in m_replacementData.
(WebCore::ContentFilter::needsMoreData): Returned the result of wkFilterIsBuffering().
(WebCore::ContentFilter::didBlockData): Returned the result of wkFilterWasBlocked().
(WebCore::ContentFilter::getReplacementData): Returned the data stored in m_replacementData.
* platform/mac/WebCoreSystemInterface.h: Updated to reflect changes in WKSI.
* platform/mac/WebCoreSystemInterface.mm: Ditto.

* WebCore.exp.in:
* WebCore.xcodeproj/project.pbxproj:
* loader/MainResourceLoader.cpp:
(WebCore::MainResourceLoader::MainResourceLoader):
(WebCore::MainResourceLoader::~MainResourceLoader):
(WebCore::MainResourceLoader::cancel):
(WebCore::MainResourceLoader::responseReceived):
(WebCore::MainResourceLoader::dataReceived):
(WebCore::MainResourceLoader::didFinishLoading):
(WebCore::MainResourceLoader::notifyFinished):
* loader/MainResourceLoader.h:
(MainResourceLoader):
* platform/ContentFilter.h: Added.
(WebCore):
(ContentFilter):
* platform/mac/ContentFilterMac.mm: Added.
(WebCore):
(WebCore::ContentFilter::create):
(WebCore::ContentFilter::ContentFilter):
(WebCore::ContentFilter::isEnabled):
(WebCore::ContentFilter::addData):
(WebCore::ContentFilter::finishedAddingData):
(WebCore::ContentFilter::needsMoreData):
(WebCore::ContentFilter::didBlockData):
(WebCore::ContentFilter::getReplacementData):
* platform/mac/WebCoreSystemInterface.h:
* platform/mac/WebCoreSystemInterface.mm:

Source/WebKit/mac:

* WebCoreSupport/WebSystemInterface.mm:
(InitWebCoreSystemInterface): Updated to reflect changes in WKSI.

Source/WebKit2:

* WebProcess/WebCoreSupport/mac/WebSystemInterface.mm:
(InitWebCoreSystemInterface): Updated to reflect changes in WKSI.

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (140874 => 140875)


--- trunk/Source/WebCore/ChangeLog	2013-01-26 00:03:48 UTC (rev 140874)
+++ trunk/Source/WebCore/ChangeLog	2013-01-26 00:10:46 UTC (rev 140875)
@@ -1,3 +1,79 @@
+2013-01-25  Andy Estes  <[email protected]>
+
+        Wrap content filtering code in an object
+        https://bugs.webkit.org/show_bug.cgi?id=107914
+
+        Reviewed by Alexey Proskuryakov.
+
+        Content filtering code currently requires explicit and somewhat complex
+        lifetime management of the WebFilterEvaluator object for correct
+        behavior. Simplify this by wrapping WebFilterEvaluator in an object and
+        have MainResourceLoader implicitly manage its lifetime by holding it in
+        an OwnPtr.
+
+        This change has benefits other than the simplified lifetime management.
+        It removes direct calls into WebKitSystemInterface from the loader, and
+        it allows us to keep a strong reference to the replacement data
+        returned from wkFilterAddData() and wkFilterDataComplete() rather than
+        relying on it being autoreleased.
+
+        * WebCore.exp.in: Updated to match changes in WebCoreSystemInterface.
+        * WebCore.xcodeproj/project.pbxproj: Added new files.
+        * loader/MainResourceLoader.cpp:
+        (WebCore::MainResourceLoader::MainResourceLoader): Removed unneeded initialization.
+        (WebCore::MainResourceLoader::~MainResourceLoader): Removed an unneeded ASSERT().
+        (WebCore::MainResourceLoader::cancel): Removed unneeded wkFilterRelease().
+        (WebCore::MainResourceLoader::responseReceived): Created a
+        ContentFilter object rather than calling wkFilterCreateInstance().
+        (WebCore::MainResourceLoader::dataReceived): Rewrote content filtering
+        logic in terms of the wrapper object. Removed any explicit lifetime
+        management.
+        (WebCore::MainResourceLoader::didFinishLoading): Ditto.
+        (WebCore::MainResourceLoader::notifyFinished): Removed unneeded wkFilterRelease().
+        * loader/MainResourceLoader.h:
+        * platform/ContentFilter.h: Added.
+        * platform/mac/ContentFilterMac.mm: Added.
+        (WebCore::ContentFilter::create):
+        (WebCore::ContentFilter::ContentFilter):
+        (WebCore::ContentFilter::isEnabled): Returned the result of wkFilterIsManagedSession().
+        (WebCore::ContentFilter::addData): Called wkFilterAddData() and stored
+        the resulting NSData in m_replacementData.
+        (WebCore::ContentFilter::finishedAddingData): Called wkFilterDataComplete()
+        and stored the resulting NSData in m_replacementData.
+        (WebCore::ContentFilter::needsMoreData): Returned the result of wkFilterIsBuffering().
+        (WebCore::ContentFilter::didBlockData): Returned the result of wkFilterWasBlocked().
+        (WebCore::ContentFilter::getReplacementData): Returned the data stored in m_replacementData.
+        * platform/mac/WebCoreSystemInterface.h: Updated to reflect changes in WKSI.
+        * platform/mac/WebCoreSystemInterface.mm: Ditto.
+
+        * WebCore.exp.in:
+        * WebCore.xcodeproj/project.pbxproj:
+        * loader/MainResourceLoader.cpp:
+        (WebCore::MainResourceLoader::MainResourceLoader):
+        (WebCore::MainResourceLoader::~MainResourceLoader):
+        (WebCore::MainResourceLoader::cancel):
+        (WebCore::MainResourceLoader::responseReceived):
+        (WebCore::MainResourceLoader::dataReceived):
+        (WebCore::MainResourceLoader::didFinishLoading):
+        (WebCore::MainResourceLoader::notifyFinished):
+        * loader/MainResourceLoader.h:
+        (MainResourceLoader):
+        * platform/ContentFilter.h: Added.
+        (WebCore):
+        (ContentFilter):
+        * platform/mac/ContentFilterMac.mm: Added.
+        (WebCore):
+        (WebCore::ContentFilter::create):
+        (WebCore::ContentFilter::ContentFilter):
+        (WebCore::ContentFilter::isEnabled):
+        (WebCore::ContentFilter::addData):
+        (WebCore::ContentFilter::finishedAddingData):
+        (WebCore::ContentFilter::needsMoreData):
+        (WebCore::ContentFilter::didBlockData):
+        (WebCore::ContentFilter::getReplacementData):
+        * platform/mac/WebCoreSystemInterface.h:
+        * platform/mac/WebCoreSystemInterface.mm:
+
 2013-01-25  Simon Fraser  <[email protected]>
 
         When the FrameView has a non-opaque background color, make sure the TileCache tiles are not opaque

Modified: trunk/Source/WebCore/WebCore.exp.in (140874 => 140875)


--- trunk/Source/WebCore/WebCore.exp.in	2013-01-26 00:03:48 UTC (rev 140874)
+++ trunk/Source/WebCore/WebCore.exp.in	2013-01-26 00:10:46 UTC (rev 140875)
@@ -2157,8 +2157,8 @@
 _wkFilterAddData
 _wkFilterCreateInstance
 _wkFilterDataComplete
+_wkFilterIsBuffering
 _wkFilterIsManagedSession
-_wkFilterRelease
 _wkFilterWasBlocked
 #endif
 

Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (140874 => 140875)


--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2013-01-26 00:03:48 UTC (rev 140874)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2013-01-26 00:10:46 UTC (rev 140875)
@@ -747,6 +747,8 @@
 		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 */; settings = {ATTRIBUTES = (Private, ); }; };
+		2919A1EB16B3378900787213 /* ContentFilterMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2919A1EA16B3378900787213 /* ContentFilterMac.mm */; };
 		293EAE1F1356B2FE0067ACF9 /* RuntimeApplicationChecks.h in Headers */ = {isa = PBXBuildFile; fileRef = 293EAE1E1356B2FE0067ACF9 /* RuntimeApplicationChecks.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		293EAE211356B32E0067ACF9 /* RuntimeApplicationChecks.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 293EAE201356B32E0067ACF9 /* RuntimeApplicationChecks.cpp */; };
 		29489FC712C00F0300D83F0F /* AccessibilityScrollView.h in Headers */ = {isa = PBXBuildFile; fileRef = 29489FC512C00F0300D83F0F /* AccessibilityScrollView.h */; };
@@ -8005,6 +8007,8 @@
 		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>"; };
+		2919A1EA16B3378900787213 /* ContentFilterMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ContentFilterMac.mm; 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>"; };
@@ -16057,6 +16061,7 @@
 				65F80697054D9F86008BF776 /* BlockExceptions.mm */,
 				2D90660B0665D937006B6F1A /* ClipboardMac.h */,
 				2D90660C0665D937006B6F1A /* ClipboardMac.mm */,
+				2919A1EA16B3378900787213 /* ContentFilterMac.mm */,
 				06027CB20B1CC03D00884B2D /* ContextMenuItemMac.mm */,
 				93B6A0E90B0BCA8400F5027A /* ContextMenuMac.mm */,
 				F58784F002DE375901EA4122 /* CursorMac.mm */,
@@ -21311,6 +21316,7 @@
 				C330A22113EC196B0000B45B /* ColorChooser.h */,
 				C37CDEBC149EF2030042090D /* ColorChooserClient.h */,
 				BCC8CFCA0986CD2400140BF2 /* ColorData.gperf */,
+				2919A1E816B3376600787213 /* ContentFilter.h */,
 				41D015C90F4B5C71004A662F /* ContentType.cpp */,
 				41D015C80F4B5C71004A662F /* ContentType.h */,
 				93B6A0E50B0BCA5C00F5027A /* ContextMenu.h */,
@@ -26280,6 +26286,7 @@
 				FB91392616AE4C2F001FE682 /* CanvasPathMethods.h in Headers */,
 				FB91392A16AE4FC0001FE682 /* JSDOMPath.h in Headers */,
 				2E07753416B1BD4C004D9936 /* MicroDataAttributeTokenList.h in Headers */,
+				2919A1E916B3376600787213 /* ContentFilter.h in Headers */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
@@ -29431,6 +29438,7 @@
 				FB91392716AE4C34001FE682 /* CanvasPathMethods.cpp in Sources */,
 				FB91392B16AE4FC0001FE682 /* JSDOMPath.cpp in Sources */,
 				2E07753116B1BD13004D9936 /* MicroDataAttributeTokenList.cpp in Sources */,
+				2919A1EB16B3378900787213 /* ContentFilterMac.mm in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};

Modified: trunk/Source/WebCore/loader/MainResourceLoader.cpp (140874 => 140875)


--- trunk/Source/WebCore/loader/MainResourceLoader.cpp	2013-01-26 00:03:48 UTC (rev 140874)
+++ trunk/Source/WebCore/loader/MainResourceLoader.cpp	2013-01-26 00:10:46 UTC (rev 140875)
@@ -62,7 +62,7 @@
 #endif
 
 #if USE(CONTENT_FILTERING)
-#include "WebCoreSystemInterface.h"
+#include "ContentFilter.h"
 #endif
 
 namespace WebCore {
@@ -74,18 +74,12 @@
     , m_waitingForContentPolicy(false)
     , m_timeOfLastDataReceived(0.0)
     , m_substituteDataLoadIdentifier(0)
-#if USE(CONTENT_FILTERING)
-    , m_filter(0)
-#endif
 {
 }
 
 MainResourceLoader::~MainResourceLoader()
 {
     clearResource();
-#if USE(CONTENT_FILTERING)
-    ASSERT(!m_filter);
-#endif
 }
 
 PassRefPtr<MainResourceLoader> MainResourceLoader::create(DocumentLoader* documentLoader)
@@ -135,13 +129,6 @@
 
     clearResource();
     receivedError(resourceError);
-
-#if USE(CONTENT_FILTERING)
-    if (m_filter) {
-        wkFilterRelease(m_filter);
-        m_filter = 0;
-    }
-#endif
 }
 
 void MainResourceLoader::clearResource()
@@ -454,8 +441,8 @@
 #endif
 
 #if USE(CONTENT_FILTERING)
-    if (r.url().protocolIs("https") && wkFilterIsManagedSession())
-        m_filter = wkFilterCreateInstance(r.nsURLResponse());
+    if (r.url().protocolIs("https") && ContentFilter::isEnabled())
+        m_contentFilter = ContentFilter::create(r);
 #endif
 
     frameLoader()->policyChecker()->checkContentPolicy(m_response, callContinueAfterContentPolicy, this);
@@ -484,17 +471,20 @@
 #endif
 
 #if USE(CONTENT_FILTERING)
-    if (m_filter) {
-        ASSERT(!wkFilterWasBlocked(m_filter));
-        const char* blockedData = wkFilterAddData(m_filter, data, &length);
-        // If we don't have blockedData, that means we're still accumulating data
-        if (!blockedData) {
-            // Transition to committed state.
+    bool loadWasBlockedBeforeFinishing = false;
+    if (m_contentFilter && m_contentFilter->needsMoreData()) {
+        m_contentFilter->addData(data, length);
+
+        if (m_contentFilter->needsMoreData()) {
+            // Since the filter still needs more data to make a decision,
+            // transition back to the committed state so that we don't partially
+            // load content that might later be blocked.
             documentLoader()->receivedData(0, 0);
             return;
         }
 
-        data = ""
+        data = ""
+        loadWasBlockedBeforeFinishing = m_contentFilter->didBlockData();
     }
 #endif
 
@@ -512,16 +502,8 @@
     documentLoader()->receivedData(data, length);
 
 #if USE(CONTENT_FILTERING)
-    if (WebFilterEvaluator *filter = m_filter) {
-        // If we got here, it means we know if we were blocked or not. If we were blocked, we're
-        // done loading the page altogether. Either way, we don't need the filter anymore.
-
-        // Remove this->m_filter early so didFinishLoading doesn't see it.
-        m_filter = 0;
-        if (wkFilterWasBlocked(filter))
-            cancel();
-        wkFilterRelease(filter);
-    }
+    if (loadWasBlockedBeforeFinishing)
+        cancel();
 #endif
 }
 
@@ -544,15 +526,13 @@
     }
 
 #if USE(CONTENT_FILTERING)
-    if (m_filter) {
+    if (m_contentFilter && m_contentFilter->needsMoreData()) {
+        m_contentFilter->finishedAddingData();
+
         int length;
-        const char* data = "" &length);
-        WebFilterEvaluator *filter = m_filter;
-        // Remove this->m_filter early so didReceiveData doesn't see it.
-        m_filter = 0;
+        const char* data = ""
         if (data)
             dataReceived(m_resource.get(), data, length);
-        wkFilterRelease(filter);
     }
 #endif
 
@@ -579,13 +559,6 @@
         return;
     }
 
-#if USE(CONTENT_FILTERING)
-    if (m_filter) {
-        wkFilterRelease(m_filter);
-        m_filter = 0;
-    }
-#endif
-
     const ResourceError& error = m_resource->resourceError();
     if (documentLoader()->applicationCacheHost()->maybeLoadFallbackForMainError(request(), error))
         return;

Modified: trunk/Source/WebCore/loader/MainResourceLoader.h (140874 => 140875)


--- trunk/Source/WebCore/loader/MainResourceLoader.h	2013-01-26 00:03:48 UTC (rev 140874)
+++ trunk/Source/WebCore/loader/MainResourceLoader.h	2013-01-26 00:10:46 UTC (rev 140875)
@@ -36,10 +36,6 @@
 #include "SubstituteData.h"
 #include <wtf/Forward.h>
 
-#if USE(CONTENT_FILTERING)
-OBJC_CLASS WebFilterEvaluator;
-#endif
-
 #if HAVE(RUNLOOP_TIMER)
 #include "RunLoopTimer.h"
 #else
@@ -50,6 +46,10 @@
 
 class FormState;
 class ResourceRequest;
+    
+#if USE(CONTENT_FILTERING)
+class ContentFilter;
+#endif
 
 class MainResourceLoader : public RefCounted<MainResourceLoader>, public CachedRawResourceClient {
     WTF_MAKE_FAST_ALLOCATED;
@@ -131,7 +131,7 @@
     unsigned long m_substituteDataLoadIdentifier;
 
 #if USE(CONTENT_FILTERING)
-    WebFilterEvaluator *m_filter;
+    OwnPtr<ContentFilter> m_contentFilter;
 #endif
 };
 

Added: trunk/Source/WebCore/platform/ContentFilter.h (0 => 140875)


--- trunk/Source/WebCore/platform/ContentFilter.h	                        (rev 0)
+++ trunk/Source/WebCore/platform/ContentFilter.h	2013-01-26 00:10:46 UTC (rev 140875)
@@ -0,0 +1,66 @@
+/*
+ * 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 USE(CONTENT_FILTERING)
+
+#include <wtf/PassOwnPtr.h>
+#include <wtf/RetainPtr.h>
+
+#if PLATFORM(MAC)
+OBJC_CLASS WebFilterEvaluator;
+#endif
+
+namespace WebCore {
+
+class ResourceResponse;
+
+class ContentFilter {
+public:
+    static PassOwnPtr<ContentFilter> create(const ResourceResponse&);
+    static bool isEnabled();
+    
+    void addData(const char* data, int length);
+    void finishedAddingData();
+    bool needsMoreData() const;
+    bool didBlockData() const;
+    const char* getReplacementData(int& length) const;
+    
+private:
+    explicit ContentFilter(const ResourceResponse&);
+    
+#if PLATFORM(MAC)
+    RetainPtr<WebFilterEvaluator> m_platformContentFilter;
+    RetainPtr<NSData> m_replacementData;
+#endif
+};
+
+} // namespace WebCore
+
+#endif // USE(CONTENT_FILTERING)
+
+#endif // ContentFilter_h

Added: trunk/Source/WebCore/platform/mac/ContentFilterMac.mm (0 => 140875)


--- trunk/Source/WebCore/platform/mac/ContentFilterMac.mm	                        (rev 0)
+++ trunk/Source/WebCore/platform/mac/ContentFilterMac.mm	2013-01-26 00:10:46 UTC (rev 140875)
@@ -0,0 +1,87 @@
+/*
+ * 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.
+ */
+
+#import "config.h"
+#import "ContentFilter.h"
+
+#if USE(CONTENT_FILTERING)
+
+#import "ResourceResponse.h"
+#import "WebCoreSystemInterface.h"
+
+namespace WebCore {
+
+PassOwnPtr<ContentFilter> ContentFilter::create(const ResourceResponse& response)
+{
+    return adoptPtr(new ContentFilter(response));
+}
+
+ContentFilter::ContentFilter(const ResourceResponse& response)
+    : m_platformContentFilter(AdoptNS, wkFilterCreateInstance(response.nsURLResponse()))
+{
+    ASSERT(m_platformContentFilter);
+}
+
+bool ContentFilter::isEnabled()
+{
+    return wkFilterIsManagedSession();
+}
+
+void ContentFilter::addData(const char* data, int length)
+{
+    ASSERT(needsMoreData());
+    ASSERT(![m_replacementData.get() length]);
+    m_replacementData = wkFilterAddData(m_platformContentFilter.get(), [NSData dataWithBytesNoCopy:(void*)data length:length freeWhenDone:NO]);
+    ASSERT(needsMoreData() || [m_replacementData.get() length]);
+}
+    
+void ContentFilter::finishedAddingData()
+{
+    ASSERT(needsMoreData());
+    ASSERT(![m_replacementData.get() length]);
+    m_replacementData = wkFilterDataComplete(m_platformContentFilter.get());
+    ASSERT(!needsMoreData());
+}
+
+bool ContentFilter::needsMoreData() const
+{
+    return wkFilterIsBuffering(m_platformContentFilter.get());
+}
+
+bool ContentFilter::didBlockData() const
+{
+    return wkFilterWasBlocked(m_platformContentFilter.get());
+}
+
+const char* ContentFilter::getReplacementData(int& length) const
+{
+    ASSERT(!needsMoreData());
+    length = [m_replacementData.get() length];
+    return static_cast<const char*>([m_replacementData.get() bytes]);
+}
+
+} // namespace WebCore
+
+#endif // USE(CONTENT_FILTERING)

Modified: trunk/Source/WebCore/platform/mac/WebCoreSystemInterface.h (140874 => 140875)


--- trunk/Source/WebCore/platform/mac/WebCoreSystemInterface.h	2013-01-26 00:03:48 UTC (rev 140874)
+++ trunk/Source/WebCore/platform/mac/WebCoreSystemInterface.h	2013-01-26 00:10:46 UTC (rev 140875)
@@ -339,10 +339,10 @@
 #if USE(CONTENT_FILTERING)
 extern BOOL (*wkFilterIsManagedSession)(void);
 extern WebFilterEvaluator *(*wkFilterCreateInstance)(NSURLResponse *);
-extern void (*wkFilterRelease)(WebFilterEvaluator *);
 extern BOOL (*wkFilterWasBlocked)(WebFilterEvaluator *);
-extern const char* (*wkFilterAddData)(WebFilterEvaluator *, const char* data, int* length);
-extern const char* (*wkFilterDataComplete)(WebFilterEvaluator *, int* length);
+extern BOOL (*wkFilterIsBuffering)(WebFilterEvaluator *);
+extern NSData *(*wkFilterAddData)(WebFilterEvaluator *, NSData *);
+extern NSData *(*wkFilterDataComplete)(WebFilterEvaluator *);
 #endif
 
 #if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1080 && !PLATFORM(IOS)

Modified: trunk/Source/WebCore/platform/mac/WebCoreSystemInterface.mm (140874 => 140875)


--- trunk/Source/WebCore/platform/mac/WebCoreSystemInterface.mm	2013-01-26 00:03:48 UTC (rev 140874)
+++ trunk/Source/WebCore/platform/mac/WebCoreSystemInterface.mm	2013-01-26 00:10:46 UTC (rev 140875)
@@ -211,10 +211,10 @@
 #if USE(CONTENT_FILTERING)
 BOOL (*wkFilterIsManagedSession)(void);
 WebFilterEvaluator *(*wkFilterCreateInstance)(NSURLResponse *);
-void (*wkFilterRelease)(WebFilterEvaluator *);
 BOOL (*wkFilterWasBlocked)(WebFilterEvaluator *);
-const char* (*wkFilterAddData)(WebFilterEvaluator *, const char* data, int* length);
-const char* (*wkFilterDataComplete)(WebFilterEvaluator *, int* length);
+BOOL (*wkFilterIsBuffering)(WebFilterEvaluator *);
+NSData *(*wkFilterAddData)(WebFilterEvaluator *, NSData *);
+NSData *(*wkFilterDataComplete)(WebFilterEvaluator *);
 #endif
 
 #if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1080 && !PLATFORM(IOS)

Modified: trunk/Source/WebKit/mac/ChangeLog (140874 => 140875)


--- trunk/Source/WebKit/mac/ChangeLog	2013-01-26 00:03:48 UTC (rev 140874)
+++ trunk/Source/WebKit/mac/ChangeLog	2013-01-26 00:10:46 UTC (rev 140875)
@@ -1,3 +1,13 @@
+2013-01-25  Andy Estes  <[email protected]>
+
+        Wrap content filtering code in an object
+        https://bugs.webkit.org/show_bug.cgi?id=107914
+
+        Reviewed by Alexey Proskuryakov.
+
+        * WebCoreSupport/WebSystemInterface.mm:
+        (InitWebCoreSystemInterface): Updated to reflect changes in WKSI.
+
 2013-01-24  Dan Bernstein  <[email protected]>
 
         WebNavigationData does not distinguish between an empty title and a missing title

Modified: trunk/Source/WebKit/mac/WebCoreSupport/WebSystemInterface.mm (140874 => 140875)


--- trunk/Source/WebKit/mac/WebCoreSupport/WebSystemInterface.mm	2013-01-26 00:03:48 UTC (rev 140874)
+++ trunk/Source/WebKit/mac/WebCoreSupport/WebSystemInterface.mm	2013-01-26 00:10:46 UTC (rev 140875)
@@ -208,8 +208,8 @@
 #if USE(CONTENT_FILTERING)
     INIT(FilterIsManagedSession);
     INIT(FilterCreateInstance);
-    INIT(FilterRelease);
     INIT(FilterWasBlocked);
+    INIT(FilterIsBuffering);
     INIT(FilterAddData);
     INIT(FilterDataComplete);
 #endif

Modified: trunk/Source/WebKit2/ChangeLog (140874 => 140875)


--- trunk/Source/WebKit2/ChangeLog	2013-01-26 00:03:48 UTC (rev 140874)
+++ trunk/Source/WebKit2/ChangeLog	2013-01-26 00:10:46 UTC (rev 140875)
@@ -1,3 +1,13 @@
+2013-01-25  Andy Estes  <[email protected]>
+
+        Wrap content filtering code in an object
+        https://bugs.webkit.org/show_bug.cgi?id=107914
+
+        Reviewed by Alexey Proskuryakov.
+
+        * WebProcess/WebCoreSupport/mac/WebSystemInterface.mm:
+        (InitWebCoreSystemInterface): Updated to reflect changes in WKSI.
+
 2013-01-25  Brady Eidson  <[email protected]>
 
         HTTP Authentication should be directly between the NetworkProcess and the UIProcess

Modified: trunk/Source/WebKit2/WebProcess/WebCoreSupport/mac/WebSystemInterface.mm (140874 => 140875)


--- trunk/Source/WebKit2/WebProcess/WebCoreSupport/mac/WebSystemInterface.mm	2013-01-26 00:03:48 UTC (rev 140874)
+++ trunk/Source/WebKit2/WebProcess/WebCoreSupport/mac/WebSystemInterface.mm	2013-01-26 00:10:46 UTC (rev 140875)
@@ -171,8 +171,8 @@
 #if USE(CONTENT_FILTERING)
         INIT(FilterIsManagedSession);
         INIT(FilterCreateInstance);
-        INIT(FilterRelease);
         INIT(FilterWasBlocked);
+        INIT(FilterIsBuffering);
         INIT(FilterAddData);
         INIT(FilterDataComplete);
 #endif
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to