<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[181037] trunk/Source/WebCore</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/181037">181037</a></dd>
<dt>Author</dt> <dd>aestes@apple.com</dd>
<dt>Date</dt> <dd>2015-03-04 14:43:35 -0800 (Wed, 04 Mar 2015)</dd>
</dl>
<h3>Log Message</h3>
<pre>[Content Filtering] Make it easier to add new content filters
https://bugs.webkit.org/show_bug.cgi?id=142255
Reviewed by Sam Weinig.
ContentFilter was becoming a bit of a mess, with both the WebFilterEvaluator and NEFilterSource implementations
awkwardly living side-by-side. This patch cleans things up by moving these implementations into two separate
classes and turning ContentFilter itself into an abstract interface that each implements. A new class called
ContentFilterCollection, which also inherits from ContentFilter, manages the collection of individual content
filters and is vended to the rest of the system by ContentFilter::createIfNeeded().
This refactoring will make it easier to add a third type of content filter in a follow-on patch, namely a mock
content filter for testing purposes.
* WebCore.xcodeproj/project.pbxproj:
* loader/DocumentLoader.cpp:
(WebCore::DocumentLoader::responseReceived): Called ContentFilter::createIfNeeded() instead of instantiating a ContentFilter directly.
* platform/ContentFilter.h:
(WebCore::ContentFilter::~ContentFilter):
* platform/cocoa/NetworkExtensionContentFilter.h: Copied from Source/WebCore/platform/ContentFilter.h.
* platform/cocoa/NetworkExtensionContentFilter.mm: Added.
(WebCore::NetworkExtensionContentFilter::canHandleResponse): Moved NEFilterSource code from ContentFilterMac.mm to here.
(WebCore::NetworkExtensionContentFilter::create): Ditto.
(WebCore::NetworkExtensionContentFilter::NetworkExtensionContentFilter): Ditto.
(WebCore::NetworkExtensionContentFilter::~NetworkExtensionContentFilter): Ditto.
(WebCore::NetworkExtensionContentFilter::addData): Ditto.
(WebCore::NetworkExtensionContentFilter::finishedAddingData): Ditto.
(WebCore::NetworkExtensionContentFilter::needsMoreData): Ditto.
(WebCore::NetworkExtensionContentFilter::didBlockData): Ditto.
(WebCore::NetworkExtensionContentFilter::getReplacementData): Ditto.
(WebCore::NetworkExtensionContentFilter::unblockHandler): Ditto.
* platform/cocoa/ParentalControlsContentFilter.h: Copied from Source/WebCore/platform/ContentFilter.h.
* platform/cocoa/ParentalControlsContentFilter.mm: Added.
(WebCore::ParentalControlsContentFilter::canHandleResponse): Moved WebFilterEvaluator code from ContentFilterMac.mm to here.
(WebCore::ParentalControlsContentFilter::create): Ditto.
(WebCore::ParentalControlsContentFilter::ParentalControlsContentFilter): Ditto.
(WebCore::ParentalControlsContentFilter::addData): Ditto.
(WebCore::ParentalControlsContentFilter::finishedAddingData): Ditto.
(WebCore::ParentalControlsContentFilter::needsMoreData): Ditto.
(WebCore::ParentalControlsContentFilter::didBlockData): Ditto.
(WebCore::ParentalControlsContentFilter::getReplacementData): Ditto.
(WebCore::ParentalControlsContentFilter::unblockHandler): Ditto.
* platform/mac/ContentFilterMac.mm:
(WebCore::contentFilterType): Added a helper function template that creates a new ContentFilterType.
(WebCore::contentFilterTypes): Registered a ContentFilterType for each type of content filter.
(WebCore::ContentFilter::createIfNeeded): Created a ContentFilterCollection containing each content filter that can handle the given response.
(WebCore::ContentFilterCollection::ContentFilterCollection): Constructs a ContentFilterCollection given a Vector of content filters.
(WebCore::ContentFilterCollection::addData): Forwarded the call to each content filter in m_contentFilters.
(WebCore::ContentFilterCollection::finishedAddingData): Ditto.
(WebCore::ContentFilterCollection::needsMoreData): Ditto.
(WebCore::ContentFilterCollection::didBlockData): Ditto.
(WebCore::ContentFilterCollection::getReplacementData): Returned replacement data for the first filter that blocked the load.
If no filter blocked the load, returned the first filter's replacement data.
(WebCore::ContentFilterCollection::unblockHandler): Returned the unblock handler for the first filter that blocked the load.
(WebCore::ContentFilter::ContentFilter): Deleted.
(WebCore::ContentFilter::~ContentFilter): Deleted.
(WebCore::ContentFilter::canHandleResponse): Deleted.
(WebCore::ContentFilter::addData): Deleted.
(WebCore::ContentFilter::finishedAddingData): Deleted.
(WebCore::ContentFilter::needsMoreData): Deleted.
(WebCore::ContentFilter::didBlockData): Deleted.
(WebCore::ContentFilter::getReplacementData): Deleted.
(WebCore::ContentFilter::unblockHandler): Deleted.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreWebCorexcodeprojprojectpbxproj">trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj</a></li>
<li><a href="#trunkSourceWebCoreloaderDocumentLoadercpp">trunk/Source/WebCore/loader/DocumentLoader.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformContentFilterh">trunk/Source/WebCore/platform/ContentFilter.h</a></li>
<li><a href="#trunkSourceWebCoreplatformmacContentFilterMacmm">trunk/Source/WebCore/platform/mac/ContentFilterMac.mm</a></li>
</ul>
<h3>Added Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreplatformcocoaNetworkExtensionContentFilterh">trunk/Source/WebCore/platform/cocoa/NetworkExtensionContentFilter.h</a></li>
<li><a href="#trunkSourceWebCoreplatformcocoaNetworkExtensionContentFiltermm">trunk/Source/WebCore/platform/cocoa/NetworkExtensionContentFilter.mm</a></li>
<li><a href="#trunkSourceWebCoreplatformcocoaParentalControlsContentFilterh">trunk/Source/WebCore/platform/cocoa/ParentalControlsContentFilter.h</a></li>
<li><a href="#trunkSourceWebCoreplatformcocoaParentalControlsContentFiltermm">trunk/Source/WebCore/platform/cocoa/ParentalControlsContentFilter.mm</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (181036 => 181037)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2015-03-04 22:41:24 UTC (rev 181036)
+++ trunk/Source/WebCore/ChangeLog        2015-03-04 22:43:35 UTC (rev 181037)
</span><span class="lines">@@ -1,3 +1,69 @@
</span><ins>+2015-03-03 Andy Estes <aestes@apple.com>
+
+ [Content Filtering] Make it easier to add new content filters
+ https://bugs.webkit.org/show_bug.cgi?id=142255
+
+ Reviewed by Sam Weinig.
+
+ ContentFilter was becoming a bit of a mess, with both the WebFilterEvaluator and NEFilterSource implementations
+ awkwardly living side-by-side. This patch cleans things up by moving these implementations into two separate
+ classes and turning ContentFilter itself into an abstract interface that each implements. A new class called
+ ContentFilterCollection, which also inherits from ContentFilter, manages the collection of individual content
+ filters and is vended to the rest of the system by ContentFilter::createIfNeeded().
+
+ This refactoring will make it easier to add a third type of content filter in a follow-on patch, namely a mock
+ content filter for testing purposes.
+
+ * WebCore.xcodeproj/project.pbxproj:
+ * loader/DocumentLoader.cpp:
+ (WebCore::DocumentLoader::responseReceived): Called ContentFilter::createIfNeeded() instead of instantiating a ContentFilter directly.
+ * platform/ContentFilter.h:
+ (WebCore::ContentFilter::~ContentFilter):
+ * platform/cocoa/NetworkExtensionContentFilter.h: Copied from Source/WebCore/platform/ContentFilter.h.
+ * platform/cocoa/NetworkExtensionContentFilter.mm: Added.
+ (WebCore::NetworkExtensionContentFilter::canHandleResponse): Moved NEFilterSource code from ContentFilterMac.mm to here.
+ (WebCore::NetworkExtensionContentFilter::create): Ditto.
+ (WebCore::NetworkExtensionContentFilter::NetworkExtensionContentFilter): Ditto.
+ (WebCore::NetworkExtensionContentFilter::~NetworkExtensionContentFilter): Ditto.
+ (WebCore::NetworkExtensionContentFilter::addData): Ditto.
+ (WebCore::NetworkExtensionContentFilter::finishedAddingData): Ditto.
+ (WebCore::NetworkExtensionContentFilter::needsMoreData): Ditto.
+ (WebCore::NetworkExtensionContentFilter::didBlockData): Ditto.
+ (WebCore::NetworkExtensionContentFilter::getReplacementData): Ditto.
+ (WebCore::NetworkExtensionContentFilter::unblockHandler): Ditto.
+ * platform/cocoa/ParentalControlsContentFilter.h: Copied from Source/WebCore/platform/ContentFilter.h.
+ * platform/cocoa/ParentalControlsContentFilter.mm: Added.
+ (WebCore::ParentalControlsContentFilter::canHandleResponse): Moved WebFilterEvaluator code from ContentFilterMac.mm to here.
+ (WebCore::ParentalControlsContentFilter::create): Ditto.
+ (WebCore::ParentalControlsContentFilter::ParentalControlsContentFilter): Ditto.
+ (WebCore::ParentalControlsContentFilter::addData): Ditto.
+ (WebCore::ParentalControlsContentFilter::finishedAddingData): Ditto.
+ (WebCore::ParentalControlsContentFilter::needsMoreData): Ditto.
+ (WebCore::ParentalControlsContentFilter::didBlockData): Ditto.
+ (WebCore::ParentalControlsContentFilter::getReplacementData): Ditto.
+ (WebCore::ParentalControlsContentFilter::unblockHandler): Ditto.
+ * platform/mac/ContentFilterMac.mm:
+ (WebCore::contentFilterType): Added a helper function template that creates a new ContentFilterType.
+ (WebCore::contentFilterTypes): Registered a ContentFilterType for each type of content filter.
+ (WebCore::ContentFilter::createIfNeeded): Created a ContentFilterCollection containing each content filter that can handle the given response.
+ (WebCore::ContentFilterCollection::ContentFilterCollection): Constructs a ContentFilterCollection given a Vector of content filters.
+ (WebCore::ContentFilterCollection::addData): Forwarded the call to each content filter in m_contentFilters.
+ (WebCore::ContentFilterCollection::finishedAddingData): Ditto.
+ (WebCore::ContentFilterCollection::needsMoreData): Ditto.
+ (WebCore::ContentFilterCollection::didBlockData): Ditto.
+ (WebCore::ContentFilterCollection::getReplacementData): Returned replacement data for the first filter that blocked the load.
+ If no filter blocked the load, returned the first filter's replacement data.
+ (WebCore::ContentFilterCollection::unblockHandler): Returned the unblock handler for the first filter that blocked the load.
+ (WebCore::ContentFilter::ContentFilter): Deleted.
+ (WebCore::ContentFilter::~ContentFilter): Deleted.
+ (WebCore::ContentFilter::canHandleResponse): Deleted.
+ (WebCore::ContentFilter::addData): Deleted.
+ (WebCore::ContentFilter::finishedAddingData): Deleted.
+ (WebCore::ContentFilter::needsMoreData): Deleted.
+ (WebCore::ContentFilter::didBlockData): Deleted.
+ (WebCore::ContentFilter::getReplacementData): Deleted.
+ (WebCore::ContentFilter::unblockHandler): Deleted.
+
</ins><span class="cx"> 2015-03-04 David Kilzer <ddkilzer@apple.com>
</span><span class="cx">
</span><span class="cx"> Switch remaining CoreMedia soft-linking in WebCore over to CoreMediaSoftLink.{cpp,h}
</span></span></pre></div>
<a id="trunkSourceWebCoreWebCorexcodeprojprojectpbxproj"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (181036 => 181037)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj        2015-03-04 22:41:24 UTC (rev 181036)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj        2015-03-04 22:43:35 UTC (rev 181037)
</span><span class="lines">@@ -3804,8 +3804,12 @@
</span><span class="cx">                 A14832CF187F684700DA63A6 /* WebCoreThreadSystemInterface.h in Headers */ = {isa = PBXBuildFile; fileRef = A14832A1187F508700DA63A6 /* WebCoreThreadSystemInterface.h */; settings = {ATTRIBUTES = (Private, ); }; };
</span><span class="cx">                 A17C81220F2A5CF7005DAAEB /* HTMLElementFactory.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A17C81200F2A5CF7005DAAEB /* HTMLElementFactory.cpp */; };
</span><span class="cx">                 A17C81230F2A5CF7005DAAEB /* HTMLElementFactory.h in Headers */ = {isa = PBXBuildFile; fileRef = A17C81210F2A5CF7005DAAEB /* HTMLElementFactory.h */; };
</span><ins>+                A18890AE1AA13F250026C301 /* ParentalControlsContentFilter.mm in Sources */ = {isa = PBXBuildFile; fileRef = A18890AC1AA13F250026C301 /* ParentalControlsContentFilter.mm */; };
+                A18890AF1AA13F250026C301 /* ParentalControlsContentFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = A18890AD1AA13F250026C301 /* ParentalControlsContentFilter.h */; };
</ins><span class="cx">                 A19D93461A9FEC7200B46C24 /* NEFilterSourceSPI.h in Headers */ = {isa = PBXBuildFile; fileRef = A19D93441A9FEC7200B46C24 /* NEFilterSourceSPI.h */; };
</span><span class="cx">                 A19D93471A9FEC7200B46C24 /* WebFilterEvaluatorSPI.h in Headers */ = {isa = PBXBuildFile; fileRef = A19D93451A9FEC7200B46C24 /* WebFilterEvaluatorSPI.h */; };
</span><ins>+                A19D934A1AA11B1E00B46C24 /* NetworkExtensionContentFilter.mm in Sources */ = {isa = PBXBuildFile; fileRef = A19D93481AA11B1E00B46C24 /* NetworkExtensionContentFilter.mm */; };
+                A19D934B1AA11B1E00B46C24 /* NetworkExtensionContentFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = A19D93491AA11B1E00B46C24 /* NetworkExtensionContentFilter.h */; };
</ins><span class="cx">                 A1C797181883DD82000F5E1F /* DOMGestureEvent.h in Copy Generated Headers */ = {isa = PBXBuildFile; fileRef = 0F54DCDD1880F901003EEDBB /* DOMGestureEvent.h */; };
</span><span class="cx">                 A1C797191883DDED000F5E1F /* DOMTouch.h in Copy Generated Headers */ = {isa = PBXBuildFile; fileRef = 0F54DCCD1880F867003EEDBB /* DOMTouch.h */; };
</span><span class="cx">                 A1C7971A1883DE0D000F5E1F /* DOMTouchEvent.h in Copy Generated Headers */ = {isa = PBXBuildFile; fileRef = 0F54DCCF1880F867003EEDBB /* DOMTouchEvent.h */; };
</span><span class="lines">@@ -11033,8 +11037,12 @@
</span><span class="cx">                 A14832AB187F508700DA63A6 /* WKViewPrivate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = WKViewPrivate.h; path = ios/wak/WKViewPrivate.h; sourceTree = "<group>"; };
</span><span class="cx">                 A17C81200F2A5CF7005DAAEB /* HTMLElementFactory.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = HTMLElementFactory.cpp; sourceTree = "<group>"; };
</span><span class="cx">                 A17C81210F2A5CF7005DAAEB /* HTMLElementFactory.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HTMLElementFactory.h; sourceTree = "<group>"; };
</span><ins>+                A18890AC1AA13F250026C301 /* ParentalControlsContentFilter.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ParentalControlsContentFilter.mm; sourceTree = "<group>"; };
+                A18890AD1AA13F250026C301 /* ParentalControlsContentFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ParentalControlsContentFilter.h; sourceTree = "<group>"; };
</ins><span class="cx">                 A19D93441A9FEC7200B46C24 /* NEFilterSourceSPI.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NEFilterSourceSPI.h; sourceTree = "<group>"; };
</span><span class="cx">                 A19D93451A9FEC7200B46C24 /* WebFilterEvaluatorSPI.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebFilterEvaluatorSPI.h; sourceTree = "<group>"; };
</span><ins>+                A19D93481AA11B1E00B46C24 /* NetworkExtensionContentFilter.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = NetworkExtensionContentFilter.mm; sourceTree = "<group>"; };
+                A19D93491AA11B1E00B46C24 /* NetworkExtensionContentFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NetworkExtensionContentFilter.h; sourceTree = "<group>"; };
</ins><span class="cx">                 A1C7971C1883E51F000F5E1F /* DOMHTMLTextAreaElementPrivate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DOMHTMLTextAreaElementPrivate.h; sourceTree = "<group>"; };
</span><span class="cx">                 A1C7FAA1133A5D3500D6732D /* JSXPathResultCustom.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSXPathResultCustom.cpp; sourceTree = "<group>"; };
</span><span class="cx">                 A1DE712B18612AC100734192 /* TouchEvents.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = TouchEvents.cpp; sourceTree = "<group>"; };
</span><span class="lines">@@ -18723,6 +18731,10 @@
</span><span class="cx">                                 1A0409F21A43675C009E47F3 /* MachSendRight.cpp */,
</span><span class="cx">                                 1A0409DB1A4360B5009E47F3 /* MachSendRight.h */,
</span><span class="cx">                                 ADB6B29718FB90240081963E /* MemoryPressureHandlerCocoa.mm */,
</span><ins>+                                A19D93491AA11B1E00B46C24 /* NetworkExtensionContentFilter.h */,
+                                A19D93481AA11B1E00B46C24 /* NetworkExtensionContentFilter.mm */,
+                                A18890AD1AA13F250026C301 /* ParentalControlsContentFilter.h */,
+                                A18890AC1AA13F250026C301 /* ParentalControlsContentFilter.mm */,
</ins><span class="cx">                                 1AA84F03143BA7BD0051D153 /* ScrollController.h */,
</span><span class="cx">                                 1AA84F02143BA7BD0051D153 /* ScrollController.mm */,
</span><span class="cx">                                 5D5975B119635F1100D00878 /* SystemVersion.h */,
</span><span class="lines">@@ -24652,6 +24664,7 @@
</span><span class="cx">                                 A871DE270A152AC800B12A68 /* HTMLHtmlElement.h in Headers */,
</span><span class="cx">                                 A871DE2A0A152AC800B12A68 /* HTMLIFrameElement.h in Headers */,
</span><span class="cx">                                 A8EA7D2D0A19385500A8EF5F /* HTMLImageElement.h in Headers */,
</span><ins>+                                A19D934B1AA11B1E00B46C24 /* NetworkExtensionContentFilter.h in Headers */,
</ins><span class="cx">                                 A8EA7D2B0A19385500A8EF5F /* HTMLImageLoader.h in Headers */,
</span><span class="cx">                                 A81369CC097374F600D74463 /* HTMLInputElement.h in Headers */,
</span><span class="cx">                                 97BC849B12370A4B000C6161 /* HTMLInputStream.h in Headers */,
</span><span class="lines">@@ -26533,6 +26546,7 @@
</span><span class="cx">                                 B2227A940D00BF220071B782 /* SVGPolylineElement.h in Headers */,
</span><span class="cx">                                 B2227A970D00BF220071B782 /* SVGPreserveAspectRatio.h in Headers */,
</span><span class="cx">                                 088A0E0A126EF1DB00978F7A /* SVGProperty.h in Headers */,
</span><ins>+                                A18890AF1AA13F250026C301 /* ParentalControlsContentFilter.h in Headers */,
</ins><span class="cx">                                 081DD49C13BA1A6000DC7627 /* SVGPropertyInfo.h in Headers */,
</span><span class="cx">                                 088A0E0B126EF1DB00978F7A /* SVGPropertyTearOff.h in Headers */,
</span><span class="cx">                                 088A0E0C126EF1DB00978F7A /* SVGPropertyTraits.h in Headers */,
</span><span class="lines">@@ -29653,6 +29667,7 @@
</span><span class="cx">                                 4512502215DCE37D002F84E2 /* SpinButtonElement.cpp in Sources */,
</span><span class="cx">                                 93309E11099E64920056E581 /* SplitElementCommand.cpp in Sources */,
</span><span class="cx">                                 93309E13099E64920056E581 /* SplitTextNodeCommand.cpp in Sources */,
</span><ins>+                                A19D934A1AA11B1E00B46C24 /* NetworkExtensionContentFilter.mm in Sources */,
</ins><span class="cx">                                 93309E15099E64920056E581 /* SplitTextNodeContainingElementCommand.cpp in Sources */,
</span><span class="cx">                                 A1E1154813015C5D0054AC8C /* SpotLightSource.cpp in Sources */,
</span><span class="cx">                                 97BC6A3E1505F081001B74AC /* SQLException.cpp in Sources */,
</span><span class="lines">@@ -29744,6 +29759,7 @@
</span><span class="cx">                                 4381763B13A697D4007D1187 /* SVGAnimatedLength.cpp in Sources */,
</span><span class="cx">                                 431A2FD713B7707A007791E4 /* SVGAnimatedLengthList.cpp in Sources */,
</span><span class="cx">                                 43A0F0B113AC7D6D00A5F0A7 /* SVGAnimatedNumber.cpp in Sources */,
</span><ins>+                                A18890AE1AA13F250026C301 /* ParentalControlsContentFilter.mm in Sources */,
</ins><span class="cx">                                 4331AC7813B6870000A9E5AE /* SVGAnimatedNumberList.cpp in Sources */,
</span><span class="cx">                                 431A2F9D13B6F2B0007791E4 /* SVGAnimatedNumberOptionalNumber.cpp in Sources */,
</span><span class="cx">                                 08B5F25513B5FFF2002959EC /* SVGAnimatedPath.cpp in Sources */,
</span></span></pre></div>
<a id="trunkSourceWebCoreloaderDocumentLoadercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/loader/DocumentLoader.cpp (181036 => 181037)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/loader/DocumentLoader.cpp        2015-03-04 22:41:24 UTC (rev 181036)
+++ trunk/Source/WebCore/loader/DocumentLoader.cpp        2015-03-04 22:43:35 UTC (rev 181037)
</span><span class="lines">@@ -666,8 +666,7 @@
</span><span class="cx"> #endif
</span><span class="cx">
</span><span class="cx"> #if ENABLE(CONTENT_FILTERING)
</span><del>- if (ContentFilter::canHandleResponse(response))
- m_contentFilter = std::make_unique<ContentFilter>(response);
</del><ins>+ m_contentFilter = ContentFilter::createIfNeeded(response);
</ins><span class="cx"> #endif
</span><span class="cx">
</span><span class="cx"> frameLoader()->policyChecker().checkContentPolicy(m_response, [this](PolicyAction policy) {
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformContentFilterh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/ContentFilter.h (181036 => 181037)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/ContentFilter.h        2015-03-04 22:41:24 UTC (rev 181036)
+++ trunk/Source/WebCore/platform/ContentFilter.h        2015-03-04 22:43:35 UTC (rev 181037)
</span><span class="lines">@@ -29,53 +29,25 @@
</span><span class="cx"> #if ENABLE(CONTENT_FILTERING)
</span><span class="cx">
</span><span class="cx"> #include "ContentFilterUnblockHandler.h"
</span><del>-#include <wtf/PassRefPtr.h>
-#include <wtf/RetainPtr.h>
</del><span class="cx">
</span><del>-#if PLATFORM(COCOA)
-OBJC_CLASS NSData;
-OBJC_CLASS WebFilterEvaluator;
-#endif
-
</del><span class="cx"> #define HAVE_NE_FILTER_SOURCE TARGET_OS_EMBEDDED || (!TARGET_OS_IPHONE && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101000 && CPU(X86_64))
</span><span class="cx">
</span><del>-#if HAVE(NE_FILTER_SOURCE)
-#import <dispatch/dispatch.h>
-OBJC_CLASS NEFilterSource;
-OBJC_CLASS NSMutableData;
-#endif
-
</del><span class="cx"> namespace WebCore {
</span><span class="cx">
</span><del>-class ResourceRequest;
</del><span class="cx"> class ResourceResponse;
</span><span class="cx">
</span><span class="cx"> class ContentFilter {
</span><span class="cx"> public:
</span><del>- static bool canHandleResponse(const ResourceResponse&);
</del><ins>+ static std::unique_ptr<ContentFilter> createIfNeeded(const ResourceResponse&);
</ins><span class="cx">
</span><del>- explicit ContentFilter(const ResourceResponse&);
- WEBCORE_EXPORT ~ContentFilter();
</del><ins>+ virtual ~ContentFilter() { }
</ins><span class="cx">
</span><del>- void addData(const char* data, int length);
- void finishedAddingData();
- bool needsMoreData() const;
- bool didBlockData() const;
- const char* getReplacementData(int& length) const;
- ContentFilterUnblockHandler unblockHandler() const;
-
-private:
-#if PLATFORM(COCOA)
- RetainPtr<WebFilterEvaluator> m_platformContentFilter;
- RetainPtr<NSData> m_replacementData;
-#endif
-
-#if HAVE(NE_FILTER_SOURCE)
- long m_neFilterSourceStatus;
- RetainPtr<NEFilterSource> m_neFilterSource;
- dispatch_queue_t m_neFilterSourceQueue;
- RetainPtr<NSMutableData> m_originalData;
-#endif
</del><ins>+ 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;
</ins><span class="cx"> };
</span><span class="cx">
</span><span class="cx"> } // namespace WebCore
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformcocoaNetworkExtensionContentFilterhfromrev181036trunkSourceWebCoreplatformContentFilterh"></a>
<div class="copfile"><h4>Copied: trunk/Source/WebCore/platform/cocoa/NetworkExtensionContentFilter.h (from rev 181036, trunk/Source/WebCore/platform/ContentFilter.h) (0 => 181037)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/cocoa/NetworkExtensionContentFilter.h         (rev 0)
+++ trunk/Source/WebCore/platform/cocoa/NetworkExtensionContentFilter.h        2015-03-04 22:43:35 UTC (rev 181037)
</span><span class="lines">@@ -0,0 +1,62 @@
</span><ins>+/*
+ * 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 NetworkExtensionContentFilter_h
+#define NetworkExtensionContentFilter_h
+
+#include "ContentFilter.h"
+#include <wtf/Compiler.h>
+#include <wtf/RetainPtr.h>
+
+OBJC_CLASS NEFilterSource;
+OBJC_CLASS NSMutableData;
+
+namespace WebCore {
+
+class NetworkExtensionContentFilter final : public ContentFilter {
+public:
+ static bool canHandleResponse(const ResourceResponse&);
+ static std::unique_ptr<NetworkExtensionContentFilter> create(const ResourceResponse&);
+
+ explicit NetworkExtensionContentFilter(const ResourceResponse&);
+ ~NetworkExtensionContentFilter() override;
+
+ 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:
+ NSInteger m_neFilterSourceStatus;
+ RetainPtr<NEFilterSource> m_neFilterSource;
+ dispatch_queue_t m_neFilterSourceQueue;
+ RetainPtr<NSMutableData> m_originalData;
+};
+
+} // namespace WebCore
+
+#endif // NetworkExtensionContentFilter_h
</ins></span></pre></div>
<a id="trunkSourceWebCoreplatformcocoaNetworkExtensionContentFiltermm"></a>
<div class="addfile"><h4>Added: trunk/Source/WebCore/platform/cocoa/NetworkExtensionContentFilter.mm (0 => 181037)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/cocoa/NetworkExtensionContentFilter.mm         (rev 0)
+++ trunk/Source/WebCore/platform/cocoa/NetworkExtensionContentFilter.mm        2015-03-04 22:43:35 UTC (rev 181037)
</span><span class="lines">@@ -0,0 +1,134 @@
</span><ins>+/*
+ * 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.
+ */
+
+#import "config.h"
+#import "NetworkExtensionContentFilter.h"
+
+#if HAVE(NE_FILTER_SOURCE)
+
+#import "NEFilterSourceSPI.h"
+#import "ResourceResponse.h"
+#import "SoftLinking.h"
+#import <objc/runtime.h>
+
+SOFT_LINK_FRAMEWORK(NetworkExtension);
+SOFT_LINK_CLASS(NetworkExtension, NEFilterSource);
+
+namespace WebCore {
+
+bool NetworkExtensionContentFilter::canHandleResponse(const ResourceResponse& response)
+{
+ return response.url().protocolIsInHTTPFamily() && [getNEFilterSourceClass() filterRequired];
+}
+
+std::unique_ptr<NetworkExtensionContentFilter> NetworkExtensionContentFilter::create(const ResourceResponse& response)
+{
+ return std::make_unique<NetworkExtensionContentFilter>(response);
+}
+
+NetworkExtensionContentFilter::NetworkExtensionContentFilter(const ResourceResponse& response)
+ : m_neFilterSourceStatus { NEFilterSourceStatusNeedsMoreData }
+ , m_neFilterSource { adoptNS([allocNEFilterSourceInstance() initWithURL:[response.nsURLResponse() URL] direction:NEFilterSourceDirectionInbound socketIdentifier:0]) }
+ , m_neFilterSourceQueue { dispatch_queue_create("com.apple.WebCore.NEFilterSourceQueue", DISPATCH_QUEUE_SERIAL) }
+{
+ ASSERT([getNEFilterSourceClass() filterRequired]);
+
+ long long expectedContentSize = [response.nsURLResponse() expectedContentLength];
+ if (expectedContentSize < 0)
+ m_originalData = adoptNS([[NSMutableData alloc] init]);
+ else
+ m_originalData = adoptNS([[NSMutableData alloc] initWithCapacity:(NSUInteger)expectedContentSize]);
+}
+
+NetworkExtensionContentFilter::~NetworkExtensionContentFilter()
+{
+ dispatch_release(m_neFilterSourceQueue);
+}
+
+void NetworkExtensionContentFilter::addData(const char* data, int length)
+{
+ // FIXME: NEFilterSource doesn't buffer data like WebFilterEvaluator does,
+ // so we need to do it ourselves so getReplacementData() can return the
+ // original bytes back to the loader. We should find a way to remove this
+ // additional copy.
+ [m_originalData appendBytes:data length:length];
+
+ dispatch_semaphore_t neFilterSourceSemaphore = dispatch_semaphore_create(0);
+ [m_neFilterSource addData:[NSData dataWithBytes:(void*)data length:length] withCompletionQueue:m_neFilterSourceQueue completionHandler:^(NEFilterSourceStatus status, NSData *) {
+ m_neFilterSourceStatus = status;
+ dispatch_semaphore_signal(neFilterSourceSemaphore);
+ }];
+
+ // FIXME: We have to block here since DocumentLoader expects to have a
+ // blocked/not blocked answer from the filter immediately after calling
+ // addData(). We should find a way to make this asynchronous.
+ dispatch_semaphore_wait(neFilterSourceSemaphore, DISPATCH_TIME_FOREVER);
+ dispatch_release(neFilterSourceSemaphore);
+}
+
+void NetworkExtensionContentFilter::finishedAddingData()
+{
+ dispatch_semaphore_t neFilterSourceSemaphore = dispatch_semaphore_create(0);
+ [m_neFilterSource dataCompleteWithCompletionQueue:m_neFilterSourceQueue completionHandler:^(NEFilterSourceStatus status, NSData *) {
+ m_neFilterSourceStatus = status;
+ dispatch_semaphore_signal(neFilterSourceSemaphore);
+ }];
+
+ // FIXME: We have to block here since DocumentLoader expects to have a
+ // blocked/not blocked answer from the filter immediately after calling
+ // finishedAddingData(). We should find a way to make this asynchronous.
+ dispatch_semaphore_wait(neFilterSourceSemaphore, DISPATCH_TIME_FOREVER);
+ dispatch_release(neFilterSourceSemaphore);
+}
+
+bool NetworkExtensionContentFilter::needsMoreData() const
+{
+ return m_neFilterSourceStatus == NEFilterSourceStatusNeedsMoreData;
+}
+
+bool NetworkExtensionContentFilter::didBlockData() const
+{
+ return m_neFilterSourceStatus == NEFilterSourceStatusBlock;
+}
+
+const char* NetworkExtensionContentFilter::getReplacementData(int& length) const
+{
+ if (didBlockData()) {
+ length = 0;
+ return nullptr;
+ }
+
+ length = [m_originalData length];
+ return static_cast<const char*>([m_originalData bytes]);
+}
+
+ContentFilterUnblockHandler NetworkExtensionContentFilter::unblockHandler() const
+{
+ return { };
+}
+
+} // namespace WebCore
+
+#endif // HAVE(NE_FILTER_SOURCE)
</ins></span></pre></div>
<a id="trunkSourceWebCoreplatformcocoaParentalControlsContentFilterhfromrev181036trunkSourceWebCoreplatformContentFilterh"></a>
<div class="copfile"><h4>Copied: trunk/Source/WebCore/platform/cocoa/ParentalControlsContentFilter.h (from rev 181036, trunk/Source/WebCore/platform/ContentFilter.h) (0 => 181037)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/cocoa/ParentalControlsContentFilter.h         (rev 0)
+++ trunk/Source/WebCore/platform/cocoa/ParentalControlsContentFilter.h        2015-03-04 22:43:35 UTC (rev 181037)
</span><span class="lines">@@ -0,0 +1,59 @@
</span><ins>+/*
+ * 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 ParentalControlsContentFilter_h
+#define ParentalControlsContentFilter_h
+
+#include "ContentFilter.h"
+#include <wtf/Compiler.h>
+#include <wtf/RetainPtr.h>
+
+OBJC_CLASS NSData;
+OBJC_CLASS WebFilterEvaluator;
+
+namespace WebCore {
+
+class ParentalControlsContentFilter final : public ContentFilter {
+public:
+ static bool canHandleResponse(const ResourceResponse&);
+ static std::unique_ptr<ParentalControlsContentFilter> create(const ResourceResponse&);
+
+ explicit ParentalControlsContentFilter(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:
+ RetainPtr<WebFilterEvaluator> m_webFilterEvaluator;
+ RetainPtr<NSData> m_replacementData;
+};
+
+} // namespace WebCore
+
+#endif // ParentalControlsContentFilter_h
</ins></span></pre></div>
<a id="trunkSourceWebCoreplatformcocoaParentalControlsContentFiltermm"></a>
<div class="addfile"><h4>Added: trunk/Source/WebCore/platform/cocoa/ParentalControlsContentFilter.mm (0 => 181037)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/cocoa/ParentalControlsContentFilter.mm         (rev 0)
+++ trunk/Source/WebCore/platform/cocoa/ParentalControlsContentFilter.mm        2015-03-04 22:43:35 UTC (rev 181037)
</span><span class="lines">@@ -0,0 +1,99 @@
</span><ins>+/*
+ * 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.
+ */
+
+#import "config.h"
+#import "ParentalControlsContentFilter.h"
+
+#import "ResourceResponse.h"
+#import "SoftLinking.h"
+#import "WebFilterEvaluatorSPI.h"
+#import <objc/runtime.h>
+
+SOFT_LINK_PRIVATE_FRAMEWORK(WebContentAnalysis);
+SOFT_LINK_CLASS(WebContentAnalysis, WebFilterEvaluator);
+
+namespace WebCore {
+
+bool ParentalControlsContentFilter::canHandleResponse(const ResourceResponse& response)
+{
+ if (!response.url().protocolIsInHTTPFamily())
+ return false;
+
+ if ([getWebFilterEvaluatorClass() isManagedSession]) {
+#if PLATFORM(MAC)
+ if (response.url().protocolIs("https"))
+#endif
+ return true;
+ }
+
+ return false;
+}
+
+std::unique_ptr<ParentalControlsContentFilter> ParentalControlsContentFilter::create(const ResourceResponse& response)
+{
+ return std::make_unique<ParentalControlsContentFilter>(response);
+}
+
+ParentalControlsContentFilter::ParentalControlsContentFilter(const ResourceResponse& response)
+ : m_webFilterEvaluator { adoptNS([allocWebFilterEvaluatorInstance() initWithResponse:response.nsURLResponse()]) }
+{
+ ASSERT([getWebFilterEvaluatorClass() isManagedSession]);
+}
+
+void ParentalControlsContentFilter::addData(const char* data, int length)
+{
+ ASSERT(![m_replacementData.get() length]);
+ m_replacementData = [m_webFilterEvaluator addData:[NSData dataWithBytesNoCopy:(void*)data length:length freeWhenDone:NO]];
+ ASSERT(needsMoreData() || [m_replacementData.get() length]);
+}
+
+void ParentalControlsContentFilter::finishedAddingData()
+{
+ ASSERT(![m_replacementData.get() length]);
+ m_replacementData = [m_webFilterEvaluator dataComplete];
+}
+
+bool ParentalControlsContentFilter::needsMoreData() const
+{
+ return [m_webFilterEvaluator filterState] == kWFEStateBuffering;
+}
+
+bool ParentalControlsContentFilter::didBlockData() const
+{
+ return [m_webFilterEvaluator wasBlocked];
+}
+
+const char* ParentalControlsContentFilter::getReplacementData(int& length) const
+{
+ length = [m_replacementData length];
+ return static_cast<const char*>([m_replacementData bytes]);
+}
+
+ContentFilterUnblockHandler ParentalControlsContentFilter::unblockHandler() const
+{
+ return ContentFilterUnblockHandler { m_webFilterEvaluator.get() };
+}
+
+} // namespace WebCore
</ins></span></pre></div>
<a id="trunkSourceWebCoreplatformmacContentFilterMacmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/mac/ContentFilterMac.mm (181036 => 181037)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/mac/ContentFilterMac.mm        2015-03-04 22:41:24 UTC (rev 181036)
+++ trunk/Source/WebCore/platform/mac/ContentFilterMac.mm        2015-03-04 22:43:35 UTC (rev 181037)
</span><span class="lines">@@ -23,180 +23,142 @@
</span><span class="cx"> * THE POSSIBILITY OF SUCH DAMAGE.
</span><span class="cx"> */
</span><span class="cx">
</span><ins>+// FIXME: Rename to ContentFilter.cpp and move to platform/.
+
</ins><span class="cx"> #import "config.h"
</span><span class="cx"> #import "ContentFilter.h"
</span><span class="cx">
</span><span class="cx"> #if ENABLE(CONTENT_FILTERING)
</span><span class="cx">
</span><del>-#import "ResourceResponse.h"
-#import "SoftLinking.h"
-#import "WebFilterEvaluatorSPI.h"
-#import <objc/runtime.h>
</del><ins>+#import "NetworkExtensionContentFilter.h"
+#import "ParentalControlsContentFilter.h"
+#import <wtf/NeverDestroyed.h>
+#import <wtf/Vector.h>
</ins><span class="cx">
</span><del>-#if HAVE(NE_FILTER_SOURCE)
-#import "NEFilterSourceSPI.h"
-SOFT_LINK_FRAMEWORK(NetworkExtension);
-SOFT_LINK_CLASS(NetworkExtension, NEFilterSource);
-#endif
-
-SOFT_LINK_PRIVATE_FRAMEWORK(WebContentAnalysis);
-SOFT_LINK_CLASS(WebContentAnalysis, WebFilterEvaluator);
-
</del><span class="cx"> namespace WebCore {
</span><span class="cx">
</span><del>-ContentFilter::ContentFilter(const ResourceResponse& response)
-#if HAVE(NE_FILTER_SOURCE)
- : m_neFilterSourceStatus(NEFilterSourceStatusNeedsMoreData)
- , m_neFilterSourceQueue(0)
-#endif
-{
- if ([getWebFilterEvaluatorClass() isManagedSession])
- m_platformContentFilter = adoptNS([allocWebFilterEvaluatorInstance() initWithResponse:response.nsURLResponse()]);
</del><ins>+struct ContentFilterType {
+ const std::function<bool(const ResourceResponse&)> canHandleResponse;
+ const std::function<std::unique_ptr<ContentFilter>(const ResourceResponse&)> create;
+};
</ins><span class="cx">
</span><del>-#if HAVE(NE_FILTER_SOURCE)
- if ([getNEFilterSourceClass() filterRequired]) {
- m_neFilterSource = adoptNS([allocNEFilterSourceInstance() initWithURL:[response.nsURLResponse() URL] direction:NEFilterSourceDirectionInbound socketIdentifier:0]);
- m_neFilterSourceQueue = dispatch_queue_create("com.apple.WebCore.NEFilterSourceQueue", DISPATCH_QUEUE_SERIAL);
-
- long long expectedContentSize = [response.nsURLResponse() expectedContentLength];
- if (expectedContentSize < 0)
- m_originalData = adoptNS([[NSMutableData alloc] init]);
- else
- m_originalData = adoptNS([[NSMutableData alloc] initWithCapacity:(NSUInteger)expectedContentSize]);
- }
-#endif
</del><ins>+template <typename T>
+static inline ContentFilterType contentFilterType()
+{
+ return { T::canHandleResponse, T::create };
</ins><span class="cx"> }
</span><span class="cx">
</span><del>-ContentFilter::~ContentFilter()
</del><ins>+static const Vector<ContentFilterType>& contentFilterTypes()
</ins><span class="cx"> {
</span><ins>+ static NeverDestroyed<Vector<ContentFilterType>> types(
+ Vector<ContentFilterType>({
+ contentFilterType<ParentalControlsContentFilter>(),
</ins><span class="cx"> #if HAVE(NE_FILTER_SOURCE)
</span><del>- if (m_neFilterSourceQueue)
- dispatch_release(m_neFilterSourceQueue);
</del><ins>+ contentFilterType<NetworkExtensionContentFilter>()
</ins><span class="cx"> #endif
</span><ins>+ })
+ );
+ return types;
</ins><span class="cx"> }
</span><span class="cx">
</span><del>-bool ContentFilter::canHandleResponse(const ResourceResponse& response)
-{
- if (!response.url().protocolIsInHTTPFamily())
- return false;
</del><ins>+class ContentFilterCollection final : public ContentFilter {
+public:
+ using Container = Vector<std::unique_ptr<ContentFilter>>;
</ins><span class="cx">
</span><del>- if ([getWebFilterEvaluatorClass() isManagedSession]) {
-#if PLATFORM(MAC)
- if (response.url().protocolIs("https"))
-#endif
- return true;
- }
</del><ins>+ explicit ContentFilterCollection(Container);
</ins><span class="cx">
</span><del>-#if HAVE(NE_FILTER_SOURCE)
- return [getNEFilterSourceClass() filterRequired];
-#else
- return false;
-#endif
-}
</del><ins>+ 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;
</ins><span class="cx">
</span><del>-void ContentFilter::addData(const char* data, int length)
-{
- ASSERT(needsMoreData());
</del><ins>+private:
+ Container m_contentFilters;
+};
</ins><span class="cx">
</span><del>- if (m_platformContentFilter) {
- ASSERT(![m_replacementData.get() length]);
- m_replacementData = [m_platformContentFilter addData:[NSData dataWithBytesNoCopy:(void*)data length:length freeWhenDone:NO]];
- ASSERT(needsMoreData() || [m_replacementData.get() length]);
</del><ins>+std::unique_ptr<ContentFilter> ContentFilter::createIfNeeded(const ResourceResponse& response)
+{
+ ContentFilterCollection::Container filters;
+ for (auto& type : contentFilterTypes()) {
+ if (type.canHandleResponse(response))
+ filters.append(type.create(response));
</ins><span class="cx"> }
</span><span class="cx">
</span><del>-#if HAVE(NE_FILTER_SOURCE)
- if (!m_neFilterSource)
- return;
</del><ins>+ if (filters.isEmpty())
+ return nullptr;
</ins><span class="cx">
</span><del>- // FIXME: NEFilterSource doesn't buffer data like WebFilterEvaluator does,
- // so we need to do it ourselves so getReplacementData() can return the
- // original bytes back to the loader. We should find a way to remove this
- // additional copy.
- [m_originalData appendBytes:data length:length];
</del><ins>+ return std::make_unique<ContentFilterCollection>(WTF::move(filters));
+}
</ins><span class="cx">
</span><del>- dispatch_semaphore_t neFilterSourceSemaphore = dispatch_semaphore_create(0);
- [m_neFilterSource addData:[NSData dataWithBytes:(void*)data length:length] withCompletionQueue:m_neFilterSourceQueue completionHandler:^(NEFilterSourceStatus status, NSData *) {
- m_neFilterSourceStatus = status;
- dispatch_semaphore_signal(neFilterSourceSemaphore);
- }];
</del><ins>+ContentFilterCollection::ContentFilterCollection(Container contentFilters)
+ : m_contentFilters { WTF::move(contentFilters) }
+{
+ ASSERT(!m_contentFilters.isEmpty());
+}
</ins><span class="cx">
</span><del>- // FIXME: We have to block here since DocumentLoader expects to have a
- // blocked/not blocked answer from the filter immediately after calling
- // addData(). We should find a way to make this asynchronous.
- dispatch_semaphore_wait(neFilterSourceSemaphore, DISPATCH_TIME_FOREVER);
- dispatch_release(neFilterSourceSemaphore);
-#endif
</del><ins>+void ContentFilterCollection::addData(const char* data, int length)
+{
+ ASSERT(needsMoreData());
+
+ for (auto& contentFilter : m_contentFilters)
+ contentFilter->addData(data, length);
</ins><span class="cx"> }
</span><span class="cx">
</span><del>-void ContentFilter::finishedAddingData()
</del><ins>+void ContentFilterCollection::finishedAddingData()
</ins><span class="cx"> {
</span><span class="cx"> ASSERT(needsMoreData());
</span><span class="cx">
</span><del>- if (m_platformContentFilter) {
- ASSERT(![m_replacementData.get() length]);
- m_replacementData = [m_platformContentFilter dataComplete];
- }
</del><ins>+ for (auto& contentFilter : m_contentFilters)
+ contentFilter->finishedAddingData();
</ins><span class="cx">
</span><del>-#if HAVE(NE_FILTER_SOURCE)
- if (!m_neFilterSource)
- return;
-
- dispatch_semaphore_t neFilterSourceSemaphore = dispatch_semaphore_create(0);
- [m_neFilterSource dataCompleteWithCompletionQueue:m_neFilterSourceQueue completionHandler:^(NEFilterSourceStatus status, NSData *) {
- m_neFilterSourceStatus = status;
- dispatch_semaphore_signal(neFilterSourceSemaphore);
- }];
-
- // FIXME: We have to block here since DocumentLoader expects to have a
- // blocked/not blocked answer from the filter immediately after calling
- // finishedAddingData(). We should find a way to make this asynchronous.
- dispatch_semaphore_wait(neFilterSourceSemaphore, DISPATCH_TIME_FOREVER);
- dispatch_release(neFilterSourceSemaphore);
-#endif
-
</del><span class="cx"> ASSERT(!needsMoreData());
</span><span class="cx"> }
</span><span class="cx">
</span><del>-bool ContentFilter::needsMoreData() const
</del><ins>+bool ContentFilterCollection::needsMoreData() const
</ins><span class="cx"> {
</span><del>- return [m_platformContentFilter filterState] == kWFEStateBuffering
-#if HAVE(NE_FILTER_SOURCE)
- || (m_neFilterSource && m_neFilterSourceStatus == NEFilterSourceStatusNeedsMoreData)
-#endif
- ;
</del><ins>+ for (auto& contentFilter : m_contentFilters) {
+ if (contentFilter->needsMoreData())
+ return true;
+ }
+
+ return false;
</ins><span class="cx"> }
</span><span class="cx">
</span><del>-bool ContentFilter::didBlockData() const
</del><ins>+bool ContentFilterCollection::didBlockData() const
</ins><span class="cx"> {
</span><del>- return [m_platformContentFilter wasBlocked]
-#if HAVE(NE_FILTER_SOURCE)
- || (m_neFilterSource && m_neFilterSourceStatus == NEFilterSourceStatusBlock)
-#endif
- ;
</del><ins>+ for (auto& contentFilter : m_contentFilters) {
+ if (contentFilter->didBlockData())
+ return true;
+ }
+
+ return false;
</ins><span class="cx"> }
</span><span class="cx">
</span><del>-const char* ContentFilter::getReplacementData(int& length) const
</del><ins>+const char* ContentFilterCollection::getReplacementData(int& length) const
</ins><span class="cx"> {
</span><span class="cx"> ASSERT(!needsMoreData());
</span><span class="cx">
</span><del>- if (didBlockData()) {
- length = [m_replacementData length];
- return static_cast<const char*>([m_replacementData bytes]);
</del><ins>+ for (auto& contentFilter : m_contentFilters) {
+ if (contentFilter->didBlockData())
+ return contentFilter->getReplacementData(length);
</ins><span class="cx"> }
</span><span class="cx">
</span><del>- NSData *originalData = m_replacementData.get();
-#if HAVE(NE_FILTER_SOURCE)
- if (!originalData)
- originalData = m_originalData.get();
-#endif
-
- length = [originalData length];
- return static_cast<const char*>([originalData bytes]);
</del><ins>+ return m_contentFilters[0]->getReplacementData(length);
</ins><span class="cx"> }
</span><span class="cx">
</span><del>-ContentFilterUnblockHandler ContentFilter::unblockHandler() const
</del><ins>+ContentFilterUnblockHandler ContentFilterCollection::unblockHandler() const
</ins><span class="cx"> {
</span><del>- return ContentFilterUnblockHandler { m_platformContentFilter.get() };
</del><ins>+ ASSERT(didBlockData());
+
+ for (auto& contentFilter : m_contentFilters) {
+ if (contentFilter->didBlockData())
+ return contentFilter->unblockHandler();
+ }
+
+ ASSERT_NOT_REACHED();
+ return { };
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> } // namespace WebCore
</span></span></pre>
</div>
</div>
</body>
</html>