| 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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 return; | 61 return; |
| 62 | 62 |
| 63 PPBURLLoader_UpdateProgress_Params params; | 63 PPBURLLoader_UpdateProgress_Params params; |
| 64 params.instance = pp_instance; | 64 params.instance = pp_instance; |
| 65 params.resource.SetHostResource(pp_instance, pp_resource); | 65 params.resource.SetHostResource(pp_instance, pp_resource); |
| 66 params.bytes_sent = bytes_sent; | 66 params.bytes_sent = bytes_sent; |
| 67 params.total_bytes_to_be_sent = total_bytes_to_be_sent; | 67 params.total_bytes_to_be_sent = total_bytes_to_be_sent; |
| 68 params.bytes_received = bytes_received; | 68 params.bytes_received = bytes_received; |
| 69 params.total_bytes_to_be_received = total_bytes_to_be_received; | 69 params.total_bytes_to_be_received = total_bytes_to_be_received; |
| 70 dispatcher->Send(new PpapiMsg_PPBURLLoader_UpdateProgress( | 70 dispatcher->Send(new PpapiMsg_PPBURLLoader_UpdateProgress( |
| 71 INTERFACE_ID_PPB_URL_LOADER, params)); | 71 API_ID_PPB_URL_LOADER, params)); |
| 72 } | 72 } |
| 73 | 73 |
| 74 InterfaceProxy* CreateURLLoaderProxy(Dispatcher* dispatcher) { | 74 InterfaceProxy* CreateURLLoaderProxy(Dispatcher* dispatcher) { |
| 75 return new PPB_URLLoader_Proxy(dispatcher); | 75 return new PPB_URLLoader_Proxy(dispatcher); |
| 76 } | 76 } |
| 77 | 77 |
| 78 } // namespace | 78 } // namespace |
| 79 | 79 |
| 80 // URLLoader ------------------------------------------------------------------- | 80 // URLLoader ------------------------------------------------------------------- |
| 81 | 81 |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 | 181 |
| 182 int32_t URLLoader::Open(PP_Resource request_id, | 182 int32_t URLLoader::Open(PP_Resource request_id, |
| 183 PP_CompletionCallback callback) { | 183 PP_CompletionCallback callback) { |
| 184 EnterResourceNoLock<thunk::PPB_URLRequestInfo_API> enter(request_id, true); | 184 EnterResourceNoLock<thunk::PPB_URLRequestInfo_API> enter(request_id, true); |
| 185 if (enter.failed()) | 185 if (enter.failed()) |
| 186 return PP_ERROR_BADRESOURCE; | 186 return PP_ERROR_BADRESOURCE; |
| 187 | 187 |
| 188 // TODO(brettw) http://crbug.com/86279: SendCallback doesn't ensure that | 188 // TODO(brettw) http://crbug.com/86279: SendCallback doesn't ensure that |
| 189 // the proper callback semantics happen if the object is deleted. | 189 // the proper callback semantics happen if the object is deleted. |
| 190 GetDispatcher()->Send(new PpapiHostMsg_PPBURLLoader_Open( | 190 GetDispatcher()->Send(new PpapiHostMsg_PPBURLLoader_Open( |
| 191 INTERFACE_ID_PPB_URL_LOADER, host_resource(), enter.object()->GetData(), | 191 API_ID_PPB_URL_LOADER, host_resource(), enter.object()->GetData(), |
| 192 GetDispatcher()->callback_tracker().SendCallback(callback))); | 192 GetDispatcher()->callback_tracker().SendCallback(callback))); |
| 193 return PP_OK_COMPLETIONPENDING; | 193 return PP_OK_COMPLETIONPENDING; |
| 194 } | 194 } |
| 195 | 195 |
| 196 int32_t URLLoader::FollowRedirect(PP_CompletionCallback callback) { | 196 int32_t URLLoader::FollowRedirect(PP_CompletionCallback callback) { |
| 197 // TODO(brettw) http://crbug.com/86279: SendCallback doesn't ensure that | 197 // TODO(brettw) http://crbug.com/86279: SendCallback doesn't ensure that |
| 198 // the proper callback semantics happen if the object is deleted. | 198 // the proper callback semantics happen if the object is deleted. |
| 199 GetDispatcher()->Send(new PpapiHostMsg_PPBURLLoader_FollowRedirect( | 199 GetDispatcher()->Send(new PpapiHostMsg_PPBURLLoader_FollowRedirect( |
| 200 INTERFACE_ID_PPB_URL_LOADER, host_resource(), | 200 API_ID_PPB_URL_LOADER, host_resource(), |
| 201 GetDispatcher()->callback_tracker().SendCallback(callback))); | 201 GetDispatcher()->callback_tracker().SendCallback(callback))); |
| 202 return PP_OK_COMPLETIONPENDING; | 202 return PP_OK_COMPLETIONPENDING; |
| 203 } | 203 } |
| 204 | 204 |
| 205 PP_Bool URLLoader::GetUploadProgress(int64_t* bytes_sent, | 205 PP_Bool URLLoader::GetUploadProgress(int64_t* bytes_sent, |
| 206 int64_t* total_bytes_to_be_sent) { | 206 int64_t* total_bytes_to_be_sent) { |
| 207 if (bytes_sent_ == -1) { | 207 if (bytes_sent_ == -1) { |
| 208 *bytes_sent = 0; | 208 *bytes_sent = 0; |
| 209 *total_bytes_to_be_sent = 0; | 209 *total_bytes_to_be_sent = 0; |
| 210 return PP_FALSE; | 210 return PP_FALSE; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 224 } | 224 } |
| 225 *bytes_received = bytes_received_; | 225 *bytes_received = bytes_received_; |
| 226 *total_bytes_to_be_received = total_bytes_to_be_received_; | 226 *total_bytes_to_be_received = total_bytes_to_be_received_; |
| 227 return PP_TRUE; | 227 return PP_TRUE; |
| 228 } | 228 } |
| 229 | 229 |
| 230 PP_Resource URLLoader::GetResponseInfo() { | 230 PP_Resource URLLoader::GetResponseInfo() { |
| 231 if (!response_info_) { | 231 if (!response_info_) { |
| 232 HostResource response_id; | 232 HostResource response_id; |
| 233 GetDispatcher()->Send(new PpapiHostMsg_PPBURLLoader_GetResponseInfo( | 233 GetDispatcher()->Send(new PpapiHostMsg_PPBURLLoader_GetResponseInfo( |
| 234 INTERFACE_ID_PPB_URL_LOADER, host_resource(), &response_id)); | 234 API_ID_PPB_URL_LOADER, host_resource(), &response_id)); |
| 235 if (response_id.is_null()) | 235 if (response_id.is_null()) |
| 236 return 0; | 236 return 0; |
| 237 | 237 |
| 238 response_info_ = PPB_URLResponseInfo_Proxy::CreateResponseForResource( | 238 response_info_ = PPB_URLResponseInfo_Proxy::CreateResponseForResource( |
| 239 response_id); | 239 response_id); |
| 240 } | 240 } |
| 241 | 241 |
| 242 // The caller expects to get a ref, and we want to keep holding ours. | 242 // The caller expects to get a ref, and we want to keep holding ours. |
| 243 PpapiGlobals::Get()->GetResourceTracker()->AddRefResource(response_info_); | 243 PpapiGlobals::Get()->GetResourceTracker()->AddRefResource(response_info_); |
| 244 return response_info_; | 244 return response_info_; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 262 // return data to the caller. Do so without making IPCs. | 262 // return data to the caller. Do so without making IPCs. |
| 263 PopBuffer(buffer, bytes_to_read); | 263 PopBuffer(buffer, bytes_to_read); |
| 264 return bytes_to_read; | 264 return bytes_to_read; |
| 265 } | 265 } |
| 266 | 266 |
| 267 current_read_callback_ = callback; | 267 current_read_callback_ = callback; |
| 268 current_read_buffer_ = buffer; | 268 current_read_buffer_ = buffer; |
| 269 current_read_buffer_size_ = bytes_to_read; | 269 current_read_buffer_size_ = bytes_to_read; |
| 270 | 270 |
| 271 GetDispatcher()->Send(new PpapiHostMsg_PPBURLLoader_ReadResponseBody( | 271 GetDispatcher()->Send(new PpapiHostMsg_PPBURLLoader_ReadResponseBody( |
| 272 INTERFACE_ID_PPB_URL_LOADER, host_resource(), bytes_to_read)); | 272 API_ID_PPB_URL_LOADER, host_resource(), bytes_to_read)); |
| 273 return PP_OK_COMPLETIONPENDING; | 273 return PP_OK_COMPLETIONPENDING; |
| 274 } | 274 } |
| 275 | 275 |
| 276 int32_t URLLoader::FinishStreamingToFile(PP_CompletionCallback callback) { | 276 int32_t URLLoader::FinishStreamingToFile(PP_CompletionCallback callback) { |
| 277 GetDispatcher()->Send(new PpapiHostMsg_PPBURLLoader_FinishStreamingToFile( | 277 GetDispatcher()->Send(new PpapiHostMsg_PPBURLLoader_FinishStreamingToFile( |
| 278 INTERFACE_ID_PPB_URL_LOADER, host_resource(), | 278 API_ID_PPB_URL_LOADER, host_resource(), |
| 279 GetDispatcher()->callback_tracker().SendCallback(callback))); | 279 GetDispatcher()->callback_tracker().SendCallback(callback))); |
| 280 return PP_OK_COMPLETIONPENDING; | 280 return PP_OK_COMPLETIONPENDING; |
| 281 } | 281 } |
| 282 | 282 |
| 283 void URLLoader::Close() { | 283 void URLLoader::Close() { |
| 284 GetDispatcher()->Send(new PpapiHostMsg_PPBURLLoader_Close( | 284 GetDispatcher()->Send(new PpapiHostMsg_PPBURLLoader_Close( |
| 285 INTERFACE_ID_PPB_URL_LOADER, host_resource())); | 285 API_ID_PPB_URL_LOADER, host_resource())); |
| 286 } | 286 } |
| 287 | 287 |
| 288 void URLLoader::GrantUniversalAccess() { | 288 void URLLoader::GrantUniversalAccess() { |
| 289 GetDispatcher()->Send( | 289 GetDispatcher()->Send( |
| 290 new PpapiHostMsg_PPBURLLoader_GrantUniversalAccess( | 290 new PpapiHostMsg_PPBURLLoader_GrantUniversalAccess( |
| 291 INTERFACE_ID_PPB_URL_LOADER, host_resource())); | 291 API_ID_PPB_URL_LOADER, host_resource())); |
| 292 } | 292 } |
| 293 | 293 |
| 294 void URLLoader::SetStatusCallback( | 294 void URLLoader::SetStatusCallback( |
| 295 PP_URLLoaderTrusted_StatusCallback cb) { | 295 PP_URLLoaderTrusted_StatusCallback cb) { |
| 296 // Not implemented in the proxied version, this is for implementing the | 296 // Not implemented in the proxied version, this is for implementing the |
| 297 // proxy itself in the host. | 297 // proxy itself in the host. |
| 298 } | 298 } |
| 299 | 299 |
| 300 void URLLoader::UpdateProgress( | 300 void URLLoader::UpdateProgress( |
| 301 const PPBURLLoader_UpdateProgress_Params& params) { | 301 const PPBURLLoader_UpdateProgress_Params& params) { |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 359 PP_Resource PPB_URLLoader_Proxy::TrackPluginResource( | 359 PP_Resource PPB_URLLoader_Proxy::TrackPluginResource( |
| 360 const HostResource& url_loader_resource) { | 360 const HostResource& url_loader_resource) { |
| 361 return (new URLLoader(url_loader_resource))->GetReference(); | 361 return (new URLLoader(url_loader_resource))->GetReference(); |
| 362 } | 362 } |
| 363 | 363 |
| 364 // static | 364 // static |
| 365 const InterfaceProxy::Info* PPB_URLLoader_Proxy::GetTrustedInfo() { | 365 const InterfaceProxy::Info* PPB_URLLoader_Proxy::GetTrustedInfo() { |
| 366 static const Info info = { | 366 static const Info info = { |
| 367 thunk::GetPPB_URLLoaderTrusted_Thunk(), | 367 thunk::GetPPB_URLLoaderTrusted_Thunk(), |
| 368 PPB_URLLOADERTRUSTED_INTERFACE, | 368 PPB_URLLOADERTRUSTED_INTERFACE, |
| 369 INTERFACE_ID_NONE, // URL_LOADER is the canonical one. | 369 API_ID_NONE, // URL_LOADER is the canonical one. |
| 370 false, | 370 false, |
| 371 &CreateURLLoaderProxy | 371 &CreateURLLoaderProxy |
| 372 }; | 372 }; |
| 373 return &info; | 373 return &info; |
| 374 } | 374 } |
| 375 | 375 |
| 376 // static | 376 // static |
| 377 PP_Resource PPB_URLLoader_Proxy::CreateProxyResource(PP_Instance pp_instance) { | 377 PP_Resource PPB_URLLoader_Proxy::CreateProxyResource(PP_Instance pp_instance) { |
| 378 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(pp_instance); | 378 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(pp_instance); |
| 379 if (!dispatcher) | 379 if (!dispatcher) |
| 380 return 0; | 380 return 0; |
| 381 | 381 |
| 382 HostResource result; | 382 HostResource result; |
| 383 dispatcher->Send(new PpapiHostMsg_PPBURLLoader_Create( | 383 dispatcher->Send(new PpapiHostMsg_PPBURLLoader_Create( |
| 384 INTERFACE_ID_PPB_URL_LOADER, pp_instance, &result)); | 384 API_ID_PPB_URL_LOADER, pp_instance, &result)); |
| 385 if (result.is_null()) | 385 if (result.is_null()) |
| 386 return 0; | 386 return 0; |
| 387 return PPB_URLLoader_Proxy::TrackPluginResource(result); | 387 return PPB_URLLoader_Proxy::TrackPluginResource(result); |
| 388 } | 388 } |
| 389 | 389 |
| 390 bool PPB_URLLoader_Proxy::OnMessageReceived(const IPC::Message& msg) { | 390 bool PPB_URLLoader_Proxy::OnMessageReceived(const IPC::Message& msg) { |
| 391 bool handled = true; | 391 bool handled = true; |
| 392 IPC_BEGIN_MESSAGE_MAP(PPB_URLLoader_Proxy, msg) | 392 IPC_BEGIN_MESSAGE_MAP(PPB_URLLoader_Proxy, msg) |
| 393 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBURLLoader_Create, | 393 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBURLLoader_Create, |
| 394 OnMsgCreate) | 394 OnMsgCreate) |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 567 } | 567 } |
| 568 | 568 |
| 569 void PPB_URLLoader_Proxy::OnReadCallback(int32_t result, | 569 void PPB_URLLoader_Proxy::OnReadCallback(int32_t result, |
| 570 ReadCallbackInfo* info) { | 570 ReadCallbackInfo* info) { |
| 571 int32_t bytes_read = 0; | 571 int32_t bytes_read = 0; |
| 572 if (result > 0) | 572 if (result > 0) |
| 573 bytes_read = result; // Positive results indicate bytes read. | 573 bytes_read = result; // Positive results indicate bytes read. |
| 574 info->read_buffer.resize(bytes_read); | 574 info->read_buffer.resize(bytes_read); |
| 575 | 575 |
| 576 dispatcher()->Send(new PpapiMsg_PPBURLLoader_ReadResponseBody_Ack( | 576 dispatcher()->Send(new PpapiMsg_PPBURLLoader_ReadResponseBody_Ack( |
| 577 INTERFACE_ID_PPB_URL_LOADER, info->resource, result, info->read_buffer)); | 577 API_ID_PPB_URL_LOADER, info->resource, result, info->read_buffer)); |
| 578 | 578 |
| 579 delete info; | 579 delete info; |
| 580 } | 580 } |
| 581 | 581 |
| 582 } // namespace proxy | 582 } // namespace proxy |
| 583 } // namespace ppapi | 583 } // namespace ppapi |
| OLD | NEW |