[WK2] Add SPI for using a custom protocol handler
authorweinig@apple.com <weinig@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 20 Dec 2013 23:55:04 +0000 (23:55 +0000)
committerweinig@apple.com <weinig@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 20 Dec 2013 23:55:04 +0000 (23:55 +0000)
https://bugs.webkit.org/show_bug.cgi?id=126089

Reviewed by Anders Carlsson.

* UIProcess/API/C/mac/WKContextPrivateMac.h:
* UIProcess/API/C/mac/WKContextPrivateMac.mm:
(WKContextRegisterSchemeForCustomProtocol):
(WKContextUnregisterSchemeForCustomProtocol):
* UIProcess/API/Cocoa/WKBrowsingContextController.mm:
(+[WKBrowsingContextController registerSchemeForCustomProtocol:]):
(+[WKBrowsingContextController unregisterSchemeForCustomProtocol:]):
* UIProcess/WebContext.cpp:
(WebKit::WebContext::globalURLSchemesWithCustomProtocolHandlers):
(WebKit::WebContext::registerGlobalURLSchemeAsHavingCustomProtocolHandlers):
(WebKit::WebContext::unregisterGlobalURLSchemeAsHavingCustomProtocolHandlers):
* UIProcess/WebContext.h:
* UIProcess/mac/WebContextMac.mm:
(WebKit::WebContext::platformInitializeWebProcess):
(WebKit::WebContext::platformInitializeNetworkProcess):
(WebKit::WebContext::registerNotificationObservers):
(WebKit::WebContext::unregisterNotificationObservers):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@160939 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/API/C/mac/WKContextPrivateMac.h
Source/WebKit2/UIProcess/API/C/mac/WKContextPrivateMac.mm
Source/WebKit2/UIProcess/API/Cocoa/WKBrowsingContextController.mm
Source/WebKit2/UIProcess/WebContext.cpp
Source/WebKit2/UIProcess/WebContext.h
Source/WebKit2/UIProcess/mac/WebContextMac.mm

index 8eb52b9..c1915af 100644 (file)
@@ -1,3 +1,28 @@
+2013-12-20  Sam Weinig  <sam@webkit.org>
+
+        [WK2] Add SPI for using a custom protocol handler
+        https://bugs.webkit.org/show_bug.cgi?id=126089
+
+        Reviewed by Anders Carlsson.
+
+        * UIProcess/API/C/mac/WKContextPrivateMac.h:
+        * UIProcess/API/C/mac/WKContextPrivateMac.mm:
+        (WKContextRegisterSchemeForCustomProtocol):
+        (WKContextUnregisterSchemeForCustomProtocol):
+        * UIProcess/API/Cocoa/WKBrowsingContextController.mm:
+        (+[WKBrowsingContextController registerSchemeForCustomProtocol:]):
+        (+[WKBrowsingContextController unregisterSchemeForCustomProtocol:]):
+        * UIProcess/WebContext.cpp:
+        (WebKit::WebContext::globalURLSchemesWithCustomProtocolHandlers):
+        (WebKit::WebContext::registerGlobalURLSchemeAsHavingCustomProtocolHandlers):
+        (WebKit::WebContext::unregisterGlobalURLSchemeAsHavingCustomProtocolHandlers):
+        * UIProcess/WebContext.h:
+        * UIProcess/mac/WebContextMac.mm:
+        (WebKit::WebContext::platformInitializeWebProcess):
+        (WebKit::WebContext::platformInitializeNetworkProcess):
+        (WebKit::WebContext::registerNotificationObservers):
+        (WebKit::WebContext::unregisterNotificationObservers):
+
 2013-12-20  Tim Horton  <timothy_horton@apple.com>
 
         WebKit2 View Gestures: Implement smartMagnifyWithEvent: and make it work
index 937a4a6..30b9ac2 100644 (file)
@@ -44,6 +44,9 @@ WK_EXPORT void WKContextGetInfoForInstalledPlugIns(WKContextRef context, WKConte
 
 WK_EXPORT void WKContextResetHSTSHosts(WKContextRef context);
 
+WK_EXPORT void WKContextRegisterSchemeForCustomProtocol(WKContextRef context, WKStringRef scheme);
+WK_EXPORT void WKContextUnregisterSchemeForCustomProtocol(WKContextRef context, WKStringRef scheme);
+
 /* DEPRECATED -  Please use constants from WKPluginInformation instead. */
 
 /* Value type: WKStringRef */
index 282c32f..0425c5d 100644 (file)
@@ -105,6 +105,17 @@ void WKContextResetHSTSHosts(WKContextRef context)
 }
 
 
+
+void WKContextRegisterSchemeForCustomProtocol(WKContextRef context, WKStringRef scheme)
+{
+    WebContext::registerGlobalURLSchemeAsHavingCustomProtocolHandlers(toWTFString(scheme));
+}
+
+void WKContextUnregisterSchemeForCustomProtocol(WKContextRef context, WKStringRef scheme)
+{
+    WebContext::unregisterGlobalURLSchemeAsHavingCustomProtocolHandlers(toWTFString(scheme));
+}
+
 /* DEPRECATED -  Please use constants from WKPluginInformation instead. */
 
 WKStringRef WKPlugInInfoPathKey()
index 5c24aff..0c2b85a 100644 (file)
@@ -176,22 +176,12 @@ static NSString * const frameErrorKey = @"WKBrowsingContextFrameErrorKey";
 
 + (void)registerSchemeForCustomProtocol:(NSString *)scheme
 {
-    if (!scheme)
-        return;
-
-    NSString *lowercaseScheme = [scheme lowercaseString];
-    [[WKBrowsingContextController customSchemes] addObject:lowercaseScheme];
-    [[NSNotificationCenter defaultCenter] postNotificationName:SchemeForCustomProtocolRegisteredNotificationName object:lowercaseScheme];
+    WebContext::registerGlobalURLSchemeAsHavingCustomProtocolHandlers(scheme);
 }
 
 + (void)unregisterSchemeForCustomProtocol:(NSString *)scheme
 {
-    if (!scheme)
-        return;
-
-    NSString *lowercaseScheme = [scheme lowercaseString];
-    [[WKBrowsingContextController customSchemes] removeObject:lowercaseScheme];
-    [[NSNotificationCenter defaultCenter] postNotificationName:SchemeForCustomProtocolUnregisteredNotificationName object:lowercaseScheme];
+    WebContext::unregisterGlobalURLSchemeAsHavingCustomProtocolHandlers(scheme);
 }
 
 - (void)loadRequest:(NSURLRequest *)request
index 7a5c52a..3dd2800 100644 (file)
@@ -64,6 +64,7 @@
 #include <runtime/Operations.h>
 #include <wtf/CurrentTime.h>
 #include <wtf/MainThread.h>
+#include <wtf/NeverDestroyed.h>
 #include <wtf/RunLoop.h>
 
 #if ENABLE(BATTERY_STATUS)
@@ -874,6 +875,34 @@ void WebContext::registerURLSchemeAsCORSEnabled(const String& urlScheme)
     sendToAllProcesses(Messages::WebProcess::RegisterURLSchemeAsCORSEnabled(urlScheme));
 }
 
+HashSet<String>& WebContext::globalURLSchemesWithCustomProtocolHandlers()
+{
+    static NeverDestroyed<HashSet<String>> set;
+    return set;
+}
+
+void WebContext::registerGlobalURLSchemeAsHavingCustomProtocolHandlers(const String& urlScheme)
+{
+    if (!urlScheme)
+        return;
+
+    String schemeLower = urlScheme.lower();
+    globalURLSchemesWithCustomProtocolHandlers().add(schemeLower);
+    for (auto* context : allContexts())
+        context->registerSchemeForCustomProtocol(schemeLower);
+}
+
+void WebContext::unregisterGlobalURLSchemeAsHavingCustomProtocolHandlers(const String& urlScheme)
+{
+    if (!urlScheme)
+        return;
+
+    String schemeLower = urlScheme.lower();
+    globalURLSchemesWithCustomProtocolHandlers().remove(schemeLower);
+    for (auto* context : allContexts())
+        context->unregisterSchemeForCustomProtocol(schemeLower);
+}
+
 void WebContext::setCacheModel(CacheModel cacheModel)
 {
     m_cacheModel = cacheModel;
index e9a2e33..2690c6b 100644 (file)
@@ -85,11 +85,6 @@ class WebNetworkInfoManagerProxy;
 struct NetworkProcessCreationParameters;
 #endif
 
-#if PLATFORM(MAC)
-extern NSString *SchemeForCustomProtocolRegisteredNotificationName;
-extern NSString *SchemeForCustomProtocolUnregisteredNotificationName;
-#endif
-
 class WebContext : public API::ObjectImpl<API::Object::Type::Context>, private CoreIPC::MessageReceiver
 #if ENABLE(NETSCAPE_PLUGIN_API)
     , private PluginInfoStoreClient
@@ -312,6 +307,15 @@ public:
     bool isURLKnownHSTSHost(const String& urlString, bool privateBrowsingEnabled) const;
     void resetHSTSHosts();
 
+#if ENABLE(CUSTOM_PROTOCOLS)
+    void registerSchemeForCustomProtocol(const String&);
+    void unregisterSchemeForCustomProtocol(const String&);
+
+    static HashSet<String>& globalURLSchemesWithCustomProtocolHandlers();
+    static void registerGlobalURLSchemeAsHavingCustomProtocolHandlers(const String&);
+    static void unregisterGlobalURLSchemeAsHavingCustomProtocolHandlers(const String&);
+#endif
+
 private:
     void platformInitialize();
 
@@ -391,11 +395,6 @@ private:
     void unregisterNotificationObservers();
 #endif
 
-#if ENABLE(CUSTOM_PROTOCOLS)
-    void registerSchemeForCustomProtocol(const String&);
-    void unregisterSchemeForCustomProtocol(const String&);
-#endif
-
     void addPlugInAutoStartOriginHash(const String& pageOrigin, unsigned plugInOriginHash);
     void plugInDidReceiveUserInteraction(unsigned plugInOriginHash);
 
@@ -469,9 +468,6 @@ private:
 
 #if PLATFORM(MAC)
     RetainPtr<NSObject> m_enhancedAccessibilityObserver;
-    RetainPtr<NSObject> m_customSchemeRegisteredObserver;
-    RetainPtr<NSObject> m_customSchemeUnregisteredObserver;
-
     RetainPtr<NSObject> m_automaticTextReplacementNotificationObserver;
     RetainPtr<NSObject> m_automaticSpellingCorrectionNotificationObserver;
 #if !PLATFORM(IOS) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 1090
index 6d744d2..1ed5023 100644 (file)
@@ -310,8 +310,8 @@ void WebContext::platformInitializeWebProcess(WebProcessCreationParameters& para
 #if ENABLE(NETWORK_PROCESS)
     if (!m_usesNetworkProcess) {
 #endif
-#if ENABLE(CUSTOM_PROTOCOLS) && WK_API_ENABLED
-        for (NSString *scheme in [WKBrowsingContextController customSchemes])
+#if ENABLE(CUSTOM_PROTOCOLS)
+        for (const auto& scheme : globalURLSchemesWithCustomProtocolHandlers())
             parameters.urlSchemesRegisteredForCustomProtocols.append(scheme);
 #endif
 #if ENABLE(NETWORK_PROCESS)
@@ -329,8 +329,8 @@ void WebContext::platformInitializeNetworkProcess(NetworkProcessCreationParamete
     parameters.parentProcessName = [[NSProcessInfo processInfo] processName];
     parameters.uiProcessBundleIdentifier = [[NSBundle mainBundle] bundleIdentifier];
 
-#if WK_API_ENABLED
-    for (NSString *scheme in [WKBrowsingContextController customSchemes])
+#if ENABLE(CUSTOM_PROTOCOLS)
+    for (const auto& scheme : globalURLSchemesWithCustomProtocolHandlers())
         parameters.urlSchemesRegisteredForCustomProtocols.append(scheme);
 #endif
 
@@ -573,18 +573,6 @@ void WebContext::processSuppressionEnabledChanged()
 void WebContext::registerNotificationObservers()
 {
 #if !PLATFORM(IOS)
-    m_customSchemeRegisteredObserver = [[NSNotificationCenter defaultCenter] addObserverForName:WebKit::SchemeForCustomProtocolRegisteredNotificationName object:nil queue:[NSOperationQueue currentQueue] usingBlock:^(NSNotification *notification) {
-        NSString *scheme = [notification object];
-        ASSERT([scheme isKindOfClass:[NSString class]]);
-        registerSchemeForCustomProtocol(scheme);
-    }];
-
-    m_customSchemeUnregisteredObserver = [[NSNotificationCenter defaultCenter] addObserverForName:WebKit::SchemeForCustomProtocolUnregisteredNotificationName object:nil queue:[NSOperationQueue currentQueue] usingBlock:^(NSNotification *notification) {
-        NSString *scheme = [notification object];
-        ASSERT([scheme isKindOfClass:[NSString class]]);
-        unregisterSchemeForCustomProtocol(scheme);
-    }];
-
     // Listen for enhanced accessibility changes and propagate them to the WebProcess.
     m_enhancedAccessibilityObserver = [[NSNotificationCenter defaultCenter] addObserverForName:WebKitApplicationDidChangeAccessibilityEnhancedUserInterfaceNotification object:nil queue:[NSOperationQueue currentQueue] usingBlock:^(NSNotification *note) {
         setEnhancedAccessibility([[[note userInfo] objectForKey:@"AXEnhancedUserInterface"] boolValue]);
@@ -617,10 +605,7 @@ void WebContext::registerNotificationObservers()
 void WebContext::unregisterNotificationObservers()
 {
 #if !PLATFORM(IOS)
-    [[NSNotificationCenter defaultCenter] removeObserver:m_customSchemeRegisteredObserver.get()];
-    [[NSNotificationCenter defaultCenter] removeObserver:m_customSchemeUnregisteredObserver.get()];
-    [[NSNotificationCenter defaultCenter] removeObserver:m_enhancedAccessibilityObserver.get()];
-    
+    [[NSNotificationCenter defaultCenter] removeObserver:m_enhancedAccessibilityObserver.get()];    
     [[NSNotificationCenter defaultCenter] removeObserver:m_automaticTextReplacementNotificationObserver.get()];
     [[NSNotificationCenter defaultCenter] removeObserver:m_automaticSpellingCorrectionNotificationObserver.get()];
 #if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1090