summaryrefslogtreecommitdiffstats
path: root/ppapi/proxy/url_loader_resource.h
diff options
context:
space:
mode:
authorbbudge@chromium.org <bbudge@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-05-16 01:50:40 +0000
committerbbudge@chromium.org <bbudge@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-05-16 01:50:40 +0000
commit47cb253f15ca0e9dfcef8dd4b42bb5bc443c522f (patch)
treea71128d32bc0af6005739c13a99e851ad400d614 /ppapi/proxy/url_loader_resource.h
parent3af832f9c543e7866d375ba326fe659b6f3df939 (diff)
downloadchromium_src-47cb253f15ca0e9dfcef8dd4b42bb5bc443c522f.zip
chromium_src-47cb253f15ca0e9dfcef8dd4b42bb5bc443c522f.tar.gz
chromium_src-47cb253f15ca0e9dfcef8dd4b42bb5bc443c522f.tar.bz2
Implementation of URLLoader using PluginResource/ResourceHost.
This change is essentially the same as: https://codereview.chromium.org/11416363 Here's the description from that CL: "This doesn't use the resource call/reply infrastructure, but rather pipes WebKit callbacks to the plugin via unsolicited callbacks. This eliminates state tracking in the host which makes things simpler. This fixes some bugs in Close() as well to fix the below-mentioned bug." Other things contained in the original CL: - Add a GetPluginPID method to RendererPpapiHost. This is needed when the loader host Opens() a request. - Add a HandleDocumentLoad method to PluginDelegate and implements it in PepperPluginDelegateImpl. This creates the host for both in- and out-of-process proxies. - Removes the GetURLLoaderBufferedBytes function from the PPB_Proxy_Private interface. - Removes the HandleDocumentLoad implementation in the PPP_Instance_Proxy class. - Removes the document_loader_ field from webkit::ppapi::WebPluginImpl and changes the implementation to forward document load notifications to the PluginInstance. - Changes the PluginInstance to manage the document loader. This CL differs from the original in two ways. First, the trusted interface keeps the RegisterStatusCallback function. The NaCl plugin relies on this to generate progress messages back to the embedding page. Second, PluginInstance is changed to recognize when it's a NaCl instance, and to defer calling the plugin delegate's HandleDocumentLoad method until after the proxy is switched. In the meantime, it saves document events in a special loader object. When the proxy is switched, the delegate's HandleDocumentLoad method is called and the response and document events are then replayed through the new loader resource. BUG=69457 R=brettw@chromium.org Review URL: https://codereview.chromium.org/14371021 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@200412 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi/proxy/url_loader_resource.h')
-rw-r--r--ppapi/proxy/url_loader_resource.h146
1 files changed, 146 insertions, 0 deletions
diff --git a/ppapi/proxy/url_loader_resource.h b/ppapi/proxy/url_loader_resource.h
new file mode 100644
index 0000000..685ccfe
--- /dev/null
+++ b/ppapi/proxy/url_loader_resource.h
@@ -0,0 +1,146 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef PPAPI_PROXY_URL_LOADER_RESOURCE_H_
+#define PPAPI_PROXY_URL_LOADER_RESOURCE_H_
+
+#include <deque>
+
+#include "base/basictypes.h"
+#include "base/compiler_specific.h"
+#include "ppapi/c/trusted/ppb_url_loader_trusted.h"
+#include "ppapi/proxy/plugin_resource.h"
+#include "ppapi/proxy/ppapi_proxy_export.h"
+#include "ppapi/shared_impl/url_request_info_data.h"
+#include "ppapi/thunk/ppb_url_loader_api.h"
+
+namespace ppapi {
+namespace proxy {
+
+class URLResponseInfoResource;
+
+class PPAPI_PROXY_EXPORT URLLoaderResource
+ : public PluginResource,
+ public NON_EXPORTED_BASE(thunk::PPB_URLLoader_API) {
+ public:
+ // Constructor for plugin-initiated loads.
+ URLLoaderResource(Connection connection,
+ PP_Instance instance);
+
+ // Constructor for renderer-initiated (document) loads. The loader ID is the
+ // pending host ID for the already-created host in the renderer, and the
+ // response data is the response for the already-opened connection.
+ URLLoaderResource(Connection connection,
+ PP_Instance instance,
+ int pending_main_document_loader_id,
+ const URLResponseInfoData& data);
+
+ virtual ~URLLoaderResource();
+
+ // Resource override.
+ thunk::PPB_URLLoader_API* AsPPB_URLLoader_API() OVERRIDE;
+
+ // PPB_URLLoader_API implementation.
+ virtual int32_t Open(PP_Resource request_id,
+ scoped_refptr<TrackedCallback> callback) OVERRIDE;
+ virtual int32_t Open(const URLRequestInfoData& data,
+ int requestor_pid,
+ scoped_refptr<TrackedCallback> callback) OVERRIDE;
+ virtual int32_t FollowRedirect(
+ scoped_refptr<TrackedCallback> callback) OVERRIDE;
+ virtual PP_Bool GetUploadProgress(int64_t* bytes_sent,
+ int64_t* total_bytes_to_be_sent) OVERRIDE;
+ virtual PP_Bool GetDownloadProgress(
+ int64_t* bytes_received,
+ int64_t* total_bytes_to_be_received) OVERRIDE;
+ virtual PP_Resource GetResponseInfo() OVERRIDE;
+ virtual int32_t ReadResponseBody(
+ void* buffer,
+ int32_t bytes_to_read,
+ scoped_refptr<TrackedCallback> callback) OVERRIDE;
+ virtual int32_t FinishStreamingToFile(
+ scoped_refptr<TrackedCallback> callback) OVERRIDE;
+ virtual void Close() OVERRIDE;
+ virtual void GrantUniversalAccess() OVERRIDE;
+ virtual void RegisterStatusCallback(
+ PP_URLLoaderTrusted_StatusCallback callback) OVERRIDE;
+
+ // PluginResource implementation.
+ virtual void OnReplyReceived(const ResourceMessageReplyParams& params,
+ const IPC::Message& msg) OVERRIDE;
+
+ private:
+ enum Mode {
+ // The plugin has not called Open() yet.
+ MODE_WAITING_TO_OPEN,
+
+ // The plugin is waiting for the Open() or FollowRedirect callback.
+ MODE_OPENING,
+
+ // We've started to receive data and may receive more.
+ MODE_STREAMING_DATA,
+
+ // All data has been streamed or there was an error.
+ MODE_LOAD_COMPLETE
+ };
+
+ // IPC message handlers.
+ void OnPluginMsgReceivedResponse(const ResourceMessageReplyParams& params,
+ const URLResponseInfoData& data);
+ void OnPluginMsgSendData(const ResourceMessageReplyParams& params,
+ const IPC::Message& message);
+ void OnPluginMsgFinishedLoading(const ResourceMessageReplyParams& params,
+ int32_t result);
+ void OnPluginMsgUpdateProgress(const ResourceMessageReplyParams& params,
+ int64_t bytes_sent,
+ int64_t total_bytes_to_be_sent,
+ int64_t bytes_received,
+ int64_t total_bytes_to_be_received);
+
+ // Sends the defers loading message to the renderer to block or unblock the
+ // load.
+ void SetDefersLoading(bool defers_loading);
+
+ int32_t ValidateCallback(scoped_refptr<TrackedCallback> callback);
+
+ // Sets up |callback| as the pending callback. This should only be called once
+ // it is certain that |PP_OK_COMPLETIONPENDING| will be returned.
+ void RegisterCallback(scoped_refptr<TrackedCallback> callback);
+
+ void RunCallback(int32_t result);
+
+ // Saves the given response info to response_info_, handling file refs if
+ // necessary. This does not issue any callbacks.
+ void SaveResponseInfo(const URLResponseInfoData& data);
+
+ size_t FillUserBuffer();
+
+ Mode mode_;
+ URLRequestInfoData request_data_;
+
+ scoped_refptr<TrackedCallback> pending_callback_;
+
+ PP_URLLoaderTrusted_StatusCallback status_callback_;
+
+ std::deque<char> buffer_;
+ int64_t bytes_sent_;
+ int64_t total_bytes_to_be_sent_;
+ int64_t bytes_received_;
+ int64_t total_bytes_to_be_received_;
+ char* user_buffer_;
+ size_t user_buffer_size_;
+ int32_t done_status_;
+ bool is_streaming_to_file_;
+ bool is_asynchronous_load_suspended_;
+
+ // The response info if we've received it.
+ scoped_refptr<URLResponseInfoResource> response_info_;
+
+ DISALLOW_COPY_AND_ASSIGN(URLLoaderResource);
+};
+
+} // namespace proxy
+} // namespace ppapi
+
+#endif // PPAPI_PROXY_URL_LOADER_RESOURCE_H_ \ No newline at end of file