OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ppapi/proxy/ppb_url_loader_proxy.h" | 5 #include "ppapi/proxy/ppb_url_loader_proxy.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <deque> | 8 #include <deque> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "build/build_config.h" | 12 #include "build/build_config.h" |
13 #include "ppapi/c/pp_completion_callback.h" | 13 #include "ppapi/c/pp_completion_callback.h" |
14 #include "ppapi/c/pp_errors.h" | 14 #include "ppapi/c/pp_errors.h" |
15 #include "ppapi/c/pp_resource.h" | 15 #include "ppapi/c/pp_resource.h" |
16 #include "ppapi/c/ppb_url_loader.h" | 16 #include "ppapi/c/ppb_url_loader.h" |
17 #include "ppapi/c/private/ppb_proxy_private.h" | 17 #include "ppapi/c/private/ppb_proxy_private.h" |
18 #include "ppapi/c/trusted/ppb_url_loader_trusted.h" | 18 #include "ppapi/c/trusted/ppb_url_loader_trusted.h" |
19 #include "ppapi/proxy/enter_proxy.h" | 19 #include "ppapi/proxy/enter_proxy.h" |
20 #include "ppapi/proxy/host_dispatcher.h" | 20 #include "ppapi/proxy/host_dispatcher.h" |
21 #include "ppapi/proxy/plugin_dispatcher.h" | 21 #include "ppapi/proxy/plugin_dispatcher.h" |
22 #include "ppapi/proxy/plugin_resource.h" | |
23 #include "ppapi/proxy/plugin_resource_tracker.h" | 22 #include "ppapi/proxy/plugin_resource_tracker.h" |
24 #include "ppapi/proxy/ppapi_messages.h" | 23 #include "ppapi/proxy/ppapi_messages.h" |
25 #include "ppapi/proxy/ppb_url_response_info_proxy.h" | 24 #include "ppapi/proxy/ppb_url_response_info_proxy.h" |
26 #include "ppapi/thunk/enter.h" | 25 #include "ppapi/thunk/enter.h" |
27 #include "ppapi/thunk/ppb_url_loader_api.h" | 26 #include "ppapi/thunk/ppb_url_loader_api.h" |
28 #include "ppapi/thunk/resource_creation_api.h" | 27 #include "ppapi/thunk/resource_creation_api.h" |
29 #include "ppapi/thunk/thunk.h" | 28 #include "ppapi/thunk/thunk.h" |
30 | 29 |
31 #if defined(OS_LINUX) | 30 #if defined(OS_LINUX) |
32 #include <sys/shm.h> | 31 #include <sys/shm.h> |
33 #endif | 32 #endif |
34 | 33 |
35 using ppapi::HostResource; | 34 using ppapi::HostResource; |
| 35 using ppapi::Resource; |
36 using ppapi::thunk::EnterFunctionNoLock; | 36 using ppapi::thunk::EnterFunctionNoLock; |
37 using ppapi::thunk::EnterResourceNoLock; | 37 using ppapi::thunk::EnterResourceNoLock; |
38 using ppapi::thunk::PPB_URLLoader_API; | 38 using ppapi::thunk::PPB_URLLoader_API; |
39 using ppapi::thunk::ResourceCreationAPI; | 39 using ppapi::thunk::ResourceCreationAPI; |
40 | 40 |
41 namespace pp { | 41 namespace pp { |
42 namespace proxy { | 42 namespace proxy { |
43 | 43 |
44 namespace { | 44 namespace { |
45 | 45 |
(...skipping 27 matching lines...) Expand all Loading... |
73 | 73 |
74 InterfaceProxy* CreateURLLoaderProxy(Dispatcher* dispatcher, | 74 InterfaceProxy* CreateURLLoaderProxy(Dispatcher* dispatcher, |
75 const void* target_interface) { | 75 const void* target_interface) { |
76 return new PPB_URLLoader_Proxy(dispatcher, target_interface); | 76 return new PPB_URLLoader_Proxy(dispatcher, target_interface); |
77 } | 77 } |
78 | 78 |
79 } // namespace | 79 } // namespace |
80 | 80 |
81 // URLLoader ------------------------------------------------------------------- | 81 // URLLoader ------------------------------------------------------------------- |
82 | 82 |
83 class URLLoader : public PluginResource, public PPB_URLLoader_API { | 83 class URLLoader : public Resource, public PPB_URLLoader_API { |
84 public: | 84 public: |
85 URLLoader(const HostResource& resource); | 85 URLLoader(const HostResource& resource); |
86 virtual ~URLLoader(); | 86 virtual ~URLLoader(); |
87 | 87 |
88 // ResourceObjectBase overrides. | 88 // Resource overrides. |
89 virtual PPB_URLLoader_API* AsPPB_URLLoader_API() OVERRIDE; | 89 virtual PPB_URLLoader_API* AsPPB_URLLoader_API() OVERRIDE; |
90 | 90 |
91 // PPB_URLLoader_API implementation. | 91 // PPB_URLLoader_API implementation. |
92 virtual int32_t Open(PP_Resource request_id, | 92 virtual int32_t Open(PP_Resource request_id, |
93 PP_CompletionCallback callback) OVERRIDE; | 93 PP_CompletionCallback callback) OVERRIDE; |
94 virtual int32_t FollowRedirect(PP_CompletionCallback callback) OVERRIDE; | 94 virtual int32_t FollowRedirect(PP_CompletionCallback callback) OVERRIDE; |
95 virtual PP_Bool GetUploadProgress(int64_t* bytes_sent, | 95 virtual PP_Bool GetUploadProgress(int64_t* bytes_sent, |
96 int64_t* total_bytes_to_be_sent) OVERRIDE; | 96 int64_t* total_bytes_to_be_sent) OVERRIDE; |
97 virtual PP_Bool GetDownloadProgress( | 97 virtual PP_Bool GetDownloadProgress( |
98 int64_t* bytes_received, | 98 int64_t* bytes_received, |
(...skipping 15 matching lines...) Expand all Loading... |
114 // Called when the browser responds to our ReadResponseBody request. | 114 // Called when the browser responds to our ReadResponseBody request. |
115 void ReadResponseBodyAck(int32 result, const std::string& data); | 115 void ReadResponseBodyAck(int32 result, const std::string& data); |
116 | 116 |
117 private: | 117 private: |
118 // Reads the give bytes out of the buffer_, placing them in the given output | 118 // Reads the give bytes out of the buffer_, placing them in the given output |
119 // buffer, and removes the bytes from the buffer. | 119 // buffer, and removes the bytes from the buffer. |
120 // | 120 // |
121 // The size must be not more than the current size of the buffer. | 121 // The size must be not more than the current size of the buffer. |
122 void PopBuffer(void* output_buffer, int32_t output_size); | 122 void PopBuffer(void* output_buffer, int32_t output_size); |
123 | 123 |
| 124 PluginDispatcher* GetDispatcher() const { |
| 125 return PluginDispatcher::GetForResource(this); |
| 126 } |
| 127 |
124 // Initialized to -1. Will be set to nonnegative values by the UpdateProgress | 128 // Initialized to -1. Will be set to nonnegative values by the UpdateProgress |
125 // message when the values are known. | 129 // message when the values are known. |
126 int64_t bytes_sent_; | 130 int64_t bytes_sent_; |
127 int64_t total_bytes_to_be_sent_; | 131 int64_t total_bytes_to_be_sent_; |
128 int64_t bytes_received_; | 132 int64_t bytes_received_; |
129 int64_t total_bytes_to_be_received_; | 133 int64_t total_bytes_to_be_received_; |
130 | 134 |
131 // When an asynchronous read is pending, this will contain the callback and | 135 // When an asynchronous read is pending, this will contain the callback and |
132 // the buffer to put the data. | 136 // the buffer to put the data. |
133 PP_CompletionCallback current_read_callback_; | 137 PP_CompletionCallback current_read_callback_; |
134 void* current_read_buffer_; | 138 void* current_read_buffer_; |
135 int32_t current_read_buffer_size_; | 139 int32_t current_read_buffer_size_; |
136 | 140 |
137 // A buffer of all the data that's been sent to us from the host that we | 141 // A buffer of all the data that's been sent to us from the host that we |
138 // have yet to send out to the plugin. | 142 // have yet to send out to the plugin. |
139 std::deque<char> buffer_; | 143 std::deque<char> buffer_; |
140 | 144 |
141 // Cached copy of the response info. When nonzero, we're holding a reference | 145 // Cached copy of the response info. When nonzero, we're holding a reference |
142 // to this resource. | 146 // to this resource. |
143 PP_Resource response_info_; | 147 PP_Resource response_info_; |
144 | 148 |
145 private: | 149 private: |
146 DISALLOW_COPY_AND_ASSIGN(URLLoader); | 150 DISALLOW_COPY_AND_ASSIGN(URLLoader); |
147 }; | 151 }; |
148 | 152 |
149 URLLoader::URLLoader(const HostResource& resource) | 153 URLLoader::URLLoader(const HostResource& resource) |
150 : PluginResource(resource), | 154 : Resource(resource), |
151 bytes_sent_(-1), | 155 bytes_sent_(-1), |
152 total_bytes_to_be_sent_(-1), | 156 total_bytes_to_be_sent_(-1), |
153 bytes_received_(-1), | 157 bytes_received_(-1), |
154 total_bytes_to_be_received_(-1), | 158 total_bytes_to_be_received_(-1), |
155 current_read_callback_(PP_MakeCompletionCallback(NULL, NULL)), | 159 current_read_callback_(PP_MakeCompletionCallback(NULL, NULL)), |
156 current_read_buffer_(NULL), | 160 current_read_buffer_(NULL), |
157 current_read_buffer_size_(0), | 161 current_read_buffer_size_(0), |
158 response_info_(0) { | 162 response_info_(0) { |
159 } | 163 } |
160 | 164 |
(...skipping 10 matching lines...) Expand all Loading... |
171 if (response_info_) | 175 if (response_info_) |
172 PluginResourceTracker::GetInstance()->ReleaseResource(response_info_); | 176 PluginResourceTracker::GetInstance()->ReleaseResource(response_info_); |
173 } | 177 } |
174 | 178 |
175 PPB_URLLoader_API* URLLoader::AsPPB_URLLoader_API() { | 179 PPB_URLLoader_API* URLLoader::AsPPB_URLLoader_API() { |
176 return this; | 180 return this; |
177 } | 181 } |
178 | 182 |
179 int32_t URLLoader::Open(PP_Resource request_id, | 183 int32_t URLLoader::Open(PP_Resource request_id, |
180 PP_CompletionCallback callback) { | 184 PP_CompletionCallback callback) { |
181 PluginResource* request_object = | 185 Resource* request_object = |
182 PluginResourceTracker::GetInstance()->GetResourceObject(request_id); | 186 PluginResourceTracker::GetInstance()->GetResource(request_id); |
183 if (!request_object) | 187 if (!request_object) |
184 return PP_ERROR_BADARGUMENT; | 188 return PP_ERROR_BADARGUMENT; |
185 | 189 |
186 // TODO(brettw) http://crbug.com/86279: SendCallback doesn't ensure that | 190 // TODO(brettw) http://crbug.com/86279: SendCallback doesn't ensure that |
187 // the proper callback semantics happen if the object is deleted. | 191 // the proper callback semantics happen if the object is deleted. |
188 GetDispatcher()->Send(new PpapiHostMsg_PPBURLLoader_Open( | 192 GetDispatcher()->Send(new PpapiHostMsg_PPBURLLoader_Open( |
189 INTERFACE_ID_PPB_URL_LOADER, host_resource(), | 193 INTERFACE_ID_PPB_URL_LOADER, host_resource(), |
190 request_object->host_resource(), | 194 request_object->host_resource(), |
191 GetDispatcher()->callback_tracker().SendCallback(callback))); | 195 GetDispatcher()->callback_tracker().SendCallback(callback))); |
192 return PP_OK_COMPLETIONPENDING; | 196 return PP_OK_COMPLETIONPENDING; |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
351 callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), | 355 callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
352 host_urlloader_trusted_interface_(NULL) { | 356 host_urlloader_trusted_interface_(NULL) { |
353 } | 357 } |
354 | 358 |
355 PPB_URLLoader_Proxy::~PPB_URLLoader_Proxy() { | 359 PPB_URLLoader_Proxy::~PPB_URLLoader_Proxy() { |
356 } | 360 } |
357 | 361 |
358 // static | 362 // static |
359 PP_Resource PPB_URLLoader_Proxy::TrackPluginResource( | 363 PP_Resource PPB_URLLoader_Proxy::TrackPluginResource( |
360 const HostResource& url_loader_resource) { | 364 const HostResource& url_loader_resource) { |
361 return PluginResourceTracker::GetInstance()->AddResource( | 365 return (new URLLoader(url_loader_resource))->GetReference(); |
362 new URLLoader(url_loader_resource)); | |
363 } | 366 } |
364 | 367 |
365 // static | 368 // static |
366 const InterfaceProxy::Info* PPB_URLLoader_Proxy::GetInfo() { | 369 const InterfaceProxy::Info* PPB_URLLoader_Proxy::GetInfo() { |
367 static const Info info = { | 370 static const Info info = { |
368 ::ppapi::thunk::GetPPB_URLLoader_Thunk(), | 371 ::ppapi::thunk::GetPPB_URLLoader_Thunk(), |
369 PPB_URLLOADER_INTERFACE, | 372 PPB_URLLOADER_INTERFACE, |
370 INTERFACE_ID_PPB_URL_LOADER, | 373 INTERFACE_ID_PPB_URL_LOADER, |
371 false, | 374 false, |
372 &CreateURLLoaderProxy, | 375 &CreateURLLoaderProxy, |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
578 info->read_buffer.resize(bytes_read); | 581 info->read_buffer.resize(bytes_read); |
579 | 582 |
580 dispatcher()->Send(new PpapiMsg_PPBURLLoader_ReadResponseBody_Ack( | 583 dispatcher()->Send(new PpapiMsg_PPBURLLoader_ReadResponseBody_Ack( |
581 INTERFACE_ID_PPB_URL_LOADER, info->resource, result, info->read_buffer)); | 584 INTERFACE_ID_PPB_URL_LOADER, info->resource, result, info->read_buffer)); |
582 | 585 |
583 delete info; | 586 delete info; |
584 } | 587 } |
585 | 588 |
586 } // namespace proxy | 589 } // namespace proxy |
587 } // namespace pp | 590 } // namespace pp |
OLD | NEW |