Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(507)

Side by Side Diff: webkit/plugins/ppapi/ppb_url_loader_impl.cc

Issue 10993031: Refactor the URLResponseInfo to use new design (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: revert shim Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "webkit/plugins/ppapi/ppb_url_loader_impl.h" 5 #include "webkit/plugins/ppapi/ppb_url_loader_impl.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "net/base/net_errors.h" 8 #include "net/base/net_errors.h"
9 #include "ppapi/c/pp_completion_callback.h" 9 #include "ppapi/c/pp_completion_callback.h"
10 #include "ppapi/c/pp_errors.h" 10 #include "ppapi/c/pp_errors.h"
11 #include "ppapi/c/ppb_url_loader.h" 11 #include "ppapi/c/ppb_url_loader.h"
12 #include "ppapi/c/trusted/ppb_url_loader_trusted.h" 12 #include "ppapi/c/trusted/ppb_url_loader_trusted.h"
13 #include "ppapi/shared_impl/ppapi_globals.h"
14 #include "ppapi/shared_impl/url_response_info_data.h"
13 #include "ppapi/thunk/enter.h" 15 #include "ppapi/thunk/enter.h"
14 #include "ppapi/thunk/ppb_url_request_info_api.h" 16 #include "ppapi/thunk/ppb_url_request_info_api.h"
15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" 17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h"
16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h" 18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h"
17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" 19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h" 20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h"
19 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebKitPlatfo rmSupport.h" 21 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebKitPlatfo rmSupport.h"
20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h" 22 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h"
21 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h" 23 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h"
22 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLError. h" 24 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLError. h"
23 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLLoader .h" 25 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLLoader .h"
24 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLLoaderOptions.h " 26 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLLoaderOptions.h "
25 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLReques t.h" 27 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLReques t.h"
26 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLRespon se.h" 28 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLRespon se.h"
27 #include "webkit/appcache/web_application_cache_host_impl.h" 29 #include "webkit/appcache/web_application_cache_host_impl.h"
28 #include "webkit/plugins/ppapi/common.h" 30 #include "webkit/plugins/ppapi/common.h"
29 #include "webkit/plugins/ppapi/plugin_module.h" 31 #include "webkit/plugins/ppapi/plugin_module.h"
30 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" 32 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
31 #include "webkit/plugins/ppapi/resource_helper.h" 33 #include "webkit/plugins/ppapi/resource_helper.h"
32 #include "webkit/plugins/ppapi/url_request_info_util.h" 34 #include "webkit/plugins/ppapi/url_request_info_util.h"
33 #include "webkit/plugins/ppapi/ppb_url_response_info_impl.h" 35 #include "webkit/plugins/ppapi/url_response_info_util.h"
34 36
35 using appcache::WebApplicationCacheHostImpl; 37 using appcache::WebApplicationCacheHostImpl;
36 using ppapi::Resource; 38 using ppapi::Resource;
37 using ppapi::thunk::EnterResourceNoLock; 39 using ppapi::thunk::EnterResourceNoLock;
38 using ppapi::thunk::PPB_URLLoader_API; 40 using ppapi::thunk::PPB_URLLoader_API;
39 using ppapi::thunk::PPB_URLRequestInfo_API; 41 using ppapi::thunk::PPB_URLRequestInfo_API;
40 using ppapi::TrackedCallback; 42 using ppapi::TrackedCallback;
41 using WebKit::WebFrame; 43 using WebKit::WebFrame;
42 using WebKit::WebString; 44 using WebKit::WebString;
43 using WebKit::WebURL; 45 using WebKit::WebURL;
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 *bytes_received = 0; 215 *bytes_received = 0;
214 *total_bytes_to_be_received = 0; 216 *total_bytes_to_be_received = 0;
215 return PP_FALSE; 217 return PP_FALSE;
216 } 218 }
217 *bytes_received = bytes_received_; 219 *bytes_received = bytes_received_;
218 *total_bytes_to_be_received = total_bytes_to_be_received_; 220 *total_bytes_to_be_received = total_bytes_to_be_received_;
219 return PP_TRUE; 221 return PP_TRUE;
220 } 222 }
221 223
222 PP_Resource PPB_URLLoader_Impl::GetResponseInfo() { 224 PP_Resource PPB_URLLoader_Impl::GetResponseInfo() {
223 if (!response_info_) 225 ::ppapi::thunk::EnterResourceCreationNoLock enter(pp_instance());
226 if (enter.failed() || !response_info_.get())
224 return 0; 227 return 0;
225 return response_info_->GetReference(); 228
229 // Since we're the "host" the process-local resource for the file ref is
230 // the same as the host resource.
231 return enter.functions()->CreateURLResponseInfo(
232 pp_instance(),
233 *response_info_,
234 response_info_->body_as_file_ref.resource.host_resource());
226 } 235 }
227 236
228 int32_t PPB_URLLoader_Impl::ReadResponseBody( 237 int32_t PPB_URLLoader_Impl::ReadResponseBody(
229 void* buffer, 238 void* buffer,
230 int32_t bytes_to_read, 239 int32_t bytes_to_read,
231 scoped_refptr<TrackedCallback> callback) { 240 scoped_refptr<TrackedCallback> callback) {
232 int32_t rv = ValidateCallback(callback); 241 int32_t rv = ValidateCallback(callback);
233 if (rv != PP_OK) 242 if (rv != PP_OK)
234 return rv; 243 return rv;
235 if (!response_info_ || response_info_->body()) 244 if (!response_info_.get() ||
245 !response_info_->body_as_file_ref.resource.is_null())
236 return PP_ERROR_FAILED; 246 return PP_ERROR_FAILED;
237 if (bytes_to_read <= 0 || !buffer) 247 if (bytes_to_read <= 0 || !buffer)
238 return PP_ERROR_BADARGUMENT; 248 return PP_ERROR_BADARGUMENT;
239 249
240 user_buffer_ = static_cast<char*>(buffer); 250 user_buffer_ = static_cast<char*>(buffer);
241 user_buffer_size_ = bytes_to_read; 251 user_buffer_size_ = bytes_to_read;
242 252
243 if (!buffer_.empty()) 253 if (!buffer_.empty())
244 return FillUserBuffer(); 254 return FillUserBuffer();
245 255
246 // We may have already reached EOF. 256 // We may have already reached EOF.
247 if (done_status_ != PP_OK_COMPLETIONPENDING) { 257 if (done_status_ != PP_OK_COMPLETIONPENDING) {
248 user_buffer_ = NULL; 258 user_buffer_ = NULL;
249 user_buffer_size_ = 0; 259 user_buffer_size_ = 0;
250 return done_status_; 260 return done_status_;
251 } 261 }
252 262
253 RegisterCallback(callback); 263 RegisterCallback(callback);
254 return PP_OK_COMPLETIONPENDING; 264 return PP_OK_COMPLETIONPENDING;
255 } 265 }
256 266
257 int32_t PPB_URLLoader_Impl::FinishStreamingToFile( 267 int32_t PPB_URLLoader_Impl::FinishStreamingToFile(
258 scoped_refptr<TrackedCallback> callback) { 268 scoped_refptr<TrackedCallback> callback) {
259 int32_t rv = ValidateCallback(callback); 269 int32_t rv = ValidateCallback(callback);
260 if (rv != PP_OK) 270 if (rv != PP_OK)
261 return rv; 271 return rv;
262 if (!response_info_ || !response_info_->body()) 272 if (!response_info_.get() ||
273 response_info_->body_as_file_ref.resource.is_null())
263 return PP_ERROR_FAILED; 274 return PP_ERROR_FAILED;
264 275
265 // We may have already reached EOF. 276 // We may have already reached EOF.
266 if (done_status_ != PP_OK_COMPLETIONPENDING) 277 if (done_status_ != PP_OK_COMPLETIONPENDING)
267 return done_status_; 278 return done_status_;
268 279
269 is_streaming_to_file_ = true; 280 is_streaming_to_file_ = true;
270 if (is_asynchronous_load_suspended_) 281 if (is_asynchronous_load_suspended_)
271 SetDefersLoading(false); 282 SetDefersLoading(false);
272 283
(...skipping 13 matching lines...) Expand all
286 297
287 void PPB_URLLoader_Impl::GrantUniversalAccess() { 298 void PPB_URLLoader_Impl::GrantUniversalAccess() {
288 has_universal_access_ = true; 299 has_universal_access_ = true;
289 } 300 }
290 301
291 void PPB_URLLoader_Impl::SetStatusCallback( 302 void PPB_URLLoader_Impl::SetStatusCallback(
292 PP_URLLoaderTrusted_StatusCallback cb) { 303 PP_URLLoaderTrusted_StatusCallback cb) {
293 status_callback_ = cb; 304 status_callback_ = cb;
294 } 305 }
295 306
307 bool PPB_URLLoader_Impl::GetResponseInfoData(
308 ::ppapi::URLResponseInfoData* data) {
309 if (!response_info_.get())
310 return false;
311
312 *data = *response_info_;
313
314 // We transfer one plugin reference to the FileRef to the caller.
315 if (!response_info_->body_as_file_ref.resource.is_null()) {
316 ::ppapi::PpapiGlobals::Get()->GetResourceTracker()->AddRefResource(
317 response_info_->body_as_file_ref.resource.host_resource());
318 }
319 return true;
320 }
321
296 void PPB_URLLoader_Impl::willSendRequest( 322 void PPB_URLLoader_Impl::willSendRequest(
297 WebURLLoader* loader, 323 WebURLLoader* loader,
298 WebURLRequest& new_request, 324 WebURLRequest& new_request,
299 const WebURLResponse& redirect_response) { 325 const WebURLResponse& redirect_response) {
300 if (!request_data_.follow_redirects) { 326 if (!request_data_.follow_redirects) {
301 SaveResponse(redirect_response); 327 SaveResponse(redirect_response);
302 SetDefersLoading(true); 328 SetDefersLoading(true);
303 RunCallback(PP_OK); 329 RunCallback(PP_OK);
304 } 330 }
305 } 331 }
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
464 SetDefersLoading(false); 490 SetDefersLoading(false);
465 } 491 }
466 492
467 // Reset for next time. 493 // Reset for next time.
468 user_buffer_ = NULL; 494 user_buffer_ = NULL;
469 user_buffer_size_ = 0; 495 user_buffer_size_ = 0;
470 return bytes_to_copy; 496 return bytes_to_copy;
471 } 497 }
472 498
473 void PPB_URLLoader_Impl::SaveResponse(const WebURLResponse& response) { 499 void PPB_URLLoader_Impl::SaveResponse(const WebURLResponse& response) {
474 scoped_refptr<PPB_URLResponseInfo_Impl> response_info( 500 // DataFromWebURLResponse returns a file ref with one reference to it, which
475 new PPB_URLResponseInfo_Impl(pp_instance())); 501 // we take over via our ScopedPPResource.
476 if (response_info->Initialize(response)) 502 response_info_.reset(new ::ppapi::URLResponseInfoData(
477 response_info_ = response_info; 503 DataFromWebURLResponse(pp_instance(), response)));
504 response_info_file_ref_ = ::ppapi::ScopedPPResource(
505 ::ppapi::ScopedPPResource::PassRef(),
506 response_info_->body_as_file_ref.resource.host_resource());
478 } 507 }
479 508
480 void PPB_URLLoader_Impl::UpdateStatus() { 509 void PPB_URLLoader_Impl::UpdateStatus() {
481 if (status_callback_ && 510 if (status_callback_ &&
482 (RecordDownloadProgress() || RecordUploadProgress())) { 511 (RecordDownloadProgress() || RecordUploadProgress())) {
483 // Here we go through some effort to only send the exact information that 512 // Here we go through some effort to only send the exact information that
484 // the requestor wanted in the request flags. It would be just as 513 // the requestor wanted in the request flags. It would be just as
485 // efficient to send all of it, but we don't want people to rely on 514 // efficient to send all of it, but we don't want people to rely on
486 // getting download progress when they happen to set the upload progress 515 // getting download progress when they happen to set the upload progress
487 // flag. 516 // flag.
488 status_callback_( 517 status_callback_(
489 pp_instance(), pp_resource(), 518 pp_instance(), pp_resource(),
490 RecordUploadProgress() ? bytes_sent_ : -1, 519 RecordUploadProgress() ? bytes_sent_ : -1,
491 RecordUploadProgress() ? total_bytes_to_be_sent_ : -1, 520 RecordUploadProgress() ? total_bytes_to_be_sent_ : -1,
492 RecordDownloadProgress() ? bytes_received_ : -1, 521 RecordDownloadProgress() ? bytes_received_ : -1,
493 RecordDownloadProgress() ? total_bytes_to_be_received_ : -1); 522 RecordDownloadProgress() ? total_bytes_to_be_received_ : -1);
494 } 523 }
495 } 524 }
496 525
497 bool PPB_URLLoader_Impl::RecordDownloadProgress() const { 526 bool PPB_URLLoader_Impl::RecordDownloadProgress() const {
498 return request_data_.record_download_progress; 527 return request_data_.record_download_progress;
499 } 528 }
500 529
501 bool PPB_URLLoader_Impl::RecordUploadProgress() const { 530 bool PPB_URLLoader_Impl::RecordUploadProgress() const {
502 return request_data_.record_upload_progress; 531 return request_data_.record_upload_progress;
503 } 532 }
504 533
505 } // namespace ppapi 534 } // namespace ppapi
506 } // namespace webkit 535 } // namespace webkit
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698