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