| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 PP_Resource Create(PP_Instance instance_id) { | 68 PP_Resource Create(PP_Instance instance_id) { |
| 69 PluginDispatcher* dispatcher = PluginDispatcher::Get(); | 69 PluginDispatcher* dispatcher = PluginDispatcher::Get(); |
| 70 PP_Resource result = 0; | 70 PP_Resource result = 0; |
| 71 dispatcher->Send(new PpapiHostMsg_PPBURLLoader_Create( | 71 dispatcher->Send(new PpapiHostMsg_PPBURLLoader_Create( |
| 72 INTERFACE_ID_PPB_URL_LOADER, instance_id, &result)); | 72 INTERFACE_ID_PPB_URL_LOADER, instance_id, &result)); |
| 73 if (result) | 73 if (result) |
| 74 PPB_URLLoader_Proxy::TrackPluginResource(result); | 74 PPB_URLLoader_Proxy::TrackPluginResource(result); |
| 75 return result; | 75 return result; |
| 76 } | 76 } |
| 77 | 77 |
| 78 bool IsURLLoader(PP_Resource resource) { | 78 PP_Bool IsURLLoader(PP_Resource resource) { |
| 79 URLLoader* object = PluginResource::GetAs<URLLoader>(resource); | 79 URLLoader* object = PluginResource::GetAs<URLLoader>(resource); |
| 80 return !!object; | 80 return BoolToPPBool(!!object); |
| 81 } | 81 } |
| 82 | 82 |
| 83 int32_t Open(PP_Resource loader_id, | 83 int32_t Open(PP_Resource loader_id, |
| 84 PP_Resource request_id, | 84 PP_Resource request_id, |
| 85 PP_CompletionCallback callback) { | 85 PP_CompletionCallback callback) { |
| 86 Dispatcher* dispatcher = PluginDispatcher::Get(); | 86 Dispatcher* dispatcher = PluginDispatcher::Get(); |
| 87 dispatcher->Send(new PpapiHostMsg_PPBURLLoader_Open( | 87 dispatcher->Send(new PpapiHostMsg_PPBURLLoader_Open( |
| 88 INTERFACE_ID_PPB_URL_LOADER, loader_id, request_id, | 88 INTERFACE_ID_PPB_URL_LOADER, loader_id, request_id, |
| 89 dispatcher->callback_tracker().SendCallback(callback))); | 89 dispatcher->callback_tracker().SendCallback(callback))); |
| 90 return PP_ERROR_WOULDBLOCK; | 90 return PP_ERROR_WOULDBLOCK; |
| 91 } | 91 } |
| 92 | 92 |
| 93 int32_t FollowRedirect(PP_Resource loader_id, | 93 int32_t FollowRedirect(PP_Resource loader_id, |
| 94 PP_CompletionCallback callback) { | 94 PP_CompletionCallback callback) { |
| 95 Dispatcher* dispatcher = PluginDispatcher::Get(); | 95 Dispatcher* dispatcher = PluginDispatcher::Get(); |
| 96 dispatcher->Send(new PpapiHostMsg_PPBURLLoader_FollowRedirect( | 96 dispatcher->Send(new PpapiHostMsg_PPBURLLoader_FollowRedirect( |
| 97 INTERFACE_ID_PPB_URL_LOADER, loader_id, | 97 INTERFACE_ID_PPB_URL_LOADER, loader_id, |
| 98 dispatcher->callback_tracker().SendCallback(callback))); | 98 dispatcher->callback_tracker().SendCallback(callback))); |
| 99 return PP_ERROR_WOULDBLOCK; | 99 return PP_ERROR_WOULDBLOCK; |
| 100 } | 100 } |
| 101 | 101 |
| 102 bool GetUploadProgress(PP_Resource loader_id, | 102 PP_Bool GetUploadProgress(PP_Resource loader_id, |
| 103 int64_t* bytes_sent, | 103 int64_t* bytes_sent, |
| 104 int64_t* total_bytes_to_be_sent) { | 104 int64_t* total_bytes_to_be_sent) { |
| 105 URLLoader* object = PluginResource::GetAs<URLLoader>(loader_id); | 105 URLLoader* object = PluginResource::GetAs<URLLoader>(loader_id); |
| 106 if (!object || object->bytes_sent_ == -1) { | 106 if (!object || object->bytes_sent_ == -1) { |
| 107 *bytes_sent = 0; | 107 *bytes_sent = 0; |
| 108 *total_bytes_to_be_sent = 0; | 108 *total_bytes_to_be_sent = 0; |
| 109 return false; | 109 return PP_FALSE; |
| 110 } | 110 } |
| 111 *bytes_sent = object->bytes_sent_; | 111 *bytes_sent = object->bytes_sent_; |
| 112 *total_bytes_to_be_sent = object->total_bytes_to_be_sent_; | 112 *total_bytes_to_be_sent = object->total_bytes_to_be_sent_; |
| 113 return true; | 113 return PP_TRUE; |
| 114 } | 114 } |
| 115 | 115 |
| 116 bool GetDownloadProgress(PP_Resource loader_id, | 116 PP_Bool GetDownloadProgress(PP_Resource loader_id, |
| 117 int64_t* bytes_received, | 117 int64_t* bytes_received, |
| 118 int64_t* total_bytes_to_be_received) { | 118 int64_t* total_bytes_to_be_received) { |
| 119 URLLoader* object = PluginResource::GetAs<URLLoader>(loader_id); | 119 URLLoader* object = PluginResource::GetAs<URLLoader>(loader_id); |
| 120 if (!object || object->bytes_received_ == -1) { | 120 if (!object || object->bytes_received_ == -1) { |
| 121 *bytes_received = 0; | 121 *bytes_received = 0; |
| 122 *total_bytes_to_be_received = 0; | 122 *total_bytes_to_be_received = 0; |
| 123 return false; | 123 return PP_FALSE; |
| 124 } | 124 } |
| 125 *bytes_received = object->bytes_received_; | 125 *bytes_received = object->bytes_received_; |
| 126 *total_bytes_to_be_received = object->total_bytes_to_be_received_; | 126 *total_bytes_to_be_received = object->total_bytes_to_be_received_; |
| 127 return true; | 127 return PP_TRUE; |
| 128 } | 128 } |
| 129 | 129 |
| 130 PP_Resource GetResponseInfo(PP_Resource loader_id) { | 130 PP_Resource GetResponseInfo(PP_Resource loader_id) { |
| 131 // If we find that plugins are frequently requesting the response info, we | 131 // If we find that plugins are frequently requesting the response info, we |
| 132 // can improve performance by caching the PP_Resource in the URLLoader | 132 // can improve performance by caching the PP_Resource in the URLLoader |
| 133 // object. This way we only have to do IPC for the first request. However, | 133 // object. This way we only have to do IPC for the first request. However, |
| 134 // it seems that most plugins will only call this once so there's no use | 134 // it seems that most plugins will only call this once so there's no use |
| 135 // optimizing this case. | 135 // optimizing this case. |
| 136 | 136 |
| 137 PP_Resource result; | 137 PP_Resource result; |
| (...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 410 // The plugin should be able to make a new request from their callback, so | 410 // The plugin should be able to make a new request from their callback, so |
| 411 // we have to clear our copy first. | 411 // we have to clear our copy first. |
| 412 PP_CompletionCallback temp_callback = object->current_read_callback_; | 412 PP_CompletionCallback temp_callback = object->current_read_callback_; |
| 413 object->current_read_callback_ = PP_BlockUntilComplete(); | 413 object->current_read_callback_ = PP_BlockUntilComplete(); |
| 414 object->current_read_buffer_ = NULL; | 414 object->current_read_buffer_ = NULL; |
| 415 PP_RunCompletionCallback(&temp_callback, result); | 415 PP_RunCompletionCallback(&temp_callback, result); |
| 416 } | 416 } |
| 417 | 417 |
| 418 } // namespace proxy | 418 } // namespace proxy |
| 419 } // namespace pp | 419 } // namespace pp |
| OLD | NEW |