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_tracker.h" | 22 #include "ppapi/proxy/plugin_resource_tracker.h" |
23 #include "ppapi/proxy/ppapi_messages.h" | 23 #include "ppapi/proxy/ppapi_messages.h" |
24 #include "ppapi/proxy/ppb_url_response_info_proxy.h" | 24 #include "ppapi/proxy/ppb_url_response_info_proxy.h" |
| 25 #include "ppapi/shared_impl/scoped_pp_resource.h" |
25 #include "ppapi/thunk/enter.h" | 26 #include "ppapi/thunk/enter.h" |
26 #include "ppapi/thunk/ppb_url_loader_api.h" | 27 #include "ppapi/thunk/ppb_url_loader_api.h" |
27 #include "ppapi/thunk/resource_creation_api.h" | 28 #include "ppapi/thunk/resource_creation_api.h" |
28 #include "ppapi/thunk/thunk.h" | 29 #include "ppapi/thunk/thunk.h" |
29 | 30 |
30 #if defined(OS_LINUX) | 31 #if defined(OS_LINUX) |
31 #include <sys/shm.h> | 32 #include <sys/shm.h> |
32 #endif | 33 #endif |
33 | 34 |
34 using ppapi::thunk::EnterFunctionNoLock; | 35 using ppapi::thunk::EnterFunctionNoLock; |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 if (response_info_) | 174 if (response_info_) |
174 PluginResourceTracker::GetInstance()->ReleaseResource(response_info_); | 175 PluginResourceTracker::GetInstance()->ReleaseResource(response_info_); |
175 } | 176 } |
176 | 177 |
177 PPB_URLLoader_API* URLLoader::AsPPB_URLLoader_API() { | 178 PPB_URLLoader_API* URLLoader::AsPPB_URLLoader_API() { |
178 return this; | 179 return this; |
179 } | 180 } |
180 | 181 |
181 int32_t URLLoader::Open(PP_Resource request_id, | 182 int32_t URLLoader::Open(PP_Resource request_id, |
182 PP_CompletionCallback callback) { | 183 PP_CompletionCallback callback) { |
183 Resource* request_object = | 184 EnterResourceNoLock<thunk::PPB_URLRequestInfo_API> enter(request_id, true); |
184 PluginResourceTracker::GetInstance()->GetResource(request_id); | 185 if (enter.failed()) |
185 if (!request_object) | 186 return PP_ERROR_BADRESOURCE; |
186 return PP_ERROR_BADARGUMENT; | |
187 | 187 |
188 // TODO(brettw) http://crbug.com/86279: SendCallback doesn't ensure that | 188 // TODO(brettw) http://crbug.com/86279: SendCallback doesn't ensure that |
189 // the proper callback semantics happen if the object is deleted. | 189 // the proper callback semantics happen if the object is deleted. |
190 GetDispatcher()->Send(new PpapiHostMsg_PPBURLLoader_Open( | 190 GetDispatcher()->Send(new PpapiHostMsg_PPBURLLoader_Open( |
191 INTERFACE_ID_PPB_URL_LOADER, host_resource(), | 191 INTERFACE_ID_PPB_URL_LOADER, host_resource(), enter.object()->GetData(), |
192 request_object->host_resource(), | |
193 GetDispatcher()->callback_tracker().SendCallback(callback))); | 192 GetDispatcher()->callback_tracker().SendCallback(callback))); |
194 return PP_OK_COMPLETIONPENDING; | 193 return PP_OK_COMPLETIONPENDING; |
195 } | 194 } |
196 | 195 |
197 int32_t URLLoader::FollowRedirect(PP_CompletionCallback callback) { | 196 int32_t URLLoader::FollowRedirect(PP_CompletionCallback callback) { |
198 // TODO(brettw) http://crbug.com/86279: SendCallback doesn't ensure that | 197 // TODO(brettw) http://crbug.com/86279: SendCallback doesn't ensure that |
199 // the proper callback semantics happen if the object is deleted. | 198 // the proper callback semantics happen if the object is deleted. |
200 GetDispatcher()->Send(new PpapiHostMsg_PPBURLLoader_FollowRedirect( | 199 GetDispatcher()->Send(new PpapiHostMsg_PPBURLLoader_FollowRedirect( |
201 INTERFACE_ID_PPB_URL_LOADER, host_resource(), | 200 INTERFACE_ID_PPB_URL_LOADER, host_resource(), |
202 GetDispatcher()->callback_tracker().SendCallback(callback))); | 201 GetDispatcher()->callback_tracker().SendCallback(callback))); |
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
446 HostResource* result) { | 445 HostResource* result) { |
447 EnterFunctionNoLock<ResourceCreationAPI> enter(instance, true); | 446 EnterFunctionNoLock<ResourceCreationAPI> enter(instance, true); |
448 if (enter.succeeded()) { | 447 if (enter.succeeded()) { |
449 result->SetHostResource(instance, | 448 result->SetHostResource(instance, |
450 enter.functions()->CreateURLLoader(instance)); | 449 enter.functions()->CreateURLLoader(instance)); |
451 PrepareURLLoaderForSendingToPlugin(result->host_resource()); | 450 PrepareURLLoaderForSendingToPlugin(result->host_resource()); |
452 } | 451 } |
453 } | 452 } |
454 | 453 |
455 void PPB_URLLoader_Proxy::OnMsgOpen(const HostResource& loader, | 454 void PPB_URLLoader_Proxy::OnMsgOpen(const HostResource& loader, |
456 const HostResource& request_info, | 455 const PPB_URLRequestInfo_Data& data, |
457 uint32_t serialized_callback) { | 456 uint32_t serialized_callback) { |
| 457 // Have to be careful to always issue the callback, so don't return early. |
458 EnterHostFromHostResource<PPB_URLLoader_API> enter(loader); | 458 EnterHostFromHostResource<PPB_URLLoader_API> enter(loader); |
| 459 EnterFunctionNoLock<ResourceCreationAPI> enter_creation( |
| 460 loader.instance(), true); |
| 461 |
459 PP_CompletionCallback callback = ReceiveCallback(serialized_callback); | 462 PP_CompletionCallback callback = ReceiveCallback(serialized_callback); |
| 463 |
460 int32_t result = PP_ERROR_BADRESOURCE; | 464 int32_t result = PP_ERROR_BADRESOURCE; |
461 if (enter.succeeded()) | 465 if (enter.succeeded() && enter_creation.succeeded()) { |
462 result = enter.object()->Open(request_info.host_resource(), callback); | 466 ScopedPPResource request_resource( |
| 467 ScopedPPResource::PassRef(), |
| 468 enter_creation.functions()->CreateURLRequestInfo(loader.instance(), |
| 469 data)); |
| 470 result = enter.object()->Open(request_resource, callback); |
| 471 } |
463 if (result != PP_OK_COMPLETIONPENDING) | 472 if (result != PP_OK_COMPLETIONPENDING) |
464 PP_RunCompletionCallback(&callback, result); | 473 PP_RunCompletionCallback(&callback, result); |
465 // TODO(brettw) bug 73236 register for the status callbacks. | 474 // TODO(brettw) bug 73236 register for the status callbacks. |
466 } | 475 } |
467 | 476 |
468 void PPB_URLLoader_Proxy::OnMsgFollowRedirect( | 477 void PPB_URLLoader_Proxy::OnMsgFollowRedirect( |
469 const HostResource& loader, | 478 const HostResource& loader, |
470 uint32_t serialized_callback) { | 479 uint32_t serialized_callback) { |
471 EnterHostFromHostResource<PPB_URLLoader_API> enter(loader); | 480 EnterHostFromHostResource<PPB_URLLoader_API> enter(loader); |
472 PP_CompletionCallback callback = ReceiveCallback(serialized_callback); | 481 PP_CompletionCallback callback = ReceiveCallback(serialized_callback); |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
579 info->read_buffer.resize(bytes_read); | 588 info->read_buffer.resize(bytes_read); |
580 | 589 |
581 dispatcher()->Send(new PpapiMsg_PPBURLLoader_ReadResponseBody_Ack( | 590 dispatcher()->Send(new PpapiMsg_PPBURLLoader_ReadResponseBody_Ack( |
582 INTERFACE_ID_PPB_URL_LOADER, info->resource, result, info->read_buffer)); | 591 INTERFACE_ID_PPB_URL_LOADER, info->resource, result, info->read_buffer)); |
583 | 592 |
584 delete info; | 593 delete info; |
585 } | 594 } |
586 | 595 |
587 } // namespace proxy | 596 } // namespace proxy |
588 } // namespace ppapi | 597 } // namespace ppapi |
OLD | NEW |