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

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

Issue 10913257: Convert url request info to new proxy API. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 3 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/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
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
bbudge 2012/09/14 17:48:52 Why don't we need this anymore?
brettw 2012/09/14 22:50:47 I moved it to the internal version below (so it on
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(const ::ppapi::URLRequestInfoData& in_data,
bbudge 2012/09/14 17:48:52 It would be clearer to me if 'in_data' was called
113 scoped_refptr<TrackedCallback> callback) {
114 // Main document loads are already open, so don't allow people to open them
115 // again.
116 if (main_document_loader_)
117 return PP_ERROR_INPROGRESS;
115 118
116 int32_t rv = ValidateCallback(callback); 119 int32_t rv = ValidateCallback(callback);
117 if (rv != PP_OK) 120 if (rv != PP_OK)
118 return rv; 121 return rv;
119 122
120 if (request->RequiresUniversalAccess() && !has_universal_access_) { 123 // Create a copy of the request data since CreateWebURLRequest will populate
124 // the file refs.
125 ::ppapi::URLRequestInfoData request_data = in_data;
126
127 if (URLRequestRequiresUniversalAccess(request_data) &&
128 !has_universal_access_) {
121 Log(PP_LOGLEVEL_ERROR, "PPB_URLLoader.Open: The URL you're requesting is " 129 Log(PP_LOGLEVEL_ERROR, "PPB_URLLoader.Open: The URL you're requesting is "
122 " on a different security origin than your plugin. To request " 130 " on a different security origin than your plugin. To request "
123 " cross-origin resources, see " 131 " cross-origin resources, see "
124 " PP_URLREQUESTPROPERTY_ALLOWCROSSORIGINREQUESTS."); 132 " PP_URLREQUESTPROPERTY_ALLOWCROSSORIGINREQUESTS.");
125 return PP_ERROR_NOACCESS; 133 return PP_ERROR_NOACCESS;
126 } 134 }
127 135
128 if (loader_.get()) 136 if (loader_.get())
129 return PP_ERROR_INPROGRESS; 137 return PP_ERROR_INPROGRESS;
130 138
131 WebFrame* frame = GetFrameForResource(this); 139 WebFrame* frame = GetFrameForResource(this);
132 if (!frame) 140 if (!frame)
133 return PP_ERROR_FAILED; 141 return PP_ERROR_FAILED;
134 WebURLRequest web_request; 142 WebURLRequest web_request;
135 if (!request->ToWebURLRequest(frame, &web_request)) 143 if (!CreateWebURLRequest(&request_data, frame, &web_request))
136 return PP_ERROR_FAILED; 144 return PP_ERROR_FAILED;
137 145
138 // Save a copy of the request info so the plugin can continue to use and 146 // 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 147 // 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. 148 // this after ToWebURLRequest since that fills out the file refs.
bbudge 2012/09/14 17:48:52 s/ToWebURLRequest/CreateWebURLRequest
141 request_data_ = request->GetData(); 149 request_data_ = request_data;
142 150
143 WebURLLoaderOptions options; 151 WebURLLoaderOptions options;
144 if (has_universal_access_) { 152 if (has_universal_access_) {
145 options.allowCredentials = true; 153 options.allowCredentials = true;
146 options.crossOriginRequestPolicy = 154 options.crossOriginRequestPolicy =
147 WebURLLoaderOptions::CrossOriginRequestPolicyAllow; 155 WebURLLoaderOptions::CrossOriginRequestPolicyAllow;
148 } else { 156 } else {
149 // All other HTTP requests are untrusted. 157 // All other HTTP requests are untrusted.
150 options.untrustedHTTP = true; 158 options.untrustedHTTP = true;
151 if (request_data_.allow_cross_origin_requests) { 159 if (request_data_.allow_cross_origin_requests) {
(...skipping 19 matching lines...) Expand all
171 RegisterCallback(callback); 179 RegisterCallback(callback);
172 return PP_OK_COMPLETIONPENDING; 180 return PP_OK_COMPLETIONPENDING;
173 } 181 }
174 182
175 int32_t PPB_URLLoader_Impl::FollowRedirect( 183 int32_t PPB_URLLoader_Impl::FollowRedirect(
176 scoped_refptr<TrackedCallback> callback) { 184 scoped_refptr<TrackedCallback> callback) {
177 int32_t rv = ValidateCallback(callback); 185 int32_t rv = ValidateCallback(callback);
178 if (rv != PP_OK) 186 if (rv != PP_OK)
179 return rv; 187 return rv;
180 188
181 WebURL redirect_url = GURL(response_info_->redirect_url());
182
183 SetDefersLoading(false); // Allow the redirect to continue. 189 SetDefersLoading(false); // Allow the redirect to continue.
184 RegisterCallback(callback); 190 RegisterCallback(callback);
185 return PP_OK_COMPLETIONPENDING; 191 return PP_OK_COMPLETIONPENDING;
186 } 192 }
187 193
188 PP_Bool PPB_URLLoader_Impl::GetUploadProgress(int64_t* bytes_sent, 194 PP_Bool PPB_URLLoader_Impl::GetUploadProgress(int64_t* bytes_sent,
189 int64_t* total_bytes_to_be_sent) { 195 int64_t* total_bytes_to_be_sent) {
190 if (!RecordUploadProgress()) { 196 if (!RecordUploadProgress()) {
191 *bytes_sent = 0; 197 *bytes_sent = 0;
192 *total_bytes_to_be_sent = 0; 198 *total_bytes_to_be_sent = 0;
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after
482 bool PPB_URLLoader_Impl::RecordDownloadProgress() const { 488 bool PPB_URLLoader_Impl::RecordDownloadProgress() const {
483 return request_data_.record_download_progress; 489 return request_data_.record_download_progress;
484 } 490 }
485 491
486 bool PPB_URLLoader_Impl::RecordUploadProgress() const { 492 bool PPB_URLLoader_Impl::RecordUploadProgress() const {
487 return request_data_.record_upload_progress; 493 return request_data_.record_upload_progress;
488 } 494 }
489 495
490 } // namespace ppapi 496 } // namespace ppapi
491 } // namespace webkit 497 } // namespace webkit
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698