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 |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 params.instance = pp_instance; | 63 params.instance = pp_instance; |
64 params.resource.SetHostResource(pp_instance, pp_resource); | 64 params.resource.SetHostResource(pp_instance, pp_resource); |
65 params.bytes_sent = bytes_sent; | 65 params.bytes_sent = bytes_sent; |
66 params.total_bytes_to_be_sent = total_bytes_to_be_sent; | 66 params.total_bytes_to_be_sent = total_bytes_to_be_sent; |
67 params.bytes_received = bytes_received; | 67 params.bytes_received = bytes_received; |
68 params.total_bytes_to_be_received = total_bytes_to_be_received; | 68 params.total_bytes_to_be_received = total_bytes_to_be_received; |
69 dispatcher->Send(new PpapiMsg_PPBURLLoader_UpdateProgress( | 69 dispatcher->Send(new PpapiMsg_PPBURLLoader_UpdateProgress( |
70 INTERFACE_ID_PPB_URL_LOADER, params)); | 70 INTERFACE_ID_PPB_URL_LOADER, params)); |
71 } | 71 } |
72 | 72 |
73 InterfaceProxy* CreateURLLoaderProxy(Dispatcher* dispatcher) { | 73 InterfaceProxy* CreateURLLoaderProxy(Dispatcher* dispatcher, |
74 return new PPB_URLLoader_Proxy(dispatcher); | 74 const void* target_interface) { |
| 75 return new PPB_URLLoader_Proxy(dispatcher, target_interface); |
75 } | 76 } |
76 | 77 |
77 } // namespace | 78 } // namespace |
78 | 79 |
79 // URLLoader ------------------------------------------------------------------- | 80 // URLLoader ------------------------------------------------------------------- |
80 | 81 |
81 class URLLoader : public Resource, public PPB_URLLoader_API { | 82 class URLLoader : public Resource, public PPB_URLLoader_API { |
82 public: | 83 public: |
83 URLLoader(const HostResource& resource); | 84 URLLoader(const HostResource& resource); |
84 virtual ~URLLoader(); | 85 virtual ~URLLoader(); |
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
338 buffer_.begin() + output_size); | 339 buffer_.begin() + output_size); |
339 } | 340 } |
340 | 341 |
341 // PPB_URLLoader_Proxy --------------------------------------------------------- | 342 // PPB_URLLoader_Proxy --------------------------------------------------------- |
342 | 343 |
343 struct PPB_URLLoader_Proxy::ReadCallbackInfo { | 344 struct PPB_URLLoader_Proxy::ReadCallbackInfo { |
344 HostResource resource; | 345 HostResource resource; |
345 std::string read_buffer; | 346 std::string read_buffer; |
346 }; | 347 }; |
347 | 348 |
348 PPB_URLLoader_Proxy::PPB_URLLoader_Proxy(Dispatcher* dispatcher) | 349 PPB_URLLoader_Proxy::PPB_URLLoader_Proxy(Dispatcher* dispatcher, |
349 : InterfaceProxy(dispatcher), | 350 const void* target_interface) |
| 351 : InterfaceProxy(dispatcher, target_interface), |
350 callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), | 352 callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
351 host_urlloader_trusted_interface_(NULL) { | 353 host_urlloader_trusted_interface_(NULL) { |
352 } | 354 } |
353 | 355 |
354 PPB_URLLoader_Proxy::~PPB_URLLoader_Proxy() { | 356 PPB_URLLoader_Proxy::~PPB_URLLoader_Proxy() { |
355 } | 357 } |
356 | 358 |
357 // static | 359 // static |
358 PP_Resource PPB_URLLoader_Proxy::TrackPluginResource( | 360 PP_Resource PPB_URLLoader_Proxy::TrackPluginResource( |
359 const HostResource& url_loader_resource) { | 361 const HostResource& url_loader_resource) { |
360 return (new URLLoader(url_loader_resource))->GetReference(); | 362 return (new URLLoader(url_loader_resource))->GetReference(); |
361 } | 363 } |
362 | 364 |
363 // static | 365 // static |
| 366 const InterfaceProxy::Info* PPB_URLLoader_Proxy::GetInfo() { |
| 367 static const Info info = { |
| 368 thunk::GetPPB_URLLoader_Thunk(), |
| 369 PPB_URLLOADER_INTERFACE, |
| 370 INTERFACE_ID_PPB_URL_LOADER, |
| 371 false, |
| 372 &CreateURLLoaderProxy, |
| 373 }; |
| 374 return &info; |
| 375 } |
| 376 |
| 377 // static |
364 const InterfaceProxy::Info* PPB_URLLoader_Proxy::GetTrustedInfo() { | 378 const InterfaceProxy::Info* PPB_URLLoader_Proxy::GetTrustedInfo() { |
365 static const Info info = { | 379 static const Info info = { |
366 thunk::GetPPB_URLLoaderTrusted_Thunk(), | 380 thunk::GetPPB_URLLoaderTrusted_Thunk(), |
367 PPB_URLLOADERTRUSTED_INTERFACE, | 381 PPB_URLLOADERTRUSTED_INTERFACE, |
368 INTERFACE_ID_NONE, // URL_LOADER is the canonical one. | 382 INTERFACE_ID_NONE, // URL_LOADER is the canonical one. |
369 false, | 383 false, |
370 &CreateURLLoaderProxy | 384 &CreateURLLoaderProxy |
371 }; | 385 }; |
372 return &info; | 386 return &info; |
373 } | 387 } |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
422 // callback before sending any URLLoader to the plugin. | 436 // callback before sending any URLLoader to the plugin. |
423 EnterResourceNoLock<PPB_URLLoader_API> enter(resource, false); | 437 EnterResourceNoLock<PPB_URLLoader_API> enter(resource, false); |
424 if (enter.succeeded()) | 438 if (enter.succeeded()) |
425 enter.object()->SetStatusCallback(&UpdateResourceLoadStatus); | 439 enter.object()->SetStatusCallback(&UpdateResourceLoadStatus); |
426 else | 440 else |
427 NOTREACHED(); // Only called internally, resource should be valid. | 441 NOTREACHED(); // Only called internally, resource should be valid. |
428 } | 442 } |
429 | 443 |
430 void PPB_URLLoader_Proxy::OnMsgCreate(PP_Instance instance, | 444 void PPB_URLLoader_Proxy::OnMsgCreate(PP_Instance instance, |
431 HostResource* result) { | 445 HostResource* result) { |
432 thunk::EnterResourceCreation enter(instance); | 446 EnterFunctionNoLock<ResourceCreationAPI> enter(instance, true); |
433 if (enter.succeeded()) { | 447 if (enter.succeeded()) { |
434 result->SetHostResource(instance, | 448 result->SetHostResource(instance, |
435 enter.functions()->CreateURLLoader(instance)); | 449 enter.functions()->CreateURLLoader(instance)); |
436 PrepareURLLoaderForSendingToPlugin(result->host_resource()); | 450 PrepareURLLoaderForSendingToPlugin(result->host_resource()); |
437 } | 451 } |
438 } | 452 } |
439 | 453 |
440 void PPB_URLLoader_Proxy::OnMsgOpen(const HostResource& loader, | 454 void PPB_URLLoader_Proxy::OnMsgOpen(const HostResource& loader, |
441 const PPB_URLRequestInfo_Data& data, | 455 const PPB_URLRequestInfo_Data& data, |
442 uint32_t serialized_callback) { | 456 uint32_t serialized_callback) { |
443 // Have to be careful to always issue the callback, so don't return early. | 457 // Have to be careful to always issue the callback, so don't return early. |
444 EnterHostFromHostResource<PPB_URLLoader_API> enter(loader); | 458 EnterHostFromHostResource<PPB_URLLoader_API> enter(loader); |
445 thunk::EnterResourceCreation enter_creation(loader.instance()); | 459 EnterFunctionNoLock<ResourceCreationAPI> enter_creation( |
| 460 loader.instance(), true); |
446 | 461 |
447 PP_CompletionCallback callback = ReceiveCallback(serialized_callback); | 462 PP_CompletionCallback callback = ReceiveCallback(serialized_callback); |
448 | 463 |
449 int32_t result = PP_ERROR_BADRESOURCE; | 464 int32_t result = PP_ERROR_BADRESOURCE; |
450 if (enter.succeeded() && enter_creation.succeeded()) { | 465 if (enter.succeeded() && enter_creation.succeeded()) { |
451 ScopedPPResource request_resource( | 466 ScopedPPResource request_resource( |
452 ScopedPPResource::PassRef(), | 467 ScopedPPResource::PassRef(), |
453 enter_creation.functions()->CreateURLRequestInfo(loader.instance(), | 468 enter_creation.functions()->CreateURLRequestInfo(loader.instance(), |
454 data)); | 469 data)); |
455 result = enter.object()->Open(request_resource, callback); | 470 result = enter.object()->Open(request_resource, callback); |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
573 info->read_buffer.resize(bytes_read); | 588 info->read_buffer.resize(bytes_read); |
574 | 589 |
575 dispatcher()->Send(new PpapiMsg_PPBURLLoader_ReadResponseBody_Ack( | 590 dispatcher()->Send(new PpapiMsg_PPBURLLoader_ReadResponseBody_Ack( |
576 INTERFACE_ID_PPB_URL_LOADER, info->resource, result, info->read_buffer)); | 591 INTERFACE_ID_PPB_URL_LOADER, info->resource, result, info->read_buffer)); |
577 | 592 |
578 delete info; | 593 delete info; |
579 } | 594 } |
580 | 595 |
581 } // namespace proxy | 596 } // namespace proxy |
582 } // namespace ppapi | 597 } // namespace ppapi |
OLD | NEW |