| 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 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 | 41 |
| 42 namespace ppapi { | 42 namespace ppapi { |
| 43 namespace proxy { | 43 namespace proxy { |
| 44 | 44 |
| 45 namespace { | 45 namespace { |
| 46 | 46 |
| 47 // The maximum size we'll read into the plugin without being explicitly | 47 // The maximum size we'll read into the plugin without being explicitly |
| 48 // asked for a larger buffer. | 48 // asked for a larger buffer. |
| 49 const int32_t kMaxReadBufferSize = 16777216; // 16MB | 49 const int32_t kMaxReadBufferSize = 16777216; // 16MB |
| 50 | 50 |
| 51 #if !defined(OS_NACL) |
| 51 // Called in the renderer when the byte counts have changed. We send a message | 52 // Called in the renderer when the byte counts have changed. We send a message |
| 52 // to the plugin to synchronize its counts so it can respond to status polls | 53 // to the plugin to synchronize its counts so it can respond to status polls |
| 53 // from the plugin. | 54 // from the plugin. |
| 54 void UpdateResourceLoadStatus(PP_Instance pp_instance, | 55 void UpdateResourceLoadStatus(PP_Instance pp_instance, |
| 55 PP_Resource pp_resource, | 56 PP_Resource pp_resource, |
| 56 int64 bytes_sent, | 57 int64 bytes_sent, |
| 57 int64 total_bytes_to_be_sent, | 58 int64 total_bytes_to_be_sent, |
| 58 int64 bytes_received, | 59 int64 bytes_received, |
| 59 int64 total_bytes_to_be_received) { | 60 int64 total_bytes_to_be_received) { |
| 60 #if !defined(OS_NACL) | |
| 61 Dispatcher* dispatcher = HostDispatcher::GetForInstance(pp_instance); | 61 Dispatcher* dispatcher = HostDispatcher::GetForInstance(pp_instance); |
| 62 if (!dispatcher) | 62 if (!dispatcher) |
| 63 return; | 63 return; |
| 64 | 64 |
| 65 PPBURLLoader_UpdateProgress_Params params; | 65 PPBURLLoader_UpdateProgress_Params params; |
| 66 params.instance = pp_instance; | 66 params.instance = pp_instance; |
| 67 params.resource.SetHostResource(pp_instance, pp_resource); | 67 params.resource.SetHostResource(pp_instance, pp_resource); |
| 68 params.bytes_sent = bytes_sent; | 68 params.bytes_sent = bytes_sent; |
| 69 params.total_bytes_to_be_sent = total_bytes_to_be_sent; | 69 params.total_bytes_to_be_sent = total_bytes_to_be_sent; |
| 70 params.bytes_received = bytes_received; | 70 params.bytes_received = bytes_received; |
| 71 params.total_bytes_to_be_received = total_bytes_to_be_received; | 71 params.total_bytes_to_be_received = total_bytes_to_be_received; |
| 72 dispatcher->Send(new PpapiMsg_PPBURLLoader_UpdateProgress( | 72 dispatcher->Send(new PpapiMsg_PPBURLLoader_UpdateProgress( |
| 73 API_ID_PPB_URL_LOADER, params)); | 73 API_ID_PPB_URL_LOADER, params)); |
| 74 #endif | |
| 75 } | 74 } |
| 75 #endif // !defined(OS_NACL) |
| 76 | 76 |
| 77 InterfaceProxy* CreateURLLoaderProxy(Dispatcher* dispatcher) { | 77 InterfaceProxy* CreateURLLoaderProxy(Dispatcher* dispatcher) { |
| 78 return new PPB_URLLoader_Proxy(dispatcher); | 78 return new PPB_URLLoader_Proxy(dispatcher); |
| 79 } | 79 } |
| 80 | 80 |
| 81 } // namespace | 81 } // namespace |
| 82 | 82 |
| 83 // URLLoader ------------------------------------------------------------------- | 83 // URLLoader ------------------------------------------------------------------- |
| 84 | 84 |
| 85 class URLLoader : public Resource, public PPB_URLLoader_API { | 85 class URLLoader : public Resource, public PPB_URLLoader_API { |
| (...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 405 dispatcher->Send(new PpapiHostMsg_PPBURLLoader_Create( | 405 dispatcher->Send(new PpapiHostMsg_PPBURLLoader_Create( |
| 406 API_ID_PPB_URL_LOADER, pp_instance, &result)); | 406 API_ID_PPB_URL_LOADER, pp_instance, &result)); |
| 407 if (result.is_null()) | 407 if (result.is_null()) |
| 408 return 0; | 408 return 0; |
| 409 return PPB_URLLoader_Proxy::TrackPluginResource(result); | 409 return PPB_URLLoader_Proxy::TrackPluginResource(result); |
| 410 } | 410 } |
| 411 | 411 |
| 412 bool PPB_URLLoader_Proxy::OnMessageReceived(const IPC::Message& msg) { | 412 bool PPB_URLLoader_Proxy::OnMessageReceived(const IPC::Message& msg) { |
| 413 bool handled = true; | 413 bool handled = true; |
| 414 IPC_BEGIN_MESSAGE_MAP(PPB_URLLoader_Proxy, msg) | 414 IPC_BEGIN_MESSAGE_MAP(PPB_URLLoader_Proxy, msg) |
| 415 #if !defined(OS_NACL) |
| 415 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBURLLoader_Create, | 416 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBURLLoader_Create, |
| 416 OnMsgCreate) | 417 OnMsgCreate) |
| 417 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBURLLoader_Open, | 418 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBURLLoader_Open, |
| 418 OnMsgOpen) | 419 OnMsgOpen) |
| 419 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBURLLoader_FollowRedirect, | 420 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBURLLoader_FollowRedirect, |
| 420 OnMsgFollowRedirect) | 421 OnMsgFollowRedirect) |
| 421 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBURLLoader_GetResponseInfo, | 422 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBURLLoader_GetResponseInfo, |
| 422 OnMsgGetResponseInfo) | 423 OnMsgGetResponseInfo) |
| 423 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBURLLoader_ReadResponseBody, | 424 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBURLLoader_ReadResponseBody, |
| 424 OnMsgReadResponseBody) | 425 OnMsgReadResponseBody) |
| 425 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBURLLoader_FinishStreamingToFile, | 426 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBURLLoader_FinishStreamingToFile, |
| 426 OnMsgFinishStreamingToFile) | 427 OnMsgFinishStreamingToFile) |
| 427 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBURLLoader_Close, | 428 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBURLLoader_Close, |
| 428 OnMsgClose) | 429 OnMsgClose) |
| 429 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBURLLoader_GrantUniversalAccess, | 430 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBURLLoader_GrantUniversalAccess, |
| 430 OnMsgGrantUniversalAccess) | 431 OnMsgGrantUniversalAccess) |
| 432 #endif // !defined(OS_NACL) |
| 433 |
| 431 IPC_MESSAGE_HANDLER(PpapiMsg_PPBURLLoader_UpdateProgress, | 434 IPC_MESSAGE_HANDLER(PpapiMsg_PPBURLLoader_UpdateProgress, |
| 432 OnMsgUpdateProgress) | 435 OnMsgUpdateProgress) |
| 433 IPC_MESSAGE_HANDLER(PpapiMsg_PPBURLLoader_ReadResponseBody_Ack, | 436 IPC_MESSAGE_HANDLER(PpapiMsg_PPBURLLoader_ReadResponseBody_Ack, |
| 434 OnMsgReadResponseBodyAck) | 437 OnMsgReadResponseBodyAck) |
| 435 IPC_MESSAGE_HANDLER(PpapiMsg_PPBURLLoader_CallbackComplete, | 438 IPC_MESSAGE_HANDLER(PpapiMsg_PPBURLLoader_CallbackComplete, |
| 436 OnMsgCallbackComplete) | 439 OnMsgCallbackComplete) |
| 437 IPC_MESSAGE_UNHANDLED(handled = false) | 440 IPC_MESSAGE_UNHANDLED(handled = false) |
| 438 IPC_END_MESSAGE_MAP() | 441 IPC_END_MESSAGE_MAP() |
| 439 // TODO(brettw) handle bad messages! | 442 // TODO(brettw) handle bad messages! |
| 440 return handled; | 443 return handled; |
| 441 } | 444 } |
| 442 | 445 |
| 446 #if !defined(OS_NACL) |
| 443 void PPB_URLLoader_Proxy::PrepareURLLoaderForSendingToPlugin( | 447 void PPB_URLLoader_Proxy::PrepareURLLoaderForSendingToPlugin( |
| 444 PP_Resource resource) { | 448 PP_Resource resource) { |
| 445 // So the plugin can query load status, we need to register our status | 449 // So the plugin can query load status, we need to register our status |
| 446 // callback before sending any URLLoader to the plugin. | 450 // callback before sending any URLLoader to the plugin. |
| 447 EnterResourceNoLock<PPB_URLLoader_API> enter(resource, false); | 451 EnterResourceNoLock<PPB_URLLoader_API> enter(resource, false); |
| 448 if (enter.succeeded()) | 452 if (enter.succeeded()) |
| 449 enter.object()->SetStatusCallback(&UpdateResourceLoadStatus); | 453 enter.object()->SetStatusCallback(&UpdateResourceLoadStatus); |
| 450 else | 454 else |
| 451 NOTREACHED(); // Only called internally, resource should be valid. | 455 NOTREACHED(); // Only called internally, resource should be valid. |
| 452 } | 456 } |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 546 if (enter.succeeded()) | 550 if (enter.succeeded()) |
| 547 enter.object()->Close(); | 551 enter.object()->Close(); |
| 548 } | 552 } |
| 549 | 553 |
| 550 void PPB_URLLoader_Proxy::OnMsgGrantUniversalAccess( | 554 void PPB_URLLoader_Proxy::OnMsgGrantUniversalAccess( |
| 551 const HostResource& loader) { | 555 const HostResource& loader) { |
| 552 EnterHostFromHostResource<PPB_URLLoader_API> enter(loader); | 556 EnterHostFromHostResource<PPB_URLLoader_API> enter(loader); |
| 553 if (enter.succeeded()) | 557 if (enter.succeeded()) |
| 554 enter.object()->GrantUniversalAccess(); | 558 enter.object()->GrantUniversalAccess(); |
| 555 } | 559 } |
| 560 #endif // !defined(OS_NACL) |
| 556 | 561 |
| 557 // Called in the Plugin. | 562 // Called in the Plugin. |
| 558 void PPB_URLLoader_Proxy::OnMsgUpdateProgress( | 563 void PPB_URLLoader_Proxy::OnMsgUpdateProgress( |
| 559 const PPBURLLoader_UpdateProgress_Params& params) { | 564 const PPBURLLoader_UpdateProgress_Params& params) { |
| 560 EnterPluginFromHostResource<PPB_URLLoader_API> enter(params.resource); | 565 EnterPluginFromHostResource<PPB_URLLoader_API> enter(params.resource); |
| 561 if (enter.succeeded()) | 566 if (enter.succeeded()) |
| 562 static_cast<URLLoader*>(enter.object())->UpdateProgress(params); | 567 static_cast<URLLoader*>(enter.object())->UpdateProgress(params); |
| 563 } | 568 } |
| 564 | 569 |
| 565 // Called in the Plugin. | 570 // Called in the Plugin. |
| (...skipping 29 matching lines...) Expand all Loading... |
| 595 | 600 |
| 596 // Called in the plugin. | 601 // Called in the plugin. |
| 597 void PPB_URLLoader_Proxy::OnMsgCallbackComplete( | 602 void PPB_URLLoader_Proxy::OnMsgCallbackComplete( |
| 598 const HostResource& host_resource, | 603 const HostResource& host_resource, |
| 599 int32_t result) { | 604 int32_t result) { |
| 600 EnterPluginFromHostResource<PPB_URLLoader_API> enter(host_resource); | 605 EnterPluginFromHostResource<PPB_URLLoader_API> enter(host_resource); |
| 601 if (enter.succeeded()) | 606 if (enter.succeeded()) |
| 602 static_cast<URLLoader*>(enter.object())->CallbackComplete(result); | 607 static_cast<URLLoader*>(enter.object())->CallbackComplete(result); |
| 603 } | 608 } |
| 604 | 609 |
| 610 #if !defined(OS_NACL) |
| 605 void PPB_URLLoader_Proxy::OnReadCallback(int32_t result, | 611 void PPB_URLLoader_Proxy::OnReadCallback(int32_t result, |
| 606 IPC::Message* message) { | 612 IPC::Message* message) { |
| 607 int32_t bytes_read = 0; | 613 int32_t bytes_read = 0; |
| 608 if (result > 0) | 614 if (result > 0) |
| 609 bytes_read = result; // Positive results indicate bytes read. | 615 bytes_read = result; // Positive results indicate bytes read. |
| 610 | 616 |
| 611 message->TrimWriteData(bytes_read); | 617 message->TrimWriteData(bytes_read); |
| 612 message->WriteInt(result); | 618 message->WriteInt(result); |
| 613 | 619 |
| 614 dispatcher()->Send(message); | 620 dispatcher()->Send(message); |
| 615 } | 621 } |
| 616 | 622 |
| 617 void PPB_URLLoader_Proxy::OnCallback(int32_t result, | 623 void PPB_URLLoader_Proxy::OnCallback(int32_t result, |
| 618 const HostResource& resource) { | 624 const HostResource& resource) { |
| 619 dispatcher()->Send(new PpapiMsg_PPBURLLoader_CallbackComplete( | 625 dispatcher()->Send(new PpapiMsg_PPBURLLoader_CallbackComplete( |
| 620 API_ID_PPB_URL_LOADER, resource, result)); | 626 API_ID_PPB_URL_LOADER, resource, result)); |
| 621 } | 627 } |
| 628 #endif // !defined(OS_NACL) |
| 622 | 629 |
| 623 } // namespace proxy | 630 } // namespace proxy |
| 624 } // namespace ppapi | 631 } // namespace ppapi |
| OLD | NEW |