Title: [291499] trunk
Revision
291499
Author
pvol...@apple.com
Date
2022-03-18 15:12:12 -0700 (Fri, 18 Mar 2022)

Log Message

Fix test failures when enabling content filtering in the Network process
https://bugs.webkit.org/show_bug.cgi?id=237217

Reviewed by Brent Fulgham.

Source/WebCore:

This patch addresses test failures when enabling content filtering in the Network process.
When content filtering is running in the Network process, we need to send the mock content
filter and settings to the Network process to support testing. The mock content filter is
moved from the WebCore test support library target to the WebCore framework, since WebKit
now also will reference the mock content filter when sending it to the Network process.
Previously a compile time guard was used to disable the content filtering code in the
document loader. However, we still need to support content filtering in the document
loader for WK1, so this patch changes that to use a runtime check instead. The rest of
this patch addresses test failures seen when running the layout and API tests. This patch
does not enable the feature.

No new tests, covered by existing tests.

* WebCore.xcodeproj/project.pbxproj:
* loader/ContentFilter.cpp:
(WebCore::ContentFilter::startFilteringMainResource):
(WebCore::ContentFilter::continueAfterDataReceived):
(WebCore::ContentFilter::continueAfterNotifyFinished):
(WebCore::ContentFilter::deliverResourceData):
(WebCore::ContentFilter::url):
(WebCore::ContentFilter::continueAfterSubstituteDataRequest):
* loader/ContentFilter.h:
(WebCore::ContentFilter::setBlockedError):
* loader/ContentFilterClient.h:
* loader/DocumentLoader.cpp:
(WebCore::contentFilterInDocumentLoader):
(WebCore::DocumentLoader::notifyFinished):
(WebCore::DocumentLoader::willSendRequest):
(WebCore::DocumentLoader::responseReceived):
(WebCore::DocumentLoader::dataReceived):
(WebCore::DocumentLoader::detachFromFrame):
(WebCore::DocumentLoader::startLoadingMainResource):
(WebCore::DocumentLoader::clearMainResource):
(WebCore::DocumentLoader::becomeMainResourceClient):
(WebCore::DocumentLoader::dataReceivedThroughContentFilter):
(WebCore::DocumentLoader::contentFilterWillHandleProvisionalLoadFailure):
(WebCore::DocumentLoader::contentFilterHandleProvisionalLoadFailure):
* loader/DocumentLoader.h:
(WebCore::DocumentLoader::setBlockedPageURL):
(WebCore::DocumentLoader::setSubstituteDataFromContentFilter):
* loader/PolicyChecker.cpp:
(WebCore::FrameLoader::PolicyChecker::checkNavigationPolicy):
* platform/ContentFilterUnblockHandler.h:
* platform/cocoa/ContentFilterUnblockHandlerCocoa.mm:
(WebCore::ContentFilterUnblockHandler::encode const):
(WebCore::ContentFilterUnblockHandler::decode):
(WebCore::ContentFilterUnblockHandler::canHandleRequest const):
(WebCore::ContentFilterUnblockHandler::requestUnblockAsync const):
(WebCore::ContentFilterUnblockHandler::setUnblockedAfterRequest):
* testing/MockContentFilterManager.cpp: Added.
(WebCore::MockContentFilterManager::singleton):
(WebCore::MockContentFilterManager::setClient):
(WebCore::MockContentFilterManager::notifySettingsChanged const):
* testing/MockContentFilterManager.h: Added.
* testing/MockContentFilterSettings.cpp:
(WebCore::MockContentFilterSettings::reset):
(WebCore::MockContentFilterSettings::setEnabled):
(WebCore::MockContentFilterSettings::setBlockedString):
(WebCore::MockContentFilterSettings::setDecisionPoint):
(WebCore::MockContentFilterSettings::setDecision):
(WebCore::MockContentFilterSettings::setUnblockRequestDecision):
(WebCore::MockContentFilterSettings::setModifiedRequestURL):
* testing/MockContentFilterSettings.h:
(WebCore::MockContentFilterSettings::encode const):
(WebCore::MockContentFilterSettings::decode):
(WebCore::MockContentFilterSettings::setBlockedString): Deleted.
(WebCore::MockContentFilterSettings::setDecisionPoint): Deleted.
(WebCore::MockContentFilterSettings::setDecision): Deleted.
(WebCore::MockContentFilterSettings::setUnblockRequestDecision): Deleted.
(WebCore::MockContentFilterSettings::setModifiedRequestURL): Deleted.
* testing/MockContentFilterSettingsClient.h: Added.
(WebCore::MockContentFilterSettingsClient::~MockContentFilterSettingsClient):

Source/WebKit:

Add a WebMockContentFilterManager in the WebContent process, which will be notified
when mock content filter settings are changed from _javascript_, and then send the new
settings to the Network process and install the mock content filter. The other
changes are addressing layout and API test failures.

* NetworkProcess/NetworkConnectionToWebProcess.cpp:
(WebKit::NetworkConnectionToWebProcess::installMockContentFilter):
* NetworkProcess/NetworkConnectionToWebProcess.h:
* NetworkProcess/NetworkConnectionToWebProcess.messages.in:
* NetworkProcess/NetworkResourceLoader.cpp:
(WebKit::NetworkResourceLoader::start):
(WebKit::NetworkResourceLoader::startContentFiltering):
(WebKit::NetworkResourceLoader::didFinishLoading):
(WebKit::NetworkResourceLoader::willSendRedirectedRequestInternal):
(WebKit::NetworkResourceLoader::contentFilterDidBlock):
(WebKit::NetworkResourceLoader::cancelMainResourceLoadForContentFilter):
(WebKit::NetworkResourceLoader::handleProvisionalLoadFailureFromContentFilter):
* NetworkProcess/NetworkResourceLoader.h:
* Shared/WebCoreArgumentCoders.h:
* WebKit.xcodeproj/project.pbxproj:
* WebProcess/Network/WebMockContentFilterManager.cpp: Added.
(WebKit::WebMockContentFilterManager::singleton):
(WebKit::WebMockContentFilterManager::startObservingSettings):
(WebKit::WebMockContentFilterManager::mockContentFilterSettingsChanged):
* WebProcess/Network/WebMockContentFilterManager.h: Added.
* WebProcess/Network/WebResourceLoader.cpp:
(WebKit::WebResourceLoader::contentFilterDidBlockLoad):
(WebKit::WebResourceLoader::cancelMainResourceLoadForContentFilter):
(WebKit::WebResourceLoader::handleProvisionalLoadFailureFromContentFilter): Deleted.
* WebProcess/Network/WebResourceLoader.h:
* WebProcess/Network/WebResourceLoader.messages.in:
* WebProcess/WebProcess.cpp:

Tools:

TestWebKitAPI needs to link with WebCore now that the mock content filter is compiled into WebCore.
Adjust test expectations, since the content filters are not expected to be loaded in the WebContent
process anymore.

* TestWebKitAPI/Configurations/TestWebKitAPI.xcconfig:
* TestWebKitAPI/Configurations/WebProcessPlugIn.xcconfig:
* TestWebKitAPI/Tests/WebKitCocoa/ContentFiltering.mm:
(TEST):
* TestWebKitAPI/Tests/WebKitCocoa/ContentFilteringPlugIn.mm:
* TestWebKitAPI/Tests/mac/ContentFiltering.mm:

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (291498 => 291499)


--- trunk/Source/WebCore/ChangeLog	2022-03-18 22:09:34 UTC (rev 291498)
+++ trunk/Source/WebCore/ChangeLog	2022-03-18 22:12:12 UTC (rev 291499)
@@ -1,3 +1,83 @@
+2022-03-18  Per Arne Vollan  <pvol...@apple.com>
+
+        Fix test failures when enabling content filtering in the Network process
+        https://bugs.webkit.org/show_bug.cgi?id=237217
+
+        Reviewed by Brent Fulgham.
+
+        This patch addresses test failures when enabling content filtering in the Network process.
+        When content filtering is running in the Network process, we need to send the mock content
+        filter and settings to the Network process to support testing. The mock content filter is
+        moved from the WebCore test support library target to the WebCore framework, since WebKit
+        now also will reference the mock content filter when sending it to the Network process.
+        Previously a compile time guard was used to disable the content filtering code in the
+        document loader. However, we still need to support content filtering in the document
+        loader for WK1, so this patch changes that to use a runtime check instead. The rest of
+        this patch addresses test failures seen when running the layout and API tests. This patch
+        does not enable the feature.
+        
+        No new tests, covered by existing tests.
+
+        * WebCore.xcodeproj/project.pbxproj:
+        * loader/ContentFilter.cpp:
+        (WebCore::ContentFilter::startFilteringMainResource):
+        (WebCore::ContentFilter::continueAfterDataReceived):
+        (WebCore::ContentFilter::continueAfterNotifyFinished):
+        (WebCore::ContentFilter::deliverResourceData):
+        (WebCore::ContentFilter::url):
+        (WebCore::ContentFilter::continueAfterSubstituteDataRequest):
+        * loader/ContentFilter.h:
+        (WebCore::ContentFilter::setBlockedError):
+        * loader/ContentFilterClient.h:
+        * loader/DocumentLoader.cpp:
+        (WebCore::contentFilterInDocumentLoader):
+        (WebCore::DocumentLoader::notifyFinished):
+        (WebCore::DocumentLoader::willSendRequest):
+        (WebCore::DocumentLoader::responseReceived):
+        (WebCore::DocumentLoader::dataReceived):
+        (WebCore::DocumentLoader::detachFromFrame):
+        (WebCore::DocumentLoader::startLoadingMainResource):
+        (WebCore::DocumentLoader::clearMainResource):
+        (WebCore::DocumentLoader::becomeMainResourceClient):
+        (WebCore::DocumentLoader::dataReceivedThroughContentFilter):
+        (WebCore::DocumentLoader::contentFilterWillHandleProvisionalLoadFailure):
+        (WebCore::DocumentLoader::contentFilterHandleProvisionalLoadFailure):
+        * loader/DocumentLoader.h:
+        (WebCore::DocumentLoader::setBlockedPageURL):
+        (WebCore::DocumentLoader::setSubstituteDataFromContentFilter):
+        * loader/PolicyChecker.cpp:
+        (WebCore::FrameLoader::PolicyChecker::checkNavigationPolicy):
+        * platform/ContentFilterUnblockHandler.h:
+        * platform/cocoa/ContentFilterUnblockHandlerCocoa.mm:
+        (WebCore::ContentFilterUnblockHandler::encode const):
+        (WebCore::ContentFilterUnblockHandler::decode):
+        (WebCore::ContentFilterUnblockHandler::canHandleRequest const):
+        (WebCore::ContentFilterUnblockHandler::requestUnblockAsync const):
+        (WebCore::ContentFilterUnblockHandler::setUnblockedAfterRequest):
+        * testing/MockContentFilterManager.cpp: Added.
+        (WebCore::MockContentFilterManager::singleton):
+        (WebCore::MockContentFilterManager::setClient):
+        (WebCore::MockContentFilterManager::notifySettingsChanged const):
+        * testing/MockContentFilterManager.h: Added.
+        * testing/MockContentFilterSettings.cpp:
+        (WebCore::MockContentFilterSettings::reset):
+        (WebCore::MockContentFilterSettings::setEnabled):
+        (WebCore::MockContentFilterSettings::setBlockedString):
+        (WebCore::MockContentFilterSettings::setDecisionPoint):
+        (WebCore::MockContentFilterSettings::setDecision):
+        (WebCore::MockContentFilterSettings::setUnblockRequestDecision):
+        (WebCore::MockContentFilterSettings::setModifiedRequestURL):
+        * testing/MockContentFilterSettings.h:
+        (WebCore::MockContentFilterSettings::encode const):
+        (WebCore::MockContentFilterSettings::decode):
+        (WebCore::MockContentFilterSettings::setBlockedString): Deleted.
+        (WebCore::MockContentFilterSettings::setDecisionPoint): Deleted.
+        (WebCore::MockContentFilterSettings::setDecision): Deleted.
+        (WebCore::MockContentFilterSettings::setUnblockRequestDecision): Deleted.
+        (WebCore::MockContentFilterSettings::setModifiedRequestURL): Deleted.
+        * testing/MockContentFilterSettingsClient.h: Added.
+        (WebCore::MockContentFilterSettingsClient::~MockContentFilterSettingsClient):
+
 2022-03-18  Nikolaos Mouchtaris  <nmouchta...@apple.com>
 
         Allow history swipe in scroller with overscroll-behavior

Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (291498 => 291499)


--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2022-03-18 22:09:34 UTC (rev 291498)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2022-03-18 22:12:12 UTC (rev 291499)
@@ -3413,8 +3413,6 @@
 		A1ADAF7E2360FD3E009CB776 /* PreviewConverterProvider.h in Headers */ = {isa = PBXBuildFile; fileRef = A1ADAF7C2360FD3E009CB776 /* PreviewConverterProvider.h */; };
 		A1AFEDE61F8BFF6D0087013F /* MockPaymentCoordinator.h in Headers */ = {isa = PBXBuildFile; fileRef = A1AFEDE41F8BFF6D0087013F /* MockPaymentCoordinator.h */; };
 		A1AFEDE71F8BFF6D0087013F /* MockPaymentCoordinator.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A1AFEDE51F8BFF6D0087013F /* MockPaymentCoordinator.cpp */; };
-		A1B5B29E1AAA846E008B6042 /* MockContentFilterSettings.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A1B5B29C1AAA846E008B6042 /* MockContentFilterSettings.cpp */; };
-		A1B5B29F1AAA846F008B6042 /* MockContentFilterSettings.h in Headers */ = {isa = PBXBuildFile; fileRef = A1B5B29D1AAA846E008B6042 /* MockContentFilterSettings.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		A1BB859C2159AEA10067E07D /* ApplePayErrorCode.h in Headers */ = {isa = PBXBuildFile; fileRef = A1BB85992159AEA10067E07D /* ApplePayErrorCode.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		A1BB85A32159AF570067E07D /* ApplePayErrorContactField.h in Headers */ = {isa = PBXBuildFile; fileRef = A1BB85A02159AF570067E07D /* ApplePayErrorContactField.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		A1BB85A92159B02C0067E07D /* MockPaymentError.h in Headers */ = {isa = PBXBuildFile; fileRef = A1BB85A62159B02C0067E07D /* MockPaymentError.h */; };
@@ -3422,8 +3420,6 @@
 		A1BB85B32159B1A10067E07D /* JSApplePayErrorContactField.h in Headers */ = {isa = PBXBuildFile; fileRef = A1BB85AF2159B1A00067E07D /* JSApplePayErrorContactField.h */; };
 		A1BB85B82159B3A40067E07D /* JSMockPaymentError.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A1BB85B42159B3890067E07D /* JSMockPaymentError.cpp */; };
 		A1BB85B92159B3AE0067E07D /* JSMockPaymentError.h in Headers */ = {isa = PBXBuildFile; fileRef = A1BB85B52159B38A0067E07D /* JSMockPaymentError.h */; };
-		A1BF6B821AA96C7D00AF4A8A /* MockContentFilter.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A1BF6B801AA96C7D00AF4A8A /* MockContentFilter.cpp */; };
-		A1BF6B831AA96C7D00AF4A8A /* MockContentFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = A1BF6B811AA96C7D00AF4A8A /* MockContentFilter.h */; };
 		A1C1507A1E3F2B3E0032C98C /* PreviewConverter.h in Headers */ = {isa = PBXBuildFile; fileRef = A1C150781E3F2B3E0032C98C /* PreviewConverter.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		A1CBEF641F9F11290028DE7C /* MockPaymentMethod.h in Headers */ = {isa = PBXBuildFile; fileRef = A1CBEF631F9F11290028DE7C /* MockPaymentMethod.h */; };
 		A1CC56671F46147A00A4555B /* JSPaymentAddress.h in Headers */ = {isa = PBXBuildFile; fileRef = A1CC56651F46146800A4555B /* JSPaymentAddress.h */; };
@@ -5300,6 +5296,13 @@
 		E36D702027B72013006531B7 /* EmptyAttachmentElementClient.h in Headers */ = {isa = PBXBuildFile; fileRef = E36D701E27B71F04006531B7 /* EmptyAttachmentElementClient.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		E377FE4D1DADE16500CDD025 /* NodeConstants.h in Headers */ = {isa = PBXBuildFile; fileRef = E3D049931DADC04500718F3C /* NodeConstants.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		E37C86501EB63E3F0087C6CA /* JSDOMPromise.h in Headers */ = {isa = PBXBuildFile; fileRef = E37C864F1EB63E2D0087C6CA /* JSDOMPromise.h */; settings = {ATTRIBUTES = (Private, ); }; };
+		E3952FE527C6AC7F0086F5D9 /* MockContentFilterSettingsClient.h in Headers */ = {isa = PBXBuildFile; fileRef = E3952FE427C6AC7F0086F5D9 /* MockContentFilterSettingsClient.h */; settings = {ATTRIBUTES = (Private, ); }; };
+		E3952FEB27C6DCCF0086F5D9 /* MockContentFilterManager.h in Headers */ = {isa = PBXBuildFile; fileRef = E3952FEA27C6DCCE0086F5D9 /* MockContentFilterManager.h */; settings = {ATTRIBUTES = (Private, ); }; };
+		E3952FEE27C6DF140086F5D9 /* MockContentFilterManager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E3952FED27C6DF130086F5D9 /* MockContentFilterManager.cpp */; };
+		E3952FF027C7CDAC0086F5D9 /* MockContentFilterSettings.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A1B5B29C1AAA846E008B6042 /* MockContentFilterSettings.cpp */; };
+		E3952FF127C7CDB50086F5D9 /* MockContentFilterSettings.h in Headers */ = {isa = PBXBuildFile; fileRef = A1B5B29D1AAA846E008B6042 /* MockContentFilterSettings.h */; settings = {ATTRIBUTES = (Private, ); }; };
+		E3952FF227C7CFD30086F5D9 /* MockContentFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = A1BF6B811AA96C7D00AF4A8A /* MockContentFilter.h */; settings = {ATTRIBUTES = (Private, ); }; };
+		E3952FF327C7CFDD0086F5D9 /* MockContentFilter.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A1BF6B801AA96C7D00AF4A8A /* MockContentFilter.cpp */; };
 		E39628BF2395728F00658ECD /* DeviceOrientationUpdateProvider.h in Headers */ = {isa = PBXBuildFile; fileRef = E39628BD2395728E00658ECD /* DeviceOrientationUpdateProvider.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		E39628C12395743100658ECD /* MotionManagerClient.h in Headers */ = {isa = PBXBuildFile; fileRef = E39628C02395743000658ECD /* MotionManagerClient.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		E3A776671DC85D2800B690D8 /* DOMJITIDLConvert.h in Headers */ = {isa = PBXBuildFile; fileRef = E3A776651DC85D2200B690D8 /* DOMJITIDLConvert.h */; settings = {ATTRIBUTES = (Private, ); }; };
@@ -17361,6 +17364,9 @@
 		E38838941BAD145F00D62EE3 /* ScriptModuleLoader.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ScriptModuleLoader.cpp; sourceTree = "<group>"; };
 		E38838951BAD145F00D62EE3 /* ScriptModuleLoader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ScriptModuleLoader.h; sourceTree = "<group>"; };
 		E38D06091F8E811900649CF2 /* ModuleFetchParameters.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ModuleFetchParameters.h; sourceTree = "<group>"; };
+		E3952FE427C6AC7F0086F5D9 /* MockContentFilterSettingsClient.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MockContentFilterSettingsClient.h; sourceTree = "<group>"; };
+		E3952FEA27C6DCCE0086F5D9 /* MockContentFilterManager.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MockContentFilterManager.h; sourceTree = "<group>"; };
+		E3952FED27C6DF130086F5D9 /* MockContentFilterManager.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = MockContentFilterManager.cpp; sourceTree = "<group>"; };
 		E39628BD2395728E00658ECD /* DeviceOrientationUpdateProvider.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DeviceOrientationUpdateProvider.h; sourceTree = "<group>"; };
 		E39628C02395743000658ECD /* MotionManagerClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MotionManagerClient.h; sourceTree = "<group>"; };
 		E3975B761EC9AF3900847717 /* JSDocumentFragmentDOMJIT.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSDocumentFragmentDOMJIT.cpp; sourceTree = "<group>"; };
@@ -21162,9 +21168,12 @@
 				CDF4B71F1E03BF6F00E235A2 /* MockCDMFactory.idl */,
 				A1BF6B801AA96C7D00AF4A8A /* MockContentFilter.cpp */,
 				A1BF6B811AA96C7D00AF4A8A /* MockContentFilter.h */,
+				E3952FED27C6DF130086F5D9 /* MockContentFilterManager.cpp */,
+				E3952FEA27C6DCCE0086F5D9 /* MockContentFilterManager.h */,
 				A1B5B29C1AAA846E008B6042 /* MockContentFilterSettings.cpp */,
 				A1B5B29D1AAA846E008B6042 /* MockContentFilterSettings.h */,
 				A19AEA1C1AAA7C4900B52B25 /* MockContentFilterSettings.idl */,
+				E3952FE427C6AC7F0086F5D9 /* MockContentFilterSettingsClient.h */,
 				51058AD71D679257009A538C /* MockGamepad.cpp */,
 				51058AD81D679257009A538C /* MockGamepad.h */,
 				51058AD91D679257009A538C /* MockGamepadProvider.cpp */,
@@ -33414,8 +33423,6 @@
 				427DA71E13735DFA007C57FB /* JSServiceWorkerInternals.h in Headers */,
 				EBF5121D1696496C0056BD25 /* JSTypeConversions.h in Headers */,
 				CDC26B41160A8CCE0026757B /* LegacyMockCDM.h in Headers */,
-				A1BF6B831AA96C7D00AF4A8A /* MockContentFilter.h in Headers */,
-				A1B5B29F1AAA846F008B6042 /* MockContentFilterSettings.h in Headers */,
 				4157EBFB1E3AB67F00AC9FE9 /* MockLibWebRTCPeerConnection.h in Headers */,
 				2D6F3E911C1ECB2F0061DBD4 /* MockPageOverlay.h in Headers */,
 				2D97F04819DD4140001EE9C3 /* MockPageOverlayClient.h in Headers */,
@@ -36400,6 +36407,10 @@
 				CDF2B0111820540600F2B424 /* MockBox.h in Headers */,
 				CDF4B7241E03BF8100E235A2 /* MockCDMFactory.h in Headers */,
 				CDF4B7201E03BF6F00E235A2 /* MockCDMFactory.idl in Headers */,
+				E3952FF227C7CFD30086F5D9 /* MockContentFilter.h in Headers */,
+				E3952FEB27C6DCCF0086F5D9 /* MockContentFilterManager.h in Headers */,
+				E3952FF127C7CDB50086F5D9 /* MockContentFilterSettings.h in Headers */,
+				E3952FE527C6AC7F0086F5D9 /* MockContentFilterSettingsClient.h in Headers */,
 				51058AE01D67C229009A538C /* MockGamepad.h in Headers */,
 				51058AE21D67C229009A538C /* MockGamepadProvider.h in Headers */,
 				413CCD4A20DE034F0065A21A /* MockMediaDevice.h in Headers */,
@@ -38741,8 +38752,6 @@
 				CDC26B40160A8CC60026757B /* LegacyMockCDM.cpp in Sources */,
 				A1E086632489D34E00E496D9 /* MockApplePaySetupFeature.cpp in Sources */,
 				CDF4B7311E03D00700E235A2 /* MockCDMFactory.cpp in Sources */,
-				A1BF6B821AA96C7D00AF4A8A /* MockContentFilter.cpp in Sources */,
-				A1B5B29E1AAA846E008B6042 /* MockContentFilterSettings.cpp in Sources */,
 				51058ADB1D6792C1009A538C /* MockGamepad.cpp in Sources */,
 				51058ADD1D6792C1009A538C /* MockGamepadProvider.cpp in Sources */,
 				4157EBFA1E3AB67900AC9FE9 /* MockLibWebRTCPeerConnection.cpp in Sources */,
@@ -38831,6 +38840,9 @@
 				CDA9593524123CB800910EEF /* MediaSessionHelperIOS.mm in Sources */,
 				07638A9A1884487200E15A1B /* MediaSessionManagerIOS.mm in Sources */,
 				4133CB8B20F80E9900E89B11 /* MediaStreamAudioSourceCocoa.cpp in Sources */,
+				E3952FF327C7CFDD0086F5D9 /* MockContentFilter.cpp in Sources */,
+				E3952FEE27C6DF140086F5D9 /* MockContentFilterManager.cpp in Sources */,
+				E3952FF027C7CDAC0086F5D9 /* MockContentFilterSettings.cpp in Sources */,
 				2D9BF7421DBFDC27007A7D99 /* NavigatorEME.cpp in Sources */,
 				51A4BB101954D62700FA5C2E /* NavigatorGamepad.cpp in Sources */,
 				1A569D130D7E2B82007C3983 /* objc_class.mm in Sources */,

Modified: trunk/Source/WebCore/loader/ContentFilter.cpp (291498 => 291499)


--- trunk/Source/WebCore/loader/ContentFilter.cpp	2022-03-18 22:09:34 UTC (rev 291498)
+++ trunk/Source/WebCore/loader/ContentFilter.cpp	2022-03-18 22:12:12 UTC (rev 291499)
@@ -122,7 +122,8 @@
     ASSERT(m_mainResourceURL.isEmpty());
     m_mainResourceURL = url;
 }
-#else
+#endif
+
 void ContentFilter::startFilteringMainResource(CachedRawResource& resource)
 {
     if (m_state != State::Stopped)
@@ -133,7 +134,6 @@
     ASSERT(!m_mainResource);
     m_mainResource = &resource;
 }
-#endif
 
 void ContentFilter::stopFilteringMainResource()
 {
@@ -164,9 +164,6 @@
 
 #if ENABLE(CONTENT_FILTERING_IN_NETWORKING_PROCESS)
 bool ContentFilter::continueAfterDataReceived(const SharedBuffer& data, size_t encodedDataLength)
-#else
-bool ContentFilter::continueAfterDataReceived(const SharedBuffer& data)
-#endif
 {
     Ref<ContentFilterClient> protectedClient { m_client };
 
@@ -176,19 +173,33 @@
         forEachContentFilterUntilBlocked([data = "" { data }](auto& contentFilter) {
             contentFilter.addData(data);
         });
-#if ENABLE(CONTENT_FILTERING_IN_NETWORKING_PROCESS)
         if (m_state == State::Allowed) {
             deliverStoredResourceData();
             deliverResourceData(data, encodedDataLength);
         } else
             m_buffers.append(ResourceDataItem { RefPtr { &data }, encodedDataLength });
-#else
+        return false;
+    }
+
+    return m_state != State::Blocked;
+}
+#endif
+
+bool ContentFilter::continueAfterDataReceived(const SharedBuffer& data)
+{
+    Ref<ContentFilterClient> protectedClient { m_client };
+
+    if (m_state == State::Filtering) {
+        LOG(ContentFiltering, "ContentFilter received %zu bytes of data from <%{sensitive}s>.\n", data.size(), url().string().ascii().data());
+
+        forEachContentFilterUntilBlocked([data = "" { data }](auto& contentFilter) {
+            contentFilter.addData(data);
+        });
         if (m_state == State::Allowed) {
             ASSERT(m_mainResource->dataBufferingPolicy() == DataBufferingPolicy::BufferData);
             if (auto* buffer = m_mainResource->resourceBuffer())
                 deliverResourceData(buffer->makeContiguous());
         }
-#endif
         return false;
     }
 
@@ -197,18 +208,35 @@
 
 #if ENABLE(CONTENT_FILTERING_IN_NETWORKING_PROCESS)
 bool ContentFilter::continueAfterNotifyFinished(const URL& resourceURL)
-#else
+{
+    Ref<ContentFilterClient> protectedClient { m_client };
+    ASSERT_UNUSED(resourceURL, resourceURL == m_mainResourceURL);
+
+    if (m_state == State::Filtering) {
+        LOG(ContentFiltering, "ContentFilter will finish filtering main resource at <%{sensitive}s>.\n", url().string().ascii().data());
+        forEachContentFilterUntilBlocked([](PlatformContentFilter& contentFilter) {
+            contentFilter.finishedAddingData();
+        });
+
+        if (m_state != State::Blocked) {
+            m_state = State::Allowed;
+            deliverStoredResourceData();
+        }
+
+        if (m_state == State::Stopped)
+            return false;
+    }
+
+    return m_state != State::Blocked;
+}
+#endif
+
 bool ContentFilter::continueAfterNotifyFinished(CachedResource& resource)
-#endif
 {
     Ref<ContentFilterClient> protectedClient { m_client };
-#if ENABLE(CONTENT_FILTERING_IN_NETWORKING_PROCESS)
-    ASSERT_UNUSED(resourceURL, resourceURL == m_mainResourceURL);
-#else
     ASSERT_UNUSED(resource, &resource == m_mainResource);
     if (m_mainResource->errorOccurred())
         return true;
-#endif
 
     if (m_state == State::Filtering) {
         LOG(ContentFiltering, "ContentFilter will finish filtering main resource at <%{sensitive}s>.\n", url().string().ascii().data());
@@ -218,14 +246,10 @@
 
         if (m_state != State::Blocked) {
             m_state = State::Allowed;
-#if ENABLE(CONTENT_FILTERING_IN_NETWORKING_PROCESS)
-            deliverStoredResourceData();
-#else
             if (auto* buffer = m_mainResource->resourceBuffer()) {
                 ASSERT(m_mainResource->dataBufferingPolicy() == DataBufferingPolicy::BufferData);
                 deliverResourceData(buffer->makeContiguous());
             }
-#endif
         }
 
         if (m_state == State::Stopped)
@@ -279,21 +303,16 @@
 void ContentFilter::deliverResourceData(const SharedBuffer& buffer, size_t encodedDataLength)
 {
     ASSERT(m_state == State::Allowed);
-#if ENABLE(CONTENT_FILTERING_IN_NETWORKING_PROCESS)
     m_client.dataReceivedThroughContentFilter(buffer, encodedDataLength);
-#else
-    UNUSED_PARAM(encodedDataLength);
-    m_client.dataReceivedThroughContentFilter(buffer);
-#endif
 }
 
 URL ContentFilter::url()
 {
+    if (m_mainResource)
+        return m_mainResource->url();
 #if ENABLE(CONTENT_FILTERING_IN_NETWORKING_PROCESS)
     return m_mainResourceURL;
 #else
-    if (m_mainResource)
-        return m_mainResource->url();
     return URL();
 #endif
 }
@@ -307,7 +326,6 @@
     return blockedPageURL;
 }
 
-#if !ENABLE(CONTENT_FILTERING_IN_NETWORKING_PROCESS)
 bool ContentFilter::continueAfterSubstituteDataRequest(const DocumentLoader& activeLoader, const SubstituteData& substituteData)
 {
     if (auto contentFilter = activeLoader.contentFilter()) {
@@ -322,7 +340,6 @@
 
     return true;
 }
-#endif
 
 bool ContentFilter::willHandleProvisionalLoadFailure(const ResourceError& error) const
 {

Modified: trunk/Source/WebCore/loader/ContentFilter.h (291498 => 291499)


--- trunk/Source/WebCore/loader/ContentFilter.h	2022-03-18 22:09:34 UTC (rev 291498)
+++ trunk/Source/WebCore/loader/ContentFilter.h	2022-03-18 22:12:12 UTC (rev 291499)
@@ -57,9 +57,8 @@
 
 #if ENABLE(CONTENT_FILTERING_IN_NETWORKING_PROCESS)
     WEBCORE_EXPORT void startFilteringMainResource(const URL&);
-#else
+#endif
     void startFilteringMainResource(CachedRawResource&);
-#endif
     WEBCORE_EXPORT void stopFilteringMainResource();
 
     WEBCORE_EXPORT bool continueAfterWillSendRequest(ResourceRequest&, const ResourceResponse&);
@@ -67,10 +66,9 @@
 #if ENABLE(CONTENT_FILTERING_IN_NETWORKING_PROCESS)
     WEBCORE_EXPORT bool continueAfterDataReceived(const SharedBuffer&, size_t encodedDataLength);
     WEBCORE_EXPORT bool continueAfterNotifyFinished(const URL& resourceURL);
-#else
+#endif
     bool continueAfterDataReceived(const SharedBuffer&);
     bool continueAfterNotifyFinished(CachedResource&);
-#endif
 
     static bool continueAfterSubstituteDataRequest(const DocumentLoader& activeLoader, const SubstituteData&);
     bool willHandleProvisionalLoadFailure(const ResourceError&) const;
@@ -77,6 +75,7 @@
     WEBCORE_EXPORT void handleProvisionalLoadFailure(const ResourceError&);
 
     const ResourceError& blockedError() const { return m_blockedError; }
+    void setBlockedError(const ResourceError& error) { m_blockedError = error; }
     bool isAllowed() const { return m_state == State::Allowed; }
     bool responseReceived() const { return m_responseReceived; }
     
@@ -112,9 +111,8 @@
     };
     
     Vector<ResourceDataItem> m_buffers;
-#else
+#endif
     CachedResourceHandle<CachedRawResource> m_mainResource;
-#endif
     const PlatformContentFilter* m_blockingContentFilter { nullptr };
     State m_state { State::Stopped };
     ResourceError m_blockedError;

Modified: trunk/Source/WebCore/loader/ContentFilterClient.h (291498 => 291499)


--- trunk/Source/WebCore/loader/ContentFilterClient.h	2022-03-18 22:09:34 UTC (rev 291498)
+++ trunk/Source/WebCore/loader/ContentFilterClient.h	2022-03-18 22:12:12 UTC (rev 291499)
@@ -42,11 +42,7 @@
     virtual void ref() const = 0;
     virtual void deref() const = 0;
 
-#if ENABLE(CONTENT_FILTERING_IN_NETWORKING_PROCESS)
     virtual void dataReceivedThroughContentFilter(const SharedBuffer&, size_t) = 0;
-#else
-    virtual void dataReceivedThroughContentFilter(const SharedBuffer&) = 0;
-#endif
     virtual ResourceError contentFilterDidBlock(ContentFilterUnblockHandler, String&& unblockRequestDeniedScript) = 0;
     virtual void cancelMainResourceLoadForContentFilter(const ResourceError&) = 0;
     virtual void handleProvisionalLoadFailureFromContentFilter(const URL& blockedPageURL, SubstituteData&) = 0;

Modified: trunk/Source/WebCore/loader/DocumentLoader.cpp (291498 => 291499)


--- trunk/Source/WebCore/loader/DocumentLoader.cpp	2022-03-18 22:09:34 UTC (rev 291498)
+++ trunk/Source/WebCore/loader/DocumentLoader.cpp	2022-03-18 22:12:12 UTC (rev 291499)
@@ -138,6 +138,15 @@
 
 namespace WebCore {
 
+#if ENABLE(CONTENT_FILTERING)
+static bool& contentFilterInDocumentLoader()
+{
+    static bool filter = false;
+    RELEASE_ASSERT(isMainThread());
+    return filter;
+}
+#endif
+
 static void cancelAll(const ResourceLoaderMap& loaders)
 {
     for (auto& loader : copyToVector(loaders.values()))
@@ -419,7 +428,7 @@
 void DocumentLoader::notifyFinished(CachedResource& resource, const NetworkLoadMetrics& metrics)
 {
     ASSERT(isMainThread());
-#if ENABLE(CONTENT_FILTERING) && !ENABLE(CONTENT_FILTERING_IN_NETWORKING_PROCESS)
+#if ENABLE(CONTENT_FILTERING)
     if (m_contentFilter && !m_contentFilter->continueAfterNotifyFinished(resource))
         return;
 #endif
@@ -710,7 +719,7 @@
         newRequest.setURL(WTFMove(url));
     }
 
-#if ENABLE(CONTENT_FILTERING) && !ENABLE(CONTENT_FILTERING_IN_NETWORKING_PROCESS)
+#if ENABLE(CONTENT_FILTERING)
     if (m_contentFilter && !m_contentFilter->continueAfterWillSendRequest(newRequest, redirectResponse))
         return completionHandler(WTFMove(newRequest));
 #endif
@@ -902,7 +911,7 @@
     ASSERT(response.certificateInfo());
     CompletionHandlerCallingScope completionHandlerCaller(WTFMove(completionHandler));
 
-#if ENABLE(CONTENT_FILTERING) && !ENABLE(CONTENT_FILTERING_IN_NETWORKING_PROCESS)
+#if ENABLE(CONTENT_FILTERING)
     if (m_contentFilter && !m_contentFilter->continueAfterResponseReceived(response))
         return;
 #endif
@@ -1322,7 +1331,7 @@
 
 void DocumentLoader::dataReceived(const SharedBuffer& buffer)
 {
-#if ENABLE(CONTENT_FILTERING) && !ENABLE(CONTENT_FILTERING_IN_NETWORKING_PROCESS)
+#if ENABLE(CONTENT_FILTERING)
     if (m_contentFilter && !m_contentFilter->continueAfterDataReceived(buffer))
         return;
 #endif
@@ -1463,7 +1472,7 @@
     stopLoading();
     if (m_mainResource && m_mainResource->hasClient(*this))
         m_mainResource->removeClient(*this);
-#if ENABLE(CONTENT_FILTERING) && !ENABLE(CONTENT_FILTERING_IN_NETWORKING_PROCESS)
+#if ENABLE(CONTENT_FILTERING)
     if (m_contentFilter)
         m_contentFilter->stopFilteringMainResource();
 #endif
@@ -2025,10 +2034,17 @@
         return;
     }
 
-#if ENABLE(CONTENT_FILTERING) && !ENABLE(CONTENT_FILTERING_IN_NETWORKING_PROCESS)
-    m_contentFilter = !m_substituteData.isValid() ? ContentFilter::create(*this) : nullptr;
+#if ENABLE(CONTENT_FILTERING)
+    contentFilterInDocumentLoader() = true;
+#if ENABLE(CONTENT_FILTERING_IN_NETWORKING_PROCESS)
+    // Always filter in WK1
+    contentFilterInDocumentLoader() = m_frame && m_frame->view() && m_frame->view()->platformWidget();
 #endif
-
+    if (contentFilterInDocumentLoader())
+        m_contentFilter = !m_substituteData.isValid() ? ContentFilter::create(*this) : nullptr;
+#endif
+    
+    
     // Make sure we re-apply the user agent to the Document's ResourceRequest upon reload in case the embedding
     // application has changed it, by clearing the previous user agent value here and applying the new value in CachedResourceLoader.
     m_request.clearHTTPUserAgent();
@@ -2230,7 +2246,7 @@
     ASSERT(isMainThread());
     if (m_mainResource && m_mainResource->hasClient(*this))
         m_mainResource->removeClient(*this);
-#if ENABLE(CONTENT_FILTERING) && !ENABLE(CONTENT_FILTERING_IN_NETWORKING_PROCESS)
+#if ENABLE(CONTENT_FILTERING)
     if (m_contentFilter)
         m_contentFilter->stopFilteringMainResource();
 #endif
@@ -2357,7 +2373,7 @@
 
 void DocumentLoader::becomeMainResourceClient()
 {
-#if ENABLE(CONTENT_FILTERING) && !ENABLE(CONTENT_FILTERING_IN_NETWORKING_PROCESS)
+#if ENABLE(CONTENT_FILTERING)
     if (m_contentFilter)
         m_contentFilter->startFilteringMainResource(*m_mainResource);
 #endif
@@ -2414,8 +2430,8 @@
     m_frame->document()->enqueueSecurityPolicyViolationEvent(WTFMove(eventInit));
 }
 
-#if ENABLE(CONTENT_FILTERING) && !ENABLE(CONTENT_FILTERING_IN_NETWORKING_PROCESS)
-void DocumentLoader::dataReceivedThroughContentFilter(const SharedBuffer& buffer)
+#if ENABLE(CONTENT_FILTERING)
+void DocumentLoader::dataReceivedThroughContentFilter(const SharedBuffer& buffer, size_t)
 {
     dataReceived(buffer);
 }
@@ -2434,7 +2450,7 @@
 {
     frameLoader()->load(FrameLoadRequest(*frame(), blockedPageURL, substituteData));
 }
-#endif // ENABLE(CONTENT_FILTERING) && !ENABLE(CONTENT_FILTERING_IN_NETWORKING_PROCESS)
+#endif // ENABLE(CONTENT_FILTERING)
 
 #if ENABLE(CONTENT_FILTERING)
 ResourceError DocumentLoader::handleContentFilterDidBlock(ContentFilterUnblockHandler unblockHandler, String&& unblockRequestDeniedScript)
@@ -2457,27 +2473,27 @@
     return error;
 }
 
-void DocumentLoader::handleContentFilterProvisionalLoadFailure(const URL& blockedPageURL, const SubstituteData& substituteData)
-{
-    frameLoader()->load(FrameLoadRequest(*frame(), blockedPageURL, substituteData));
-}
-
 bool DocumentLoader::contentFilterWillHandleProvisionalLoadFailure(const ResourceError& error)
 {
+    if (m_contentFilter && m_contentFilter->willHandleProvisionalLoadFailure(error))
+        return true;
+    if (contentFilterInDocumentLoader())
+        return false;
 #if ENABLE(CONTENT_FILTERING_IN_NETWORKING_PROCESS)
     return m_blockedByContentFilter && m_blockedError.errorCode() == error.errorCode() && m_blockedError.domain() == error.domain();
 #else
-    return m_contentFilter && m_contentFilter->willHandleProvisionalLoadFailure(error);
+    return false;
 #endif
 }
 
 void DocumentLoader::contentFilterHandleProvisionalLoadFailure(const ResourceError& error)
 {
-#if ENABLE(CONTENT_FILTERING_IN_NETWORKING_PROCESS)
-    UNUSED_PARAM(error);
-#else
     if (m_contentFilter)
         m_contentFilter->handleProvisionalLoadFailure(error);
+    if (contentFilterInDocumentLoader())
+        return;
+#if ENABLE(CONTENT_FILTERING_IN_NETWORKING_PROCESS)
+    handleProvisionalLoadFailureFromContentFilter(m_blockedPageURL, m_substituteDataFromContentFilter);
 #endif
 }
 

Modified: trunk/Source/WebCore/loader/DocumentLoader.h (291498 => 291499)


--- trunk/Source/WebCore/loader/DocumentLoader.h	2022-03-18 22:09:34 UTC (rev 291498)
+++ trunk/Source/WebCore/loader/DocumentLoader.h	2022-03-18 22:12:12 UTC (rev 291499)
@@ -159,7 +159,7 @@
     : public RefCounted<DocumentLoader>
     , public FrameDestructionObserver
     , public ContentSecurityPolicyClient
-#if ENABLE(CONTENT_FILTERING) && !ENABLE(CONTENT_FILTERING_IN_NETWORKING_PROCESS)
+#if ENABLE(CONTENT_FILTERING)
     , public ContentFilterClient
 #endif
     , private CachedRawResourceClient {
@@ -402,13 +402,15 @@
     ShouldOpenExternalURLsPolicy shouldOpenExternalURLsPolicyToPropagate() const;
 
 #if ENABLE(CONTENT_FILTERING)
-#if !ENABLE(CONTENT_FILTERING_IN_NETWORKING_PROCESS)
+#if ENABLE(CONTENT_FILTERING_IN_NETWORKING_PROCESS)
+    void setBlockedPageURL(const URL& blockedPageURL) { m_blockedPageURL = blockedPageURL; }
+    void setSubstituteDataFromContentFilter(SubstituteData&& substituteDataFromContentFilter) { m_substituteDataFromContentFilter = WTFMove(substituteDataFromContentFilter); }
+#endif // ENABLE(CONTENT_FILTERING_IN_NETWORKING_PROCESS)
     ContentFilter* contentFilter() const { return m_contentFilter.get(); }
     void ref() const final { RefCounted<DocumentLoader>::ref(); }
     void deref() const final { RefCounted<DocumentLoader>::deref(); }
-#endif
+
     WEBCORE_EXPORT ResourceError handleContentFilterDidBlock(ContentFilterUnblockHandler, String&& unblockRequestDeniedScript);
-    WEBCORE_EXPORT void handleContentFilterProvisionalLoadFailure(const URL& blockedPageURL, const SubstituteData&);
 #endif
 
     void startIconLoading();
@@ -512,9 +514,9 @@
 
     void responseReceived(const ResourceResponse&, CompletionHandler<void()>&&);
 
-#if ENABLE(CONTENT_FILTERING) && !ENABLE(CONTENT_FILTERING_IN_NETWORKING_PROCESS)
+#if ENABLE(CONTENT_FILTERING)
     // ContentFilterClient
-    WEBCORE_EXPORT void dataReceivedThroughContentFilter(const SharedBuffer&) final;
+    WEBCORE_EXPORT void dataReceivedThroughContentFilter(const SharedBuffer&, size_t) final;
     WEBCORE_EXPORT ResourceError contentFilterDidBlock(ContentFilterUnblockHandler, String&& unblockRequestDeniedScript) final;
     WEBCORE_EXPORT void cancelMainResourceLoadForContentFilter(const ResourceError&) final;
     WEBCORE_EXPORT void handleProvisionalLoadFailureFromContentFilter(const URL& blockedPageURL, SubstituteData&) final;
@@ -664,13 +666,14 @@
     std::unique_ptr<ContentSecurityPolicy> m_contentSecurityPolicy;
 
 #if ENABLE(CONTENT_FILTERING)
-#if !ENABLE(CONTENT_FILTERING_IN_NETWORKING_PROCESS)
     std::unique_ptr<ContentFilter> m_contentFilter;
-#else
+#if ENABLE(CONTENT_FILTERING_IN_NETWORKING_PROCESS)
     bool m_blockedByContentFilter { false };
     ResourceError m_blockedError;
-#endif
-#endif
+    URL m_blockedPageURL;
+    SubstituteData m_substituteDataFromContentFilter;
+#endif // ENABLE(CONTENT_FILTERING_IN_NETWORKING_PROCESS)
+#endif // ENABLE(CONTENT_FILTERING)
 
 #if USE(QUICK_LOOK)
     RefPtr<PreviewConverter> m_previewConverter;

Modified: trunk/Source/WebCore/loader/PolicyChecker.cpp (291498 => 291499)


--- trunk/Source/WebCore/loader/PolicyChecker.cpp	2022-03-18 22:09:34 UTC (rev 291498)
+++ trunk/Source/WebCore/loader/PolicyChecker.cpp	2022-03-18 22:12:12 UTC (rev 291499)
@@ -141,7 +141,7 @@
     auto& substituteData = loader->substituteData();
     if (substituteData.isValid() && !substituteData.failingURL().isEmpty()) {
         bool shouldContinue = true;
-#if ENABLE(CONTENT_FILTERING) && !ENABLE(CONTENT_FILTERING_IN_NETWORKING_PROCESS)
+#if ENABLE(CONTENT_FILTERING)
         if (auto loader = m_frame.loader().activeDocumentLoader())
             shouldContinue = ContentFilter::continueAfterSubstituteDataRequest(*loader, substituteData);
 #endif

Modified: trunk/Source/WebCore/platform/ContentFilterUnblockHandler.h (291498 => 291499)


--- trunk/Source/WebCore/platform/ContentFilterUnblockHandler.h	2022-03-18 22:09:34 UTC (rev 291498)
+++ trunk/Source/WebCore/platform/ContentFilterUnblockHandler.h	2022-03-18 22:12:12 UTC (rev 291499)
@@ -33,6 +33,7 @@
 #include <wtf/text/WTFString.h>
 
 OBJC_CLASS NSCoder;
+OBJC_CLASS NSNumber;
 
 #if PLATFORM(IOS_FAMILY)
 OBJC_CLASS WebFilterEvaluator;
@@ -64,6 +65,10 @@
     const URL& unreachableURL() const { return m_unreachableURL; }
     void setUnreachableURL(const URL& url) { m_unreachableURL = url; }
 
+#if ENABLE(CONTENT_FILTERING_IN_NETWORKING_PROCESS)
+    WEBCORE_EXPORT void setUnblockedAfterRequest(bool);
+#endif
+
 private:
     String m_unblockURLHost;
     URL m_unreachableURL;
@@ -71,6 +76,9 @@
 #if HAVE(PARENTAL_CONTROLS_WITH_UNBLOCK_HANDLER)
     RetainPtr<WebFilterEvaluator> m_webFilterEvaluator;
 #endif
+#if ENABLE(CONTENT_FILTERING_IN_NETWORKING_PROCESS)
+    NSNumber* m_unblockedAfterRequest { nil };
+#endif
 };
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/platform/cocoa/ContentFilterUnblockHandlerCocoa.mm (291498 => 291499)


--- trunk/Source/WebCore/platform/cocoa/ContentFilterUnblockHandlerCocoa.mm	2022-03-18 22:09:34 UTC (rev 291498)
+++ trunk/Source/WebCore/platform/cocoa/ContentFilterUnblockHandlerCocoa.mm	2022-03-18 22:12:12 UTC (rev 291499)
@@ -42,6 +42,9 @@
 
 static NSString * const unblockURLHostKey { @"unblockURLHost" };
 static NSString * const unreachableURLKey { @"unreachableURL" };
+#if ENABLE(CONTENT_FILTERING_IN_NETWORKING_PROCESS)
+static NSString * const unblockedAfterRequestKey { @"unblockedAfterRequest" };
+#endif
 
 #if HAVE(PARENTAL_CONTROLS_WITH_UNBLOCK_HANDLER)
 static NSString * const webFilterEvaluatorKey { @"webFilterEvaluator" };
@@ -101,6 +104,10 @@
 #if HAVE(PARENTAL_CONTROLS_WITH_UNBLOCK_HANDLER)
     [coder encodeObject:m_webFilterEvaluator.get() forKey:webFilterEvaluatorKey];
 #endif
+#if ENABLE(CONTENT_FILTERING_IN_NETWORKING_PROCESS)
+    [coder encodeObject:m_unblockedAfterRequest forKey:unblockedAfterRequestKey];
+#endif
+
     END_BLOCK_OBJC_EXCEPTIONS
 }
 
@@ -113,6 +120,9 @@
 #if HAVE(PARENTAL_CONTROLS_WITH_UNBLOCK_HANDLER)
     unblockHandler.m_webFilterEvaluator = [coder decodeObjectOfClass:getWebFilterEvaluatorClass() forKey:webFilterEvaluatorKey];
 #endif
+#if ENABLE(CONTENT_FILTERING_IN_NETWORKING_PROCESS)
+    unblockHandler.m_unblockedAfterRequest = [coder decodeObjectOfClass:[NSNumber class] forKey:unblockedAfterRequestKey];
+#endif
     return true;
     END_BLOCK_OBJC_EXCEPTIONS
     return false;
@@ -120,7 +130,11 @@
 
 bool ContentFilterUnblockHandler::canHandleRequest(const ResourceRequest& request) const
 {
-    if (!m_unblockRequester) {
+    if (!m_unblockRequester
+#if ENABLE(CONTENT_FILTERING_IN_NETWORKING_PROCESS)
+        && !m_unblockedAfterRequest
+#endif
+        ) {
 #if HAVE(PARENTAL_CONTROLS_WITH_UNBLOCK_HANDLER)
         if (!m_webFilterEvaluator)
             return false;
@@ -150,9 +164,16 @@
         return;
     }
 #endif
-
-    if (m_unblockRequester) {
-        m_unblockRequester([decisionHandler](bool unblocked) {
+    auto unblockRequester = m_unblockRequester;
+#if ENABLE(CONTENT_FILTERING_IN_NETWORKING_PROCESS)
+    if (!unblockRequester && m_unblockedAfterRequest) {
+        unblockRequester = [unblocked = m_unblockedAfterRequest.boolValue](ContentFilterUnblockHandler::DecisionHandlerFunction function) {
+            function(unblocked);
+        };
+    }
+#endif
+    if (unblockRequester) {
+        unblockRequester([decisionHandler](bool unblocked) {
             callOnMainThread([decisionHandler, unblocked] {
                 decisionHandler(unblocked);
             });
@@ -160,6 +181,13 @@
     }
 }
 
+#if ENABLE(CONTENT_FILTERING_IN_NETWORKING_PROCESS)
+void ContentFilterUnblockHandler::setUnblockedAfterRequest(bool unblocked)
+{
+    m_unblockedAfterRequest = [NSNumber numberWithBool:unblocked];
+}
+#endif
+
 } // namespace WebCore
 
 #endif // ENABLE(CONTENT_FILTERING)

Copied: trunk/Source/WebCore/testing/MockContentFilterManager.cpp (from rev 291498, trunk/Source/WebCore/testing/MockContentFilterSettings.cpp) (0 => 291499)


--- trunk/Source/WebCore/testing/MockContentFilterManager.cpp	                        (rev 0)
+++ trunk/Source/WebCore/testing/MockContentFilterManager.cpp	2022-03-18 22:12:12 UTC (rev 291499)
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2022 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "MockContentFilterManager.h"
+
+namespace WebCore {
+
+MockContentFilterManager& MockContentFilterManager::singleton()
+{
+    static NeverDestroyed<MockContentFilterManager> manager;
+    return manager.get();
+}
+
+void MockContentFilterManager::setClient(RefPtr<MockContentFilterSettingsClient> client)
+{
+    m_client = client;
+}
+    
+void MockContentFilterManager::notifySettingsChanged(WebCore::MockContentFilterSettings& settings) const
+{
+    if (m_client)
+        m_client->mockContentFilterSettingsChanged(settings);
+}
+
+};

Copied: trunk/Source/WebCore/testing/MockContentFilterManager.h (from rev 291498, trunk/Source/WebCore/testing/MockContentFilterSettings.cpp) (0 => 291499)


--- trunk/Source/WebCore/testing/MockContentFilterManager.h	                        (rev 0)
+++ trunk/Source/WebCore/testing/MockContentFilterManager.h	2022-03-18 22:12:12 UTC (rev 291499)
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2022 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.
+ */
+
+#pragma once
+
+#include <WebCore/MockContentFilterSettingsClient.h>
+
+namespace WebCore {
+
+class MockContentFilterManager {
+public:
+    WEBCORE_TESTSUPPORT_EXPORT static MockContentFilterManager& singleton();
+
+    WEBCORE_TESTSUPPORT_EXPORT void setClient(RefPtr<MockContentFilterSettingsClient>);
+    
+    WEBCORE_TESTSUPPORT_EXPORT void notifySettingsChanged(WebCore::MockContentFilterSettings&) const;
+
+private:
+    RefPtr<MockContentFilterSettingsClient> m_client;
+};
+
+};

Modified: trunk/Source/WebCore/testing/MockContentFilterSettings.cpp (291498 => 291499)


--- trunk/Source/WebCore/testing/MockContentFilterSettings.cpp	2022-03-18 22:09:34 UTC (rev 291498)
+++ trunk/Source/WebCore/testing/MockContentFilterSettings.cpp	2022-03-18 22:12:12 UTC (rev 291499)
@@ -31,6 +31,7 @@
 #include "ContentFilter.h"
 #include "ContentFilterUnblockHandler.h"
 #include "MockContentFilter.h"
+#include "MockContentFilterManager.h"
 #include <wtf/NeverDestroyed.h>
 
 namespace WebCore {
@@ -44,6 +45,7 @@
 void MockContentFilterSettings::reset()
 {
     singleton() = MockContentFilterSettings();
+    MockContentFilterManager::singleton().notifySettingsChanged(singleton());
 }
 
 void MockContentFilterSettings::setEnabled(bool enabled)
@@ -50,8 +52,39 @@
 {
     MockContentFilter::ensureInstalled();
     m_enabled = enabled;
+    MockContentFilterManager::singleton().notifySettingsChanged(singleton());
 }
 
+void MockContentFilterSettings::setBlockedString(const String& blockedString)
+{
+    m_blockedString = blockedString;
+    MockContentFilterManager::singleton().notifySettingsChanged(singleton());
+}
+
+void MockContentFilterSettings::setDecisionPoint(DecisionPoint decisionPoint)
+{
+    m_decisionPoint = decisionPoint;
+    MockContentFilterManager::singleton().notifySettingsChanged(singleton());
+}
+
+void MockContentFilterSettings::setDecision(Decision decision)
+{
+    m_decision = decision;
+    MockContentFilterManager::singleton().notifySettingsChanged(singleton());
+}
+
+void MockContentFilterSettings::setUnblockRequestDecision(Decision unblockRequestDecision)
+{
+    m_unblockRequestDecision = unblockRequestDecision;
+    MockContentFilterManager::singleton().notifySettingsChanged(singleton());
+}
+
+void MockContentFilterSettings::setModifiedRequestURL(const String& modifiedRequestURL)
+{
+    m_modifiedRequestURL = modifiedRequestURL;
+    MockContentFilterManager::singleton().notifySettingsChanged(singleton());
+}
+
 const String& MockContentFilterSettings::unblockRequestURL() const
 {
     static NeverDestroyed<String> unblockRequestURL = makeString(ContentFilter::urlScheme(), "://", unblockURLHost());

Modified: trunk/Source/WebCore/testing/MockContentFilterSettings.h (291498 => 291499)


--- trunk/Source/WebCore/testing/MockContentFilterSettings.h	2022-03-18 22:09:34 UTC (rev 291498)
+++ trunk/Source/WebCore/testing/MockContentFilterSettings.h	2022-03-18 22:12:12 UTC (rev 291499)
@@ -47,7 +47,7 @@
     };
 
     WEBCORE_TESTSUPPORT_EXPORT static MockContentFilterSettings& singleton();
-    static void reset();
+    WEBCORE_TESTSUPPORT_EXPORT static void reset();
     static const char* unblockURLHost() { return "mock-unblock"; }
 
     // Trick the generated bindings into thinking we're RefCounted.
@@ -58,26 +58,29 @@
     WEBCORE_TESTSUPPORT_EXPORT void setEnabled(bool);
 
     const String& blockedString() const { return m_blockedString; }
-    void setBlockedString(const String& blockedString) { m_blockedString = blockedString; }
+    WEBCORE_TESTSUPPORT_EXPORT void setBlockedString(const String&);
 
     DecisionPoint decisionPoint() const { return m_decisionPoint; }
-    void setDecisionPoint(DecisionPoint decisionPoint) { m_decisionPoint = decisionPoint; }
+    WEBCORE_TESTSUPPORT_EXPORT void setDecisionPoint(DecisionPoint);
 
     Decision decision() const { return m_decision; }
-    void setDecision(Decision decision) { m_decision = decision; }
+    WEBCORE_TESTSUPPORT_EXPORT void setDecision(Decision);
 
     Decision unblockRequestDecision() const { return m_unblockRequestDecision; }
-    void setUnblockRequestDecision(Decision unblockRequestDecision) { m_unblockRequestDecision = unblockRequestDecision; }
+    WEBCORE_TESTSUPPORT_EXPORT void setUnblockRequestDecision(Decision);
 
-    const String& unblockRequestURL() const;
+    WEBCORE_TESTSUPPORT_EXPORT const String& unblockRequestURL() const;
 
     const String& modifiedRequestURL() const { return m_modifiedRequestURL; }
-    void setModifiedRequestURL(const String& modifiedRequestURL) { m_modifiedRequestURL = modifiedRequestURL; }
+    WEBCORE_TESTSUPPORT_EXPORT void setModifiedRequestURL(const String&);
 
-private:
+    template<class Encoder> void encode(Encoder&) const;
+    template<class Decoder> static std::optional<MockContentFilterSettings> decode(Decoder&);
+
     MockContentFilterSettings() = default;
-    MockContentFilterSettings(const MockContentFilterSettings&) = delete;
+    MockContentFilterSettings(const MockContentFilterSettings&) = default;
     MockContentFilterSettings& operator=(const MockContentFilterSettings&) = default;
+private:
 
     bool m_enabled { false };
     DecisionPoint m_decisionPoint { DecisionPoint::AfterResponse };
@@ -87,4 +90,53 @@
     String m_modifiedRequestURL;
 };
 
+template<class Encoder>
+void MockContentFilterSettings::encode(Encoder& encoder) const
+{
+    encoder << m_enabled;
+    encoder << decisionPoint();
+    encoder << decision();
+    encoder << unblockRequestDecision();
+    encoder << blockedString();
+    encoder << modifiedRequestURL();
+}
+
+template<class Decoder>
+std::optional<MockContentFilterSettings> MockContentFilterSettings::decode(Decoder& decoder )
+{
+    std::optional<bool> enabled;
+    decoder >> enabled;
+    if (!enabled)
+        return std::nullopt;
+    std::optional<DecisionPoint> decisionPoint;
+    decoder >> decisionPoint;
+    if (!decisionPoint)
+        return std::nullopt;
+    std::optional<WebCore::MockContentFilterSettings::Decision> decision;
+    decoder >> decision;
+    if (!decision)
+        return std::nullopt;
+    std::optional<WebCore::MockContentFilterSettings::Decision> unblockRequestDecision;
+    decoder >> unblockRequestDecision;
+    if (!unblockRequestDecision)
+        return std::nullopt;
+    std::optional<String> blockedString;
+    decoder >> blockedString;
+    if (!blockedString)
+        return std::nullopt;
+    std::optional<String> modifiedRequestURL;
+    decoder >> modifiedRequestURL;
+    if (!modifiedRequestURL)
+        return std::nullopt;
+
+    MockContentFilterSettings settings;
+    settings.setEnabled(*enabled);
+    settings.setDecisionPoint(*decisionPoint);
+    settings.setDecision(*decision);
+    settings.setUnblockRequestDecision(*unblockRequestDecision);
+    settings.setBlockedString(WTFMove(*blockedString));
+    settings.setModifiedRequestURL(WTFMove(*modifiedRequestURL));
+
+    return settings;
+}
 } // namespace WebCore

Copied: trunk/Source/WebCore/testing/MockContentFilterSettingsClient.h (from rev 291498, trunk/Source/WebCore/testing/MockContentFilterSettings.cpp) (0 => 291499)


--- trunk/Source/WebCore/testing/MockContentFilterSettingsClient.h	                        (rev 0)
+++ trunk/Source/WebCore/testing/MockContentFilterSettingsClient.h	2022-03-18 22:12:12 UTC (rev 291499)
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) 2022 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.
+ */
+
+#pragma once
+
+#include <wtf/RefCounted.h>
+
+namespace WebCore {
+
+class MockContentFilterSettings;
+
+class MockContentFilterSettingsClient : public RefCounted<MockContentFilterSettingsClient> {
+public:
+    virtual ~MockContentFilterSettingsClient() { }
+
+    virtual void mockContentFilterSettingsChanged(MockContentFilterSettings&) = 0;
+};
+
+};

Modified: trunk/Source/WebKit/ChangeLog (291498 => 291499)


--- trunk/Source/WebKit/ChangeLog	2022-03-18 22:09:34 UTC (rev 291498)
+++ trunk/Source/WebKit/ChangeLog	2022-03-18 22:12:12 UTC (rev 291499)
@@ -1,3 +1,43 @@
+2022-03-18  Per Arne Vollan  <pvol...@apple.com>
+
+        Fix test failures when enabling content filtering in the Network process
+        https://bugs.webkit.org/show_bug.cgi?id=237217
+
+        Reviewed by Brent Fulgham.
+
+        Add a WebMockContentFilterManager in the WebContent process, which will be notified
+        when mock content filter settings are changed from _javascript_, and then send the new
+        settings to the Network process and install the mock content filter. The other
+        changes are addressing layout and API test failures.
+
+        * NetworkProcess/NetworkConnectionToWebProcess.cpp:
+        (WebKit::NetworkConnectionToWebProcess::installMockContentFilter):
+        * NetworkProcess/NetworkConnectionToWebProcess.h:
+        * NetworkProcess/NetworkConnectionToWebProcess.messages.in:
+        * NetworkProcess/NetworkResourceLoader.cpp:
+        (WebKit::NetworkResourceLoader::start):
+        (WebKit::NetworkResourceLoader::startContentFiltering):
+        (WebKit::NetworkResourceLoader::didFinishLoading):
+        (WebKit::NetworkResourceLoader::willSendRedirectedRequestInternal):
+        (WebKit::NetworkResourceLoader::contentFilterDidBlock):
+        (WebKit::NetworkResourceLoader::cancelMainResourceLoadForContentFilter):
+        (WebKit::NetworkResourceLoader::handleProvisionalLoadFailureFromContentFilter):
+        * NetworkProcess/NetworkResourceLoader.h:
+        * Shared/WebCoreArgumentCoders.h:
+        * WebKit.xcodeproj/project.pbxproj:
+        * WebProcess/Network/WebMockContentFilterManager.cpp: Added.
+        (WebKit::WebMockContentFilterManager::singleton):
+        (WebKit::WebMockContentFilterManager::startObservingSettings):
+        (WebKit::WebMockContentFilterManager::mockContentFilterSettingsChanged):
+        * WebProcess/Network/WebMockContentFilterManager.h: Added.
+        * WebProcess/Network/WebResourceLoader.cpp:
+        (WebKit::WebResourceLoader::contentFilterDidBlockLoad):
+        (WebKit::WebResourceLoader::cancelMainResourceLoadForContentFilter):
+        (WebKit::WebResourceLoader::handleProvisionalLoadFailureFromContentFilter): Deleted.
+        * WebProcess/Network/WebResourceLoader.h:
+        * WebProcess/Network/WebResourceLoader.messages.in:
+        * WebProcess/WebProcess.cpp:
+
 2022-03-18  Chris Dumez  <cdu...@apple.com>
 
         Avoid calls to [CLLocationManager authorizationStatus] & [CLLocationManager locationServicesEnabled]

Modified: trunk/Source/WebKit/NetworkProcess/NetworkConnectionToWebProcess.cpp (291498 => 291499)


--- trunk/Source/WebKit/NetworkProcess/NetworkConnectionToWebProcess.cpp	2022-03-18 22:09:34 UTC (rev 291498)
+++ trunk/Source/WebKit/NetworkProcess/NetworkConnectionToWebProcess.cpp	2022-03-18 22:12:12 UTC (rev 291499)
@@ -1432,6 +1432,13 @@
     return m_networkResourceLoaders.take(resourceLoadIdentifier);
 }
 
+#if ENABLE(CONTENT_FILTERING_IN_NETWORKING_PROCESS)
+void NetworkConnectionToWebProcess::installMockContentFilter(WebCore::MockContentFilterSettings&& settings)
+{
+    MockContentFilterSettings::singleton() = WTFMove(settings);
+}
+#endif
+
 } // namespace WebKit
 
 #undef CONNECTION_RELEASE_LOG

Modified: trunk/Source/WebKit/NetworkProcess/NetworkConnectionToWebProcess.h (291498 => 291499)


--- trunk/Source/WebKit/NetworkProcess/NetworkConnectionToWebProcess.h	2022-03-18 22:09:34 UTC (rev 291498)
+++ trunk/Source/WebKit/NetworkProcess/NetworkConnectionToWebProcess.h	2022-03-18 22:12:12 UTC (rev 291499)
@@ -68,6 +68,7 @@
 class BlobDataFileReference;
 class BlobPart;
 class BlobRegistryImpl;
+class MockContentFilterSettings;
 class ResourceError;
 class ResourceRequest;
 enum class StorageAccessScope : bool;
@@ -200,6 +201,10 @@
     void broadcastConsoleMessage(JSC::MessageSource, JSC::MessageLevel, const String& message);
     RefPtr<NetworkResourceLoader> takeNetworkResourceLoader(WebCore::ResourceLoaderIdentifier);
 
+#if ENABLE(CONTENT_FILTERING_IN_NETWORKING_PROCESS)
+    void installMockContentFilter(WebCore::MockContentFilterSettings&&);
+#endif
+
 private:
     NetworkConnectionToWebProcess(NetworkProcess&, WebCore::ProcessIdentifier, PAL::SessionID, IPC::Connection::Identifier);
 

Modified: trunk/Source/WebKit/NetworkProcess/NetworkConnectionToWebProcess.messages.in (291498 => 291499)


--- trunk/Source/WebKit/NetworkProcess/NetworkConnectionToWebProcess.messages.in	2022-03-18 22:09:34 UTC (rev 291498)
+++ trunk/Source/WebKit/NetworkProcess/NetworkConnectionToWebProcess.messages.in	2022-03-18 22:12:12 UTC (rev 291499)
@@ -113,4 +113,8 @@
 #endif
     SetResourceLoadSchedulingMode(WebCore::PageIdentifier webPageID, enum:uint8_t WebCore::LoadSchedulingMode mode)
     PrioritizeResourceLoads(Vector<WebCore::ResourceLoaderIdentifier> loadIdentifiers)
+
+#if ENABLE(CONTENT_FILTERING_IN_NETWORKING_PROCESS)
+    InstallMockContentFilter(WebCore::MockContentFilterSettings settings)
+#endif
 }

Modified: trunk/Source/WebKit/NetworkProcess/NetworkResourceLoader.cpp (291498 => 291499)


--- trunk/Source/WebKit/NetworkProcess/NetworkResourceLoader.cpp	2022-03-18 22:09:34 UTC (rev 291498)
+++ trunk/Source/WebKit/NetworkProcess/NetworkResourceLoader.cpp	2022-03-18 22:12:12 UTC (rev 291499)
@@ -187,16 +187,17 @@
     ASSERT(RunLoop::isMain());
     LOADER_RELEASE_LOG("start: hasNetworkLoadChecker=%d", !!m_networkLoadChecker);
 
+    auto newRequest = ResourceRequest { originalRequest() };
+#if ENABLE(CONTENT_FILTERING_IN_NETWORKING_PROCESS)
+    if (!startContentFiltering(newRequest))
+        return;
+#endif
+
     m_networkActivityTracker = m_connection->startTrackingResourceLoad(m_parameters.webPageID, m_parameters.identifier, isMainFrameLoad());
 
     ASSERT(!m_wasStarted);
     m_wasStarted = true;
 
-    auto newRequest = ResourceRequest { originalRequest() };
-#if ENABLE(CONTENT_FILTERING_IN_NETWORKING_PROCESS)
-    startContentFiltering(newRequest);
-#endif
-
     if (m_networkLoadChecker) {
         m_networkLoadChecker->check(ResourceRequest { newRequest }, this, [this, weakThis = WeakPtr { *this }] (auto&& result) {
             if (!weakThis)
@@ -236,14 +237,17 @@
 }
 
 #if ENABLE(CONTENT_FILTERING_IN_NETWORKING_PROCESS)
-void NetworkResourceLoader::startContentFiltering(ResourceRequest& request)
+bool NetworkResourceLoader::startContentFiltering(ResourceRequest& request)
 {
     if (!isMainResource())
-        return;
+        return true;
     m_contentFilter = ContentFilter::create(*this);
-    if (!m_contentFilter->continueAfterWillSendRequest(request, ResourceResponse()))
-        return;
     m_contentFilter->startFilteringMainResource(request.url());
+    if (!m_contentFilter->continueAfterWillSendRequest(request, ResourceResponse())) {
+        m_contentFilter->stopFilteringMainResource();
+        return false;
+    }
+    return true;
 }
 #endif
 
@@ -946,11 +950,11 @@
         }
 #if ENABLE(CONTENT_FILTERING_IN_NETWORKING_PROCESS)
         if (m_contentFilter) {
-            m_contentFilter->continueAfterNotifyFinished(m_parameters.request.url());
+            if (!m_contentFilter->continueAfterNotifyFinished(m_parameters.request.url()))
+                return;
             m_contentFilter->stopFilteringMainResource();
         }
 #endif
-
         send(Messages::WebResourceLoader::DidFinishResourceLoad(networkLoadMetrics));
     }
 
@@ -1051,7 +1055,7 @@
         m_firstResponseURL = redirectResponse.url();
 
 #if ENABLE(CONTENT_FILTERING_IN_NETWORKING_PROCESS)
-    if (m_contentFilter && !m_contentFilter->continueAfterWillSendRequest(request, redirectResponse))
+    if (m_contentFilter && !m_contentFilter->continueAfterWillSendRequest(redirectRequest, redirectResponse))
         return;
 #endif
 
@@ -1798,32 +1802,38 @@
 
 WebCore::ResourceError NetworkResourceLoader::contentFilterDidBlock(WebCore::ContentFilterUnblockHandler unblockHandler, String&& unblockRequestDeniedScript)
 {
-    send(Messages::WebResourceLoader::ContentFilterDidBlockLoad(unblockHandler, unblockRequestDeniedScript));
-    if (!unblockHandler.needsUIProcess()) {
-        unblockHandler.requestUnblockAsync([this, protectedThis = Ref { *this }](bool unblocked) {
-            if (!unblocked)
-                return;
-            m_connection->networkProcess().parentProcessConnection()->send(Messages::NetworkProcessProxy::ReloadAfterUnblockedContentFilter(m_parameters.webPageProxyID), 0);
+    auto error = WebKit::blockedByContentFilterError(m_parameters.request);
+
+    m_unblockHandler = unblockHandler;
+    m_unblockRequestDeniedScript = unblockRequestDeniedScript;
+    
+    if (unblockHandler.needsUIProcess())
+        m_contentFilter->handleProvisionalLoadFailure(error);
+    else {
+        unblockHandler.requestUnblockAsync([this, protectedThis = Ref { *this }](bool unblocked) mutable {
+            m_unblockHandler.setUnblockedAfterRequest(unblocked);
+
+            ResourceRequest request;
+            if (m_wasStarted || unblocked)
+                request = m_parameters.request;
+            else
+                request = ResourceRequest(aboutBlankURL());
+            auto error = WebKit::blockedByContentFilterError(request);
+            m_contentFilter->setBlockedError(error);
+            m_contentFilter->handleProvisionalLoadFailure(error);
         });
     }
-    return WebKit::blockedByContentFilterError(m_parameters.request);
+    return error;
 }
 
 void NetworkResourceLoader::cancelMainResourceLoadForContentFilter(const WebCore::ResourceError& error)
 {
     RELEASE_ASSERT(m_contentFilter);
-    m_contentFilter->handleProvisionalLoadFailure(error);
 }
 
 void NetworkResourceLoader::handleProvisionalLoadFailureFromContentFilter(const URL& blockedPageURL, WebCore::SubstituteData& substituteData)
 {
-    if (substituteData.isValid())
-        send(Messages::WebResourceLoader::HandleProvisionalLoadFailureFromContentFilter(blockedPageURL, substituteData));
-    else {
-        RELEASE_ASSERT(m_contentFilter);
-        auto& error = m_contentFilter->blockedError();
-        send(Messages::WebResourceLoader::CancelMainResourceLoadForContentFilter(error));
-    }
+    send(Messages::WebResourceLoader::ContentFilterDidBlockLoad(m_unblockHandler, m_unblockRequestDeniedScript, m_contentFilter->blockedError(), blockedPageURL, substituteData));
 }
 #endif // ENABLE(CONTENT_FILTERING_IN_NETWORKING_PROCESS)
 

Modified: trunk/Source/WebKit/NetworkProcess/NetworkResourceLoader.h (291498 => 291499)


--- trunk/Source/WebKit/NetworkProcess/NetworkResourceLoader.h	2022-03-18 22:09:34 UTC (rev 291498)
+++ trunk/Source/WebKit/NetworkProcess/NetworkResourceLoader.h	2022-03-18 22:12:12 UTC (rev 291499)
@@ -35,6 +35,7 @@
 #include "NetworkResourceLoadParameters.h"
 #include "PrivateRelayed.h"
 #include <WebCore/ContentFilterClient.h>
+#include <WebCore/ContentFilterUnblockHandler.h>
 #include <WebCore/ContentSecurityPolicyClient.h>
 #include <WebCore/CrossOriginAccessControl.h>
 #include <WebCore/PrivateClickMeasurement.h>
@@ -241,7 +242,7 @@
     ResourceLoadInfo resourceLoadInfo();
 
 #if ENABLE(CONTENT_FILTERING_IN_NETWORKING_PROCESS)
-    void startContentFiltering(WebCore::ResourceRequest&);
+    bool startContentFiltering(WebCore::ResourceRequest&);
 #endif
 
     enum class IsFromServiceWorker : bool { No, Yes };
@@ -295,6 +296,8 @@
 
 #if ENABLE(CONTENT_FILTERING_IN_NETWORKING_PROCESS)
     std::unique_ptr<WebCore::ContentFilter> m_contentFilter;
+    WebCore::ContentFilterUnblockHandler m_unblockHandler;
+    String m_unblockRequestDeniedScript;
 #endif
 
     PrivateRelayed m_privateRelayed { PrivateRelayed::No };

Modified: trunk/Source/WebKit/Shared/WebCoreArgumentCoders.h (291498 => 291499)


--- trunk/Source/WebKit/Shared/WebCoreArgumentCoders.h	2022-03-18 22:09:34 UTC (rev 291498)
+++ trunk/Source/WebKit/Shared/WebCoreArgumentCoders.h	2022-03-18 22:12:12 UTC (rev 291499)
@@ -94,6 +94,10 @@
 #include <WebCore/PlatformXR.h>
 #endif
 
+#if ENABLE(CONTENT_FILTERING_IN_NETWORKING_PROCESS)
+#include <WebCore/MockContentFilterSettings.h>
+#endif
+
 #if PLATFORM(COCOA)
 #include "ArgumentCodersCF.h"
 
@@ -847,6 +851,28 @@
     >;
 };
 
+#if ENABLE(CONTENT_FILTERING_IN_NETWORKING_PROCESS)
+template<> struct EnumTraits<WebCore::MockContentFilterSettings::DecisionPoint> {
+    using values = EnumValues<
+        WebCore::MockContentFilterSettings::DecisionPoint,
+        WebCore::MockContentFilterSettings::DecisionPoint::AfterWillSendRequest,
+        WebCore::MockContentFilterSettings::DecisionPoint::AfterRedirect,
+        WebCore::MockContentFilterSettings::DecisionPoint::AfterResponse,
+        WebCore::MockContentFilterSettings::DecisionPoint::AfterAddData,
+        WebCore::MockContentFilterSettings::DecisionPoint::AfterFinishedAddingData,
+        WebCore::MockContentFilterSettings::DecisionPoint::Never
+    >;
+};
+
+template<> struct EnumTraits<WebCore::MockContentFilterSettings::Decision> {
+    using values = EnumValues<
+        WebCore::MockContentFilterSettings::Decision,
+        WebCore::MockContentFilterSettings::Decision::Allow,
+        WebCore::MockContentFilterSettings::Decision::Block
+    >;
+};
+#endif
+
 template<> struct EnumTraits<WebCore::AutoplayEvent> {
     using values = EnumValues<
         WebCore::AutoplayEvent,

Modified: trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj (291498 => 291499)


--- trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj	2022-03-18 22:09:34 UTC (rev 291498)
+++ trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj	2022-03-18 22:12:12 UTC (rev 291499)
@@ -1997,6 +1997,8 @@
 		E1D26A53175964D90095BFD1 /* WebContentProcess.xib in Resources */ = {isa = PBXBuildFile; fileRef = E1D26A4C1759634E0095BFD1 /* WebContentProcess.xib */; };
 		E1E552C516AE065F004ED653 /* SandboxInitializationParameters.h in Headers */ = {isa = PBXBuildFile; fileRef = E1E552C316AE065E004ED653 /* SandboxInitializationParameters.h */; };
 		E1EE53E311F8CFC000CCBEE4 /* InjectedBundlePageEditorClient.h in Headers */ = {isa = PBXBuildFile; fileRef = E1EE53DC11F8CF9F00CCBEE4 /* InjectedBundlePageEditorClient.h */; };
+		E3816B3D27E2463A005EAFC0 /* WebMockContentFilterManager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E3816B3B27E24639005EAFC0 /* WebMockContentFilterManager.cpp */; };
+		E3816B3E27E2463A005EAFC0 /* WebMockContentFilterManager.h in Headers */ = {isa = PBXBuildFile; fileRef = E3816B3C27E24639005EAFC0 /* WebMockContentFilterManager.h */; };
 		E3866AE52397400400F88FE9 /* WebDeviceOrientationUpdateProviderProxy.mm in Sources */ = {isa = PBXBuildFile; fileRef = E3866AE42397400400F88FE9 /* WebDeviceOrientationUpdateProviderProxy.mm */; };
 		E3866AE72397405300F88FE9 /* WebDeviceOrientationUpdateProviderProxy.h in Headers */ = {isa = PBXBuildFile; fileRef = E3866AE62397405300F88FE9 /* WebDeviceOrientationUpdateProviderProxy.h */; };
 		E3866B082399A2D100F88FE9 /* WebDeviceOrientationUpdateProviderProxyMessages.h in Headers */ = {isa = PBXBuildFile; fileRef = E3866B052399979C00F88FE9 /* WebDeviceOrientationUpdateProviderProxyMessages.h */; };
@@ -6496,9 +6498,13 @@
 		E30CFB9D2660663C0094D9C0 /* com.apple.WebKit.WebContent.sb */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = com.apple.WebKit.WebContent.sb; path = DerivedSources/WebKit/com.apple.WebKit.WebContent.sb; sourceTree = BUILT_PRODUCTS_DIR; };
 		E313664D265EE5AF0051084F /* com.apple.WebKit.WebContent.sb.in */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = com.apple.WebKit.WebContent.sb.in; sourceTree = "<group>"; };
 		E3439B632345463A0011DE0B /* NetworkProcessConnectionInfo.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = NetworkProcessConnectionInfo.h; path = Network/NetworkProcessConnectionInfo.h; sourceTree = "<group>"; };
+		E34B110C27C46BC6006D2F2E /* libWebCoreTestShim.dylib */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.dylib"; path = libWebCoreTestShim.dylib; sourceTree = BUILT_PRODUCTS_DIR; };
+		E34B110F27C46D09006D2F2E /* libWebCoreTestSupport.dylib */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.dylib"; path = libWebCoreTestSupport.dylib; sourceTree = BUILT_PRODUCTS_DIR; };
 		E3612FF026F90862007B1175 /* Sandbox */ = {isa = PBXFileReference; lastKnownFileType = folder; path = Sandbox; sourceTree = "<group>"; };
 		E36D701A27B709ED006531B7 /* WebAttachmentElementClient.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WebAttachmentElementClient.h; sourceTree = "<group>"; };
 		E36D701D27B718EF006531B7 /* WebAttachmentElementClient.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = WebAttachmentElementClient.cpp; sourceTree = "<group>"; };
+		E3816B3B27E24639005EAFC0 /* WebMockContentFilterManager.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = WebMockContentFilterManager.cpp; path = Network/WebMockContentFilterManager.cpp; sourceTree = "<group>"; };
+		E3816B3C27E24639005EAFC0 /* WebMockContentFilterManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = WebMockContentFilterManager.h; path = Network/WebMockContentFilterManager.h; sourceTree = "<group>"; };
 		E3866AE42397400400F88FE9 /* WebDeviceOrientationUpdateProviderProxy.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = WebDeviceOrientationUpdateProviderProxy.mm; path = ios/WebDeviceOrientationUpdateProviderProxy.mm; sourceTree = "<group>"; };
 		E3866AE62397405300F88FE9 /* WebDeviceOrientationUpdateProviderProxy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = WebDeviceOrientationUpdateProviderProxy.h; path = ios/WebDeviceOrientationUpdateProviderProxy.h; sourceTree = "<group>"; };
 		E3866AED2398471A00F88FE9 /* WebDeviceOrientationUpdateProviderProxy.messages.in */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = WebDeviceOrientationUpdateProviderProxy.messages.in; path = ios/WebDeviceOrientationUpdateProviderProxy.messages.in; sourceTree = "<group>"; };
@@ -9515,6 +9521,8 @@
 				E3439B632345463A0011DE0B /* NetworkProcessConnectionInfo.h */,
 				51ABF65616392F1500132A7A /* WebLoaderStrategy.cpp */,
 				51ABF65716392F1500132A7A /* WebLoaderStrategy.h */,
+				E3816B3B27E24639005EAFC0 /* WebMockContentFilterManager.cpp */,
+				E3816B3C27E24639005EAFC0 /* WebMockContentFilterManager.h */,
 				A5860E6F230F67DE00461AAE /* WebResourceInterceptController.cpp */,
 				A5860E70230F67DE00461AAE /* WebResourceInterceptController.h */,
 				510AFFB716542048001BA05E /* WebResourceLoader.cpp */,
@@ -10032,6 +10040,8 @@
 		5750F3292032D4E300389347 /* Frameworks */ = {
 			isa = PBXGroup;
 			children = (
+				E34B110C27C46BC6006D2F2E /* libWebCoreTestShim.dylib */,
+				E34B110F27C46D09006D2F2E /* libWebCoreTestSupport.dylib */,
 				DDE992F4278D06D900F60D26 /* libWebKitAdditions.a */,
 				57A9FF15252C6AEF006A2040 /* libWTF.a */,
 				5750F32A2032D4E500389347 /* LocalAuthentication.framework */,
@@ -13823,6 +13833,7 @@
 				2D3EF4431917646300034184 /* WebMemoryPressureHandler.h in Headers */,
 				909854ED12BC4E18000AD080 /* WebMemorySampler.h in Headers */,
 				513FFB91201459C6002596EA /* WebMessagePortChannelProvider.h in Headers */,
+				E3816B3E27E2463A005EAFC0 /* WebMockContentFilterManager.h in Headers */,
 				BCF69F9A1176CED600471A52 /* WebNavigationDataStore.h in Headers */,
 				7CCCC8FB1A5F50FD008FB0DA /* WebNavigationState.h in Headers */,
 				31A2EC49148997C200810D71 /* WebNotification.h in Headers */,
@@ -16207,6 +16218,7 @@
 				A181A79821ACC74B0059A316 /* WebKitAdditions.mm in Sources */,
 				CDF1B91B267025550007EC10 /* WebKitSwiftSoftLink.mm in Sources */,
 				51F060E11654318500F3282F /* WebMDNSRegisterMessageReceiver.cpp in Sources */,
+				E3816B3D27E2463A005EAFC0 /* WebMockContentFilterManager.cpp in Sources */,
 				31BA924D148831260062EDB5 /* WebNotificationManagerMessageReceiver.cpp in Sources */,
 				2DF6FE52212E110900469030 /* WebPage.cpp in Sources */,
 				C0CE72A01247E71D00BC0EC4 /* WebPageMessageReceiver.cpp in Sources */,

Copied: trunk/Source/WebKit/WebProcess/Network/WebMockContentFilterManager.cpp (from rev 291498, trunk/Source/WebCore/testing/MockContentFilterSettings.cpp) (0 => 291499)


--- trunk/Source/WebKit/WebProcess/Network/WebMockContentFilterManager.cpp	                        (rev 0)
+++ trunk/Source/WebKit/WebProcess/Network/WebMockContentFilterManager.cpp	2022-03-18 22:12:12 UTC (rev 291499)
@@ -0,0 +1,60 @@
+/*
+ * Copyright (C) 2022 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "WebMockContentFilterManager.h"
+
+#if ENABLE(CONTENT_FILTERING_IN_NETWORKING_PROCESS)
+
+#include "NetworkConnectionToWebProcessMessages.h"
+#include "NetworkProcessConnection.h"
+#include "WebCoreArgumentCoders.h"
+#include "WebProcess.h"
+#include <WebCore/MockContentFilterManager.h>
+#include <WebCore/MockContentFilterSettings.h>
+#include <wtf/NeverDestroyed.h>
+
+namespace WebKit {
+
+WebMockContentFilterManager& WebMockContentFilterManager::singleton()
+{
+    static NeverDestroyed<WebMockContentFilterManager> manager;
+    return manager.get();
+}
+
+void WebMockContentFilterManager::startObservingSettings()
+{
+    WebCore::MockContentFilterManager::singleton().setClient(this);
+}
+
+void WebMockContentFilterManager::mockContentFilterSettingsChanged(WebCore::MockContentFilterSettings& settings)
+{
+    if (auto connection = WebProcess::singleton().existingNetworkProcessConnection())
+        connection->connection().send(Messages::NetworkConnectionToWebProcess::InstallMockContentFilter(settings), 0);
+}
+
+};
+
+#endif

Copied: trunk/Source/WebKit/WebProcess/Network/WebMockContentFilterManager.h (from rev 291498, trunk/Source/WebCore/testing/MockContentFilterSettings.cpp) (0 => 291499)


--- trunk/Source/WebKit/WebProcess/Network/WebMockContentFilterManager.h	                        (rev 0)
+++ trunk/Source/WebKit/WebProcess/Network/WebMockContentFilterManager.h	2022-03-18 22:12:12 UTC (rev 291499)
@@ -0,0 +1,42 @@
+/*
+ * Copyright (C) 2022 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.
+ */
+
+#pragma once
+
+#include <WebCore/MockContentFilterSettingsClient.h>
+
+namespace WebKit {
+
+class WebMockContentFilterManager : public WebCore::MockContentFilterSettingsClient {
+public:
+    static WebMockContentFilterManager& singleton();
+
+    void startObservingSettings();
+    
+    // WebCore::MockContentFilterSettingsClient
+    void mockContentFilterSettingsChanged(WebCore::MockContentFilterSettings&) final;
+};
+
+};

Modified: trunk/Source/WebKit/WebProcess/Network/WebResourceLoader.cpp (291498 => 291499)


--- trunk/Source/WebKit/WebProcess/Network/WebResourceLoader.cpp	2022-03-18 22:09:34 UTC (rev 291498)
+++ trunk/Source/WebKit/WebProcess/Network/WebResourceLoader.cpp	2022-03-18 22:12:12 UTC (rev 291499)
@@ -354,11 +354,14 @@
 #endif
 
 #if ENABLE(CONTENT_FILTERING_IN_NETWORKING_PROCESS)
-void WebResourceLoader::contentFilterDidBlockLoad(const WebCore::ContentFilterUnblockHandler& unblockHandler, String&& unblockRequestDeniedScript)
+void WebResourceLoader::contentFilterDidBlockLoad(const WebCore::ContentFilterUnblockHandler& unblockHandler, String&& unblockRequestDeniedScript, const ResourceError& error, const URL& blockedPageURL,  WebCore::SubstituteData&& substituteData)
 {
     if (!m_coreLoader || !m_coreLoader->documentLoader())
         return;
+    m_coreLoader->documentLoader()->setBlockedPageURL(blockedPageURL);
+    m_coreLoader->documentLoader()->setSubstituteDataFromContentFilter(WTFMove(substituteData));
     m_coreLoader->documentLoader()->handleContentFilterDidBlock(unblockHandler, WTFMove(unblockRequestDeniedScript));
+    m_coreLoader->documentLoader()->cancelMainResourceLoad(error);
 }
 
 void WebResourceLoader::cancelMainResourceLoadForContentFilter(const WebCore::ResourceError& error)
@@ -367,13 +370,6 @@
         return;
     m_coreLoader->documentLoader()->cancelMainResourceLoad(error);
 }
-
-void WebResourceLoader::handleProvisionalLoadFailureFromContentFilter(const URL& blockedPageURL, const WebCore::SubstituteData& substituteData)
-{
-    if (!m_coreLoader || !m_coreLoader->documentLoader() || !substituteData.isValid())
-        return;
-    m_coreLoader->documentLoader()->handleContentFilterProvisionalLoadFailure(blockedPageURL, substituteData);
-}
 #endif // ENABLE(CONTENT_FILTERING_IN_NETWORKING_PROCESS)
 
 } // namespace WebKit

Modified: trunk/Source/WebKit/WebProcess/Network/WebResourceLoader.h (291498 => 291499)


--- trunk/Source/WebKit/WebProcess/Network/WebResourceLoader.h	2022-03-18 22:09:34 UTC (rev 291498)
+++ trunk/Source/WebKit/WebProcess/Network/WebResourceLoader.h	2022-03-18 22:12:12 UTC (rev 291499)
@@ -102,9 +102,8 @@
 #endif
 
 #if ENABLE(CONTENT_FILTERING_IN_NETWORKING_PROCESS)
-    void contentFilterDidBlockLoad(const WebCore::ContentFilterUnblockHandler&, String&& unblockRequestDeniedScript);
+    void contentFilterDidBlockLoad(const WebCore::ContentFilterUnblockHandler&, String&& unblockRequestDeniedScript, const WebCore::ResourceError&, const URL& blockedPageURL, WebCore::SubstituteData&&);
     void cancelMainResourceLoadForContentFilter(const WebCore::ResourceError&);
-    void handleProvisionalLoadFailureFromContentFilter(const URL& blockedPageURL, const WebCore::SubstituteData&);
 #endif
     
     RefPtr<WebCore::ResourceLoader> m_coreLoader;

Modified: trunk/Source/WebKit/WebProcess/Network/WebResourceLoader.messages.in (291498 => 291499)


--- trunk/Source/WebKit/WebProcess/Network/WebResourceLoader.messages.in	2022-03-18 22:09:34 UTC (rev 291498)
+++ trunk/Source/WebKit/WebProcess/Network/WebResourceLoader.messages.in	2022-03-18 22:12:12 UTC (rev 291499)
@@ -39,9 +39,8 @@
 #endif
 
 #if ENABLE(CONTENT_FILTERING_IN_NETWORKING_PROCESS)
-    ContentFilterDidBlockLoad(WebCore::ContentFilterUnblockHandler unblockHandler, String unblockRequestDeniedScript)
+    ContentFilterDidBlockLoad(WebCore::ContentFilterUnblockHandler unblockHandler, String unblockRequestDeniedScript, WebCore::ResourceError error, URL blockedPageURL, WebCore::SubstituteData substituteData)
     CancelMainResourceLoadForContentFilter(WebCore::ResourceError error)
-    HandleProvisionalLoadFailureFromContentFilter(URL blockedPageURL, WebCore::SubstituteData substituteData)
 #endif
 
 }

Modified: trunk/Source/WebKit/WebProcess/WebProcess.cpp (291498 => 291499)


--- trunk/Source/WebKit/WebProcess/WebProcess.cpp	2022-03-18 22:09:34 UTC (rev 291498)
+++ trunk/Source/WebKit/WebProcess/WebProcess.cpp	2022-03-18 22:12:12 UTC (rev 291499)
@@ -232,6 +232,10 @@
 #include <wtf/linux/RealTimeThreads.h>
 #endif
 
+#if ENABLE(CONTENT_FILTERING_IN_NETWORKING_PROCESS)
+#include "WebMockContentFilterManager.h"
+#endif
+
 #undef WEBPROCESS_RELEASE_LOG
 #define RELEASE_LOG_SESSION_ID (m_sessionID ? m_sessionID->toUInt64() : 0)
 #if RELEASE_LOG_DISABLED
@@ -341,6 +345,10 @@
 #endif
 
     Gigacage::forbidDisablingPrimitiveGigacage();
+
+#if ENABLE(CONTENT_FILTERING_IN_NETWORKING_PROCESS)
+    WebMockContentFilterManager::singleton().startObservingSettings();
+#endif
 }
 
 WebProcess::~WebProcess()
@@ -2228,7 +2236,6 @@
     return *supplement<RemoteMediaEngineConfigurationFactory>();
 }
 #endif
-
 } // namespace WebKit
 
 #undef RELEASE_LOG_SESSION_ID

Modified: trunk/Tools/ChangeLog (291498 => 291499)


--- trunk/Tools/ChangeLog	2022-03-18 22:09:34 UTC (rev 291498)
+++ trunk/Tools/ChangeLog	2022-03-18 22:12:12 UTC (rev 291499)
@@ -1,3 +1,21 @@
+2022-03-18  Per Arne Vollan  <pvol...@apple.com>
+
+        Fix test failures when enabling content filtering in the Network process
+        https://bugs.webkit.org/show_bug.cgi?id=237217
+
+        Reviewed by Brent Fulgham.
+
+        TestWebKitAPI needs to link with WebCore now that the mock content filter is compiled into WebCore.
+        Adjust test expectations, since the content filters are not expected to be loaded in the WebContent
+        process anymore.
+
+        * TestWebKitAPI/Configurations/TestWebKitAPI.xcconfig:
+        * TestWebKitAPI/Configurations/WebProcessPlugIn.xcconfig:
+        * TestWebKitAPI/Tests/WebKitCocoa/ContentFiltering.mm:
+        (TEST):
+        * TestWebKitAPI/Tests/WebKitCocoa/ContentFilteringPlugIn.mm:
+        * TestWebKitAPI/Tests/mac/ContentFiltering.mm:
+
 2022-03-18  Ben Nham  <n...@apple.com>
 
         Remove push subscriptions when associated service worker registrations are removed

Modified: trunk/Tools/TestWebKitAPI/Configurations/TestWebKitAPI.xcconfig (291498 => 291499)


--- trunk/Tools/TestWebKitAPI/Configurations/TestWebKitAPI.xcconfig	2022-03-18 22:09:34 UTC (rev 291498)
+++ trunk/Tools/TestWebKitAPI/Configurations/TestWebKitAPI.xcconfig	2022-03-18 22:12:12 UTC (rev 291499)
@@ -86,9 +86,15 @@
 WK_UIKITMACHELPER_LDFLAGS = $(WK_UIKITMACHELPER_LDFLAGS_$(WK_PLATFORM_NAME));
 WK_UIKITMACHELPER_LDFLAGS_maccatalyst = -framework UIKitMacHelper;
 
+WK_WEBCORE_LDFLAGS = $(WK_WEBCORE_LDFLAGS_$(WK_PLATFORM_NAME));
+WK_WEBCORE_LDFLAGS_iphoneos = -framework WebCore
+WK_WEBCORE_LDFLAGS_iphonesimulator = -framework WebCore
+WK_WEBCORE_LDFLAGS_watchos = -framework WebCore
+WK_WEBCORE_LDFLAGS_watchsimulator = -framework WebCore
+
 OTHER_CPLUSPLUSFLAGS = $(inherited) -isystem $(SDKROOT)/System/Library/Frameworks/System.framework/PrivateHeaders;
 
-OTHER_LDFLAGS = $(inherited) -lgtest -force_load $(BUILT_PRODUCTS_DIR)/libTestWebKitAPI.a -framework _javascript_Core -framework WebKit -lWebCoreTestSupport -framework Metal -framework IOSurface $(WK_APPSERVERSUPPORT_LDFLAGS) $(WK_AUTHKIT_LDFLAGS) -framework Network $(WK_HID_LDFLAGS) $(WK_OPENGL_LDFLAGS) $(WK_PDFKIT_LDFLAGS) $(WK_SYSTEM_LDFLAGS) $(WK_UIKITMACHELPER_LDFLAGS) $(WK_VISIONKITCORE_LDFLAGS) $(OTHER_LDFLAGS_PLATFORM_$(WK_COCOA_TOUCH));
+OTHER_LDFLAGS = $(inherited) -lgtest -force_load $(BUILT_PRODUCTS_DIR)/libTestWebKitAPI.a -framework _javascript_Core -framework WebKit -lWebCoreTestSupport -framework Metal -framework IOSurface $(WK_APPSERVERSUPPORT_LDFLAGS) $(WK_AUTHKIT_LDFLAGS) -framework Network $(WK_HID_LDFLAGS) $(WK_OPENGL_LDFLAGS) $(WK_PDFKIT_LDFLAGS) $(WK_SYSTEM_LDFLAGS) $(WK_UIKITMACHELPER_LDFLAGS) $(WK_VISIONKITCORE_LDFLAGS) $(WK_WEBCORE_LDFLAGS) $(OTHER_LDFLAGS_PLATFORM_$(WK_COCOA_TOUCH));
 OTHER_LDFLAGS_PLATFORM_ = -framework Cocoa -framework Carbon;
 
 // FIXME: This should not be built on iOS. Instead we should create and use a TestWebKitAPI application.

Modified: trunk/Tools/TestWebKitAPI/Configurations/WebProcessPlugIn.xcconfig (291498 => 291499)


--- trunk/Tools/TestWebKitAPI/Configurations/WebProcessPlugIn.xcconfig	2022-03-18 22:09:34 UTC (rev 291498)
+++ trunk/Tools/TestWebKitAPI/Configurations/WebProcessPlugIn.xcconfig	2022-03-18 22:12:12 UTC (rev 291499)
@@ -28,6 +28,12 @@
 PRODUCT_BUNDLE_IDENTIFIER = com.apple.$(PRODUCT_NAME:rfc1034identifier);
 EXECUTABLE_SUFFIX = .bundle;
 WRAPPER_EXTENSION = wkbundle;
-OTHER_LDFLAGS = $(inherited) -framework _javascript_Core -framework WebKit -lWebCoreTestSupport;
+WK_WEBCORE_LDFLAGS = $(WK_WEBCORE_LDFLAGS_$(WK_PLATFORM_NAME));
+WK_WEBCORE_LDFLAGS_iphoneos = -framework WebCore
+WK_WEBCORE_LDFLAGS_iphonesimulator = -framework WebCore
+WK_WEBCORE_LDFLAGS_watchos = -framework WebCore
+WK_WEBCORE_LDFLAGS_watchsimulator = -framework WebCore
+
+OTHER_LDFLAGS = $(inherited) -framework _javascript_Core -framework WebKit -lWebCoreTestSupport $(WK_WEBCORE_LDFLAGS);
 LD_RUNPATH_SEARCH_PATHS[sdk=macosx*] = "@loader_path/../../..";
 LD_RUNPATH_SEARCH_PATHS[sdk=embedded*] = "@loader_path/..";

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/ContentFiltering.mm (291498 => 291499)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/ContentFiltering.mm	2022-03-18 22:09:34 UTC (rev 291498)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/ContentFiltering.mm	2022-03-18 22:12:12 UTC (rev 291499)
@@ -29,10 +29,10 @@
 
 #import "DeprecatedGlobalValues.h"
 #import "ContentFiltering.h"
-#import "MockContentFilterSettings.h"
 #import "PlatformUtilities.h"
 #import "TestProtocol.h"
 #import "WKWebViewConfigurationExtras.h"
+#import <WebCore/MockContentFilterSettings.h>
 #import <WebKit/WKErrorRef.h>
 #import <WebKit/WKNavigationDelegatePrivate.h>
 #import <WebKit/WKProcessPoolPrivate.h>
@@ -433,7 +433,7 @@
         [TestProtocol registerWithScheme:@"http"];
         [[controller webView] loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://test"]]];
         TestWebKitAPI::Util::run(&isDone);
-#if PLATFORM(MAC)
+#if PLATFORM(MAC) || ENABLE(CONTENT_FILTERING_IN_NETWORKING_PROCESS)
         [controller expectParentalControlsLoaded:NO];
 #else
         [controller expectParentalControlsLoaded:YES];
@@ -445,7 +445,11 @@
         [TestProtocol registerWithScheme:@"https"];
         [[controller webView] loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"https://test"]]];
         TestWebKitAPI::Util::run(&isDone);
+#if ENABLE(CONTENT_FILTERING_IN_NETWORKING_PROCESS)
+        [controller expectParentalControlsLoaded:NO];
+#else
         [controller expectParentalControlsLoaded:YES];
+#endif
         [TestProtocol unregister];
 #endif
     }

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/ContentFilteringPlugIn.mm (291498 => 291499)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/ContentFilteringPlugIn.mm	2022-03-18 22:09:34 UTC (rev 291498)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/ContentFilteringPlugIn.mm	2022-03-18 22:12:12 UTC (rev 291499)
@@ -28,7 +28,7 @@
 #if ENABLE(CONTENT_FILTERING)
 
 #import "ContentFiltering.h"
-#import "MockContentFilterSettings.h"
+#import <WebCore/MockContentFilterSettings.h>
 #import <WebKit/WKWebProcessPlugIn.h>
 #import <WebKit/WKWebProcessPlugInBrowserContextControllerPrivate.h>
 #import <WebKit/_WKRemoteObjectInterface.h>

Modified: trunk/Tools/TestWebKitAPI/Tests/mac/ContentFiltering.mm (291498 => 291499)


--- trunk/Tools/TestWebKitAPI/Tests/mac/ContentFiltering.mm	2022-03-18 22:09:34 UTC (rev 291498)
+++ trunk/Tools/TestWebKitAPI/Tests/mac/ContentFiltering.mm	2022-03-18 22:12:12 UTC (rev 291499)
@@ -26,9 +26,9 @@
 #import "config.h"
 
 #import "DeprecatedGlobalValues.h"
-#import "MockContentFilterSettings.h"
 #import "PlatformUtilities.h"
 #import "TestProtocol.h"
+#import <WebCore/MockContentFilterSettings.h>
 #import <WebKit/WebKit.h>
 #import <WebKit/WebKitErrorsPrivate.h>
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to