Changeset 240030 in webkit


Ignore:
Timestamp:
Jan 15, 2019 8:57:54 PM (5 years ago)
Author:
achristensen@apple.com
Message:

Remove more NetworkProcess::singleton use
https://bugs.webkit.org/show_bug.cgi?id=193484

Reviewed by Geoffrey Garen.

This removes the use of NetworkProcess::singleton in the LegacyCustomProtocolManager.
This is the kind of awful duct tape code that keeps me awake at night, but it's necessary
because we can't quite remove LegacyCustomProtocolManager yet but we need to allow more than
one NetworkProcess object. To make it work well enough until we remove LegacyCustomProtocolManager,
use the last NetworkProcess object that has been created.

  • NetworkProcess/CustomProtocols/Cocoa/LegacyCustomProtocolManagerCocoa.mm:

(newestNetworkProcess):
(LegacyCustomProtocolManager::networkProcessCreated):
(+[WKCustomProtocol canInitWithRequest:]):
(-[WKCustomProtocol initWithRequest:cachedResponse:client:]):
(-[WKCustomProtocol startLoading]):
(-[WKCustomProtocol stopLoading]):

  • NetworkProcess/CustomProtocols/LegacyCustomProtocolManager.cpp:

(WebKit::LegacyCustomProtocolManager::LegacyCustomProtocolManager):
(WebKit::LegacyCustomProtocolManager::startLoading):
(WebKit::LegacyCustomProtocolManager::stopLoading):

  • NetworkProcess/CustomProtocols/LegacyCustomProtocolManager.h:
  • NetworkProcess/NetworkProcess.cpp:

(WebKit::NetworkProcess::NetworkProcess):

Location:
trunk/Source/WebKit
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r240029 r240030  
     12019-01-15  Alex Christensen  <achristensen@webkit.org>
     2
     3        Remove more NetworkProcess::singleton use
     4        https://bugs.webkit.org/show_bug.cgi?id=193484
     5
     6        Reviewed by Geoffrey Garen.
     7
     8        This removes the use of NetworkProcess::singleton in the LegacyCustomProtocolManager.
     9        This is the kind of awful duct tape code that keeps me awake at night, but it's necessary
     10        because we can't quite remove LegacyCustomProtocolManager yet but we need to allow more than
     11        one NetworkProcess object.  To make it work well enough until we remove LegacyCustomProtocolManager,
     12        use the last NetworkProcess object that has been created.
     13
     14        * NetworkProcess/CustomProtocols/Cocoa/LegacyCustomProtocolManagerCocoa.mm:
     15        (newestNetworkProcess):
     16        (LegacyCustomProtocolManager::networkProcessCreated):
     17        (+[WKCustomProtocol canInitWithRequest:]):
     18        (-[WKCustomProtocol initWithRequest:cachedResponse:client:]):
     19        (-[WKCustomProtocol startLoading]):
     20        (-[WKCustomProtocol stopLoading]):
     21        * NetworkProcess/CustomProtocols/LegacyCustomProtocolManager.cpp:
     22        (WebKit::LegacyCustomProtocolManager::LegacyCustomProtocolManager):
     23        (WebKit::LegacyCustomProtocolManager::startLoading):
     24        (WebKit::LegacyCustomProtocolManager::stopLoading):
     25        * NetworkProcess/CustomProtocols/LegacyCustomProtocolManager.h:
     26        * NetworkProcess/NetworkProcess.cpp:
     27        (WebKit::NetworkProcess::NetworkProcess):
     28
    1292019-01-15  Alex Christensen  <achristensen@webkit.org>
    230
  • trunk/Source/WebKit/NetworkProcess/CustomProtocols/Cocoa/LegacyCustomProtocolManagerCocoa.mm

    r238771 r240030  
    4040using namespace WebKit;
    4141
     42static RefPtr<NetworkProcess>& firstNetworkProcess()
     43{
     44    static NeverDestroyed<RefPtr<NetworkProcess>> networkProcess;
     45    return networkProcess.get();
     46}
     47
     48void LegacyCustomProtocolManager::networkProcessCreated(NetworkProcess& networkProcess)
     49{
     50    auto hasRegisteredSchemes = [] (auto* legacyCustomProtocolManager) {
     51        if (!legacyCustomProtocolManager)
     52            return false;
     53        LockHolder locker(legacyCustomProtocolManager->m_registeredSchemesMutex);
     54        return !legacyCustomProtocolManager->m_registeredSchemes.isEmpty();
     55    };
     56
     57    RELEASE_ASSERT(!firstNetworkProcess() || !hasRegisteredSchemes(firstNetworkProcess()->supplement<LegacyCustomProtocolManager>()));
     58    firstNetworkProcess() = &networkProcess;
     59}
     60
    4261@interface WKCustomProtocol : NSURLProtocol {
    4362@private
     
    5574+ (BOOL)canInitWithRequest:(NSURLRequest *)request
    5675{
    57     if (auto* customProtocolManager = NetworkProcess::singleton().supplement<LegacyCustomProtocolManager>())
     76    if (auto* customProtocolManager = firstNetworkProcess()->supplement<LegacyCustomProtocolManager>())
    5877        return customProtocolManager->supportsScheme([[[request URL] scheme] lowercaseString]);
    5978    return NO;
     
    7695        return nil;
    7796
    78     if (auto* customProtocolManager = NetworkProcess::singleton().supplement<LegacyCustomProtocolManager>())
     97    if (auto* customProtocolManager = firstNetworkProcess()->supplement<LegacyCustomProtocolManager>())
    7998        _customProtocolID = customProtocolManager->addCustomProtocol(self);
    8099    _initializationRunLoop = CFRunLoopGetCurrent();
     
    90109- (void)startLoading
    91110{
    92     if (auto* customProtocolManager = NetworkProcess::singleton().supplement<LegacyCustomProtocolManager>())
     111    if (auto* customProtocolManager = firstNetworkProcess()->supplement<LegacyCustomProtocolManager>())
    93112        customProtocolManager->startLoading(self.customProtocolID, [self request]);
    94113}
     
    96115- (void)stopLoading
    97116{
    98     if (auto* customProtocolManager = NetworkProcess::singleton().supplement<LegacyCustomProtocolManager>()) {
     117    if (auto* customProtocolManager = firstNetworkProcess()->supplement<LegacyCustomProtocolManager>()) {
    99118        customProtocolManager->stopLoading(self.customProtocolID);
    100119        customProtocolManager->removeCustomProtocol(self.customProtocolID);
  • trunk/Source/WebKit/NetworkProcess/CustomProtocols/LegacyCustomProtocolManager.cpp

    r221743 r240030  
    2828#include "LegacyCustomProtocolManager.h"
    2929
    30 #include "ChildProcess.h"
    3130#include "LegacyCustomProtocolManagerMessages.h"
    3231#include "LegacyCustomProtocolManagerProxyMessages.h"
     32#include "NetworkProcess.h"
    3333#include "NetworkProcessCreationParameters.h"
    3434#include "WebCoreArgumentCoders.h"
     
    4848}
    4949
    50 LegacyCustomProtocolManager::LegacyCustomProtocolManager(ChildProcess& childProcess)
    51     : m_childProcess(childProcess)
     50LegacyCustomProtocolManager::LegacyCustomProtocolManager(NetworkProcess& networkProcess)
     51    : m_networkProcess(networkProcess)
    5252{
    53     m_childProcess.addMessageReceiver(Messages::LegacyCustomProtocolManager::messageReceiverName(), *this);
     53    m_networkProcess.addMessageReceiver(Messages::LegacyCustomProtocolManager::messageReceiverName(), *this);
    5454}
    5555
     
    7878void LegacyCustomProtocolManager::startLoading(uint64_t customProtocolID, const WebCore::ResourceRequest& request)
    7979{
    80     m_childProcess.send(Messages::LegacyCustomProtocolManagerProxy::StartLoading(customProtocolID, request));
     80    m_networkProcess.send(Messages::LegacyCustomProtocolManagerProxy::StartLoading(customProtocolID, request));
    8181}
    8282
    8383void LegacyCustomProtocolManager::stopLoading(uint64_t customProtocolID)
    8484{
    85     m_childProcess.send(Messages::LegacyCustomProtocolManagerProxy::StopLoading(customProtocolID), 0);
     85    m_networkProcess.send(Messages::LegacyCustomProtocolManagerProxy::StopLoading(customProtocolID), 0);
    8686}
    8787
  • trunk/Source/WebKit/NetworkProcess/CustomProtocols/LegacyCustomProtocolManager.h

    r227364 r240030  
    6060namespace WebKit {
    6161
    62 class ChildProcess;
     62class NetworkProcess;
    6363struct NetworkProcessCreationParameters;
    6464
     
    6666    WTF_MAKE_NONCOPYABLE(LegacyCustomProtocolManager);
    6767public:
    68     explicit LegacyCustomProtocolManager(ChildProcess&);
     68    explicit LegacyCustomProtocolManager(NetworkProcess&);
    6969
    7070    static const char* supplementName();
     
    9797#if PLATFORM(COCOA)
    9898    void registerProtocolClass(NSURLSessionConfiguration*);
     99    static void networkProcessCreated(NetworkProcess&);
    99100#endif
    100101
     
    114115    void registerProtocolClass();
    115116
    116     ChildProcess& m_childProcess;
     117    NetworkProcess& m_networkProcess;
    117118
    118119    typedef HashMap<uint64_t, CustomProtocol> CustomProtocolMap;
  • trunk/Source/WebKit/NetworkProcess/NetworkProcess.cpp

    r239817 r240030  
    143143#if ENABLE(LEGACY_CUSTOM_PROTOCOL_MANAGER)
    144144    addSupplement<LegacyCustomProtocolManager>();
     145#if PLATFORM(COCOA)
     146    LegacyCustomProtocolManager::networkProcessCreated(*this);
     147#endif
    145148#endif
    146149#if ENABLE(PROXIMITY_NETWORKING)
Note: See TracChangeset for help on using the changeset viewer.