Title: [160939] trunk/Source/WebKit2
Revision
160939
Author
wei...@apple.com
Date
2013-12-20 15:55:04 -0800 (Fri, 20 Dec 2013)

Log Message

[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):

Modified Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (160938 => 160939)


--- trunk/Source/WebKit2/ChangeLog	2013-12-20 23:46:12 UTC (rev 160938)
+++ trunk/Source/WebKit2/ChangeLog	2013-12-20 23:55:04 UTC (rev 160939)
@@ -1,3 +1,28 @@
+2013-12-20  Sam Weinig  <s...@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_hor...@apple.com>
 
         WebKit2 View Gestures: Implement smartMagnifyWithEvent: and make it work

Modified: trunk/Source/WebKit2/UIProcess/API/C/mac/WKContextPrivateMac.h (160938 => 160939)


--- trunk/Source/WebKit2/UIProcess/API/C/mac/WKContextPrivateMac.h	2013-12-20 23:46:12 UTC (rev 160938)
+++ trunk/Source/WebKit2/UIProcess/API/C/mac/WKContextPrivateMac.h	2013-12-20 23:55:04 UTC (rev 160939)
@@ -44,6 +44,9 @@
 
 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 */

Modified: trunk/Source/WebKit2/UIProcess/API/C/mac/WKContextPrivateMac.mm (160938 => 160939)


--- trunk/Source/WebKit2/UIProcess/API/C/mac/WKContextPrivateMac.mm	2013-12-20 23:46:12 UTC (rev 160938)
+++ trunk/Source/WebKit2/UIProcess/API/C/mac/WKContextPrivateMac.mm	2013-12-20 23:55:04 UTC (rev 160939)
@@ -105,6 +105,17 @@
 }
 
 
+
+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()

Modified: trunk/Source/WebKit2/UIProcess/API/Cocoa/WKBrowsingContextController.mm (160938 => 160939)


--- trunk/Source/WebKit2/UIProcess/API/Cocoa/WKBrowsingContextController.mm	2013-12-20 23:46:12 UTC (rev 160938)
+++ trunk/Source/WebKit2/UIProcess/API/Cocoa/WKBrowsingContextController.mm	2013-12-20 23:55:04 UTC (rev 160939)
@@ -176,22 +176,12 @@
 
 + (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

Modified: trunk/Source/WebKit2/UIProcess/WebContext.cpp (160938 => 160939)


--- trunk/Source/WebKit2/UIProcess/WebContext.cpp	2013-12-20 23:46:12 UTC (rev 160938)
+++ trunk/Source/WebKit2/UIProcess/WebContext.cpp	2013-12-20 23:55:04 UTC (rev 160939)
@@ -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 @@
     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;

Modified: trunk/Source/WebKit2/UIProcess/WebContext.h (160938 => 160939)


--- trunk/Source/WebKit2/UIProcess/WebContext.h	2013-12-20 23:46:12 UTC (rev 160938)
+++ trunk/Source/WebKit2/UIProcess/WebContext.h	2013-12-20 23:55:04 UTC (rev 160939)
@@ -85,11 +85,6 @@
 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 @@
     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 @@
     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 @@
 
 #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

Modified: trunk/Source/WebKit2/UIProcess/mac/WebContextMac.mm (160938 => 160939)


--- trunk/Source/WebKit2/UIProcess/mac/WebContextMac.mm	2013-12-20 23:46:12 UTC (rev 160938)
+++ trunk/Source/WebKit2/UIProcess/mac/WebContextMac.mm	2013-12-20 23:55:04 UTC (rev 160939)
@@ -310,8 +310,8 @@
 #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 @@
     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::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::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
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to