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

Side by Side Diff: content/renderer/pepper/pepper_url_loader_host.cc

Issue 2399463007: AssociatedURLLoader shouldn't derive from WebURLLoader (Closed)
Patch Set: Rebase Created 4 years, 1 month 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
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 "content/renderer/pepper/pepper_url_loader_host.h" 5 #include "content/renderer/pepper/pepper_url_loader_host.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "content/renderer/pepper/pepper_plugin_instance_impl.h" 9 #include "content/renderer/pepper/pepper_plugin_instance_impl.h"
10 #include "content/renderer/pepper/renderer_ppapi_host_impl.h" 10 #include "content/renderer/pepper/renderer_ppapi_host_impl.h"
11 #include "content/renderer/pepper/url_request_info_util.h" 11 #include "content/renderer/pepper/url_request_info_util.h"
12 #include "content/renderer/pepper/url_response_info_util.h" 12 #include "content/renderer/pepper/url_response_info_util.h"
13 #include "net/base/net_errors.h" 13 #include "net/base/net_errors.h"
14 #include "ppapi/c/pp_errors.h" 14 #include "ppapi/c/pp_errors.h"
15 #include "ppapi/host/dispatch_host_message.h" 15 #include "ppapi/host/dispatch_host_message.h"
16 #include "ppapi/host/host_message_context.h" 16 #include "ppapi/host/host_message_context.h"
17 #include "ppapi/host/ppapi_host.h" 17 #include "ppapi/host/ppapi_host.h"
18 #include "ppapi/proxy/ppapi_messages.h" 18 #include "ppapi/proxy/ppapi_messages.h"
19 #include "ppapi/shared_impl/ppapi_globals.h" 19 #include "ppapi/shared_impl/ppapi_globals.h"
20 #include "third_party/WebKit/public/platform/WebSecurityOrigin.h" 20 #include "third_party/WebKit/public/platform/WebSecurityOrigin.h"
21 #include "third_party/WebKit/public/platform/WebURLError.h" 21 #include "third_party/WebKit/public/platform/WebURLError.h"
22 #include "third_party/WebKit/public/platform/WebURLLoader.h"
23 #include "third_party/WebKit/public/platform/WebURLRequest.h" 22 #include "third_party/WebKit/public/platform/WebURLRequest.h"
24 #include "third_party/WebKit/public/platform/WebURLResponse.h" 23 #include "third_party/WebKit/public/platform/WebURLResponse.h"
24 #include "third_party/WebKit/public/web/WebAssociatedURLLoader.h"
25 #include "third_party/WebKit/public/web/WebAssociatedURLLoaderOptions.h"
25 #include "third_party/WebKit/public/web/WebDocument.h" 26 #include "third_party/WebKit/public/web/WebDocument.h"
26 #include "third_party/WebKit/public/web/WebElement.h" 27 #include "third_party/WebKit/public/web/WebElement.h"
27 #include "third_party/WebKit/public/web/WebKit.h" 28 #include "third_party/WebKit/public/web/WebKit.h"
28 #include "third_party/WebKit/public/web/WebLocalFrame.h" 29 #include "third_party/WebKit/public/web/WebLocalFrame.h"
29 #include "third_party/WebKit/public/web/WebPluginContainer.h" 30 #include "third_party/WebKit/public/web/WebPluginContainer.h"
30 #include "third_party/WebKit/public/web/WebURLLoaderOptions.h"
31 31
32 using blink::WebAssociatedURLLoader;
33 using blink::WebAssociatedURLLoaderOptions;
32 using blink::WebLocalFrame; 34 using blink::WebLocalFrame;
33 using blink::WebString; 35 using blink::WebString;
34 using blink::WebURL; 36 using blink::WebURL;
35 using blink::WebURLError; 37 using blink::WebURLError;
36 using blink::WebURLLoader;
37 using blink::WebURLLoaderOptions;
38 using blink::WebURLRequest; 38 using blink::WebURLRequest;
39 using blink::WebURLResponse; 39 using blink::WebURLResponse;
40 40
41 #ifdef _MSC_VER 41 #ifdef _MSC_VER
42 // Do not warn about use of std::copy with raw pointers. 42 // Do not warn about use of std::copy with raw pointers.
43 #pragma warning(disable : 4996) 43 #pragma warning(disable : 4996)
44 #endif 44 #endif
45 45
46 namespace content { 46 namespace content {
47 47
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 DCHECK(instance_object->document_loader() == this); 93 DCHECK(instance_object->document_loader() == this);
94 instance_object->set_document_loader(NULL); 94 instance_object->set_document_loader(NULL);
95 } 95 }
96 } 96 }
97 97
98 // There is a path whereby the destructor for the loader_ member can 98 // There is a path whereby the destructor for the loader_ member can
99 // invoke InstanceWasDeleted() upon this URLLoaderResource, thereby 99 // invoke InstanceWasDeleted() upon this URLLoaderResource, thereby
100 // re-entering the scoped_ptr destructor with the same scoped_ptr object 100 // re-entering the scoped_ptr destructor with the same scoped_ptr object
101 // via loader_.reset(). Be sure that loader_ is first NULL then destroy 101 // via loader_.reset(). Be sure that loader_ is first NULL then destroy
102 // the scoped_ptr. See http://crbug.com/159429. 102 // the scoped_ptr. See http://crbug.com/159429.
103 std::unique_ptr<blink::WebURLLoader> for_destruction_only(loader_.release()); 103 std::unique_ptr<WebAssociatedURLLoader> for_destruction_only(
104 loader_.release());
104 } 105 }
105 106
106 int32_t PepperURLLoaderHost::OnResourceMessageReceived( 107 int32_t PepperURLLoaderHost::OnResourceMessageReceived(
107 const IPC::Message& msg, 108 const IPC::Message& msg,
108 ppapi::host::HostMessageContext* context) { 109 ppapi::host::HostMessageContext* context) {
109 PPAPI_BEGIN_MESSAGE_MAP(PepperURLLoaderHost, msg) 110 PPAPI_BEGIN_MESSAGE_MAP(PepperURLLoaderHost, msg)
110 PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_URLLoader_Open, 111 PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_URLLoader_Open,
111 OnHostMsgOpen) 112 OnHostMsgOpen)
112 PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_URLLoader_SetDeferLoading, 113 PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_URLLoader_SetDeferLoading,
113 OnHostMsgSetDeferLoading) 114 OnHostMsgSetDeferLoading)
114 PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(PpapiHostMsg_URLLoader_Close, 115 PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(PpapiHostMsg_URLLoader_Close,
115 OnHostMsgClose); 116 OnHostMsgClose);
116 PPAPI_DISPATCH_HOST_RESOURCE_CALL_0( 117 PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(
117 PpapiHostMsg_URLLoader_GrantUniversalAccess, 118 PpapiHostMsg_URLLoader_GrantUniversalAccess,
118 OnHostMsgGrantUniversalAccess) 119 OnHostMsgGrantUniversalAccess)
119 PPAPI_END_MESSAGE_MAP() 120 PPAPI_END_MESSAGE_MAP()
120 return PP_ERROR_FAILED; 121 return PP_ERROR_FAILED;
121 } 122 }
122 123
123 bool PepperURLLoaderHost::willFollowRedirect( 124 bool PepperURLLoaderHost::willFollowRedirect(
124 WebURLLoader* loader, 125 const WebURLRequest& new_request,
125 WebURLRequest& new_request,
126 const WebURLResponse& redirect_response) { 126 const WebURLResponse& redirect_response) {
127 DCHECK(out_of_order_replies_.empty()); 127 DCHECK(out_of_order_replies_.empty());
128 if (!request_data_.follow_redirects) { 128 if (!request_data_.follow_redirects) {
129 SaveResponse(redirect_response); 129 SaveResponse(redirect_response);
130 SetDefersLoading(true); 130 SetDefersLoading(true);
131 // Defer the request and wait the plugin to audit the redirect. We 131 // Defer the request and wait the plugin to audit the redirect. We
132 // shouldn't return false here as decision has been delegated to the 132 // shouldn't return false here as decision has been delegated to the
133 // plugin. 133 // plugin.
134 } 134 }
135 return true; 135 return true;
136 } 136 }
137 137
138 void PepperURLLoaderHost::didSendData( 138 void PepperURLLoaderHost::didSendData(
139 WebURLLoader* loader,
140 unsigned long long bytes_sent, 139 unsigned long long bytes_sent,
141 unsigned long long total_bytes_to_be_sent) { 140 unsigned long long total_bytes_to_be_sent) {
142 // TODO(darin): Bounds check input? 141 // TODO(darin): Bounds check input?
143 bytes_sent_ = static_cast<int64_t>(bytes_sent); 142 bytes_sent_ = static_cast<int64_t>(bytes_sent);
144 total_bytes_to_be_sent_ = static_cast<int64_t>(total_bytes_to_be_sent); 143 total_bytes_to_be_sent_ = static_cast<int64_t>(total_bytes_to_be_sent);
145 UpdateProgress(); 144 UpdateProgress();
146 } 145 }
147 146
148 void PepperURLLoaderHost::didReceiveResponse(WebURLLoader* loader, 147 void PepperURLLoaderHost::didReceiveResponse(const WebURLResponse& response) {
149 const WebURLResponse& response) {
150 // Sets -1 if the content length is unknown. Send before issuing callback. 148 // Sets -1 if the content length is unknown. Send before issuing callback.
151 total_bytes_to_be_received_ = response.expectedContentLength(); 149 total_bytes_to_be_received_ = response.expectedContentLength();
152 UpdateProgress(); 150 UpdateProgress();
153 151
154 SaveResponse(response); 152 SaveResponse(response);
155 } 153 }
156 154
157 void PepperURLLoaderHost::didDownloadData(WebURLLoader* loader, 155 void PepperURLLoaderHost::didDownloadData(int data_length) {
158 int data_length,
159 int encoded_data_length) {
160 bytes_received_ += data_length; 156 bytes_received_ += data_length;
161 UpdateProgress(); 157 UpdateProgress();
162 } 158 }
163 159
164 void PepperURLLoaderHost::didReceiveData(WebURLLoader* loader, 160 void PepperURLLoaderHost::didReceiveData(const char* data, int data_length) {
165 const char* data,
166 int data_length,
167 int encoded_data_length,
168 int encoded_body_length) {
169 // Note that |loader| will be NULL for document loads. 161 // Note that |loader| will be NULL for document loads.
170 bytes_received_ += data_length; 162 bytes_received_ += data_length;
171 UpdateProgress(); 163 UpdateProgress();
172 164
173 PpapiPluginMsg_URLLoader_SendData* message = 165 PpapiPluginMsg_URLLoader_SendData* message =
174 new PpapiPluginMsg_URLLoader_SendData; 166 new PpapiPluginMsg_URLLoader_SendData;
175 message->WriteData(data, data_length); 167 message->WriteData(data, data_length);
176 SendUpdateToPlugin(message); 168 SendUpdateToPlugin(message);
177 } 169 }
178 170
179 void PepperURLLoaderHost::didFinishLoading(WebURLLoader* loader, 171 void PepperURLLoaderHost::didFinishLoading(double finish_time) {
180 double finish_time,
181 int64_t total_encoded_data_length) {
182 // Note that |loader| will be NULL for document loads. 172 // Note that |loader| will be NULL for document loads.
183 SendUpdateToPlugin(new PpapiPluginMsg_URLLoader_FinishedLoading(PP_OK)); 173 SendUpdateToPlugin(new PpapiPluginMsg_URLLoader_FinishedLoading(PP_OK));
184 } 174 }
185 175
186 void PepperURLLoaderHost::didFail(WebURLLoader* loader, 176 void PepperURLLoaderHost::didFail(const WebURLError& error) {
187 const WebURLError& error) {
188 // Note that |loader| will be NULL for document loads. 177 // Note that |loader| will be NULL for document loads.
189 int32_t pp_error = PP_ERROR_FAILED; 178 int32_t pp_error = PP_ERROR_FAILED;
190 if (error.domain.equals(WebString::fromUTF8(net::kErrorDomain))) { 179 if (error.domain.equals(WebString::fromUTF8(net::kErrorDomain))) {
191 // TODO(bbudge): Extend pp_errors.h to cover interesting network errors 180 // TODO(bbudge): Extend pp_errors.h to cover interesting network errors
192 // from the net error domain. 181 // from the net error domain.
193 switch (error.reason) { 182 switch (error.reason) {
194 case net::ERR_ACCESS_DENIED: 183 case net::ERR_ACCESS_DENIED:
195 case net::ERR_NETWORK_ACCESS_DENIED: 184 case net::ERR_NETWORK_ACCESS_DENIED:
196 pp_error = PP_ERROR_NOACCESS; 185 pp_error = PP_ERROR_NOACCESS;
197 break; 186 break;
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 pp_instance(), &filled_in_request_data, frame, &web_request)) { 252 pp_instance(), &filled_in_request_data, frame, &web_request)) {
264 return PP_ERROR_FAILED; 253 return PP_ERROR_FAILED;
265 } 254 }
266 255
267 web_request.setRequestContext(WebURLRequest::RequestContextPlugin); 256 web_request.setRequestContext(WebURLRequest::RequestContextPlugin);
268 web_request.setRequestorProcessID(renderer_ppapi_host_->GetPluginPID()); 257 web_request.setRequestorProcessID(renderer_ppapi_host_->GetPluginPID());
269 // The requests from the plugins with private permission which can bypass same 258 // The requests from the plugins with private permission which can bypass same
270 // origin must skip the ServiceWorker. 259 // origin must skip the ServiceWorker.
271 web_request.setSkipServiceWorker( 260 web_request.setSkipServiceWorker(
272 host()->permissions().HasPermission(ppapi::PERMISSION_PRIVATE) 261 host()->permissions().HasPermission(ppapi::PERMISSION_PRIVATE)
273 ? blink::WebURLRequest::SkipServiceWorker::All 262 ? WebURLRequest::SkipServiceWorker::All
274 : blink::WebURLRequest::SkipServiceWorker::None); 263 : WebURLRequest::SkipServiceWorker::None);
275 264
276 WebURLLoaderOptions options; 265 WebAssociatedURLLoaderOptions options;
277 if (has_universal_access_) { 266 if (has_universal_access_) {
278 options.allowCredentials = true; 267 options.allowCredentials = true;
279 options.crossOriginRequestPolicy = 268 options.crossOriginRequestPolicy =
280 WebURLLoaderOptions::CrossOriginRequestPolicyAllow; 269 WebAssociatedURLLoaderOptions::CrossOriginRequestPolicyAllow;
281 } else { 270 } else {
282 // All other HTTP requests are untrusted. 271 // All other HTTP requests are untrusted.
283 options.untrustedHTTP = true; 272 options.untrustedHTTP = true;
284 if (filled_in_request_data.allow_cross_origin_requests) { 273 if (filled_in_request_data.allow_cross_origin_requests) {
285 // Allow cross-origin requests with access control. The request specifies 274 // Allow cross-origin requests with access control. The request specifies
286 // if credentials are to be sent. 275 // if credentials are to be sent.
287 options.allowCredentials = filled_in_request_data.allow_credentials; 276 options.allowCredentials = filled_in_request_data.allow_credentials;
288 options.crossOriginRequestPolicy = 277 options.crossOriginRequestPolicy = WebAssociatedURLLoaderOptions::
289 WebURLLoaderOptions::CrossOriginRequestPolicyUseAccessControl; 278 CrossOriginRequestPolicyUseAccessControl;
290 } else { 279 } else {
291 // Same-origin requests can always send credentials. 280 // Same-origin requests can always send credentials.
292 options.allowCredentials = true; 281 options.allowCredentials = true;
293 } 282 }
294 } 283 }
295 284
296 loader_.reset(frame->createAssociatedURLLoader(options)); 285 loader_.reset(frame->createAssociatedURLLoader(options));
297 if (!loader_.get()) 286 if (!loader_.get())
298 return PP_ERROR_FAILED; 287 return PP_ERROR_FAILED;
299 288
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
373 362
374 void PepperURLLoaderHost::Close() { 363 void PepperURLLoaderHost::Close() {
375 if (loader_.get()) { 364 if (loader_.get()) {
376 loader_->cancel(); 365 loader_->cancel();
377 } else if (main_document_loader_) { 366 } else if (main_document_loader_) {
378 // TODO(raymes): Calling WebLocalFrame::stopLoading here is incorrect as it 367 // TODO(raymes): Calling WebLocalFrame::stopLoading here is incorrect as it
379 // cancels all URL loaders associated with the frame. If a client has opened 368 // cancels all URL loaders associated with the frame. If a client has opened
380 // other URLLoaders and then closes the main one, the others should still 369 // other URLLoaders and then closes the main one, the others should still
381 // remain connected. Work out how to only cancel the main request: 370 // remain connected. Work out how to only cancel the main request:
382 // crbug.com/384197. 371 // crbug.com/384197.
383 blink::WebLocalFrame* frame = GetFrame(); 372 WebLocalFrame* frame = GetFrame();
384 if (frame) 373 if (frame)
385 frame->stopLoading(); 374 frame->stopLoading();
386 } 375 }
387 } 376 }
388 377
389 blink::WebLocalFrame* PepperURLLoaderHost::GetFrame() { 378 WebLocalFrame* PepperURLLoaderHost::GetFrame() {
390 PepperPluginInstanceImpl* instance_object = 379 PepperPluginInstanceImpl* instance_object =
391 static_cast<PepperPluginInstanceImpl*>( 380 static_cast<PepperPluginInstanceImpl*>(
392 renderer_ppapi_host_->GetPluginInstance(pp_instance())); 381 renderer_ppapi_host_->GetPluginInstance(pp_instance()));
393 if (!instance_object || instance_object->is_deleted()) 382 if (!instance_object || instance_object->is_deleted())
394 return NULL; 383 return NULL;
395 return instance_object->GetContainer()->document().frame(); 384 return instance_object->GetContainer()->document().frame();
396 } 385 }
397 386
398 void PepperURLLoaderHost::SetDefersLoading(bool defers_loading) { 387 void PepperURLLoaderHost::SetDefersLoading(bool defers_loading) {
399 if (loader_.get()) 388 if (loader_.get())
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
442 ppapi::proxy::ResourceMessageReplyParams params; 431 ppapi::proxy::ResourceMessageReplyParams params;
443 SendUpdateToPlugin(new PpapiPluginMsg_URLLoader_UpdateProgress( 432 SendUpdateToPlugin(new PpapiPluginMsg_URLLoader_UpdateProgress(
444 record_upload ? bytes_sent_ : -1, 433 record_upload ? bytes_sent_ : -1,
445 record_upload ? total_bytes_to_be_sent_ : -1, 434 record_upload ? total_bytes_to_be_sent_ : -1,
446 record_download ? bytes_received_ : -1, 435 record_download ? bytes_received_ : -1,
447 record_download ? total_bytes_to_be_received_ : -1)); 436 record_download ? total_bytes_to_be_received_ : -1));
448 } 437 }
449 } 438 }
450 439
451 } // namespace content 440 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/pepper/pepper_url_loader_host.h ('k') | content/renderer/pepper/pepper_webplugin_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698