Title: [240030] trunk/Source/WebKit
Revision
240030
Author
[email protected]
Date
2019-01-15 20:57:54 -0800 (Tue, 15 Jan 2019)

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

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (240029 => 240030)


--- trunk/Source/WebKit/ChangeLog	2019-01-16 04:27:04 UTC (rev 240029)
+++ trunk/Source/WebKit/ChangeLog	2019-01-16 04:57:54 UTC (rev 240030)
@@ -1,5 +1,33 @@
 2019-01-15  Alex Christensen  <[email protected]>
 
+        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):
+
+2019-01-15  Alex Christensen  <[email protected]>
+
         Fix WinCairo build after r240014
         https://bugs.webkit.org/show_bug.cgi?id=161106
 

Modified: trunk/Source/WebKit/NetworkProcess/CustomProtocols/Cocoa/LegacyCustomProtocolManagerCocoa.mm (240029 => 240030)


--- trunk/Source/WebKit/NetworkProcess/CustomProtocols/Cocoa/LegacyCustomProtocolManagerCocoa.mm	2019-01-16 04:27:04 UTC (rev 240029)
+++ trunk/Source/WebKit/NetworkProcess/CustomProtocols/Cocoa/LegacyCustomProtocolManagerCocoa.mm	2019-01-16 04:57:54 UTC (rev 240030)
@@ -39,6 +39,25 @@
 
 using namespace WebKit;
 
+static RefPtr<NetworkProcess>& firstNetworkProcess()
+{
+    static NeverDestroyed<RefPtr<NetworkProcess>> networkProcess;
+    return networkProcess.get();
+}
+
+void LegacyCustomProtocolManager::networkProcessCreated(NetworkProcess& networkProcess)
+{
+    auto hasRegisteredSchemes = [] (auto* legacyCustomProtocolManager) {
+        if (!legacyCustomProtocolManager)
+            return false;
+        LockHolder locker(legacyCustomProtocolManager->m_registeredSchemesMutex);
+        return !legacyCustomProtocolManager->m_registeredSchemes.isEmpty();
+    };
+
+    RELEASE_ASSERT(!firstNetworkProcess() || !hasRegisteredSchemes(firstNetworkProcess()->supplement<LegacyCustomProtocolManager>()));
+    firstNetworkProcess() = &networkProcess;
+}
+
 @interface WKCustomProtocol : NSURLProtocol {
 @private
     uint64_t _customProtocolID;
@@ -54,7 +73,7 @@
 
 + (BOOL)canInitWithRequest:(NSURLRequest *)request
 {
-    if (auto* customProtocolManager = NetworkProcess::singleton().supplement<LegacyCustomProtocolManager>())
+    if (auto* customProtocolManager = firstNetworkProcess()->supplement<LegacyCustomProtocolManager>())
         return customProtocolManager->supportsScheme([[[request URL] scheme] lowercaseString]);
     return NO;
 }
@@ -75,7 +94,7 @@
     if (!self)
         return nil;
 
-    if (auto* customProtocolManager = NetworkProcess::singleton().supplement<LegacyCustomProtocolManager>())
+    if (auto* customProtocolManager = firstNetworkProcess()->supplement<LegacyCustomProtocolManager>())
         _customProtocolID = customProtocolManager->addCustomProtocol(self);
     _initializationRunLoop = CFRunLoopGetCurrent();
 
@@ -89,13 +108,13 @@
 
 - (void)startLoading
 {
-    if (auto* customProtocolManager = NetworkProcess::singleton().supplement<LegacyCustomProtocolManager>())
+    if (auto* customProtocolManager = firstNetworkProcess()->supplement<LegacyCustomProtocolManager>())
         customProtocolManager->startLoading(self.customProtocolID, [self request]);
 }
 
 - (void)stopLoading
 {
-    if (auto* customProtocolManager = NetworkProcess::singleton().supplement<LegacyCustomProtocolManager>()) {
+    if (auto* customProtocolManager = firstNetworkProcess()->supplement<LegacyCustomProtocolManager>()) {
         customProtocolManager->stopLoading(self.customProtocolID);
         customProtocolManager->removeCustomProtocol(self.customProtocolID);
     }

Modified: trunk/Source/WebKit/NetworkProcess/CustomProtocols/LegacyCustomProtocolManager.cpp (240029 => 240030)


--- trunk/Source/WebKit/NetworkProcess/CustomProtocols/LegacyCustomProtocolManager.cpp	2019-01-16 04:27:04 UTC (rev 240029)
+++ trunk/Source/WebKit/NetworkProcess/CustomProtocols/LegacyCustomProtocolManager.cpp	2019-01-16 04:57:54 UTC (rev 240030)
@@ -27,9 +27,9 @@
 #include "config.h"
 #include "LegacyCustomProtocolManager.h"
 
-#include "ChildProcess.h"
 #include "LegacyCustomProtocolManagerMessages.h"
 #include "LegacyCustomProtocolManagerProxyMessages.h"
+#include "NetworkProcess.h"
 #include "NetworkProcessCreationParameters.h"
 #include "WebCoreArgumentCoders.h"
 #include <WebCore/ResourceRequest.h>
@@ -47,10 +47,10 @@
     return "LegacyCustomProtocolManager";
 }
 
-LegacyCustomProtocolManager::LegacyCustomProtocolManager(ChildProcess& childProcess)
-    : m_childProcess(childProcess)
+LegacyCustomProtocolManager::LegacyCustomProtocolManager(NetworkProcess& networkProcess)
+    : m_networkProcess(networkProcess)
 {
-    m_childProcess.addMessageReceiver(Messages::LegacyCustomProtocolManager::messageReceiverName(), *this);
+    m_networkProcess.addMessageReceiver(Messages::LegacyCustomProtocolManager::messageReceiverName(), *this);
 }
 
 void LegacyCustomProtocolManager::initialize(const NetworkProcessCreationParameters& parameters)
@@ -77,12 +77,12 @@
 
 void LegacyCustomProtocolManager::startLoading(uint64_t customProtocolID, const WebCore::ResourceRequest& request)
 {
-    m_childProcess.send(Messages::LegacyCustomProtocolManagerProxy::StartLoading(customProtocolID, request));
+    m_networkProcess.send(Messages::LegacyCustomProtocolManagerProxy::StartLoading(customProtocolID, request));
 }
 
 void LegacyCustomProtocolManager::stopLoading(uint64_t customProtocolID)
 {
-    m_childProcess.send(Messages::LegacyCustomProtocolManagerProxy::StopLoading(customProtocolID), 0);
+    m_networkProcess.send(Messages::LegacyCustomProtocolManagerProxy::StopLoading(customProtocolID), 0);
 }
 
 } // namespace WebKit

Modified: trunk/Source/WebKit/NetworkProcess/CustomProtocols/LegacyCustomProtocolManager.h (240029 => 240030)


--- trunk/Source/WebKit/NetworkProcess/CustomProtocols/LegacyCustomProtocolManager.h	2019-01-16 04:27:04 UTC (rev 240029)
+++ trunk/Source/WebKit/NetworkProcess/CustomProtocols/LegacyCustomProtocolManager.h	2019-01-16 04:57:54 UTC (rev 240030)
@@ -59,13 +59,13 @@
 
 namespace WebKit {
 
-class ChildProcess;
+class NetworkProcess;
 struct NetworkProcessCreationParameters;
 
 class LegacyCustomProtocolManager : public NetworkProcessSupplement, public IPC::MessageReceiver {
     WTF_MAKE_NONCOPYABLE(LegacyCustomProtocolManager);
 public:
-    explicit LegacyCustomProtocolManager(ChildProcess&);
+    explicit LegacyCustomProtocolManager(NetworkProcess&);
 
     static const char* supplementName();
 
@@ -96,6 +96,7 @@
 
 #if PLATFORM(COCOA)
     void registerProtocolClass(NSURLSessionConfiguration*);
+    static void networkProcessCreated(NetworkProcess&);
 #endif
 
 private:
@@ -113,7 +114,7 @@
 
     void registerProtocolClass();
 
-    ChildProcess& m_childProcess;
+    NetworkProcess& m_networkProcess;
 
     typedef HashMap<uint64_t, CustomProtocol> CustomProtocolMap;
     CustomProtocolMap m_customProtocolMap;

Modified: trunk/Source/WebKit/NetworkProcess/NetworkProcess.cpp (240029 => 240030)


--- trunk/Source/WebKit/NetworkProcess/NetworkProcess.cpp	2019-01-16 04:27:04 UTC (rev 240029)
+++ trunk/Source/WebKit/NetworkProcess/NetworkProcess.cpp	2019-01-16 04:57:54 UTC (rev 240030)
@@ -142,7 +142,10 @@
     addSupplement<WebCookieManager>();
 #if ENABLE(LEGACY_CUSTOM_PROTOCOL_MANAGER)
     addSupplement<LegacyCustomProtocolManager>();
+#if PLATFORM(COCOA)
+    LegacyCustomProtocolManager::networkProcessCreated(*this);
 #endif
+#endif
 #if ENABLE(PROXIMITY_NETWORKING)
     addSupplement<NetworkProximityManager>();
 #endif
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to