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