Title: [213686] trunk/Source
Revision
213686
Author
[email protected]
Date
2017-03-09 16:38:20 -0800 (Thu, 09 Mar 2017)

Log Message

Add WKURLSchemeHandler API for handling custom protocols.
https://bugs.webkit.org/show_bug.cgi?id=169422

Reviewed by Tim Horton.

Source/WebCore:

* platform/URLParser.cpp:
(WebCore::URLParser::maybeCanonicalizeScheme):
(WebCore::URLParser::isSpecialScheme):
* platform/URLParser.h:

Source/WebKit2:

This introduces two new protocols to the WK2 API surface:
- WKURLSchemeHandler
- WKURLSchemeHandlerTask

By registering an object that conforms to the WKURLSchemeHandler protocol with a WKWebViewConfiguration an application will
be handed an object conforming to WKURLSchemeHandlerTask for each resource load in that WKWebView with a custom URL scheme.

Using that id <WKURLSchemeHandlerTask>, the application can communicate the data for the resource back to WebKit.

* Shared/API/APIObject.h:
* Shared/Cocoa/APIObject.mm:
(API::Object::newObject):

* Shared/WebPageCreationParameters.cpp:
(WebKit::WebPageCreationParameters::encode):
(WebKit::WebPageCreationParameters::decode):
* Shared/WebPageCreationParameters.h:

* UIProcess/API/APIURLSchemeHandlerTask.cpp:
(API::URLSchemeHandlerTask::create):
(API::URLSchemeHandlerTask::URLSchemeHandlerTask):
* UIProcess/API/APIURLSchemeHandlerTask.h:

Add the WKURLSchemeHandler @protocol:
* UIProcess/API/Cocoa/WKURLSchemeHandler.h: Added.

Add the WKURLSchemeHandlerTask @protocol, as well as WebKit's concrete implementation of it:
* UIProcess/API/Cocoa/WKURLSchemeHandlerTask.h: Added.
* UIProcess/API/Cocoa/WKURLSchemeHandlerTask.mm: Added.
(raiseExceptionIfNecessary):
(-[WKURLSchemeHandlerTaskImpl request]):
(-[WKURLSchemeHandlerTaskImpl didReceiveResponse:]):
(-[WKURLSchemeHandlerTaskImpl didReceiveData:]):
(-[WKURLSchemeHandlerTaskImpl didFinish]):
(-[WKURLSchemeHandlerTaskImpl didFailWithError:]):
(-[WKURLSchemeHandlerTaskImpl _apiObject]):
* UIProcess/API/Cocoa/WKURLSchemeHandlerTaskInternal.h:
(WebKit::wrapper):

* UIProcess/API/Cocoa/WKWebView.h:
* UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView _initializeWithConfiguration:]):
(-[WKWebView urlSchemeHandlerForURLScheme:]):
(+[WKWebView handlesURLScheme:]):

* UIProcess/API/Cocoa/WKWebViewConfiguration.h:
* UIProcess/API/Cocoa/WKWebViewConfiguration.mm:
(-[WKWebViewConfiguration copyWithZone:]):
(-[WKWebViewConfiguration setURLSchemeHandler:forURLScheme:]):
(-[WKWebViewConfiguration urlSchemeHandlerForURLScheme:]):
(-[WKWebViewConfiguration _urlSchemeHandlers]):
* UIProcess/API/Cocoa/WKWebViewConfigurationInternal.h:

* UIProcess/Cocoa/WebURLSchemeHandlerCocoa.h:
(WebKit::WebURLSchemeHandlerCocoa::apiHandler):
* UIProcess/Cocoa/WebURLSchemeHandlerCocoa.mm: Added.
(WebKit::WebURLSchemeHandlerCocoa::create):
(WebKit::WebURLSchemeHandlerCocoa::WebURLSchemeHandlerCocoa):
(WebKit::WebURLSchemeHandlerCocoa::platformStartTask):
(WebKit::WebURLSchemeHandlerCocoa::platformStopTask):

* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::creationParameters):
(WebKit::WebPageProxy::setURLSchemeHandlerForScheme):
(WebKit::WebPageProxy::urlSchemeHandlerForScheme):
(WebKit::WebPageProxy::startURLSchemeHandlerTask):
(WebKit::WebPageProxy::stopURLSchemeHandlerTask):
* UIProcess/WebPageProxy.h:
* UIProcess/WebPageProxy.messages.in:

* UIProcess/WebURLSchemeHandler.cpp:
(WebKit::generateWebURLSchemeHandlerIdentifier):
(WebKit::WebURLSchemeHandler::WebURLSchemeHandler):
(WebKit::WebURLSchemeHandler::~WebURLSchemeHandler):
(WebKit::WebURLSchemeHandler::startTask):
(WebKit::WebURLSchemeHandler::stopTask):
* UIProcess/WebURLSchemeHandler.h:
(WebKit::WebURLSchemeHandler::identifier):

* UIProcess/WebURLSchemeHandlerTask.cpp: Added.
(WebKit::WebURLSchemeHandlerTask::create):
(WebKit::WebURLSchemeHandlerTask::WebURLSchemeHandlerTask):
(WebKit::WebURLSchemeHandlerTask::didReceiveResponse):
(WebKit::WebURLSchemeHandlerTask::didReceiveData):
(WebKit::WebURLSchemeHandlerTask::didComplete):
(WebKit::WebURLSchemeHandlerTask::pageDestroyed):
(WebKit::WebURLSchemeHandlerTask::stop):
* UIProcess/WebURLSchemeHandlerTask.h: Added.
(WebKit::WebURLSchemeHandlerTask::identifier):
(WebKit::WebURLSchemeHandlerTask::request):

* WebProcess/Network/WebLoaderStrategy.cpp:
(WebKit::WebLoaderStrategy::scheduleLoad):
(WebKit::WebLoaderStrategy::remove):
* WebProcess/Network/WebLoaderStrategy.h:

* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::urlSchemeHandlerForScheme):
(WebKit::WebPage::registerURLSchemeHandler):
(WebKit::WebPage::urlSchemeHandlerTaskDidReceiveResponse):
(WebKit::WebPage::urlSchemeHandlerTaskDidReceiveData):
(WebKit::WebPage::urlSchemeHandlerTaskDidComplete):
* WebProcess/WebPage/WebPage.h:
* WebProcess/WebPage/WebPage.messages.in:

* WebProcess/WebPage/WebURLSchemeHandlerProxy.cpp: Added.
(WebKit::WebURLSchemeHandlerProxy::WebURLSchemeHandlerProxy):
(WebKit::WebURLSchemeHandlerProxy::~WebURLSchemeHandlerProxy):
(WebKit::WebURLSchemeHandlerProxy::startNewTask):
(WebKit::WebURLSchemeHandlerProxy::taskDidReceiveResponse):
(WebKit::WebURLSchemeHandlerProxy::taskDidReceiveData):
(WebKit::WebURLSchemeHandlerProxy::taskDidComplete):
* WebProcess/WebPage/WebURLSchemeHandlerProxy.h:
(WebKit::WebURLSchemeHandlerProxy::identifier):
(WebKit::WebURLSchemeHandlerProxy::page):

* WebProcess/WebPage/WebURLSchemeHandlerTaskProxy.cpp: Added.
(WebKit::WebURLSchemeHandlerTaskProxy::WebURLSchemeHandlerTaskProxy):
(WebKit::WebURLSchemeHandlerTaskProxy::startLoading):
(WebKit::WebURLSchemeHandlerTaskProxy::stopLoading):
(WebKit::WebURLSchemeHandlerTaskProxy::didReceiveResponse):
(WebKit::WebURLSchemeHandlerTaskProxy::didReceiveData):
(WebKit::WebURLSchemeHandlerTaskProxy::didComplete):
* WebProcess/WebPage/WebURLSchemeHandlerTaskProxy.h:
(WebKit::WebURLSchemeHandlerTaskProxy::request):

* WebKit2.xcodeproj/project.pbxproj:
* CMakeLists.txt:

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (213685 => 213686)


--- trunk/Source/WebCore/ChangeLog	2017-03-10 00:16:02 UTC (rev 213685)
+++ trunk/Source/WebCore/ChangeLog	2017-03-10 00:38:20 UTC (rev 213686)
@@ -1,3 +1,15 @@
+2017-03-09  Brady Eidson  <[email protected]>
+
+        Add WKURLSchemeHandler API for handling custom protocols.
+        https://bugs.webkit.org/show_bug.cgi?id=169422
+
+        Reviewed by Tim Horton.
+
+        * platform/URLParser.cpp:
+        (WebCore::URLParser::maybeCanonicalizeScheme):
+        (WebCore::URLParser::isSpecialScheme):
+        * platform/URLParser.h:
+
 2017-03-09  Dean Jackson  <[email protected]>
 
         WebGPU: Backend - Buffers

Modified: trunk/Source/WebCore/platform/URLParser.cpp (213685 => 213686)


--- trunk/Source/WebCore/platform/URLParser.cpp	2017-03-10 00:16:02 UTC (rev 213685)
+++ trunk/Source/WebCore/platform/URLParser.cpp	2017-03-10 00:38:20 UTC (rev 213686)
@@ -790,6 +790,28 @@
     }
 }
 
+std::optional<String> URLParser::maybeCanonicalizeScheme(const String& scheme)
+{
+    if (scheme.isEmpty())
+        return std::nullopt;
+
+    if (!isASCIIAlpha(scheme[0]))
+        return std::nullopt;
+
+    for (size_t i = 1; i < scheme.length(); ++i) {
+        if (isASCIIAlphanumeric(scheme[i]) || scheme[i] == '+' || scheme[i] == '-' || scheme[i] == '.')
+            continue;
+        return std::nullopt;
+    }
+
+    return scheme.convertToASCIILowercase();
+}
+
+bool URLParser::isSpecialScheme(const String& schemeArg)
+{
+    return scheme(schemeArg) != Scheme::NonSpecial;
+}
+
 enum class URLParser::URLPart {
     SchemeEnd,
     UserStart,

Modified: trunk/Source/WebCore/platform/URLParser.h (213685 => 213686)


--- trunk/Source/WebCore/platform/URLParser.h	2017-03-10 00:16:02 UTC (rev 213685)
+++ trunk/Source/WebCore/platform/URLParser.h	2017-03-10 00:38:20 UTC (rev 213686)
@@ -50,6 +50,9 @@
 
     static const UIDNA& internationalDomainNameTranscoder();
 
+    WEBCORE_EXPORT static bool isSpecialScheme(const String& scheme);
+    WEBCORE_EXPORT static std::optional<String> maybeCanonicalizeScheme(const String& scheme);
+
 private:
     static std::optional<uint16_t> defaultPortForProtocol(StringView);
     friend std::optional<uint16_t> defaultPortForProtocol(StringView);

Modified: trunk/Source/WebKit2/CMakeLists.txt (213685 => 213686)


--- trunk/Source/WebKit2/CMakeLists.txt	2017-03-10 00:16:02 UTC (rev 213685)
+++ trunk/Source/WebKit2/CMakeLists.txt	2017-03-10 00:38:20 UTC (rev 213686)
@@ -326,6 +326,8 @@
     UIProcess/WebProcessLifetimeTracker.cpp
     UIProcess/WebProcessPool.cpp
     UIProcess/WebProcessProxy.cpp
+    UIProcess/WebURLSchemeHandler.cpp
+    UIProcess/WebURLSchemeHandlerTask.cpp
     UIProcess/WebVibrationProvider.cpp
     UIProcess/WebVibrationProxy.cpp
     UIProcess/WebViewportAttributes.cpp
@@ -339,6 +341,7 @@
     UIProcess/API/APIProcessPoolConfiguration.cpp
     UIProcess/API/APIOpenPanelParameters.cpp
     UIProcess/API/APISessionState.cpp
+    UIProcess/API/APIURLSchemeHandlerTask.cpp
     UIProcess/API/APIUserContentExtension.cpp
     UIProcess/API/APIUserContentExtensionStore.cpp
     UIProcess/API/APIUserContentWorld.cpp
@@ -579,10 +582,10 @@
     WebProcess/WebPage/WebPage.cpp
     WebProcess/WebPage/WebPageGroupProxy.cpp
     WebProcess/WebPage/WebPageOverlay.cpp
+    WebProcess/WebPage/WebURLSchemeHandlerProxy.cpp
+    WebProcess/WebPage/WebURLSchemeHandlerTaskProxy.cpp
     WebProcess/WebPage/WebUndoStep.cpp
 
-
-
     ${NetworkProcess_COMMON_SOURCES}
 )
 

Modified: trunk/Source/WebKit2/ChangeLog (213685 => 213686)


--- trunk/Source/WebKit2/ChangeLog	2017-03-10 00:16:02 UTC (rev 213685)
+++ trunk/Source/WebKit2/ChangeLog	2017-03-10 00:38:20 UTC (rev 213686)
@@ -1,3 +1,139 @@
+2017-03-09  Brady Eidson  <[email protected]>
+
+        Add WKURLSchemeHandler API for handling custom protocols.
+        https://bugs.webkit.org/show_bug.cgi?id=169422
+
+        Reviewed by Tim Horton.
+
+        This introduces two new protocols to the WK2 API surface:
+        - WKURLSchemeHandler
+        - WKURLSchemeHandlerTask
+        
+        By registering an object that conforms to the WKURLSchemeHandler protocol with a WKWebViewConfiguration an application will
+        be handed an object conforming to WKURLSchemeHandlerTask for each resource load in that WKWebView with a custom URL scheme.
+        
+        Using that id <WKURLSchemeHandlerTask>, the application can communicate the data for the resource back to WebKit.
+        
+        * Shared/API/APIObject.h:
+        * Shared/Cocoa/APIObject.mm:
+        (API::Object::newObject):
+
+        * Shared/WebPageCreationParameters.cpp:
+        (WebKit::WebPageCreationParameters::encode):
+        (WebKit::WebPageCreationParameters::decode):
+        * Shared/WebPageCreationParameters.h:
+
+        * UIProcess/API/APIURLSchemeHandlerTask.cpp: 
+        (API::URLSchemeHandlerTask::create):
+        (API::URLSchemeHandlerTask::URLSchemeHandlerTask):
+        * UIProcess/API/APIURLSchemeHandlerTask.h: 
+
+        Add the WKURLSchemeHandler @protocol:
+        * UIProcess/API/Cocoa/WKURLSchemeHandler.h: Added.
+
+        Add the WKURLSchemeHandlerTask @protocol, as well as WebKit's concrete implementation of it:
+        * UIProcess/API/Cocoa/WKURLSchemeHandlerTask.h: Added.
+        * UIProcess/API/Cocoa/WKURLSchemeHandlerTask.mm: Added.
+        (raiseExceptionIfNecessary):
+        (-[WKURLSchemeHandlerTaskImpl request]):
+        (-[WKURLSchemeHandlerTaskImpl didReceiveResponse:]):
+        (-[WKURLSchemeHandlerTaskImpl didReceiveData:]):
+        (-[WKURLSchemeHandlerTaskImpl didFinish]):
+        (-[WKURLSchemeHandlerTaskImpl didFailWithError:]):
+        (-[WKURLSchemeHandlerTaskImpl _apiObject]):
+        * UIProcess/API/Cocoa/WKURLSchemeHandlerTaskInternal.h: 
+        (WebKit::wrapper):
+
+        * UIProcess/API/Cocoa/WKWebView.h:
+        * UIProcess/API/Cocoa/WKWebView.mm:
+        (-[WKWebView _initializeWithConfiguration:]):
+        (-[WKWebView urlSchemeHandlerForURLScheme:]):
+        (+[WKWebView handlesURLScheme:]):
+
+        * UIProcess/API/Cocoa/WKWebViewConfiguration.h:
+        * UIProcess/API/Cocoa/WKWebViewConfiguration.mm:
+        (-[WKWebViewConfiguration copyWithZone:]):
+        (-[WKWebViewConfiguration setURLSchemeHandler:forURLScheme:]):
+        (-[WKWebViewConfiguration urlSchemeHandlerForURLScheme:]):
+        (-[WKWebViewConfiguration _urlSchemeHandlers]):
+        * UIProcess/API/Cocoa/WKWebViewConfigurationInternal.h:
+
+        * UIProcess/Cocoa/WebURLSchemeHandlerCocoa.h: 
+        (WebKit::WebURLSchemeHandlerCocoa::apiHandler):
+        * UIProcess/Cocoa/WebURLSchemeHandlerCocoa.mm: Added.
+        (WebKit::WebURLSchemeHandlerCocoa::create):
+        (WebKit::WebURLSchemeHandlerCocoa::WebURLSchemeHandlerCocoa):
+        (WebKit::WebURLSchemeHandlerCocoa::platformStartTask):
+        (WebKit::WebURLSchemeHandlerCocoa::platformStopTask):
+
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::creationParameters):
+        (WebKit::WebPageProxy::setURLSchemeHandlerForScheme):
+        (WebKit::WebPageProxy::urlSchemeHandlerForScheme):
+        (WebKit::WebPageProxy::startURLSchemeHandlerTask):
+        (WebKit::WebPageProxy::stopURLSchemeHandlerTask):
+        * UIProcess/WebPageProxy.h:
+        * UIProcess/WebPageProxy.messages.in:
+
+        * UIProcess/WebURLSchemeHandler.cpp: 
+        (WebKit::generateWebURLSchemeHandlerIdentifier):
+        (WebKit::WebURLSchemeHandler::WebURLSchemeHandler):
+        (WebKit::WebURLSchemeHandler::~WebURLSchemeHandler):
+        (WebKit::WebURLSchemeHandler::startTask):
+        (WebKit::WebURLSchemeHandler::stopTask):
+        * UIProcess/WebURLSchemeHandler.h: 
+        (WebKit::WebURLSchemeHandler::identifier):
+
+        * UIProcess/WebURLSchemeHandlerTask.cpp: Added.
+        (WebKit::WebURLSchemeHandlerTask::create):
+        (WebKit::WebURLSchemeHandlerTask::WebURLSchemeHandlerTask):
+        (WebKit::WebURLSchemeHandlerTask::didReceiveResponse):
+        (WebKit::WebURLSchemeHandlerTask::didReceiveData):
+        (WebKit::WebURLSchemeHandlerTask::didComplete):
+        (WebKit::WebURLSchemeHandlerTask::pageDestroyed):
+        (WebKit::WebURLSchemeHandlerTask::stop):
+        * UIProcess/WebURLSchemeHandlerTask.h: Added.
+        (WebKit::WebURLSchemeHandlerTask::identifier):
+        (WebKit::WebURLSchemeHandlerTask::request):
+
+        * WebProcess/Network/WebLoaderStrategy.cpp:
+        (WebKit::WebLoaderStrategy::scheduleLoad):
+        (WebKit::WebLoaderStrategy::remove):
+        * WebProcess/Network/WebLoaderStrategy.h:
+
+        * WebProcess/WebPage/WebPage.cpp:
+        (WebKit::WebPage::urlSchemeHandlerForScheme):
+        (WebKit::WebPage::registerURLSchemeHandler):
+        (WebKit::WebPage::urlSchemeHandlerTaskDidReceiveResponse):
+        (WebKit::WebPage::urlSchemeHandlerTaskDidReceiveData):
+        (WebKit::WebPage::urlSchemeHandlerTaskDidComplete):
+        * WebProcess/WebPage/WebPage.h:
+        * WebProcess/WebPage/WebPage.messages.in:
+
+        * WebProcess/WebPage/WebURLSchemeHandlerProxy.cpp: Added.
+        (WebKit::WebURLSchemeHandlerProxy::WebURLSchemeHandlerProxy):
+        (WebKit::WebURLSchemeHandlerProxy::~WebURLSchemeHandlerProxy):
+        (WebKit::WebURLSchemeHandlerProxy::startNewTask):
+        (WebKit::WebURLSchemeHandlerProxy::taskDidReceiveResponse):
+        (WebKit::WebURLSchemeHandlerProxy::taskDidReceiveData):
+        (WebKit::WebURLSchemeHandlerProxy::taskDidComplete):
+        * WebProcess/WebPage/WebURLSchemeHandlerProxy.h:
+        (WebKit::WebURLSchemeHandlerProxy::identifier):
+        (WebKit::WebURLSchemeHandlerProxy::page):
+
+        * WebProcess/WebPage/WebURLSchemeHandlerTaskProxy.cpp: Added.
+        (WebKit::WebURLSchemeHandlerTaskProxy::WebURLSchemeHandlerTaskProxy):
+        (WebKit::WebURLSchemeHandlerTaskProxy::startLoading):
+        (WebKit::WebURLSchemeHandlerTaskProxy::stopLoading):
+        (WebKit::WebURLSchemeHandlerTaskProxy::didReceiveResponse):
+        (WebKit::WebURLSchemeHandlerTaskProxy::didReceiveData):
+        (WebKit::WebURLSchemeHandlerTaskProxy::didComplete):
+        * WebProcess/WebPage/WebURLSchemeHandlerTaskProxy.h:
+        (WebKit::WebURLSchemeHandlerTaskProxy::request):
+
+        * WebKit2.xcodeproj/project.pbxproj:
+        * CMakeLists.txt:
+
 2017-03-09  Joseph Pecoraro  <[email protected]>
 
         Unreviewed follow-up to r213682.

Modified: trunk/Source/WebKit2/Shared/API/APIObject.h (213685 => 213686)


--- trunk/Source/WebKit2/Shared/API/APIObject.h	2017-03-10 00:16:02 UTC (rev 213685)
+++ trunk/Source/WebKit2/Shared/API/APIObject.h	2017-03-10 00:38:20 UTC (rev 213686)
@@ -144,6 +144,7 @@
         RunJavaScriptConfirmResultListener,
         RunJavaScriptPromptResultListener,
         TextChecker,
+        URLSchemeHandlerTask,
         UserContentController,
         UserContentExtension,
         UserContentExtensionStore,

Modified: trunk/Source/WebKit2/Shared/Cocoa/APIObject.mm (213685 => 213686)


--- trunk/Source/WebKit2/Shared/Cocoa/APIObject.mm	2017-03-10 00:16:02 UTC (rev 213685)
+++ trunk/Source/WebKit2/Shared/Cocoa/APIObject.mm	2017-03-10 00:38:20 UTC (rev 213686)
@@ -51,6 +51,7 @@
 #import "WKPreferencesInternal.h"
 #import "WKProcessPoolInternal.h"
 #import "WKSecurityOriginInternal.h"
+#import "WKURLSchemeHandlerTaskInternal.h"
 #import "WKUserContentControllerInternal.h"
 #import "WKUserScriptInternal.h"
 #import "WKWebProcessPlugInBrowserContextControllerInternal.h"
@@ -225,6 +226,10 @@
         wrapper = NSAllocateObject([WKNSURLRequest class], size, nullptr);
         break;
 
+    case Type::URLSchemeHandlerTask:
+        wrapper = [WKURLSchemeHandlerTaskImpl alloc];
+        break;
+
     case Type::UserContentController:
         wrapper = [WKUserContentController alloc];
         break;

Modified: trunk/Source/WebKit2/Shared/WebPageCreationParameters.cpp (213685 => 213686)


--- trunk/Source/WebKit2/Shared/WebPageCreationParameters.cpp	2017-03-10 00:16:02 UTC (rev 213685)
+++ trunk/Source/WebKit2/Shared/WebPageCreationParameters.cpp	2017-03-10 00:38:20 UTC (rev 213686)
@@ -93,6 +93,7 @@
     encoder.encodeEnum(userInterfaceLayoutDirection);
     encoder.encodeEnum(observedLayoutMilestones);
     encoder << overrideContentSecurityPolicy;
+    encoder << urlSchemeHandlers;
 #if ENABLE(WEB_RTC)
     encoder << iceCandidateFilteringEnabled;
 #if USE(LIBWEBRTC)
@@ -221,6 +222,9 @@
     if (!decoder.decode(parameters.overrideContentSecurityPolicy))
         return false;
 
+    if (!decoder.decode(parameters.urlSchemeHandlers))
+        return false;
+
 #if ENABLE(WEB_RTC)
     if (!decoder.decode(parameters.iceCandidateFilteringEnabled))
         return false;

Modified: trunk/Source/WebKit2/Shared/WebPageCreationParameters.h (213685 => 213686)


--- trunk/Source/WebKit2/Shared/WebPageCreationParameters.h	2017-03-10 00:16:02 UTC (rev 213685)
+++ trunk/Source/WebKit2/Shared/WebPageCreationParameters.h	2017-03-10 00:38:20 UTC (rev 213686)
@@ -42,6 +42,7 @@
 #include <WebCore/ScrollTypes.h>
 #include <WebCore/SessionID.h>
 #include <WebCore/UserInterfaceLayoutDirection.h>
+#include <wtf/HashMap.h>
 #include <wtf/text/WTFString.h>
 
 #if PLATFORM(MAC)
@@ -146,6 +147,8 @@
 
     String overrideContentSecurityPolicy;
 
+    HashMap<String, uint64_t> urlSchemeHandlers;
+
 #if ENABLE(WEB_RTC)
     bool iceCandidateFilteringEnabled { true };
 #if USE(LIBWEBRTC)

Copied: trunk/Source/WebKit2/UIProcess/API/APIURLSchemeHandlerTask.cpp (from rev 213685, trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebViewConfigurationInternal.h) (0 => 213686)


--- trunk/Source/WebKit2/UIProcess/API/APIURLSchemeHandlerTask.cpp	                        (rev 0)
+++ trunk/Source/WebKit2/UIProcess/API/APIURLSchemeHandlerTask.cpp	2017-03-10 00:38:20 UTC (rev 213686)
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2017 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 "APIURLSchemeHandlerTask.h"
+
+#include "WebURLSchemeHandler.h"
+#include "WebURLSchemeHandlerTask.h"
+
+namespace API {
+
+Ref<URLSchemeHandlerTask> URLSchemeHandlerTask::create(WebKit::WebURLSchemeHandlerTask& webURLSchemeHandlerTask)
+{
+    return adoptRef(*new URLSchemeHandlerTask(webURLSchemeHandlerTask));
+}
+
+URLSchemeHandlerTask::URLSchemeHandlerTask(WebKit::WebURLSchemeHandlerTask& webURLSchemeHandlerTask)
+    : m_webURLSchemeHandlerTask(webURLSchemeHandlerTask)
+{
+}
+
+}

Copied: trunk/Source/WebKit2/UIProcess/API/APIURLSchemeHandlerTask.h (from rev 213685, trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebViewConfigurationInternal.h) (0 => 213686)


--- trunk/Source/WebKit2/UIProcess/API/APIURLSchemeHandlerTask.h	                        (rev 0)
+++ trunk/Source/WebKit2/UIProcess/API/APIURLSchemeHandlerTask.h	2017-03-10 00:38:20 UTC (rev 213686)
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2017 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 "APIObject.h"
+
+namespace WebKit {
+class WebURLSchemeHandlerTask;
+}
+
+namespace API {
+
+class URLSchemeHandlerTask final : public ObjectImpl<Object::Type::URLSchemeHandlerTask> {
+public:
+    static Ref<URLSchemeHandlerTask> create(WebKit::WebURLSchemeHandlerTask&);
+
+    WebKit::WebURLSchemeHandlerTask& task() { return m_webURLSchemeHandlerTask.get(); }
+
+private:
+    URLSchemeHandlerTask(WebKit::WebURLSchemeHandlerTask&);
+
+    Ref<WebKit::WebURLSchemeHandlerTask> m_webURLSchemeHandlerTask;
+};
+
+}

Added: trunk/Source/WebKit2/UIProcess/API/Cocoa/WKURLSchemeHandler.h (0 => 213686)


--- trunk/Source/WebKit2/UIProcess/API/Cocoa/WKURLSchemeHandler.h	                        (rev 0)
+++ trunk/Source/WebKit2/UIProcess/API/Cocoa/WKURLSchemeHandler.h	2017-03-10 00:38:20 UTC (rev 213686)
@@ -0,0 +1,64 @@
+/*
+ * Copyright (C) 2017 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 <WebKit/WKFoundation.h>
+
+#if WK_API_ENABLED
+
+#import <Foundation/Foundation.h>
+
+NS_ASSUME_NONNULL_BEGIN
+
+@class WKWebView;
+@protocol WKURLSchemeHandlerTask;
+
+/*! A class conforming to the WKURLSchemeHandler protocol provides methods for
+ loading resources with URL schemes that WebKit doesn't know how to handle itself.
+ */
+WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA))
+@protocol WKURLSchemeHandler <NSObject>
+
+/*! @abstract Notifies your app to start loading the data for a particular resource 
+ represented by the URL scheme handler task.
+ @param webView The web view invoking the method.
+ @param urlSchemeHandlerTask The task that your app should start loading data for.
+ */
+- (void)webView:(WKWebView *)webView startTask:(id <WKURLSchemeHandlerTask>)urlSchemeHandlerTask;
+
+/*! @abstract Notifies your app to stop handling a URL scheme handler task.
+ @param webView The web view invoking the method.
+ @param urlSchemeHandlerTask The task that your app should stop handling.
+ @discussion After your app is told to stop loading data for a URL scheme handler task
+ it must not perform any callbacks for that task.
+ An exception will be thrown if any callbacks are made on the URL scheme handler task
+ after your app has been told to stop loading for it.
+ */
+- (void)webView:(WKWebView *)webView stopTask:(id <WKURLSchemeHandlerTask>)urlSchemeHandlerTask;
+
+@end
+
+NS_ASSUME_NONNULL_END
+
+#endif

Added: trunk/Source/WebKit2/UIProcess/API/Cocoa/WKURLSchemeHandlerTask.h (0 => 213686)


--- trunk/Source/WebKit2/UIProcess/API/Cocoa/WKURLSchemeHandlerTask.h	                        (rev 0)
+++ trunk/Source/WebKit2/UIProcess/API/Cocoa/WKURLSchemeHandlerTask.h	2017-03-10 00:38:20 UTC (rev 213686)
@@ -0,0 +1,78 @@
+/*
+ * Copyright (C) 2017 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 <WebKit/WKFoundation.h>
+
+#if WK_API_ENABLED
+
+#import <Foundation/Foundation.h>
+
+NS_ASSUME_NONNULL_BEGIN
+
+WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA))
+@protocol WKURLSchemeHandlerTask <NSObject>
+
+/*! @abstract The request to load for this task.
+ */
+@property (nonatomic, readonly, copy) NSURLRequest *request;
+
+/*! @abstract Set the current response object for the task.
+ @param response The response to use.
+ @discussion This method must be called at least once for each URL scheme handler task.
+ An exception will be thrown if you try to send a new response object after the task has already been completed.
+ An exception will be thrown if your app has been told to stop loading this task via the registered WKURLSchemeHandler object.
+ */
+- (void)didReceiveResponse:(NSURLResponse *)response;
+
+/*! @abstract Add received data to the task.
+ @param data The data to add.
+ @discussion After a URL scheme handler task's final response object is received you should
+ start sending it data.
+ Each time this method is called the data you send will be appended to all previous data.
+ An exception will be thrown if you try to send the task any data before sending it a response.
+ An exception will be thrown if you try to send the task any data after the task has already been completed.
+ An exception will be thrown if your app has been told to stop loading this task via the registered WKURLSchemeHandler object.
+ */
+- (void)didReceiveData:(NSData *)data;
+
+/*! @abstract Mark the task as successfully completed.
+ @discussion An exception will be thrown if you try to finish the task before sending it a response.
+ An exception will be thrown if you try to mark a task completed after it has already been marked completed or failed.
+ An exception will be thrown if your app has been told to stop loading this task via the registered WKURLSchemeHandler object.
+ */
+- (void)didFinish;
+
+/*! @abstract Mark the task as failed.
+ @param error A description of the error that caused the task to fail.
+ @discussion  An exception will be thrown if you try to mark a task failed after it has already been marked completed or failed.
+ An exception will be thrown if your app has been told to stop loading this task via the registered WKURLSchemeHandler object.
+ */
+- (void)didFailWithError:(NSError *)error;
+
+@end
+
+NS_ASSUME_NONNULL_END
+
+#endif

Added: trunk/Source/WebKit2/UIProcess/API/Cocoa/WKURLSchemeHandlerTask.mm (0 => 213686)


--- trunk/Source/WebKit2/UIProcess/API/Cocoa/WKURLSchemeHandlerTask.mm	                        (rev 0)
+++ trunk/Source/WebKit2/UIProcess/API/Cocoa/WKURLSchemeHandlerTask.mm	2017-03-10 00:38:20 UTC (rev 213686)
@@ -0,0 +1,98 @@
+/*
+ * Copyright (C) 2017 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import "config.h"
+#import "WKURLSchemeHandlerTaskInternal.h"
+
+#if WK_API_ENABLED
+
+#include "WebURLSchemeHandlerTask.h"
+#include <WebCore/ResourceError.h>
+#include <WebCore/ResourceResponse.h>
+#include <WebCore/SharedBuffer.h>
+
+using namespace WebCore;
+
+static void raiseExceptionIfNecessary(WebKit::WebURLSchemeHandlerTask::ExceptionType exceptionType)
+{
+    switch (exceptionType) {
+    case WebKit::WebURLSchemeHandlerTask::ExceptionType::None:
+        return;
+    case WebKit::WebURLSchemeHandlerTask::ExceptionType::TaskAlreadyStopped:
+        [NSException raise:NSInternalInconsistencyException format:@"This task has already been stopped"];
+        break;
+    case WebKit::WebURLSchemeHandlerTask::ExceptionType::CompleteAlreadyCalled:
+        [NSException raise:NSInternalInconsistencyException format:@"[WKURLSchemeHandlerTask taskDidCompleteWithError:] has already been called for this task"];
+        break;
+    case WebKit::WebURLSchemeHandlerTask::ExceptionType::DataAlreadySent:
+        [NSException raise:NSInternalInconsistencyException format:@"[WKURLSchemeHandlerTask taskDidReceiveData:] has already been called for this task"];
+        break;
+    case WebKit::WebURLSchemeHandlerTask::ExceptionType::NoResponseSent:
+        [NSException raise:NSInternalInconsistencyException format:@"No response has been sent for this task"];
+        break;
+    }
+}
+
+@implementation WKURLSchemeHandlerTaskImpl
+
+- (NSURLRequest *)request
+{
+    return _urlSchemeHandlerTask->task().request().nsURLRequest(DoNotUpdateHTTPBody);
+}
+
+- (void)didReceiveResponse:(NSURLResponse *)response
+{
+    auto result = _urlSchemeHandlerTask->task().didReceiveResponse(response);
+    raiseExceptionIfNecessary(result);
+}
+
+- (void)didReceiveData:(NSData *)data
+{
+    auto result = _urlSchemeHandlerTask->task().didReceiveData(WebCore::SharedBuffer::wrapNSData(data));
+    raiseExceptionIfNecessary(result);
+}
+
+- (void)didFinish
+{
+    auto result = _urlSchemeHandlerTask->task().didComplete({ });
+    raiseExceptionIfNecessary(result);
+}
+
+- (void)didFailWithError:(NSError *)error
+{
+    auto result = _urlSchemeHandlerTask->task().didComplete(error);
+    raiseExceptionIfNecessary(result);
+}
+
+#pragma mark WKObject protocol implementation
+
+- (API::Object&)_apiObject
+{
+    return *_urlSchemeHandlerTask;
+}
+
+@end
+
+#endif // #if WK_API_ENABLED

Copied: trunk/Source/WebKit2/UIProcess/API/Cocoa/WKURLSchemeHandlerTaskInternal.h (from rev 213685, trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebViewConfigurationInternal.h) (0 => 213686)


--- trunk/Source/WebKit2/UIProcess/API/Cocoa/WKURLSchemeHandlerTaskInternal.h	                        (rev 0)
+++ trunk/Source/WebKit2/UIProcess/API/Cocoa/WKURLSchemeHandlerTaskInternal.h	2017-03-10 00:38:20 UTC (rev 213686)
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2017 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 "WKURLSchemeHandlerTask.h"
+
+#if WK_API_ENABLED
+
+#import "APIURLSchemeHandlerTask.h"
+#import "WKObject.h"
+
+@interface WKURLSchemeHandlerTaskImpl : NSObject <WKURLSchemeHandlerTask>
+@end
+
+namespace WebKit {
+
+inline id<WKURLSchemeHandlerTask> wrapper(API::URLSchemeHandlerTask& urlSchemeHandlerTask)
+{
+    ASSERT([urlSchemeHandlerTask.wrapper() isKindOfClass:[WKURLSchemeHandlerTaskImpl class]]);
+    return (id<WKURLSchemeHandlerTask>)urlSchemeHandlerTask.wrapper();
+}
+
+}
+
+@interface WKURLSchemeHandlerTaskImpl () <WKObject> {
+@package
+    API::ObjectStorage<API::URLSchemeHandlerTask> _urlSchemeHandlerTask;
+}
+@end
+
+#endif // WK_API_ENABLED

Modified: trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.h (213685 => 213686)


--- trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.h	2017-03-10 00:16:02 UTC (rev 213685)
+++ trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.h	2017-03-10 00:38:20 UTC (rev 213686)
@@ -279,6 +279,11 @@
 
 #endif
 
+/* @abstract Checks whether or not WKWebViews handle the given URL scheme by default.
+ @param scheme The URL scheme to check.
+ */
++ (BOOL)handlesURLScheme:(NSString *)urlScheme WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
+
 @end
 
 #if !TARGET_OS_IPHONE

Modified: trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm (213685 => 213686)


--- trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm	2017-03-10 00:16:02 UTC (rev 213685)
+++ trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm	2017-03-10 00:38:20 UTC (rev 213686)
@@ -78,6 +78,7 @@
 #import "WebPreferencesKeys.h"
 #import "WebProcessPool.h"
 #import "WebProcessProxy.h"
+#import "WebURLSchemeHandlerCocoa.h"
 #import "WebViewImpl.h"
 #import "_WKDiagnosticLoggingDelegate.h"
 #import "_WKFindDelegate.h"
@@ -100,6 +101,7 @@
 #import <WebCore/SQLiteDatabaseTracker.h>
 #import <WebCore/Settings.h>
 #import <WebCore/TextStream.h>
+#import <WebCore/URLParser.h>
 #import <WebCore/ValidationBubble.h>
 #import <WebCore/WritingMode.h>
 #import <wtf/HashMap.h>
@@ -576,6 +578,10 @@
     [self _setUpSQLiteDatabaseTrackerClient];
 #endif
 
+    auto *handlers = _configuration.get()._urlSchemeHandlers;
+    for (NSString *key in handlers)
+        _page->setURLSchemeHandlerForScheme(WebKit::WebURLSchemeHandlerCocoa::create(handlers[key]), key);
+
     pageToViewMap().add(_page.get(), self);
 }
 
@@ -3530,6 +3536,17 @@
 
 #endif // HAVE(TOUCH_BAR)
 
+- (id <WKURLSchemeHandler>)urlSchemeHandlerForURLScheme:(NSString *)urlScheme
+{
+    auto* handler = static_cast<WebKit::WebURLSchemeHandlerCocoa*>(_page->urlSchemeHandlerForScheme(urlScheme));
+    return handler ? handler->apiHandler() : nil;
+}
+
++ (BOOL)handlesURLScheme:(NSString *)urlScheme
+{
+    return WebCore::URLParser::isSpecialScheme(urlScheme);
+}
+
 @end
 
 @implementation WKWebView (WKPrivate)

Modified: trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebViewConfiguration.h (213685 => 213686)


--- trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebViewConfiguration.h	2017-03-10 00:16:02 UTC (rev 213685)
+++ trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebViewConfiguration.h	2017-03-10 00:38:20 UTC (rev 213686)
@@ -36,6 +36,7 @@
 @class WKProcessPool;
 @class WKUserContentController;
 @class WKWebsiteDataStore;
+@protocol WKURLSchemeHandler;
 
 #if TARGET_OS_IPHONE
 
@@ -175,6 +176,25 @@
 
 #endif
 
+/* @abstract Sets the URL scheme handler object for the given URL scheme.
+ @param urlSchemeHandler The object to register.
+ @param scheme The URL scheme the object will handle.
+ @discussion Each URL scheme can only have one URL scheme handler object registered.
+ An exception will be thrown if you try to register an object for a particular URL scheme more than once.
+ URL schemes are case insensitive. e.g. "myprotocol" and "MyProtocol" are equivalent.
+ Valid URL schemes must start with an ASCII letter and can only contain ASCII letters, numbers, the '+' character,
+ the '-' character, and the '.' character.
+ An exception will be thrown if you try to register a URL scheme handler for an invalid URL scheme.
+ An exception will be thrown if you try to register a URL scheme handler for a URL scheme that WebKit handles internally.
+ You can use +[WKWebView handlesURLScheme:] to check the availability of a given URL scheme.
+ */
+- (void)setURLSchemeHandler:(nullable id <WKURLSchemeHandler>)urlSchemeHandler forURLScheme:(NSString *)urlScheme WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
+
+/* @abstract Returns the currently registered URL scheme handler object for the given URL scheme.
+ @param scheme The URL scheme to lookup.
+ */
+- (nullable id <WKURLSchemeHandler>)urlSchemeHandlerForURLScheme:(NSString *)urlScheme WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
+
 @end
 
 @interface WKWebViewConfiguration (WKDeprecated)

Modified: trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebViewConfiguration.mm (213685 => 213686)


--- trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebViewConfiguration.mm	2017-03-10 00:16:02 UTC (rev 213685)
+++ trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebViewConfiguration.mm	2017-03-10 00:38:20 UTC (rev 213686)
@@ -33,11 +33,14 @@
 #import "WKPreferences.h"
 #import "WKProcessPool.h"
 #import "WKUserContentController.h"
+#import "WKWebView.h"
 #import "WKWebViewContentProviderRegistry.h"
 #import "WeakObjCPtr.h"
+#import "WebKit2Initialize.h"
 #import "_WKVisitedLinkStore.h"
 #import "_WKWebsiteDataStoreInternal.h"
 #import <WebCore/RuntimeApplicationChecks.h>
+#import <WebCore/URLParser.h>
 #import <wtf/RetainPtr.h>
 
 #if PLATFORM(IOS)
@@ -94,6 +97,7 @@
     WebKit::WeakObjCPtr<WKWebView> _alternateWebViewForNavigationGestures;
     RetainPtr<NSString> _groupIdentifier;
     LazyInitialized<RetainPtr<NSString>> _applicationNameForUserAgent;
+    LazyInitialized<RetainPtr<NSMutableDictionary<NSString *, id <WKURLSchemeHandler>>>> _urlSchemeHandlers;
     NSTimeInterval _incrementalRenderingSuppressionTimeout;
     BOOL _treatsSHA1SignedCertificatesAsInsecure;
     BOOL _respectsImageOrientation;
@@ -141,7 +145,9 @@
 {
     if (!(self = [super init]))
         return nil;
-    
+
+    WebKit::InitializeWebKit2();
+
 #if PLATFORM(IOS)
     _allowsPictureInPictureMediaPlayback = YES;
     _allowsInlineMediaPlayback = WebCore::deviceClass() == MGDeviceClassiPad;
@@ -328,6 +334,8 @@
     configuration->_needsStorageAccessFromFileURLsQuirk = self->_needsStorageAccessFromFileURLsQuirk;
     configuration->_overrideContentSecurityPolicy = self->_overrideContentSecurityPolicy;
 
+    configuration->_urlSchemeHandlers.set(adoptNS([self._urlSchemeHandlers mutableCopyWithZone:zone]));
+
     return configuration;
 }
 
@@ -400,6 +408,33 @@
     _visitedLinkStore.set(visitedLinkStore);
 }
 
+- (void)setURLSchemeHandler:(id <WKURLSchemeHandler>)urlSchemeHandler forURLScheme:(NSString *)urlScheme
+{
+    auto *urlSchemeHandlers = _urlSchemeHandlers.get([] { return adoptNS([[NSMutableDictionary alloc] init]); });
+
+    if ([WKWebView handlesURLScheme:urlScheme])
+        [NSException raise:NSInvalidArgumentException format:@"'%@' is a URL scheme that WKWebView handles natively", urlScheme];
+
+    auto canonicalScheme = WebCore::URLParser::maybeCanonicalizeScheme(urlScheme);
+    if (!canonicalScheme)
+        [NSException raise:NSInvalidArgumentException format:@"'%@' is not a valid URL scheme", urlScheme];
+
+    if ([urlSchemeHandlers objectForKey:(NSString *)canonicalScheme.value()])
+        [NSException raise:NSInvalidArgumentException format:@"URL scheme '%@' already has a registered URL scheme handler", urlScheme];
+
+    [urlSchemeHandlers setObject:urlSchemeHandler forKey:(NSString *)canonicalScheme.value()];
+}
+
+- (nullable id <WKURLSchemeHandler>)urlSchemeHandlerForURLScheme:(NSString *)urlScheme
+{
+    auto canonicalScheme = WebCore::URLParser::maybeCanonicalizeScheme(urlScheme);
+    if (!canonicalScheme)
+        return nil;
+
+    auto *urlSchemeHandlers = _urlSchemeHandlers.get([] { return adoptNS([[NSMutableDictionary alloc] init]); });
+    return [urlSchemeHandlers objectForKey:(NSString *)canonicalScheme.value()];
+}
+
 #pragma clang diagnostic push
 #pragma clang diagnostic ignored "-Wdeprecated-declarations"
 
@@ -415,6 +450,11 @@
 
 #pragma clang diagnostic pop
 
+- (NSMutableDictionary<NSString *, id <WKURLSchemeHandler>> *)_urlSchemeHandlers
+{
+    return _urlSchemeHandlers.get([] { return adoptNS([[NSMutableDictionary alloc] init]); });
+}
+
 #if PLATFORM(IOS)
 - (WKWebViewContentProviderRegistry *)_contentProviderRegistry
 {

Modified: trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebViewConfigurationInternal.h (213685 => 213686)


--- trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebViewConfigurationInternal.h	2017-03-10 00:16:02 UTC (rev 213685)
+++ trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebViewConfigurationInternal.h	2017-03-10 00:38:20 UTC (rev 213686)
@@ -32,6 +32,8 @@
 
 @interface WKWebViewConfiguration ()
 
+@property (nonatomic, readonly) NSMutableDictionary<NSString *, id <WKURLSchemeHandler>> *_urlSchemeHandlers;
+
 #if PLATFORM(IOS)
 @property (nonatomic, setter=_setContentProviderRegistry:) WKWebViewContentProviderRegistry *_contentProviderRegistry;
 #endif

Copied: trunk/Source/WebKit2/UIProcess/Cocoa/WebURLSchemeHandlerCocoa.h (from rev 213685, trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebViewConfigurationInternal.h) (0 => 213686)


--- trunk/Source/WebKit2/UIProcess/Cocoa/WebURLSchemeHandlerCocoa.h	                        (rev 0)
+++ trunk/Source/WebKit2/UIProcess/Cocoa/WebURLSchemeHandlerCocoa.h	2017-03-10 00:38:20 UTC (rev 213686)
@@ -0,0 +1,56 @@
+/*
+ * Copyright (C) 2017 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 "WebURLSchemeHandler.h"
+#include <wtf/RetainPtr.h>
+
+@protocol WKURLSchemeHandler;
+
+namespace API {
+class URLSchemeHandlerTask;
+}
+
+namespace WebKit {
+
+class WebURLSchemeHandlerCocoa : public WebURLSchemeHandler {
+public:
+    static Ref<WebURLSchemeHandlerCocoa> create(id <WKURLSchemeHandler>);
+
+    id <WKURLSchemeHandler> apiHandler() const { return m_apiHandler.get(); }
+
+private:
+    WebURLSchemeHandlerCocoa(id <WKURLSchemeHandler>);
+
+    void platformStartTask(WebPageProxy&, WebURLSchemeHandlerTask&) final;
+    void platformStopTask(WebPageProxy&, WebURLSchemeHandlerTask&) final;
+
+    RetainPtr<id <WKURLSchemeHandler>> m_apiHandler;
+    HashMap<uint64_t, Ref<API::URLSchemeHandlerTask>> m_apiTasks;
+
+}; // class WebURLSchemeHandler
+
+} // namespace WebKit

Added: trunk/Source/WebKit2/UIProcess/Cocoa/WebURLSchemeHandlerCocoa.mm (0 => 213686)


--- trunk/Source/WebKit2/UIProcess/Cocoa/WebURLSchemeHandlerCocoa.mm	                        (rev 0)
+++ trunk/Source/WebKit2/UIProcess/Cocoa/WebURLSchemeHandlerCocoa.mm	2017-03-10 00:38:20 UTC (rev 213686)
@@ -0,0 +1,82 @@
+/*
+ * Copyright (C) 2017 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import "config.h"
+#import "WebURLSchemeHandlerCocoa.h"
+
+#import "APIURLSchemeHandlerTask.h"
+#import "WKFoundation.h"
+#import "WKURLSchemeHandler.h"
+#import "WKURLSchemeHandlerTaskInternal.h"
+#import "WKWebViewInternal.h"
+#import "WebURLSchemeHandlerTask.h"
+
+using namespace WebCore;
+
+namespace WebKit {
+
+Ref<WebURLSchemeHandlerCocoa> WebURLSchemeHandlerCocoa::create(id <WKURLSchemeHandler> apiHandler)
+{
+    return adoptRef(*new WebURLSchemeHandlerCocoa(apiHandler));
+}
+
+WebURLSchemeHandlerCocoa::WebURLSchemeHandlerCocoa(id <WKURLSchemeHandler> apiHandler)
+    : m_apiHandler(apiHandler)
+{
+#if !WK_API_ENABLED
+    ASSERT_NOT_REACHED();
+#endif
+}
+
+void WebURLSchemeHandlerCocoa::platformStartTask(WebPageProxy& page, WebURLSchemeHandlerTask& task)
+{
+#if WK_API_ENABLED
+    auto result = m_apiTasks.add(task.identifier(), API::URLSchemeHandlerTask::create(task));
+    ASSERT(result.isNewEntry);
+
+    [m_apiHandler.get() webView:fromWebPageProxy(page) startTask:wrapper(result.iterator->value.get())];
+#else
+    UNUSED_PARAM(page);
+    UNUSED_PARAM(task);
+#endif
+}
+
+void WebURLSchemeHandlerCocoa::platformStopTask(WebPageProxy& page, WebURLSchemeHandlerTask& task)
+{
+#if WK_API_ENABLED
+    auto iterator = m_apiTasks.find(task.identifier());
+    if (iterator == m_apiTasks.end())
+        return;
+
+    [m_apiHandler.get() webView:fromWebPageProxy(page) stopTask:wrapper(iterator->value.get())];
+
+    m_apiTasks.remove(iterator);
+#else
+    UNUSED_PARAM(page);
+    UNUSED_PARAM(task);
+#endif
+}
+
+} // namespace WebKit

Modified: trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp (213685 => 213686)


--- trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp	2017-03-10 00:16:02 UTC (rev 213685)
+++ trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp	2017-03-10 00:38:20 UTC (rev 213686)
@@ -108,6 +108,7 @@
 #include "WebProcessPool.h"
 #include "WebProcessProxy.h"
 #include "WebProtectionSpace.h"
+#include "WebURLSchemeHandler.h"
 #include "WebUserContentControllerProxy.h"
 #include "WebsiteDataStore.h"
 #include <WebCore/BitmapImage.h>
@@ -127,6 +128,7 @@
 #include <WebCore/TextCheckerClient.h>
 #include <WebCore/TextIndicator.h>
 #include <WebCore/URL.h>
+#include <WebCore/URLParser.h>
 #include <WebCore/ValidationBubble.h>
 #include <WebCore/WindowFeatures.h>
 #include <stdio.h>
@@ -5588,6 +5590,9 @@
     parameters.observedLayoutMilestones = m_observedLayoutMilestones;
     parameters.overrideContentSecurityPolicy = m_overrideContentSecurityPolicy;
 
+    for (auto& iterator : m_urlSchemeHandlersByScheme)
+        parameters.urlSchemeHandlers.set(iterator.key, iterator.value->identifier());
+
 #if ENABLE(WEB_RTC)
     parameters.iceCandidateFilteringEnabled = m_preferences->iceCandidateFilteringEnabled();
 #if USE(LIBWEBRTC)
@@ -6843,5 +6848,41 @@
 }
 #endif
 
+void WebPageProxy::setURLSchemeHandlerForScheme(Ref<WebURLSchemeHandler>&& handler, const String& scheme)
+{
+    auto canonicalizedScheme = URLParser::maybeCanonicalizeScheme(scheme);
+    ASSERT(canonicalizedScheme);
+    ASSERT(!URLParser::isSpecialScheme(canonicalizedScheme.value()));
 
+    auto schemeResult = m_urlSchemeHandlersByScheme.add(canonicalizedScheme.value(), handler.get());
+    ASSERT_UNUSED(schemeResult, schemeResult.isNewEntry);
+
+    auto identifier = handler->identifier();
+    auto identifierResult = m_urlSchemeHandlersByIdentifier.add(identifier, WTFMove(handler));
+    ASSERT_UNUSED(identifierResult, identifierResult.isNewEntry);
+
+    m_process->send(Messages::WebPage::RegisterURLSchemeHandler(identifier, canonicalizedScheme.value()), m_pageID);
+}
+
+WebURLSchemeHandler* WebPageProxy::urlSchemeHandlerForScheme(const String& scheme)
+{
+    return m_urlSchemeHandlersByScheme.get(scheme);
+}
+
+void WebPageProxy::startURLSchemeHandlerTask(uint64_t handlerIdentifier, uint64_t resourceIdentifier, const WebCore::ResourceRequest& request)
+{
+    auto iterator = m_urlSchemeHandlersByIdentifier.find(handlerIdentifier);
+    ASSERT(iterator != m_urlSchemeHandlersByIdentifier.end());
+
+    iterator->value->startTask(*this, resourceIdentifier, request);
+}
+
+void WebPageProxy::stopURLSchemeHandlerTask(uint64_t handlerIdentifier, uint64_t resourceIdentifier)
+{
+    auto iterator = m_urlSchemeHandlersByIdentifier.find(handlerIdentifier);
+    ASSERT(iterator != m_urlSchemeHandlersByIdentifier.end());
+
+    iterator->value->stopTask(*this, resourceIdentifier);
+}
+
 } // namespace WebKit

Modified: trunk/Source/WebKit2/UIProcess/WebPageProxy.h (213685 => 213686)


--- trunk/Source/WebKit2/UIProcess/WebPageProxy.h	2017-03-10 00:16:02 UTC (rev 213685)
+++ trunk/Source/WebKit2/UIProcess/WebPageProxy.h	2017-03-10 00:38:20 UTC (rev 213686)
@@ -202,6 +202,7 @@
 class WebNavigationState;
 class WebVideoFullscreenManagerProxy;
 class WebKeyboardEvent;
+class WebURLSchemeHandler;
 class WebMouseEvent;
 class WebOpenPanelResultListenerProxy;
 class WebPageGroup;
@@ -1191,6 +1192,9 @@
 
     void setShouldSkipWaitingForPaintAfterNextViewDidMoveToWindow(bool shouldSkip) { m_shouldSkipWaitingForPaintAfterNextViewDidMoveToWindow = shouldSkip; }
 
+    void setURLSchemeHandlerForScheme(Ref<WebURLSchemeHandler>&&, const String& scheme);
+    WebURLSchemeHandler* urlSchemeHandlerForScheme(const String& scheme);
+
 private:
     WebPageProxy(PageClient&, WebProcessProxy&, uint64_t pageID, Ref<API::PageConfiguration>&&);
     void platformInitialize();
@@ -1594,6 +1598,9 @@
 #endif
 #endif
 
+    void startURLSchemeHandlerTask(uint64_t handlerIdentifier, uint64_t resourceIdentifier, const WebCore::ResourceRequest&);
+    void stopURLSchemeHandlerTask(uint64_t handlerIdentifier, uint64_t resourceIdentifier);
+
     void handleAutoFillButtonClick(const UserData&);
 
     void finishInitializingWebPageAfterProcessLaunch();
@@ -1979,6 +1986,9 @@
     bool m_isUsingHighPerformanceWebGL { false };
         
     WeakPtrFactory<WebPageProxy> m_weakPtrFactory;
+
+    HashMap<String, Ref<WebURLSchemeHandler>> m_urlSchemeHandlersByScheme;
+    HashMap<uint64_t, Ref<WebURLSchemeHandler>> m_urlSchemeHandlersByIdentifier;
 };
 
 } // namespace WebKit

Modified: trunk/Source/WebKit2/UIProcess/WebPageProxy.messages.in (213685 => 213686)


--- trunk/Source/WebKit2/UIProcess/WebPageProxy.messages.in	2017-03-10 00:16:02 UTC (rev 213685)
+++ trunk/Source/WebKit2/UIProcess/WebPageProxy.messages.in	2017-03-10 00:38:20 UTC (rev 213686)
@@ -490,4 +490,7 @@
 #endif
 
     SetIsUsingHighPerformanceWebGL(bool isUsingHighPerformanceWebGL)
+
+    StartURLSchemeHandlerTask(uint64_t loaderIdentifier, uint64_t resourceIdentifier, WebCore::ResourceRequest request)
+    StopURLSchemeHandlerTask(uint64_t loaderIdentifier, uint64_t resourceIdentifier)
 }

Copied: trunk/Source/WebKit2/UIProcess/WebURLSchemeHandler.cpp (from rev 213685, trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebViewConfigurationInternal.h) (0 => 213686)


--- trunk/Source/WebKit2/UIProcess/WebURLSchemeHandler.cpp	                        (rev 0)
+++ trunk/Source/WebKit2/UIProcess/WebURLSchemeHandler.cpp	2017-03-10 00:38:20 UTC (rev 213686)
@@ -0,0 +1,72 @@
+/*
+ * Copyright (C) 2017 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 "WebURLSchemeHandler.h"
+
+#include "WebURLSchemeHandlerTask.h"
+
+using namespace WebCore;
+
+namespace WebKit {
+
+static uint64_t generateWebURLSchemeHandlerIdentifier()
+{
+    static uint64_t nextIdentifier = 1;
+    return nextIdentifier++;
+}
+
+WebURLSchemeHandler::WebURLSchemeHandler()
+    : m_identifier(generateWebURLSchemeHandlerIdentifier())
+{
+}
+
+WebURLSchemeHandler::~WebURLSchemeHandler()
+{
+    ASSERT(m_tasks.isEmpty());
+}
+
+void WebURLSchemeHandler::startTask(WebPageProxy& page, uint64_t resourceIdentifier, const ResourceRequest& request)
+{
+    auto result = m_tasks.add(resourceIdentifier, WebURLSchemeHandlerTask::create(*this, page, resourceIdentifier, request));
+    ASSERT(result.isNewEntry);
+
+    platformStartTask(page, result.iterator->value);
+}
+
+void WebURLSchemeHandler::stopTask(WebPageProxy& page, uint64_t resourceIdentifier)
+{
+    auto iterator = m_tasks.find(resourceIdentifier);
+    if (iterator == m_tasks.end())
+        return;
+
+    iterator->value->stop();
+
+    platformStopTask(page, iterator->value);
+
+    m_tasks.remove(iterator);
+}
+
+} // namespace WebKit

Copied: trunk/Source/WebKit2/UIProcess/WebURLSchemeHandler.h (from rev 213685, trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebViewConfigurationInternal.h) (0 => 213686)


--- trunk/Source/WebKit2/UIProcess/WebURLSchemeHandler.h	                        (rev 0)
+++ trunk/Source/WebKit2/UIProcess/WebURLSchemeHandler.h	2017-03-10 00:38:20 UTC (rev 213686)
@@ -0,0 +1,64 @@
+/*
+ * Copyright (C) 2017 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 "WebURLSchemeHandlerTask.h"
+#include <wtf/HashMap.h>
+#include <wtf/RefCounted.h>
+#include <wtf/RefPtr.h>
+
+namespace WebCore {
+class ResourceRequest;
+}
+
+namespace WebKit {
+
+class WebPageProxy;
+
+class WebURLSchemeHandler : public RefCounted<WebURLSchemeHandler> {
+    WTF_MAKE_NONCOPYABLE(WebURLSchemeHandler);
+public:
+    virtual ~WebURLSchemeHandler();
+
+    uint64_t identifier() const { return m_identifier; }
+
+    void startTask(WebPageProxy&, uint64_t resourceIdentifier, const WebCore::ResourceRequest&);
+    void stopTask(WebPageProxy&, uint64_t resourceIdentifier);
+
+protected:
+    WebURLSchemeHandler();
+
+private:
+    virtual void platformStartTask(WebPageProxy&, WebURLSchemeHandlerTask&) = 0;
+    virtual void platformStopTask(WebPageProxy&, WebURLSchemeHandlerTask&) = 0;
+
+    uint64_t m_identifier;
+
+    HashMap<uint64_t, Ref<WebURLSchemeHandlerTask>> m_tasks;
+
+}; // class WebURLSchemeHandler
+
+} // namespace WebKit

Added: trunk/Source/WebKit2/UIProcess/WebURLSchemeHandlerTask.cpp (0 => 213686)


--- trunk/Source/WebKit2/UIProcess/WebURLSchemeHandlerTask.cpp	                        (rev 0)
+++ trunk/Source/WebKit2/UIProcess/WebURLSchemeHandlerTask.cpp	2017-03-10 00:38:20 UTC (rev 213686)
@@ -0,0 +1,112 @@
+/*
+ * Copyright (C) 2017 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 "WebURLSchemeHandlerTask.h"
+
+#include "DataReference.h"
+#include "WebPageMessages.h"
+#include "WebPageProxy.h"
+#include "WebURLSchemeHandler.h"
+
+using namespace WebCore;
+
+namespace WebKit {
+
+Ref<WebURLSchemeHandlerTask> WebURLSchemeHandlerTask::create(WebURLSchemeHandler& handler, WebPageProxy& page, uint64_t resourceIdentifier, const ResourceRequest& request)
+{
+    return adoptRef(*new WebURLSchemeHandlerTask(handler, page, resourceIdentifier, request));
+}
+
+WebURLSchemeHandlerTask::WebURLSchemeHandlerTask(WebURLSchemeHandler& handler, WebPageProxy& page, uint64_t resourceIdentifier, const ResourceRequest& request)
+    : m_urlSchemeHandler(handler)
+    , m_page(&page)
+    , m_identifier(resourceIdentifier)
+    , m_request(request)
+{
+}
+
+WebURLSchemeHandlerTask::ExceptionType WebURLSchemeHandlerTask::didReceiveResponse(const ResourceResponse& response)
+{
+    if (m_stopped)
+        return WebURLSchemeHandlerTask::ExceptionType::TaskAlreadyStopped;
+
+    if (m_completed)
+        return WebURLSchemeHandlerTask::ExceptionType::CompleteAlreadyCalled;
+
+    if (m_dataSent)
+        return WebURLSchemeHandlerTask::ExceptionType::DataAlreadySent;
+
+    m_responseSent = true;
+    m_page->send(Messages::WebPage::URLSchemeHandlerTaskDidReceiveResponse(m_urlSchemeHandler->identifier(), m_identifier, response));
+    return WebURLSchemeHandlerTask::ExceptionType::None;
+}
+
+WebURLSchemeHandlerTask::ExceptionType WebURLSchemeHandlerTask::didReceiveData(Ref<SharedBuffer> buffer)
+{
+    if (m_stopped)
+        return WebURLSchemeHandlerTask::ExceptionType::TaskAlreadyStopped;
+
+    if (m_completed)
+        return WebURLSchemeHandlerTask::ExceptionType::CompleteAlreadyCalled;
+
+    if (!m_responseSent)
+        return WebURLSchemeHandlerTask::ExceptionType::NoResponseSent;
+
+    m_dataSent = true;
+    m_page->send(Messages::WebPage::URLSchemeHandlerTaskDidReceiveData(m_urlSchemeHandler->identifier(), m_identifier, IPC::SharedBufferDataReference(buffer.ptr())));
+    return WebURLSchemeHandlerTask::ExceptionType::None;
+}
+
+WebURLSchemeHandlerTask::ExceptionType WebURLSchemeHandlerTask::didComplete(const ResourceError& error)
+{
+    if (m_stopped)
+        return WebURLSchemeHandlerTask::ExceptionType::TaskAlreadyStopped;
+
+    if (m_completed)
+        return WebURLSchemeHandlerTask::ExceptionType::CompleteAlreadyCalled;
+
+    if (!m_responseSent && error.isNull())
+        return WebURLSchemeHandlerTask::ExceptionType::NoResponseSent;
+
+    m_completed = true;
+    m_page->send(Messages::WebPage::URLSchemeHandlerTaskDidComplete(m_urlSchemeHandler->identifier(), m_identifier, error));
+    return WebURLSchemeHandlerTask::ExceptionType::None;
+}
+
+void WebURLSchemeHandlerTask::pageDestroyed()
+{
+    ASSERT(m_page);
+    m_page = nullptr;
+    m_stopped = true;
+}
+
+void WebURLSchemeHandlerTask::stop()
+{
+    ASSERT(!m_stopped);
+    m_stopped = true;
+}
+
+} // namespace WebKit

Added: trunk/Source/WebKit2/UIProcess/WebURLSchemeHandlerTask.h (0 => 213686)


--- trunk/Source/WebKit2/UIProcess/WebURLSchemeHandlerTask.h	                        (rev 0)
+++ trunk/Source/WebKit2/UIProcess/WebURLSchemeHandlerTask.h	2017-03-10 00:38:20 UTC (rev 213686)
@@ -0,0 +1,79 @@
+/*
+ * Copyright (C) 2017 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/ResourceRequest.h>
+#include <wtf/RefCounted.h>
+#include <wtf/RefPtr.h>
+
+namespace WebCore {
+class ResourceError;
+class ResourceResponse;
+class SharedBuffer;
+}
+
+namespace WebKit {
+
+class WebURLSchemeHandler;
+class WebPageProxy;
+
+class WebURLSchemeHandlerTask : public RefCounted<WebURLSchemeHandlerTask> {
+    WTF_MAKE_NONCOPYABLE(WebURLSchemeHandlerTask);
+public:
+    static Ref<WebURLSchemeHandlerTask> create(WebURLSchemeHandler&, WebPageProxy&, uint64_t identifier, const WebCore::ResourceRequest&);
+
+    uint64_t identifier() const { return m_identifier; }
+
+    const WebCore::ResourceRequest& request() const { return m_request; }
+
+    enum class ExceptionType {
+        DataAlreadySent,
+        CompleteAlreadyCalled,
+        TaskAlreadyStopped,
+        NoResponseSent,
+        None,
+    };
+    ExceptionType didReceiveResponse(const WebCore::ResourceResponse&);
+    ExceptionType didReceiveData(Ref<WebCore::SharedBuffer>);
+    ExceptionType didComplete(const WebCore::ResourceError&);
+
+    void stop();
+    void pageDestroyed();
+
+private:
+    WebURLSchemeHandlerTask(WebURLSchemeHandler&, WebPageProxy&, uint64_t identifier, const WebCore::ResourceRequest&);
+
+    Ref<WebURLSchemeHandler> m_urlSchemeHandler;
+    WebPageProxy* m_page;
+    uint64_t m_identifier;
+    WebCore::ResourceRequest m_request;
+    bool m_stopped { false };
+    bool m_responseSent { false };
+    bool m_dataSent { false };
+    bool m_completed { false };
+};
+
+} // namespace WebKit

Modified: trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj (213685 => 213686)


--- trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj	2017-03-10 00:16:02 UTC (rev 213685)
+++ trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj	2017-03-10 00:38:20 UTC (rev 213686)
@@ -1055,6 +1055,14 @@
 		51D02F6A132EC73700BEAA96 /* WebIconDatabaseMessages.h in Headers */ = {isa = PBXBuildFile; fileRef = 51D02F67132EC73700BEAA96 /* WebIconDatabaseMessages.h */; };
 		51D02F6B132EC73700BEAA96 /* WebIconDatabaseProxyMessageReceiver.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 51D02F68132EC73700BEAA96 /* WebIconDatabaseProxyMessageReceiver.cpp */; };
 		51D02F6C132EC73700BEAA96 /* WebIconDatabaseProxyMessages.h in Headers */ = {isa = PBXBuildFile; fileRef = 51D02F69132EC73700BEAA96 /* WebIconDatabaseProxyMessages.h */; };
+		51D124231E6D34A1002B2820 /* WebURLSchemeHandlerTaskProxy.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 51D124211E6D349A002B2820 /* WebURLSchemeHandlerTaskProxy.cpp */; };
+		51D124281E6D3F5D002B2820 /* WebURLSchemeHandler.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 51D124241E6D3CC3002B2820 /* WebURLSchemeHandler.cpp */; };
+		51D1242C1E6D41FD002B2820 /* WebURLSchemeHandlerProxy.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 51D1242A1E6D41BC002B2820 /* WebURLSchemeHandlerProxy.cpp */; };
+		51D124331E6DE6CA002B2820 /* WebURLSchemeHandlerCocoa.mm in Sources */ = {isa = PBXBuildFile; fileRef = 51D124321E6DE521002B2820 /* WebURLSchemeHandlerCocoa.mm */; };
+		51D124341E6DF643002B2820 /* WKURLSchemeHandler.h in Headers */ = {isa = PBXBuildFile; fileRef = 51D1242D1E6DDDD7002B2820 /* WKURLSchemeHandler.h */; settings = {ATTRIBUTES = (Public, ); }; };
+		51D124351E6DF652002B2820 /* WKURLSchemeHandlerTask.h in Headers */ = {isa = PBXBuildFile; fileRef = 51D1242F1E6DDDD7002B2820 /* WKURLSchemeHandlerTask.h */; settings = {ATTRIBUTES = (Public, ); }; };
+		51D124361E6DFB39002B2820 /* WKURLSchemeHandlerTask.mm in Sources */ = {isa = PBXBuildFile; fileRef = 51D124301E6DDDD7002B2820 /* WKURLSchemeHandlerTask.mm */; };
+		51D1243A1E6E0AAB002B2820 /* APIURLSchemeHandlerTask.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 51D124381E6DFDB9002B2820 /* APIURLSchemeHandlerTask.cpp */; };
 		51D130531382EAC000351EDD /* SecItemRequestData.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 51D1304F1382EAC000351EDD /* SecItemRequestData.cpp */; };
 		51D130541382EAC000351EDD /* SecItemRequestData.h in Headers */ = {isa = PBXBuildFile; fileRef = 51D130501382EAC000351EDD /* SecItemRequestData.h */; };
 		51D130551382EAC000351EDD /* SecItemResponseData.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 51D130511382EAC000351EDD /* SecItemResponseData.cpp */; };
@@ -1069,6 +1077,7 @@
 		51E35202180F5D1E00E53BE9 /* DatabaseProcessMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 51E35201180F5D1E00E53BE9 /* DatabaseProcessMac.mm */; };
 		51E35209180F5D6B00E53BE9 /* DatabaseServiceEntryPoint.mm in Sources */ = {isa = PBXBuildFile; fileRef = 51E35208180F5D6B00E53BE9 /* DatabaseServiceEntryPoint.mm */; };
 		51E399061D6F54C7009C8831 /* UIGamepadProviderCocoa.mm in Sources */ = {isa = PBXBuildFile; fileRef = 51E399051D6F54C5009C8831 /* UIGamepadProviderCocoa.mm */; };
+		51E8B68E1E712877001B7132 /* WebURLSchemeHandlerTask.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 51E8B68D1E712873001B7132 /* WebURLSchemeHandlerTask.cpp */; };
 		51E949971D76211300EC9EB9 /* UIGamepadProviderIOS.mm in Sources */ = {isa = PBXBuildFile; fileRef = 51E949961D761CC700EC9EB9 /* UIGamepadProviderIOS.mm */; };
 		51EFC1CF1524E62500C9A938 /* WKBundleDOMWindowExtension.h in Headers */ = {isa = PBXBuildFile; fileRef = 51FA2D541521118600C1BA0B /* WKBundleDOMWindowExtension.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		51F060E01654317F00F3281B /* WebResourceLoaderMessages.h in Headers */ = {isa = PBXBuildFile; fileRef = 51F060DE1654317500F3281B /* WebResourceLoaderMessages.h */; };
@@ -3253,6 +3262,21 @@
 		51D02F67132EC73700BEAA96 /* WebIconDatabaseMessages.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebIconDatabaseMessages.h; sourceTree = "<group>"; };
 		51D02F68132EC73700BEAA96 /* WebIconDatabaseProxyMessageReceiver.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebIconDatabaseProxyMessageReceiver.cpp; sourceTree = "<group>"; };
 		51D02F69132EC73700BEAA96 /* WebIconDatabaseProxyMessages.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebIconDatabaseProxyMessages.h; sourceTree = "<group>"; };
+		51D124211E6D349A002B2820 /* WebURLSchemeHandlerTaskProxy.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebURLSchemeHandlerTaskProxy.cpp; sourceTree = "<group>"; };
+		51D124221E6D349A002B2820 /* WebURLSchemeHandlerTaskProxy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebURLSchemeHandlerTaskProxy.h; sourceTree = "<group>"; };
+		51D124241E6D3CC3002B2820 /* WebURLSchemeHandler.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebURLSchemeHandler.cpp; sourceTree = "<group>"; };
+		51D124251E6D3CC3002B2820 /* WebURLSchemeHandler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebURLSchemeHandler.h; sourceTree = "<group>"; };
+		51D124271E6D3F1F002B2820 /* WebURLSchemeHandlerTask.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebURLSchemeHandlerTask.h; sourceTree = "<group>"; };
+		51D1242A1E6D41BC002B2820 /* WebURLSchemeHandlerProxy.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebURLSchemeHandlerProxy.cpp; sourceTree = "<group>"; };
+		51D1242B1E6D41BC002B2820 /* WebURLSchemeHandlerProxy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebURLSchemeHandlerProxy.h; sourceTree = "<group>"; };
+		51D1242D1E6DDDD7002B2820 /* WKURLSchemeHandler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKURLSchemeHandler.h; sourceTree = "<group>"; };
+		51D1242F1E6DDDD7002B2820 /* WKURLSchemeHandlerTask.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKURLSchemeHandlerTask.h; sourceTree = "<group>"; };
+		51D124301E6DDDD7002B2820 /* WKURLSchemeHandlerTask.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WKURLSchemeHandlerTask.mm; sourceTree = "<group>"; };
+		51D124311E6DE521002B2820 /* WebURLSchemeHandlerCocoa.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebURLSchemeHandlerCocoa.h; sourceTree = "<group>"; };
+		51D124321E6DE521002B2820 /* WebURLSchemeHandlerCocoa.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebURLSchemeHandlerCocoa.mm; sourceTree = "<group>"; };
+		51D124371E6DFD2A002B2820 /* WKURLSchemeHandlerTaskInternal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKURLSchemeHandlerTaskInternal.h; sourceTree = "<group>"; };
+		51D124381E6DFDB9002B2820 /* APIURLSchemeHandlerTask.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = APIURLSchemeHandlerTask.cpp; sourceTree = "<group>"; };
+		51D124391E6DFDB9002B2820 /* APIURLSchemeHandlerTask.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = APIURLSchemeHandlerTask.h; sourceTree = "<group>"; };
 		51D1304F1382EAC000351EDD /* SecItemRequestData.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SecItemRequestData.cpp; sourceTree = "<group>"; };
 		51D130501382EAC000351EDD /* SecItemRequestData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SecItemRequestData.h; sourceTree = "<group>"; };
 		51D130511382EAC000351EDD /* SecItemResponseData.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SecItemResponseData.cpp; sourceTree = "<group>"; };
@@ -3271,6 +3295,7 @@
 		51E35207180F5D6100E53BE9 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
 		51E35208180F5D6B00E53BE9 /* DatabaseServiceEntryPoint.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DatabaseServiceEntryPoint.mm; sourceTree = "<group>"; };
 		51E399051D6F54C5009C8831 /* UIGamepadProviderCocoa.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = UIGamepadProviderCocoa.mm; sourceTree = "<group>"; };
+		51E8B68D1E712873001B7132 /* WebURLSchemeHandlerTask.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebURLSchemeHandlerTask.cpp; sourceTree = "<group>"; };
 		51E949961D761CC700EC9EB9 /* UIGamepadProviderIOS.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = UIGamepadProviderIOS.mm; sourceTree = "<group>"; };
 		51F060DD1654317500F3281B /* WebResourceLoaderMessageReceiver.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = WebResourceLoaderMessageReceiver.cpp; sourceTree = "<group>"; };
 		51F060DD1654317500F3281C /* WebRTCSocketMessageReceiver.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = WebRTCSocketMessageReceiver.cpp; sourceTree = "<group>"; };
@@ -5058,6 +5083,8 @@
 				2DAF4FFA1B636181006013D6 /* ViewGestureController.cpp */,
 				2D125C5C1857EA05003BA3CB /* ViewGestureController.h */,
 				2D1B5D5A18586599006C6596 /* ViewGestureController.messages.in */,
+				51D124311E6DE521002B2820 /* WebURLSchemeHandlerCocoa.h */,
+				51D124321E6DE521002B2820 /* WebURLSchemeHandlerCocoa.mm */,
 				1AC0273E196622D600C12B75 /* WebPageProxyCocoa.mm */,
 				7C4694CB1A4B510A00AD5845 /* WebPasteboardProxyCocoa.mm */,
 				CDA29A1E1CBEB5FB00901CCF /* WebPlaybackSessionManagerProxy.h */,
@@ -5540,6 +5567,10 @@
 				93F549B51E3174DA000E7239 /* WKSnapshotConfiguration.mm */,
 				1AD8790918B6C38A006CAFD7 /* WKUIDelegate.h */,
 				3743925718BC4C60001C8675 /* WKUIDelegatePrivate.h */,
+				51D1242D1E6DDDD7002B2820 /* WKURLSchemeHandler.h */,
+				51D1242F1E6DDDD7002B2820 /* WKURLSchemeHandlerTask.h */,
+				51D124301E6DDDD7002B2820 /* WKURLSchemeHandlerTask.mm */,
+				51D124371E6DFD2A002B2820 /* WKURLSchemeHandlerTaskInternal.h */,
 				1AFA3AC718E61C61003CCBAE /* WKUserContentController.h */,
 				1AFA3AC618E61C61003CCBAE /* WKUserContentController.mm */,
 				1AAF08A3192682DA00B6390C /* WKUserContentControllerInternal.h */,
@@ -6474,6 +6505,10 @@
 				BC7B621312A4219A00D174A4 /* WebPageGroupProxy.h */,
 				2D5C9D0319C81D8F00B3C5C1 /* WebPageOverlay.cpp */,
 				2D5C9D0419C81D8F00B3C5C1 /* WebPageOverlay.h */,
+				51D1242A1E6D41BC002B2820 /* WebURLSchemeHandlerProxy.cpp */,
+				51D1242B1E6D41BC002B2820 /* WebURLSchemeHandlerProxy.h */,
+				51D124211E6D349A002B2820 /* WebURLSchemeHandlerTaskProxy.cpp */,
+				51D124221E6D349A002B2820 /* WebURLSchemeHandlerTaskProxy.h */,
 				BCA0EF7E12331E78007D3CFB /* WebUndoStep.cpp */,
 				BCA0EF7D12331E78007D3CFB /* WebUndoStep.h */,
 			);
@@ -6639,6 +6674,10 @@
 				7A9CD8C01C77984900D9F6C7 /* WebResourceLoadStatisticsStore.cpp */,
 				7A9CD8C11C77984900D9F6C7 /* WebResourceLoadStatisticsStore.h */,
 				7A9CD8C21C779AD600D9F6C7 /* WebResourceLoadStatisticsStore.messages.in */,
+				51D124241E6D3CC3002B2820 /* WebURLSchemeHandler.cpp */,
+				51D124251E6D3CC3002B2820 /* WebURLSchemeHandler.h */,
+				51E8B68D1E712873001B7132 /* WebURLSchemeHandlerTask.cpp */,
+				51D124271E6D3F1F002B2820 /* WebURLSchemeHandlerTask.h */,
 			);
 			path = UIProcess;
 			sourceTree = "<group>";
@@ -6689,6 +6728,8 @@
 				1AFDE65F1954E9B100C48FFA /* APISessionState.cpp */,
 				1AFDE6601954E9B100C48FFA /* APISessionState.h */,
 				1A4D664718A2D91A00D82E21 /* APIUIClient.h */,
+				51D124381E6DFDB9002B2820 /* APIURLSchemeHandlerTask.cpp */,
+				51D124391E6DFDB9002B2820 /* APIURLSchemeHandlerTask.h */,
 				7C89D2B11A6B068C003A5FDE /* APIUserContentExtension.cpp */,
 				7C89D2B21A6B068C003A5FDE /* APIUserContentExtension.h */,
 				7C3A06A51AAB903E009D74BA /* APIUserContentExtensionStore.cpp */,
@@ -8156,6 +8197,7 @@
 				0FDCD7F71D47E92A009F08BC /* LogInitialization.h in Headers */,
 				1A6D86C21DF75265007745E8 /* MachMessage.h in Headers */,
 				BCC56F791159957D001CCAF9 /* MachPort.h in Headers */,
+				51D124341E6DF643002B2820 /* WKURLSchemeHandler.h in Headers */,
 				1A24B5F311F531E800C38269 /* MachUtilities.h in Headers */,
 				CE1A0BD51A48E6C60054EF74 /* ManagedConfigurationSPI.h in Headers */,
 				51933DEF1965EB31008AC3EA /* MenuUtilities.h in Headers */,
@@ -8280,6 +8322,7 @@
 				83048AE61ACA45DC0082C832 /* ProcessThrottlerClient.h in Headers */,
 				A118A9EF1907AD6F00F7C92B /* QuickLookDocumentData.h in Headers */,
 				2D47B56D1810714E003A3AEE /* RemoteLayerBackingStore.h in Headers */,
+				51D124351E6DF652002B2820 /* WKURLSchemeHandlerTask.h in Headers */,
 				2DDF731518E95060004F5A66 /* RemoteLayerBackingStoreCollection.h in Headers */,
 				1AB16AEA164B3A8800290D62 /* RemoteLayerTreeContext.h in Headers */,
 				2D29ECD0192F2C2E00984B78 /* RemoteLayerTreeDisplayRefreshMonitor.h in Headers */,
@@ -9484,6 +9527,7 @@
 				1A5704F71BE01FF400874AF1 /* _WKContextMenuElementInfo.mm in Sources */,
 				A1A4FE5B18DCE9FA00B5EA8A /* _WKDownload.mm in Sources */,
 				379A873918BBFE0F00588AF2 /* _WKElementAction.mm in Sources */,
+				51D1242C1E6D41FD002B2820 /* WebURLSchemeHandlerProxy.cpp in Sources */,
 				1AD01BC81905D37E00C9C45F /* _WKErrorRecoveryAttempting.mm in Sources */,
 				317FE7CE1C487DB800A0CA89 /* _WKExperimentalFeature.mm in Sources */,
 				373D122218A473010066D9CC /* _WKFrameHandle.mm in Sources */,
@@ -9635,6 +9679,7 @@
 				2DA049B7180CCD0A00AAFA9E /* GraphicsLayerCARemote.cpp in Sources */,
 				1AC75A1E1B33695E0056745B /* HangDetectionDisablerMac.mm in Sources */,
 				51C0C9751DDD76030032CAD3 /* IconLoadingDelegate.mm in Sources */,
+				51D124231E6D34A1002B2820 /* WebURLSchemeHandlerTaskProxy.cpp in Sources */,
 				51E351CA180F2CCC00E53BE9 /* IDBUtilities.cpp in Sources */,
 				BC204EE211C83E98008F3375 /* InjectedBundle.cpp in Sources */,
 				935EEBA1127761CC003322B8 /* InjectedBundleBackForwardList.cpp in Sources */,
@@ -9804,6 +9849,7 @@
 				1A0EC75F124BC7B2007EF4A5 /* PluginProcessProxy.cpp in Sources */,
 				1A2D90BB1281C931001EB962 /* PluginProcessProxyMac.mm in Sources */,
 				1A043B5D124D5E9D00FFBFB5 /* PluginProcessProxyMessageReceiver.cpp in Sources */,
+				51D124361E6DFB39002B2820 /* WKURLSchemeHandlerTask.mm in Sources */,
 				1A043DC2124FF87500FFBFB5 /* PluginProxy.cpp in Sources */,
 				1A2D92211281DC1B001EB962 /* PluginProxyMac.mm in Sources */,
 				1A8EFA701252B84100F7067F /* PluginProxyMessageReceiver.cpp in Sources */,
@@ -9957,6 +10003,7 @@
 				1AA83F6C1A5B63FF00026EC6 /* WebDatabaseProvider.cpp in Sources */,
 				CD19A26D1A13E82A008D650E /* WebDiagnosticLoggingClient.cpp in Sources */,
 				1A5B1C5418987EDF004FCF9B /* WebDocumentLoader.cpp in Sources */,
+				51D124281E6D3F5D002B2820 /* WebURLSchemeHandler.cpp in Sources */,
 				BC111A5D112F4FBB00337BAB /* WebDragClient.cpp in Sources */,
 				C574A37712E6099D002DFE98 /* WebDragClientMac.mm in Sources */,
 				BCA0EFA012332642007D3CFB /* WebEditCommandProxy.cpp in Sources */,
@@ -9986,6 +10033,7 @@
 				BC1BE1E112D54A410004A228 /* WebGeolocationClient.cpp in Sources */,
 				BC0E5FE612D697160012A72A /* WebGeolocationManager.cpp in Sources */,
 				BC0E606112D6BA910012A72A /* WebGeolocationManagerMessageReceiver.cpp in Sources */,
+				51D124331E6DE6CA002B2820 /* WebURLSchemeHandlerCocoa.mm in Sources */,
 				BC54CACC12D64291005C67B0 /* WebGeolocationManagerProxy.cpp in Sources */,
 				BC0E618212D6CB1D0012A72A /* WebGeolocationManagerProxyMessageReceiver.cpp in Sources */,
 				413075AE1DE85F580039EC69 /* LibWebRTCSocket.cpp in Sources */,
@@ -10102,6 +10150,7 @@
 				2DA944B01884E9BA00ED86DB /* WebProcessProxyIOS.mm in Sources */,
 				51D130581382F10500351EDD /* WebProcessProxyMac.mm in Sources */,
 				BCEE7AD012817988009827DA /* WebProcessProxyMessageReceiver.cpp in Sources */,
+				51D1243A1E6E0AAB002B2820 /* APIURLSchemeHandlerTask.cpp in Sources */,
 				1A1E093318861D3800D2DC49 /* WebProgressTrackerClient.cpp in Sources */,
 				512F589C12A8838800629530 /* WebProtectionSpace.cpp in Sources */,
 				A1C512C8190656E500448914 /* WebQuickLookHandleClient.cpp in Sources */,
@@ -10283,6 +10332,7 @@
 				BC85806212B8505700EDEB2E /* WKOpenPanelResultListener.cpp in Sources */,
 				BCD597D6112B56DC00EC8C23 /* WKPage.cpp in Sources */,
 				7C89D29B1A67837B003A5FDE /* WKPageConfigurationRef.cpp in Sources */,
+				51E8B68E1E712877001B7132 /* WebURLSchemeHandlerTask.cpp in Sources */,
 				BC7B633812A45ABA00D174A4 /* WKPageGroup.cpp in Sources */,
 				BCE17B7D1381F1170012A641 /* WKPagePrivateMac.mm in Sources */,
 				2D6AB542192B1C4A003A9FD1 /* WKPDFPageNumberIndicator.mm in Sources */,

Modified: trunk/Source/WebKit2/WebProcess/Network/WebLoaderStrategy.cpp (213685 => 213686)


--- trunk/Source/WebKit2/WebProcess/Network/WebLoaderStrategy.cpp	2017-03-10 00:16:02 UTC (rev 213685)
+++ trunk/Source/WebKit2/WebProcess/Network/WebLoaderStrategy.cpp	2017-03-10 00:38:20 UTC (rev 213686)
@@ -39,8 +39,11 @@
 #include "WebFrameLoaderClient.h"
 #include "WebFrameNetworkingContext.h"
 #include "WebPage.h"
+#include "WebPageProxyMessages.h"
 #include "WebProcess.h"
 #include "WebResourceLoader.h"
+#include "WebURLSchemeHandlerProxy.h"
+#include "WebURLSchemeHandlerTaskProxy.h"
 #include <WebCore/ApplicationCacheHost.h>
 #include <WebCore/CachedResource.h>
 #include <WebCore/DiagnosticLoggingClient.h>
@@ -194,6 +197,16 @@
     }
 #endif
 
+    if (webPage) {
+        if (auto* handler = webPage->urlSchemeHandlerForScheme(resourceLoader.request().url().protocol().toStringWithoutCopying())) {
+            LOG(NetworkScheduling, "(WebProcess) WebLoaderStrategy::scheduleLoad, URL '%s' will be handled by a UIProcess URL scheme handler.", resourceLoader.url().string().utf8().data());
+            RELEASE_LOG_IF_ALLOWED(resourceLoader, "scheduleLoad: URL will be handled by a UIProcess URL scheme handler (frame = %p, resourceID = %" PRIu64 ")", resourceLoader.frame(), identifier);
+
+            handler->startNewTask(resourceLoader);
+            return;
+        }
+    }
+
     LOG(NetworkScheduling, "(WebProcess) WebLoaderStrategy::scheduleLoad, url '%s' will be scheduled with the NetworkProcess with priority %d", resourceLoader.url().string().latin1().data(), static_cast<int>(resourceLoader.request().priority()));
 
     ContentSniffingPolicy contentSniffingPolicy = resourceLoader.shouldSniffContent() ? SniffContent : DoNotSniffContent;
@@ -260,6 +273,11 @@
         m_internallyFailedResourceLoaders.remove(resourceLoader);
         return;
     }
+
+    if (auto task = m_urlSchemeHandlerTasks.take(resourceLoader->identifier())) {
+        task->stopLoading();
+        return;
+    }
     
     ResourceLoadIdentifier identifier = resourceLoader->identifier();
     if (!identifier) {

Modified: trunk/Source/WebKit2/WebProcess/Network/WebLoaderStrategy.h (213685 => 213686)


--- trunk/Source/WebKit2/WebProcess/Network/WebLoaderStrategy.h	2017-03-10 00:16:02 UTC (rev 213685)
+++ trunk/Source/WebKit2/WebProcess/Network/WebLoaderStrategy.h	2017-03-10 00:38:20 UTC (rev 213686)
@@ -35,6 +35,7 @@
 namespace WebKit {
 
 class NetworkProcessConnection;
+class WebURLSchemeHandlerTaskProxy;
 typedef uint64_t ResourceLoadIdentifier;
 
 class WebLoaderStrategy : public WebCore::LoaderStrategy {
@@ -74,6 +75,7 @@
     RunLoop::Timer<WebLoaderStrategy> m_internallyFailedLoadTimer;
     
     HashMap<unsigned long, RefPtr<WebResourceLoader>> m_webResourceLoaders;
+    HashMap<unsigned long, std::unique_ptr<WebURLSchemeHandlerTaskProxy>> m_urlSchemeHandlerTasks;
 };
 
 } // namespace WebKit

Modified: trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp (213685 => 213686)


--- trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp	2017-03-10 00:16:02 UTC (rev 213685)
+++ trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp	2017-03-10 00:38:20 UTC (rev 213686)
@@ -110,6 +110,7 @@
 #include "WebProgressTrackerClient.h"
 #include "WebSocketProvider.h"
 #include "WebStorageNamespaceProvider.h"
+#include "WebURLSchemeHandlerProxy.h"
 #include "WebUndoStep.h"
 #include "WebUserContentController.h"
 #include "WebUserMediaClient.h"
@@ -561,6 +562,9 @@
         enableEnumeratingAllNetworkInterfaces();
 #endif
 #endif
+
+    for (auto iterator : parameters.urlSchemeHandlers)
+        registerURLSchemeHandler(iterator.value, iterator.key);
 }
 
 void WebPage::reinitializeWebPage(WebPageCreationParameters&& parameters)
@@ -5744,4 +5748,42 @@
     static_cast<WebFrameLoaderClient&>(corePage()->mainFrame().loader().client()).setUseIconLoadingClient(useIconLoadingClient);
 }
 
+WebURLSchemeHandlerProxy* WebPage::urlSchemeHandlerForScheme(const String& scheme)
+{
+    return m_schemeToURLSchemeHandlerProxyMap.get(scheme);
+}
+
+void WebPage::registerURLSchemeHandler(uint64_t handlerIdentifier, const String& scheme)
+{
+    auto schemeResult = m_schemeToURLSchemeHandlerProxyMap.add(scheme, std::make_unique<WebURLSchemeHandlerProxy>(*this, handlerIdentifier));
+    ASSERT(schemeResult.isNewEntry);
+
+    auto identifierResult = m_identifierToURLSchemeHandlerProxyMap.add(handlerIdentifier, schemeResult.iterator->value.get());
+    ASSERT_UNUSED(identifierResult, identifierResult.isNewEntry);
+}
+
+void WebPage::urlSchemeHandlerTaskDidReceiveResponse(uint64_t handlerIdentifier, uint64_t taskIdentifier, const ResourceResponse& response)
+{
+    auto* handler = m_identifierToURLSchemeHandlerProxyMap.get(handlerIdentifier);
+    ASSERT(handler);
+
+    handler->taskDidReceiveResponse(taskIdentifier, response);
+}
+
+void WebPage::urlSchemeHandlerTaskDidReceiveData(uint64_t handlerIdentifier, uint64_t taskIdentifier, const IPC::DataReference& data)
+{
+    auto* handler = m_identifierToURLSchemeHandlerProxyMap.get(handlerIdentifier);
+    ASSERT(handler);
+
+    handler->taskDidReceiveData(taskIdentifier, data.size(), data.data());
+}
+
+void WebPage::urlSchemeHandlerTaskDidComplete(uint64_t handlerIdentifier, uint64_t taskIdentifier, const ResourceError& error)
+{
+    auto* handler = m_identifierToURLSchemeHandlerProxyMap.get(handlerIdentifier);
+    ASSERT(handler);
+
+    handler->taskDidComplete(taskIdentifier, error);
+}
+
 } // namespace WebKit

Modified: trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h (213685 => 213686)


--- trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h	2017-03-10 00:16:02 UTC (rev 213685)
+++ trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h	2017-03-10 00:38:20 UTC (rev 213686)
@@ -47,6 +47,7 @@
 #include "ShareableBitmap.h"
 #include "UserData.h"
 #include "UserMediaPermissionRequestManager.h"
+#include "WebURLSchemeHandler.h"
 #include <WebCore/ActivityState.h>
 #include <WebCore/DictationAlternative.h>
 #include <WebCore/DictionaryPopupInfo.h>
@@ -178,6 +179,7 @@
 class WebInspectorUI;
 class WebGestureEvent;
 class WebKeyboardEvent;
+class WebURLSchemeHandlerProxy;
 class WebMouseEvent;
 class WebNotificationClient;
 class WebOpenPanelResultListener;
@@ -969,6 +971,8 @@
     void didConcludeEditDataInteraction();
 #endif
 
+    WebURLSchemeHandlerProxy* urlSchemeHandlerForScheme(const String&);
+
 private:
     WebPage(uint64_t pageID, WebPageCreationParameters&&);
 
@@ -1262,6 +1266,12 @@
     void didReceivePasswordForQuickLookDocument(const String&);
 #endif
 
+    void registerURLSchemeHandler(uint64_t identifier, const String& scheme);
+
+    void urlSchemeHandlerTaskDidReceiveResponse(uint64_t handlerIdentifier, uint64_t taskIdentifier, const WebCore::ResourceResponse&);
+    void urlSchemeHandlerTaskDidReceiveData(uint64_t handlerIdentifier, uint64_t taskIdentifier, const IPC::DataReference&);
+    void urlSchemeHandlerTaskDidComplete(uint64_t handlerIdentifier, uint64_t taskIdentifier, const WebCore::ResourceError&);
+
     uint64_t m_pageID;
 
     std::unique_ptr<WebCore::Page> m_page;
@@ -1540,6 +1550,9 @@
     WebCore::UserInterfaceLayoutDirection m_userInterfaceLayoutDirection { WebCore::UserInterfaceLayoutDirection::LTR };
 
     const String m_overrideContentSecurityPolicy;
+
+    HashMap<String, std::unique_ptr<WebURLSchemeHandlerProxy>> m_schemeToURLSchemeHandlerProxyMap;
+    HashMap<uint64_t, WebURLSchemeHandlerProxy*> m_identifierToURLSchemeHandlerProxyMap;
 };
 
 } // namespace WebKit

Modified: trunk/Source/WebKit2/WebProcess/WebPage/WebPage.messages.in (213685 => 213686)


--- trunk/Source/WebKit2/WebProcess/WebPage/WebPage.messages.in	2017-03-10 00:16:02 UTC (rev 213685)
+++ trunk/Source/WebKit2/WebProcess/WebPage/WebPage.messages.in	2017-03-10 00:38:20 UTC (rev 213686)
@@ -469,4 +469,10 @@
 #if USE(QUICK_LOOK)
     DidReceivePasswordForQuickLookDocument(String password)
 #endif
+
+    RegisterURLSchemeHandler(uint64_t identifier, String scheme)
+
+    URLSchemeHandlerTaskDidReceiveResponse(uint64_t providerIdentifier, uint64_t taskIdentifier, WebCore::ResourceResponse response)
+    URLSchemeHandlerTaskDidReceiveData(uint64_t providerIdentifier, uint64_t taskIdentifier, IPC::DataReference data)
+    URLSchemeHandlerTaskDidComplete(uint64_t providerIdentifier, uint64_t taskIdentifier, WebCore::ResourceError error)
 }

Added: trunk/Source/WebKit2/WebProcess/WebPage/WebURLSchemeHandlerProxy.cpp (0 => 213686)


--- trunk/Source/WebKit2/WebProcess/WebPage/WebURLSchemeHandlerProxy.cpp	                        (rev 0)
+++ trunk/Source/WebKit2/WebProcess/WebPage/WebURLSchemeHandlerProxy.cpp	2017-03-10 00:38:20 UTC (rev 213686)
@@ -0,0 +1,83 @@
+/*
+ * Copyright (C) 2017 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 "WebURLSchemeHandlerProxy.h"
+
+#include "WebErrors.h"
+#include <WebCore/ResourceLoader.h>
+
+using namespace WebCore;
+
+namespace WebKit {
+
+WebURLSchemeHandlerProxy::WebURLSchemeHandlerProxy(WebPage& page, uint64_t identifier)
+    : m_webPage(page)
+    , m_identifier(identifier)
+{
+}
+
+WebURLSchemeHandlerProxy::~WebURLSchemeHandlerProxy()
+{
+    ASSERT(m_tasks.isEmpty());
+}
+
+void WebURLSchemeHandlerProxy::startNewTask(ResourceLoader& loader)
+{
+    auto result = m_tasks.add(loader.identifier(), std::make_unique<WebURLSchemeHandlerTaskProxy>(*this, loader));
+    ASSERT(result.isNewEntry);
+
+    result.iterator->value->startLoading();
+}
+
+
+void WebURLSchemeHandlerProxy::taskDidReceiveResponse(uint64_t taskIdentifier, const ResourceResponse& response)
+{
+    auto* task = m_tasks.get(taskIdentifier);
+    if (!task)
+        return;
+
+    task->didReceiveResponse(response);
+}
+
+void WebURLSchemeHandlerProxy::taskDidReceiveData(uint64_t taskIdentifier, size_t size, const uint8_t* data)
+{
+    auto* task = m_tasks.get(taskIdentifier);
+    if (!task)
+        return;
+
+    task->didReceiveData(size, data);
+}
+
+void WebURLSchemeHandlerProxy::taskDidComplete(uint64_t taskIdentifier, const ResourceError& error)
+{
+    auto task = m_tasks.take(taskIdentifier);
+    if (!task)
+        return;
+
+    task->didComplete(error);
+}
+
+} // namespace WebKit

Copied: trunk/Source/WebKit2/WebProcess/WebPage/WebURLSchemeHandlerProxy.h (from rev 213685, trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebViewConfigurationInternal.h) (0 => 213686)


--- trunk/Source/WebKit2/WebProcess/WebPage/WebURLSchemeHandlerProxy.h	                        (rev 0)
+++ trunk/Source/WebKit2/WebProcess/WebPage/WebURLSchemeHandlerProxy.h	2017-03-10 00:38:20 UTC (rev 213686)
@@ -0,0 +1,63 @@
+/*
+ * Copyright (C) 2017 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 "WebURLSchemeHandlerTaskProxy.h"
+#include <wtf/HashMap.h>
+
+namespace WebCore {
+class ResourceError;
+class ResourceLoader;
+class ResourceResponse;
+}
+
+namespace WebKit {
+
+class WebPage;
+
+class WebURLSchemeHandlerProxy {
+    WTF_MAKE_NONCOPYABLE(WebURLSchemeHandlerProxy);
+public:
+    WebURLSchemeHandlerProxy(WebPage&, uint64_t identifier);
+    ~WebURLSchemeHandlerProxy();
+
+    void startNewTask(WebCore::ResourceLoader&);
+
+    uint64_t identifier() const { return m_identifier; }
+    WebPage& page() { return m_webPage; }
+
+    void taskDidReceiveResponse(uint64_t taskIdentifier, const WebCore::ResourceResponse&);
+    void taskDidReceiveData(uint64_t taskIdentifier, size_t, const uint8_t* data);
+    void taskDidComplete(uint64_t taskIdentifier, const WebCore::ResourceError&);
+
+private:
+    WebPage& m_webPage;
+    uint64_t m_identifier { 0 };
+
+    HashMap<unsigned long, std::unique_ptr<WebURLSchemeHandlerTaskProxy>> m_tasks;
+}; // class WebURLSchemeHandlerProxy
+
+} // namespace WebKit

Added: trunk/Source/WebKit2/WebProcess/WebPage/WebURLSchemeHandlerTaskProxy.cpp (0 => 213686)


--- trunk/Source/WebKit2/WebProcess/WebPage/WebURLSchemeHandlerTaskProxy.cpp	                        (rev 0)
+++ trunk/Source/WebKit2/WebProcess/WebPage/WebURLSchemeHandlerTaskProxy.cpp	2017-03-10 00:38:20 UTC (rev 213686)
@@ -0,0 +1,92 @@
+/*
+ * Copyright (C) 2017 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 "WebURLSchemeHandlerTaskProxy.h"
+
+#include "WebPage.h"
+#include "WebPageProxyMessages.h"
+#include "WebURLSchemeHandlerProxy.h"
+#include <WebCore/NetworkLoadMetrics.h>
+#include <WebCore/ResourceError.h>
+#include <WebCore/ResourceLoader.h>
+#include <wtf/CurrentTime.h>
+
+using namespace WebCore;
+
+namespace WebKit {
+
+WebURLSchemeHandlerTaskProxy::WebURLSchemeHandlerTaskProxy(WebURLSchemeHandlerProxy& handler, ResourceLoader& loader)
+    : m_urlSchemeHandler(handler)
+    , m_coreLoader(&loader)
+    , m_request(loader.request())
+{
+}
+
+void WebURLSchemeHandlerTaskProxy::startLoading()
+{
+    ASSERT(m_coreLoader);
+    m_urlSchemeHandler.page().send(Messages::WebPageProxy::StartURLSchemeHandlerTask(m_urlSchemeHandler.identifier(), m_coreLoader->identifier(), m_request));
+}
+
+void WebURLSchemeHandlerTaskProxy::stopLoading()
+{
+    if (!m_coreLoader)
+        return;
+
+    m_urlSchemeHandler.page().send(Messages::WebPageProxy::StopURLSchemeHandlerTask(m_urlSchemeHandler.identifier(), m_coreLoader->identifier()));
+    m_coreLoader = nullptr;
+}
+
+void WebURLSchemeHandlerTaskProxy::didReceiveResponse(const ResourceResponse& response)
+{
+    if (!m_coreLoader)
+        return;
+
+    m_coreLoader->didReceiveResponse(response);
+}
+
+void WebURLSchemeHandlerTaskProxy::didReceiveData(size_t size, const uint8_t* data)
+{
+    if (!m_coreLoader)
+        return;
+
+    m_coreLoader->didReceiveData(reinterpret_cast<const char*>(data), size, 0, DataPayloadType::DataPayloadBytes);
+}
+
+void WebURLSchemeHandlerTaskProxy::didComplete(const ResourceError& error)
+{
+    if (!m_coreLoader)
+        return;
+
+    if (error.isNull())
+        m_coreLoader->didFinishLoading(NetworkLoadMetrics());
+    else
+        m_coreLoader->didFail(error);
+
+    m_coreLoader = nullptr;
+}
+
+} // namespace WebKit

Copied: trunk/Source/WebKit2/WebProcess/WebPage/WebURLSchemeHandlerTaskProxy.h (from rev 213685, trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebViewConfigurationInternal.h) (0 => 213686)


--- trunk/Source/WebKit2/WebProcess/WebPage/WebURLSchemeHandlerTaskProxy.h	                        (rev 0)
+++ trunk/Source/WebKit2/WebProcess/WebPage/WebURLSchemeHandlerTaskProxy.h	2017-03-10 00:38:20 UTC (rev 213686)
@@ -0,0 +1,61 @@
+/*
+ * Copyright (C) 2017 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/ResourceRequest.h>
+
+namespace WebCore {
+class ResourceError;
+class ResourceLoader;
+class ResourceResponse;
+}
+
+namespace WebKit {
+
+class WebURLSchemeHandlerProxy;
+
+class WebURLSchemeHandlerTaskProxy {
+    WTF_MAKE_NONCOPYABLE(WebURLSchemeHandlerTaskProxy);
+public:
+    WebURLSchemeHandlerTaskProxy(WebURLSchemeHandlerProxy&, WebCore::ResourceLoader&);
+
+    const WebCore::ResourceRequest& request() const { return m_request; }
+
+    void startLoading();
+    void stopLoading();
+
+    void didReceiveResponse(const WebCore::ResourceResponse&);
+    void didReceiveData(size_t, const uint8_t* data);
+    void didComplete(const WebCore::ResourceError&);
+
+private:
+    WebURLSchemeHandlerProxy& m_urlSchemeHandler;
+    RefPtr<WebCore::ResourceLoader> m_coreLoader;
+    WebCore::ResourceRequest m_request;
+
+};
+
+} // namespace WebKit
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to