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 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 PP_CompletionCallback callback) OVERRIDE; | 104 PP_CompletionCallback callback) OVERRIDE; |
105 virtual void Close() OVERRIDE; | 105 virtual void Close() OVERRIDE; |
106 virtual void GrantUniversalAccess() OVERRIDE; | 106 virtual void GrantUniversalAccess() OVERRIDE; |
107 virtual void SetStatusCallback( | 107 virtual void SetStatusCallback( |
108 PP_URLLoaderTrusted_StatusCallback cb) OVERRIDE; | 108 PP_URLLoaderTrusted_StatusCallback cb) OVERRIDE; |
109 | 109 |
110 // Called when the browser has new up/download progress to report. | 110 // Called when the browser has new up/download progress to report. |
111 void UpdateProgress(const PPBURLLoader_UpdateProgress_Params& params); | 111 void UpdateProgress(const PPBURLLoader_UpdateProgress_Params& params); |
112 | 112 |
113 // Called when the browser responds to our ReadResponseBody request. | 113 // Called when the browser responds to our ReadResponseBody request. |
114 void ReadResponseBodyAck(int32_t result, const std::string& data); | 114 void ReadResponseBodyAck(int32 result, const std::string& data); |
115 | |
116 // Called when any callback other than the read callback has been executed. | |
117 void CallbackComplete(int32_t result); | |
118 | 115 |
119 private: | 116 private: |
120 // Reads the give bytes out of the buffer_, placing them in the given output | 117 // Reads the give bytes out of the buffer_, placing them in the given output |
121 // buffer, and removes the bytes from the buffer. | 118 // buffer, and removes the bytes from the buffer. |
122 // | 119 // |
123 // The size must be not more than the current size of the buffer. | 120 // The size must be not more than the current size of the buffer. |
124 void PopBuffer(void* output_buffer, int32_t output_size); | 121 void PopBuffer(void* output_buffer, int32_t output_size); |
125 | 122 |
126 PluginDispatcher* GetDispatcher() const { | 123 PluginDispatcher* GetDispatcher() const { |
127 return PluginDispatcher::GetForResource(this); | 124 return PluginDispatcher::GetForResource(this); |
128 } | 125 } |
129 | 126 |
130 // Initialized to -1. Will be set to nonnegative values by the UpdateProgress | 127 // Initialized to -1. Will be set to nonnegative values by the UpdateProgress |
131 // message when the values are known. | 128 // message when the values are known. |
132 int64_t bytes_sent_; | 129 int64_t bytes_sent_; |
133 int64_t total_bytes_to_be_sent_; | 130 int64_t total_bytes_to_be_sent_; |
134 int64_t bytes_received_; | 131 int64_t bytes_received_; |
135 int64_t total_bytes_to_be_received_; | 132 int64_t total_bytes_to_be_received_; |
136 | 133 |
137 // Current completion callback for the current phase of loading. We have only | 134 // When an asynchronous read is pending, this will contain the callback and |
138 // one thing (open, follow redirect, read, etc.) outstanding at once. | 135 // the buffer to put the data. |
139 PP_CompletionCallback current_callback_; | 136 PP_CompletionCallback current_read_callback_; |
140 | |
141 // When an asynchronous read is pending, this will contain the buffer to put | |
142 // the data. The current_callback_ will identify the read callback. | |
143 void* current_read_buffer_; | 137 void* current_read_buffer_; |
144 int32_t current_read_buffer_size_; | 138 int32_t current_read_buffer_size_; |
145 | 139 |
146 // A buffer of all the data that's been sent to us from the host that we | 140 // A buffer of all the data that's been sent to us from the host that we |
147 // have yet to send out to the plugin. | 141 // have yet to send out to the plugin. |
148 std::deque<char> buffer_; | 142 std::deque<char> buffer_; |
149 | 143 |
150 // Cached copy of the response info. When nonzero, we're holding a reference | 144 // Cached copy of the response info. When nonzero, we're holding a reference |
151 // to this resource. | 145 // to this resource. |
152 PP_Resource response_info_; | 146 PP_Resource response_info_; |
153 | 147 |
154 private: | 148 private: |
155 DISALLOW_COPY_AND_ASSIGN(URLLoader); | 149 DISALLOW_COPY_AND_ASSIGN(URLLoader); |
156 }; | 150 }; |
157 | 151 |
158 URLLoader::URLLoader(const HostResource& resource) | 152 URLLoader::URLLoader(const HostResource& resource) |
159 : Resource(resource), | 153 : Resource(resource), |
160 bytes_sent_(-1), | 154 bytes_sent_(-1), |
161 total_bytes_to_be_sent_(-1), | 155 total_bytes_to_be_sent_(-1), |
162 bytes_received_(-1), | 156 bytes_received_(-1), |
163 total_bytes_to_be_received_(-1), | 157 total_bytes_to_be_received_(-1), |
164 current_callback_(PP_MakeCompletionCallback(NULL, NULL)), | 158 current_read_callback_(PP_MakeCompletionCallback(NULL, NULL)), |
165 current_read_buffer_(NULL), | 159 current_read_buffer_(NULL), |
166 current_read_buffer_size_(0), | 160 current_read_buffer_size_(0), |
167 response_info_(0) { | 161 response_info_(0) { |
168 } | 162 } |
169 | 163 |
170 URLLoader::~URLLoader() { | 164 URLLoader::~URLLoader() { |
171 // Always need to fire completion callbacks to prevent a leak in the plugin. | 165 // Always need to fire completion callbacks to prevent a leak in the plugin. |
172 if (current_callback_.func) { | 166 if (current_read_callback_.func) { |
173 // TODO(brettw) the callbacks at this level should be refactored with a | 167 // TODO(brettw) the callbacks at this level should be refactored with a |
174 // more automatic tracking system like we have in the renderer. | 168 // more automatic tracking system like we have in the renderer. |
175 MessageLoop::current()->PostTask(FROM_HERE, base::Bind( | 169 MessageLoop::current()->PostTask(FROM_HERE, base::Bind( |
176 current_callback_.func, current_callback_.user_data, | 170 current_read_callback_.func, current_read_callback_.user_data, |
177 static_cast<int32_t>(PP_ERROR_ABORTED))); | 171 static_cast<int32_t>(PP_ERROR_ABORTED))); |
178 } | 172 } |
179 | 173 |
180 if (response_info_) | 174 if (response_info_) |
181 PpapiGlobals::Get()->GetResourceTracker()->ReleaseResource(response_info_); | 175 PpapiGlobals::Get()->GetResourceTracker()->ReleaseResource(response_info_); |
182 } | 176 } |
183 | 177 |
184 PPB_URLLoader_API* URLLoader::AsPPB_URLLoader_API() { | 178 PPB_URLLoader_API* URLLoader::AsPPB_URLLoader_API() { |
185 return this; | 179 return this; |
186 } | 180 } |
187 | 181 |
188 int32_t URLLoader::Open(PP_Resource request_id, | 182 int32_t URLLoader::Open(PP_Resource request_id, |
189 PP_CompletionCallback callback) { | 183 PP_CompletionCallback callback) { |
190 EnterResourceNoLock<thunk::PPB_URLRequestInfo_API> enter(request_id, true); | 184 EnterResourceNoLock<thunk::PPB_URLRequestInfo_API> enter(request_id, true); |
191 if (enter.failed()) | 185 if (enter.failed()) |
192 return PP_ERROR_BADRESOURCE; | 186 return PP_ERROR_BADRESOURCE; |
193 | 187 |
194 if (current_callback_.func) | 188 // TODO(brettw) http://crbug.com/86279: SendCallback doesn't ensure that |
195 return PP_ERROR_INPROGRESS; | 189 // the proper callback semantics happen if the object is deleted. |
196 | |
197 if (!callback.func) | |
198 return PP_ERROR_BLOCKS_MAIN_THREAD; | |
199 current_callback_ = callback; | |
200 | |
201 GetDispatcher()->Send(new PpapiHostMsg_PPBURLLoader_Open( | 190 GetDispatcher()->Send(new PpapiHostMsg_PPBURLLoader_Open( |
202 API_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))); |
203 return PP_OK_COMPLETIONPENDING; | 193 return PP_OK_COMPLETIONPENDING; |
204 } | 194 } |
205 | 195 |
206 int32_t URLLoader::FollowRedirect(PP_CompletionCallback callback) { | 196 int32_t URLLoader::FollowRedirect(PP_CompletionCallback callback) { |
207 if (current_callback_.func) | 197 // TODO(brettw) http://crbug.com/86279: SendCallback doesn't ensure that |
208 return PP_ERROR_INPROGRESS; | 198 // the proper callback semantics happen if the object is deleted. |
209 | |
210 if (!callback.func) | |
211 return PP_ERROR_BLOCKS_MAIN_THREAD; | |
212 current_callback_ = callback; | |
213 | |
214 GetDispatcher()->Send(new PpapiHostMsg_PPBURLLoader_FollowRedirect( | 199 GetDispatcher()->Send(new PpapiHostMsg_PPBURLLoader_FollowRedirect( |
215 API_ID_PPB_URL_LOADER, host_resource())); | 200 API_ID_PPB_URL_LOADER, host_resource(), |
| 201 GetDispatcher()->callback_tracker().SendCallback(callback))); |
216 return PP_OK_COMPLETIONPENDING; | 202 return PP_OK_COMPLETIONPENDING; |
217 } | 203 } |
218 | 204 |
219 PP_Bool URLLoader::GetUploadProgress(int64_t* bytes_sent, | 205 PP_Bool URLLoader::GetUploadProgress(int64_t* bytes_sent, |
220 int64_t* total_bytes_to_be_sent) { | 206 int64_t* total_bytes_to_be_sent) { |
221 if (bytes_sent_ == -1) { | 207 if (bytes_sent_ == -1) { |
222 *bytes_sent = 0; | 208 *bytes_sent = 0; |
223 *total_bytes_to_be_sent = 0; | 209 *total_bytes_to_be_sent = 0; |
224 return PP_FALSE; | 210 return PP_FALSE; |
225 } | 211 } |
(...skipping 30 matching lines...) Expand all Loading... |
256 // 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. |
257 PpapiGlobals::Get()->GetResourceTracker()->AddRefResource(response_info_); | 243 PpapiGlobals::Get()->GetResourceTracker()->AddRefResource(response_info_); |
258 return response_info_; | 244 return response_info_; |
259 } | 245 } |
260 | 246 |
261 int32_t URLLoader::ReadResponseBody(void* buffer, | 247 int32_t URLLoader::ReadResponseBody(void* buffer, |
262 int32_t bytes_to_read, | 248 int32_t bytes_to_read, |
263 PP_CompletionCallback callback) { | 249 PP_CompletionCallback callback) { |
264 if (!buffer || bytes_to_read <= 0) | 250 if (!buffer || bytes_to_read <= 0) |
265 return PP_ERROR_BADARGUMENT; // Must specify an output buffer. | 251 return PP_ERROR_BADARGUMENT; // Must specify an output buffer. |
266 if (current_callback_.func) | 252 if (current_read_callback_.func) |
267 return PP_ERROR_INPROGRESS; // Can only have one request pending. | 253 return PP_ERROR_INPROGRESS; // Can only have one request pending. |
268 | 254 |
269 // Currently we don't support sync calls to read. We'll need to revisit | 255 // Currently we don't support sync calls to read. We'll need to revisit |
270 // how this works when we allow blocking calls (from background threads). | 256 // how this works when we allow blocking calls (from background threads). |
271 if (!callback.func) | 257 if (!callback.func) |
272 return PP_ERROR_BADARGUMENT; | 258 return PP_ERROR_BADARGUMENT; |
273 | 259 |
274 if (static_cast<size_t>(bytes_to_read) <= buffer_.size()) { | 260 if (static_cast<size_t>(bytes_to_read) <= buffer_.size()) { |
275 // Special case: we've buffered enough data to be able to synchronously | 261 // Special case: we've buffered enough data to be able to synchronously |
276 // return data to the caller. Do so without making IPCs. | 262 // return data to the caller. Do so without making IPCs. |
277 PopBuffer(buffer, bytes_to_read); | 263 PopBuffer(buffer, bytes_to_read); |
278 return bytes_to_read; | 264 return bytes_to_read; |
279 } | 265 } |
280 | 266 |
281 current_callback_ = callback; | 267 current_read_callback_ = callback; |
282 current_read_buffer_ = buffer; | 268 current_read_buffer_ = buffer; |
283 current_read_buffer_size_ = bytes_to_read; | 269 current_read_buffer_size_ = bytes_to_read; |
284 | 270 |
285 GetDispatcher()->Send(new PpapiHostMsg_PPBURLLoader_ReadResponseBody( | 271 GetDispatcher()->Send(new PpapiHostMsg_PPBURLLoader_ReadResponseBody( |
286 API_ID_PPB_URL_LOADER, host_resource(), bytes_to_read)); | 272 API_ID_PPB_URL_LOADER, host_resource(), bytes_to_read)); |
287 return PP_OK_COMPLETIONPENDING; | 273 return PP_OK_COMPLETIONPENDING; |
288 } | 274 } |
289 | 275 |
290 int32_t URLLoader::FinishStreamingToFile(PP_CompletionCallback callback) { | 276 int32_t URLLoader::FinishStreamingToFile(PP_CompletionCallback callback) { |
291 if (current_callback_.func) | |
292 return PP_ERROR_INPROGRESS; | |
293 | |
294 if (!callback.func) | |
295 return PP_ERROR_BLOCKS_MAIN_THREAD; | |
296 current_callback_ = callback; | |
297 | |
298 GetDispatcher()->Send(new PpapiHostMsg_PPBURLLoader_FinishStreamingToFile( | 277 GetDispatcher()->Send(new PpapiHostMsg_PPBURLLoader_FinishStreamingToFile( |
299 API_ID_PPB_URL_LOADER, host_resource())); | 278 API_ID_PPB_URL_LOADER, host_resource(), |
| 279 GetDispatcher()->callback_tracker().SendCallback(callback))); |
300 return PP_OK_COMPLETIONPENDING; | 280 return PP_OK_COMPLETIONPENDING; |
301 } | 281 } |
302 | 282 |
303 void URLLoader::Close() { | 283 void URLLoader::Close() { |
304 GetDispatcher()->Send(new PpapiHostMsg_PPBURLLoader_Close( | 284 GetDispatcher()->Send(new PpapiHostMsg_PPBURLLoader_Close( |
305 API_ID_PPB_URL_LOADER, host_resource())); | 285 API_ID_PPB_URL_LOADER, host_resource())); |
306 } | 286 } |
307 | 287 |
308 void URLLoader::GrantUniversalAccess() { | 288 void URLLoader::GrantUniversalAccess() { |
309 GetDispatcher()->Send( | 289 GetDispatcher()->Send( |
310 new PpapiHostMsg_PPBURLLoader_GrantUniversalAccess( | 290 new PpapiHostMsg_PPBURLLoader_GrantUniversalAccess( |
311 API_ID_PPB_URL_LOADER, host_resource())); | 291 API_ID_PPB_URL_LOADER, host_resource())); |
312 } | 292 } |
313 | 293 |
314 void URLLoader::SetStatusCallback( | 294 void URLLoader::SetStatusCallback( |
315 PP_URLLoaderTrusted_StatusCallback cb) { | 295 PP_URLLoaderTrusted_StatusCallback cb) { |
316 // Not implemented in the proxied version, this is for implementing the | 296 // Not implemented in the proxied version, this is for implementing the |
317 // proxy itself in the host. | 297 // proxy itself in the host. |
318 } | 298 } |
319 | 299 |
320 void URLLoader::UpdateProgress( | 300 void URLLoader::UpdateProgress( |
321 const PPBURLLoader_UpdateProgress_Params& params) { | 301 const PPBURLLoader_UpdateProgress_Params& params) { |
322 bytes_sent_ = params.bytes_sent; | 302 bytes_sent_ = params.bytes_sent; |
323 total_bytes_to_be_sent_ = params.total_bytes_to_be_sent; | 303 total_bytes_to_be_sent_ = params.total_bytes_to_be_sent; |
324 bytes_received_ = params.bytes_received; | 304 bytes_received_ = params.bytes_received; |
325 total_bytes_to_be_received_ = params.total_bytes_to_be_received; | 305 total_bytes_to_be_received_ = params.total_bytes_to_be_received; |
326 } | 306 } |
327 | 307 |
328 void URLLoader::ReadResponseBodyAck(int32 result, const std::string& data) { | 308 void URLLoader::ReadResponseBodyAck(int32 result, const std::string& data) { |
329 if (!current_callback_.func || !current_read_buffer_) { | 309 if (!current_read_callback_.func || !current_read_buffer_) { |
330 NOTREACHED(); | 310 NOTREACHED(); |
331 return; | 311 return; |
332 } | 312 } |
333 | 313 |
334 // Append the data we requested to the internal buffer. | 314 // Append the data we requested to the internal buffer. |
335 // TODO(brettw) avoid double-copying data that's coming from IPC and going | 315 // TODO(brettw) avoid double-copying data that's coming from IPC and going |
336 // into the plugin buffer (we can skip the internal buffer in this case). | 316 // into the plugin buffer (we can skip the internal buffer in this case). |
337 buffer_.insert(buffer_.end(), data.begin(), data.end()); | 317 buffer_.insert(buffer_.end(), data.begin(), data.end()); |
338 | 318 |
339 if (result >= 0) { | 319 if (result >= 0) { |
340 // Fill the user buffer. We may get fewer bytes than requested in the | 320 // Fill the user buffer. We may get fewer bytes than requested in the |
341 // case of stream end. | 321 // case of stream end. |
342 int32_t bytes_to_return = std::min(current_read_buffer_size_, | 322 int32_t bytes_to_return = std::min(current_read_buffer_size_, |
343 static_cast<int32_t>(buffer_.size())); | 323 static_cast<int32_t>(buffer_.size())); |
344 PopBuffer(current_read_buffer_, bytes_to_return); | 324 PopBuffer(current_read_buffer_, bytes_to_return); |
345 result = bytes_to_return; | 325 result = bytes_to_return; |
346 } | 326 } |
347 | 327 |
348 // The plugin should be able to make a new request from their callback, so | 328 // The plugin should be able to make a new request from their callback, so |
349 // we have to clear our copy first. | 329 // we have to clear our copy first. |
350 PP_RunAndClearCompletionCallback(¤t_callback_, result); | 330 PP_RunAndClearCompletionCallback(¤t_read_callback_, result); |
351 } | |
352 | |
353 void URLLoader::CallbackComplete(int32_t result) { | |
354 PP_RunAndClearCompletionCallback(¤t_callback_, result); | |
355 } | 331 } |
356 | 332 |
357 void URLLoader::PopBuffer(void* output_buffer, int32_t output_size) { | 333 void URLLoader::PopBuffer(void* output_buffer, int32_t output_size) { |
358 CHECK(output_size <= static_cast<int32_t>(buffer_.size())); | 334 CHECK(output_size <= static_cast<int32_t>(buffer_.size())); |
359 std::copy(buffer_.begin(), | 335 std::copy(buffer_.begin(), |
360 buffer_.begin() + output_size, | 336 buffer_.begin() + output_size, |
361 static_cast<char*>(output_buffer)); | 337 static_cast<char*>(output_buffer)); |
362 buffer_.erase(buffer_.begin(), | 338 buffer_.erase(buffer_.begin(), |
363 buffer_.begin() + output_size); | 339 buffer_.begin() + output_size); |
364 } | 340 } |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
456 HostResource* result) { | 432 HostResource* result) { |
457 thunk::EnterResourceCreation enter(instance); | 433 thunk::EnterResourceCreation enter(instance); |
458 if (enter.succeeded()) { | 434 if (enter.succeeded()) { |
459 result->SetHostResource(instance, | 435 result->SetHostResource(instance, |
460 enter.functions()->CreateURLLoader(instance)); | 436 enter.functions()->CreateURLLoader(instance)); |
461 PrepareURLLoaderForSendingToPlugin(result->host_resource()); | 437 PrepareURLLoaderForSendingToPlugin(result->host_resource()); |
462 } | 438 } |
463 } | 439 } |
464 | 440 |
465 void PPB_URLLoader_Proxy::OnMsgOpen(const HostResource& loader, | 441 void PPB_URLLoader_Proxy::OnMsgOpen(const HostResource& loader, |
466 const PPB_URLRequestInfo_Data& data) { | 442 const PPB_URLRequestInfo_Data& data, |
467 EnterHostFromHostResourceForceCallback<PPB_URLLoader_API> enter( | 443 uint32_t serialized_callback) { |
468 loader, callback_factory_, &PPB_URLLoader_Proxy::OnCallback, loader); | 444 // Have to be careful to always issue the callback, so don't return early. |
| 445 EnterHostFromHostResource<PPB_URLLoader_API> enter(loader); |
469 thunk::EnterResourceCreation enter_creation(loader.instance()); | 446 thunk::EnterResourceCreation enter_creation(loader.instance()); |
470 if (enter.failed() || enter_creation.failed()) | |
471 return; | |
472 | 447 |
473 ScopedPPResource request_resource( | 448 PP_CompletionCallback callback = ReceiveCallback(serialized_callback); |
474 ScopedPPResource::PassRef(), | 449 |
475 enter_creation.functions()->CreateURLRequestInfo(loader.instance(), | 450 int32_t result = PP_ERROR_BADRESOURCE; |
476 data)); | 451 if (enter.succeeded() && enter_creation.succeeded()) { |
477 enter.SetResult(enter.object()->Open(request_resource, enter.callback())); | 452 ScopedPPResource request_resource( |
| 453 ScopedPPResource::PassRef(), |
| 454 enter_creation.functions()->CreateURLRequestInfo(loader.instance(), |
| 455 data)); |
| 456 result = enter.object()->Open(request_resource, callback); |
| 457 } |
| 458 if (result != PP_OK_COMPLETIONPENDING) |
| 459 PP_RunCompletionCallback(&callback, result); |
478 // TODO(brettw) bug 73236 register for the status callbacks. | 460 // TODO(brettw) bug 73236 register for the status callbacks. |
479 } | 461 } |
480 | 462 |
481 void PPB_URLLoader_Proxy::OnMsgFollowRedirect( | 463 void PPB_URLLoader_Proxy::OnMsgFollowRedirect( |
482 const HostResource& loader) { | 464 const HostResource& loader, |
483 EnterHostFromHostResourceForceCallback<PPB_URLLoader_API> enter( | 465 uint32_t serialized_callback) { |
484 loader, callback_factory_, &PPB_URLLoader_Proxy::OnCallback, loader); | 466 EnterHostFromHostResource<PPB_URLLoader_API> enter(loader); |
| 467 PP_CompletionCallback callback = ReceiveCallback(serialized_callback); |
| 468 int32_t result = PP_ERROR_BADRESOURCE; |
485 if (enter.succeeded()) | 469 if (enter.succeeded()) |
486 enter.SetResult(enter.object()->FollowRedirect(enter.callback())); | 470 result = enter.object()->FollowRedirect(callback); |
| 471 if (result != PP_OK_COMPLETIONPENDING) |
| 472 PP_RunCompletionCallback(&callback, result); |
487 } | 473 } |
488 | 474 |
489 void PPB_URLLoader_Proxy::OnMsgGetResponseInfo(const HostResource& loader, | 475 void PPB_URLLoader_Proxy::OnMsgGetResponseInfo(const HostResource& loader, |
490 HostResource* result) { | 476 HostResource* result) { |
491 EnterHostFromHostResource<PPB_URLLoader_API> enter(loader); | 477 EnterHostFromHostResource<PPB_URLLoader_API> enter(loader); |
492 if (enter.succeeded()) { | 478 if (enter.succeeded()) { |
493 result->SetHostResource(loader.instance(), | 479 result->SetHostResource(loader.instance(), |
494 enter.object()->GetResponseInfo()); | 480 enter.object()->GetResponseInfo()); |
495 } | 481 } |
496 } | 482 } |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
531 EnterHostFromHostResourceForceCallback<PPB_URLLoader_API> enter( | 517 EnterHostFromHostResourceForceCallback<PPB_URLLoader_API> enter( |
532 loader, callback_factory_, &PPB_URLLoader_Proxy::OnReadCallback, info); | 518 loader, callback_factory_, &PPB_URLLoader_Proxy::OnReadCallback, info); |
533 if (enter.succeeded()) { | 519 if (enter.succeeded()) { |
534 enter.SetResult(enter.object()->ReadResponseBody( | 520 enter.SetResult(enter.object()->ReadResponseBody( |
535 const_cast<char*>(info->read_buffer.c_str()), | 521 const_cast<char*>(info->read_buffer.c_str()), |
536 bytes_to_read, enter.callback())); | 522 bytes_to_read, enter.callback())); |
537 } | 523 } |
538 } | 524 } |
539 | 525 |
540 void PPB_URLLoader_Proxy::OnMsgFinishStreamingToFile( | 526 void PPB_URLLoader_Proxy::OnMsgFinishStreamingToFile( |
541 const HostResource& loader) { | 527 const HostResource& loader, |
542 EnterHostFromHostResourceForceCallback<PPB_URLLoader_API> enter( | 528 uint32_t serialized_callback) { |
543 loader, callback_factory_, &PPB_URLLoader_Proxy::OnCallback, loader); | 529 EnterHostFromHostResource<PPB_URLLoader_API> enter(loader); |
544 if (enter.failed()) | 530 PP_CompletionCallback callback = ReceiveCallback(serialized_callback); |
545 enter.SetResult(enter.object()->FinishStreamingToFile(enter.callback()));; | 531 int32_t result = PP_ERROR_BADRESOURCE; |
| 532 if (enter.succeeded()) |
| 533 result = enter.object()->FinishStreamingToFile(callback); |
| 534 if (result != PP_OK_COMPLETIONPENDING) |
| 535 PP_RunCompletionCallback(&callback, result); |
546 } | 536 } |
547 | 537 |
548 void PPB_URLLoader_Proxy::OnMsgClose(const HostResource& loader) { | 538 void PPB_URLLoader_Proxy::OnMsgClose(const HostResource& loader) { |
549 EnterHostFromHostResource<PPB_URLLoader_API> enter(loader); | 539 EnterHostFromHostResource<PPB_URLLoader_API> enter(loader); |
550 if (enter.succeeded()) | 540 if (enter.succeeded()) |
551 enter.object()->Close(); | 541 enter.object()->Close(); |
552 } | 542 } |
553 | 543 |
554 void PPB_URLLoader_Proxy::OnMsgGrantUniversalAccess( | 544 void PPB_URLLoader_Proxy::OnMsgGrantUniversalAccess( |
555 const HostResource& loader) { | 545 const HostResource& loader) { |
(...skipping 13 matching lines...) Expand all Loading... |
569 // Called in the Plugin. | 559 // Called in the Plugin. |
570 void PPB_URLLoader_Proxy::OnMsgReadResponseBodyAck( | 560 void PPB_URLLoader_Proxy::OnMsgReadResponseBodyAck( |
571 const HostResource& host_resource, | 561 const HostResource& host_resource, |
572 int32 result, | 562 int32 result, |
573 const std::string& data) { | 563 const std::string& data) { |
574 EnterPluginFromHostResource<PPB_URLLoader_API> enter(host_resource); | 564 EnterPluginFromHostResource<PPB_URLLoader_API> enter(host_resource); |
575 if (enter.succeeded()) | 565 if (enter.succeeded()) |
576 static_cast<URLLoader*>(enter.object())->ReadResponseBodyAck(result, data); | 566 static_cast<URLLoader*>(enter.object())->ReadResponseBodyAck(result, data); |
577 } | 567 } |
578 | 568 |
579 // Called in the plugin. | |
580 void PPB_URLLoader_Proxy::OnMsgCallbackComplete( | |
581 const HostResource& host_resource, | |
582 int32_t result) { | |
583 EnterPluginFromHostResource<PPB_URLLoader_API> enter(host_resource); | |
584 if (enter.succeeded()) | |
585 static_cast<URLLoader*>(enter.object())->CallbackComplete(result); | |
586 } | |
587 | |
588 void PPB_URLLoader_Proxy::OnReadCallback(int32_t result, | 569 void PPB_URLLoader_Proxy::OnReadCallback(int32_t result, |
589 ReadCallbackInfo* info) { | 570 ReadCallbackInfo* info) { |
590 int32_t bytes_read = 0; | 571 int32_t bytes_read = 0; |
591 if (result > 0) | 572 if (result > 0) |
592 bytes_read = result; // Positive results indicate bytes read. | 573 bytes_read = result; // Positive results indicate bytes read. |
593 info->read_buffer.resize(bytes_read); | 574 info->read_buffer.resize(bytes_read); |
594 | 575 |
595 dispatcher()->Send(new PpapiMsg_PPBURLLoader_ReadResponseBody_Ack( | 576 dispatcher()->Send(new PpapiMsg_PPBURLLoader_ReadResponseBody_Ack( |
596 API_ID_PPB_URL_LOADER, info->resource, result, info->read_buffer)); | 577 API_ID_PPB_URL_LOADER, info->resource, result, info->read_buffer)); |
597 | 578 |
598 delete info; | 579 delete info; |
599 } | 580 } |
600 | 581 |
601 void PPB_URLLoader_Proxy::OnCallback(int32_t result, | |
602 const HostResource& resource) { | |
603 dispatcher()->Send(new PpapiMsg_PPBURLLoader_CallbackComplete( | |
604 API_ID_PPB_URL_LOADER, resource, result)); | |
605 } | |
606 | |
607 } // namespace proxy | 582 } // namespace proxy |
608 } // namespace ppapi | 583 } // namespace ppapi |
OLD | NEW |