| OLD | NEW |
| 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/thunk/enter.h" | 13 #include "ppapi/thunk/enter.h" |
| 14 #include "ppapi/thunk/ppb_url_request_info_api.h" |
| 14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" | 15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" |
| 15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h" | 16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h" |
| 16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
| 17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h" | 18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h" |
| 18 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebKitPlatfo
rmSupport.h" | 19 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebKitPlatfo
rmSupport.h" |
| 19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h" | 20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h" |
| 20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h" | 21 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h" |
| 21 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLError.
h" | 22 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLError.
h" |
| 22 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLLoader
.h" | 23 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLLoader
.h" |
| 23 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLLoaderOptions.h
" | 24 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLLoaderOptions.h
" |
| 24 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLReques
t.h" | 25 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLReques
t.h" |
| 25 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLRespon
se.h" | 26 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLRespon
se.h" |
| 26 #include "webkit/appcache/web_application_cache_host_impl.h" | 27 #include "webkit/appcache/web_application_cache_host_impl.h" |
| 27 #include "webkit/plugins/ppapi/common.h" | 28 #include "webkit/plugins/ppapi/common.h" |
| 28 #include "webkit/plugins/ppapi/plugin_module.h" | 29 #include "webkit/plugins/ppapi/plugin_module.h" |
| 29 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" | 30 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" |
| 30 #include "webkit/plugins/ppapi/ppb_url_request_info_impl.h" | 31 #include "webkit/plugins/ppapi/resource_helper.h" |
| 32 #include "webkit/plugins/ppapi/url_request_info_util.h" |
| 31 #include "webkit/plugins/ppapi/ppb_url_response_info_impl.h" | 33 #include "webkit/plugins/ppapi/ppb_url_response_info_impl.h" |
| 32 #include "webkit/plugins/ppapi/resource_helper.h" | |
| 33 | 34 |
| 34 using appcache::WebApplicationCacheHostImpl; | 35 using appcache::WebApplicationCacheHostImpl; |
| 35 using ppapi::Resource; | 36 using ppapi::Resource; |
| 36 using ppapi::thunk::EnterResourceNoLock; | 37 using ppapi::thunk::EnterResourceNoLock; |
| 37 using ppapi::thunk::PPB_URLLoader_API; | 38 using ppapi::thunk::PPB_URLLoader_API; |
| 38 using ppapi::thunk::PPB_URLRequestInfo_API; | 39 using ppapi::thunk::PPB_URLRequestInfo_API; |
| 39 using ppapi::TrackedCallback; | 40 using ppapi::TrackedCallback; |
| 40 using WebKit::WebFrame; | 41 using WebKit::WebFrame; |
| 41 using WebKit::WebString; | 42 using WebKit::WebString; |
| 42 using WebKit::WebURL; | 43 using WebKit::WebURL; |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 return this; | 91 return this; |
| 91 } | 92 } |
| 92 | 93 |
| 93 void PPB_URLLoader_Impl::InstanceWasDeleted() { | 94 void PPB_URLLoader_Impl::InstanceWasDeleted() { |
| 94 Resource::InstanceWasDeleted(); | 95 Resource::InstanceWasDeleted(); |
| 95 loader_.reset(); | 96 loader_.reset(); |
| 96 } | 97 } |
| 97 | 98 |
| 98 int32_t PPB_URLLoader_Impl::Open(PP_Resource request_id, | 99 int32_t PPB_URLLoader_Impl::Open(PP_Resource request_id, |
| 99 scoped_refptr<TrackedCallback> callback) { | 100 scoped_refptr<TrackedCallback> callback) { |
| 100 // Main document loads are already open, so don't allow people to open them | |
| 101 // again. | |
| 102 if (main_document_loader_) | |
| 103 return PP_ERROR_INPROGRESS; | |
| 104 | |
| 105 EnterResourceNoLock<PPB_URLRequestInfo_API> enter_request(request_id, true); | 101 EnterResourceNoLock<PPB_URLRequestInfo_API> enter_request(request_id, true); |
| 106 if (enter_request.failed()) { | 102 if (enter_request.failed()) { |
| 107 Log(PP_LOGLEVEL_ERROR, | 103 Log(PP_LOGLEVEL_ERROR, |
| 108 "PPB_URLLoader.Open: invalid request resource ID. (Hint to C++ wrapper" | 104 "PPB_URLLoader.Open: invalid request resource ID. (Hint to C++ wrapper" |
| 109 " users: use the ResourceRequest constructor that takes an instance or" | 105 " users: use the ResourceRequest constructor that takes an instance or" |
| 110 " else the request will be null.)"); | 106 " else the request will be null.)"); |
| 111 return PP_ERROR_BADARGUMENT; | 107 return PP_ERROR_BADARGUMENT; |
| 112 } | 108 } |
| 113 PPB_URLRequestInfo_Impl* request = static_cast<PPB_URLRequestInfo_Impl*>( | 109 return Open(enter_request.object()->GetData(), callback); |
| 114 enter_request.object()); | 110 } |
| 111 |
| 112 int32_t PPB_URLLoader_Impl::Open( |
| 113 const ::ppapi::URLRequestInfoData& request_data, |
| 114 scoped_refptr<TrackedCallback> callback) { |
| 115 // Main document loads are already open, so don't allow people to open them |
| 116 // again. |
| 117 if (main_document_loader_) |
| 118 return PP_ERROR_INPROGRESS; |
| 115 | 119 |
| 116 int32_t rv = ValidateCallback(callback); | 120 int32_t rv = ValidateCallback(callback); |
| 117 if (rv != PP_OK) | 121 if (rv != PP_OK) |
| 118 return rv; | 122 return rv; |
| 119 | 123 |
| 120 if (request->RequiresUniversalAccess() && !has_universal_access_) { | 124 // Create a copy of the request data since CreateWebURLRequest will populate |
| 125 // the file refs. |
| 126 ::ppapi::URLRequestInfoData filled_in_request_data = request_data; |
| 127 |
| 128 if (URLRequestRequiresUniversalAccess(filled_in_request_data) && |
| 129 !has_universal_access_) { |
| 121 Log(PP_LOGLEVEL_ERROR, "PPB_URLLoader.Open: The URL you're requesting is " | 130 Log(PP_LOGLEVEL_ERROR, "PPB_URLLoader.Open: The URL you're requesting is " |
| 122 " on a different security origin than your plugin. To request " | 131 " on a different security origin than your plugin. To request " |
| 123 " cross-origin resources, see " | 132 " cross-origin resources, see " |
| 124 " PP_URLREQUESTPROPERTY_ALLOWCROSSORIGINREQUESTS."); | 133 " PP_URLREQUESTPROPERTY_ALLOWCROSSORIGINREQUESTS."); |
| 125 return PP_ERROR_NOACCESS; | 134 return PP_ERROR_NOACCESS; |
| 126 } | 135 } |
| 127 | 136 |
| 128 if (loader_.get()) | 137 if (loader_.get()) |
| 129 return PP_ERROR_INPROGRESS; | 138 return PP_ERROR_INPROGRESS; |
| 130 | 139 |
| 131 WebFrame* frame = GetFrameForResource(this); | 140 WebFrame* frame = GetFrameForResource(this); |
| 132 if (!frame) | 141 if (!frame) |
| 133 return PP_ERROR_FAILED; | 142 return PP_ERROR_FAILED; |
| 134 WebURLRequest web_request; | 143 WebURLRequest web_request; |
| 135 if (!request->ToWebURLRequest(frame, &web_request)) | 144 if (!CreateWebURLRequest(&filled_in_request_data, frame, &web_request)) |
| 136 return PP_ERROR_FAILED; | 145 return PP_ERROR_FAILED; |
| 137 | 146 |
| 138 // Save a copy of the request info so the plugin can continue to use and | 147 // Save a copy of the request info so the plugin can continue to use and |
| 139 // change it while we're doing the request without affecting us. We must do | 148 // change it while we're doing the request without affecting us. We must do |
| 140 // this after ToWebURLRequest since that fills out the file refs. | 149 // this after CreateWebURLRequest since that fills out the file refs. |
| 141 request_data_ = request->GetData(); | 150 request_data_ = filled_in_request_data; |
| 142 | 151 |
| 143 WebURLLoaderOptions options; | 152 WebURLLoaderOptions options; |
| 144 if (has_universal_access_) { | 153 if (has_universal_access_) { |
| 145 options.allowCredentials = true; | 154 options.allowCredentials = true; |
| 146 options.crossOriginRequestPolicy = | 155 options.crossOriginRequestPolicy = |
| 147 WebURLLoaderOptions::CrossOriginRequestPolicyAllow; | 156 WebURLLoaderOptions::CrossOriginRequestPolicyAllow; |
| 148 } else { | 157 } else { |
| 149 // All other HTTP requests are untrusted. | 158 // All other HTTP requests are untrusted. |
| 150 options.untrustedHTTP = true; | 159 options.untrustedHTTP = true; |
| 151 if (request_data_.allow_cross_origin_requests) { | 160 if (request_data_.allow_cross_origin_requests) { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 171 RegisterCallback(callback); | 180 RegisterCallback(callback); |
| 172 return PP_OK_COMPLETIONPENDING; | 181 return PP_OK_COMPLETIONPENDING; |
| 173 } | 182 } |
| 174 | 183 |
| 175 int32_t PPB_URLLoader_Impl::FollowRedirect( | 184 int32_t PPB_URLLoader_Impl::FollowRedirect( |
| 176 scoped_refptr<TrackedCallback> callback) { | 185 scoped_refptr<TrackedCallback> callback) { |
| 177 int32_t rv = ValidateCallback(callback); | 186 int32_t rv = ValidateCallback(callback); |
| 178 if (rv != PP_OK) | 187 if (rv != PP_OK) |
| 179 return rv; | 188 return rv; |
| 180 | 189 |
| 181 WebURL redirect_url = GURL(response_info_->redirect_url()); | |
| 182 | |
| 183 SetDefersLoading(false); // Allow the redirect to continue. | 190 SetDefersLoading(false); // Allow the redirect to continue. |
| 184 RegisterCallback(callback); | 191 RegisterCallback(callback); |
| 185 return PP_OK_COMPLETIONPENDING; | 192 return PP_OK_COMPLETIONPENDING; |
| 186 } | 193 } |
| 187 | 194 |
| 188 PP_Bool PPB_URLLoader_Impl::GetUploadProgress(int64_t* bytes_sent, | 195 PP_Bool PPB_URLLoader_Impl::GetUploadProgress(int64_t* bytes_sent, |
| 189 int64_t* total_bytes_to_be_sent) { | 196 int64_t* total_bytes_to_be_sent) { |
| 190 if (!RecordUploadProgress()) { | 197 if (!RecordUploadProgress()) { |
| 191 *bytes_sent = 0; | 198 *bytes_sent = 0; |
| 192 *total_bytes_to_be_sent = 0; | 199 *total_bytes_to_be_sent = 0; |
| (...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 482 bool PPB_URLLoader_Impl::RecordDownloadProgress() const { | 489 bool PPB_URLLoader_Impl::RecordDownloadProgress() const { |
| 483 return request_data_.record_download_progress; | 490 return request_data_.record_download_progress; |
| 484 } | 491 } |
| 485 | 492 |
| 486 bool PPB_URLLoader_Impl::RecordUploadProgress() const { | 493 bool PPB_URLLoader_Impl::RecordUploadProgress() const { |
| 487 return request_data_.record_upload_progress; | 494 return request_data_.record_upload_progress; |
| 488 } | 495 } |
| 489 | 496 |
| 490 } // namespace ppapi | 497 } // namespace ppapi |
| 491 } // namespace webkit | 498 } // namespace webkit |
| OLD | NEW |