| 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 "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 Loading... |
| 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_NOACCESS; |
| 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 | 281 // TODO(bbudge) Remove this code when AssociatedURLLoader is changed to |
| 280 // didFail method synchronously for certain kinds of access violations | 282 // return errors asynchronously. |
| 281 // so we must return an error to the caller. | 283 if (done_status_ == PP_ERROR_FAILED || |
| 282 // TODO(bbudge) Modify the underlying AssociatedURLLoader to only call | 284 done_status_ == PP_ERROR_NOACCESS) |
| 283 // back asynchronously. | 285 return done_status_; |
| 284 if (done_status_ == PP_ERROR_FAILED) | |
| 285 return PP_ERROR_NOACCESS; | |
| 286 | 286 |
| 287 request_info_ = scoped_refptr<PPB_URLRequestInfo_Impl>(request); | 287 request_info_ = scoped_refptr<PPB_URLRequestInfo_Impl>(request); |
| 288 | 288 |
| 289 // Notify completion when we receive a redirect or response headers. | 289 // Notify completion when we receive a redirect or response headers. |
| 290 RegisterCallback(callback); | 290 RegisterCallback(callback); |
| 291 return PP_OK_COMPLETIONPENDING; | 291 return PP_OK_COMPLETIONPENDING; |
| 292 } | 292 } |
| 293 | 293 |
| 294 int32_t PPB_URLLoader_Impl::FollowRedirect(PP_CompletionCallback callback) { | 294 int32_t PPB_URLLoader_Impl::FollowRedirect(PP_CompletionCallback callback) { |
| 295 int32_t rv = ValidateCallback(callback); | 295 int32_t rv = ValidateCallback(callback); |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 468 } | 468 } |
| 469 | 469 |
| 470 void PPB_URLLoader_Impl::didFinishLoading(WebURLLoader* loader, | 470 void PPB_URLLoader_Impl::didFinishLoading(WebURLLoader* loader, |
| 471 double finish_time) { | 471 double finish_time) { |
| 472 done_status_ = PP_OK; | 472 done_status_ = PP_OK; |
| 473 RunCallback(done_status_); | 473 RunCallback(done_status_); |
| 474 } | 474 } |
| 475 | 475 |
| 476 void PPB_URLLoader_Impl::didFail(WebURLLoader* loader, | 476 void PPB_URLLoader_Impl::didFail(WebURLLoader* loader, |
| 477 const WebURLError& error) { | 477 const WebURLError& error) { |
| 478 // TODO(darin): Provide more detailed error information. | 478 if (error.domain.equals(WebString::fromUTF8(net::kErrorDomain))) { |
| 479 done_status_ = PP_ERROR_FAILED; | 479 // TODO(bbudge): Extend pp_errors.h to cover interesting network errors |
| 480 // from the net error domain. |
| 481 switch (error.reason) { |
| 482 case net::ERR_ACCESS_DENIED: |
| 483 case net::ERR_NETWORK_ACCESS_DENIED: |
| 484 done_status_ = PP_ERROR_NOACCESS; |
| 485 break; |
| 486 default: |
| 487 done_status_ = PP_ERROR_FAILED; |
| 488 break; |
| 489 } |
| 490 } else { |
| 491 // It's a WebKit error. |
| 492 done_status_ = PP_ERROR_NOACCESS; |
| 493 } |
| 494 |
| 480 RunCallback(done_status_); | 495 RunCallback(done_status_); |
| 481 } | 496 } |
| 482 | 497 |
| 483 int32_t PPB_URLLoader_Impl::ValidateCallback(PP_CompletionCallback callback) { | 498 int32_t PPB_URLLoader_Impl::ValidateCallback(PP_CompletionCallback callback) { |
| 484 // We only support non-blocking calls. | 499 // We only support non-blocking calls. |
| 485 if (!callback.func) | 500 if (!callback.func) |
| 486 return PP_ERROR_BADARGUMENT; | 501 return PP_ERROR_BADARGUMENT; |
| 487 | 502 |
| 488 if (pending_callback_.get() && !pending_callback_->completed()) | 503 if (pending_callback_.get() && !pending_callback_->completed()) |
| 489 return PP_ERROR_INPROGRESS; | 504 return PP_ERROR_INPROGRESS; |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 573 bool PPB_URLLoader_Impl::RecordDownloadProgress() const { | 588 bool PPB_URLLoader_Impl::RecordDownloadProgress() const { |
| 574 return request_info_ && request_info_->record_download_progress(); | 589 return request_info_ && request_info_->record_download_progress(); |
| 575 } | 590 } |
| 576 | 591 |
| 577 bool PPB_URLLoader_Impl::RecordUploadProgress() const { | 592 bool PPB_URLLoader_Impl::RecordUploadProgress() const { |
| 578 return request_info_ && request_info_->record_upload_progress(); | 593 return request_info_ && request_info_->record_upload_progress(); |
| 579 } | 594 } |
| 580 | 595 |
| 581 } // namespace ppapi | 596 } // namespace ppapi |
| 582 } // namespace webkit | 597 } // namespace webkit |
| OLD | NEW |