Title: [138426] trunk/Source/WebKit2
Revision
138426
Author
[email protected]
Date
2012-12-23 13:03:15 -0800 (Sun, 23 Dec 2012)

Log Message

Make CustomProtocolManager a MessageReceiver to remove more special casing
https://bugs.webkit.org/show_bug.cgi?id=105682

Reviewed by Dan Bernstein.

To avoid storing a Connection in CustomProtocolManager, which is not a great idea without
it being the Connection::Client and therefore getting death notifications, I also made
ChildProcess a MessageSender so that extensions to it, like CustomProtocolManager, can
easily send messages to the parent process.

* NetworkProcess/NetworkProcess.cpp:
(WebKit::NetworkProcess::NetworkProcess):
Initialize the shared CustomProtocolManager, which will add it to the MessageReceiverMap in
the ChildProcess.

(WebKit::NetworkProcess::didReceiveMessage):
Remove the special case for CustomProtocolManager.

(WebKit::NetworkProcess::initializeNetworkProcess):
Call connectionEstablished on the CustomProtocolManager to make it start working as a NSURLProtocol handler.

* NetworkProcess/NetworkProcess.h:
Add overrides necessary for MessageSender.

* PluginProcess/PluginProcess.h:
Ditto.

* Shared/ChildProcess.h:
(ChildProcess):
Make ChildProcess a MessageSender.

* Shared/Network/CustomProtocols/CustomProtocolManager.h:
(CustomProtocolManager):
(WebKit::CustomProtocolManager::childProcess):
* Shared/Network/CustomProtocols/mac/CustomProtocolManagerMac.mm:
(-[WKCustomProtocol startLoading]):
(-[WKCustomProtocol stopLoading]):
(WebKit::CustomProtocolManager::CustomProtocolManager):
(WebKit::CustomProtocolManager::initialize):
(WebKit::CustomProtocolManager::connectionEstablished):
Make CustomProtocolManager a MessageReceiver and split initialization and the time when it can
start acting as protocol handler as these happen at different times now. It also now stores a
ChildProcess rather than a Connection.

* SharedWorkerProcess/SharedWorkerProcess.h:
Add overrides necessary for MessageSender.

* WebProcess/WebProcess.cpp:
(WebKit::WebProcess::WebProcess):
Initialize the shared CustomProtocolManager, which will add it to the MessageReceiverMap in
the ChildProcess.

(WebKit::WebProcess::didReceiveMessage):
Remove the special case for CustomProtocolManager.

(WebKit::WebProcess::initializeCustomProtocolManager):
Call connectionEstablished on the CustomProtocolManager to make it start working as a NSURLProtocol handler.

* WebProcess/WebProcess.h:
Add overrides necessary for MessageSender.

Modified Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (138425 => 138426)


--- trunk/Source/WebKit2/ChangeLog	2012-12-23 20:22:16 UTC (rev 138425)
+++ trunk/Source/WebKit2/ChangeLog	2012-12-23 21:03:15 UTC (rev 138426)
@@ -1,3 +1,66 @@
+2012-12-22  Sam Weinig  <[email protected]>
+
+        Make CustomProtocolManager a MessageReceiver to remove more special casing
+        https://bugs.webkit.org/show_bug.cgi?id=105682
+
+        Reviewed by Dan Bernstein.
+
+        To avoid storing a Connection in CustomProtocolManager, which is not a great idea without
+        it being the Connection::Client and therefore getting death notifications, I also made
+        ChildProcess a MessageSender so that extensions to it, like CustomProtocolManager, can
+        easily send messages to the parent process.
+
+        * NetworkProcess/NetworkProcess.cpp:
+        (WebKit::NetworkProcess::NetworkProcess):
+        Initialize the shared CustomProtocolManager, which will add it to the MessageReceiverMap in 
+        the ChildProcess.
+
+        (WebKit::NetworkProcess::didReceiveMessage):
+        Remove the special case for CustomProtocolManager.
+
+        (WebKit::NetworkProcess::initializeNetworkProcess):
+        Call connectionEstablished on the CustomProtocolManager to make it start working as a NSURLProtocol handler.
+
+        * NetworkProcess/NetworkProcess.h:
+        Add overrides necessary for MessageSender.
+
+        * PluginProcess/PluginProcess.h:
+        Ditto.
+
+        * Shared/ChildProcess.h:
+        (ChildProcess):
+        Make ChildProcess a MessageSender.
+
+        * Shared/Network/CustomProtocols/CustomProtocolManager.h:
+        (CustomProtocolManager):
+        (WebKit::CustomProtocolManager::childProcess):
+        * Shared/Network/CustomProtocols/mac/CustomProtocolManagerMac.mm:
+        (-[WKCustomProtocol startLoading]):
+        (-[WKCustomProtocol stopLoading]):
+        (WebKit::CustomProtocolManager::CustomProtocolManager):
+        (WebKit::CustomProtocolManager::initialize):
+        (WebKit::CustomProtocolManager::connectionEstablished):
+        Make CustomProtocolManager a MessageReceiver and split initialization and the time when it can 
+        start acting as protocol handler as these happen at different times now. It also now stores a
+        ChildProcess rather than a Connection.
+
+        * SharedWorkerProcess/SharedWorkerProcess.h:
+        Add overrides necessary for MessageSender.
+
+        * WebProcess/WebProcess.cpp:
+        (WebKit::WebProcess::WebProcess):
+        Initialize the shared CustomProtocolManager, which will add it to the MessageReceiverMap in 
+        the ChildProcess.
+
+        (WebKit::WebProcess::didReceiveMessage):
+        Remove the special case for CustomProtocolManager.
+
+        (WebKit::WebProcess::initializeCustomProtocolManager):
+        Call connectionEstablished on the CustomProtocolManager to make it start working as a NSURLProtocol handler.
+
+        * WebProcess/WebProcess.h:
+        Add overrides necessary for MessageSender.
+
 2012-12-20  Martin Robinson  <[email protected]>
 
         [GTK] Remove plugin process configuration option

Modified: trunk/Source/WebKit2/NetworkProcess/NetworkProcess.cpp (138425 => 138426)


--- trunk/Source/WebKit2/NetworkProcess/NetworkProcess.cpp	2012-12-23 20:22:16 UTC (rev 138425)
+++ trunk/Source/WebKit2/NetworkProcess/NetworkProcess.cpp	2012-12-23 21:03:15 UTC (rev 138426)
@@ -56,6 +56,9 @@
     , m_cacheModel(CacheModelDocumentViewer)
     , m_downloadsAuthenticationManager(this)
 {
+#if ENABLE(CUSTOM_PROTOCOLS)
+    CustomProtocolManager::shared().initialize(this);
+#endif
 }
 
 NetworkProcess::~NetworkProcess()
@@ -98,13 +101,6 @@
     if (m_messageReceiverMap.dispatchMessage(connection, messageID, decoder))
         return;
 
-#if ENABLE(CUSTOM_PROTOCOLS)
-    if (messageID.is<CoreIPC::MessageClassCustomProtocolManager>()) {
-        CustomProtocolManager::shared().didReceiveMessage(connection, messageID, decoder);
-        return;
-    }
-#endif
-
     didReceiveNetworkProcessMessage(connection, messageID, decoder);
 }
 
@@ -163,7 +159,7 @@
         RemoteNetworkingContext::ensurePrivateBrowsingSession();
 
 #if ENABLE(CUSTOM_PROTOCOLS)
-    CustomProtocolManager::shared().initialize(m_uiConnection);
+    CustomProtocolManager::shared().connectionEstablished();
     for (size_t i = 0; i < parameters.urlSchemesRegisteredForCustomProtocols.size(); ++i)
         CustomProtocolManager::shared().registerScheme(parameters.urlSchemesRegisteredForCustomProtocols[i]);
 #endif

Modified: trunk/Source/WebKit2/NetworkProcess/NetworkProcess.h (138425 => 138426)


--- trunk/Source/WebKit2/NetworkProcess/NetworkProcess.h	2012-12-23 20:22:16 UTC (rev 138425)
+++ trunk/Source/WebKit2/NetworkProcess/NetworkProcess.h	2012-12-23 21:03:15 UTC (rev 138426)
@@ -45,7 +45,7 @@
 class NetworkConnectionToWebProcess;
 struct NetworkProcessCreationParameters;
 
-class NetworkProcess : ChildProcess, DownloadManager::Client {
+class NetworkProcess : public ChildProcess, DownloadManager::Client {
     WTF_MAKE_NONCOPYABLE(NetworkProcess);
 public:
     static NetworkProcess& shared();
@@ -66,6 +66,8 @@
 
     // ChildProcess
     virtual bool shouldTerminate() OVERRIDE;
+    virtual CoreIPC::Connection* connection() const OVERRIDE { return m_uiConnection.get(); }
+    virtual uint64_t destinationID() const OVERRIDE { return 0; }
 
     // CoreIPC::Connection::Client
     virtual void didReceiveMessage(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::MessageDecoder&) OVERRIDE;

Modified: trunk/Source/WebKit2/PluginProcess/PluginProcess.h (138425 => 138426)


--- trunk/Source/WebKit2/PluginProcess/PluginProcess.h	2012-12-23 20:22:16 UTC (rev 138425)
+++ trunk/Source/WebKit2/PluginProcess/PluginProcess.h	2012-12-23 21:03:15 UTC (rev 138426)
@@ -79,6 +79,8 @@
 
     // ChildProcess
     virtual bool shouldTerminate();
+    virtual CoreIPC::Connection* connection() const OVERRIDE { return m_connection.get(); }
+    virtual uint64_t destinationID() const OVERRIDE { return 0; }
 
     // CoreIPC::Connection::Client
     virtual void didReceiveMessage(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::MessageDecoder&) OVERRIDE;

Modified: trunk/Source/WebKit2/Shared/ChildProcess.h (138425 => 138426)


--- trunk/Source/WebKit2/Shared/ChildProcess.h	2012-12-23 20:22:16 UTC (rev 138425)
+++ trunk/Source/WebKit2/Shared/ChildProcess.h	2012-12-23 21:03:15 UTC (rev 138426)
@@ -28,6 +28,7 @@
 
 #include "Connection.h"
 #include "MessageReceiverMap.h"
+#include "MessageSender.h"
 #include <WebCore/RunLoop.h>
 #include <wtf/RetainPtr.h>
 
@@ -37,7 +38,7 @@
 
 namespace WebKit {
 
-class ChildProcess : protected CoreIPC::Connection::Client {
+class ChildProcess : protected CoreIPC::Connection::Client, public CoreIPC::MessageSender<ChildProcess> {
     WTF_MAKE_NONCOPYABLE(ChildProcess);
 
 public:
@@ -74,6 +75,10 @@
 
     static void didCloseOnConnectionWorkQueue(WorkQueue&, CoreIPC::Connection*);
 
+    // Used by CoreIPC::MessageSender
+    virtual CoreIPC::Connection* connection() const = 0;
+    virtual uint64_t destinationID() const = 0;
+
 protected:
     explicit ChildProcess();
     virtual ~ChildProcess();

Modified: trunk/Source/WebKit2/Shared/Network/CustomProtocols/CustomProtocolManager.h (138425 => 138426)


--- trunk/Source/WebKit2/Shared/Network/CustomProtocols/CustomProtocolManager.h	2012-12-23 20:22:16 UTC (rev 138425)
+++ trunk/Source/WebKit2/Shared/Network/CustomProtocols/CustomProtocolManager.h	2012-12-23 21:03:15 UTC (rev 138426)
@@ -29,7 +29,7 @@
 #if ENABLE(CUSTOM_PROTOCOLS)
 
 #include "Connection.h"
-#include "MessageID.h"
+#include "MessageReceiver.h"
 #include <wtf/HashSet.h>
 #include <wtf/text/WTFString.h>
 
@@ -42,7 +42,6 @@
 
 namespace CoreIPC {
 class DataReference;
-class MessageDecoder;
 } // namespace CoreIPC
 
 namespace WebCore {
@@ -52,29 +51,22 @@
 
 namespace WebKit {
 
-class CustomProtocolManager {
+class ChildProcess;
+
+class CustomProtocolManager : private CoreIPC::MessageReceiver {
     WTF_MAKE_NONCOPYABLE(CustomProtocolManager);
 
 public:
     static CustomProtocolManager& shared();
     
-    void initialize(PassRefPtr<CoreIPC::Connection>);
+    void initialize(ChildProcess*);
+    void connectionEstablished();
 
-    CoreIPC::Connection* connection() const
-    {
-        ASSERT(m_connection);
-        return m_connection.get();
-    }
+    ChildProcess* childProcess() const { return m_childProcess; }
 
     void registerScheme(const String&);
     void unregisterScheme(const String&);
     bool supportsScheme(const String&);
-
-    void didReceiveMessage(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::MessageDecoder&);
-    void didFailWithError(uint64_t customProtocolID, const WebCore::ResourceError&);
-    void didLoadData(uint64_t customProtocolID, const CoreIPC::DataReference&);
-    void didReceiveResponse(uint64_t customProtocolID, const WebCore::ResourceResponse&, uint32_t cacheStoragePolicy);
-    void didFinishLoading(uint64_t customProtocolID);
     
 #if PLATFORM(MAC)
     void addCustomProtocol(WKCustomProtocol *);
@@ -82,11 +74,19 @@
 #endif
 
 private:
-    CustomProtocolManager() { }
+    CustomProtocolManager();
+
+    // CoreIPC::MessageReceiver
+    virtual void didReceiveMessage(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::MessageDecoder&) OVERRIDE;
     void didReceiveCustomProtocolManagerMessage(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::MessageDecoder&);
-    
+
+    void didFailWithError(uint64_t customProtocolID, const WebCore::ResourceError&);
+    void didLoadData(uint64_t customProtocolID, const CoreIPC::DataReference&);
+    void didReceiveResponse(uint64_t customProtocolID, const WebCore::ResourceResponse&, uint32_t cacheStoragePolicy);
+    void didFinishLoading(uint64_t customProtocolID);
+
     HashSet<String> m_registeredSchemes;
-    RefPtr<CoreIPC::Connection> m_connection;
+    ChildProcess* m_childProcess;
 
 #if PLATFORM(MAC)
     typedef HashMap<uint64_t, RetainPtr<WKCustomProtocol> > CustomProtocolMap;

Modified: trunk/Source/WebKit2/Shared/Network/CustomProtocols/mac/CustomProtocolManagerMac.mm (138425 => 138426)


--- trunk/Source/WebKit2/Shared/Network/CustomProtocols/mac/CustomProtocolManagerMac.mm	2012-12-23 20:22:16 UTC (rev 138425)
+++ trunk/Source/WebKit2/Shared/Network/CustomProtocols/mac/CustomProtocolManagerMac.mm	2012-12-23 21:03:15 UTC (rev 138426)
@@ -28,6 +28,7 @@
 
 #if ENABLE(CUSTOM_PROTOCOLS)
 
+#import "CustomProtocolManagerMessages.h"
 #import "CustomProtocolManagerProxyMessages.h"
 #import "DataReference.h"
 #import "WebCoreArgumentCoders.h"
@@ -82,12 +83,12 @@
 
 - (void)startLoading
 {
-    CustomProtocolManager::shared().connection()->send(Messages::CustomProtocolManagerProxy::StartLoading(self.customProtocolID, [self request]), 0);
+    CustomProtocolManager::shared().childProcess()->send(Messages::CustomProtocolManagerProxy::StartLoading(self.customProtocolID, [self request]), 0);
 }
 
 - (void)stopLoading
 {
-    CustomProtocolManager::shared().connection()->send(Messages::CustomProtocolManagerProxy::StopLoading(self.customProtocolID), 0);
+    CustomProtocolManager::shared().childProcess()->send(Messages::CustomProtocolManagerProxy::StopLoading(self.customProtocolID), 0);
     CustomProtocolManager::shared().removeCustomProtocol(self);
 }
 
@@ -101,11 +102,22 @@
     return customProtocolManager;
 }
 
-void CustomProtocolManager::initialize(PassRefPtr<CoreIPC::Connection> connection)
+CustomProtocolManager::CustomProtocolManager()
+    : m_childProcess(0)
 {
-    ASSERT(connection);
-    ASSERT(!CustomProtocolManager::shared().m_connection);
-    CustomProtocolManager::shared().m_connection = connection;
+}
+
+void CustomProtocolManager::initialize(ChildProcess* childProcess)
+{
+    ASSERT(!m_childProcess);
+    ASSERT(childProcess);
+
+    m_childProcess = childProcess;
+    m_childProcess->addMessageReceiver(Messages::CustomProtocolManager::messageReceiverName(), this);
+}
+
+void CustomProtocolManager::connectionEstablished()
+{
     [NSURLProtocol registerClass:[WKCustomProtocol class]];
 }
 

Modified: trunk/Source/WebKit2/SharedWorkerProcess/SharedWorkerProcess.h (138425 => 138426)


--- trunk/Source/WebKit2/SharedWorkerProcess/SharedWorkerProcess.h	2012-12-23 20:22:16 UTC (rev 138425)
+++ trunk/Source/WebKit2/SharedWorkerProcess/SharedWorkerProcess.h	2012-12-23 21:03:15 UTC (rev 138426)
@@ -55,6 +55,8 @@
 
     // ChildProcess
     virtual bool shouldTerminate();
+    virtual CoreIPC::Connection* connection() const OVERRIDE { return m_connection.get(); }
+    virtual uint64_t destinationID() const OVERRIDE { return 0; }
 
     // CoreIPC::Connection::Client
     virtual void didReceiveMessage(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::MessageDecoder&);

Modified: trunk/Source/WebKit2/WebProcess/WebProcess.cpp (138425 => 138426)


--- trunk/Source/WebKit2/WebProcess/WebProcess.cpp	2012-12-23 20:22:16 UTC (rev 138425)
+++ trunk/Source/WebKit2/WebProcess/WebProcess.cpp	2012-12-23 21:03:15 UTC (rev 138426)
@@ -160,6 +160,10 @@
     WebCore::initializeLoggingChannelsIfNecessary();
     WebKit::initializeLogChannelsIfNecessary();
 #endif // !LOG_DISABLED
+
+#if ENABLE(CUSTOM_PROTOCOLS)
+    CustomProtocolManager::shared().initialize(this);
+#endif
 }
 
 void WebProcess::initialize(CoreIPC::Connection::Identifier serverIdentifier, RunLoop* runLoop)
@@ -602,13 +606,6 @@
         WebResourceCacheManager::shared().didReceiveMessage(connection, messageID, decoder);
         return;
     }
-    
-#if ENABLE(CUSTOM_PROTOCOLS)
-    if (messageID.is<CoreIPC::MessageClassCustomProtocolManager>()) {
-        CustomProtocolManager::shared().didReceiveMessage(connection, messageID, decoder);
-        return;
-    }
-#endif
 
     if (messageID.is<CoreIPC::MessageClassWebPageGroupProxy>()) {
         uint64_t pageGroupID = decoder.destinationID();
@@ -1078,7 +1075,7 @@
         return;
 #endif
 
-    CustomProtocolManager::shared().initialize(m_connection);
+    CustomProtocolManager::shared().connectionEstablished();
     for (size_t i = 0; i < parameters.urlSchemesRegisteredForCustomProtocols.size(); ++i)
         CustomProtocolManager::shared().registerScheme(parameters.urlSchemesRegisteredForCustomProtocols[i]);
 }

Modified: trunk/Source/WebKit2/WebProcess/WebProcess.h (138425 => 138426)


--- trunk/Source/WebKit2/WebProcess/WebProcess.h	2012-12-23 20:22:16 UTC (rev 138425)
+++ trunk/Source/WebKit2/WebProcess/WebProcess.h	2012-12-23 21:03:15 UTC (rev 138426)
@@ -116,7 +116,9 @@
 
     void initialize(CoreIPC::Connection::Identifier, WebCore::RunLoop*);
 
-    CoreIPC::Connection* connection() const { return m_connection.get(); }
+    virtual CoreIPC::Connection* connection() const OVERRIDE { return m_connection.get(); }
+    virtual uint64_t destinationID() const OVERRIDE { return 0; }
+
     WebCore::RunLoop* runLoop() const { return m_runLoop; }
     WebConnectionToUIProcess* webConnectionToUIProcess() const { return m_webConnection.get(); }
 
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to