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

Side by Side Diff: content/child/web_url_loader_impl.cc

Issue 226273005: Remove webkit's ResourceLoaderBridge interface. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: StartSync -> StartAsync -> Cancel - change StartAsync to request request_id Created 6 years, 8 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 // An implementation of WebURLLoader in terms of ResourceLoaderBridge.
6
7 #include "content/child/web_url_loader_impl.h" 5 #include "content/child/web_url_loader_impl.h"
8 6
9 #include "base/bind.h" 7 #include "base/bind.h"
10 #include "base/files/file_path.h" 8 #include "base/files/file_path.h"
11 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
12 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
13 #include "base/strings/string_util.h" 11 #include "base/strings/string_util.h"
14 #include "base/time/time.h" 12 #include "base/time/time.h"
15 #include "content/child/child_thread.h" 13 #include "content/child/child_thread.h"
16 #include "content/child/ftp_directory_listing_response_delegate.h" 14 #include "content/child/ftp_directory_listing_response_delegate.h"
17 #include "content/child/request_extra_data.h" 15 #include "content/child/request_extra_data.h"
18 #include "content/child/request_info.h" 16 #include "content/child/request_info.h"
17 #include "content/child/resource_dispatcher.h"
19 #include "content/child/sync_load_response.h" 18 #include "content/child/sync_load_response.h"
20 #include "content/common/resource_request_body.h" 19 #include "content/common/resource_request_body.h"
21 #include "content/public/child/request_peer.h" 20 #include "content/public/child/request_peer.h"
22 #include "net/base/data_url.h" 21 #include "net/base/data_url.h"
23 #include "net/base/filename_util.h" 22 #include "net/base/filename_util.h"
24 #include "net/base/load_flags.h" 23 #include "net/base/load_flags.h"
25 #include "net/base/mime_util.h" 24 #include "net/base/mime_util.h"
26 #include "net/base/net_errors.h" 25 #include "net/base/net_errors.h"
27 #include "net/http/http_response_headers.h" 26 #include "net/http/http_response_headers.h"
28 #include "net/http/http_util.h" 27 #include "net/http/http_util.h"
29 #include "net/url_request/url_request.h" 28 #include "net/url_request/url_request.h"
30 #include "third_party/WebKit/public/platform/WebHTTPHeaderVisitor.h" 29 #include "third_party/WebKit/public/platform/WebHTTPHeaderVisitor.h"
31 #include "third_party/WebKit/public/platform/WebHTTPLoadInfo.h" 30 #include "third_party/WebKit/public/platform/WebHTTPLoadInfo.h"
32 #include "third_party/WebKit/public/platform/WebURL.h" 31 #include "third_party/WebKit/public/platform/WebURL.h"
33 #include "third_party/WebKit/public/platform/WebURLError.h" 32 #include "third_party/WebKit/public/platform/WebURLError.h"
34 #include "third_party/WebKit/public/platform/WebURLLoadTiming.h" 33 #include "third_party/WebKit/public/platform/WebURLLoadTiming.h"
35 #include "third_party/WebKit/public/platform/WebURLLoaderClient.h" 34 #include "third_party/WebKit/public/platform/WebURLLoaderClient.h"
36 #include "third_party/WebKit/public/platform/WebURLRequest.h" 35 #include "third_party/WebKit/public/platform/WebURLRequest.h"
37 #include "third_party/WebKit/public/platform/WebURLResponse.h" 36 #include "third_party/WebKit/public/platform/WebURLResponse.h"
38 #include "third_party/WebKit/public/web/WebSecurityPolicy.h" 37 #include "third_party/WebKit/public/web/WebSecurityPolicy.h"
39 #include "webkit/child/multipart_response_delegate.h" 38 #include "webkit/child/multipart_response_delegate.h"
40 #include "webkit/child/resource_loader_bridge.h"
41 #include "webkit/child/weburlresponse_extradata_impl.h" 39 #include "webkit/child/weburlresponse_extradata_impl.h"
42 40
43 using base::Time; 41 using base::Time;
44 using base::TimeTicks; 42 using base::TimeTicks;
45 using blink::WebData; 43 using blink::WebData;
46 using blink::WebHTTPBody; 44 using blink::WebHTTPBody;
47 using blink::WebHTTPHeaderVisitor; 45 using blink::WebHTTPHeaderVisitor;
48 using blink::WebHTTPLoadInfo; 46 using blink::WebHTTPLoadInfo;
49 using blink::WebReferrerPolicy; 47 using blink::WebReferrerPolicy;
50 using blink::WebSecurityPolicy; 48 using blink::WebSecurityPolicy;
51 using blink::WebString; 49 using blink::WebString;
52 using blink::WebURL; 50 using blink::WebURL;
53 using blink::WebURLError; 51 using blink::WebURLError;
54 using blink::WebURLLoadTiming; 52 using blink::WebURLLoadTiming;
55 using blink::WebURLLoader; 53 using blink::WebURLLoader;
56 using blink::WebURLLoaderClient; 54 using blink::WebURLLoaderClient;
57 using blink::WebURLRequest; 55 using blink::WebURLRequest;
58 using blink::WebURLResponse; 56 using blink::WebURLResponse;
59 using webkit_glue::MultipartResponseDelegate; 57 using webkit_glue::MultipartResponseDelegate;
60 using webkit_glue::ResourceDevToolsInfo; 58 using webkit_glue::ResourceDevToolsInfo;
61 using webkit_glue::ResourceLoaderBridge;
62 using webkit_glue::ResourceResponseInfo; 59 using webkit_glue::ResourceResponseInfo;
63 using webkit_glue::WebURLResponseExtraDataImpl; 60 using webkit_glue::WebURLResponseExtraDataImpl;
64 61
65 namespace content { 62 namespace content {
66 63
67 // Utilities ------------------------------------------------------------------ 64 // Utilities ------------------------------------------------------------------
68 65
69 namespace { 66 namespace {
70 67
71 const char kThrottledErrorDescription[] = 68 const char kThrottledErrorDescription[] =
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 virtual ~Context() {} 259 virtual ~Context() {}
263 260
264 // We can optimize the handling of data URLs in most cases. 261 // We can optimize the handling of data URLs in most cases.
265 bool CanHandleDataURL(const GURL& url) const; 262 bool CanHandleDataURL(const GURL& url) const;
266 void HandleDataURL(); 263 void HandleDataURL();
267 264
268 WebURLLoaderImpl* loader_; 265 WebURLLoaderImpl* loader_;
269 WebURLRequest request_; 266 WebURLRequest request_;
270 WebURLLoaderClient* client_; 267 WebURLLoaderClient* client_;
271 WebReferrerPolicy referrer_policy_; 268 WebReferrerPolicy referrer_policy_;
272 scoped_ptr<ResourceLoaderBridge> bridge_;
273 scoped_ptr<FtpDirectoryListingResponseDelegate> ftp_listing_delegate_; 269 scoped_ptr<FtpDirectoryListingResponseDelegate> ftp_listing_delegate_;
274 scoped_ptr<MultipartResponseDelegate> multipart_delegate_; 270 scoped_ptr<MultipartResponseDelegate> multipart_delegate_;
275 scoped_ptr<ResourceLoaderBridge> completed_bridge_; 271 int request_id_;
276 }; 272 };
277 273
278 WebURLLoaderImpl::Context::Context(WebURLLoaderImpl* loader) 274 WebURLLoaderImpl::Context::Context(WebURLLoaderImpl* loader)
279 : loader_(loader), 275 : loader_(loader),
280 client_(NULL), 276 client_(NULL),
281 referrer_policy_(blink::WebReferrerPolicyDefault) { 277 referrer_policy_(blink::WebReferrerPolicyDefault),
278 request_id_(-1) {
282 } 279 }
283 280
284 void WebURLLoaderImpl::Context::Cancel() { 281 void WebURLLoaderImpl::Context::Cancel() {
285 // The bridge will still send OnCompletedRequest, which will Release() us, so 282 ChildThread::current()->resource_dispatcher()->Cancel(request_id_);
286 // we don't do that here.
287 if (bridge_)
288 bridge_->Cancel();
289 283
290 // Ensure that we do not notify the multipart delegate anymore as it has 284 // Ensure that we do not notify the multipart delegate anymore as it has
291 // its own pointer to the client. 285 // its own pointer to the client.
292 if (multipart_delegate_) 286 if (multipart_delegate_)
293 multipart_delegate_->Cancel(); 287 multipart_delegate_->Cancel();
294 288
295 // Do not make any further calls to the client. 289 // Do not make any further calls to the client.
296 client_ = NULL; 290 client_ = NULL;
297 loader_ = NULL; 291 loader_ = NULL;
298 } 292 }
299 293
300 void WebURLLoaderImpl::Context::SetDefersLoading(bool value) { 294 void WebURLLoaderImpl::Context::SetDefersLoading(bool value) {
301 if (bridge_) 295 ChildThread::current()->resource_dispatcher()->SetDefersLoading(request_id_,
302 bridge_->SetDefersLoading(value); 296 value);
303 } 297 }
304 298
305 void WebURLLoaderImpl::Context::DidChangePriority( 299 void WebURLLoaderImpl::Context::DidChangePriority(
306 WebURLRequest::Priority new_priority, int intra_priority_value) { 300 WebURLRequest::Priority new_priority,
307 if (bridge_) 301 int intra_priority_value) {
308 bridge_->DidChangePriority( 302 ChildThread::current()->resource_dispatcher()->DidChangePriority(
309 ConvertWebKitPriorityToNetPriority(new_priority), intra_priority_value); 303 0 /*routing_id*/,
304 request_id_,
305 ConvertWebKitPriorityToNetPriority(new_priority),
306 intra_priority_value);
310 } 307 }
311 308
312 void WebURLLoaderImpl::Context::Start(const WebURLRequest& request, 309 void WebURLLoaderImpl::Context::Start(const WebURLRequest& request,
313 SyncLoadResponse* sync_load_response) { 310 SyncLoadResponse* sync_load_response) {
314 DCHECK(!bridge_.get());
315
316 request_ = request; // Save the request. 311 request_ = request; // Save the request.
317 312
318 GURL url = request.url(); 313 GURL url = request.url();
319 if (url.SchemeIs("data") && CanHandleDataURL(url)) { 314 if (url.SchemeIs("data") && CanHandleDataURL(url)) {
320 if (sync_load_response) { 315 if (sync_load_response) {
321 // This is a sync load. Do the work now. 316 // This is a sync load. Do the work now.
322 sync_load_response->url = url; 317 sync_load_response->url = url;
323 std::string data; 318 std::string data;
324 GetInfoFromDataURL(sync_load_response->url, sync_load_response, 319 GetInfoFromDataURL(sync_load_response->url, sync_load_response,
325 &sync_load_response->data, 320 &sync_load_response->data,
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
393 ResourceType::FromTargetType(request.targetType()); 388 ResourceType::FromTargetType(request.targetType());
394 request_info.priority = 389 request_info.priority =
395 ConvertWebKitPriorityToNetPriority(request.priority()); 390 ConvertWebKitPriorityToNetPriority(request.priority());
396 request_info.appcache_host_id = request.appCacheHostID(); 391 request_info.appcache_host_id = request.appCacheHostID();
397 request_info.routing_id = request.requestorID(); 392 request_info.routing_id = request.requestorID();
398 request_info.download_to_file = request.downloadToFile(); 393 request_info.download_to_file = request.downloadToFile();
399 request_info.has_user_gesture = request.hasUserGesture(); 394 request_info.has_user_gesture = request.hasUserGesture();
400 request_info.extra_data = request.extraData(); 395 request_info.extra_data = request.extraData();
401 referrer_policy_ = request.referrerPolicy(); 396 referrer_policy_ = request.referrerPolicy();
402 request_info.referrer_policy = request.referrerPolicy(); 397 request_info.referrer_policy = request.referrerPolicy();
403 bridge_.reset(ChildThread::current()->CreateBridge(request_info)); 398 ResourceDispatcher* dispatcher =
399 ChildThread::current()->resource_dispatcher();
404 400
405 if (!request.httpBody().isNull()) { 401 if (!request.httpBody().isNull()) {
406 // GET and HEAD requests shouldn't have http bodies. 402 // GET and HEAD requests shouldn't have http bodies.
407 DCHECK(method != "GET" && method != "HEAD"); 403 DCHECK(method != "GET" && method != "HEAD");
408 const WebHTTPBody& httpBody = request.httpBody(); 404 const WebHTTPBody& httpBody = request.httpBody();
409 size_t i = 0; 405 size_t i = 0;
410 WebHTTPBody::Element element; 406 WebHTTPBody::Element element;
411 scoped_refptr<ResourceRequestBody> request_body = new ResourceRequestBody; 407 scoped_refptr<ResourceRequestBody> request_body = new ResourceRequestBody;
412 while (httpBody.elementAt(i++, element)) { 408 while (httpBody.elementAt(i++, element)) {
413 switch (element.type) { 409 switch (element.type) {
(...skipping 29 matching lines...) Expand all
443 break; 439 break;
444 } 440 }
445 case WebHTTPBody::Element::TypeBlob: 441 case WebHTTPBody::Element::TypeBlob:
446 request_body->AppendBlob(element.blobUUID.utf8()); 442 request_body->AppendBlob(element.blobUUID.utf8());
447 break; 443 break;
448 default: 444 default:
449 NOTREACHED(); 445 NOTREACHED();
450 } 446 }
451 } 447 }
452 request_body->set_identifier(request.httpBody().identifier()); 448 request_body->set_identifier(request.httpBody().identifier());
453 bridge_->SetRequestBody(request_body.get());
454 }
455 449
456 if (sync_load_response) { 450 if (sync_load_response) {
457 bridge_->SyncLoad(sync_load_response); 451 dispatcher->StartSync(
458 return; 452 request_info, request_body.get(), sync_load_response);
459 } 453 return;
454 }
460 455
461 if (bridge_->Start(this)) { 456 request_id_ =
462 AddRef(); // Balanced in OnCompletedRequest 457 dispatcher->StartAsync(request_info, request_body.get(), this);
463 } else {
464 bridge_.reset();
465 } 458 }
466 } 459 }
467 460
468 void WebURLLoaderImpl::Context::OnUploadProgress(uint64 position, uint64 size) { 461 void WebURLLoaderImpl::Context::OnUploadProgress(uint64 position, uint64 size) {
469 if (client_) 462 if (client_)
470 client_->didSendData(loader_, position, size); 463 client_->didSendData(loader_, position, size);
471 } 464 }
472 465
473 bool WebURLLoaderImpl::Context::OnReceivedRedirect( 466 bool WebURLLoaderImpl::Context::OnReceivedRedirect(
474 const GURL& new_url, 467 const GURL& new_url,
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
613 const base::TimeTicks& completion_time, 606 const base::TimeTicks& completion_time,
614 int64 total_transfer_size) { 607 int64 total_transfer_size) {
615 if (ftp_listing_delegate_) { 608 if (ftp_listing_delegate_) {
616 ftp_listing_delegate_->OnCompletedRequest(); 609 ftp_listing_delegate_->OnCompletedRequest();
617 ftp_listing_delegate_.reset(NULL); 610 ftp_listing_delegate_.reset(NULL);
618 } else if (multipart_delegate_) { 611 } else if (multipart_delegate_) {
619 multipart_delegate_->OnCompletedRequest(); 612 multipart_delegate_->OnCompletedRequest();
620 multipart_delegate_.reset(NULL); 613 multipart_delegate_.reset(NULL);
621 } 614 }
622 615
623 // Prevent any further IPC to the browser now that we're complete, but
624 // don't delete it to keep any downloaded temp files alive.
625 DCHECK(!completed_bridge_.get());
626 completed_bridge_.swap(bridge_);
627
628 if (client_) { 616 if (client_) {
629 if (error_code != net::OK) { 617 if (error_code != net::OK) {
630 client_->didFail(loader_, CreateError(request_.url(), 618 client_->didFail(loader_, CreateError(request_.url(),
631 stale_copy_in_cache, 619 stale_copy_in_cache,
632 error_code)); 620 error_code));
633 } else { 621 } else {
634 client_->didFinishLoading( 622 client_->didFinishLoading(
635 loader_, (completion_time - TimeTicks()).InSecondsF(), 623 loader_, (completion_time - TimeTicks()).InSecondsF(),
636 total_transfer_size); 624 total_transfer_size);
637 } 625 }
638 } 626 }
639 627
640 // We are done with the bridge now, and so we need to release the reference 628 // We are done with the bridge now, and so we need to release the reference
641 // to ourselves that we took on behalf of the bridge. This may cause our 629 // to ourselves that we took on behalf of the bridge. This may cause our
642 // destruction. 630 // destruction.
643 Release(); 631 Release();
644 } 632 }
645 633
646 bool WebURLLoaderImpl::Context::CanHandleDataURL(const GURL& url) const { 634 bool WebURLLoaderImpl::Context::CanHandleDataURL(const GURL& url) const {
647 DCHECK(url.SchemeIs("data")); 635 DCHECK(url.SchemeIs("data"));
648 636
649 // Optimize for the case where we can handle a data URL locally. We must 637 // Optimize for the case where we can handle a data URL locally. We must
650 // skip this for data URLs targetted at frames since those could trigger a 638 // skip this for data URLs targetted at frames since those could trigger a
651 // download. 639 // download.
652 // 640 //
653 // NOTE: We special case MIME types we can render both for performance 641 // NOTE: We special case MIME types we can render both for performance
654 // reasons as well as to support unit tests, which do not have an underlying 642 // reasons as well as to support unit tests.
655 // ResourceLoaderBridge implementation.
656 643
657 #if defined(OS_ANDROID) 644 #if defined(OS_ANDROID)
658 // For compatibility reasons on Android we need to expose top-level data:// 645 // For compatibility reasons on Android we need to expose top-level data://
659 // to the browser. 646 // to the browser.
660 if (request_.targetType() == WebURLRequest::TargetIsMainFrame) 647 if (request_.targetType() == WebURLRequest::TargetIsMainFrame)
661 return false; 648 return false;
662 #endif 649 #endif
663 650
664 if (request_.targetType() != WebURLRequest::TargetIsMainFrame && 651 if (request_.targetType() != WebURLRequest::TargetIsMainFrame &&
665 request_.targetType() != WebURLRequest::TargetIsSubframe) 652 request_.targetType() != WebURLRequest::TargetIsSubframe)
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
867 void WebURLLoaderImpl::setDefersLoading(bool value) { 854 void WebURLLoaderImpl::setDefersLoading(bool value) {
868 context_->SetDefersLoading(value); 855 context_->SetDefersLoading(value);
869 } 856 }
870 857
871 void WebURLLoaderImpl::didChangePriority(WebURLRequest::Priority new_priority, 858 void WebURLLoaderImpl::didChangePriority(WebURLRequest::Priority new_priority,
872 int intra_priority_value) { 859 int intra_priority_value) {
873 context_->DidChangePriority(new_priority, intra_priority_value); 860 context_->DidChangePriority(new_priority, intra_priority_value);
874 } 861 }
875 862
876 } // namespace content 863 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698