Title: [229869] trunk
Revision
229869
Author
[email protected]
Date
2018-03-22 15:10:38 -0700 (Thu, 22 Mar 2018)

Log Message

Expose SchemeRegistry::registerAsCanDisplayOnlyIfCanRequest() as WebKit SPI
https://bugs.webkit.org/show_bug.cgi?id=183907
<rdar://problem/38759127>

Reviewed by Alex Christensen.

Source/WebCore:

Exports SchemeRegistry::registerAsCanDisplayOnlyIfCanRequest() so that we can use it from WebKit.

* platform/SchemeRegistry.h:

Source/WebKit:

Adds both modern Objective-C SPI and C SPI to allow an embedding client to register a scheme
whose content should be displayed/loaded if and only if it can be requested. Disregarding an
app that enables universal access, by using this SPI WebKit will refuse to display cross-origin
content for the registered schemes.

We need to add C SPI for embedding clients that have not transitioned to the modern Objective-
C API/SPI.

* Shared/WebProcessCreationParameters.cpp:
(WebKit::WebProcessCreationParameters::encode const):
(WebKit::WebProcessCreationParameters::decode):
* Shared/WebProcessCreationParameters.h:
* UIProcess/API/C/WKContext.cpp:
(WKContextRegisterURLSchemeAsCanDisplayOnlyIfCanRequest):
* UIProcess/API/C/WKContextPrivate.h:
* UIProcess/API/Cocoa/WKProcessPool.mm:
(-[WKProcessPool _registerURLSchemeAsCanDisplayOnlyIfCanRequest:]):
* UIProcess/API/Cocoa/WKProcessPoolPrivate.h:
* UIProcess/WebProcessPool.cpp:
(WebKit::WebProcessPool::initializeNewWebProcess):
(WebKit::WebProcessPool::registerURLSchemeAsCanDisplayOnlyIfCanRequest):
* UIProcess/WebProcessPool.h:
* WebProcess/WebProcess.cpp:
(WebKit::WebProcess::initializeWebProcess):
(WebKit::WebProcess::registerURLSchemeAsCanDisplayOnlyIfCanRequest const):
* WebProcess/WebProcess.h:
* WebProcess/WebProcess.messages.in:

Tools:

Adds unit tests for the modern Objective-C and C SPI to ensure we do not regress it.

We use the deprecated -[WKBrowsingContextController registerSchemeForCustomProtocol:]
in both the modern Objective-C API and C API tests to share code. Once we no longer
need to support the C API we should remove the tests and transition the modern Objective-
C tests to use -[WKWebViewConfiguration setURLSchemeHandler:forURLScheme:].

* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/WebKitCocoa/SchemeRegistry.mm: Added.
(+[EchoURLProtocol canInitWithRequest:]):
(+[EchoURLProtocol canonicalRequestForRequest:]):
(+[EchoURLProtocol requestIsCacheEquivalent:toRequest:]):
(-[EchoURLProtocol startLoading]):
(-[EchoURLProtocol stopLoading]):
(-[WKContextRegisterURLSchemeAsCanDisplayOnlyIfCanRequestLoadDelegate browsingContextController:didFailProvisionalLoadWithError:]):
(-[WKContextRegisterURLSchemeAsCanDisplayOnlyIfCanRequestLoadDelegate browsingContextControllerDidFinishLoad:]):
(TestWebKitAPI::TEST):

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (229868 => 229869)


--- trunk/Source/WebCore/ChangeLog	2018-03-22 22:02:58 UTC (rev 229868)
+++ trunk/Source/WebCore/ChangeLog	2018-03-22 22:10:38 UTC (rev 229869)
@@ -1,5 +1,17 @@
 2018-03-22  Daniel Bates  <[email protected]>
 
+        Expose SchemeRegistry::registerAsCanDisplayOnlyIfCanRequest() as WebKit SPI
+        https://bugs.webkit.org/show_bug.cgi?id=183907
+        <rdar://problem/38759127>
+
+        Reviewed by Alex Christensen.
+
+        Exports SchemeRegistry::registerAsCanDisplayOnlyIfCanRequest() so that we can use it from WebKit.
+
+        * platform/SchemeRegistry.h:
+
+2018-03-22  Daniel Bates  <[email protected]>
+
         CSS mask images should be retrieved using potentially CORS-enabled fetch
         https://bugs.webkit.org/show_bug.cgi?id=179983
         <rdar://problem/35678149>

Modified: trunk/Source/WebCore/platform/SchemeRegistry.h (229868 => 229869)


--- trunk/Source/WebCore/platform/SchemeRegistry.h	2018-03-22 22:02:58 UTC (rev 229868)
+++ trunk/Source/WebCore/platform/SchemeRegistry.h	2018-03-22 22:10:38 UTC (rev 229869)
@@ -66,7 +66,7 @@
     // Such schemes should delegate to SecurityOrigin::canRequest for any URL
     // passed to SecurityOrigin::canDisplay.
     static bool canDisplayOnlyIfCanRequest(const String& scheme);
-    static void registerAsCanDisplayOnlyIfCanRequest(const String& scheme);
+    WEBCORE_EXPORT static void registerAsCanDisplayOnlyIfCanRequest(const String& scheme);
 
     // Schemes against which _javascript_: URLs should not be allowed to run (stop
     // bookmarklets from running on sensitive pages). 

Modified: trunk/Source/WebKit/ChangeLog (229868 => 229869)


--- trunk/Source/WebKit/ChangeLog	2018-03-22 22:02:58 UTC (rev 229868)
+++ trunk/Source/WebKit/ChangeLog	2018-03-22 22:10:38 UTC (rev 229869)
@@ -1,3 +1,39 @@
+2018-03-22  Daniel Bates  <[email protected]>
+
+        Expose SchemeRegistry::registerAsCanDisplayOnlyIfCanRequest() as WebKit SPI
+        https://bugs.webkit.org/show_bug.cgi?id=183907
+        <rdar://problem/38759127>
+
+        Reviewed by Alex Christensen.
+
+        Adds both modern Objective-C SPI and C SPI to allow an embedding client to register a scheme
+        whose content should be displayed/loaded if and only if it can be requested. Disregarding an
+        app that enables universal access, by using this SPI WebKit will refuse to display cross-origin
+        content for the registered schemes.
+
+        We need to add C SPI for embedding clients that have not transitioned to the modern Objective-
+        C API/SPI.
+
+        * Shared/WebProcessCreationParameters.cpp:
+        (WebKit::WebProcessCreationParameters::encode const):
+        (WebKit::WebProcessCreationParameters::decode):
+        * Shared/WebProcessCreationParameters.h:
+        * UIProcess/API/C/WKContext.cpp:
+        (WKContextRegisterURLSchemeAsCanDisplayOnlyIfCanRequest):
+        * UIProcess/API/C/WKContextPrivate.h:
+        * UIProcess/API/Cocoa/WKProcessPool.mm:
+        (-[WKProcessPool _registerURLSchemeAsCanDisplayOnlyIfCanRequest:]):
+        * UIProcess/API/Cocoa/WKProcessPoolPrivate.h:
+        * UIProcess/WebProcessPool.cpp:
+        (WebKit::WebProcessPool::initializeNewWebProcess):
+        (WebKit::WebProcessPool::registerURLSchemeAsCanDisplayOnlyIfCanRequest):
+        * UIProcess/WebProcessPool.h:
+        * WebProcess/WebProcess.cpp:
+        (WebKit::WebProcess::initializeWebProcess):
+        (WebKit::WebProcess::registerURLSchemeAsCanDisplayOnlyIfCanRequest const):
+        * WebProcess/WebProcess.h:
+        * WebProcess/WebProcess.messages.in:
+
 2018-03-22  Tim Horton  <[email protected]>
 
         Improve readability of WebCore's OTHER_LDFLAGS

Modified: trunk/Source/WebKit/Shared/WebProcessCreationParameters.cpp (229868 => 229869)


--- trunk/Source/WebKit/Shared/WebProcessCreationParameters.cpp	2018-03-22 22:02:58 UTC (rev 229868)
+++ trunk/Source/WebKit/Shared/WebProcessCreationParameters.cpp	2018-03-22 22:10:38 UTC (rev 229869)
@@ -85,6 +85,7 @@
     encoder << urlSchemesRegisteredAsAlwaysRevalidated;
     encoder << urlSchemesRegisteredAsCachePartitioned;
     encoder << urlSchemesServiceWorkersCanHandle;
+    encoder << urlSchemesRegisteredAsCanDisplayOnlyIfCanRequest;
     encoder.encodeEnum(cacheModel);
     encoder << shouldAlwaysUseComplexTextCodePath;
     encoder << shouldEnableMemoryPressureReliefLogging;
@@ -281,6 +282,8 @@
         return false;
     if (!decoder.decode(parameters.urlSchemesServiceWorkersCanHandle))
         return false;
+    if (!decoder.decode(parameters.urlSchemesRegisteredAsCanDisplayOnlyIfCanRequest))
+        return false;
     if (!decoder.decodeEnum(parameters.cacheModel))
         return false;
     if (!decoder.decode(parameters.shouldAlwaysUseComplexTextCodePath))

Modified: trunk/Source/WebKit/Shared/WebProcessCreationParameters.h (229868 => 229869)


--- trunk/Source/WebKit/Shared/WebProcessCreationParameters.h	2018-03-22 22:02:58 UTC (rev 229868)
+++ trunk/Source/WebKit/Shared/WebProcessCreationParameters.h	2018-03-22 22:10:38 UTC (rev 229869)
@@ -108,6 +108,7 @@
     Vector<String> urlSchemesRegisteredAsAlwaysRevalidated;
     Vector<String> urlSchemesRegisteredAsCachePartitioned;
     Vector<String> urlSchemesServiceWorkersCanHandle;
+    Vector<String> urlSchemesRegisteredAsCanDisplayOnlyIfCanRequest;
 
     Vector<String> fontWhitelist;
     Vector<String> languages;

Modified: trunk/Source/WebKit/UIProcess/API/C/WKContext.cpp (229868 => 229869)


--- trunk/Source/WebKit/UIProcess/API/C/WKContext.cpp	2018-03-22 22:02:58 UTC (rev 229868)
+++ trunk/Source/WebKit/UIProcess/API/C/WKContext.cpp	2018-03-22 22:10:38 UTC (rev 229869)
@@ -387,6 +387,11 @@
     toImpl(contextRef)->registerURLSchemeAsCachePartitioned(toImpl(urlScheme)->string());
 }
 
+void WKContextRegisterURLSchemeAsCanDisplayOnlyIfCanRequest(WKContextRef contextRef, WKStringRef urlScheme)
+{
+    toImpl(contextRef)->registerURLSchemeAsCanDisplayOnlyIfCanRequest(toImpl(urlScheme)->string());
+}
+
 void WKContextSetDomainRelaxationForbiddenForURLScheme(WKContextRef contextRef, WKStringRef urlScheme)
 {
     toImpl(contextRef)->setDomainRelaxationForbiddenForURLScheme(toImpl(urlScheme)->string());

Modified: trunk/Source/WebKit/UIProcess/API/C/WKContextPrivate.h (229868 => 229869)


--- trunk/Source/WebKit/UIProcess/API/C/WKContextPrivate.h	2018-03-22 22:02:58 UTC (rev 229868)
+++ trunk/Source/WebKit/UIProcess/API/C/WKContextPrivate.h	2018-03-22 22:10:38 UTC (rev 229869)
@@ -63,6 +63,8 @@
 
 WK_EXPORT void WKContextRegisterURLSchemeAsCachePartitioned(WKContextRef context, WKStringRef urlScheme);
 
+WK_EXPORT void WKContextRegisterURLSchemeAsCanDisplayOnlyIfCanRequest(WKContextRef context, WKStringRef urlScheme);
+
 WK_EXPORT void WKContextSetDomainRelaxationForbiddenForURLScheme(WKContextRef context, WKStringRef urlScheme);
 
 WK_EXPORT void WKContextSetCanHandleHTTPSServerTrustEvaluation(WKContextRef context, bool value);

Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/WKProcessPool.mm (229868 => 229869)


--- trunk/Source/WebKit/UIProcess/API/Cocoa/WKProcessPool.mm	2018-03-22 22:02:58 UTC (rev 229868)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/WKProcessPool.mm	2018-03-22 22:10:38 UTC (rev 229869)
@@ -187,6 +187,11 @@
     _processPool->registerURLSchemeServiceWorkersCanHandle(scheme);
 }
 
+- (void)_registerURLSchemeAsCanDisplayOnlyIfCanRequest:(NSString *)scheme
+{
+    _processPool->registerURLSchemeAsCanDisplayOnlyIfCanRequest(scheme);
+}
+
 - (void)_setMaximumNumberOfProcesses:(NSUInteger)value
 {
     _processPool->setMaximumNumberOfProcesses(value);

Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/WKProcessPoolPrivate.h (229868 => 229869)


--- trunk/Source/WebKit/UIProcess/API/Cocoa/WKProcessPoolPrivate.h	2018-03-22 22:02:58 UTC (rev 229868)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/WKProcessPoolPrivate.h	2018-03-22 22:10:38 UTC (rev 229869)
@@ -75,6 +75,8 @@
 - (void)_addSupportedPlugin:(NSString *) domain named:(NSString *) name withMimeTypes: (NSSet<NSString *> *) mimeTypes withExtensions: (NSSet<NSString *> *) extensions WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
 - (void)_clearSupportedPlugins WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
 
+- (void)_registerURLSchemeAsCanDisplayOnlyIfCanRequest:(NSString *)scheme WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
+
 // Test only. Should be called only while no web content processes are running.
 - (void)_terminateStorageProcess;
 - (void)_terminateNetworkProcess;

Modified: trunk/Source/WebKit/UIProcess/WebProcessPool.cpp (229868 => 229869)


--- trunk/Source/WebKit/UIProcess/WebProcessPool.cpp	2018-03-22 22:02:58 UTC (rev 229868)
+++ trunk/Source/WebKit/UIProcess/WebProcessPool.cpp	2018-03-22 22:10:38 UTC (rev 229869)
@@ -807,6 +807,7 @@
     parameters.urlSchemesRegisteredAsAlwaysRevalidated = copyToVector(m_schemesToRegisterAsAlwaysRevalidated);
     parameters.urlSchemesRegisteredAsCachePartitioned = copyToVector(m_schemesToRegisterAsCachePartitioned);
     parameters.urlSchemesServiceWorkersCanHandle = copyToVector(m_schemesServiceWorkersCanHandle);
+    parameters.urlSchemesRegisteredAsCanDisplayOnlyIfCanRequest = copyToVector(m_schemesToRegisterAsCanDisplayOnlyIfCanRequest);
 
     parameters.shouldAlwaysUseComplexTextCodePath = m_alwaysUsesComplexTextCodePath;
     parameters.shouldUseFontSmoothing = m_shouldUseFontSmoothing;
@@ -1361,6 +1362,12 @@
         m_storageProcess->send(Messages::ChildProcess::RegisterURLSchemeServiceWorkersCanHandle(urlScheme), 0);
 }
 
+void WebProcessPool::registerURLSchemeAsCanDisplayOnlyIfCanRequest(const String& urlScheme)
+{
+    m_schemesToRegisterAsCanDisplayOnlyIfCanRequest.add(urlScheme);
+    sendToAllProcesses(Messages::WebProcess::RegisterURLSchemeAsCanDisplayOnlyIfCanRequest(urlScheme));
+}
+
 void WebProcessPool::setCacheModel(CacheModel cacheModel)
 {
     m_configuration->setCacheModel(cacheModel);

Modified: trunk/Source/WebKit/UIProcess/WebProcessPool.h (229868 => 229869)


--- trunk/Source/WebKit/UIProcess/WebProcessPool.h	2018-03-22 22:02:58 UTC (rev 229868)
+++ trunk/Source/WebKit/UIProcess/WebProcessPool.h	2018-03-22 22:10:38 UTC (rev 229869)
@@ -225,6 +225,8 @@
     void registerURLSchemeAsCORSEnabled(const String&);
     void registerURLSchemeAsCachePartitioned(const String&);
     void registerURLSchemeServiceWorkersCanHandle(const String&);
+    void registerURLSchemeAsCanDisplayOnlyIfCanRequest(const String&);
+
     void preconnectToServer(const WebCore::URL&);
 
     VisitedLinkStore& visitedLinkStore() { return m_visitedLinkStore.get(); }
@@ -555,6 +557,7 @@
     HashSet<String> m_schemesToRegisterAsAlwaysRevalidated;
     HashSet<String> m_schemesToRegisterAsCachePartitioned;
     HashSet<String> m_schemesServiceWorkersCanHandle;
+    HashSet<String> m_schemesToRegisterAsCanDisplayOnlyIfCanRequest;
 
     bool m_alwaysUsesComplexTextCodePath { false };
     bool m_shouldUseFontSmoothing { true };

Modified: trunk/Source/WebKit/WebProcess/WebProcess.cpp (229868 => 229869)


--- trunk/Source/WebKit/WebProcess/WebProcess.cpp	2018-03-22 22:02:58 UTC (rev 229868)
+++ trunk/Source/WebKit/WebProcess/WebProcess.cpp	2018-03-22 22:10:38 UTC (rev 229869)
@@ -371,6 +371,9 @@
     for (auto& scheme : parameters.urlSchemesServiceWorkersCanHandle)
         registerURLSchemeServiceWorkersCanHandle(scheme);
 
+    for (auto& scheme : parameters.urlSchemesRegisteredAsCanDisplayOnlyIfCanRequest)
+        registerURLSchemeAsCanDisplayOnlyIfCanRequest(scheme);
+
     setDefaultRequestTimeoutInterval(parameters.defaultRequestTimeoutInterval);
 
     setResourceLoadStatisticsEnabled(parameters.resourceLoadStatisticsEnabled);
@@ -477,6 +480,11 @@
     SchemeRegistry::registerURLSchemeAsCachePartitioned(urlScheme);
 }
 
+void WebProcess::registerURLSchemeAsCanDisplayOnlyIfCanRequest(const String& urlScheme) const
+{
+    SchemeRegistry::registerAsCanDisplayOnlyIfCanRequest(urlScheme);
+}
+
 void WebProcess::setDefaultRequestTimeoutInterval(double timeoutInterval)
 {
     ResourceRequest::setDefaultTimeoutInterval(timeoutInterval);

Modified: trunk/Source/WebKit/WebProcess/WebProcess.h (229868 => 229869)


--- trunk/Source/WebKit/WebProcess/WebProcess.h	2018-03-22 22:02:58 UTC (rev 229868)
+++ trunk/Source/WebKit/WebProcess/WebProcess.h	2018-03-22 22:10:38 UTC (rev 229869)
@@ -261,6 +261,7 @@
     void clearCachedCredentials();
 
     void platformTerminate();
+
     void registerURLSchemeAsEmptyDocument(const String&);
     void registerURLSchemeAsSecure(const String&) const;
     void registerURLSchemeAsBypassingContentSecurityPolicy(const String&) const;
@@ -271,6 +272,8 @@
     void registerURLSchemeAsCORSEnabled(const String&) const;
     void registerURLSchemeAsAlwaysRevalidated(const String&) const;
     void registerURLSchemeAsCachePartitioned(const String&) const;
+    void registerURLSchemeAsCanDisplayOnlyIfCanRequest(const String&) const;
+
     void setDefaultRequestTimeoutInterval(double);
     void setAlwaysUsesComplexTextCodePath(bool);
     void setShouldUseFontSmoothing(bool);

Modified: trunk/Source/WebKit/WebProcess/WebProcess.messages.in (229868 => 229869)


--- trunk/Source/WebKit/WebProcess/WebProcess.messages.in	2018-03-22 22:02:58 UTC (rev 229868)
+++ trunk/Source/WebKit/WebProcess/WebProcess.messages.in	2018-03-22 22:10:38 UTC (rev 229869)
@@ -28,6 +28,7 @@
 
     # Global preferences.
     SetCacheModel(uint32_t cacheModel)
+
     RegisterURLSchemeAsEmptyDocument(String scheme)
     RegisterURLSchemeAsSecure(String scheme)
     RegisterURLSchemeAsBypassingContentSecurityPolicy(String scheme)
@@ -37,6 +38,8 @@
     RegisterURLSchemeAsDisplayIsolated(String scheme)
     RegisterURLSchemeAsCORSEnabled(String scheme)
     RegisterURLSchemeAsCachePartitioned(String scheme)
+    RegisterURLSchemeAsCanDisplayOnlyIfCanRequest(String scheme)
+
     SetDefaultRequestTimeoutInterval(double timeoutInterval)
     SetAlwaysUsesComplexTextCodePath(bool alwaysUseComplexText)
     SetShouldUseFontSmoothing(bool useFontSmoothing)

Modified: trunk/Tools/ChangeLog (229868 => 229869)


--- trunk/Tools/ChangeLog	2018-03-22 22:02:58 UTC (rev 229868)
+++ trunk/Tools/ChangeLog	2018-03-22 22:10:38 UTC (rev 229869)
@@ -1,3 +1,29 @@
+2018-03-22  Daniel Bates  <[email protected]>
+
+        Expose SchemeRegistry::registerAsCanDisplayOnlyIfCanRequest() as WebKit SPI
+        https://bugs.webkit.org/show_bug.cgi?id=183907
+        <rdar://problem/38759127>
+
+        Reviewed by Alex Christensen.
+
+        Adds unit tests for the modern Objective-C and C SPI to ensure we do not regress it.
+
+        We use the deprecated -[WKBrowsingContextController registerSchemeForCustomProtocol:]
+        in both the modern Objective-C API and C API tests to share code. Once we no longer
+        need to support the C API we should remove the tests and transition the modern Objective-
+        C tests to use -[WKWebViewConfiguration setURLSchemeHandler:forURLScheme:].
+
+        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+        * TestWebKitAPI/Tests/WebKitCocoa/SchemeRegistry.mm: Added.
+        (+[EchoURLProtocol canInitWithRequest:]):
+        (+[EchoURLProtocol canonicalRequestForRequest:]):
+        (+[EchoURLProtocol requestIsCacheEquivalent:toRequest:]):
+        (-[EchoURLProtocol startLoading]):
+        (-[EchoURLProtocol stopLoading]):
+        (-[WKContextRegisterURLSchemeAsCanDisplayOnlyIfCanRequestLoadDelegate browsingContextController:didFailProvisionalLoadWithError:]):
+        (-[WKContextRegisterURLSchemeAsCanDisplayOnlyIfCanRequestLoadDelegate browsingContextControllerDidFinishLoad:]):
+        (TestWebKitAPI::TEST):
+
 2018-03-22  Adrian Perez de Castro  <[email protected]>
 
         [WPE] Enable WOFF2 support

Modified: trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (229868 => 229869)


--- trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2018-03-22 22:02:58 UTC (rev 229868)
+++ trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2018-03-22 22:10:38 UTC (rev 229869)
@@ -706,6 +706,7 @@
 		CDCFA7AA1E45183200C2433D /* SampleMap.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CDCFA7A91E45122F00C2433D /* SampleMap.cpp */; };
 		CDE195B51CFE0B880053D256 /* FullscreenTopContentInset.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = CDE195B21CFE0ADE0053D256 /* FullscreenTopContentInset.html */; };
 		CE06DF9B1E1851F200E570C9 /* SecurityOrigin.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CE06DF9A1E1851F200E570C9 /* SecurityOrigin.cpp */; };
+		CE0947372063223B003C9BA0 /* SchemeRegistry.mm in Sources */ = {isa = PBXBuildFile; fileRef = CE0947362063223B003C9BA0 /* SchemeRegistry.mm */; };
 		CE14F1A4181873B0001C2705 /* WillPerformClientRedirectToURLCrash.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = CE14F1A2181873B0001C2705 /* WillPerformClientRedirectToURLCrash.html */; };
 		CE1866491F72E8F100A0CAB6 /* MarkedText.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CE1866471F72E8F100A0CAB6 /* MarkedText.cpp */; };
 		CE3524F81B1431F60028A7C5 /* TextFieldDidBeginAndEndEditing_Bundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CE3524F21B142B8D0028A7C5 /* TextFieldDidBeginAndEndEditing_Bundle.cpp */; };
@@ -1834,6 +1835,7 @@
 		CDE195B21CFE0ADE0053D256 /* FullscreenTopContentInset.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = FullscreenTopContentInset.html; sourceTree = "<group>"; };
 		CDE195B31CFE0ADE0053D256 /* FullscreenTopContentInset.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = FullscreenTopContentInset.mm; sourceTree = "<group>"; };
 		CE06DF9A1E1851F200E570C9 /* SecurityOrigin.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SecurityOrigin.cpp; sourceTree = "<group>"; };
+		CE0947362063223B003C9BA0 /* SchemeRegistry.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = SchemeRegistry.mm; sourceTree = "<group>"; };
 		CE14F1A2181873B0001C2705 /* WillPerformClientRedirectToURLCrash.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; path = WillPerformClientRedirectToURLCrash.html; sourceTree = "<group>"; };
 		CE1866471F72E8F100A0CAB6 /* MarkedText.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = MarkedText.cpp; sourceTree = "<group>"; };
 		CE32C7C718184C4900CD8C28 /* WillPerformClientRedirectToURLCrash.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WillPerformClientRedirectToURLCrash.mm; sourceTree = "<group>"; };
@@ -2191,6 +2193,7 @@
 				CD9E292B1C90A71F000BB800 /* RequiresUserActionForPlayback.mm */,
 				51C8E1A41F26AC5400BF731B /* ResourceLoadStatistics.mm */,
 				A180C0F91EE67DF000468F47 /* RunOpenPanel.mm */,
+				CE0947362063223B003C9BA0 /* SchemeRegistry.mm */,
 				51EB12931FDF050500A5A1BD /* ServiceWorkerBasic.mm */,
 				37BCA61B1B596BA9002012CA /* ShouldOpenExternalURLsInNewWindowActions.mm */,
 				2D9A53AE1B31FA8D0074D5AA /* ShrinkToFit.mm */,
@@ -3654,6 +3657,7 @@
 				F418BE151F71B7DC001970E6 /* RoundedRectTests.cpp in Sources */,
 				A180C0FA1EE67DF000468F47 /* RunOpenPanel.mm in Sources */,
 				CDCFA7AA1E45183200C2433D /* SampleMap.cpp in Sources */,
+				CE0947372063223B003C9BA0 /* SchemeRegistry.mm in Sources */,
 				7CCE7F121A411AE600447C4C /* ScrollPinningBehaviors.cpp in Sources */,
 				F4C8797F2059D8D3009CD00B /* ScrollViewInsetTests.mm in Sources */,
 				CE06DF9B1E1851F200E570C9 /* SecurityOrigin.cpp in Sources */,

Added: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/SchemeRegistry.mm (0 => 229869)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/SchemeRegistry.mm	                        (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/SchemeRegistry.mm	2018-03-22 22:10:38 UTC (rev 229869)
@@ -0,0 +1,214 @@
+/*
+ * Copyright (C) 2018 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import "config.h"
+
+#if WK_API_ENABLED
+
+#import "PlatformUtilities.h"
+#import "Test.h"
+#import "TestNavigationDelegate.h"
+#import <WebKit/WKBrowsingContextController.h>
+#import <WebKit/WKProcessPoolPrivate.h>
+#import <wtf/RetainPtr.h>
+
+#if WK_HAVE_C_SPI
+#import "PlatformWebView.h"
+#import <WebKit/WKBrowsingContextLoadDelegate.h>
+#import <WebKit/WKContextPrivate.h>
+#import <WebKit/WKPageUIClient.h>
+#endif
+
+static NSString * const echoScheme = @"echo";
+static RetainPtr<NSURL> lastEchoedURL;
+
+@interface EchoURLProtocol : NSURLProtocol
+@end
+
+@implementation EchoURLProtocol
+
++ (BOOL)canInitWithRequest:(NSURLRequest *)request
+{
+    return [request.URL.scheme isEqualToString:echoScheme];
+}
+
++ (NSURLRequest *)canonicalRequestForRequest:(NSURLRequest *)request
+{
+    return request;
+}
+
++ (BOOL)requestIsCacheEquivalent:(NSURLRequest *)a toRequest:(NSURLRequest *)b
+{
+    return NO;
+}
+
+- (void)startLoading
+{
+    NSURL *requestURL = self.request.URL;
+    EXPECT_TRUE([requestURL.scheme isEqualToString:echoScheme]);
+
+    lastEchoedURL = requestURL;
+
+    NSData *data = "" dataUsingEncoding:NSASCIIStringEncoding];
+    auto response = adoptNS([[NSURLResponse alloc] initWithURL:self.request.URL MIMEType:@"text/html" expectedContentLength:[data length] textEncodingName:nil]);
+    [self.client URLProtocol:self didReceiveResponse:response.get() cacheStoragePolicy:NSURLCacheStorageNotAllowed];
+    [self.client URLProtocol:self didLoadData:data];
+    [self.client URLProtocolDidFinishLoading:self];
+}
+
+- (void)stopLoading
+{
+}
+
+@end
+
+#if WK_HAVE_C_SPI
+
+static bool didFinishLoad = false;
+
+@interface WKContextRegisterURLSchemeAsCanDisplayOnlyIfCanRequestLoadDelegate : NSObject <WKBrowsingContextLoadDelegate>
+@end
+
+@implementation WKContextRegisterURLSchemeAsCanDisplayOnlyIfCanRequestLoadDelegate
+
+- (void)browsingContextController:(WKBrowsingContextController *)sender didFailProvisionalLoadWithError:(NSError *)error
+{
+    didFinishLoad = true;
+}
+
+- (void)browsingContextControllerDidFinishLoad:(WKBrowsingContextController *)sender
+{
+    didFinishLoad = true;
+}
+
+@end
+
+#endif
+
+namespace TestWebKitAPI {
+
+TEST(WebKit, RegisterAsCanDisplayOnlyIfCanRequest_SameOriginLoad)
+{
+    @autoreleasepool {
+        [NSURLProtocol registerClass:[EchoURLProtocol class]];
+        [WKBrowsingContextController registerSchemeForCustomProtocol:echoScheme];
+
+        auto processPool = adoptNS([[WKProcessPool alloc] init]);
+        [processPool _registerURLSchemeAsCanDisplayOnlyIfCanRequest:echoScheme];
+
+        auto webViewConfiguration = adoptNS([[WKWebViewConfiguration alloc] init]);
+        [webViewConfiguration setProcessPool:processPool.get()];
+
+        auto webView = adoptNS([[WKWebView alloc] initWithFrame:CGRectZero configuration:webViewConfiguration.get()]);
+
+        NSString *htmlString = @"<!DOCTYPE html><body><script src=''></script>";
+        [webView loadHTMLString:htmlString baseURL:[NSURL URLWithString:@"echo://A"]];
+        [webView _test_waitForDidFinishNavigation];
+        EXPECT_WK_STREQ(@"echo://A/A_1", [lastEchoedURL absoluteString]);
+        lastEchoedURL = nullptr;
+
+        [WKBrowsingContextController unregisterSchemeForCustomProtocol:echoScheme];
+        [NSURLProtocol unregisterClass:[EchoURLProtocol class]];
+    }
+}
+
+TEST(WebKit, RegisterAsCanDisplayOnlyIfCanRequest_CrossOriginLoad)
+{
+    @autoreleasepool {
+        [NSURLProtocol registerClass:[EchoURLProtocol class]];
+        [WKBrowsingContextController registerSchemeForCustomProtocol:echoScheme];
+
+        auto processPool = adoptNS([[WKProcessPool alloc] init]);
+        [processPool _registerURLSchemeAsCanDisplayOnlyIfCanRequest:echoScheme];
+
+        auto webViewConfiguration = adoptNS([[WKWebViewConfiguration alloc] init]);
+        [webViewConfiguration setProcessPool:processPool.get()];
+
+        auto webView = adoptNS([[WKWebView alloc] initWithFrame:CGRectZero configuration:webViewConfiguration.get()]);
+
+        NSString *htmlString = @"<!DOCTYPE html><body><script src=''></script>";
+        [webView loadHTMLString:htmlString baseURL:[NSURL URLWithString:@"echo://B"]];
+        [webView _test_waitForDidFinishNavigation];
+        EXPECT_NULL(lastEchoedURL); // Script blocked
+        lastEchoedURL = nullptr;
+
+        [WKBrowsingContextController unregisterSchemeForCustomProtocol:echoScheme];
+        [NSURLProtocol unregisterClass:[EchoURLProtocol class]];
+    }
+}
+
+#if WK_HAVE_C_SPI
+
+TEST(WebKit, WKContextRegisterURLSchemeAsCanDisplayOnlyIfCanRequest_SameOriginLoad)
+{
+    @autoreleasepool {
+        [NSURLProtocol registerClass:[EchoURLProtocol class]];
+        [WKBrowsingContextController registerSchemeForCustomProtocol:echoScheme];
+
+        WKRetainPtr<WKContextRef> context = adoptWK(WKContextCreate());
+        WKContextRegisterURLSchemeAsCanDisplayOnlyIfCanRequest(context.get(), Util::toWK(echoScheme.UTF8String).get());
+
+        PlatformWebView webView { context.get() };
+        webView.platformView().browsingContextController.loadDelegate = [[WKContextRegisterURLSchemeAsCanDisplayOnlyIfCanRequestLoadDelegate alloc] init];
+        [webView.platformView().browsingContextController loadHTMLString:@"<!DOCTYPE html><body><script src=''></script>" baseURL:[NSURL URLWithString:@"echo://A"]];
+        Util::run(&didFinishLoad);
+        didFinishLoad = false;
+
+        EXPECT_WK_STREQ(@"echo://A/A_1", [lastEchoedURL absoluteString]);
+        lastEchoedURL = nullptr;
+
+        [WKBrowsingContextController unregisterSchemeForCustomProtocol:echoScheme];
+        [NSURLProtocol unregisterClass:[EchoURLProtocol class]];
+    }
+}
+
+TEST(WebKit, WKContextRegisterURLSchemeAsCanDisplayOnlyIfCanRequest_CrossOriginLoad)
+{
+    @autoreleasepool {
+        [NSURLProtocol registerClass:[EchoURLProtocol class]];
+        [WKBrowsingContextController registerSchemeForCustomProtocol:echoScheme];
+
+        WKRetainPtr<WKContextRef> context = adoptWK(WKContextCreate());
+        WKContextRegisterURLSchemeAsCanDisplayOnlyIfCanRequest(context.get(), Util::toWK(echoScheme.UTF8String).get());
+
+        PlatformWebView webView { context.get() };
+        webView.platformView().browsingContextController.loadDelegate = [[WKContextRegisterURLSchemeAsCanDisplayOnlyIfCanRequestLoadDelegate alloc] init];
+        [webView.platformView().browsingContextController loadHTMLString:@"<!DOCTYPE html><body><script src=''></script>" baseURL:[NSURL URLWithString:@"echo://B"]];
+        Util::run(&didFinishLoad);
+        didFinishLoad = false;
+
+        EXPECT_NULL(lastEchoedURL); // Script blocked
+        lastEchoedURL = nullptr;
+
+        [WKBrowsingContextController unregisterSchemeForCustomProtocol:echoScheme];
+        [NSURLProtocol unregisterClass:[EchoURLProtocol class]];
+    }
+}
+
+#endif // WK_HAVE_C_SPI
+
+} // namespace TestWebKitAPI
+
+#endif // WK_API_ENABLED
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to