Add infrastructure for NetworkProcess management
authorbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 19 Oct 2012 23:26:16 +0000 (23:26 +0000)
committerbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 19 Oct 2012 23:26:16 +0000 (23:26 +0000)
https://bugs.webkit.org/show_bug.cgi?id=99817

Reviewed by Alexey Proskuryakov.

Add support for the WebProcess itself requesting a connection to the default NetworkProcess.

Add proper handling of crashes so any of the Web/Network/UI processes crash the others take appropriate action.

Project file stuff and general messaging changes:
* DerivedSources.make:
* Platform/CoreIPC/MessageID.h:
* WebKit2.xcodeproj/project.pbxproj:
* Platform/CoreIPC/HandleMessage.h:
(CoreIPC):
(CoreIPC::callMemberFunction): Add some new required templates.

WebContext now does much less of this stuff:
* UIProcess/WebContext.cpp:
(WebKit::WebContext::createNewWebProcess):
* UIProcess/WebContext.h:
(WebContext):

UIProcess now has a process manager to handle most of this:
* UIProcess/Network/NetworkProcessManager.cpp:
(WebKit):
(WebKit::NetworkProcessManager::shared):
(WebKit::NetworkProcessManager::NetworkProcessManager):
(WebKit::NetworkProcessManager::getNetworkProcessConnection):
(WebKit::NetworkProcessManager::ensureNetworkProcess):
(WebKit::NetworkProcessManager::removeNetworkProcessProxy):
* UIProcess/Network/NetworkProcessManager.h:
(WebKit):
(NetworkProcessManager):

Flesh out the NetworkProcessProxy to handle creating these connections between Network and Web Processes:
* UIProcess/Network/NetworkProcessProxy.cpp:
(WebKit::NetworkProcessProxy::create):
(WebKit::NetworkProcessProxy::NetworkProcessProxy):
(WebKit::NetworkProcessProxy::getNetworkProcessConnection):
(WebKit):
(WebKit::NetworkProcessProxy::networkProcessCrashedOrFailedToLaunch):
(WebKit::NetworkProcessProxy::didReceiveMessage):
(WebKit::NetworkProcessProxy::didClose):
(WebKit::NetworkProcessProxy::didCreateNetworkConnectionToWebProcess):
(WebKit::NetworkProcessProxy::didFinishLaunching):
* UIProcess/Network/NetworkProcessProxy.h:
(WebKit):
(NetworkProcessProxy):
* UIProcess/Network/NetworkProcessProxy.messages.in:

Add a class representing a connection from a NetworkProcess to a particular WebProcess:
* NetworkProcess/NetworkConnectionToWebProcess.cpp: Added.
(WebKit):
(WebKit::NetworkConnectionToWebProcess::create):
(WebKit::NetworkConnectionToWebProcess::NetworkConnectionToWebProcess):
(WebKit::NetworkConnectionToWebProcess::~NetworkConnectionToWebProcess):
(WebKit::NetworkConnectionToWebProcess::didReceiveMessage):
(WebKit::NetworkConnectionToWebProcess::didReceiveSyncMessage):
(WebKit::NetworkConnectionToWebProcess::didClose):
(WebKit::NetworkConnectionToWebProcess::didReceiveInvalidMessage):
(WebKit::NetworkConnectionToWebProcess::didReceiveNetworkConnectionToWebProcessMessage):
* NetworkProcess/NetworkConnectionToWebProcess.h:
(WebKit):
(NetworkConnectionToWebProcess):
(WebKit::NetworkConnectionToWebProcess::connection):
* NetworkProcess/NetworkConnectionToWebProcess.messages.in:

Add the ability for a NetworkProcess to create a connection for a different process, which is used on behalf of WebProcesses for now:
* NetworkProcess/NetworkProcess.cpp:
(WebKit::NetworkProcess::removeNetworkConnectionToWebProcess):
(WebKit):
(WebKit::NetworkProcess::didClose):
(WebKit::NetworkProcess::createNetworkConnectionToWebProcess):
* NetworkProcess/NetworkProcess.h:
(WebKit):
(NetworkProcess):
* NetworkProcess/NetworkProcess.messages.in:

Forward on the message that a WebProcess wants a connection to a NetworkProcess:
* UIProcess/WebProcessProxy.cpp:
(WebKit):
(WebKit::WebProcessProxy::getNetworkProcessConnection):
* UIProcess/WebProcessProxy.h:
(WebProcessProxy):
* UIProcess/WebProcessProxy.messages.in:

Add a class representing the WebProcesses connection to the NetworkProcess:
* WebProcess/Network/NetworkProcessConnection.cpp:
(WebKit):
(WebKit::NetworkProcessConnection::NetworkProcessConnection):
(WebKit::NetworkProcessConnection::~NetworkProcessConnection):
(WebKit::NetworkProcessConnection::didReceiveMessage):
(WebKit::NetworkProcessConnection::didReceiveSyncMessage):
(WebKit::NetworkProcessConnection::didClose):
(WebKit::NetworkProcessConnection::didReceiveInvalidMessage):
* WebProcess/Network/NetworkProcessConnection.h:
(WebKit):
(NetworkProcessConnection):
(WebKit::NetworkProcessConnection::create):
(WebKit::NetworkProcessConnection::connection):

Have the WebProcess make sure it has a connection to the NetworkProcess, even though it currently does nothing with it:
* WebProcess/WebProcess.cpp:
(WebKit::WebProcess::initializeWebProcess):
(WebKit):
(WebKit::WebProcess::ensureNetworkProcessConnection):
(WebKit::WebProcess::networkProcessConnectionClosed):
(WebKit::WebProcess::networkProcessCrashed):
* WebProcess/WebProcess.h:
(WebKit):
(WebProcess):
* WebProcess/WebProcess.messages.in:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@131958 268f45cc-cd09-0410-ab3c-d52691b4dbfc

26 files changed:
Source/WebKit2/ChangeLog
Source/WebKit2/DerivedSources.make
Source/WebKit2/NetworkProcess/NetworkConnectionToWebProcess.cpp [new file with mode: 0644]
Source/WebKit2/NetworkProcess/NetworkConnectionToWebProcess.h [new file with mode: 0644]
Source/WebKit2/NetworkProcess/NetworkConnectionToWebProcess.messages.in [new file with mode: 0644]
Source/WebKit2/NetworkProcess/NetworkProcess.cpp
Source/WebKit2/NetworkProcess/NetworkProcess.h
Source/WebKit2/NetworkProcess/NetworkProcess.messages.in
Source/WebKit2/Platform/CoreIPC/HandleMessage.h
Source/WebKit2/Platform/CoreIPC/MessageID.h
Source/WebKit2/UIProcess/Network/NetworkProcessManager.cpp [new file with mode: 0644]
Source/WebKit2/UIProcess/Network/NetworkProcessManager.h [new file with mode: 0644]
Source/WebKit2/UIProcess/Network/NetworkProcessProxy.cpp
Source/WebKit2/UIProcess/Network/NetworkProcessProxy.h
Source/WebKit2/UIProcess/Network/NetworkProcessProxy.messages.in [new file with mode: 0644]
Source/WebKit2/UIProcess/WebContext.cpp
Source/WebKit2/UIProcess/WebContext.h
Source/WebKit2/UIProcess/WebProcessProxy.cpp
Source/WebKit2/UIProcess/WebProcessProxy.h
Source/WebKit2/UIProcess/WebProcessProxy.messages.in
Source/WebKit2/WebKit2.xcodeproj/project.pbxproj
Source/WebKit2/WebProcess/Network/NetworkProcessConnection.cpp [new file with mode: 0644]
Source/WebKit2/WebProcess/Network/NetworkProcessConnection.h [new file with mode: 0644]
Source/WebKit2/WebProcess/WebProcess.cpp
Source/WebKit2/WebProcess/WebProcess.h
Source/WebKit2/WebProcess/WebProcess.messages.in

index f6d7d6d..e52538c 100644 (file)
@@ -1,3 +1,119 @@
+2012-10-19  Brady Eidson  <beidson@apple.com>
+
+        Add infrastructure for NetworkProcess management
+        https://bugs.webkit.org/show_bug.cgi?id=99817
+
+        Reviewed by Alexey Proskuryakov.
+
+        Add support for the WebProcess itself requesting a connection to the default NetworkProcess.
+
+        Add proper handling of crashes so any of the Web/Network/UI processes crash the others take appropriate action.
+
+        Project file stuff and general messaging changes:
+        * DerivedSources.make:
+        * Platform/CoreIPC/MessageID.h:
+        * WebKit2.xcodeproj/project.pbxproj:
+        * Platform/CoreIPC/HandleMessage.h:
+        (CoreIPC):
+        (CoreIPC::callMemberFunction): Add some new required templates.
+
+        WebContext now does much less of this stuff:
+        * UIProcess/WebContext.cpp:
+        (WebKit::WebContext::createNewWebProcess):
+        * UIProcess/WebContext.h:
+        (WebContext):
+
+        UIProcess now has a process manager to handle most of this:
+        * UIProcess/Network/NetworkProcessManager.cpp:
+        (WebKit):
+        (WebKit::NetworkProcessManager::shared):
+        (WebKit::NetworkProcessManager::NetworkProcessManager):
+        (WebKit::NetworkProcessManager::getNetworkProcessConnection):
+        (WebKit::NetworkProcessManager::ensureNetworkProcess):
+        (WebKit::NetworkProcessManager::removeNetworkProcessProxy):
+        * UIProcess/Network/NetworkProcessManager.h:
+        (WebKit):
+        (NetworkProcessManager):
+
+        Flesh out the NetworkProcessProxy to handle creating these connections between Network and Web Processes:
+        * UIProcess/Network/NetworkProcessProxy.cpp:
+        (WebKit::NetworkProcessProxy::create):
+        (WebKit::NetworkProcessProxy::NetworkProcessProxy):
+        (WebKit::NetworkProcessProxy::getNetworkProcessConnection):
+        (WebKit):
+        (WebKit::NetworkProcessProxy::networkProcessCrashedOrFailedToLaunch):
+        (WebKit::NetworkProcessProxy::didReceiveMessage):
+        (WebKit::NetworkProcessProxy::didClose):
+        (WebKit::NetworkProcessProxy::didCreateNetworkConnectionToWebProcess):
+        (WebKit::NetworkProcessProxy::didFinishLaunching):
+        * UIProcess/Network/NetworkProcessProxy.h:
+        (WebKit):
+        (NetworkProcessProxy):
+        * UIProcess/Network/NetworkProcessProxy.messages.in:
+
+        Add a class representing a connection from a NetworkProcess to a particular WebProcess:
+        * NetworkProcess/NetworkConnectionToWebProcess.cpp: Added.
+        (WebKit):
+        (WebKit::NetworkConnectionToWebProcess::create):
+        (WebKit::NetworkConnectionToWebProcess::NetworkConnectionToWebProcess):
+        (WebKit::NetworkConnectionToWebProcess::~NetworkConnectionToWebProcess):
+        (WebKit::NetworkConnectionToWebProcess::didReceiveMessage):
+        (WebKit::NetworkConnectionToWebProcess::didReceiveSyncMessage):
+        (WebKit::NetworkConnectionToWebProcess::didClose):
+        (WebKit::NetworkConnectionToWebProcess::didReceiveInvalidMessage):
+        (WebKit::NetworkConnectionToWebProcess::didReceiveNetworkConnectionToWebProcessMessage):
+        * NetworkProcess/NetworkConnectionToWebProcess.h:
+        (WebKit):
+        (NetworkConnectionToWebProcess):
+        (WebKit::NetworkConnectionToWebProcess::connection):
+        * NetworkProcess/NetworkConnectionToWebProcess.messages.in:
+
+        Add the ability for a NetworkProcess to create a connection for a different process, which is used on behalf of WebProcesses for now:
+        * NetworkProcess/NetworkProcess.cpp:
+        (WebKit::NetworkProcess::removeNetworkConnectionToWebProcess):
+        (WebKit):
+        (WebKit::NetworkProcess::didClose):
+        (WebKit::NetworkProcess::createNetworkConnectionToWebProcess):
+        * NetworkProcess/NetworkProcess.h:
+        (WebKit):
+        (NetworkProcess):
+        * NetworkProcess/NetworkProcess.messages.in:
+
+        Forward on the message that a WebProcess wants a connection to a NetworkProcess:
+        * UIProcess/WebProcessProxy.cpp:
+        (WebKit):
+        (WebKit::WebProcessProxy::getNetworkProcessConnection):
+        * UIProcess/WebProcessProxy.h:
+        (WebProcessProxy):
+        * UIProcess/WebProcessProxy.messages.in:
+
+        Add a class representing the WebProcesses connection to the NetworkProcess:
+        * WebProcess/Network/NetworkProcessConnection.cpp:
+        (WebKit):
+        (WebKit::NetworkProcessConnection::NetworkProcessConnection):
+        (WebKit::NetworkProcessConnection::~NetworkProcessConnection):
+        (WebKit::NetworkProcessConnection::didReceiveMessage):
+        (WebKit::NetworkProcessConnection::didReceiveSyncMessage):
+        (WebKit::NetworkProcessConnection::didClose):
+        (WebKit::NetworkProcessConnection::didReceiveInvalidMessage):
+        * WebProcess/Network/NetworkProcessConnection.h:
+        (WebKit):
+        (NetworkProcessConnection):
+        (WebKit::NetworkProcessConnection::create):
+        (WebKit::NetworkProcessConnection::connection):
+
+        Have the WebProcess make sure it has a connection to the NetworkProcess, even though it currently does nothing with it:
+        * WebProcess/WebProcess.cpp:
+        (WebKit::WebProcess::initializeWebProcess):
+        (WebKit):
+        (WebKit::WebProcess::ensureNetworkProcessConnection):
+        (WebKit::WebProcess::networkProcessConnectionClosed):
+        (WebKit::WebProcess::networkProcessCrashed):
+        * WebProcess/WebProcess.h:
+        (WebKit):
+        (WebProcess):
+        * WebProcess/WebProcess.messages.in:
+
 2012-10-19  Tony Chang  <tony@chromium.org>
 
         Unreviewed, rolling out r131936.
index 9ab6db6..3597696 100644 (file)
@@ -44,6 +44,7 @@ VPATH = \
     $(WebKit2)/WebProcess \
     $(WebKit2)/UIProcess \
     $(WebKit2)/UIProcess/Downloads \
+    $(WebKit2)/UIProcess/Network \
     $(WebKit2)/UIProcess/Notifications \
     $(WebKit2)/UIProcess/Plugins \
     $(WebKit2)/UIProcess/SharedWorkers \
@@ -56,6 +57,7 @@ MESSAGE_RECEIVERS = \
     DownloadProxy \
     EventDispatcher \
     NetworkProcess \
+    NetworkProcessProxy \
     NPObjectMessageReceiver \
     PluginControllerProxy \
     PluginProcess \
@@ -69,6 +71,7 @@ MESSAGE_RECEIVERS = \
     WebCookieManager \
     WebCookieManagerProxy \
     WebConnection \
+    NetworkConnectionToWebProcess \
     WebContext \
     WebDatabaseManager \
     WebDatabaseManagerProxy \
diff --git a/Source/WebKit2/NetworkProcess/NetworkConnectionToWebProcess.cpp b/Source/WebKit2/NetworkProcess/NetworkConnectionToWebProcess.cpp
new file mode 100644 (file)
index 0000000..1fdce18
--- /dev/null
@@ -0,0 +1,94 @@
+/*
+ * Copyright (C) 2012 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "NetworkConnectionToWebProcess.h"
+
+#include "ConnectionStack.h"
+#include "NetworkProcess.h"
+#include <WebCore/RunLoop.h>
+
+#if ENABLE(NETWORK_PROCESS)
+
+using namespace WebCore;
+
+namespace WebKit {
+
+PassRefPtr<NetworkConnectionToWebProcess> NetworkConnectionToWebProcess::create(CoreIPC::Connection::Identifier connectionIdentifier)
+{
+    return adoptRef(new NetworkConnectionToWebProcess(connectionIdentifier));
+}
+
+NetworkConnectionToWebProcess::NetworkConnectionToWebProcess(CoreIPC::Connection::Identifier connectionIdentifier)
+{
+    m_connection = CoreIPC::Connection::createServerConnection(connectionIdentifier, this, RunLoop::main());
+    m_connection->setOnlySendMessagesAsDispatchWhenWaitingForSyncReplyWhenProcessingSuchAMessage(true);
+    m_connection->open();
+}
+
+NetworkConnectionToWebProcess::~NetworkConnectionToWebProcess()
+{
+    ASSERT(!m_connection);
+}
+
+void NetworkConnectionToWebProcess::didReceiveMessage(CoreIPC::Connection* connection, CoreIPC::MessageID messageID, CoreIPC::MessageDecoder& decoder)
+{
+    ConnectionStack::CurrentConnectionPusher currentConnection(ConnectionStack::shared(), connection);
+
+    if (messageID.is<CoreIPC::MessageClassNetworkConnectionToWebProcess>()) {
+        didReceiveNetworkConnectionToWebProcessMessage(connection, messageID, decoder);
+        return;
+    }
+
+    ASSERT_NOT_REACHED();
+}
+
+void NetworkConnectionToWebProcess::didReceiveSyncMessage(CoreIPC::Connection* connection, CoreIPC::MessageID messageID, CoreIPC::MessageDecoder& arguments, OwnPtr<CoreIPC::MessageEncoder>& reply)
+{
+    ASSERT_NOT_REACHED();
+}
+
+void NetworkConnectionToWebProcess::didClose(CoreIPC::Connection*)
+{
+    // Protect ourself as we might be otherwise be deleted during this function
+    RefPtr<NetworkConnectionToWebProcess> protector(this);
+    
+    NetworkProcess::shared().removeNetworkConnectionToWebProcess(this);
+    
+    m_connection = 0;
+}
+
+void NetworkConnectionToWebProcess::didReceiveInvalidMessage(CoreIPC::Connection*, CoreIPC::MessageID)
+{
+}
+
+void NetworkConnectionToWebProcess::didReceiveNetworkConnectionToWebProcessMessage(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::MessageDecoder&)
+{
+    // Empty for now - There are no messages to handle.
+}
+
+} // namespace WebKit
+
+#endif // ENABLE(NETWORK_PROCESS)
diff --git a/Source/WebKit2/NetworkProcess/NetworkConnectionToWebProcess.h b/Source/WebKit2/NetworkProcess/NetworkConnectionToWebProcess.h
new file mode 100644 (file)
index 0000000..6351360
--- /dev/null
@@ -0,0 +1,64 @@
+/*
+ * Copyright (C) 2012 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef NetworkConnectionToWebProcess_h
+#define NetworkConnectionToWebProcess_h
+
+#if ENABLE(NETWORK_PROCESS)
+
+#include "Connection.h"
+#include "NetworkConnectionToWebProcessMessages.h"
+#include <wtf/HashSet.h>
+#include <wtf/RefCounted.h>
+
+namespace WebKit {
+
+class NetworkConnectionToWebProcess : public RefCounted<NetworkConnectionToWebProcess>, CoreIPC::Connection::Client {
+public:
+    static PassRefPtr<NetworkConnectionToWebProcess> create(CoreIPC::Connection::Identifier);
+    virtual ~NetworkConnectionToWebProcess();
+
+    CoreIPC::Connection* connection() const { return m_connection.get(); }
+
+private:
+    NetworkConnectionToWebProcess(CoreIPC::Connection::Identifier);
+
+    // CoreIPC::Connection::Client
+    virtual void didReceiveMessage(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::MessageDecoder&);
+    virtual void didReceiveSyncMessage(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::MessageDecoder&, OwnPtr<CoreIPC::MessageEncoder>&);
+    virtual void didClose(CoreIPC::Connection*);
+    virtual void didReceiveInvalidMessage(CoreIPC::Connection*, CoreIPC::MessageID);
+
+    // Message handlers.
+    void didReceiveNetworkConnectionToWebProcessMessage(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::MessageDecoder&);
+
+    RefPtr<CoreIPC::Connection> m_connection;
+};
+
+} // namespace WebKit
+
+#endif // ENABLE(NETWORK_PROCESS)
+
+#endif // NetworkConnectionToWebProcess_h
diff --git a/Source/WebKit2/NetworkProcess/NetworkConnectionToWebProcess.messages.in b/Source/WebKit2/NetworkProcess/NetworkConnectionToWebProcess.messages.in
new file mode 100644 (file)
index 0000000..a1047c8
--- /dev/null
@@ -0,0 +1,29 @@
+# Copyright (C) 2012 Apple Inc. All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1.  Redistributions of source code must retain the above copyright
+#     notice, this list of conditions and the following disclaimer.
+# 2.  Redistributions in binary form must reproduce the above copyright
+#     notice, this list of conditions and the following disclaimer in the
+#     documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+# DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR
+# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#if ENABLE(NETWORK_PROCESS)
+
+messages -> NetworkConnectionToWebProcess {
+
+}
+
+#endif // ENABLE(NETWORK_PROCESS)
index c738245..5be2e9b 100644 (file)
 
 #include "ArgumentCoders.h"
 #include "Attachment.h"
+#include "NetworkConnectionToWebProcess.h"
+#include "NetworkProcessProxyMessages.h"
+#include <WebCore/ResourceRequest.h>
 #include <WebCore/RunLoop.h>
+#include <wtf/text/CString.h>
 
 using namespace WebCore;
 
@@ -59,6 +63,14 @@ void NetworkProcess::initialize(CoreIPC::Connection::Identifier serverIdentifier
     m_uiConnection->open();
 }
 
+void NetworkProcess::removeNetworkConnectionToWebProcess(NetworkConnectionToWebProcess* connection)
+{
+    size_t vectorIndex = m_webProcessConnections.find(connection);
+    ASSERT(vectorIndex != notFound);
+
+    m_webProcessConnections.remove(vectorIndex);
+}
+
 bool NetworkProcess::shouldTerminate()
 {
     return true;
@@ -71,10 +83,7 @@ void NetworkProcess::didReceiveMessage(CoreIPC::Connection* connection, CoreIPC:
 
 void NetworkProcess::didClose(CoreIPC::Connection*)
 {
-    // Either the connection to the UIProcess or a connection to a WebProcess has gone away.
-    // In the future we'll do appropriate cleanup and decide whether or not we want to keep
-    // the NetworkProcess open.
-    // For now we'll always close it.
+    // The UIProcess just crashed.
     RunLoop::current()->stop();
 }
 
@@ -92,6 +101,24 @@ void NetworkProcess::initializeNetworkProcess(const NetworkProcessCreationParame
     platformInitialize(parameters);
 }
 
+void NetworkProcess::createNetworkConnectionToWebProcess()
+{
+#if PLATFORM(MAC)
+    // Create the listening port.
+    mach_port_t listeningPort;
+    mach_port_allocate(mach_task_self(), MACH_PORT_RIGHT_RECEIVE, &listeningPort);
+
+    // Create a listening connection.
+    RefPtr<NetworkConnectionToWebProcess> connection = NetworkConnectionToWebProcess::create(CoreIPC::Connection::Identifier(listeningPort));
+    m_webProcessConnections.append(connection.release());
+
+    CoreIPC::Attachment clientPort(listeningPort, MACH_MSG_TYPE_MAKE_SEND);
+    m_uiConnection->send(Messages::NetworkProcessProxy::DidCreateNetworkConnectionToWebProcess(clientPort), 0);
+#else
+    notImplemented();
+#endif
+}
+
 } // namespace WebKit
 
 #endif // ENABLE(NETWORK_PROCESS)
index 59347da..5828e1f 100644 (file)
@@ -36,7 +36,8 @@ namespace WebCore {
 }
 
 namespace WebKit {
-    
+
+class NetworkConnectionToWebProcess;
 struct NetworkProcessCreationParameters;
 
 class NetworkProcess : ChildProcess {
@@ -46,6 +47,8 @@ public:
 
     void initialize(CoreIPC::Connection::Identifier, WebCore::RunLoop*);
 
+    void removeNetworkConnectionToWebProcess(NetworkConnectionToWebProcess*);
+
 private:
     NetworkProcess();
     ~NetworkProcess();
@@ -64,9 +67,14 @@ private:
     // Message Handlers
     void didReceiveNetworkProcessMessage(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::MessageDecoder&);
     void initializeNetworkProcess(const NetworkProcessCreationParameters&);
+    void createNetworkConnectionToWebProcess();
 
     // The connection to the UI process.
     RefPtr<CoreIPC::Connection> m_uiConnection;
+
+    // Connections to WebProcesses.
+    Vector<RefPtr<NetworkConnectionToWebProcess> > m_webProcessConnections;
+
 };
 
 } // namespace WebKit
index 5e46a8e..029536a 100644 (file)
@@ -25,6 +25,9 @@
 messages -> NetworkProcess {
     # Initializes the network process.
     InitializeNetworkProcess(WebKit::NetworkProcessCreationParameters processCreationParameters)
+
+    # Creates a connection for communication with a WebProcess
+    CreateNetworkConnectionToWebProcess()
 }
 
 #endif // ENABLE(NETWORK_PROCESS)
index 792e44b..77401c1 100644 (file)
@@ -198,6 +198,12 @@ void callMemberFunction(const Arguments4<P1, P2, P3, P4>& args, Arguments3<R1, R
 }
 
 // Dispatch functions with delayed reply arguments.
+template<typename C, typename MF, typename R>
+void callMemberFunction(const Arguments0&, PassRefPtr<R> delayedReply, C* object, MF function)
+{
+    (object->*function)(delayedReply);
+}
+
 template<typename C, typename MF, typename P1, typename R>
 void callMemberFunction(const Arguments1<P1>& args, PassRefPtr<R> delayedReply, C* object, MF function)
 {
@@ -211,6 +217,12 @@ void callMemberFunction(const Arguments2<P1, P2>& args, PassRefPtr<R> delayedRep
 }
 
 // Dispatch functions with connection parameter.
+template<typename C, typename MF>
+void callMemberFunction(Connection* connection, const Arguments0&, C* object, MF function)
+{
+    (object->*function)(connection);
+}
+
 template<typename C, typename MF, typename P1>
 void callMemberFunction(Connection* connection, const Arguments1<P1>& args, C* object, MF function)
 {
index 29a2054..a89e64f 100644 (file)
@@ -109,6 +109,12 @@ enum MessageClass {
     // Messages sent by the UI process to the network process.
     MessageClassNetworkProcess,
 
+    // Messages sent by the network process to the UI process.
+    MessageClassNetworkProcessProxy,
+
+    // Messages sent by the web process to the network process.
+    MessageClassNetworkConnectionToWebProcess,
+
 #if ENABLE(SHARED_WORKER_PROCESS)
     // Messages sent by the UI process to the shared worker process.
     MessageClassSharedWorkerProcess,
diff --git a/Source/WebKit2/UIProcess/Network/NetworkProcessManager.cpp b/Source/WebKit2/UIProcess/Network/NetworkProcessManager.cpp
new file mode 100644 (file)
index 0000000..00f16f4
--- /dev/null
@@ -0,0 +1,70 @@
+/*
+ * Copyright (C) 2010, 2011, 2012 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "NetworkProcessManager.h"
+
+#include "NetworkProcessProxy.h"
+
+namespace WebKit {
+
+NetworkProcessManager& NetworkProcessManager::shared()
+{
+    DEFINE_STATIC_LOCAL(NetworkProcessManager, networkProcessManager, ());
+    return networkProcessManager;
+}
+
+NetworkProcessManager::NetworkProcessManager()
+{
+}
+
+void NetworkProcessManager::getNetworkProcessConnection(PassRefPtr<Messages::WebProcessProxy::GetNetworkProcessConnection::DelayedReply> reply)
+{
+    ASSERT(reply);
+
+    ensureNetworkProcess();
+    ASSERT(m_networkProcess);
+
+    m_networkProcess->getNetworkProcessConnection(reply);
+}
+
+void NetworkProcessManager::ensureNetworkProcess()
+{
+    if (m_networkProcess)
+        return;
+
+    m_networkProcess = NetworkProcessProxy::create(this);
+}
+
+void NetworkProcessManager::removeNetworkProcessProxy(NetworkProcessProxy* networkProcessProxy)
+{
+    ASSERT(m_networkProcess);
+    ASSERT(networkProcessProxy == m_networkProcess.get());
+    
+    m_networkProcess = 0;
+}
+
+
+} // namespace WebKit
diff --git a/Source/WebKit2/UIProcess/Network/NetworkProcessManager.h b/Source/WebKit2/UIProcess/Network/NetworkProcessManager.h
new file mode 100644 (file)
index 0000000..08d422b
--- /dev/null
@@ -0,0 +1,59 @@
+/*
+ * Copyright (C) 2010, 2011, 2012 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef NetworkProcessManager_h
+#define NetworkProcessManager_h
+
+#include "Connection.h"
+#include "WebProcessProxyMessages.h"
+#include <wtf/RefCounted.h>
+#include <wtf/text/WTFString.h>
+
+namespace WebKit {
+
+class NetworkProcessConnection;
+class NetworkProcessProxy;
+class WebProcessProxy;
+
+class NetworkProcessManager {
+    WTF_MAKE_NONCOPYABLE(NetworkProcessManager);
+public:
+    static NetworkProcessManager& shared();
+
+    void ensureNetworkProcess();
+
+    void getNetworkProcessConnection(PassRefPtr<Messages::WebProcessProxy::GetNetworkProcessConnection::DelayedReply>);
+    
+    void removeNetworkProcessProxy(NetworkProcessProxy*);
+
+private:
+    NetworkProcessManager();
+
+    RefPtr<NetworkProcessProxy> m_networkProcess;
+};
+
+} // namespace WebKit
+
+#endif // NetworkProcessManager_h
index d08a891..d1a0135 100644 (file)
 #include "NetworkProcessProxy.h"
 
 #include "NetworkProcessCreationParameters.h"
+#include "NetworkProcessManager.h"
 #include "NetworkProcessMessages.h"
+#include "WebContext.h"
+#include "WebProcessMessages.h"
 #include <WebCore/RunLoop.h>
 
 #if ENABLE(NETWORK_PROCESS)
@@ -36,12 +39,14 @@ using namespace WebCore;
 
 namespace WebKit {
 
-PassRefPtr<NetworkProcessProxy> NetworkProcessProxy::create()
+PassRefPtr<NetworkProcessProxy> NetworkProcessProxy::create(NetworkProcessManager* manager)
 {
-    return adoptRef(new NetworkProcessProxy);
+    return adoptRef(new NetworkProcessProxy(manager));
 }
 
-NetworkProcessProxy::NetworkProcessProxy()
+NetworkProcessProxy::NetworkProcessProxy(NetworkProcessManager* manager)
+    : m_networkProcessManager(manager)
+    , m_numPendingConnectionRequests(0)
 {
     ProcessLauncher::LaunchOptions launchOptions;
     launchOptions.processType = ProcessLauncher::NetworkProcess;
@@ -62,14 +67,49 @@ NetworkProcessProxy::~NetworkProcessProxy()
 
 }
 
-void NetworkProcessProxy::didReceiveMessage(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::MessageDecoder&)
+void NetworkProcessProxy::getNetworkProcessConnection(PassRefPtr<Messages::WebProcessProxy::GetNetworkProcessConnection::DelayedReply> reply)
 {
+    m_pendingConnectionReplies.append(reply);
 
+    if (m_processLauncher->isLaunching()) {
+        m_numPendingConnectionRequests++;
+        return;
+    }
+
+    m_connection->send(Messages::NetworkProcess::CreateNetworkConnectionToWebProcess(), 0, CoreIPC::DispatchMessageEvenWhenWaitingForSyncReply);
+}
+
+void NetworkProcessProxy::networkProcessCrashedOrFailedToLaunch()
+{
+    // The network process must have crashed or exited, send any pending sync replies we might have.
+    while (!m_pendingConnectionReplies.isEmpty()) {
+        RefPtr<Messages::WebProcessProxy::GetNetworkProcessConnection::DelayedReply> reply = m_pendingConnectionReplies.takeFirst();
+
+#if PLATFORM(MAC)
+        reply->send(CoreIPC::Attachment(0, MACH_MSG_TYPE_MOVE_SEND));
+#else
+        notImplemented();
+#endif
+    }
+
+    // Tell the network process manager to forget about this network process proxy. This may cause us to be deleted.
+    m_networkProcessManager->removeNetworkProcessProxy(this);
+}
+
+void NetworkProcessProxy::didReceiveMessage(CoreIPC::Connection* connection, CoreIPC::MessageID messageID, CoreIPC::MessageDecoder& decoder)
+{
+    didReceiveNetworkProcessProxyMessage(connection, messageID, decoder);
 }
 
 void NetworkProcessProxy::didClose(CoreIPC::Connection*)
 {
+    // Notify all WebProcesses that the NetworkProcess crashed.
+    const Vector<WebContext*>& contexts = WebContext::allContexts();
+    for (size_t i = 0; i < contexts.size(); ++i)
+        contexts[i]->sendToAllProcesses(Messages::WebProcess::NetworkProcessCrashed());
 
+    // This may cause us to be deleted.
+    networkProcessCrashedOrFailedToLaunch();
 }
 
 void NetworkProcessProxy::didReceiveInvalidMessage(CoreIPC::Connection*, CoreIPC::MessageID)
@@ -82,6 +122,20 @@ void NetworkProcessProxy::syncMessageSendTimedOut(CoreIPC::Connection*)
 
 }
 
+void NetworkProcessProxy::didCreateNetworkConnectionToWebProcess(const CoreIPC::Attachment& connectionIdentifier)
+{
+    ASSERT(!m_pendingConnectionReplies.isEmpty());
+
+    // Grab the first pending connection reply.
+    RefPtr<Messages::WebProcessProxy::GetNetworkProcessConnection::DelayedReply> reply = m_pendingConnectionReplies.takeFirst();
+
+#if PLATFORM(MAC)
+    reply->send(CoreIPC::Attachment(connectionIdentifier.port(), MACH_MSG_TYPE_MOVE_SEND));
+#else
+    notImplemented();
+#endif
+}
+
 void NetworkProcessProxy::didFinishLaunching(ProcessLauncher*, CoreIPC::Connection::Identifier connectionIdentifier)
 {
     ASSERT(!m_connection);
@@ -103,6 +157,11 @@ void NetworkProcessProxy::didFinishLaunching(ProcessLauncher*, CoreIPC::Connecti
 
     // Initialize the network host process.
     m_connection->send(Messages::NetworkProcess::InitializeNetworkProcess(parameters), 0);
+
+    for (unsigned i = 0; i < m_numPendingConnectionRequests; ++i)
+        m_connection->send(Messages::NetworkProcess::CreateNetworkConnectionToWebProcess(), 0);
+    
+    m_numPendingConnectionRequests = 0;
 }
 
 } // namespace WebKit
index 1db5d99..1840a8e 100644 (file)
 
 namespace WebKit {
 
+class NetworkProcessManager;
 struct NetworkProcessCreationParameters;
 
 class NetworkProcessProxy : public RefCounted<NetworkProcessProxy>, CoreIPC::Connection::Client, ProcessLauncher::Client {
 public:
-    static PassRefPtr<NetworkProcessProxy> create();
+    static PassRefPtr<NetworkProcessProxy> create(NetworkProcessManager*);
     ~NetworkProcessProxy();
 
+    void getNetworkProcessConnection(PassRefPtr<Messages::WebProcessProxy::GetNetworkProcessConnection::DelayedReply>);
+
 private:
-    NetworkProcessProxy();
+    NetworkProcessProxy(NetworkProcessManager*);
 
     void platformInitializeNetworkProcess(NetworkProcessCreationParameters&);
 
+    void networkProcessCrashedOrFailedToLaunch();
+
     // CoreIPC::Connection::Client
     virtual void didReceiveMessage(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::MessageDecoder&);
     virtual void didClose(CoreIPC::Connection*);
     virtual void didReceiveInvalidMessage(CoreIPC::Connection*, CoreIPC::MessageID);
     virtual void syncMessageSendTimedOut(CoreIPC::Connection*);
 
+    // Message handlers
+    void didReceiveNetworkProcessProxyMessage(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::MessageDecoder&);
+    void didCreateNetworkConnectionToWebProcess(const CoreIPC::Attachment&);
+    
     // ProcessLauncher::Client
     virtual void didFinishLaunching(ProcessLauncher*, CoreIPC::Connection::Identifier);
 
@@ -62,6 +71,10 @@ private:
     // The process launcher for the network process.
     RefPtr<ProcessLauncher> m_processLauncher;
 
+    NetworkProcessManager* m_networkProcessManager;
+    
+    unsigned m_numPendingConnectionRequests;
+    Deque<RefPtr<Messages::WebProcessProxy::GetNetworkProcessConnection::DelayedReply> > m_pendingConnectionReplies;
 };
 
 } // namespace WebKit
diff --git a/Source/WebKit2/UIProcess/Network/NetworkProcessProxy.messages.in b/Source/WebKit2/UIProcess/Network/NetworkProcessProxy.messages.in
new file mode 100644 (file)
index 0000000..379b108
--- /dev/null
@@ -0,0 +1,29 @@
+# Copyright (C) 2012 Apple Inc. All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1.  Redistributions of source code must retain the above copyright
+#     notice, this list of conditions and the following disclaimer.
+# 2.  Redistributions in binary form must reproduce the above copyright
+#     notice, this list of conditions and the following disclaimer in the
+#     documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+# DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR
+# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#if ENABLE(NETWORK_PROCESS)
+
+messages -> NetworkProcessProxy {
+    DidCreateNetworkConnectionToWebProcess(CoreIPC::Attachment connectionIdentifier)
+}
+
+#endif // ENABLE(NETWORK_PROCESS)
index 51e179b..c9446b4 100644 (file)
 #include "WebNetworkInfoManagerProxy.h"
 #endif
 
+#if ENABLE(NETWORK_PROCESS)
+#include "NetworkProcessManager.h"
+#endif
+
 #if USE(SOUP)
 #include "WebSoupRequestManagerProxy.h"
 #endif
@@ -336,7 +340,7 @@ PassRefPtr<WebProcessProxy> WebContext::createNewWebProcess()
 {
 #if ENABLE(NETWORK_PROCESS)
     if (m_usesNetworkProcess)
-        ensureNetworkProcess();
+        NetworkProcessManager::shared().ensureNetworkProcess();
 #endif
 
     RefPtr<WebProcessProxy> process = WebProcessProxy::create(this);
@@ -435,16 +439,6 @@ void WebContext::warmInitialProcess()
     m_haveInitialEmptyProcess = true;
 }
 
-#if ENABLE(NETWORK_PROCESS)
-void WebContext::ensureNetworkProcess()
-{
-    if (m_networkProcess)
-        return;
-
-    m_networkProcess = NetworkProcessProxy::create();
-}
-#endif
-
 void WebContext::enableProcessTermination()
 {
     m_processTerminationEnabled = true;
index cee689c..e3f6a69 100644 (file)
 #include <wtf/text/StringHash.h>
 #include <wtf/text/WTFString.h>
 
-#if ENABLE(NETWORK_PROCESS)
-#include "NetworkProcessProxy.h"
-#endif
-
 namespace WebKit {
 
 class DownloadProxy;
@@ -257,10 +253,6 @@ private:
     void platformInitializeWebProcess(WebProcessCreationParameters&);
     void platformInvalidateContext();
 
-#if ENABLE(NETWORK_PROCESS)
-    void ensureNetworkProcess();
-#endif
-
 #if PLATFORM(MAC)
     void getPasteboardTypes(const String& pasteboardName, Vector<String>& pasteboardTypes);
     void getPasteboardPathnamesForType(const String& pasteboardName, const String& pasteboardType, Vector<String>& pathnames);
@@ -395,7 +387,6 @@ private:
     bool m_processTerminationEnabled;
 
 #if ENABLE(NETWORK_PROCESS)
-    RefPtr<NetworkProcessProxy> m_networkProcess;
     bool m_usesNetworkProcess;
 #endif
     
index a38e23a..7fa0d99 100644 (file)
 #include <wtf/text/CString.h>
 #include <wtf/text/WTFString.h>
 
+#if ENABLE(NETWORK_PROCESS)
+#include "NetworkProcessManager.h"
+#endif
+
 #if PLATFORM(MAC)
 #include "SimplePDFPlugin.h"
 #if ENABLE(PDFKIT_PLUGIN)
@@ -401,6 +405,13 @@ void WebProcessProxy::getSharedWorkerProcessConnection(const String& /* url */,
 }
 #endif // ENABLE(SHARED_WORKER_PROCESS)
 
+#if ENABLE(NETWORK_PROCESS)
+void WebProcessProxy::getNetworkProcessConnection(PassRefPtr<Messages::WebProcessProxy::GetNetworkProcessConnection::DelayedReply> reply)
+{
+    NetworkProcessManager::shared().getNetworkProcessConnection(reply);
+}
+#endif // ENABLE(NETWORK_PROCESS)
+
 void WebProcessProxy::didReceiveMessage(CoreIPC::Connection* connection, CoreIPC::MessageID messageID, CoreIPC::MessageDecoder& decoder)
 {
     if (m_context->dispatchMessage(connection, messageID, decoder))
index c311c4f..29dc549 100644 (file)
@@ -153,6 +153,9 @@ private:
     void didGetSitesWithPluginData(const Vector<String>& sites, uint64_t callbackID);
     void didClearPluginSiteData(uint64_t callbackID);
 #endif
+#if ENABLE(NETWORK_PROCESS)
+    void getNetworkProcessConnection(PassRefPtr<Messages::WebProcessProxy::GetNetworkProcessConnection::DelayedReply>);
+#endif
 #if ENABLE(SHARED_WORKER_PROCESS)
     void getSharedWorkerProcessConnection(const String& url, const String& name, PassRefPtr<Messages::WebProcessProxy::GetSharedWorkerProcessConnection::DelayedReply>);
 #endif
index 396a166..e721388 100644 (file)
@@ -45,6 +45,9 @@ messages -> WebProcessProxy {
     void DidGetSitesWithPluginData(Vector<WTF::String> sites, uint64_t callbackID)
     void DidClearPluginSiteData(uint64_t callbackID)
 #endif
+#if ENABLE(NETWORK_PROCESS)
+    GetNetworkProcessConnection() -> (CoreIPC::Attachment connectionHandle) Delayed
+#endif
 #if ENABLE(SHARED_WORKER_PROCESS)
     GetSharedWorkerProcessConnection(WTF::String url, WTF::String name) -> (CoreIPC::Attachment connectionHandle) Delayed
 #endif
index ee881fd..6c87cde 100644 (file)
                3F87B9C0158940D80090FF62 /* WebColorChooserProxy.h in Headers */ = {isa = PBXBuildFile; fileRef = 3F87B9BF158940D80090FF62 /* WebColorChooserProxy.h */; };
                4F601432155C5AA2001FBDE0 /* BlockingResponseMap.h in Headers */ = {isa = PBXBuildFile; fileRef = 4F601430155C5A32001FBDE0 /* BlockingResponseMap.h */; };
                51021E9C12B16788005C033C /* WebContextMenuClientMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 51021E9B12B16788005C033C /* WebContextMenuClientMac.mm */; };
+               5105B0DD162F7E9D00E27709 /* NetworkProcessManager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5105B0DB162F7E9D00E27709 /* NetworkProcessManager.cpp */; };
+               5105B0DE162F7E9D00E27709 /* NetworkProcessManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 5105B0DC162F7E9D00E27709 /* NetworkProcessManager.h */; };
                510CC8491613C85C00D03ED3 /* NetworkProcess.app in CopyFiles */ = {isa = PBXBuildFile; fileRef = 510CC80E1613C79900D03ED3 /* NetworkProcess.app */; };
                510CC84F1613C92C00D03ED3 /* MainMacProcess.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1A6FA31011E3921E00DB1371 /* MainMacProcess.cpp */; };
                510FBB9A1288C95E00AFFDF4 /* WebContextMenuItemData.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 510FBB981288C95E00AFFDF4 /* WebContextMenuItemData.cpp */; };
                512F58FC12A88A5400629530 /* WKProtectionSpace.h in Headers */ = {isa = PBXBuildFile; fileRef = 512F58F412A88A5400629530 /* WKProtectionSpace.h */; settings = {ATTRIBUTES = (Private, ); }; };
                5136183D163126DA00A99DDE /* ConnectionStack.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5136183B163126DA00A99DDE /* ConnectionStack.cpp */; };
                5136183E163126DA00A99DDE /* ConnectionStack.h in Headers */ = {isa = PBXBuildFile; fileRef = 5136183C163126DA00A99DDE /* ConnectionStack.h */; };
+               513A163C163088F6005D7D22 /* NetworkProcessProxyMessageReceiver.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 513A163A163088F6005D7D22 /* NetworkProcessProxyMessageReceiver.cpp */; };
+               513A163D163088F6005D7D22 /* NetworkProcessProxyMessages.h in Headers */ = {isa = PBXBuildFile; fileRef = 513A163B163088F6005D7D22 /* NetworkProcessProxyMessages.h */; };
+               513A164C1630A9BF005D7D22 /* NetworkConnectionToWebProcess.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 513A16491630A9BF005D7D22 /* NetworkConnectionToWebProcess.cpp */; };
+               513A164D1630A9BF005D7D22 /* NetworkConnectionToWebProcess.h in Headers */ = {isa = PBXBuildFile; fileRef = 513A164A1630A9BF005D7D22 /* NetworkConnectionToWebProcess.h */; };
                5153569C1291B1D2000749DC /* WebPageContextMenuClient.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5153569A1291B1D2000749DC /* WebPageContextMenuClient.cpp */; };
                5153569D1291B1D2000749DC /* WebPageContextMenuClient.h in Headers */ = {isa = PBXBuildFile; fileRef = 5153569B1291B1D2000749DC /* WebPageContextMenuClient.h */; };
                51578B831209ECEF00A37C4A /* WebData.h in Headers */ = {isa = PBXBuildFile; fileRef = 51578B821209ECEF00A37C4A /* WebData.h */; };
                51834592134532E90092B696 /* WebIconDatabaseClient.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 51834590134532E80092B696 /* WebIconDatabaseClient.cpp */; };
                51834593134532E90092B696 /* WebIconDatabaseClient.h in Headers */ = {isa = PBXBuildFile; fileRef = 51834591134532E80092B696 /* WebIconDatabaseClient.h */; };
                5183B3921379F7B800E8754E /* WebProcessShim.dylib in Copy Web Process Shim */ = {isa = PBXBuildFile; fileRef = 510031F61379CACB00C8DFE4 /* WebProcessShim.dylib */; };
+               5183DDEC1630BDFC008BE5C7 /* NetworkProcessConnection.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5105B0D4162F7A7A00E27709 /* NetworkProcessConnection.cpp */; };
                51871B5B127CB89D00F76232 /* WebContextMenu.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 51871B59127CB89D00F76232 /* WebContextMenu.cpp */; };
                51871B5C127CB89D00F76232 /* WebContextMenu.h in Headers */ = {isa = PBXBuildFile; fileRef = 51871B5A127CB89D00F76232 /* WebContextMenu.h */; };
                518ACAEA12AEE6BB00B04B83 /* WKProtectionSpaceTypes.h in Headers */ = {isa = PBXBuildFile; fileRef = 518ACAE912AEE6BB00B04B83 /* WKProtectionSpaceTypes.h */; settings = {ATTRIBUTES = (Private, ); }; };
                4F601430155C5A32001FBDE0 /* BlockingResponseMap.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BlockingResponseMap.h; sourceTree = "<group>"; };
                510031F61379CACB00C8DFE4 /* WebProcessShim.dylib */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.dylib"; includeInIndex = 0; path = WebProcessShim.dylib; sourceTree = BUILT_PRODUCTS_DIR; };
                51021E9B12B16788005C033C /* WebContextMenuClientMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebContextMenuClientMac.mm; sourceTree = "<group>"; };
+               5105B0D4162F7A7A00E27709 /* NetworkProcessConnection.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = NetworkProcessConnection.cpp; path = Network/NetworkProcessConnection.cpp; sourceTree = "<group>"; };
+               5105B0D5162F7A7A00E27709 /* NetworkProcessConnection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = NetworkProcessConnection.h; path = Network/NetworkProcessConnection.h; sourceTree = "<group>"; };
+               5105B0DB162F7E9D00E27709 /* NetworkProcessManager.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = NetworkProcessManager.cpp; sourceTree = "<group>"; };
+               5105B0DC162F7E9D00E27709 /* NetworkProcessManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NetworkProcessManager.h; sourceTree = "<group>"; };
+               5105B0F31630872E00E27709 /* NetworkProcessProxy.messages.in */ = {isa = PBXFileReference; lastKnownFileType = text; path = NetworkProcessProxy.messages.in; sourceTree = "<group>"; };
                510CC7DD16138E2900D03ED3 /* NetworkProcessMainMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = NetworkProcessMainMac.mm; sourceTree = "<group>"; };
                510CC7DF16138E2900D03ED3 /* NetworkProcess.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = NetworkProcess.cpp; path = NetworkProcess/NetworkProcess.cpp; sourceTree = "<group>"; };
                510CC7E016138E2900D03ED3 /* NetworkProcess.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = NetworkProcess.h; path = NetworkProcess/NetworkProcess.h; sourceTree = "<group>"; };
                512F58F412A88A5400629530 /* WKProtectionSpace.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKProtectionSpace.h; sourceTree = "<group>"; };
                5136183B163126DA00A99DDE /* ConnectionStack.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ConnectionStack.cpp; sourceTree = "<group>"; };
                5136183C163126DA00A99DDE /* ConnectionStack.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ConnectionStack.h; sourceTree = "<group>"; };
+               513A163A163088F6005D7D22 /* NetworkProcessProxyMessageReceiver.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = NetworkProcessProxyMessageReceiver.cpp; sourceTree = "<group>"; };
+               513A163B163088F6005D7D22 /* NetworkProcessProxyMessages.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NetworkProcessProxyMessages.h; sourceTree = "<group>"; };
+               513A16491630A9BF005D7D22 /* NetworkConnectionToWebProcess.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = NetworkConnectionToWebProcess.cpp; path = NetworkProcess/NetworkConnectionToWebProcess.cpp; sourceTree = "<group>"; };
+               513A164A1630A9BF005D7D22 /* NetworkConnectionToWebProcess.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = NetworkConnectionToWebProcess.h; path = NetworkProcess/NetworkConnectionToWebProcess.h; sourceTree = "<group>"; };
+               513A164B1630A9BF005D7D22 /* NetworkConnectionToWebProcess.messages.in */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = NetworkConnectionToWebProcess.messages.in; path = NetworkProcess/NetworkConnectionToWebProcess.messages.in; sourceTree = "<group>"; };
                5153569A1291B1D2000749DC /* WebPageContextMenuClient.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebPageContextMenuClient.cpp; sourceTree = "<group>"; };
                5153569B1291B1D2000749DC /* WebPageContextMenuClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebPageContextMenuClient.h; sourceTree = "<group>"; };
                51578B821209ECEF00A37C4A /* WebData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebData.h; sourceTree = "<group>"; };
                        name = cf;
                        sourceTree = "<group>";
                };
+               5105B0D2162F7A5E00E27709 /* Network */ = {
+                       isa = PBXGroup;
+                       children = (
+                               5105B0D4162F7A7A00E27709 /* NetworkProcessConnection.cpp */,
+                               5105B0D5162F7A7A00E27709 /* NetworkProcessConnection.h */,
+                       );
+                       name = Network;
+                       sourceTree = "<group>";
+               };
                510CC7DA16138E0100D03ED3 /* NetworkProcess */ = {
                        isa = PBXGroup;
                        children = (
                                510CC7DC16138E2900D03ED3 /* mac */,
+                               513A16491630A9BF005D7D22 /* NetworkConnectionToWebProcess.cpp */,
+                               513A164A1630A9BF005D7D22 /* NetworkConnectionToWebProcess.h */,
+                               513A164B1630A9BF005D7D22 /* NetworkConnectionToWebProcess.messages.in */,
                                510CC7DF16138E2900D03ED3 /* NetworkProcess.cpp */,
                                510CC7E016138E2900D03ED3 /* NetworkProcess.h */,
                                51A8A6171627F5BB000D90E9 /* NetworkProcess.messages.in */,
                        isa = PBXGroup;
                        children = (
                                516319931628980E00E22F00 /* mac */,
+                               5105B0DB162F7E9D00E27709 /* NetworkProcessManager.cpp */,
+                               5105B0DC162F7E9D00E27709 /* NetworkProcessManager.h */,
                                510CC7EA16138E7200D03ED3 /* NetworkProcessProxy.cpp */,
                                510CC7EB16138E7200D03ED3 /* NetworkProcessProxy.h */,
+                               5105B0F31630872E00E27709 /* NetworkProcessProxy.messages.in */,
                        );
                        path = Network;
                        sourceTree = "<group>";
                                51A9E0FB1315CC0E009E7031 /* KeyValueStorage */,
                                1A6FA01C11E1526300DB1371 /* mac */,
                                33D3A3BD1339609800709BE4 /* MediaCache */,
+                               5105B0D2162F7A5E00E27709 /* Network */,
                                31099974146C8AA80029DEB9 /* Notifications (User) */,
                                1A6FB7AA11E64B4900DB1371 /* Plugins */,
                                3336762B130C9978006C9DE2 /* ResourceCache */,
                                1AA576001496B7C000A4EE06 /* EventDispatcherMessages.h */,
                                51ACC9341628064800342550 /* NetworkProcessMessageReceiver.cpp */,
                                51ACC9351628064800342550 /* NetworkProcessMessages.h */,
+                               513A163A163088F6005D7D22 /* NetworkProcessProxyMessageReceiver.cpp */,
+                               513A163B163088F6005D7D22 /* NetworkProcessProxyMessages.h */,
                                1A2D8437127F65D5001EB962 /* NPObjectMessageReceiverMessageReceiver.cpp */,
                                1A2D8438127F65D5001EB962 /* NPObjectMessageReceiverMessages.h */,
                                1A8EF96C1252AF6B00F7067F /* PluginControllerProxyMessageReceiver.cpp */,
                                1A2328FF162C866A00D82F7A /* MessageEncoder.h in Headers */,
                                1A232903162C867300D82F7A /* MessageDecoder.h in Headers */,
                                5136183E163126DA00A99DDE /* ConnectionStack.h in Headers */,
+                               5105B0DE162F7E9D00E27709 /* NetworkProcessManager.h in Headers */,
+                               513A163D163088F6005D7D22 /* NetworkProcessProxyMessages.h in Headers */,
+                               513A164D1630A9BF005D7D22 /* NetworkConnectionToWebProcess.h in Headers */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
                                1A2328FE162C866A00D82F7A /* MessageEncoder.cpp in Sources */,
                                1A232902162C867300D82F7A /* MessageDecoder.cpp in Sources */,
                                5136183D163126DA00A99DDE /* ConnectionStack.cpp in Sources */,
+                               5105B0DD162F7E9D00E27709 /* NetworkProcessManager.cpp in Sources */,
+                               513A163C163088F6005D7D22 /* NetworkProcessProxyMessageReceiver.cpp in Sources */,
+                               513A164C1630A9BF005D7D22 /* NetworkConnectionToWebProcess.cpp in Sources */,
+                               5183DDEC1630BDFC008BE5C7 /* NetworkProcessConnection.cpp in Sources */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
diff --git a/Source/WebKit2/WebProcess/Network/NetworkProcessConnection.cpp b/Source/WebKit2/WebProcess/Network/NetworkProcessConnection.cpp
new file mode 100644 (file)
index 0000000..dd9d6cb
--- /dev/null
@@ -0,0 +1,66 @@
+/*
+ * Copyright (C) 2010, 2011, 2012 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "NetworkProcessConnection.h"
+
+#include "WebProcess.h"
+
+#if ENABLE(NETWORK_PROCESS)
+
+namespace WebKit {
+
+NetworkProcessConnection::NetworkProcessConnection(CoreIPC::Connection::Identifier connectionIdentifier)
+{
+    m_connection = CoreIPC::Connection::createClientConnection(connectionIdentifier, this, WebProcess::shared().runLoop());
+    m_connection->open();
+}
+
+NetworkProcessConnection::~NetworkProcessConnection()
+{
+}
+
+void NetworkProcessConnection::didReceiveMessage(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::MessageDecoder&)
+{
+}
+
+void NetworkProcessConnection::didReceiveSyncMessage(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::MessageDecoder&, OwnPtr<CoreIPC::MessageEncoder>&)
+{
+}
+
+void NetworkProcessConnection::didClose(CoreIPC::Connection*)
+{
+    // The NetworkProcess probably crashed.
+    WebProcess::shared().networkProcessConnectionClosed(this);
+}
+
+void NetworkProcessConnection::didReceiveInvalidMessage(CoreIPC::Connection*, CoreIPC::MessageID)
+{
+}
+
+    
+} // namespace WebKit
+
+#endif // ENABLE(NETWORK_PROCESS)
diff --git a/Source/WebKit2/WebProcess/Network/NetworkProcessConnection.h b/Source/WebKit2/WebProcess/Network/NetworkProcessConnection.h
new file mode 100644 (file)
index 0000000..65e2598
--- /dev/null
@@ -0,0 +1,65 @@
+/*
+ * Copyright (C) 2010, 2011, 2012 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef NetworkProcessConnection_h
+#define NetworkProcessConnection_h
+
+#include "Connection.h"
+#include <wtf/RefCounted.h>
+#include <wtf/text/WTFString.h>
+
+#if ENABLE(NETWORK_PROCESS)
+
+namespace WebKit {
+
+class NetworkProcessConnection : public RefCounted<NetworkProcessConnection>, CoreIPC::Connection::Client {
+public:
+    static PassRefPtr<NetworkProcessConnection> create(CoreIPC::Connection::Identifier connectionIdentifier)
+    {
+        return adoptRef(new NetworkProcessConnection(connectionIdentifier));
+    }
+    ~NetworkProcessConnection();
+    
+    CoreIPC::Connection* connection() const { return m_connection.get(); }
+
+private:
+    NetworkProcessConnection(CoreIPC::Connection::Identifier);
+
+    // CoreIPC::Connection::Client
+    virtual void didReceiveMessage(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::MessageDecoder&);
+    virtual void didReceiveSyncMessage(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::MessageDecoder&, OwnPtr<CoreIPC::MessageEncoder>&);
+    virtual void didClose(CoreIPC::Connection*);
+    virtual void didReceiveInvalidMessage(CoreIPC::Connection*, CoreIPC::MessageID);
+
+    // The connection from the web process to the network process.
+    RefPtr<CoreIPC::Connection> m_connection;
+};
+
+} // namespace WebKit
+
+#endif // ENABLE(NETWORK_PROCESS)
+
+
+#endif // NetworkProcessConnection_h
index d9d14e9..887c555 100644 (file)
 #include "WebNetworkInfoManagerMessages.h"
 #endif
 
+#if ENABLE(NETWORK_PROCESS)
+#include "NetworkProcessConnection.h"
+#endif
+
 #if !OS(WINDOWS)
 #include <unistd.h>
 #endif
@@ -256,9 +260,36 @@ void WebProcess::initializeWebProcess(const WebProcessCreationParameters& parame
     WebCore::ResourceHandle::setPrivateBrowsingStorageSessionIdentifierBase(parameters.uiProcessBundleIdentifier);
 #endif
 
+#if ENABLE(NETWORK_PROCESS)
+    ensureNetworkProcessConnection();
+#endif
     setTerminationTimeout(parameters.terminationTimeout);
 }
 
+#if ENABLE(NETWORK_PROCESS)
+void WebProcess::ensureNetworkProcessConnection()
+{
+    if (m_networkProcessConnection)
+        return;
+
+    CoreIPC::Attachment encodedConnectionIdentifier;
+
+    if (!connection()->sendSync(Messages::WebProcessProxy::GetNetworkProcessConnection(),
+        Messages::WebProcessProxy::GetNetworkProcessConnection::Reply(encodedConnectionIdentifier), 0))
+        return;
+
+#if PLATFORM(MAC)
+    CoreIPC::Connection::Identifier connectionIdentifier(encodedConnectionIdentifier.port());
+    if (CoreIPC::Connection::identifierIsNull(connectionIdentifier))
+        return;
+#else
+    ASSERT_NOT_REACHED();
+#endif
+
+    RefPtr<NetworkProcessConnection> m_networkProcessConnection = NetworkProcessConnection::create(connectionIdentifier);
+}
+#endif // ENABLE(NETWORK_PROCESS)
+
 void WebProcess::setShouldTrackVisitedLinks(bool shouldTrackVisitedLinks)
 {
     m_shouldTrackVisitedLinks = shouldTrackVisitedLinks;
@@ -1024,6 +1055,23 @@ void WebProcess::postInjectedBundleMessage(const CoreIPC::DataReference& message
     injectedBundle->didReceiveMessage(messageName, messageBody.get());
 }
 
+#if ENABLE(NETWORK_PROCESS)
+void WebProcess::networkProcessConnectionClosed(NetworkProcessConnection* connection)
+{
+    ASSERT(m_networkProcessConnection);
+    ASSERT(m_networkProcessConnection == connection);
+
+    m_networkProcessConnection = 0;
+}
+
+void WebProcess::networkProcessCrashed(CoreIPC::Connection*)
+{
+    ASSERT(m_networkProcessConnection);
+    
+    networkProcessConnectionClosed(m_networkProcessConnection.get());
+}
+#endif
+
 #if ENABLE(PLUGIN_PROCESS)
 void WebProcess::pluginProcessCrashed(CoreIPC::Connection*, const String& pluginPath)
 {
index 9a13ee8..cb667ef 100644 (file)
@@ -95,6 +95,10 @@ struct WebPageGroupData;
 struct WebPreferencesStore;
 struct WebProcessCreationParameters;
 
+#if ENABLE(NETWORK_PROCESS)
+class NetworkProcessConnection;
+#endif
+
 #if USE(SECURITY_FRAMEWORK)
 class SecItemResponseData;
 class SecKeychainItemResponseData;
@@ -188,6 +192,10 @@ public:
     WebSoupRequestManager& soupRequestManager() { return m_soupRequestManager; }
 #endif
 
+#if ENABLE(NETWORK_PROCESS)
+    void networkProcessConnectionClosed(NetworkProcessConnection*);
+#endif
+
 private:
     WebProcess();
 
@@ -228,7 +236,10 @@ private:
     void getSitesWithPluginData(const Vector<String>& pluginPaths, uint64_t callbackID);
     void clearPluginSiteData(const Vector<String>& pluginPaths, const Vector<String>& sites, uint64_t flags, uint64_t maxAgeInSeconds, uint64_t callbackID);
 #endif
-    
+
+#if ENABLE(NETWORK_PROCESS)
+    void networkProcessCrashed(CoreIPC::Connection*);
+#endif
 #if ENABLE(PLUGIN_PROCESS)
     void pluginProcessCrashed(CoreIPC::Connection*, const String& pluginPath);
 #endif
@@ -335,6 +346,11 @@ private:
     
     String m_localStorageDirectory;
 
+#if ENABLE(NETWORK_PROCESS)
+    void ensureNetworkProcessConnection();
+    RefPtr<NetworkProcessConnection> m_networkProcessConnection;
+#endif
+
 #if ENABLE(PLUGIN_PROCESS)
     PluginProcessConnectionManager m_pluginProcessConnectionManager;
 #endif
index 378792f..2cc1e62 100644 (file)
@@ -63,6 +63,11 @@ messages -> WebProcess {
     GetSitesWithPluginData(Vector<WTF::String> pluginPaths, uint64_t callbackID)
     ClearPluginSiteData(Vector<WTF::String> pluginPaths, Vector<WTF::String> sites, uint64_t flags, uint64_t maxAgeInSeconds, uint64_t callbackID)
 #endif
+
+#if ENABLE(NETWORK_PROCESS)
+    NetworkProcessCrashed() DispatchOnConnectionQueue
+#endif
+
 #if ENABLE(PLUGIN_PROCESS)
     PluginProcessCrashed(String pluginProcess) DispatchOnConnectionQueue
 #endif