Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef PPAPI_PROXY_URL_LOADER_RESOURCE_H_ | |
| 6 #define PPAPI_PROXY_URL_LOADER_RESOURCE_H_ | |
| 7 | |
| 8 #include <deque> | |
| 9 | |
| 10 #include "base/basictypes.h" | |
| 11 #include "base/compiler_specific.h" | |
| 12 #include "ppapi/proxy/plugin_resource.h" | |
| 13 #include "ppapi/proxy/ppapi_proxy_export.h" | |
| 14 #include "ppapi/shared_impl/url_request_info_data.h" | |
| 15 #include "ppapi/thunk/ppb_url_loader_api.h" | |
| 16 | |
| 17 namespace ppapi { | |
| 18 namespace proxy { | |
| 19 | |
| 20 class URLResponseInfoResource; | |
| 21 | |
| 22 class PPAPI_PROXY_EXPORT URLLoaderResource | |
| 23 : public PluginResource, | |
| 24 public NON_EXPORTED_BASE(thunk::PPB_URLLoader_API) { | |
| 25 public: | |
| 26 // Constructor for plugin-initiated loads. | |
| 27 URLLoaderResource(Connection connection, | |
| 28 PP_Instance instance); | |
| 29 | |
| 30 // Constructor for renderer-initiated (document) loads. The loader ID is the | |
| 31 // pending host ID for the already-created host in the renderer, and the | |
| 32 // response data is the response for the already-opened connection. | |
|
bbudge
2012/12/17 21:13:14
Does a 'Connection' have a response? I thought a c
| |
| 33 URLLoaderResource(Connection connection, | |
| 34 PP_Instance instance, | |
| 35 int pending_main_document_loader_id, | |
| 36 const URLResponseInfoData& data); | |
| 37 | |
| 38 virtual ~URLLoaderResource(); | |
| 39 | |
| 40 // Resource override. | |
| 41 thunk::PPB_URLLoader_API* AsPPB_URLLoader_API() OVERRIDE; | |
| 42 | |
| 43 // PPB_URLLoader_API implementation. | |
| 44 virtual int32_t Open(PP_Resource request_id, | |
| 45 scoped_refptr<TrackedCallback> callback) OVERRIDE; | |
| 46 virtual int32_t Open(const URLRequestInfoData& data, | |
| 47 int requestor_pid, | |
| 48 scoped_refptr<TrackedCallback> callback) OVERRIDE; | |
| 49 virtual int32_t FollowRedirect( | |
| 50 scoped_refptr<TrackedCallback> callback) OVERRIDE; | |
| 51 virtual PP_Bool GetUploadProgress(int64_t* bytes_sent, | |
| 52 int64_t* total_bytes_to_be_sent) OVERRIDE; | |
| 53 virtual PP_Bool GetDownloadProgress( | |
| 54 int64_t* bytes_received, | |
| 55 int64_t* total_bytes_to_be_received) OVERRIDE; | |
| 56 virtual PP_Resource GetResponseInfo() OVERRIDE; | |
| 57 virtual int32_t ReadResponseBody( | |
| 58 void* buffer, | |
| 59 int32_t bytes_to_read, | |
| 60 scoped_refptr<TrackedCallback> callback) OVERRIDE; | |
| 61 virtual int32_t FinishStreamingToFile( | |
| 62 scoped_refptr<TrackedCallback> callback) OVERRIDE; | |
| 63 virtual void Close() OVERRIDE; | |
| 64 virtual void GrantUniversalAccess() OVERRIDE; | |
| 65 | |
| 66 // PluginResource implementation. | |
| 67 virtual void OnReplyReceived(const ResourceMessageReplyParams& params, | |
| 68 const IPC::Message& msg) OVERRIDE; | |
| 69 | |
| 70 private: | |
| 71 enum Mode { | |
| 72 // The plugin has not called Open() yet. | |
| 73 MODE_WAITING_TO_OPEN, | |
| 74 | |
| 75 // The plugin is waiting for the Open() or FollowRedirect callback. | |
| 76 MODE_OPENING, | |
| 77 | |
| 78 // We've started to receive data and may receive more. | |
| 79 MODE_STREAMING_DATA, | |
| 80 | |
| 81 // All data has been streamed or there was an error. | |
| 82 MODE_LOAD_COMPLETE | |
| 83 }; | |
| 84 | |
| 85 // IPC message handlers. | |
| 86 void OnPluginMsgReceivedResponse(const ResourceMessageReplyParams& params, | |
| 87 const URLResponseInfoData& data); | |
| 88 void OnPluginMsgSendData(const ResourceMessageReplyParams& params, | |
| 89 const IPC::Message& message); | |
| 90 void OnPluginMsgFinishedLoading(const ResourceMessageReplyParams& params, | |
| 91 int32_t result); | |
| 92 void OnPluginMsgUpdateProgress(const ResourceMessageReplyParams& params, | |
| 93 int64_t bytes_sent, | |
| 94 int64_t total_bytes_to_be_sent, | |
| 95 int64_t bytes_received, | |
| 96 int64_t total_bytes_to_be_received); | |
| 97 | |
| 98 // Sends the defers loading message to the renderer to block or unblock the | |
| 99 // load. | |
| 100 void SetDefersLoading(bool defers_loading); | |
| 101 | |
| 102 int32_t ValidateCallback(scoped_refptr<TrackedCallback> callback); | |
| 103 | |
| 104 // Sets up |callback| as the pending callback. This should only be called once | |
| 105 // it is certain that |PP_OK_COMPLETIONPENDING| will be returned. | |
| 106 void RegisterCallback(scoped_refptr<TrackedCallback> callback); | |
| 107 | |
| 108 void RunCallback(int32_t result); | |
| 109 | |
| 110 // Saves the given response info to response_info_, handling file refs if | |
| 111 // necessary. This does not issue any callbacks. | |
| 112 void SaveResponseInfo(const URLResponseInfoData& data); | |
| 113 | |
| 114 size_t FillUserBuffer(); | |
| 115 | |
| 116 Mode mode_; | |
| 117 URLRequestInfoData request_data_; | |
| 118 | |
| 119 scoped_refptr<TrackedCallback> pending_callback_; | |
| 120 | |
| 121 std::deque<char> buffer_; | |
| 122 int64_t bytes_sent_; | |
| 123 int64_t total_bytes_to_be_sent_; | |
| 124 int64_t bytes_received_; | |
| 125 int64_t total_bytes_to_be_received_; | |
| 126 char* user_buffer_; | |
| 127 size_t user_buffer_size_; | |
| 128 int32_t done_status_; | |
| 129 bool is_streaming_to_file_; | |
| 130 bool is_asynchronous_load_suspended_; | |
| 131 | |
| 132 // The response info if we've received it. | |
| 133 scoped_refptr<URLResponseInfoResource> response_info_; | |
| 134 | |
| 135 DISALLOW_COPY_AND_ASSIGN(URLLoaderResource); | |
| 136 }; | |
| 137 | |
| 138 } // namespace proxy | |
| 139 } // namespace ppapi | |
| 140 | |
| 141 #endif // PPAPI_PROXY_URL_LOADER_RESOURCE_H_ | |
| OLD | NEW |