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 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
473 | 490 |
474 void PPB_URLLoader_Proxy::OnMsgFollowRedirect( | 491 void PPB_URLLoader_Proxy::OnMsgFollowRedirect( |
475 const HostResource& loader) { | 492 const HostResource& loader) { |
476 EnterHostFromHostResourceForceCallback<PPB_URLLoader_API> enter( | 493 EnterHostFromHostResourceForceCallback<PPB_URLLoader_API> enter( |
477 loader, callback_factory_, &PPB_URLLoader_Proxy::OnCallback, loader); | 494 loader, callback_factory_, &PPB_URLLoader_Proxy::OnCallback, loader); |
478 if (enter.succeeded()) | 495 if (enter.succeeded()) |
479 enter.SetResult(enter.object()->FollowRedirect(enter.callback())); | 496 enter.SetResult(enter.object()->FollowRedirect(enter.callback())); |
480 } | 497 } |
481 | 498 |
482 void PPB_URLLoader_Proxy::OnMsgGetResponseInfo(const HostResource& loader, | 499 void PPB_URLLoader_Proxy::OnMsgGetResponseInfo(const HostResource& loader, |
483 HostResource* result) { | 500 bool* success, |
| 501 URLResponseInfoData* result) { |
484 EnterHostFromHostResource<PPB_URLLoader_API> enter(loader); | 502 EnterHostFromHostResource<PPB_URLLoader_API> enter(loader); |
485 if (enter.succeeded()) { | 503 if (enter.succeeded()) |
486 result->SetHostResource(loader.instance(), | 504 *success = enter.object()->GetResponseInfoData(result); |
487 enter.object()->GetResponseInfo()); | 505 else |
488 } | 506 *success = false; |
489 } | 507 } |
490 | 508 |
491 void PPB_URLLoader_Proxy::OnMsgReadResponseBody( | 509 void PPB_URLLoader_Proxy::OnMsgReadResponseBody( |
492 const HostResource& loader, | 510 const HostResource& loader, |
493 int32_t bytes_to_read) { | 511 int32_t bytes_to_read) { |
494 // The plugin could be sending us malicious messages, don't accept negative | 512 // The plugin could be sending us malicious messages, don't accept negative |
495 // sizes. | 513 // sizes. |
496 if (bytes_to_read < 0) { | 514 if (bytes_to_read < 0) { |
497 // TODO(brettw) kill plugin. | 515 // TODO(brettw) kill plugin. |
498 bytes_to_read = 0; | 516 bytes_to_read = 0; |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
615 } | 633 } |
616 | 634 |
617 void PPB_URLLoader_Proxy::OnCallback(int32_t result, | 635 void PPB_URLLoader_Proxy::OnCallback(int32_t result, |
618 const HostResource& resource) { | 636 const HostResource& resource) { |
619 dispatcher()->Send(new PpapiMsg_PPBURLLoader_CallbackComplete( | 637 dispatcher()->Send(new PpapiMsg_PPBURLLoader_CallbackComplete( |
620 API_ID_PPB_URL_LOADER, resource, result)); | 638 API_ID_PPB_URL_LOADER, resource, result)); |
621 } | 639 } |
622 | 640 |
623 } // namespace proxy | 641 } // namespace proxy |
624 } // namespace ppapi | 642 } // namespace ppapi |
OLD | NEW |