Move loading responsibility out of WebResourceLoadScheduler into a new WebResourceLoader
authorbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 14 Nov 2012 23:59:01 +0000 (23:59 +0000)
committerbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 14 Nov 2012 23:59:01 +0000 (23:59 +0000)
https://bugs.webkit.org/show_bug.cgi?id=102259

Reviewed by Alexey Proskuryakov.

Add a new WebResourceLoader message class which allows NetworkResourceLoader to message
WebResourceLoaders directly.

Consolidate the NetworkProcessConnection and WebResourceLoadScheduler messaging responsibilities
directly into WebResourceLoader.

Build-system infrastructure stuff:
* DerivedSources.make:
* Platform/CoreIPC/MessageID.h:
* WebKit2.xcodeproj/project.pbxproj:

Message directly to WebResourceLoader instead of NetworkProcessConnection:
* NetworkProcess/NetworkResourceLoader.cpp:
(WebKit::NetworkResourceLoader::connection):
(WebKit::NetworkResourceLoader::didReceiveResponse):
(WebKit::NetworkResourceLoader::didReceiveData):
(WebKit::NetworkResourceLoader::didFinishLoading):
(WebKit::NetworkResourceLoader::didFail):
(WebKit::NetworkResourceLoader::willSendRequest):
* NetworkProcess/NetworkResourceLoader.h:
(WebKit::NetworkResourceLoader::destinationID):

For now handle the only relevant message class which is the WebResourceLoader class:
* WebProcess/Network/NetworkProcessConnection.cpp:
(WebKit::NetworkProcessConnection::didReceiveMessage):
* WebProcess/Network/NetworkProcessConnection.h:
* WebProcess/Network/NetworkProcessConnection.messages.in:

Allow access to WebResourceLoaders by identifier:
* WebProcess/Network/WebResourceLoadScheduler.cpp:
* WebProcess/Network/WebResourceLoadScheduler.h:
(WebKit::WebResourceLoadScheduler::webResourceLoaderForIdentifier):

Directly handle resource loading messages instead of having WebResourceLoadScheduler do it:
* WebProcess/Network/WebResourceLoader.cpp:
(WebKit::WebResourceLoader::willSendRequest):
(WebKit::WebResourceLoader::didReceiveResponse):
(WebKit::WebResourceLoader::didReceiveData):
(WebKit::WebResourceLoader::didFinishResourceLoad):
(WebKit::WebResourceLoader::didFailResourceLoad):
(WebKit::WebResourceLoader::didReceiveResource):
* WebProcess/Network/WebResourceLoader.h:
* WebProcess/Network/WebResourceLoader.messages.in:

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

14 files changed:
Source/WebKit2/ChangeLog
Source/WebKit2/DerivedSources.make
Source/WebKit2/NetworkProcess/NetworkResourceLoader.cpp
Source/WebKit2/NetworkProcess/NetworkResourceLoader.h
Source/WebKit2/Platform/CoreIPC/MessageID.h
Source/WebKit2/WebKit2.xcodeproj/project.pbxproj
Source/WebKit2/WebProcess/Network/NetworkProcessConnection.cpp
Source/WebKit2/WebProcess/Network/NetworkProcessConnection.h
Source/WebKit2/WebProcess/Network/NetworkProcessConnection.messages.in
Source/WebKit2/WebProcess/Network/WebResourceLoadScheduler.cpp
Source/WebKit2/WebProcess/Network/WebResourceLoadScheduler.h
Source/WebKit2/WebProcess/Network/WebResourceLoader.cpp
Source/WebKit2/WebProcess/Network/WebResourceLoader.h
Source/WebKit2/WebProcess/Network/WebResourceLoader.messages.in [new file with mode: 0644]

index 0cbf5dc..dad91b6 100644 (file)
@@ -1,3 +1,54 @@
+2012-11-14  Brady Eidson  <beidson@apple.com>
+
+        Move loading responsibility out of WebResourceLoadScheduler into a new WebResourceLoader
+        https://bugs.webkit.org/show_bug.cgi?id=102259
+
+        Reviewed by Alexey Proskuryakov.
+
+        Add a new WebResourceLoader message class which allows NetworkResourceLoader to message
+        WebResourceLoaders directly.
+
+        Consolidate the NetworkProcessConnection and WebResourceLoadScheduler messaging responsibilities
+        directly into WebResourceLoader.
+
+        Build-system infrastructure stuff:
+        * DerivedSources.make:
+        * Platform/CoreIPC/MessageID.h:
+        * WebKit2.xcodeproj/project.pbxproj:
+
+        Message directly to WebResourceLoader instead of NetworkProcessConnection:
+        * NetworkProcess/NetworkResourceLoader.cpp:
+        (WebKit::NetworkResourceLoader::connection):
+        (WebKit::NetworkResourceLoader::didReceiveResponse):
+        (WebKit::NetworkResourceLoader::didReceiveData):
+        (WebKit::NetworkResourceLoader::didFinishLoading):
+        (WebKit::NetworkResourceLoader::didFail):
+        (WebKit::NetworkResourceLoader::willSendRequest):
+        * NetworkProcess/NetworkResourceLoader.h:
+        (WebKit::NetworkResourceLoader::destinationID):
+
+        For now handle the only relevant message class which is the WebResourceLoader class:
+        * WebProcess/Network/NetworkProcessConnection.cpp:
+        (WebKit::NetworkProcessConnection::didReceiveMessage):
+        * WebProcess/Network/NetworkProcessConnection.h:
+        * WebProcess/Network/NetworkProcessConnection.messages.in:
+
+        Allow access to WebResourceLoaders by identifier:
+        * WebProcess/Network/WebResourceLoadScheduler.cpp:
+        * WebProcess/Network/WebResourceLoadScheduler.h:
+        (WebKit::WebResourceLoadScheduler::webResourceLoaderForIdentifier):
+
+        Directly handle resource loading messages instead of having WebResourceLoadScheduler do it:
+        * WebProcess/Network/WebResourceLoader.cpp:
+        (WebKit::WebResourceLoader::willSendRequest):
+        (WebKit::WebResourceLoader::didReceiveResponse):
+        (WebKit::WebResourceLoader::didReceiveData):
+        (WebKit::WebResourceLoader::didFinishResourceLoad):
+        (WebKit::WebResourceLoader::didFailResourceLoad):
+        (WebKit::WebResourceLoader::didReceiveResource):
+        * WebProcess/Network/WebResourceLoader.h:
+        * WebProcess/Network/WebResourceLoader.messages.in:
+
 2012-11-14  Andy Estes  <aestes@apple.com>
 
         Fix the Lion build after r134681.
index dd79f8e..a928c7f 100644 (file)
@@ -105,6 +105,7 @@ MESSAGE_RECEIVERS = \
     WebProcessProxy \
     WebResourceCacheManager \
     WebResourceCacheManagerProxy \
+    WebResourceLoader \
 #
 
 SCRIPTS = \
index aaa5aca..873bf11 100644 (file)
 #include "Logging.h"
 #include "NetworkConnectionToWebProcess.h"
 #include "NetworkProcess.h"
-#include "NetworkProcessConnectionMessages.h"
 #include "NetworkResourceLoadParameters.h"
 #include "RemoteNetworkingContext.h"
 #include "SharedMemory.h"
 #include "WebCoreArgumentCoders.h"
+#include "WebResourceLoaderMessages.h"
 #include <WebCore/NotImplemented.h>
 #include <WebCore/ResourceBuffer.h>
 #include <WebCore/ResourceHandle.h>
@@ -64,6 +64,11 @@ NetworkResourceLoader::~NetworkResourceLoader()
         m_connection->unregisterObserver(this);
 }
 
+CoreIPC::Connection* NetworkResourceLoader::connection() const
+{
+    return m_connection->connection();
+}
+
 ResourceLoadPriority NetworkResourceLoader::priority() const
 {
     return m_requestParameters.priority();
@@ -146,7 +151,7 @@ void NetworkResourceLoader::connectionToWebProcessDidClose(NetworkConnectionToWe
 void NetworkResourceLoader::didReceiveResponse(ResourceHandle*, const ResourceResponse& response)
 {
     // FIXME (NetworkProcess): Cache the response.
-    connectionToWebProcess()->connection()->send(Messages::NetworkProcessConnection::DidReceiveResponse(m_identifier, response), 0);
+    send(Messages::WebResourceLoader::DidReceiveResponse(response));
 }
 
 void NetworkResourceLoader::didReceiveData(ResourceHandle*, const char* data, int length, int encodedDataLength)
@@ -155,14 +160,14 @@ void NetworkResourceLoader::didReceiveData(ResourceHandle*, const char* data, in
     // Such buffering will need to be thread safe, as this callback is happening on a background thread.
     
     CoreIPC::DataReference dataReference(reinterpret_cast<const uint8_t*>(data), length);
-    connectionToWebProcess()->connection()->send(Messages::NetworkProcessConnection::DidReceiveData(m_identifier, dataReference, encodedDataLength, false), 0);
+    send(Messages::WebResourceLoader::DidReceiveData(dataReference, encodedDataLength, false));
 }
 
 void NetworkResourceLoader::didFinishLoading(ResourceHandle*, double finishTime)
 {
     // FIXME (NetworkProcess): For the memory cache we'll need to update the finished status of the cached resource here.
     // Such bookkeeping will need to be thread safe, as this callback is happening on a background thread.
-    connectionToWebProcess()->connection()->send(Messages::NetworkProcessConnection::DidFinishResourceLoad(m_identifier, finishTime), 0);
+    send(Messages::WebResourceLoader::DidFinishResourceLoad(finishTime));
     scheduleStopOnMainThread();
 }
 
@@ -170,7 +175,7 @@ void NetworkResourceLoader::didFail(ResourceHandle*, const ResourceError& error)
 {
     // FIXME (NetworkProcess): For the memory cache we'll need to update the finished status of the cached resource here.
     // Such bookkeeping will need to be thread safe, as this callback is happening on a background thread.
-    connectionToWebProcess()->connection()->send(Messages::NetworkProcessConnection::DidFailResourceLoad(m_identifier, error), 0);
+    send(Messages::WebResourceLoader::DidFailResourceLoad(error));
     scheduleStopOnMainThread();
 }
 
@@ -198,10 +203,7 @@ void NetworkResourceLoader::willSendRequest(ResourceHandle*, ResourceRequest& re
 
     uint64_t requestID = generateWillSendRequestID();
 
-    if (!connectionToWebProcess()->connection()->send(Messages::NetworkProcessConnection::WillSendRequest(requestID, m_identifier, request, redirectResponse), 0)) {
-        // FIXME (NetworkProcess): What should we do if we can't send the message?
-        return;
-    }
+    send(Messages::WebResourceLoader::WillSendRequest(requestID, request, redirectResponse));
     
     OwnPtr<ResourceRequest> newRequest = responseMap().waitForResponse(requestID);
     request = *newRequest;
index bf2132b..8ff2232 100644 (file)
@@ -28,6 +28,7 @@
 
 #if ENABLE(NETWORK_PROCESS)
 
+#include "MessageSender.h"
 #include "NetworkConnectionToWebProcess.h"
 #include "NetworkResourceLoadParameters.h"
 #include <WebCore/ResourceHandleClient.h>
@@ -44,7 +45,7 @@ namespace WebKit {
 class RemoteNetworkingContext;
 typedef uint64_t ResourceLoadIdentifier;
 
-class NetworkResourceLoader : public RefCounted<NetworkResourceLoader>, public NetworkConnectionToWebProcessObserver, public WebCore::ResourceHandleClient {
+class NetworkResourceLoader : public RefCounted<NetworkResourceLoader>, public NetworkConnectionToWebProcessObserver, public WebCore::ResourceHandleClient, public CoreIPC::MessageSender<NetworkResourceLoader> {
 public:
     static RefPtr<NetworkResourceLoader> create(const NetworkResourceLoadParameters& parameters, ResourceLoadIdentifier identifier, NetworkConnectionToWebProcess* connection)
     {
@@ -53,6 +54,10 @@ public:
     
     ~NetworkResourceLoader();
 
+    // Used by MessageSender.
+    CoreIPC::Connection* connection() const;
+    uint64_t destinationID() const { return identifier(); }
+    
     void start();
 
     virtual void connectionToWebProcessDidClose(NetworkConnectionToWebProcess*) OVERRIDE;
index 47fdf01..5f0a9f9 100644 (file)
@@ -118,6 +118,7 @@ enum MessageClass {
 
     // Messages sent by the network process to a web process.
     MessageClassNetworkProcessConnection,
+    MessageClassWebResourceLoader,
     
 #if ENABLE(SHARED_WORKER_PROCESS)
     // Messages sent by the UI process to the shared worker process.
index 2b2f53e..c520863 100644 (file)
                51DD9F2816367DA2001578E9 /* NetworkConnectionToWebProcessMessageReceiver.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 51DD9F2616367DA2001578E9 /* NetworkConnectionToWebProcessMessageReceiver.cpp */; };
                51DD9F2916367DA2001578E9 /* NetworkConnectionToWebProcessMessages.h in Headers */ = {isa = PBXBuildFile; fileRef = 51DD9F2716367DA2001578E9 /* NetworkConnectionToWebProcessMessages.h */; };
                51EFC1CF1524E62500C9A938 /* WKBundleDOMWindowExtension.h in Headers */ = {isa = PBXBuildFile; fileRef = 51FA2D541521118600C1BA0B /* WKBundleDOMWindowExtension.h */; settings = {ATTRIBUTES = (Private, ); }; };
+               51F060E01654317F00F3281B /* WebResourceLoaderMessages.h in Headers */ = {isa = PBXBuildFile; fileRef = 51F060DE1654317500F3281B /* WebResourceLoaderMessages.h */; };
+               51F060E11654318500F3281B /* WebResourceLoaderMessageReceiver.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 51F060DD1654317500F3281B /* WebResourceLoaderMessageReceiver.cpp */; };
                51FA2D7415212DF100C1BA0B /* InjectedBundleDOMWindowExtension.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 51FA2D5C15211A5000C1BA0B /* InjectedBundleDOMWindowExtension.cpp */; };
                51FA2D7715212E2600C1BA0B /* WKBundleDOMWindowExtension.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 51FA2D7515212E1E00C1BA0B /* WKBundleDOMWindowExtension.cpp */; };
                51FB08FF1639DE1A00EC324A /* WebResourceLoadScheduler.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 51ABF65616392F1500132A7A /* WebResourceLoadScheduler.cpp */; };
                5105B0F31630872E00E27709 /* NetworkProcessProxy.messages.in */ = {isa = PBXFileReference; lastKnownFileType = text; path = NetworkProcessProxy.messages.in; sourceTree = "<group>"; };
                510AFFB716542048001BA05E /* WebResourceLoader.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = WebResourceLoader.cpp; path = Network/WebResourceLoader.cpp; sourceTree = "<group>"; };
                510AFFB816542048001BA05E /* WebResourceLoader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = WebResourceLoader.h; path = Network/WebResourceLoader.h; sourceTree = "<group>"; };
+               510AFFCE16542CBD001BA05E /* WebResourceLoader.messages.in */ = {isa = PBXFileReference; lastKnownFileType = text; name = WebResourceLoader.messages.in; path = Network/WebResourceLoader.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>"; };
                51D130571382F10500351EDD /* WebProcessProxyMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebProcessProxyMac.mm; sourceTree = "<group>"; };
                51DD9F2616367DA2001578E9 /* NetworkConnectionToWebProcessMessageReceiver.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = NetworkConnectionToWebProcessMessageReceiver.cpp; sourceTree = "<group>"; };
                51DD9F2716367DA2001578E9 /* NetworkConnectionToWebProcessMessages.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NetworkConnectionToWebProcessMessages.h; sourceTree = "<group>"; };
+               51F060DD1654317500F3281B /* WebResourceLoaderMessageReceiver.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = WebResourceLoaderMessageReceiver.cpp; sourceTree = "<group>"; };
+               51F060DE1654317500F3281B /* WebResourceLoaderMessages.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WebResourceLoaderMessages.h; sourceTree = "<group>"; };
                51FA2D541521118600C1BA0B /* WKBundleDOMWindowExtension.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKBundleDOMWindowExtension.h; sourceTree = "<group>"; };
                51FA2D5A15211A1E00C1BA0B /* InjectedBundleDOMWindowExtension.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InjectedBundleDOMWindowExtension.h; sourceTree = "<group>"; };
                51FA2D5C15211A5000C1BA0B /* InjectedBundleDOMWindowExtension.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = InjectedBundleDOMWindowExtension.cpp; sourceTree = "<group>"; };
                                51ABF65716392F1500132A7A /* WebResourceLoadScheduler.h */,
                                510AFFB716542048001BA05E /* WebResourceLoader.cpp */,
                                510AFFB816542048001BA05E /* WebResourceLoader.h */,
+                               510AFFCE16542CBD001BA05E /* WebResourceLoader.messages.in */,
                        );
                        name = Network;
                        sourceTree = "<group>";
                                33367652130C9ECA006C9DE2 /* WebResourceCacheManagerMessages.h */,
                                33367653130C9ECA006C9DE2 /* WebResourceCacheManagerProxyMessageReceiver.cpp */,
                                33367654130C9ECA006C9DE2 /* WebResourceCacheManagerProxyMessages.h */,
+                               51F060DD1654317500F3281B /* WebResourceLoaderMessageReceiver.cpp */,
+                               51F060DE1654317500F3281B /* WebResourceLoaderMessages.h */,
                        );
                        name = "Derived Sources";
                        path = DerivedSources/WebKit2;
                                2984F57D164B915F004BC0C6 /* CustomProtocolManagerProxyMessages.h in Headers */,
                                2984F581164B9BBD004BC0C6 /* CustomProtocolManager.h in Headers */,
                                2984F589164BA095004BC0C6 /* CustomProtocolManagerMessages.h in Headers */,
+                               51F060E01654317F00F3281B /* WebResourceLoaderMessages.h in Headers */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
                                2984F57C164B915F004BC0C6 /* CustomProtocolManagerProxyMessageReceiver.cpp in Sources */,
                                2984F583164B9BD9004BC0C6 /* CustomProtocolManagerMac.mm in Sources */,
                                2984F588164BA095004BC0C6 /* CustomProtocolManagerMessageReceiver.cpp in Sources */,
+                               51F060E11654318500F3281B /* WebResourceLoaderMessageReceiver.cpp in Sources */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
index 4f3dae7..d684754 100644 (file)
@@ -51,10 +51,13 @@ NetworkProcessConnection::~NetworkProcessConnection()
 
 void NetworkProcessConnection::didReceiveMessage(CoreIPC::Connection* connection, CoreIPC::MessageID messageID, CoreIPC::MessageDecoder& decoder)
 {
-    if (messageID.is<CoreIPC::MessageClassNetworkProcessConnection>()) {
-        didReceiveNetworkProcessConnectionMessage(connection, messageID, decoder);
+    if (messageID.is<CoreIPC::MessageClassWebResourceLoader>()) {
+        if (WebResourceLoader* webResourceLoader = WebProcess::shared().webResourceLoadScheduler().webResourceLoaderForIdentifier(decoder.destinationID()))
+            webResourceLoader->didReceiveWebResourceLoaderMessage(connection, messageID, decoder);
+        
         return;
     }
+
     ASSERT_NOT_REACHED();
 }
 
@@ -73,47 +76,6 @@ void NetworkProcessConnection::didReceiveInvalidMessage(CoreIPC::Connection*, Co
 {
 }
 
-void NetworkProcessConnection::willSendRequest(uint64_t requestID, ResourceLoadIdentifier resourceLoadIdentifier, const ResourceRequest& proposedRequest, const ResourceResponse& redirectResponse)
-{
-    ResourceRequest newRequest = proposedRequest;
-    WebProcess::shared().webResourceLoadScheduler().willSendRequest(resourceLoadIdentifier, newRequest, redirectResponse);
-
-    WebProcess::shared().networkConnection()->connection()->send(Messages::NetworkConnectionToWebProcess::WillSendRequestHandled(requestID, newRequest), 0);
-}
-
-void NetworkProcessConnection::didReceiveResponse(ResourceLoadIdentifier resourceLoadIdentifier, const ResourceResponse& response)
-{
-    WebProcess::shared().webResourceLoadScheduler().didReceiveResponse(resourceLoadIdentifier, response);
-}
-
-void NetworkProcessConnection::didReceiveData(ResourceLoadIdentifier resourceLoadIdentifier, const CoreIPC::DataReference& data, int64_t encodedDataLength, bool allAtOnce)
-{
-    WebProcess::shared().webResourceLoadScheduler().didReceiveData(resourceLoadIdentifier, reinterpret_cast<const char*>(data.data()), data.size(), encodedDataLength, allAtOnce);
-}
-
-void NetworkProcessConnection::didFinishResourceLoad(ResourceLoadIdentifier resourceLoadIdentifier, double finishTime)
-{
-    WebProcess::shared().webResourceLoadScheduler().didFinishResourceLoad(resourceLoadIdentifier, finishTime);
-}
-
-void NetworkProcessConnection::didFailResourceLoad(ResourceLoadIdentifier resourceLoadIdentifier, const ResourceError& error)
-{
-    WebProcess::shared().webResourceLoadScheduler().didFailResourceLoad(resourceLoadIdentifier, error);
-}
-
-void NetworkProcessConnection::didReceiveResource(ResourceLoadIdentifier resourceLoadIdentifier, const ShareableResource::Handle& handle, double finishTime)
-{
-    RefPtr<ResourceBuffer> resourceBuffer;
-
-    RefPtr<ShareableResource> resource = ShareableResource::create(handle);
-    if (resource)
-        resourceBuffer = WebResourceBuffer::create(resource.release());
-    else
-        resourceBuffer = ResourceBuffer::create();
-    
-    WebProcess::shared().webResourceLoadScheduler().didReceiveResource(resourceLoadIdentifier, *resourceBuffer, finishTime);
-}
-
 } // namespace WebKit
 
 #endif // ENABLE(NETWORK_PROCESS)
index 764eee9..bab54cf 100644 (file)
@@ -27,7 +27,6 @@
 #define NetworkProcessConnection_h
 
 #include "Connection.h"
-#include "ShareableResource.h"
 #include <wtf/RefCounted.h>
 #include <wtf/text/WTFString.h>
 
@@ -66,17 +65,6 @@ private:
     virtual void didClose(CoreIPC::Connection*);
     virtual void didReceiveInvalidMessage(CoreIPC::Connection*, CoreIPC::StringReference messageReceiverName, CoreIPC::StringReference messageName) OVERRIDE;
 
-    void didReceiveNetworkProcessConnectionMessage(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::MessageDecoder&);
-    void didReceiveSyncNetworkProcessConnectionMessage(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::MessageDecoder&, OwnPtr<CoreIPC::MessageEncoder>&);
-
-    void willSendRequest(uint64_t requestID, ResourceLoadIdentifier, const WebCore::ResourceRequest&, const WebCore::ResourceResponse&);
-    void didReceiveResponse(ResourceLoadIdentifier, const WebCore::ResourceResponse&);
-    void didReceiveData(ResourceLoadIdentifier, const CoreIPC::DataReference&, int64_t encodedDataLength, bool allAtOnce);
-    void didFinishResourceLoad(ResourceLoadIdentifier, double finishTime);
-    void didFailResourceLoad(ResourceLoadIdentifier, const WebCore::ResourceError&);
-
-    void didReceiveResource(ResourceLoadIdentifier, const ShareableResource::Handle&, double finishTime);
-
     // The connection from the web process to the network process.
     RefPtr<CoreIPC::Connection> m_connection;
 };
index 3e09a1e..6b375a5 100644 (file)
 
 messages -> NetworkProcessConnection {
 
-    // FIXME (NetworkProcess): We'll need much more granularity for response messages.
-    WillSendRequest(uint64_t requestID, uint64_t resourceLoadIdentifier, WebCore::ResourceRequest request, WebCore::ResourceResponse redirectResponse)
-    DidReceiveResponse(uint64_t resourceLoadIdentifier, WebCore::ResourceResponse response)
-    DidReceiveData(uint64_t resourceLoadIdentifier, CoreIPC::DataReference data, int64_t encodedDataLength, bool allAtOnce)
-    DidFinishResourceLoad(uint64_t resourceLoadIdentifier, double finishTime)
-    DidFailResourceLoad(uint64_t resourceLoadIdentifier, WebCore::ResourceError error)
-
-    // DidReceiveResource is for when we have the entire resource data available at once, such as when the resource is cached in memory
-    DidReceiveResource(uint64_t resourceLoadIdentifier, WebKit::ShareableResource::Handle resource, double finishTime)
 }
 
 #endif // ENABLE(NETWORK_PROCESS)
index b84ad02..46f031c 100644 (file)
@@ -104,7 +104,7 @@ void WebResourceLoadScheduler::scheduleLoad(ResourceLoader* resourceLoader, Reso
     }
     
     resourceLoader->setIdentifier(identifier);
-    m_webResourceLoaders.set(identifier, WebResourceLoader::create(identifier, resourceLoader));
+    m_webResourceLoaders.set(identifier, WebResourceLoader::create(resourceLoader));
     
     notifyDidScheduleResourceRequest(resourceLoader);
 }
@@ -188,69 +188,6 @@ void WebResourceLoadScheduler::setSerialLoadingEnabled(bool enabled)
     WebProcess::shared().networkConnection()->connection()->sendSync(Messages::NetworkConnectionToWebProcess::SetSerialLoadingEnabled(enabled), Messages::NetworkConnectionToWebProcess::SetSerialLoadingEnabled::Reply(), 0);
 }
 
-void WebResourceLoadScheduler::willSendRequest(ResourceLoadIdentifier identifier, WebCore::ResourceRequest& request, const WebCore::ResourceResponse& redirectResponse)
-{
-    RefPtr<ResourceLoader> loader = m_webResourceLoaders.get(identifier)->coreLoader();
-    ASSERT(loader);
-
-    LOG(Network, "(WebProcess) WebResourceLoadScheduler::willSendRequest to '%s'", request.url().string().utf8().data());
-    loader->willSendRequest(request, redirectResponse);
-}
-
-void WebResourceLoadScheduler::didReceiveResponse(ResourceLoadIdentifier identifier, const WebCore::ResourceResponse& response)
-{
-    RefPtr<ResourceLoader> loader = m_webResourceLoaders.get(identifier)->coreLoader();
-    ASSERT(loader);
-
-    LOG(Network, "(WebProcess) WebResourceLoadScheduler::didReceiveResponse for '%s'", loader->url().string().utf8().data());
-    loader->didReceiveResponse(response);
-}
-
-void WebResourceLoadScheduler::didReceiveData(ResourceLoadIdentifier identifier, const char* data, int size, int64_t encodedDataLength, bool allAtOnce)
-{
-    RefPtr<ResourceLoader> loader = m_webResourceLoaders.get(identifier)->coreLoader();
-    ASSERT(loader);
-
-    LOG(Network, "(WebProcess) WebResourceLoadScheduler::didReceiveData of size %i for '%s'", size, loader->url().string().utf8().data());
-    loader->didReceiveData(data, size, encodedDataLength, allAtOnce);
-}
-
-void WebResourceLoadScheduler::didFinishResourceLoad(ResourceLoadIdentifier identifier, double finishTime)
-{
-    RefPtr<ResourceLoader> loader = m_webResourceLoaders.get(identifier)->coreLoader();
-    ASSERT(loader);
-
-    LOG(Network, "(WebProcess) WebResourceLoadScheduler::didFinishResourceLoad for '%s'", loader->url().string().utf8().data());
-    loader->didFinishLoading(finishTime);
-}
-
-void WebResourceLoadScheduler::didReceiveResource(ResourceLoadIdentifier identifier, const ResourceBuffer& buffer, double finishTime)
-{    
-    RefPtr<ResourceLoader> loader = m_webResourceLoaders.get(identifier)->coreLoader();
-    ASSERT(loader);
-
-    LOG(Network, "(WebProcess) WebResourceLoadScheduler::didReceiveResource for '%s'", loader->url().string().utf8().data());
-    
-    // Only send data to the didReceiveData callback if it exists.
-    if (!buffer.isEmpty()) {
-        // FIXME (NetworkProcess): Give ResourceLoader the ability to take ResourceBuffer arguments.
-        // That will allow us to pass it along to CachedResources and allow them to hang on to the shared memory behind the scenes.
-        loader->didReceiveData(reinterpret_cast<const char*>(buffer.data()), buffer.size(), -1 /* encodedDataLength */, true);
-    }
-
-    loader->didFinishLoading(finishTime);
-}
-
-void WebResourceLoadScheduler::didFailResourceLoad(ResourceLoadIdentifier identifier, const WebCore::ResourceError& error)
-{
-    RefPtr<ResourceLoader> loader = m_webResourceLoaders.get(identifier)->coreLoader();
-    ASSERT(loader);
-
-    LOG(Network, "(WebProcess) WebResourceLoadScheduler::didFailResourceLoad for '%s'", loader->url().string().utf8().data());
-    
-    loader->didFail(error);
-}
-
 } // namespace WebKit
 
 #endif // ENABLE(NETWORK_PROCESS)
index 0c69e1b..d6ca671 100644 (file)
@@ -26,6 +26,7 @@
 #ifndef WebResourceLoadScheduler_h
 #define WebResourceLoadScheduler_h
 
+#include "WebResourceLoader.h"
 #include <WebCore/ResourceLoadPriority.h>
 #include <WebCore/ResourceLoadScheduler.h>
 #include <WebCore/ResourceLoader.h>
@@ -35,7 +36,6 @@
 namespace WebKit {
 
 class NetworkProcessConnection;
-class WebResourceLoader;
 typedef uint64_t ResourceLoadIdentifier;
 
 class WebResourceLoadScheduler : public WebCore::ResourceLoadScheduler {
@@ -58,14 +58,7 @@ public:
 
     virtual void setSerialLoadingEnabled(bool) OVERRIDE;
 
-    // FIXME (NetworkProcess): Get the ResourceLoadScheduler out of the business of vending this data directly to ResourceLoaders.
-    // The Messages should be sent to an object that proxies the ResourceLoader directly.
-    void willSendRequest(ResourceLoadIdentifier, WebCore::ResourceRequest&, const WebCore::ResourceResponse& redirectResponse);
-    void didReceiveResponse(ResourceLoadIdentifier, const WebCore::ResourceResponse&);
-    void didReceiveData(ResourceLoadIdentifier, const char*, int, int64_t encodedDataLength, bool allAtOnce);
-    void didFinishResourceLoad(ResourceLoadIdentifier, double finishTime);
-    void didFailResourceLoad(ResourceLoadIdentifier, const WebCore::ResourceError&);
-    void didReceiveResource(ResourceLoadIdentifier, const WebCore::ResourceBuffer&, double finishTime);
+    WebResourceLoader* webResourceLoaderForIdentifier(ResourceLoadIdentifier identifier) const { return m_webResourceLoaders.get(identifier).get(); }
 
 private:
     void scheduleLoad(WebCore::ResourceLoader*, WebCore::ResourceLoadPriority);
index 098453f..6f4c3b8 100644 (file)
 
 #if ENABLE(NETWORK_PROCESS)
 
+#include "DataReference.h"
+#include "Logging.h"
+#include "NetworkConnectionToWebProcessMessages.h"
+#include "NetworkProcessConnection.h"
+#include "WebCoreArgumentCoders.h"
+#include "WebProcess.h"
 #include <WebCore/ResourceLoader.h>
 
 using namespace WebCore;
 
 namespace WebKit {
 
-PassRefPtr<WebResourceLoader> WebResourceLoader::create(ResourceLoadIdentifier identifier, PassRefPtr<ResourceLoader> coreLoader)
+PassRefPtr<WebResourceLoader> WebResourceLoader::create(PassRefPtr<ResourceLoader> coreLoader)
 {
-    return adoptRef(new WebResourceLoader(identifier, coreLoader));
+    return adoptRef(new WebResourceLoader(coreLoader));
 }
 
-WebResourceLoader::WebResourceLoader(ResourceLoadIdentifier identifier, PassRefPtr<WebCore::ResourceLoader> coreLoader)
-    : m_resourceLoadIdentifier(identifier)
-    , m_coreLoader(coreLoader)
+WebResourceLoader::WebResourceLoader(PassRefPtr<WebCore::ResourceLoader> coreLoader)
+    : m_coreLoader(coreLoader)
 {
 }
 
@@ -49,6 +54,58 @@ WebResourceLoader::~WebResourceLoader()
 {
 }
 
+void WebResourceLoader::willSendRequest(uint64_t requestID, const ResourceRequest& proposedRequest, const ResourceResponse& redirectResponse)
+{
+    LOG(Network, "(WebProcess) WebResourceLoader::willSendRequest to '%s'", proposedRequest.url().string().utf8().data());
+    
+    ResourceRequest newRequest = proposedRequest;
+    m_coreLoader->willSendRequest(newRequest, redirectResponse);
+
+    WebProcess::shared().networkConnection()->connection()->send(Messages::NetworkConnectionToWebProcess::WillSendRequestHandled(requestID, newRequest), 0);
+}
+
+void WebResourceLoader::didReceiveResponse(const WebCore::ResourceResponse& response)
+{
+    LOG(Network, "(WebProcess) WebResourceLoader::didReceiveResponse for '%s'", m_coreLoader->url().string().utf8().data());
+    m_coreLoader->didReceiveResponse(response);
+}
+
+void WebResourceLoader::didReceiveData(const CoreIPC::DataReference& data, int64_t encodedDataLength, bool allAtOnce)
+{
+    LOG(Network, "(WebProcess) WebResourceLoader::didReceiveData of size %i for '%s'", (int)data.size(), m_coreLoader->url().string().utf8().data());
+    m_coreLoader->didReceiveData(reinterpret_cast<const char*>(data.data()), data.size(), encodedDataLength, allAtOnce);
+}
+
+void WebResourceLoader::didFinishResourceLoad(double finishTime)
+{
+    LOG(Network, "(WebProcess) WebResourceLoader::didFinishResourceLoad for '%s'", m_coreLoader->url().string().utf8().data());
+    m_coreLoader->didFinishLoading(finishTime);
+}
+
+void WebResourceLoader::didFailResourceLoad(const ResourceError& error)
+{
+    LOG(Network, "(WebProcess) WebResourceLoader::didFailResourceLoad for '%s'", m_coreLoader->url().string().utf8().data());
+    
+    m_coreLoader->didFail(error);
+}
+
+void WebResourceLoader::didReceiveResource(const ShareableResource::Handle& handle, double finishTime)
+{
+    LOG(Network, "(WebProcess) WebResourceLoader::didReceiveResource for '%s'", m_coreLoader->url().string().utf8().data());
+
+    RefPtr<ShareableResource> resource = ShareableResource::create(handle);
+
+    // Only send data to the didReceiveData callback if it exists.
+    if (!resource->size()) {
+        // FIXME (NetworkProcess): Give ResourceLoader the ability to take ResourceBuffer arguments.
+        // That will allow us to pass it along to CachedResources and allow them to hang on to the shared memory behind the scenes.
+        // FIXME (NetworkProcess): Pass along the correct value for encodedDataLength.
+        m_coreLoader->didReceiveData(reinterpret_cast<const char*>(resource->data()), resource->size(), -1 /* encodedDataLength */ , true);
+    }
+
+    m_coreLoader->didFinishLoading(finishTime);
+}
+
 } // namespace WebKit
 
 #endif // ENABLE(NETWORK_PROCESS)
index 9316d3e..c41ee35 100644 (file)
 
 #if ENABLE(NETWORK_PROCESS)
 
+#include "Connection.h"
+#include "ShareableResource.h"
 #include <wtf/PassRefPtr.h>
 #include <wtf/RefCounted.h>
 #include <wtf/RefPtr.h>
 
+namespace CoreIPC {
+class DataReference;
+}
+
 namespace WebCore {
+class ResourceBuffer;
+class ResourceError;
 class ResourceLoader;
+class ResourceRequest;
+class ResourceResponse;
 }
 
 namespace WebKit {
@@ -42,17 +52,22 @@ typedef uint64_t ResourceLoadIdentifier;
 
 class WebResourceLoader : public RefCounted<WebResourceLoader> {
 public:
-    static PassRefPtr<WebResourceLoader> create(ResourceLoadIdentifier, PassRefPtr<WebCore::ResourceLoader>);
+    static PassRefPtr<WebResourceLoader> create(PassRefPtr<WebCore::ResourceLoader>);
 
     ~WebResourceLoader();
 
-    WebCore::ResourceLoader* coreLoader() const { return m_coreLoader.get(); }
-    ResourceLoadIdentifier resourceLoadIdentifier() const { return m_resourceLoadIdentifier; }
+    void didReceiveWebResourceLoaderMessage(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::MessageDecoder&);
 
 private:
-    WebResourceLoader(ResourceLoadIdentifier, PassRefPtr<WebCore::ResourceLoader>);
+    WebResourceLoader(PassRefPtr<WebCore::ResourceLoader>);
+
+    void willSendRequest(uint64_t requestID, const WebCore::ResourceRequest&, const WebCore::ResourceResponse& redirectResponse);
+    void didReceiveResponse(const WebCore::ResourceResponse&);
+    void didReceiveData(const CoreIPC::DataReference&, int64_t encodedDataLength, bool allAtOnce);
+    void didFinishResourceLoad(double finishTime);
+    void didFailResourceLoad(const WebCore::ResourceError&);
+    void didReceiveResource(const ShareableResource::Handle&, double finishTime);
 
-    ResourceLoadIdentifier m_resourceLoadIdentifier;
     RefPtr<WebCore::ResourceLoader> m_coreLoader;
 };
 
diff --git a/Source/WebKit2/WebProcess/Network/WebResourceLoader.messages.in b/Source/WebKit2/WebProcess/Network/WebResourceLoader.messages.in
new file mode 100644 (file)
index 0000000..55a4295
--- /dev/null
@@ -0,0 +1,34 @@
+# 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.
+
+messages -> WebResourceLoader {
+
+    // FIXME (NetworkProcess): We'll need much more granularity for response messages.
+    WillSendRequest(uint64_t requestID, WebCore::ResourceRequest request, WebCore::ResourceResponse redirectResponse)
+    DidReceiveResponse(WebCore::ResourceResponse response)
+    DidReceiveData(CoreIPC::DataReference data, int64_t encodedDataLength, bool allAtOnce)
+    DidFinishResourceLoad(double finishTime)
+    DidFailResourceLoad(WebCore::ResourceError error)
+
+    // DidReceiveResource is for when we have the entire resource data available at once, such as when the resource is cached in memory
+    DidReceiveResource(WebKit::ShareableResource::Handle resource, double finishTime)
+}