Changeset 134681 in webkit


Ignore:
Timestamp:
Nov 14, 2012 3:29:37 PM (11 years ago)
Author:
aestes@apple.com
Message:

[WebKit2] Need API in UIProcess to enable loading of custom protocols
https://bugs.webkit.org/show_bug.cgi?id=101674

Reviewed by Brady Eidson.

Source/WebKit2:

Enable clients of WebKit2 to implement NSURLProtocol subclasses to
control the loading of resources with schemes that WebKit2 cannot
handle natively. Since loading happens in a different process, we
accomplish this by registering a global NSURLProtocol in the web
process and proxying NSURLProtocol and NSURLProtocolClient calls to
the client's NSURLProtocol in the UI process.

  • DerivedSources.make: Addded new .messages.in files.
  • Platform/CoreIPC/MessageID.h:
  • Shared/WebProcessCreationParameters.cpp: Added the list of supported schemes.

(WebKit::WebProcessCreationParameters::encode):
(WebKit::WebProcessCreationParameters::decode):

  • Shared/WebProcessCreationParameters.h:
  • UIProcess/API/mac/WKBrowsingContextController.h:
  • UIProcess/API/mac/WKBrowsingContextController.mm:

(+[WKBrowsingContextController registerSchemeForCustomProtocol:]):
Added a class method where a client can register a scheme that it supports.
(+[WKBrowsingContextController unregisterSchemeForCustomProtocol:]):
Added a class method where a client can unregister a scheme that it no longer supports.
(+[WKBrowsingContextController customSchemes]):

  • UIProcess/API/mac/WKBrowsingContextControllerInternal.h:
  • UIProcess/Network/CustomProtocols/CustomProtocolManagerProxy.h: Added.
  • UIProcess/Network/CustomProtocols/CustomProtocolManagerProxy.messages.in: Added.
  • UIProcess/Network/CustomProtocols/mac/CustomProtocolManagerProxyMac.mm: Added.

Implemented an NSURLConnectionDelegate that proxies messages to the
equivalent NSURLProtocolClient in the web process:
(-[WKCustomProtocolLoader initWithCustomProtocolManagerProxy:customProtocolID:request:connection:]):
(-[WKCustomProtocolLoader dealloc]):
(-[WKCustomProtocolLoader connection:didFailWithError:]):
(-[WKCustomProtocolLoader connection:willCacheResponse:]):
(-[WKCustomProtocolLoader connection:didReceiveResponse:]):
(-[WKCustomProtocolLoader connection:didReceiveData:]):
(-[WKCustomProtocolLoader connection:willSendRequest:redirectResponse:]):
(-[WKCustomProtocolLoader connectionDidFinishLoading:]):

Implemented a proxy that recieves -startLoading and -stopLoading
messages from the NSURLProtocol in the web process and starts an
NSURLConnection in the UI process, which will instantiate the client's NSURLProtocol:
(WebKit::CustomProtocolManagerProxy::CustomProtocolManagerProxy):
(WebKit::CustomProtocolManagerProxy::didReceiveMessage):
(WebKit::CustomProtocolManagerProxy::startLoading):
(WebKit::CustomProtocolManagerProxy::stopLoading):

  • UIProcess/WebContext.h: Declared strings that store names of

NSNotifications used for scheme registration in the UI process.

  • UIProcess/WebProcessProxy.cpp:

(WebKit::WebProcessProxy::WebProcessProxy):
(WebKit::WebProcessProxy::didReceiveMessage): Forwarded messages to the
CustomProtocolManagerProxy.

  • UIProcess/WebProcessProxy.h:
  • UIProcess/mac/WebContextMac.mm:

(WebKit::WebContext::platformInitializeWebProcess): Added the currently
registered schemes to the WebProcessCreationParameters and register
NSNotification observers for new scheme registration that forwards to
the context's web processes.

  • WebKit2.xcodeproj/project.pbxproj:
  • WebKit2Prefix.h: Enabled the CUSTOM_PROTOCOLS macro for the Mac.
  • WebProcess/Network/CustomProtocols/CustomProtocolManager.h: Added.
  • WebProcess/Network/CustomProtocols/CustomProtocolManager.messages.in: Added.
  • WebProcess/Network/CustomProtocols/mac/CustomProtocolManagerMac.mm: Added.

(generateCustomProtocolID): Generate a per-WebProcess unique ID.

Implemented a global NSURLProtocol that claims to support all schemes
registered in the UI process. When NSURLConnection calls -startLoading
and -stopLoading, we forward these messages to the client's NSURLProtocol
in the UI process:
(+[WKCustomProtocol canInitWithRequest:]):
(+[WKCustomProtocol canonicalRequestForRequest:]):
(+[WKCustomProtocol requestIsCacheEquivalent:toRequest:]):
(-[WKCustomProtocol initWithRequest:cachedResponse:client:]):
(-[WKCustomProtocol startLoading]):
(-[WKCustomProtocol stopLoading]):

Implemented a manager that receives NSURLConnectionDelegate messages
forwarded from the UI process and passes them to the global NSURLProtocol's NSURLProtocolClient:
(WebKit::CustomProtocolManager::shared):
(WebKit::CustomProtocolManager::registerCustomProtocolClass):
(WebKit::CustomProtocolManager::addCustomProtocol):
(WebKit::CustomProtocolManager::removeCustomProtocol):
(WebKit::CustomProtocolManager::registerScheme):
(WebKit::CustomProtocolManager::unregisterScheme):
(WebKit::CustomProtocolManager::supportsScheme):
(WebKit::CustomProtocolManager::didReceiveMessage):
(WebKit::CustomProtocolManager::didFailWithError):
(WebKit::CustomProtocolManager::didLoadData):
(WebKit::CustomProtocolManager::didReceiveResponse):
(WebKit::CustomProtocolManager::didFinishLoading):
(WebKit::CustomProtocolManager::protocolForID):

  • WebProcess/WebProcess.cpp:

(WebKit::WebProcess::didReceiveMessage): Forwarded messages to the
shared CustomProtocolManager.
(WebKit::WebProcess::registerSchemeForCustomProtocol): Register a
scheme received from the UI process.
(WebKit::WebProcess::unregisterSchemeForCustomProtocol): Unregister a
scheme received from the UI process.

  • WebProcess/WebProcess.h:
  • WebProcess/WebProcess.messages.in: Declared messages for passing

supported schemes from the UI process the web process.

  • WebProcess/mac/WebProcessMac.mm:

(WebKit::WebProcess::platformInitializeWebProcess): Register the
schemes contained in the WebProcessCreationParameters.

Tools:

Add an API test that implements a custom protocol and attempts to load
a resource requiring that protocol in a WKView. The test passes only if
didFinishLoadForFrame: fires.

  • TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
  • TestWebKitAPI/Tests/WebKit2ObjC/CustomProtocolsTest.mm: Added.

(+[TestProtocol canInitWithRequest:]):
(+[TestProtocol canonicalRequestForRequest:]):
(+[TestProtocol requestIsCacheEquivalent:toRequest:]):
(-[TestProtocol startLoading]):
(-[TestProtocol stopLoading]):

  • TestWebKitAPI/Tests/WebKit2ObjC/UserContentTest.mm:
  • TestWebKitAPI/mac/TestBrowsingContextLoadDelegate.h: Copied from Source/WebKit2/UIProcess/API/mac/WKBrowsingContextControllerInternal.h.
  • TestWebKitAPI/mac/TestBrowsingContextLoadDelegate.mm: Copied from Source/WebKit2/UIProcess/API/mac/WKBrowsingContextControllerInternal.h.

(-[TestBrowsingContextLoadDelegate initWithBlockToRunOnLoad:]):
(-[TestBrowsingContextLoadDelegate browsingContextControllerDidFinishLoad:]):

Location:
trunk
Files:
10 added
21 edited
3 copied

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r134676 r134681  
     12012-11-08  Andy Estes  <aestes@apple.com>
     2
     3        [WebKit2] Need API in UIProcess to enable loading of custom protocols
     4        https://bugs.webkit.org/show_bug.cgi?id=101674
     5
     6        Reviewed by Brady Eidson.
     7
     8        Enable clients of WebKit2 to implement NSURLProtocol subclasses to
     9        control the loading of resources with schemes that WebKit2 cannot
     10        handle natively. Since loading happens in a different process, we
     11        accomplish this by registering a global NSURLProtocol in the web
     12        process and proxying NSURLProtocol and NSURLProtocolClient calls to
     13        the client's NSURLProtocol in the UI process.
     14
     15        * DerivedSources.make: Addded new .messages.in files.
     16        * Platform/CoreIPC/MessageID.h:
     17        * Shared/WebProcessCreationParameters.cpp: Added the list of supported schemes.
     18        (WebKit::WebProcessCreationParameters::encode):
     19        (WebKit::WebProcessCreationParameters::decode):
     20        * Shared/WebProcessCreationParameters.h:
     21        * UIProcess/API/mac/WKBrowsingContextController.h:
     22        * UIProcess/API/mac/WKBrowsingContextController.mm:
     23        (+[WKBrowsingContextController registerSchemeForCustomProtocol:]):
     24        Added a class method where a client can register a scheme that it supports.
     25        (+[WKBrowsingContextController unregisterSchemeForCustomProtocol:]):
     26        Added a class method where a client can unregister a scheme that it no longer supports.
     27        (+[WKBrowsingContextController customSchemes]):
     28        * UIProcess/API/mac/WKBrowsingContextControllerInternal.h:
     29        * UIProcess/Network/CustomProtocols/CustomProtocolManagerProxy.h: Added.
     30        * UIProcess/Network/CustomProtocols/CustomProtocolManagerProxy.messages.in: Added.
     31        * UIProcess/Network/CustomProtocols/mac/CustomProtocolManagerProxyMac.mm: Added.
     32
     33        Implemented an NSURLConnectionDelegate that proxies messages to the
     34        equivalent NSURLProtocolClient in the web process:
     35        (-[WKCustomProtocolLoader initWithCustomProtocolManagerProxy:customProtocolID:request:connection:]):
     36        (-[WKCustomProtocolLoader dealloc]):
     37        (-[WKCustomProtocolLoader connection:didFailWithError:]):
     38        (-[WKCustomProtocolLoader connection:willCacheResponse:]):
     39        (-[WKCustomProtocolLoader connection:didReceiveResponse:]):
     40        (-[WKCustomProtocolLoader connection:didReceiveData:]):
     41        (-[WKCustomProtocolLoader connection:willSendRequest:redirectResponse:]):
     42        (-[WKCustomProtocolLoader connectionDidFinishLoading:]):
     43
     44        Implemented a proxy that recieves -startLoading and -stopLoading
     45        messages from the NSURLProtocol in the web process and starts an
     46        NSURLConnection in the UI process, which will instantiate the client's NSURLProtocol:
     47        (WebKit::CustomProtocolManagerProxy::CustomProtocolManagerProxy):
     48        (WebKit::CustomProtocolManagerProxy::didReceiveMessage):
     49        (WebKit::CustomProtocolManagerProxy::startLoading):
     50        (WebKit::CustomProtocolManagerProxy::stopLoading):
     51
     52        * UIProcess/WebContext.h: Declared strings that store names of
     53        NSNotifications used for scheme registration in the UI process.
     54        * UIProcess/WebProcessProxy.cpp:
     55        (WebKit::WebProcessProxy::WebProcessProxy):
     56        (WebKit::WebProcessProxy::didReceiveMessage): Forwarded messages to the
     57        CustomProtocolManagerProxy.
     58        * UIProcess/WebProcessProxy.h:
     59        * UIProcess/mac/WebContextMac.mm:
     60        (WebKit::WebContext::platformInitializeWebProcess): Added the currently
     61        registered schemes to the WebProcessCreationParameters and register
     62        NSNotification observers for new scheme registration that forwards to
     63        the context's web processes.
     64        * WebKit2.xcodeproj/project.pbxproj:
     65        * WebKit2Prefix.h: Enabled the CUSTOM_PROTOCOLS macro for the Mac.
     66        * WebProcess/Network/CustomProtocols/CustomProtocolManager.h: Added.
     67        * WebProcess/Network/CustomProtocols/CustomProtocolManager.messages.in: Added.
     68        * WebProcess/Network/CustomProtocols/mac/CustomProtocolManagerMac.mm: Added.
     69        (generateCustomProtocolID): Generate a per-WebProcess unique ID.
     70
     71        Implemented a global NSURLProtocol that claims to support all schemes
     72        registered in the UI process. When NSURLConnection calls -startLoading
     73        and -stopLoading, we forward these messages to the client's NSURLProtocol
     74        in the UI process:
     75        (+[WKCustomProtocol canInitWithRequest:]):
     76        (+[WKCustomProtocol canonicalRequestForRequest:]):
     77        (+[WKCustomProtocol requestIsCacheEquivalent:toRequest:]):
     78        (-[WKCustomProtocol initWithRequest:cachedResponse:client:]):
     79        (-[WKCustomProtocol startLoading]):
     80        (-[WKCustomProtocol stopLoading]):
     81
     82        Implemented a manager that receives NSURLConnectionDelegate messages
     83        forwarded from the UI process and passes them to the global NSURLProtocol's NSURLProtocolClient:
     84        (WebKit::CustomProtocolManager::shared):
     85        (WebKit::CustomProtocolManager::registerCustomProtocolClass):
     86        (WebKit::CustomProtocolManager::addCustomProtocol):
     87        (WebKit::CustomProtocolManager::removeCustomProtocol):
     88        (WebKit::CustomProtocolManager::registerScheme):
     89        (WebKit::CustomProtocolManager::unregisterScheme):
     90        (WebKit::CustomProtocolManager::supportsScheme):
     91        (WebKit::CustomProtocolManager::didReceiveMessage):
     92        (WebKit::CustomProtocolManager::didFailWithError):
     93        (WebKit::CustomProtocolManager::didLoadData):
     94        (WebKit::CustomProtocolManager::didReceiveResponse):
     95        (WebKit::CustomProtocolManager::didFinishLoading):
     96        (WebKit::CustomProtocolManager::protocolForID):
     97
     98        * WebProcess/WebProcess.cpp:
     99        (WebKit::WebProcess::didReceiveMessage): Forwarded messages to the
     100        shared CustomProtocolManager.
     101        (WebKit::WebProcess::registerSchemeForCustomProtocol): Register a
     102        scheme received from the UI process.
     103        (WebKit::WebProcess::unregisterSchemeForCustomProtocol): Unregister a
     104        scheme received from the UI process.
     105        * WebProcess/WebProcess.h:
     106        * WebProcess/WebProcess.messages.in: Declared messages for passing
     107        supported schemes from the UI process the web process.
     108        * WebProcess/mac/WebProcessMac.mm:
     109        (WebKit::WebProcess::platformInitializeWebProcess): Register the
     110        schemes contained in the WebProcessCreationParameters.
     111
    11122012-11-14  Helder Correia  <helder.correia@nokia.com>
    2113
  • trunk/Source/WebKit2/DerivedSources.make

    r134324 r134681  
    3838    $(WebKit2)/WebProcess/MediaCache \
    3939    $(WebKit2)/WebProcess/Network \
     40    $(WebKit2)/WebProcess/Network/CustomProtocols \
    4041    $(WebKit2)/WebProcess/Notifications \
    4142    $(WebKit2)/WebProcess/Plugins \
     
    4748    $(WebKit2)/UIProcess/Downloads \
    4849    $(WebKit2)/UIProcess/Network \
     50    $(WebKit2)/UIProcess/Network/CustomProtocols \
    4951    $(WebKit2)/UIProcess/Notifications \
    5052    $(WebKit2)/UIProcess/Plugins \
     
    5557MESSAGE_RECEIVERS = \
    5658    AuthenticationManager \
     59    CustomProtocolManager \
     60    CustomProtocolManagerProxy \
    5761    DrawingArea \
    5862    DrawingAreaProxy \
  • trunk/Source/WebKit2/Platform/CoreIPC/MessageID.h

    r134324 r134681  
    127127    // Messages sent by the shared worker process to the UI process.
    128128    MessageClassSharedWorkerProcessProxy,
     129   
     130#if ENABLE(CUSTOM_PROTOCOLS)
     131    // Messages sent by the UI process to a web process (soon the network process).
     132    MessageClassCustomProtocolManager,
     133
     134    // Messages sent by a web process (soon the network process) to the UI process.
     135    MessageClassCustomProtocolManagerProxy,
     136#endif
    129137};
    130138
  • trunk/Source/WebKit2/Shared/WebProcessCreationParameters.cpp

    r133410 r134681  
    7474    encoder << urlSchemesRegisteredAsDisplayIsolated;
    7575    encoder << urlSchemesRegisteredAsCORSEnabled;
     76#if ENABLE(CUSTOM_PROTOCOLS)
     77    encoder << urlSchemesRegisteredForCustomProtocols;
     78#endif
    7679    encoder.encodeEnum(cacheModel);
    7780    encoder << shouldTrackVisitedLinks;
     
    159162    if (!decoder->decode(parameters.urlSchemesRegisteredAsCORSEnabled))
    160163        return false;
     164#if ENABLE(CUSTOM_PROTOCOLS)
     165    if (!decoder->decode(parameters.urlSchemesRegisteredForCustomProtocols))
     166        return false;
     167#endif
    161168    if (!decoder->decodeEnum(parameters.cacheModel))
    162169        return false;
  • trunk/Source/WebKit2/Shared/WebProcessCreationParameters.h

    r133410 r134681  
    7373    Vector<String> urlSchemesRegisteredAsDisplayIsolated;
    7474    Vector<String> urlSchemesRegisteredAsCORSEnabled;
     75#if ENABLE(CUSTOM_PROTOCOLS)
     76    Vector<String> urlSchemesRegisteredForCustomProtocols;
     77#endif
    7578
    7679    CacheModel cacheModel;
  • trunk/Source/WebKit2/UIProcess/API/mac/WKBrowsingContextController.h

    r124121 r134681  
    4242
    4343#pragma mark Loading
     44
     45+ (void)registerSchemeForCustomProtocol:(NSString *)scheme;
     46+ (void)unregisterSchemeForCustomProtocol:(NSString *)scheme;
    4447
    4548/* Load a request. This is only valid for requests of non-file: URLs. Passing a
  • trunk/Source/WebKit2/UIProcess/API/mac/WKBrowsingContextController.mm

    r124121 r134681  
    3737#import "WKURLRequest.h"
    3838#import "WKURLRequestNS.h"
     39#import "WebContext.h"
    3940#import <wtf/RetainPtr.h>
    4041
     
    103104
    104105#pragma mark Loading
     106
     107+ (void)registerSchemeForCustomProtocol:(NSString *)scheme
     108{
     109    NSString *lowercaseScheme = [scheme lowercaseString];
     110    [[WKBrowsingContextController customSchemes] addObject:lowercaseScheme];
     111    [[NSNotificationCenter defaultCenter] postNotificationName:WebKit::SchemeForCustomProtocolRegisteredNotificationName object:lowercaseScheme];
     112}
     113
     114+ (void)unregisterSchemeForCustomProtocol:(NSString *)scheme
     115{
     116    NSString *lowercaseScheme = [scheme lowercaseString];
     117    [[WKBrowsingContextController customSchemes] removeObject:lowercaseScheme];
     118    [[NSNotificationCenter defaultCenter] postNotificationName:WebKit::SchemeForCustomProtocolUnregisteredNotificationName object:lowercaseScheme];
     119}
    105120
    106121- (void)loadRequest:(NSURLRequest *)request
     
    404419}
    405420
    406 @end
     421+ (NSMutableSet *)customSchemes
     422{
     423    static NSMutableSet *customSchemes = [[NSMutableSet alloc] init];
     424    return customSchemes;
     425}
     426 
     427@end
  • trunk/Source/WebKit2/UIProcess/API/mac/WKBrowsingContextControllerInternal.h

    r102633 r134681  
    3030/* This should only be called from associate view. */
    3131- (id)_initWithPageRef:(WKPageRef)pageRef;
     32+ (NSMutableSet *)customSchemes;
    3233
    3334@end
  • trunk/Source/WebKit2/UIProcess/Network/CustomProtocols/CustomProtocolManagerProxy.h

    r134679 r134681  
    11/*
    2  * Copyright (C) 2011 Apple Inc. All rights reserved.
     2 * Copyright (C) 2012 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2424 */
    2525
    26 #import <WebKit2/WKBrowsingContextController.h>
     26#ifndef CustomProtocolManagerProxy_h
     27#define CustomProtocolManagerProxy_h
    2728
    28 @interface WKBrowsingContextController (Internal)
     29#if ENABLE(CUSTOM_PROTOCOLS)
    2930
    30 /* This should only be called from associate view. */
    31 - (id)_initWithPageRef:(WKPageRef)pageRef;
     31#include "MessageID.h"
    3232
    33 @end
     33#if PLATFORM(MAC)
     34#include <wtf/HashMap.h>
     35#include <wtf/RetainPtr.h>
     36OBJC_CLASS WKCustomProtocolLoader;
     37#endif
     38
     39namespace CoreIPC {
     40class Connection;
     41class MessageDecoder;
     42} // namespace CoreIPC
     43
     44namespace WebCore {
     45class ResourceRequest;
     46} // namespace WebCore
     47
     48namespace WebKit {
     49
     50class WebProcessProxy;
     51
     52class CustomProtocolManagerProxy {
     53public:
     54    explicit CustomProtocolManagerProxy(WebProcessProxy*);
     55
     56    void didReceiveMessage(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::MessageDecoder&);
     57    void startLoading(uint64_t customProtocolID, const WebCore::ResourceRequest&);
     58    void stopLoading(uint64_t customProtocolID);
     59
     60private:
     61    void didReceiveCustomProtocolManagerProxyMessage(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::MessageDecoder&);
     62
     63    WebProcessProxy* m_webProcessProxy;
     64
     65#if PLATFORM(MAC)
     66    typedef HashMap<uint64_t, RetainPtr<WKCustomProtocolLoader> > LoaderMap;
     67    LoaderMap m_loaderMap;
     68#endif
     69};
     70
     71} // namespace WebKit
     72
     73#endif // ENABLE(CUSTOM_PROTOCOLS)
     74
     75#endif // CustomProtocolManagerProxy_h
  • trunk/Source/WebKit2/UIProcess/WebContext.h

    r133828 r134681  
    7575typedef GenericCallback<WKDictionaryRef> DictionaryCallback;
    7676
     77#if PLATFORM(MAC)
     78extern NSString *SchemeForCustomProtocolRegisteredNotificationName;
     79extern NSString *SchemeForCustomProtocolUnregisteredNotificationName;
     80#endif
     81
    7782class WebContext : public APIObject, private CoreIPC::MessageReceiver {
    7883public:
     
    382387#if PLATFORM(MAC)
    383388    RetainPtr<CFTypeRef> m_enhancedAccessibilityObserver;
     389    RetainPtr<CFTypeRef> m_customSchemeRegisteredObserver;
     390    RetainPtr<CFTypeRef> m_customSchemeUnregisteredObserver;
    384391#endif
    385392
  • trunk/Source/WebKit2/UIProcess/WebProcessProxy.cpp

    r134324 r134681  
    9494    , m_context(context)
    9595    , m_mayHaveUniversalFileReadSandboxExtension(false)
     96#if ENABLE(CUSTOM_PROTOCOLS)
     97    , m_customProtocolManagerProxy(this)
     98#endif
    9699{
    97100    connect();
     
    437440    }
    438441
     442#if ENABLE(CUSTOM_PROTOCOLS)
     443    if (messageID.is<CoreIPC::MessageClassCustomProtocolManagerProxy>()) {
     444        m_customProtocolManagerProxy.didReceiveMessage(connection, messageID, decoder);
     445        return;
     446    }
     447#endif
     448
    439449    uint64_t pageID = decoder.destinationID();
    440450    if (!pageID)
  • trunk/Source/WebKit2/UIProcess/WebProcessProxy.h

    r134324 r134681  
    4141#include <wtf/RefCounted.h>
    4242
     43#if ENABLE(CUSTOM_PROTOCOLS)
     44#include "CustomProtocolManagerProxy.h"
     45#endif
     46
    4347namespace WebCore {
    4448    class KURL;
     
    220224    WebFrameProxyMap m_frameMap;
    221225    WebBackForwardListItemMap m_backForwardListItemMap;
     226   
     227#if ENABLE(CUSTOM_PROTOCOLS)
     228    CustomProtocolManagerProxy m_customProtocolManagerProxy;
     229#endif
    222230};
    223231
  • trunk/Source/WebKit2/UIProcess/mac/WebContextMac.mm

    r133699 r134681  
    3030#import "PluginProcessManager.h"
    3131#import "SharedWorkerProcessManager.h"
     32#import "WKBrowsingContextControllerInternal.h"
    3233#import "WebKitSystemInterface.h"
    3334#import "WebProcessCreationParameters.h"
     
    5758namespace WebKit {
    5859
     60NSString *SchemeForCustomProtocolRegisteredNotificationName = @"WebKitSchemeForCustomProtocolRegisteredNotification";
     61NSString *SchemeForCustomProtocolUnregisteredNotificationName = @"WebKitSchemeForCustomProtocolUnregisteredNotification";
     62
    5963bool WebContext::s_applicationIsOccluded = false;
    6064
     
    124128
    125129    parameters.uiProcessBundleIdentifier = String([[NSBundle mainBundle] bundleIdentifier]);
     130   
     131    NSArray *schemes = [[WKBrowsingContextController customSchemes] allObjects];
     132    for (size_t i = 0; i < [schemes count]; ++i)
     133        parameters.urlSchemesRegisteredForCustomProtocols.append([schemes objectAtIndex:i]);
     134   
     135    m_customSchemeRegisteredObserver = [[NSNotificationCenter defaultCenter] addObserverForName:WebKit::SchemeForCustomProtocolRegisteredNotificationName object:nil queue:[NSOperationQueue currentQueue] usingBlock:^(NSNotification *notification) {
     136        NSString *scheme = [notification object];
     137        ASSERT([scheme isKindOfClass:[NSString class]]);
     138        sendToAllProcesses(Messages::WebProcess::RegisterSchemeForCustomProtocol(scheme));
     139    }];
     140   
     141    m_customSchemeUnregisteredObserver = [[NSNotificationCenter defaultCenter] addObserverForName:WebKit::SchemeForCustomProtocolUnregisteredNotificationName object:nil queue:[NSOperationQueue currentQueue] usingBlock:^(NSNotification *notification) {
     142        NSString *scheme = [notification object];
     143        ASSERT([scheme isKindOfClass:[NSString class]]);
     144        sendToAllProcesses(Messages::WebProcess::UnregisterSchemeForCustomProtocol(scheme));
     145    }];
    126146   
    127147    // Listen for enhanced accessibility changes and propagate them to the WebProcess.
  • trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj

    r134640 r134681  
    281281                296BD85D15019BC30071F424 /* StringUtilities.h in Headers */ = {isa = PBXBuildFile; fileRef = 296BD85B15019BC30071F424 /* StringUtilities.h */; };
    282282                296BD85E15019BC30071F424 /* StringUtilities.mm in Sources */ = {isa = PBXBuildFile; fileRef = 296BD85C15019BC30071F424 /* StringUtilities.mm */; };
     283                2984F57C164B915F004BC0C6 /* CustomProtocolManagerProxyMessageReceiver.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2984F57A164B915F004BC0C6 /* CustomProtocolManagerProxyMessageReceiver.cpp */; };
     284                2984F57D164B915F004BC0C6 /* CustomProtocolManagerProxyMessages.h in Headers */ = {isa = PBXBuildFile; fileRef = 2984F57B164B915F004BC0C6 /* CustomProtocolManagerProxyMessages.h */; };
     285                2984F581164B9BBD004BC0C6 /* CustomProtocolManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 2984F580164B9BBD004BC0C6 /* CustomProtocolManager.h */; };
     286                2984F583164B9BD9004BC0C6 /* CustomProtocolManagerMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2984F582164B9BD9004BC0C6 /* CustomProtocolManagerMac.mm */; };
     287                2984F588164BA095004BC0C6 /* CustomProtocolManagerMessageReceiver.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2984F586164BA095004BC0C6 /* CustomProtocolManagerMessageReceiver.cpp */; };
     288                2984F589164BA095004BC0C6 /* CustomProtocolManagerMessages.h in Headers */ = {isa = PBXBuildFile; fileRef = 2984F587164BA095004BC0C6 /* CustomProtocolManagerMessages.h */; };
     289                29AD3093164B4C5D0072DEA9 /* CustomProtocolManagerProxy.h in Headers */ = {isa = PBXBuildFile; fileRef = 29AD3092164B4C5D0072DEA9 /* CustomProtocolManagerProxy.h */; };
     290                29AD3096164B4C930072DEA9 /* CustomProtocolManagerProxyMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 29AD3095164B4C930072DEA9 /* CustomProtocolManagerProxyMac.mm */; };
    283291                29CD55AA128E294F00133C85 /* WKAccessibilityWebPageObject.h in Headers */ = {isa = PBXBuildFile; fileRef = 29CD55A8128E294F00133C85 /* WKAccessibilityWebPageObject.h */; };
    284292                29CD55AB128E294F00133C85 /* WKAccessibilityWebPageObject.mm in Sources */ = {isa = PBXBuildFile; fileRef = 29CD55A9128E294F00133C85 /* WKAccessibilityWebPageObject.mm */; };
     
    14821490                296BD85B15019BC30071F424 /* StringUtilities.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StringUtilities.h; sourceTree = "<group>"; };
    14831491                296BD85C15019BC30071F424 /* StringUtilities.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = StringUtilities.mm; sourceTree = "<group>"; };
     1492                2984F57A164B915F004BC0C6 /* CustomProtocolManagerProxyMessageReceiver.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CustomProtocolManagerProxyMessageReceiver.cpp; sourceTree = "<group>"; };
     1493                2984F57B164B915F004BC0C6 /* CustomProtocolManagerProxyMessages.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CustomProtocolManagerProxyMessages.h; sourceTree = "<group>"; };
     1494                2984F580164B9BBD004BC0C6 /* CustomProtocolManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CustomProtocolManager.h; path = Network/CustomProtocols/CustomProtocolManager.h; sourceTree = "<group>"; };
     1495                2984F582164B9BD9004BC0C6 /* CustomProtocolManagerMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = CustomProtocolManagerMac.mm; path = Network/CustomProtocols/mac/CustomProtocolManagerMac.mm; sourceTree = "<group>"; };
     1496                2984F584164B9ED9004BC0C6 /* CustomProtocolManager.messages.in */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = CustomProtocolManager.messages.in; path = Network/CustomProtocols/CustomProtocolManager.messages.in; sourceTree = "<group>"; };
     1497                2984F586164BA095004BC0C6 /* CustomProtocolManagerMessageReceiver.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CustomProtocolManagerMessageReceiver.cpp; path = CustomProtocolManagerMessageReceiver.cpp; sourceTree = "<group>"; };
     1498                2984F587164BA095004BC0C6 /* CustomProtocolManagerMessages.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CustomProtocolManagerMessages.h; path = CustomProtocolManagerMessages.h; sourceTree = "<group>"; };
     1499                29AD3092164B4C5D0072DEA9 /* CustomProtocolManagerProxy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CustomProtocolManagerProxy.h; path = CustomProtocols/CustomProtocolManagerProxy.h; sourceTree = "<group>"; };
     1500                29AD3095164B4C930072DEA9 /* CustomProtocolManagerProxyMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = CustomProtocolManagerProxyMac.mm; path = CustomProtocols/mac/CustomProtocolManagerProxyMac.mm; sourceTree = "<group>"; };
     1501                29AD3097164B4E210072DEA9 /* CustomProtocolManagerProxy.messages.in */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = CustomProtocolManagerProxy.messages.in; path = CustomProtocols/CustomProtocolManagerProxy.messages.in; sourceTree = "<group>"; };
    14841502                29CD55A8128E294F00133C85 /* WKAccessibilityWebPageObject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKAccessibilityWebPageObject.h; sourceTree = "<group>"; };
    14851503                29CD55A9128E294F00133C85 /* WKAccessibilityWebPageObject.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WKAccessibilityWebPageObject.mm; sourceTree = "<group>"; };
     
    29682986                        sourceTree = "<group>";
    29692987                };
     2988                2984F57E164B9B56004BC0C6 /* CustomProtocols */ = {
     2989                        isa = PBXGroup;
     2990                        children = (
     2991                                2984F57F164B9B5D004BC0C6 /* mac */,
     2992                                2984F580164B9BBD004BC0C6 /* CustomProtocolManager.h */,
     2993                                2984F584164B9ED9004BC0C6 /* CustomProtocolManager.messages.in */,
     2994                        );
     2995                        name = CustomProtocols;
     2996                        sourceTree = "<group>";
     2997                };
     2998                2984F57F164B9B5D004BC0C6 /* mac */ = {
     2999                        isa = PBXGroup;
     3000                        children = (
     3001                                2984F582164B9BD9004BC0C6 /* CustomProtocolManagerMac.mm */,
     3002                        );
     3003                        name = mac;
     3004                        sourceTree = "<group>";
     3005                };
     3006                29AD3091164B4C100072DEA9 /* CustomProtocols */ = {
     3007                        isa = PBXGroup;
     3008                        children = (
     3009                                29AD3094164B4C830072DEA9 /* mac */,
     3010                                29AD3092164B4C5D0072DEA9 /* CustomProtocolManagerProxy.h */,
     3011                                29AD3097164B4E210072DEA9 /* CustomProtocolManagerProxy.messages.in */,
     3012                        );
     3013                        name = CustomProtocols;
     3014                        sourceTree = "<group>";
     3015                };
     3016                29AD3094164B4C830072DEA9 /* mac */ = {
     3017                        isa = PBXGroup;
     3018                        children = (
     3019                                29AD3095164B4C930072DEA9 /* CustomProtocolManagerProxyMac.mm */,
     3020                        );
     3021                        name = mac;
     3022                        sourceTree = "<group>";
     3023                };
    29703024                31099974146C8AA80029DEB9 /* Notifications (User) */ = {
    29713025                        isa = PBXGroup;
     
    30523106                        isa = PBXGroup;
    30533107                        children = (
     3108                                2984F57E164B9B56004BC0C6 /* CustomProtocols */,
    30543109                                5105B0D4162F7A7A00E27709 /* NetworkProcessConnection.cpp */,
    30553110                                5105B0D5162F7A7A00E27709 /* NetworkProcessConnection.h */,
     
    31003155                        isa = PBXGroup;
    31013156                        children = (
     3157                                29AD3091164B4C100072DEA9 /* CustomProtocols */,
    31023158                                516319931628980E00E22F00 /* mac */,
    31033159                                5105B0DB162F7E9D00E27709 /* NetworkProcessManager.cpp */,
     
    41764232                                512F58A012A883AD00629530 /* AuthenticationManagerMessageReceiver.cpp */,
    41774233                                512F58A112A883AD00629530 /* AuthenticationManagerMessages.h */,
     4234                                2984F586164BA095004BC0C6 /* CustomProtocolManagerMessageReceiver.cpp */,
     4235                                2984F587164BA095004BC0C6 /* CustomProtocolManagerMessages.h */,
     4236                                2984F57A164B915F004BC0C6 /* CustomProtocolManagerProxyMessageReceiver.cpp */,
     4237                                2984F57B164B915F004BC0C6 /* CustomProtocolManagerProxyMessages.h */,
    41784238                                E1967E35150AB5D500C73169 /* com.apple.WebKit.PluginProcess.sb */,
    41794239                                E1967E37150AB5E200C73169 /* com.apple.WebProcess.sb */,
     
    49164976                                51CBBA10165219B6005BE8FD /* NetworkResourceLoadParameters.h in Headers */,
    49174977                                510AFFBA16542048001BA05E /* WebResourceLoader.h in Headers */,
     4978                                29AD3093164B4C5D0072DEA9 /* CustomProtocolManagerProxy.h in Headers */,
     4979                                2984F57D164B915F004BC0C6 /* CustomProtocolManagerProxyMessages.h in Headers */,
     4980                                2984F581164B9BBD004BC0C6 /* CustomProtocolManager.h in Headers */,
     4981                                2984F589164BA095004BC0C6 /* CustomProtocolManagerMessages.h in Headers */,
    49184982                        );
    49194983                        runOnlyForDeploymentPostprocessing = 0;
     
    58635927                                51CBBA0F165219B6005BE8FD /* NetworkResourceLoadParameters.cpp in Sources */,
    58645928                                510AFFB916542048001BA05E /* WebResourceLoader.cpp in Sources */,
     5929                                29AD3096164B4C930072DEA9 /* CustomProtocolManagerProxyMac.mm in Sources */,
     5930                                2984F57C164B915F004BC0C6 /* CustomProtocolManagerProxyMessageReceiver.cpp in Sources */,
     5931                                2984F583164B9BD9004BC0C6 /* CustomProtocolManagerMac.mm in Sources */,
     5932                                2984F588164BA095004BC0C6 /* CustomProtocolManagerMessageReceiver.cpp in Sources */,
    58655933                        );
    58665934                        runOnlyForDeploymentPostprocessing = 0;
  • trunk/Source/WebKit2/WebKit2Prefix.h

    r132974 r134681  
    4545#define ENABLE_MEMORY_SAMPLER 1
    4646
     47#define ENABLE_CUSTOM_PROTOCOLS 1
     48
    4749#include <CoreFoundation/CoreFoundation.h>
    4850#include <CoreGraphics/CoreGraphics.h>
  • trunk/Source/WebKit2/WebProcess/WebProcess.cpp

    r133410 r134681  
    9999#endif
    100100
     101#if ENABLE(CUSTOM_PROTOCOLS)
     102#include "CustomProtocolManager.h"
     103#endif
     104
    101105using namespace JSC;
    102106using namespace WebCore;
     
    708712    }
    709713   
     714#if ENABLE(CUSTOM_PROTOCOLS)
     715    if (messageID.is<CoreIPC::MessageClassCustomProtocolManager>()) {
     716        CustomProtocolManager::shared().didReceiveMessage(connection, messageID, decoder);
     717        return;
     718    }
     719#endif
     720
    710721    if (messageID.is<CoreIPC::MessageClassWebPageGroupProxy>()) {
    711722        uint64_t pageGroupID = decoder.destinationID();
     
    11401151#endif // ENABLE(PLUGIN_PROCESS)
    11411152
     1153#if ENABLE(CUSTOM_PROTOCOLS)
     1154void WebProcess::registerSchemeForCustomProtocol(const WTF::String& scheme)
     1155{
     1156    CustomProtocolManager::shared().registerScheme(scheme);
     1157}
     1158
     1159void WebProcess::unregisterSchemeForCustomProtocol(const WTF::String& scheme)
     1160{
     1161    CustomProtocolManager::shared().unregisterScheme(scheme);
     1162}
     1163#endif
     1164
    11421165} // namespace WebKit
  • trunk/Source/WebKit2/WebProcess/WebProcess.h

    r133045 r134681  
    305305#endif
    306306
     307#if ENABLE(CUSTOM_PROTOCOLS)
     308    void registerSchemeForCustomProtocol(const WTF::String&);
     309    void unregisterSchemeForCustomProtocol(const WTF::String&);
     310#endif
     311
    307312    RefPtr<WebConnectionToUIProcess> m_connection;
    308313    CoreIPC::MessageReceiverMap m_messageReceiverMap;
  • trunk/Source/WebKit2/WebProcess/WebProcess.messages.in

    r133699 r134681  
    102102    SetApplicationIsOccluded(bool flag);
    103103#endif
     104
     105#if ENABLE(CUSTOM_PROTOCOLS)
     106    RegisterSchemeForCustomProtocol(WTF::String name)
     107    UnregisterSchemeForCustomProtocol(WTF::String name)
     108#endif
    104109}
  • trunk/Source/WebKit2/WebProcess/mac/WebProcessMac.mm

    r132294 r134681  
    2727#import "WebProcess.h"
    2828
     29#import "CustomProtocolManager.h"
    2930#import "SandboxExtension.h"
    3031#import "WKFullKeyboardAccessWatcher.h"
     
    292293    Method methodToPatch = class_getInstanceMethod([NSApplication class], @selector(accessibilityFocusedUIElement));
    293294    method_setImplementation(methodToPatch, (IMP)NSApplicationAccessibilityFocusedUIElement);
     295   
     296    for (size_t i = 0; i < parameters.urlSchemesRegisteredForCustomProtocols.size(); ++i)
     297        CustomProtocolManager::shared().registerScheme(parameters.urlSchemesRegisteredForCustomProtocols[i]);
     298   
     299    CustomProtocolManager::registerCustomProtocolClass();
    294300}
    295301
  • trunk/Tools/ChangeLog

    r134675 r134681  
     12012-11-08  Andy Estes  <aestes@apple.com>
     2
     3        [WebKit2] Need API in UIProcess to enable loading of custom protocols
     4        https://bugs.webkit.org/show_bug.cgi?id=101674
     5
     6        Reviewed by Brady Eidson.
     7
     8        Add an API test that implements a custom protocol and attempts to load
     9        a resource requiring that protocol in a WKView. The test passes only if
     10        didFinishLoadForFrame: fires.
     11
     12        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
     13        * TestWebKitAPI/Tests/WebKit2ObjC/CustomProtocolsTest.mm: Added.
     14        (+[TestProtocol canInitWithRequest:]):
     15        (+[TestProtocol canonicalRequestForRequest:]):
     16        (+[TestProtocol requestIsCacheEquivalent:toRequest:]):
     17        (-[TestProtocol startLoading]):
     18        (-[TestProtocol stopLoading]):
     19        * TestWebKitAPI/Tests/WebKit2ObjC/UserContentTest.mm:
     20        * TestWebKitAPI/mac/TestBrowsingContextLoadDelegate.h: Copied from Source/WebKit2/UIProcess/API/mac/WKBrowsingContextControllerInternal.h.
     21        * TestWebKitAPI/mac/TestBrowsingContextLoadDelegate.mm: Copied from Source/WebKit2/UIProcess/API/mac/WKBrowsingContextControllerInternal.h.
     22        (-[TestBrowsingContextLoadDelegate initWithBlockToRunOnLoad:]):
     23        (-[TestBrowsingContextLoadDelegate browsingContextControllerDidFinishLoad:]):
     24
    1252012-11-14  Ojan Vafai  <ojan@chromium.org>
    226
  • trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj

    r133103 r134681  
    3333                26F1B44515CA434F00D1E4BF /* StringImpl.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 26F1B44315CA434F00D1E4BF /* StringImpl.cpp */; };
    3434                2943BE86161DFEB800999E3D /* UserContentTest.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2943BE84161DFEB800999E3D /* UserContentTest.mm */; };
     35                29AB8AA1164C735800D49BEC /* CustomProtocolsTest.mm in Sources */ = {isa = PBXBuildFile; fileRef = 29AB8A9F164C735800D49BEC /* CustomProtocolsTest.mm */; };
     36                29AB8AA4164C7A9300D49BEC /* TestBrowsingContextLoadDelegate.mm in Sources */ = {isa = PBXBuildFile; fileRef = 29AB8AA2164C7A9300D49BEC /* TestBrowsingContextLoadDelegate.mm */; };
    3537                333B9CE21277F23100FEFCE3 /* PreventEmptyUserAgent.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 333B9CE11277F23100FEFCE3 /* PreventEmptyUserAgent.cpp */; };
    3638                33BE5AF5137B5A6C00705813 /* MouseMoveAfterCrash.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 33BE5AF4137B5A6C00705813 /* MouseMoveAfterCrash.cpp */; };
     
    275277                26F1B44315CA434F00D1E4BF /* StringImpl.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = StringImpl.cpp; path = WTF/StringImpl.cpp; sourceTree = "<group>"; };
    276278                2943BE84161DFEB800999E3D /* UserContentTest.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = UserContentTest.mm; path = WebKit2ObjC/UserContentTest.mm; sourceTree = "<group>"; };
     279                29AB8A9F164C735800D49BEC /* CustomProtocolsTest.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = CustomProtocolsTest.mm; path = WebKit2ObjC/CustomProtocolsTest.mm; sourceTree = "<group>"; };
     280                29AB8AA2164C7A9300D49BEC /* TestBrowsingContextLoadDelegate.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = TestBrowsingContextLoadDelegate.mm; sourceTree = "<group>"; };
     281                29AB8AA3164C7A9300D49BEC /* TestBrowsingContextLoadDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TestBrowsingContextLoadDelegate.h; sourceTree = "<group>"; };
    277282                333B9CE11277F23100FEFCE3 /* PreventEmptyUserAgent.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PreventEmptyUserAgent.cpp; sourceTree = "<group>"; };
    278283                33BE5AF4137B5A6C00705813 /* MouseMoveAfterCrash.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MouseMoveAfterCrash.cpp; sourceTree = "<group>"; };
     
    542547                        isa = PBXGroup;
    543548                        children = (
     549                                29AB8A9F164C735800D49BEC /* CustomProtocolsTest.mm */,
    544550                                2943BE84161DFEB800999E3D /* UserContentTest.mm */,
    545551                                BC3C4C7D14587AA60025FB62 /* WKBrowsingContextGroupTest.mm */,
     
    712718                                C081224313FC19EC00DC39AE /* SyntheticBackingScaleFactorWindow.h */,
    713719                                C081224413FC19EC00DC39AE /* SyntheticBackingScaleFactorWindow.m */,
     720                                29AB8AA3164C7A9300D49BEC /* TestBrowsingContextLoadDelegate.h */,
     721                                29AB8AA2164C7A9300D49BEC /* TestBrowsingContextLoadDelegate.mm */,
    714722                                C08587BE13FE956C001EF4E5 /* WebKitAgnosticTest.h */,
    715723                                C08587BD13FE956C001EF4E5 /* WebKitAgnosticTest.mm */,
     
    10171025                                378E64731632646D00B6C676 /* InjectedBundleFrameHitTest.cpp in Sources */,
    10181026                                FE217ECD1640A54A0052988B /* VMInspector.cpp in Sources */,
     1027                                29AB8AA1164C735800D49BEC /* CustomProtocolsTest.mm in Sources */,
     1028                                29AB8AA4164C7A9300D49BEC /* TestBrowsingContextLoadDelegate.mm in Sources */,
    10191029                        );
    10201030                        runOnlyForDeploymentPostprocessing = 0;
  • trunk/Tools/TestWebKitAPI/Tests/WebKit2ObjC/UserContentTest.mm

    r131544 r134681  
    2828
    2929#import "PlatformUtilities.h"
     30#import "TestBrowsingContextLoadDelegate.h"
    3031#import <JavaScriptCore/JSRetainPtr.h>
    3132#import <JavaScriptCore/JavaScriptCore.h>
     
    4243static const char* redInRGB = "rgb(255, 0, 0)";
    4344static const char* userScriptTestProperty = "window._userScriptInstalled";
    44 
    45 typedef void (^OnLoadBlock)(WKBrowsingContextController *);
    46 
    47 @interface UserContentTestLoadDelegate : NSObject <WKBrowsingContextLoadDelegate>
    48 {
    49     OnLoadBlock _onLoadBlock;
    50 }
    51 
    52 @property (nonatomic, copy) OnLoadBlock onLoadBlock;
    53 
    54 - (id)initWithBlockToRunOnLoad:(OnLoadBlock)block;
    55 
    56 @end
    57 
    58 @implementation UserContentTestLoadDelegate
    59 
    60 @synthesize onLoadBlock = _onLoadBlock;
    61 
    62 - (id)initWithBlockToRunOnLoad:(OnLoadBlock)block
    63 {
    64     if (!(self = [super init]))
    65         return nil;
    66    
    67     self.onLoadBlock = block;
    68     return self;
    69 }
    70 
    71 - (void)browsingContextControllerDidFinishLoad:(WKBrowsingContextController *)sender
    72 {
    73     if (_onLoadBlock)
    74         _onLoadBlock(sender);
    75 }
    76 
    77 @end
    7845
    7946namespace {
     
    144111    WKView *wkView = [[WKView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) processGroup:processGroup browsingContextGroup:browsingContextGroup];
    145112    WKStringRef backgroundColorQuery = WKStringCreateWithUTF8CString(backgroundColorScript);
    146     wkView.browsingContextController.loadDelegate = [[UserContentTestLoadDelegate alloc] initWithBlockToRunOnLoad:^(WKBrowsingContextController *sender) {
     113    wkView.browsingContextController.loadDelegate = [[TestBrowsingContextLoadDelegate alloc] initWithBlockToRunOnLoad:^(WKBrowsingContextController *sender) {
    147114        WKPageRunJavaScriptInMainFrame_b(wkView.pageRef, backgroundColorQuery, ^(WKSerializedScriptValueRef serializedScriptValue, WKErrorRef error) {
    148115            expectScriptValueIsString(serializedScriptValue, greenInRGB);
     
    163130    WKView *wkView = [[WKView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) processGroup:processGroup browsingContextGroup:browsingContextGroup];
    164131    WKStringRef backgroundColorQuery = WKStringCreateWithUTF8CString(backgroundColorScript);
    165     wkView.browsingContextController.loadDelegate = [[UserContentTestLoadDelegate alloc] initWithBlockToRunOnLoad:^(WKBrowsingContextController *sender) {
     132    wkView.browsingContextController.loadDelegate = [[TestBrowsingContextLoadDelegate alloc] initWithBlockToRunOnLoad:^(WKBrowsingContextController *sender) {
    166133        WKPageRunJavaScriptInMainFrame_b(wkView.pageRef, backgroundColorQuery, ^(WKSerializedScriptValueRef serializedScriptValue, WKErrorRef error) {
    167134            expectScriptValueIsString(serializedScriptValue, greenInRGB);
     
    185152    WKView *wkView = [[WKView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) processGroup:processGroup browsingContextGroup:browsingContextGroup];
    186153    WKStringRef backgroundColorQuery = WKStringCreateWithUTF8CString(backgroundColorScript);
    187     wkView.browsingContextController.loadDelegate = [[UserContentTestLoadDelegate alloc] initWithBlockToRunOnLoad:^(WKBrowsingContextController *sender) {
     154    wkView.browsingContextController.loadDelegate = [[TestBrowsingContextLoadDelegate alloc] initWithBlockToRunOnLoad:^(WKBrowsingContextController *sender) {
    188155        WKPageRunJavaScriptInMainFrame_b(wkView.pageRef, backgroundColorQuery, ^(WKSerializedScriptValueRef serializedScriptValue, WKErrorRef error) {
    189156            expectScriptValueIsString(serializedScriptValue, redInRGB);
     
    207174    WKView *wkView = [[WKView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) processGroup:processGroup browsingContextGroup:browsingContextGroup];
    208175    WKStringRef userScriptTestPropertyString = WKStringCreateWithUTF8CString(userScriptTestProperty);
    209     wkView.browsingContextController.loadDelegate = [[UserContentTestLoadDelegate alloc] initWithBlockToRunOnLoad:^(WKBrowsingContextController *sender) {
     176    wkView.browsingContextController.loadDelegate = [[TestBrowsingContextLoadDelegate alloc] initWithBlockToRunOnLoad:^(WKBrowsingContextController *sender) {
    210177        WKPageRunJavaScriptInMainFrame_b(wkView.pageRef, userScriptTestPropertyString, ^(WKSerializedScriptValueRef serializedScriptValue, WKErrorRef error) {
    211178            expectScriptValueIsBoolean(serializedScriptValue, true);
     
    226193    WKView *wkView = [[WKView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) processGroup:processGroup browsingContextGroup:browsingContextGroup];
    227194    WKStringRef userScriptTestPropertyString = WKStringCreateWithUTF8CString(userScriptTestProperty);
    228     wkView.browsingContextController.loadDelegate = [[UserContentTestLoadDelegate alloc] initWithBlockToRunOnLoad:^(WKBrowsingContextController *sender) {
     195    wkView.browsingContextController.loadDelegate = [[TestBrowsingContextLoadDelegate alloc] initWithBlockToRunOnLoad:^(WKBrowsingContextController *sender) {
    229196        WKPageRunJavaScriptInMainFrame_b(wkView.pageRef, userScriptTestPropertyString, ^(WKSerializedScriptValueRef serializedScriptValue, WKErrorRef error) {
    230197            expectScriptValueIsBoolean(serializedScriptValue, true);
     
    248215    WKView *wkView = [[WKView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) processGroup:processGroup browsingContextGroup:browsingContextGroup];
    249216    WKStringRef userScriptTestPropertyString = WKStringCreateWithUTF8CString(userScriptTestProperty);
    250     wkView.browsingContextController.loadDelegate = [[UserContentTestLoadDelegate alloc] initWithBlockToRunOnLoad:^(WKBrowsingContextController *sender) {
     217    wkView.browsingContextController.loadDelegate = [[TestBrowsingContextLoadDelegate alloc] initWithBlockToRunOnLoad:^(WKBrowsingContextController *sender) {
    251218        WKPageRunJavaScriptInMainFrame_b(wkView.pageRef, userScriptTestPropertyString, ^(WKSerializedScriptValueRef serializedScriptValue, WKErrorRef error) {
    252219            expectScriptValueIsUndefined(serializedScriptValue);
  • trunk/Tools/TestWebKitAPI/mac/TestBrowsingContextLoadDelegate.h

    r134679 r134681  
    11/*
    2  * Copyright (C) 2011 Apple Inc. All rights reserved.
     2 * Copyright (C) 2012 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2424 */
    2525
    26 #import <WebKit2/WKBrowsingContextController.h>
     26#import <WebKit2/WebKit2.h>
    2727
    28 @interface WKBrowsingContextController (Internal)
     28typedef void (^OnLoadBlock)(WKBrowsingContextController *);
    2929
    30 /* This should only be called from associate view. */
    31 - (id)_initWithPageRef:(WKPageRef)pageRef;
     30@interface TestBrowsingContextLoadDelegate : NSObject <WKBrowsingContextLoadDelegate> {
     31}
     32
     33@property(nonatomic, copy) OnLoadBlock onLoadBlock;
     34
     35- (id)initWithBlockToRunOnLoad:(OnLoadBlock)block;
    3236
    3337@end
  • trunk/Tools/TestWebKitAPI/mac/TestBrowsingContextLoadDelegate.mm

    r134679 r134681  
    11/*
    2  * Copyright (C) 2011 Apple Inc. All rights reserved.
     2 * Copyright (C) 2012 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2424 */
    2525
    26 #import <WebKit2/WKBrowsingContextController.h>
     26#include "config.h"
     27#include "TestBrowsingContextLoadDelegate.h"
    2728
    28 @interface WKBrowsingContextController (Internal)
     29@implementation TestBrowsingContextLoadDelegate
    2930
    30 /* This should only be called from associate view. */
    31 - (id)_initWithPageRef:(WKPageRef)pageRef;
     31@synthesize onLoadBlock = _onLoadBlock;
     32
     33- (id)initWithBlockToRunOnLoad:(OnLoadBlock)block
     34{
     35    if (!(self = [super init]))
     36        return nil;
     37   
     38    self.onLoadBlock = block;
     39    return self;
     40}
     41
     42- (void)browsingContextControllerDidFinishLoad:(WKBrowsingContextController *)sender
     43{
     44    if (_onLoadBlock)
     45        _onLoadBlock(sender);
     46}
    3247
    3348@end
Note: See TracChangeset for help on using the changeset viewer.