Changeset 149194 in webkit


Ignore:
Timestamp:
Apr 26, 2013 9:55:12 AM (11 years ago)
Author:
aestes@apple.com
Message:

[WebKit2] Loading a resource from a custom protocol in a synchronous XHR times out
https://bugs.webkit.org/show_bug.cgi?id=115223

Reviewed by Darin Adler.

Source/WebKit2:

When WebKit performs a synchronous load on the Mac, it spins a nested
run loop in a mode that only accepts input from the NSURLConnection
performing the load. When the load is for a custom protocol in WebKit2,
we proxy it to the UI process via CoreIPC messages, but the response
messages from the UI process are never processed as long as the run
loop is in a non-common mode (and we wouldn't want to process messages
that could re-enter WebCore in the middle of loading, anyway). Since
these messages never make it back to the NSURLConnection handling the
request, the connection eventually times out.

Fix this by using a work queue to handle custom protocol messages in
the networking process. The work queue can process incoming custom
protocol messages while the main thread is blocked.

  • NetworkProcess/NetworkProcess.cpp:

(WebKit::NetworkProcess::initializeConnection): Called
initializeConnection() on all the NetworkProcess's supplements.

  • Shared/ChildProcessSupplement.h: Added a base class for

NetworkProcessSupplement and WebProcessSupplement which defines
initializeConnection and provides an empty default implementation.
(WebKit::ChildProcessSupplement::~ChildProcessSupplement):
(WebKit::ChildProcessSupplement::initializeConnection):

  • Shared/Network/CustomProtocols/CustomProtocolManager.h:
  • Shared/Network/CustomProtocols/mac/CustomProtocolManagerMac.mm:

(WebKit::CustomProtocolManager::CustomProtocolManager): Instantiated a
work queue for message processing.
(WebKit::CustomProtocolManager::initializeConnection): Added the work
queue as a message receiver on the CoreIPC connection.
(WebKit::CustomProtocolManager::initialize): If we're in the web
process and the network process is being used, unregister and destroy
the work queue we previously created. It'd be better to not create it
in the first place, but we have to register our work queue with the
CoreIPC connection before it is established, which is before the UI
process has told us whether the network process is in use.

  • Shared/Network/NetworkProcessSupplement.h: Inherited from

ChildProcessSupplement.

  • WebKit2.xcodeproj/project.pbxproj: Added ChildProcessSupplement.h.
  • WebProcess/WebProcess.cpp:

(WebKit::WebProcess::initializeConnection): Called
initializeConnection() on all the WebProcess's supplements.

  • WebProcess/WebProcessSupplement.h: Inherited from

ChildProcessSupplement.

Tools:

Added an API test.

  • TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: Added new files.
  • TestWebKitAPI/Tests/CustomProtocolsSyncXHRTest.mm: Added.

(TestWebKitAPI::TEST): Tested that a synchronous XHR does not time out
when it loads a request with a custom protocol.

  • TestWebKitAPI/Tests/WebKit2/custom-protocol-sync-xhr.html: Added.
  • TestWebKitAPI/Tests/WebKit2ObjC/CustomProtocolsTest.mm: Moved the

NSURLProtocol subclass to TestProtocol.{h, mm} and did some
miscellaneous cleanup.

  • TestWebKitAPI/mac/TestProtocol.h: Copied from Source/WebKit2/WebProcess/WebProcessSupplement.h.
  • TestWebKitAPI/mac/TestProtocol.mm: Copied from Tools/TestWebKitAPI/Tests/WebKit2ObjC/CustomProtocolsTest.mm.

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

Location:
trunk
Files:
2 added
11 edited
3 copied

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r149192 r149194  
     12013-04-25  Andy Estes  <aestes@apple.com>
     2
     3        [WebKit2] Loading a resource from a custom protocol in a synchronous XHR times out
     4        https://bugs.webkit.org/show_bug.cgi?id=115223
     5
     6        Reviewed by Darin Adler.
     7
     8        When WebKit performs a synchronous load on the Mac, it spins a nested
     9        run loop in a mode that only accepts input from the NSURLConnection
     10        performing the load. When the load is for a custom protocol in WebKit2,
     11        we proxy it to the UI process via CoreIPC messages, but the response
     12        messages from the UI process are never processed as long as the run
     13        loop is in a non-common mode (and we wouldn't want to process messages
     14        that could re-enter WebCore in the middle of loading, anyway). Since
     15        these messages never make it back to the NSURLConnection handling the
     16        request, the connection eventually times out.
     17
     18        Fix this by using a work queue to handle custom protocol messages in
     19        the networking process. The work queue can process incoming custom
     20        protocol messages while the main thread is blocked.
     21
     22        * NetworkProcess/NetworkProcess.cpp:
     23        (WebKit::NetworkProcess::initializeConnection): Called
     24        initializeConnection() on all the NetworkProcess's supplements.
     25        * Shared/ChildProcessSupplement.h: Added a base class for
     26        NetworkProcessSupplement and WebProcessSupplement which defines
     27        initializeConnection and provides an empty default implementation.
     28        (WebKit::ChildProcessSupplement::~ChildProcessSupplement):
     29        (WebKit::ChildProcessSupplement::initializeConnection):
     30        * Shared/Network/CustomProtocols/CustomProtocolManager.h:
     31        * Shared/Network/CustomProtocols/mac/CustomProtocolManagerMac.mm:
     32        (WebKit::CustomProtocolManager::CustomProtocolManager): Instantiated a
     33        work queue for message processing.
     34        (WebKit::CustomProtocolManager::initializeConnection): Added the work
     35        queue as a message receiver on the CoreIPC connection.
     36        (WebKit::CustomProtocolManager::initialize): If we're in the web
     37        process and the network process is being used, unregister and destroy
     38        the work queue we previously created. It'd be better to not create it
     39        in the first place, but we have to register our work queue with the
     40        CoreIPC connection before it is established, which is before the UI
     41        process has told us whether the network process is in use.
     42        * Shared/Network/NetworkProcessSupplement.h: Inherited from
     43        ChildProcessSupplement.
     44        * WebKit2.xcodeproj/project.pbxproj: Added ChildProcessSupplement.h.
     45        * WebProcess/WebProcess.cpp:
     46        (WebKit::WebProcess::initializeConnection): Called
     47        initializeConnection() on all the WebProcess's supplements.
     48        * WebProcess/WebProcessSupplement.h: Inherited from
     49        ChildProcessSupplement.
     50
    1512013-04-26  Eduardo Lima Mitev  <elima@igalia.com>
    252
  • trunk/Source/WebKit2/NetworkProcess/NetworkProcess.cpp

    r147251 r149194  
    175175    SecItemShim::shared().initializeConnection(connection);
    176176#endif
     177
     178    NetworkProcessSupplementMap::const_iterator it = m_supplements.begin();
     179    NetworkProcessSupplementMap::const_iterator end = m_supplements.end();
     180    for (; it != end; ++it)
     181        it->value->initializeConnection(connection);
    177182}
    178183
  • trunk/Source/WebKit2/Shared/ChildProcessSupplement.h

    r149193 r149194  
    11/*
    2  * Copyright (C) 2012 Apple Inc. All rights reserved.
     2 * Copyright (C) 2013 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2424 */
    2525
    26 #ifndef WebProcessSupplement_h
    27 #define WebProcessSupplement_h
     26#ifndef ChildProcessSupplement_h
     27#define ChildProcessSupplement_h
     28
     29namespace CoreIPC {
     30class Connection;
     31} // namespace CoreIPC
    2832
    2933namespace WebKit {
    3034
    31 struct WebProcessCreationParameters;
    32 
    33 class WebProcessSupplement {
     35class ChildProcessSupplement {
    3436public:
    35     virtual ~WebProcessSupplement()
     37    virtual ~ChildProcessSupplement()
    3638    {
    3739    }
    3840
    39     virtual void initialize(const WebProcessCreationParameters&)
     41    virtual void initializeConnection(CoreIPC::Connection*)
    4042    {
    4143    }
     
    4446} // namespace WebKit
    4547
    46 #endif // WebProcessSupplement_h
     48#endif // ChildProcessSupplement_h
  • trunk/Source/WebKit2/Shared/Network/CustomProtocols/CustomProtocolManager.h

    r149121 r149194  
    2929#if ENABLE(CUSTOM_PROTOCOLS)
    3030
    31 #include "MessageReceiver.h"
     31#include "Connection.h"
    3232#include "NetworkProcessSupplement.h"
    3333#include "WebProcessSupplement.h"
     34#include "WorkQueue.h"
    3435#include <wtf/HashSet.h>
    3536#include <wtf/Threading.h>
     
    5758struct NetworkProcessCreationParameters;
    5859
    59 class CustomProtocolManager : public WebProcessSupplement, public NetworkProcessSupplement, public CoreIPC::MessageReceiver {
     60class CustomProtocolManager : public WebProcessSupplement, public NetworkProcessSupplement, public CoreIPC::Connection::WorkQueueMessageReceiver {
    6061    WTF_MAKE_NONCOPYABLE(CustomProtocolManager);
    6162public:
     
    7677
    7778private:
     79    // ChildProcessSupplement
     80    void initializeConnection(CoreIPC::Connection*) OVERRIDE;
     81
    7882    // WebProcessSupplement
    7983    void initialize(const WebProcessCreationParameters&) OVERRIDE;
     
    9498    HashSet<String> m_registeredSchemes;
    9599    ChildProcess* m_childProcess;
     100    RefPtr<WorkQueue> m_messageQueue;
    96101
    97102#if PLATFORM(MAC)
  • trunk/Source/WebKit2/Shared/Network/CustomProtocols/mac/CustomProtocolManagerMac.mm

    r149121 r149194  
    117117CustomProtocolManager::CustomProtocolManager(ChildProcess* childProcess)
    118118    : m_childProcess(childProcess)
    119 {
    120     m_childProcess->addMessageReceiver(Messages::CustomProtocolManager::messageReceiverName(), this);
    121 
     119    , m_messageQueue(WorkQueue::create("com.apple.WebKit.CustomProtocolManager"))
     120{
    122121    ASSERT(!sharedCustomProtocolManager);
    123122    sharedCustomProtocolManager = this;
    124123}
    125124
     125void CustomProtocolManager::initializeConnection(CoreIPC::Connection* connection)
     126{
     127    connection->addWorkQueueMessageReceiver(Messages::CustomProtocolManager::messageReceiverName(), m_messageQueue.get(), this);
     128}
     129
    126130void CustomProtocolManager::initialize(const WebProcessCreationParameters& parameters)
    127131{
    128132#if ENABLE(NETWORK_PROCESS)
    129133    ASSERT(parameters.urlSchemesRegisteredForCustomProtocols.isEmpty() || !parameters.usesNetworkProcess);
    130     if (parameters.usesNetworkProcess)
    131         return;
     134    if (parameters.usesNetworkProcess) {
     135        m_childProcess->connection()->removeWorkQueueMessageReceiver(Messages::CustomProtocolManager::messageReceiverName());
     136        m_messageQueue = nullptr;
     137        return;
     138    }
    132139#endif
    133140
  • trunk/Source/WebKit2/Shared/Network/NetworkProcessSupplement.h

    r138569 r149194  
    2727#define NetworkProcessSupplement_h
    2828
     29#include "ChildProcessSupplement.h"
     30
    2931namespace WebKit {
    3032
    3133struct NetworkProcessCreationParameters;
    3234
    33 class NetworkProcessSupplement {
     35class NetworkProcessSupplement : public ChildProcessSupplement {
    3436#if ENABLE(NETWORK_PROCESS)
    3537public:
    36     virtual ~NetworkProcessSupplement()
    37     {
    38     }
    39 
    4038    virtual void initialize(const NetworkProcessCreationParameters&)
    4139    {
  • trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj

    r149107 r149194  
    296296                1QQ417CB12C00CCA002BE67B /* TextCheckerCompletion.h in Headers */ = {isa = PBXBuildFile; fileRef = 1CC417C912C00CCA002BE67B /* TextCheckerCompletion.h */; };
    297297                1ZZ417EF12C00D87002BE67B /* TextCheckerCompletion.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1BB417C912C00CCA002BE67B /* TextCheckerCompletion.cpp */; };
     298                290F4272172A0C7400939FF0 /* ChildProcessSupplement.h in Headers */ = {isa = PBXBuildFile; fileRef = 290F4271172A0C7400939FF0 /* ChildProcessSupplement.h */; };
    298299                293EBEAB1627D9C9005F89F1 /* WKDOMText.h in Headers */ = {isa = PBXBuildFile; fileRef = 293EBEA91627D9C9005F89F1 /* WKDOMText.h */; settings = {ATTRIBUTES = (Public, ); }; };
    299300                293EBEAC1627D9C9005F89F1 /* WKDOMText.mm in Sources */ = {isa = PBXBuildFile; fileRef = 293EBEAA1627D9C9005F89F1 /* WKDOMText.mm */; };
     
    17201721                1CBC945D16515ED200D68AAE /* DockBottom.pdf */ = {isa = PBXFileReference; lastKnownFileType = image.pdf; name = DockBottom.pdf; path = Resources/DockBottom.pdf; sourceTree = "<group>"; };
    17211722                1CC417C912C00CCA002BE67B /* TextCheckerCompletion.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TextCheckerCompletion.h; sourceTree = "<group>"; };
     1723                290F4271172A0C7400939FF0 /* ChildProcessSupplement.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ChildProcessSupplement.h; sourceTree = "<group>"; };
    17221724                293EBEA91627D9C9005F89F1 /* WKDOMText.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKDOMText.h; sourceTree = "<group>"; };
    17231725                293EBEAA1627D9C9005F89F1 /* WKDOMText.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WKDOMText.mm; sourceTree = "<group>"; };
     
    32053207                                E1513C64166EABB200149FCB /* ChildProcessProxy.cpp */,
    32063208                                E1513C65166EABB200149FCB /* ChildProcessProxy.h */,
     3209                                290F4271172A0C7400939FF0 /* ChildProcessSupplement.h */,
    32073210                                1A6F9F8E11E13EFC00DB1371 /* CommandLine.h */,
    32083211                                5136183B163126DA00A99DDE /* ConnectionStack.cpp */,
     
    56185621                                BC646C1D11DD399F006455B0 /* WKBackForwardListItem.h in Headers */,
    56195622                                BCDDB317124EBD130048D13C /* WKBase.h in Headers */,
     5623                                290F4272172A0C7400939FF0 /* ChildProcessSupplement.h in Headers */,
    56205624                                BCBAAC73144E619E0053F82F /* WKBrowsingContextController.h in Headers */,
    56215625                                BCBAAC74144E61A50053F82F /* WKBrowsingContextControllerInternal.h in Headers */,
  • trunk/Source/WebKit2/WebProcess/WebProcess.cpp

    r149074 r149194  
    230230    SecItemShim::shared().initializeConnection(connection);
    231231#endif
     232   
     233    WebProcessSupplementMap::const_iterator it = m_supplements.begin();
     234    WebProcessSupplementMap::const_iterator end = m_supplements.end();
     235    for (; it != end; ++it)
     236        it->value->initializeConnection(connection);
    232237
    233238    m_webConnection = WebConnectionToUIProcess::create(this);
  • trunk/Source/WebKit2/WebProcess/WebProcessSupplement.h

    r138569 r149194  
    2727#define WebProcessSupplement_h
    2828
     29#include "ChildProcessSupplement.h"
     30
    2931namespace WebKit {
    3032
    3133struct WebProcessCreationParameters;
    3234
    33 class WebProcessSupplement {
     35class WebProcessSupplement : public ChildProcessSupplement {
    3436public:
    35     virtual ~WebProcessSupplement()
    36     {
    37     }
    38 
    3937    virtual void initialize(const WebProcessCreationParameters&)
    4038    {
  • trunk/Tools/ChangeLog

    r149193 r149194  
     12013-04-25  Andy Estes  <aestes@apple.com>
     2
     3        [WebKit2] Loading a resource from a custom protocol in a synchronous XHR times out
     4        https://bugs.webkit.org/show_bug.cgi?id=115223
     5
     6        Reviewed by Darin Adler.
     7
     8        Added an API test.
     9
     10        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: Added new files.
     11        * TestWebKitAPI/Tests/CustomProtocolsSyncXHRTest.mm: Added.
     12        (TestWebKitAPI::TEST): Tested that a synchronous XHR does not time out
     13        when it loads a request with a custom protocol.
     14        * TestWebKitAPI/Tests/WebKit2/custom-protocol-sync-xhr.html: Added.
     15        * TestWebKitAPI/Tests/WebKit2ObjC/CustomProtocolsTest.mm: Moved the
     16        NSURLProtocol subclass to TestProtocol.{h, mm} and did some
     17        miscellaneous cleanup.
     18        * TestWebKitAPI/mac/TestProtocol.h: Copied from Source/WebKit2/WebProcess/WebProcessSupplement.h.
     19        * TestWebKitAPI/mac/TestProtocol.mm: Copied from Tools/TestWebKitAPI/Tests/WebKit2ObjC/CustomProtocolsTest.mm.
     20        (+[TestProtocol canInitWithRequest:]):
     21        (+[TestProtocol canonicalRequestForRequest:]):
     22        (+[TestProtocol requestIsCacheEquivalent:toRequest:]):
     23        (+[TestProtocol scheme]):
     24        (-[TestProtocol startLoading]):
     25        (-[TestProtocol stopLoading]):
     26
    1272013-04-26  Martin Robinson  <mrobinson@igalia.com>
    228
  • trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj

    r148921 r149194  
    3636                26F1B44415CA434F00D1E4BF /* AtomicString.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 26F1B44215CA434F00D1E4BF /* AtomicString.cpp */; };
    3737                26F1B44515CA434F00D1E4BF /* StringImpl.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 26F1B44315CA434F00D1E4BF /* StringImpl.cpp */; };
     38                290F4275172A221C00939FF0 /* custom-protocol-sync-xhr.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 290F4274172A1FDE00939FF0 /* custom-protocol-sync-xhr.html */; };
     39                290F4278172A232C00939FF0 /* CustomProtocolsSyncXHRTest.mm in Sources */ = {isa = PBXBuildFile; fileRef = 290F4276172A232C00939FF0 /* CustomProtocolsSyncXHRTest.mm */; };
     40                290F427B172A23A500939FF0 /* TestProtocol.mm in Sources */ = {isa = PBXBuildFile; fileRef = 290F4279172A23A500939FF0 /* TestProtocol.mm */; };
    3841                2943BE86161DFEB800999E3D /* UserContentTest.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2943BE84161DFEB800999E3D /* UserContentTest.mm */; };
    3942                29AB8AA1164C735800D49BEC /* CustomProtocolsTest.mm in Sources */ = {isa = PBXBuildFile; fileRef = 29AB8A9F164C735800D49BEC /* CustomProtocolsTest.mm */; };
     
    233236                        dstSubfolderSpec = 7;
    234237                        files = (
     238                                290F4275172A221C00939FF0 /* custom-protocol-sync-xhr.html in Copy Resources */,
    235239                                C2CF975B16CEC71B0054E99D /* JSContextBackForwardCache1.html in Copy Resources */,
    236240                                C2CF975A16CEC7140054E99D /* JSContextBackForwardCache2.html in Copy Resources */,
     
    303307                26F1B44215CA434F00D1E4BF /* AtomicString.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = AtomicString.cpp; path = WTF/AtomicString.cpp; sourceTree = "<group>"; };
    304308                26F1B44315CA434F00D1E4BF /* StringImpl.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = StringImpl.cpp; path = WTF/StringImpl.cpp; sourceTree = "<group>"; };
     309                290F4274172A1FDE00939FF0 /* custom-protocol-sync-xhr.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "custom-protocol-sync-xhr.html"; sourceTree = "<group>"; };
     310                290F4276172A232C00939FF0 /* CustomProtocolsSyncXHRTest.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = CustomProtocolsSyncXHRTest.mm; sourceTree = "<group>"; };
     311                290F4279172A23A500939FF0 /* TestProtocol.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = TestProtocol.mm; sourceTree = "<group>"; };
     312                290F427A172A23A500939FF0 /* TestProtocol.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TestProtocol.h; sourceTree = "<group>"; };
    305313                2943BE84161DFEB800999E3D /* UserContentTest.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = UserContentTest.mm; path = WebKit2ObjC/UserContentTest.mm; sourceTree = "<group>"; };
    306314                29AB8A9F164C735800D49BEC /* CustomProtocolsTest.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = CustomProtocolsTest.mm; path = WebKit2ObjC/CustomProtocolsTest.mm; sourceTree = "<group>"; };
     
    599607                        children = (
    600608                                29AB8A9F164C735800D49BEC /* CustomProtocolsTest.mm */,
     609                                290F4276172A232C00939FF0 /* CustomProtocolsSyncXHRTest.mm */,
    601610                                2943BE84161DFEB800999E3D /* UserContentTest.mm */,
    602611                                BC3C4C7D14587AA60025FB62 /* WKBrowsingContextGroupTest.mm */,
     
    746755                                C045F9461385C2F800C0F3CD /* 18-characters.html */,
    747756                                76E182DE15475A8300F1FADD /* auto-submitting-form.html */,
     757                                290F4274172A1FDE00939FF0 /* custom-protocol-sync-xhr.html */,
    748758                                C5E1AFFD16B22179006CC1F2 /* execCopy.html */,
    749759                                BC2D004A12A9FEB300E732A3 /* file-with-anchor.html */,
     
    780790                                29AB8AA3164C7A9300D49BEC /* TestBrowsingContextLoadDelegate.h */,
    781791                                29AB8AA2164C7A9300D49BEC /* TestBrowsingContextLoadDelegate.mm */,
     792                                290F427A172A23A500939FF0 /* TestProtocol.h */,
     793                                290F4279172A23A500939FF0 /* TestProtocol.mm */,
    782794                                C08587BE13FE956C001EF4E5 /* WebKitAgnosticTest.h */,
    783795                                C08587BD13FE956C001EF4E5 /* WebKitAgnosticTest.mm */,
     
    10231035                                BCBD3710125AA2EB00D2C29F /* FrameMIMETypeHTML.cpp in Sources */,
    10241036                                BCBD3761125ABCFE00D2C29F /* FrameMIMETypePNG.cpp in Sources */,
     1037                                290F427B172A23A500939FF0 /* TestProtocol.mm in Sources */,
    10251038                                1AA9E55914980A9900001A8A /* Functional.cpp in Sources */,
    10261039                                C0C5D3BE14598B6F00A802A6 /* GetBackingScaleFactor.mm in Sources */,
     
    11051118                                520BCF4D141EB09E00937EA8 /* WebArchive.cpp in Sources */,
    11061119                                0F17BBD615AF6C4D007AB753 /* WebCoreStatisticsWithNoWebProcess.cpp in Sources */,
     1120                                290F4278172A232C00939FF0 /* CustomProtocolsSyncXHRTest.mm in Sources */,
    11071121                                C08587BF13FE956C001EF4E5 /* WebKitAgnosticTest.mm in Sources */,
    11081122                                51FBBB4D1513D4E900822738 /* WebViewCanPasteURL.mm in Sources */,
  • trunk/Tools/TestWebKitAPI/Tests/WebKit2ObjC/CustomProtocolsTest.mm

    r134681 r149194  
    2929#import "PlatformUtilities.h"
    3030#import "TestBrowsingContextLoadDelegate.h"
    31 #import <Foundation/Foundation.h>
     31#import "TestProtocol.h"
    3232#import <WebKit2/WebKit2.h>
    3333
    34 static NSString *testScheme = @"test";
    35 static NSString *testHost = @"test";
    3634static bool testFinished = false;
    3735
    38 @interface TestProtocol : NSURLProtocol {
    39 }
    40 @end
     36namespace TestWebKitAPI {
    4137
    42 @implementation TestProtocol
    43 
    44 + (BOOL)canInitWithRequest:(NSURLRequest *)request
    45 {
    46     return [[[request URL] scheme] caseInsensitiveCompare:testScheme] == NSOrderedSame;
    47 }
    48 
    49 + (NSURLRequest *)canonicalRequestForRequest:(NSURLRequest *)request
    50 {
    51     return request;
    52 }
    53 
    54 + (BOOL)requestIsCacheEquivalent:(NSURLRequest *)a toRequest:(NSURLRequest *)b
    55 {
    56     return NO;
    57 }
    58 
    59 - (void)startLoading
    60 {
    61     EXPECT_TRUE([[[[self request] URL] scheme] isEqualToString:testScheme]);
    62     EXPECT_TRUE([[[[self request] URL] host] isEqualToString:testHost]);
    63    
    64     NSData *data = [@"<body>PASS</body>" dataUsingEncoding:NSASCIIStringEncoding];
    65     NSURLResponse *response = [[NSURLResponse alloc] initWithURL:[[self request] URL] MIMEType:@"text/html" expectedContentLength:[data length] textEncodingName:nil];
    66     [[self client] URLProtocol:self didReceiveResponse:response cacheStoragePolicy:NSURLCacheStorageNotAllowed];
    67     [[self client] URLProtocol:self didLoadData:data];
    68     [[self client] URLProtocolDidFinishLoading:self];
    69     [response release];
    70 }
    71 
    72 - (void)stopLoading
    73 {
    74 }
    75 
    76 @end
    77 
    78 TEST(WebKit2CustomProtocolsTest, CustomProtocolUsed)
     38TEST(WebKit2CustomProtocolsTest, MainResource)
    7939{
    8040    [NSURLProtocol registerClass:[TestProtocol class]];
    81     [WKBrowsingContextController registerSchemeForCustomProtocol:testScheme];
     41    [WKBrowsingContextController registerSchemeForCustomProtocol:[TestProtocol scheme]];
    8242
    8343    WKProcessGroup *processGroup = [[WKProcessGroup alloc] init];
     
    8747        testFinished = true;
    8848    }];
    89     [wkView.browsingContextController loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@://%@", testScheme, testHost]]]];
     49    [wkView.browsingContextController loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@://test", [TestProtocol scheme]]]]];
    9050
    91     TestWebKitAPI::Util::run(&testFinished);
     51    Util::run(&testFinished);
    9252}
     53
     54} // namespace TestWebKitAPI
  • trunk/Tools/TestWebKitAPI/mac/TestProtocol.h

    r149193 r149194  
    11/*
    2  * Copyright (C) 2012 Apple Inc. All rights reserved.
     2 * Copyright (C) 2013 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2424 */
    2525
    26 #ifndef WebProcessSupplement_h
    27 #define WebProcessSupplement_h
     26#ifndef TestProtocol_h
     27#define TestProtocol_h
    2828
    29 namespace WebKit {
     29@interface TestProtocol : NSURLProtocol {
     30}
     31+ (NSString *)scheme;
     32@end
    3033
    31 struct WebProcessCreationParameters;
    32 
    33 class WebProcessSupplement {
    34 public:
    35     virtual ~WebProcessSupplement()
    36     {
    37     }
    38 
    39     virtual void initialize(const WebProcessCreationParameters&)
    40     {
    41     }
    42 };
    43 
    44 } // namespace WebKit
    45 
    46 #endif // WebProcessSupplement_h
     34#endif // TestProtocol_h
  • trunk/Tools/TestWebKitAPI/mac/TestProtocol.mm

    r149193 r149194  
    11/*
    2  * Copyright (C) 2012 Apple Inc. All rights reserved.
     2 * Copyright (C) 2013 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2525
    2626#import "config.h"
    27 #import "Test.h"
    28 
    29 #import "PlatformUtilities.h"
    30 #import "TestBrowsingContextLoadDelegate.h"
    31 #import <Foundation/Foundation.h>
    32 #import <WebKit2/WebKit2.h>
     27#import "TestProtocol.h"
    3328
    3429static NSString *testScheme = @"test";
    35 static NSString *testHost = @"test";
    36 static bool testFinished = false;
    37 
    38 @interface TestProtocol : NSURLProtocol {
    39 }
    40 @end
    4130
    4231@implementation TestProtocol
     
    5746}
    5847
     48+ (NSString *)scheme
     49{
     50    return testScheme;
     51}
     52
    5953- (void)startLoading
    6054{
    6155    EXPECT_TRUE([[[[self request] URL] scheme] isEqualToString:testScheme]);
    62     EXPECT_TRUE([[[[self request] URL] host] isEqualToString:testHost]);
    6356   
    64     NSData *data = [@"<body>PASS</body>" dataUsingEncoding:NSASCIIStringEncoding];
     57    NSData *data = [@"PASS" dataUsingEncoding:NSASCIIStringEncoding];
    6558    NSURLResponse *response = [[NSURLResponse alloc] initWithURL:[[self request] URL] MIMEType:@"text/html" expectedContentLength:[data length] textEncodingName:nil];
    6659    [[self client] URLProtocol:self didReceiveResponse:response cacheStoragePolicy:NSURLCacheStorageNotAllowed];
     
    7568
    7669@end
    77 
    78 TEST(WebKit2CustomProtocolsTest, CustomProtocolUsed)
    79 {
    80     [NSURLProtocol registerClass:[TestProtocol class]];
    81     [WKBrowsingContextController registerSchemeForCustomProtocol:testScheme];
    82 
    83     WKProcessGroup *processGroup = [[WKProcessGroup alloc] init];
    84     WKBrowsingContextGroup *browsingContextGroup = [[WKBrowsingContextGroup alloc] initWithIdentifier:@"TestIdentifier"];
    85     WKView *wkView = [[WKView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) processGroup:processGroup browsingContextGroup:browsingContextGroup];
    86     wkView.browsingContextController.loadDelegate = [[TestBrowsingContextLoadDelegate alloc] initWithBlockToRunOnLoad:^(WKBrowsingContextController *sender) {
    87         testFinished = true;
    88     }];
    89     [wkView.browsingContextController loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@://%@", testScheme, testHost]]]];
    90 
    91     TestWebKitAPI::Util::run(&testFinished);
    92 }
Note: See TracChangeset for help on using the changeset viewer.