OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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/bind.h" | 11 #include "base/bind.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "build/build_config.h" | 13 #include "build/build_config.h" |
14 #include "ppapi/c/pp_completion_callback.h" | 14 #include "ppapi/c/pp_completion_callback.h" |
15 #include "ppapi/c/pp_errors.h" | 15 #include "ppapi/c/pp_errors.h" |
16 #include "ppapi/c/pp_resource.h" | 16 #include "ppapi/c/pp_resource.h" |
17 #include "ppapi/c/ppb_url_loader.h" | 17 #include "ppapi/c/ppb_url_loader.h" |
18 #include "ppapi/c/private/ppb_proxy_private.h" | 18 #include "ppapi/c/private/ppb_proxy_private.h" |
19 #include "ppapi/c/trusted/ppb_url_loader_trusted.h" | 19 #include "ppapi/c/trusted/ppb_url_loader_trusted.h" |
20 #include "ppapi/proxy/enter_proxy.h" | 20 #include "ppapi/proxy/enter_proxy.h" |
21 #include "ppapi/proxy/host_dispatcher.h" | 21 #include "ppapi/proxy/host_dispatcher.h" |
22 #include "ppapi/proxy/plugin_dispatcher.h" | 22 #include "ppapi/proxy/plugin_dispatcher.h" |
23 #include "ppapi/proxy/plugin_resource_tracker.h" | 23 #include "ppapi/proxy/plugin_resource_tracker.h" |
24 #include "ppapi/proxy/ppapi_messages.h" | 24 #include "ppapi/proxy/ppapi_messages.h" |
25 #include "ppapi/proxy/ppb_url_response_info_proxy.h" | 25 #include "ppapi/proxy/ppb_file_ref_proxy.h" |
26 #include "ppapi/shared_impl/scoped_pp_resource.h" | 26 #include "ppapi/shared_impl/scoped_pp_resource.h" |
27 #include "ppapi/shared_impl/tracked_callback.h" | 27 #include "ppapi/shared_impl/tracked_callback.h" |
28 #include "ppapi/thunk/enter.h" | 28 #include "ppapi/thunk/enter.h" |
29 #include "ppapi/thunk/ppb_url_loader_api.h" | 29 #include "ppapi/thunk/ppb_url_loader_api.h" |
30 #include "ppapi/thunk/ppb_url_request_info_api.h" | 30 #include "ppapi/thunk/ppb_url_request_info_api.h" |
31 #include "ppapi/thunk/resource_creation_api.h" | 31 #include "ppapi/thunk/resource_creation_api.h" |
32 #include "ppapi/thunk/thunk.h" | 32 #include "ppapi/thunk/thunk.h" |
33 | 33 |
34 #if defined(OS_LINUX) | 34 #if defined(OS_LINUX) |
35 #include <sys/shm.h> | 35 #include <sys/shm.h> |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 virtual int32_t ReadResponseBody( | 107 virtual int32_t ReadResponseBody( |
108 void* buffer, | 108 void* buffer, |
109 int32_t bytes_to_read, | 109 int32_t bytes_to_read, |
110 scoped_refptr<TrackedCallback> callback) OVERRIDE; | 110 scoped_refptr<TrackedCallback> callback) OVERRIDE; |
111 virtual int32_t FinishStreamingToFile( | 111 virtual int32_t FinishStreamingToFile( |
112 scoped_refptr<TrackedCallback> callback) OVERRIDE; | 112 scoped_refptr<TrackedCallback> callback) OVERRIDE; |
113 virtual void Close() OVERRIDE; | 113 virtual void Close() OVERRIDE; |
114 virtual void GrantUniversalAccess() OVERRIDE; | 114 virtual void GrantUniversalAccess() OVERRIDE; |
115 virtual void SetStatusCallback( | 115 virtual void SetStatusCallback( |
116 PP_URLLoaderTrusted_StatusCallback cb) OVERRIDE; | 116 PP_URLLoaderTrusted_StatusCallback cb) OVERRIDE; |
| 117 virtual bool GetResponseInfoData(URLResponseInfoData* data) OVERRIDE; |
117 | 118 |
118 // Called when the browser has new up/download progress to report. | 119 // Called when the browser has new up/download progress to report. |
119 void UpdateProgress(const PPBURLLoader_UpdateProgress_Params& params); | 120 void UpdateProgress(const PPBURLLoader_UpdateProgress_Params& params); |
120 | 121 |
121 // Called when the browser responds to our ReadResponseBody request. | 122 // Called when the browser responds to our ReadResponseBody request. |
122 void ReadResponseBodyAck(int32_t result, const char* data); | 123 void ReadResponseBodyAck(int32_t result, const char* data); |
123 | 124 |
124 // Called when any callback other than the read callback has been executed. | 125 // Called when any callback other than the read callback has been executed. |
125 void CallbackComplete(int32_t result); | 126 void CallbackComplete(int32_t result); |
126 | 127 |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 *total_bytes_to_be_received = 0; | 243 *total_bytes_to_be_received = 0; |
243 return PP_FALSE; | 244 return PP_FALSE; |
244 } | 245 } |
245 *bytes_received = bytes_received_; | 246 *bytes_received = bytes_received_; |
246 *total_bytes_to_be_received = total_bytes_to_be_received_; | 247 *total_bytes_to_be_received = total_bytes_to_be_received_; |
247 return PP_TRUE; | 248 return PP_TRUE; |
248 } | 249 } |
249 | 250 |
250 PP_Resource URLLoader::GetResponseInfo() { | 251 PP_Resource URLLoader::GetResponseInfo() { |
251 if (!response_info_) { | 252 if (!response_info_) { |
252 HostResource response_id; | 253 bool success = false; |
| 254 URLResponseInfoData data; |
253 GetDispatcher()->Send(new PpapiHostMsg_PPBURLLoader_GetResponseInfo( | 255 GetDispatcher()->Send(new PpapiHostMsg_PPBURLLoader_GetResponseInfo( |
254 API_ID_PPB_URL_LOADER, host_resource(), &response_id)); | 256 API_ID_PPB_URL_LOADER, host_resource(), &success, &data)); |
255 if (response_id.is_null()) | 257 if (!success) |
256 return 0; | 258 return 0; |
257 | 259 |
258 response_info_ = PPB_URLResponseInfo_Proxy::CreateResponseForResource( | 260 // Create a proxy resource for the the file ref host resource if needed. |
259 response_id); | 261 PP_Resource body_as_file_ref = 0; |
| 262 if (!data.body_as_file_ref.resource.is_null()) { |
| 263 body_as_file_ref = |
| 264 PPB_FileRef_Proxy::DeserializeFileRef(data.body_as_file_ref); |
| 265 } |
| 266 |
| 267 // Assumes ownership of body_as_file_ref. |
| 268 thunk::EnterResourceCreationNoLock enter(pp_instance()); |
| 269 response_info_ = enter.functions()->CreateURLResponseInfo( |
| 270 pp_instance(), data, body_as_file_ref); |
260 } | 271 } |
261 | 272 |
262 // The caller expects to get a ref, and we want to keep holding ours. | 273 // The caller expects to get a ref, and we want to keep holding ours. |
263 PpapiGlobals::Get()->GetResourceTracker()->AddRefResource(response_info_); | 274 PpapiGlobals::Get()->GetResourceTracker()->AddRefResource(response_info_); |
264 return response_info_; | 275 return response_info_; |
265 } | 276 } |
266 | 277 |
267 int32_t URLLoader::ReadResponseBody(void* buffer, | 278 int32_t URLLoader::ReadResponseBody(void* buffer, |
268 int32_t bytes_to_read, | 279 int32_t bytes_to_read, |
269 scoped_refptr<TrackedCallback> callback) { | 280 scoped_refptr<TrackedCallback> callback) { |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
312 new PpapiHostMsg_PPBURLLoader_GrantUniversalAccess( | 323 new PpapiHostMsg_PPBURLLoader_GrantUniversalAccess( |
313 API_ID_PPB_URL_LOADER, host_resource())); | 324 API_ID_PPB_URL_LOADER, host_resource())); |
314 } | 325 } |
315 | 326 |
316 void URLLoader::SetStatusCallback( | 327 void URLLoader::SetStatusCallback( |
317 PP_URLLoaderTrusted_StatusCallback cb) { | 328 PP_URLLoaderTrusted_StatusCallback cb) { |
318 // Not implemented in the proxied version, this is for implementing the | 329 // Not implemented in the proxied version, this is for implementing the |
319 // proxy itself in the host. | 330 // proxy itself in the host. |
320 } | 331 } |
321 | 332 |
| 333 bool URLLoader::GetResponseInfoData(URLResponseInfoData* data) { |
| 334 // Not implemented in the proxied version, this is for implementing the |
| 335 // proxy itself in the host. |
| 336 return false; |
| 337 } |
| 338 |
322 void URLLoader::UpdateProgress( | 339 void URLLoader::UpdateProgress( |
323 const PPBURLLoader_UpdateProgress_Params& params) { | 340 const PPBURLLoader_UpdateProgress_Params& params) { |
324 bytes_sent_ = params.bytes_sent; | 341 bytes_sent_ = params.bytes_sent; |
325 total_bytes_to_be_sent_ = params.total_bytes_to_be_sent; | 342 total_bytes_to_be_sent_ = params.total_bytes_to_be_sent; |
326 bytes_received_ = params.bytes_received; | 343 bytes_received_ = params.bytes_received; |
327 total_bytes_to_be_received_ = params.total_bytes_to_be_received; | 344 total_bytes_to_be_received_ = params.total_bytes_to_be_received; |
328 } | 345 } |
329 | 346 |
330 void URLLoader::ReadResponseBodyAck(int32 result, const char* data) { | 347 void URLLoader::ReadResponseBodyAck(int32 result, const char* data) { |
331 if (!TrackedCallback::IsPending(current_callback_) || !current_read_buffer_) { | 348 if (!TrackedCallback::IsPending(current_callback_) || !current_read_buffer_) { |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
477 | 494 |
478 void PPB_URLLoader_Proxy::OnMsgFollowRedirect( | 495 void PPB_URLLoader_Proxy::OnMsgFollowRedirect( |
479 const HostResource& loader) { | 496 const HostResource& loader) { |
480 EnterHostFromHostResourceForceCallback<PPB_URLLoader_API> enter( | 497 EnterHostFromHostResourceForceCallback<PPB_URLLoader_API> enter( |
481 loader, callback_factory_, &PPB_URLLoader_Proxy::OnCallback, loader); | 498 loader, callback_factory_, &PPB_URLLoader_Proxy::OnCallback, loader); |
482 if (enter.succeeded()) | 499 if (enter.succeeded()) |
483 enter.SetResult(enter.object()->FollowRedirect(enter.callback())); | 500 enter.SetResult(enter.object()->FollowRedirect(enter.callback())); |
484 } | 501 } |
485 | 502 |
486 void PPB_URLLoader_Proxy::OnMsgGetResponseInfo(const HostResource& loader, | 503 void PPB_URLLoader_Proxy::OnMsgGetResponseInfo(const HostResource& loader, |
487 HostResource* result) { | 504 bool* success, |
| 505 URLResponseInfoData* result) { |
488 EnterHostFromHostResource<PPB_URLLoader_API> enter(loader); | 506 EnterHostFromHostResource<PPB_URLLoader_API> enter(loader); |
489 if (enter.succeeded()) { | 507 if (enter.succeeded()) |
490 result->SetHostResource(loader.instance(), | 508 *success = enter.object()->GetResponseInfoData(result); |
491 enter.object()->GetResponseInfo()); | 509 else |
492 } | 510 *success = false; |
493 } | 511 } |
494 | 512 |
495 void PPB_URLLoader_Proxy::OnMsgReadResponseBody( | 513 void PPB_URLLoader_Proxy::OnMsgReadResponseBody( |
496 const HostResource& loader, | 514 const HostResource& loader, |
497 int32_t bytes_to_read) { | 515 int32_t bytes_to_read) { |
498 // The plugin could be sending us malicious messages, don't accept negative | 516 // The plugin could be sending us malicious messages, don't accept negative |
499 // sizes. | 517 // sizes. |
500 if (bytes_to_read < 0) { | 518 if (bytes_to_read < 0) { |
501 // TODO(brettw) kill plugin. | 519 // TODO(brettw) kill plugin. |
502 bytes_to_read = 0; | 520 bytes_to_read = 0; |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
622 | 640 |
623 void PPB_URLLoader_Proxy::OnCallback(int32_t result, | 641 void PPB_URLLoader_Proxy::OnCallback(int32_t result, |
624 const HostResource& resource) { | 642 const HostResource& resource) { |
625 dispatcher()->Send(new PpapiMsg_PPBURLLoader_CallbackComplete( | 643 dispatcher()->Send(new PpapiMsg_PPBURLLoader_CallbackComplete( |
626 API_ID_PPB_URL_LOADER, resource, result)); | 644 API_ID_PPB_URL_LOADER, resource, result)); |
627 } | 645 } |
628 #endif // !defined(OS_NACL) | 646 #endif // !defined(OS_NACL) |
629 | 647 |
630 } // namespace proxy | 648 } // namespace proxy |
631 } // namespace ppapi | 649 } // namespace ppapi |
OLD | NEW |