Changeset 160939 in webkit


Ignore:
Timestamp:
Dec 20, 2013 3:55:04 PM (10 years ago)
Author:
weinig@apple.com
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):

Location:
trunk/Source/WebKit2
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r160923 r160939  
     12013-12-20  Sam Weinig  <sam@webkit.org>
     2
     3        [WK2] Add SPI for using a custom protocol handler
     4        https://bugs.webkit.org/show_bug.cgi?id=126089
     5
     6        Reviewed by Anders Carlsson.
     7
     8        * UIProcess/API/C/mac/WKContextPrivateMac.h:
     9        * UIProcess/API/C/mac/WKContextPrivateMac.mm:
     10        (WKContextRegisterSchemeForCustomProtocol):
     11        (WKContextUnregisterSchemeForCustomProtocol):
     12        * UIProcess/API/Cocoa/WKBrowsingContextController.mm:
     13        (+[WKBrowsingContextController registerSchemeForCustomProtocol:]):
     14        (+[WKBrowsingContextController unregisterSchemeForCustomProtocol:]):
     15        * UIProcess/WebContext.cpp:
     16        (WebKit::WebContext::globalURLSchemesWithCustomProtocolHandlers):
     17        (WebKit::WebContext::registerGlobalURLSchemeAsHavingCustomProtocolHandlers):
     18        (WebKit::WebContext::unregisterGlobalURLSchemeAsHavingCustomProtocolHandlers):
     19        * UIProcess/WebContext.h:
     20        * UIProcess/mac/WebContextMac.mm:
     21        (WebKit::WebContext::platformInitializeWebProcess):
     22        (WebKit::WebContext::platformInitializeNetworkProcess):
     23        (WebKit::WebContext::registerNotificationObservers):
     24        (WebKit::WebContext::unregisterNotificationObservers):
     25
    1262013-12-20  Tim Horton  <timothy_horton@apple.com>
    227
  • trunk/Source/WebKit2/UIProcess/API/C/mac/WKContextPrivateMac.h

    r159788 r160939  
    4545WK_EXPORT void WKContextResetHSTSHosts(WKContextRef context);
    4646
     47WK_EXPORT void WKContextRegisterSchemeForCustomProtocol(WKContextRef context, WKStringRef scheme);
     48WK_EXPORT void WKContextUnregisterSchemeForCustomProtocol(WKContextRef context, WKStringRef scheme);
     49
    4750/* DEPRECATED -  Please use constants from WKPluginInformation instead. */
    4851
  • trunk/Source/WebKit2/UIProcess/API/C/mac/WKContextPrivateMac.mm

    r160608 r160939  
    106106
    107107
     108
     109void WKContextRegisterSchemeForCustomProtocol(WKContextRef context, WKStringRef scheme)
     110{
     111    WebContext::registerGlobalURLSchemeAsHavingCustomProtocolHandlers(toWTFString(scheme));
     112}
     113
     114void WKContextUnregisterSchemeForCustomProtocol(WKContextRef context, WKStringRef scheme)
     115{
     116    WebContext::unregisterGlobalURLSchemeAsHavingCustomProtocolHandlers(toWTFString(scheme));
     117}
     118
    108119/* DEPRECATED -  Please use constants from WKPluginInformation instead. */
    109120
  • trunk/Source/WebKit2/UIProcess/API/Cocoa/WKBrowsingContextController.mm

    r160787 r160939  
    177177+ (void)registerSchemeForCustomProtocol:(NSString *)scheme
    178178{
    179     if (!scheme)
    180         return;
    181 
    182     NSString *lowercaseScheme = [scheme lowercaseString];
    183     [[WKBrowsingContextController customSchemes] addObject:lowercaseScheme];
    184     [[NSNotificationCenter defaultCenter] postNotificationName:SchemeForCustomProtocolRegisteredNotificationName object:lowercaseScheme];
     179    WebContext::registerGlobalURLSchemeAsHavingCustomProtocolHandlers(scheme);
    185180}
    186181
    187182+ (void)unregisterSchemeForCustomProtocol:(NSString *)scheme
    188183{
    189     if (!scheme)
    190         return;
    191 
    192     NSString *lowercaseScheme = [scheme lowercaseString];
    193     [[WKBrowsingContextController customSchemes] removeObject:lowercaseScheme];
    194     [[NSNotificationCenter defaultCenter] postNotificationName:SchemeForCustomProtocolUnregisteredNotificationName object:lowercaseScheme];
     184    WebContext::unregisterGlobalURLSchemeAsHavingCustomProtocolHandlers(scheme);
    195185}
    196186
  • trunk/Source/WebKit2/UIProcess/WebContext.cpp

    r160922 r160939  
    6565#include <wtf/CurrentTime.h>
    6666#include <wtf/MainThread.h>
     67#include <wtf/NeverDestroyed.h>
    6768#include <wtf/RunLoop.h>
    6869
     
    875876}
    876877
     878HashSet<String>& WebContext::globalURLSchemesWithCustomProtocolHandlers()
     879{
     880    static NeverDestroyed<HashSet<String>> set;
     881    return set;
     882}
     883
     884void WebContext::registerGlobalURLSchemeAsHavingCustomProtocolHandlers(const String& urlScheme)
     885{
     886    if (!urlScheme)
     887        return;
     888
     889    String schemeLower = urlScheme.lower();
     890    globalURLSchemesWithCustomProtocolHandlers().add(schemeLower);
     891    for (auto* context : allContexts())
     892        context->registerSchemeForCustomProtocol(schemeLower);
     893}
     894
     895void WebContext::unregisterGlobalURLSchemeAsHavingCustomProtocolHandlers(const String& urlScheme)
     896{
     897    if (!urlScheme)
     898        return;
     899
     900    String schemeLower = urlScheme.lower();
     901    globalURLSchemesWithCustomProtocolHandlers().remove(schemeLower);
     902    for (auto* context : allContexts())
     903        context->unregisterSchemeForCustomProtocol(schemeLower);
     904}
     905
    877906void WebContext::setCacheModel(CacheModel cacheModel)
    878907{
  • trunk/Source/WebKit2/UIProcess/WebContext.h

    r160922 r160939  
    8686#endif
    8787
    88 #if PLATFORM(MAC)
    89 extern NSString *SchemeForCustomProtocolRegisteredNotificationName;
    90 extern NSString *SchemeForCustomProtocolUnregisteredNotificationName;
    91 #endif
    92 
    9388class WebContext : public API::ObjectImpl<API::Object::Type::Context>, private CoreIPC::MessageReceiver
    9489#if ENABLE(NETSCAPE_PLUGIN_API)
     
    312307    bool isURLKnownHSTSHost(const String& urlString, bool privateBrowsingEnabled) const;
    313308    void resetHSTSHosts();
     309
     310#if ENABLE(CUSTOM_PROTOCOLS)
     311    void registerSchemeForCustomProtocol(const String&);
     312    void unregisterSchemeForCustomProtocol(const String&);
     313
     314    static HashSet<String>& globalURLSchemesWithCustomProtocolHandlers();
     315    static void registerGlobalURLSchemeAsHavingCustomProtocolHandlers(const String&);
     316    static void unregisterGlobalURLSchemeAsHavingCustomProtocolHandlers(const String&);
     317#endif
    314318
    315319private:
     
    392396#endif
    393397
    394 #if ENABLE(CUSTOM_PROTOCOLS)
    395     void registerSchemeForCustomProtocol(const String&);
    396     void unregisterSchemeForCustomProtocol(const String&);
    397 #endif
    398 
    399398    void addPlugInAutoStartOriginHash(const String& pageOrigin, unsigned plugInOriginHash);
    400399    void plugInDidReceiveUserInteraction(unsigned plugInOriginHash);
     
    470469#if PLATFORM(MAC)
    471470    RetainPtr<NSObject> m_enhancedAccessibilityObserver;
    472     RetainPtr<NSObject> m_customSchemeRegisteredObserver;
    473     RetainPtr<NSObject> m_customSchemeUnregisteredObserver;
    474 
    475471    RetainPtr<NSObject> m_automaticTextReplacementNotificationObserver;
    476472    RetainPtr<NSObject> m_automaticSpellingCorrectionNotificationObserver;
  • trunk/Source/WebKit2/UIProcess/mac/WebContextMac.mm

    r159760 r160939  
    311311    if (!m_usesNetworkProcess) {
    312312#endif
    313 #if ENABLE(CUSTOM_PROTOCOLS) && WK_API_ENABLED
    314         for (NSString *scheme in [WKBrowsingContextController customSchemes])
     313#if ENABLE(CUSTOM_PROTOCOLS)
     314        for (const auto& scheme : globalURLSchemesWithCustomProtocolHandlers())
    315315            parameters.urlSchemesRegisteredForCustomProtocols.append(scheme);
    316316#endif
     
    330330    parameters.uiProcessBundleIdentifier = [[NSBundle mainBundle] bundleIdentifier];
    331331
    332 #if WK_API_ENABLED
    333     for (NSString *scheme in [WKBrowsingContextController customSchemes])
     332#if ENABLE(CUSTOM_PROTOCOLS)
     333    for (const auto& scheme : globalURLSchemesWithCustomProtocolHandlers())
    334334        parameters.urlSchemesRegisteredForCustomProtocols.append(scheme);
    335335#endif
     
    574574{
    575575#if !PLATFORM(IOS)
    576     m_customSchemeRegisteredObserver = [[NSNotificationCenter defaultCenter] addObserverForName:WebKit::SchemeForCustomProtocolRegisteredNotificationName object:nil queue:[NSOperationQueue currentQueue] usingBlock:^(NSNotification *notification) {
    577         NSString *scheme = [notification object];
    578         ASSERT([scheme isKindOfClass:[NSString class]]);
    579         registerSchemeForCustomProtocol(scheme);
    580     }];
    581 
    582     m_customSchemeUnregisteredObserver = [[NSNotificationCenter defaultCenter] addObserverForName:WebKit::SchemeForCustomProtocolUnregisteredNotificationName object:nil queue:[NSOperationQueue currentQueue] usingBlock:^(NSNotification *notification) {
    583         NSString *scheme = [notification object];
    584         ASSERT([scheme isKindOfClass:[NSString class]]);
    585         unregisterSchemeForCustomProtocol(scheme);
    586     }];
    587 
    588576    // Listen for enhanced accessibility changes and propagate them to the WebProcess.
    589577    m_enhancedAccessibilityObserver = [[NSNotificationCenter defaultCenter] addObserverForName:WebKitApplicationDidChangeAccessibilityEnhancedUserInterfaceNotification object:nil queue:[NSOperationQueue currentQueue] usingBlock:^(NSNotification *note) {
     
    618606{
    619607#if !PLATFORM(IOS)
    620     [[NSNotificationCenter defaultCenter] removeObserver:m_customSchemeRegisteredObserver.get()];
    621     [[NSNotificationCenter defaultCenter] removeObserver:m_customSchemeUnregisteredObserver.get()];
    622     [[NSNotificationCenter defaultCenter] removeObserver:m_enhancedAccessibilityObserver.get()];
    623    
     608    [[NSNotificationCenter defaultCenter] removeObserver:m_enhancedAccessibilityObserver.get()];   
    624609    [[NSNotificationCenter defaultCenter] removeObserver:m_automaticTextReplacementNotificationObserver.get()];
    625610    [[NSNotificationCenter defaultCenter] removeObserver:m_automaticSpellingCorrectionNotificationObserver.get()];
Note: See TracChangeset for help on using the changeset viewer.