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

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

Issue 7046091: Fix problems with PPB_URLLoader_Impl and PPAPITests.URLLoader. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 6 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
« no previous file with comments | « ppapi/tests/test_url_loader.cc ('k') | webkit/plugins/ppapi/ppb_url_request_info_impl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "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 "ppapi/c/pp_completion_callback.h" 9 #include "ppapi/c/pp_completion_callback.h"
9 #include "ppapi/c/pp_errors.h" 10 #include "ppapi/c/pp_errors.h"
10 #include "ppapi/c/ppb_url_loader.h" 11 #include "ppapi/c/ppb_url_loader.h"
11 #include "ppapi/c/trusted/ppb_url_loader_trusted.h" 12 #include "ppapi/c/trusted/ppb_url_loader_trusted.h"
12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" 13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h"
13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h" 14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h"
14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" 15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h" 16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h"
16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebKitClient.h" 17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebKitClient.h"
17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h" 18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h"
18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h" 19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h"
20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLError.h"
19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLLoader.h" 21 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLLoader.h"
20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLLoaderOptions.h " 22 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLLoaderOptions.h "
21 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLRequest.h" 23 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLRequest.h"
22 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLResponse.h" 24 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLResponse.h"
23 #include "webkit/appcache/web_application_cache_host_impl.h" 25 #include "webkit/appcache/web_application_cache_host_impl.h"
24 #include "webkit/plugins/ppapi/common.h" 26 #include "webkit/plugins/ppapi/common.h"
25 #include "webkit/plugins/ppapi/plugin_module.h" 27 #include "webkit/plugins/ppapi/plugin_module.h"
26 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" 28 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
27 #include "webkit/plugins/ppapi/ppb_url_request_info_impl.h" 29 #include "webkit/plugins/ppapi/ppb_url_request_info_impl.h"
28 #include "webkit/plugins/ppapi/ppb_url_response_info_impl.h" 30 #include "webkit/plugins/ppapi/ppb_url_response_info_impl.h"
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 } 242 }
241 } 243 }
242 244
243 int32_t PPB_URLLoader_Impl::Open(PPB_URLRequestInfo_Impl* request, 245 int32_t PPB_URLLoader_Impl::Open(PPB_URLRequestInfo_Impl* request,
244 PP_CompletionCallback callback) { 246 PP_CompletionCallback callback) {
245 int32_t rv = ValidateCallback(callback); 247 int32_t rv = ValidateCallback(callback);
246 if (rv != PP_OK) 248 if (rv != PP_OK)
247 return rv; 249 return rv;
248 250
249 if (request->RequiresUniversalAccess() && !has_universal_access_) 251 if (request->RequiresUniversalAccess() && !has_universal_access_)
250 return PP_ERROR_BADARGUMENT; 252 return PP_ERROR_BADARGUMENT;
polina 2011/06/14 07:53:28 have you considered changing this to PP_ERROR_NOAC
bbudge 2011/06/15 20:26:20 This is a tough call. If you look at the implement
polina 2011/06/15 22:46:34 Seemed to match the error better based on the meth
251 253
252 if (loader_.get()) 254 if (loader_.get())
253 return PP_ERROR_INPROGRESS; 255 return PP_ERROR_INPROGRESS;
254 256
255 WebFrame* frame = GetFrame(instance()); 257 WebFrame* frame = GetFrame(instance());
256 if (!frame) 258 if (!frame)
257 return PP_ERROR_FAILED; 259 return PP_ERROR_FAILED;
258 WebURLRequest web_request(request->ToWebURLRequest(frame)); 260 WebURLRequest web_request(request->ToWebURLRequest(frame));
259 261
260 WebURLLoaderOptions options; 262 WebURLLoaderOptions options;
261 if (has_universal_access_) { 263 if (has_universal_access_) {
262 // Universal access allows cross-origin requests and sends credentials. 264 // Universal access allows cross-origin requests and sends credentials.
263 options.crossOriginRequestPolicy = 265 options.crossOriginRequestPolicy =
264 WebURLLoaderOptions::CrossOriginRequestPolicyAllow; 266 WebURLLoaderOptions::CrossOriginRequestPolicyAllow;
265 options.allowCredentials = true; 267 options.allowCredentials = true;
266 } else if (request->allow_cross_origin_requests()) { 268 } else if (request->allow_cross_origin_requests()) {
267 // Otherwise, allow cross-origin requests with access control. 269 // Otherwise, allow cross-origin requests with access control.
268 options.crossOriginRequestPolicy = 270 options.crossOriginRequestPolicy =
269 WebURLLoaderOptions::CrossOriginRequestPolicyUseAccessControl; 271 WebURLLoaderOptions::CrossOriginRequestPolicyUseAccessControl;
270 options.allowCredentials = request->allow_credentials(); 272 options.allowCredentials = request->allow_credentials();
271 } 273 }
272 274
273 is_asynchronous_load_suspended_ = false; 275 is_asynchronous_load_suspended_ = false;
274 loader_.reset(frame->createAssociatedURLLoader(options)); 276 loader_.reset(frame->createAssociatedURLLoader(options));
275 if (!loader_.get()) 277 if (!loader_.get())
276 return PP_ERROR_FAILED; 278 return PP_ERROR_FAILED;
277 279
278 loader_->loadAsynchronously(web_request, this); 280 loader_->loadAsynchronously(web_request, this);
279 // Check for immediate failure; The AssociatedURLLoader will call our
280 // didFail method synchronously for certain kinds of access violations
281 // so we must return an error to the caller.
282 // TODO(bbudge) Modify the underlying AssociatedURLLoader to only call
283 // back asynchronously.
284 if (done_status_ == PP_ERROR_FAILED)
285 return PP_ERROR_NOACCESS;
286 281
287 request_info_ = scoped_refptr<PPB_URLRequestInfo_Impl>(request); 282 request_info_ = scoped_refptr<PPB_URLRequestInfo_Impl>(request);
288 283
289 // Notify completion when we receive a redirect or response headers. 284 // Notify completion when we receive a redirect or response headers.
290 RegisterCallback(callback); 285 RegisterCallback(callback);
291 return PP_OK_COMPLETIONPENDING; 286 return PP_OK_COMPLETIONPENDING;
292 } 287 }
293 288
294 int32_t PPB_URLLoader_Impl::FollowRedirect(PP_CompletionCallback callback) { 289 int32_t PPB_URLLoader_Impl::FollowRedirect(PP_CompletionCallback callback) {
295 int32_t rv = ValidateCallback(callback); 290 int32_t rv = ValidateCallback(callback);
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
468 } 463 }
469 464
470 void PPB_URLLoader_Impl::didFinishLoading(WebURLLoader* loader, 465 void PPB_URLLoader_Impl::didFinishLoading(WebURLLoader* loader,
471 double finish_time) { 466 double finish_time) {
472 done_status_ = PP_OK; 467 done_status_ = PP_OK;
473 RunCallback(done_status_); 468 RunCallback(done_status_);
474 } 469 }
475 470
476 void PPB_URLLoader_Impl::didFail(WebURLLoader* loader, 471 void PPB_URLLoader_Impl::didFail(WebURLLoader* loader,
477 const WebURLError& error) { 472 const WebURLError& error) {
478 // TODO(darin): Provide more detailed error information. 473 // By default report PP_ERROR_NOACCESS. This assumes that errors from WebKit
479 done_status_ = PP_ERROR_FAILED; 474 // are access errors.
475 done_status_ = PP_ERROR_NOACCESS;
476 // For our 'net' error domain, report all non-access errors as
477 // PP_ERROR_FAILED.
478 if (error.domain.equals(WebString::fromUTF8(net::kErrorDomain)) &&
479 error.reason != net::ERR_ACCESS_DENIED &&
480 error.reason != net::ERR_NETWORK_ACCESS_DENIED)
481 done_status_ = PP_ERROR_FAILED;
482
480 RunCallback(done_status_); 483 RunCallback(done_status_);
481 } 484 }
482 485
483 int32_t PPB_URLLoader_Impl::ValidateCallback(PP_CompletionCallback callback) { 486 int32_t PPB_URLLoader_Impl::ValidateCallback(PP_CompletionCallback callback) {
484 // We only support non-blocking calls. 487 // We only support non-blocking calls.
485 if (!callback.func) 488 if (!callback.func)
486 return PP_ERROR_BADARGUMENT; 489 return PP_ERROR_BADARGUMENT;
487 490
488 if (pending_callback_.get() && !pending_callback_->completed()) 491 if (pending_callback_.get() && !pending_callback_->completed())
489 return PP_ERROR_INPROGRESS; 492 return PP_ERROR_INPROGRESS;
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
573 bool PPB_URLLoader_Impl::RecordDownloadProgress() const { 576 bool PPB_URLLoader_Impl::RecordDownloadProgress() const {
574 return request_info_ && request_info_->record_download_progress(); 577 return request_info_ && request_info_->record_download_progress();
575 } 578 }
576 579
577 bool PPB_URLLoader_Impl::RecordUploadProgress() const { 580 bool PPB_URLLoader_Impl::RecordUploadProgress() const {
578 return request_info_ && request_info_->record_upload_progress(); 581 return request_info_ && request_info_->record_upload_progress();
579 } 582 }
580 583
581 } // namespace ppapi 584 } // namespace ppapi
582 } // namespace webkit 585 } // namespace webkit
OLDNEW
« no previous file with comments | « ppapi/tests/test_url_loader.cc ('k') | webkit/plugins/ppapi/ppb_url_request_info_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698