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) |
431 IPC_MESSAGE_HANDLER(PpapiMsg_PPBURLLoader_UpdateProgress, | 432 IPC_MESSAGE_HANDLER(PpapiMsg_PPBURLLoader_UpdateProgress, |
432 OnMsgUpdateProgress) | 433 OnMsgUpdateProgress) |
| 434 #endif // !defined(OS_NACL) |
| 435 |
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 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 } |
556 | 560 |
| 561 void PPB_URLLoader_Proxy::OnReadCallback(int32_t result, |
| 562 IPC::Message* message) { |
| 563 int32_t bytes_read = 0; |
| 564 if (result > 0) |
| 565 bytes_read = result; // Positive results indicate bytes read. |
| 566 |
| 567 message->TrimWriteData(bytes_read); |
| 568 message->WriteInt(result); |
| 569 |
| 570 dispatcher()->Send(message); |
| 571 } |
| 572 |
| 573 void PPB_URLLoader_Proxy::OnCallback(int32_t result, |
| 574 const HostResource& resource) { |
| 575 dispatcher()->Send(new PpapiMsg_PPBURLLoader_CallbackComplete( |
| 576 API_ID_PPB_URL_LOADER, resource, result)); |
| 577 } |
| 578 #endif // !defined(OS_NACL) |
| 579 |
557 // Called in the Plugin. | 580 // Called in the Plugin. |
558 void PPB_URLLoader_Proxy::OnMsgUpdateProgress( | 581 void PPB_URLLoader_Proxy::OnMsgUpdateProgress( |
559 const PPBURLLoader_UpdateProgress_Params& params) { | 582 const PPBURLLoader_UpdateProgress_Params& params) { |
560 EnterPluginFromHostResource<PPB_URLLoader_API> enter(params.resource); | 583 EnterPluginFromHostResource<PPB_URLLoader_API> enter(params.resource); |
561 if (enter.succeeded()) | 584 if (enter.succeeded()) |
562 static_cast<URLLoader*>(enter.object())->UpdateProgress(params); | 585 static_cast<URLLoader*>(enter.object())->UpdateProgress(params); |
563 } | 586 } |
564 | 587 |
565 // Called in the Plugin. | 588 // Called in the Plugin. |
566 void PPB_URLLoader_Proxy::OnMsgReadResponseBodyAck( | 589 void PPB_URLLoader_Proxy::OnMsgReadResponseBodyAck( |
(...skipping 28 matching lines...) Expand all Loading... |
595 | 618 |
596 // Called in the plugin. | 619 // Called in the plugin. |
597 void PPB_URLLoader_Proxy::OnMsgCallbackComplete( | 620 void PPB_URLLoader_Proxy::OnMsgCallbackComplete( |
598 const HostResource& host_resource, | 621 const HostResource& host_resource, |
599 int32_t result) { | 622 int32_t result) { |
600 EnterPluginFromHostResource<PPB_URLLoader_API> enter(host_resource); | 623 EnterPluginFromHostResource<PPB_URLLoader_API> enter(host_resource); |
601 if (enter.succeeded()) | 624 if (enter.succeeded()) |
602 static_cast<URLLoader*>(enter.object())->CallbackComplete(result); | 625 static_cast<URLLoader*>(enter.object())->CallbackComplete(result); |
603 } | 626 } |
604 | 627 |
605 void PPB_URLLoader_Proxy::OnReadCallback(int32_t result, | |
606 IPC::Message* message) { | |
607 int32_t bytes_read = 0; | |
608 if (result > 0) | |
609 bytes_read = result; // Positive results indicate bytes read. | |
610 | |
611 message->TrimWriteData(bytes_read); | |
612 message->WriteInt(result); | |
613 | |
614 dispatcher()->Send(message); | |
615 } | |
616 | |
617 void PPB_URLLoader_Proxy::OnCallback(int32_t result, | |
618 const HostResource& resource) { | |
619 dispatcher()->Send(new PpapiMsg_PPBURLLoader_CallbackComplete( | |
620 API_ID_PPB_URL_LOADER, resource, result)); | |
621 } | |
622 | |
623 } // namespace proxy | 628 } // namespace proxy |
624 } // namespace ppapi | 629 } // namespace ppapi |
OLD | NEW |