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

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: rm resource_loader_bridge.* 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/load_flags.h" 22 #include "net/base/load_flags.h"
24 #include "net/base/mime_util.h" 23 #include "net/base/mime_util.h"
25 #include "net/base/net_errors.h" 24 #include "net/base/net_errors.h"
26 #include "net/base/net_util.h" 25 #include "net/base/net_util.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_;
276 }; 271 };
277 272
278 WebURLLoaderImpl::Context::Context(WebURLLoaderImpl* loader) 273 WebURLLoaderImpl::Context::Context(WebURLLoaderImpl* loader)
279 : loader_(loader), 274 : loader_(loader),
280 client_(NULL), 275 client_(NULL),
281 referrer_policy_(blink::WebReferrerPolicyDefault) { 276 referrer_policy_(blink::WebReferrerPolicyDefault) {
282 } 277 }
283 278
284 void WebURLLoaderImpl::Context::Cancel() { 279 void WebURLLoaderImpl::Context::Cancel() {
285 // The bridge will still send OnCompletedRequest, which will Release() us, so 280 ChildThread::current()->resource_dispatcher()->Cancel();
286 // we don't do that here.
287 if (bridge_)
288 bridge_->Cancel();
289 281
290 // Ensure that we do not notify the multipart delegate anymore as it has 282 // Ensure that we do not notify the multipart delegate anymore as it has
291 // its own pointer to the client. 283 // its own pointer to the client.
292 if (multipart_delegate_) 284 if (multipart_delegate_)
293 multipart_delegate_->Cancel(); 285 multipart_delegate_->Cancel();
294 286
295 // Do not make any further calls to the client. 287 // Do not make any further calls to the client.
296 client_ = NULL; 288 client_ = NULL;
297 loader_ = NULL; 289 loader_ = NULL;
298 } 290 }
299 291
300 void WebURLLoaderImpl::Context::SetDefersLoading(bool value) { 292 void WebURLLoaderImpl::Context::SetDefersLoading(bool value) {
301 if (bridge_) 293 ChildThread::current()->resource_dispatcher()->SetDefersLoading(value);
302 bridge_->SetDefersLoading(value);
303 } 294 }
304 295
305 void WebURLLoaderImpl::Context::DidChangePriority( 296 void WebURLLoaderImpl::Context::DidChangePriority(
306 WebURLRequest::Priority new_priority, int intra_priority_value) { 297 WebURLRequest::Priority new_priority,
307 if (bridge_) 298 int intra_priority_value) {
308 bridge_->DidChangePriority( 299 ChildThread::current()->resource_dispatcher()->DidChangePriority(
309 ConvertWebKitPriorityToNetPriority(new_priority), intra_priority_value); 300 ConvertWebKitPriorityToNetPriority(new_priority), intra_priority_value);
310 } 301 }
311 302
312 void WebURLLoaderImpl::Context::Start(const WebURLRequest& request, 303 void WebURLLoaderImpl::Context::Start(const WebURLRequest& request,
313 SyncLoadResponse* sync_load_response) { 304 SyncLoadResponse* sync_load_response) {
314 DCHECK(!bridge_.get());
315
316 request_ = request; // Save the request. 305 request_ = request; // Save the request.
317 306
318 GURL url = request.url(); 307 GURL url = request.url();
319 if (url.SchemeIs("data") && CanHandleDataURL(url)) { 308 if (url.SchemeIs("data") && CanHandleDataURL(url)) {
320 if (sync_load_response) { 309 if (sync_load_response) {
321 // This is a sync load. Do the work now. 310 // This is a sync load. Do the work now.
322 sync_load_response->url = url; 311 sync_load_response->url = url;
323 std::string data; 312 std::string data;
324 GetInfoFromDataURL(sync_load_response->url, sync_load_response, 313 GetInfoFromDataURL(sync_load_response->url, sync_load_response,
325 &sync_load_response->data, 314 &sync_load_response->data,
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
393 ResourceType::FromTargetType(request.targetType()); 382 ResourceType::FromTargetType(request.targetType());
394 request_info.priority = 383 request_info.priority =
395 ConvertWebKitPriorityToNetPriority(request.priority()); 384 ConvertWebKitPriorityToNetPriority(request.priority());
396 request_info.appcache_host_id = request.appCacheHostID(); 385 request_info.appcache_host_id = request.appCacheHostID();
397 request_info.routing_id = request.requestorID(); 386 request_info.routing_id = request.requestorID();
398 request_info.download_to_file = request.downloadToFile(); 387 request_info.download_to_file = request.downloadToFile();
399 request_info.has_user_gesture = request.hasUserGesture(); 388 request_info.has_user_gesture = request.hasUserGesture();
400 request_info.extra_data = request.extraData(); 389 request_info.extra_data = request.extraData();
401 referrer_policy_ = request.referrerPolicy(); 390 referrer_policy_ = request.referrerPolicy();
402 request_info.referrer_policy = request.referrerPolicy(); 391 request_info.referrer_policy = request.referrerPolicy();
403 bridge_.reset(ChildThread::current()->CreateBridge(request_info)); 392 ResourceDispatcher* dispatcher =
393 ChildThread::current()->resource_dispatcher();
394 dispatcher->CreateBridge(request_info);
404 395
405 if (!request.httpBody().isNull()) { 396 if (!request.httpBody().isNull()) {
406 // GET and HEAD requests shouldn't have http bodies. 397 // GET and HEAD requests shouldn't have http bodies.
407 DCHECK(method != "GET" && method != "HEAD"); 398 DCHECK(method != "GET" && method != "HEAD");
408 const WebHTTPBody& httpBody = request.httpBody(); 399 const WebHTTPBody& httpBody = request.httpBody();
409 size_t i = 0; 400 size_t i = 0;
410 WebHTTPBody::Element element; 401 WebHTTPBody::Element element;
411 scoped_refptr<ResourceRequestBody> request_body = new ResourceRequestBody; 402 scoped_refptr<ResourceRequestBody> request_body = new ResourceRequestBody;
412 while (httpBody.elementAt(i++, element)) { 403 while (httpBody.elementAt(i++, element)) {
413 switch (element.type) { 404 switch (element.type) {
(...skipping 29 matching lines...) Expand all
443 break; 434 break;
444 } 435 }
445 case WebHTTPBody::Element::TypeBlob: 436 case WebHTTPBody::Element::TypeBlob:
446 request_body->AppendBlob(element.blobUUID.utf8()); 437 request_body->AppendBlob(element.blobUUID.utf8());
447 break; 438 break;
448 default: 439 default:
449 NOTREACHED(); 440 NOTREACHED();
450 } 441 }
451 } 442 }
452 request_body->set_identifier(request.httpBody().identifier()); 443 request_body->set_identifier(request.httpBody().identifier());
453 bridge_->SetRequestBody(request_body.get()); 444 dispatcher->SetRequestBody(request_body.get());
454 } 445 }
455 446
456 if (sync_load_response) { 447 if (sync_load_response) {
457 bridge_->SyncLoad(sync_load_response); 448 dispatcher->SyncLoad(sync_load_response);
458 return; 449 return;
459 } 450 }
460 451
461 if (bridge_->Start(this)) { 452 if (dispatcher->Start(this)) {
462 AddRef(); // Balanced in OnCompletedRequest 453 AddRef(); // Balanced in OnCompletedRequest
463 } else {
464 bridge_.reset();
465 } 454 }
466 } 455 }
467 456
468 void WebURLLoaderImpl::Context::OnUploadProgress(uint64 position, uint64 size) { 457 void WebURLLoaderImpl::Context::OnUploadProgress(uint64 position, uint64 size) {
469 if (client_) 458 if (client_)
470 client_->didSendData(loader_, position, size); 459 client_->didSendData(loader_, position, size);
471 } 460 }
472 461
473 bool WebURLLoaderImpl::Context::OnReceivedRedirect( 462 bool WebURLLoaderImpl::Context::OnReceivedRedirect(
474 const GURL& new_url, 463 const GURL& new_url,
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
613 const base::TimeTicks& completion_time, 602 const base::TimeTicks& completion_time,
614 int64 total_transfer_size) { 603 int64 total_transfer_size) {
615 if (ftp_listing_delegate_) { 604 if (ftp_listing_delegate_) {
616 ftp_listing_delegate_->OnCompletedRequest(); 605 ftp_listing_delegate_->OnCompletedRequest();
617 ftp_listing_delegate_.reset(NULL); 606 ftp_listing_delegate_.reset(NULL);
618 } else if (multipart_delegate_) { 607 } else if (multipart_delegate_) {
619 multipart_delegate_->OnCompletedRequest(); 608 multipart_delegate_->OnCompletedRequest();
620 multipart_delegate_.reset(NULL); 609 multipart_delegate_.reset(NULL);
621 } 610 }
622 611
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_) { 612 if (client_) {
629 if (error_code != net::OK) { 613 if (error_code != net::OK) {
630 client_->didFail(loader_, CreateError(request_.url(), 614 client_->didFail(loader_, CreateError(request_.url(),
631 stale_copy_in_cache, 615 stale_copy_in_cache,
632 error_code)); 616 error_code));
633 } else { 617 } else {
634 client_->didFinishLoading( 618 client_->didFinishLoading(
635 loader_, (completion_time - TimeTicks()).InSecondsF(), 619 loader_, (completion_time - TimeTicks()).InSecondsF(),
636 total_transfer_size); 620 total_transfer_size);
637 } 621 }
638 } 622 }
639 623
640 // We are done with the bridge now, and so we need to release the reference 624 // 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 625 // to ourselves that we took on behalf of the bridge. This may cause our
642 // destruction. 626 // destruction.
643 Release(); 627 Release();
644 } 628 }
645 629
646 bool WebURLLoaderImpl::Context::CanHandleDataURL(const GURL& url) const { 630 bool WebURLLoaderImpl::Context::CanHandleDataURL(const GURL& url) const {
647 DCHECK(url.SchemeIs("data")); 631 DCHECK(url.SchemeIs("data"));
648 632
649 // Optimize for the case where we can handle a data URL locally. We must 633 // 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 634 // skip this for data URLs targetted at frames since those could trigger a
651 // download. 635 // download.
652 // 636 //
653 // NOTE: We special case MIME types we can render both for performance 637 // 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 638 // reasons as well as to support unit tests.
655 // ResourceLoaderBridge implementation.
656 639
657 #if defined(OS_ANDROID) 640 #if defined(OS_ANDROID)
658 // For compatibility reasons on Android we need to expose top-level data:// 641 // For compatibility reasons on Android we need to expose top-level data://
659 // to the browser. 642 // to the browser.
660 if (request_.targetType() == WebURLRequest::TargetIsMainFrame) 643 if (request_.targetType() == WebURLRequest::TargetIsMainFrame)
661 return false; 644 return false;
662 #endif 645 #endif
663 646
664 if (request_.targetType() != WebURLRequest::TargetIsMainFrame && 647 if (request_.targetType() != WebURLRequest::TargetIsMainFrame &&
665 request_.targetType() != WebURLRequest::TargetIsSubframe) 648 request_.targetType() != WebURLRequest::TargetIsSubframe)
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
867 void WebURLLoaderImpl::setDefersLoading(bool value) { 850 void WebURLLoaderImpl::setDefersLoading(bool value) {
868 context_->SetDefersLoading(value); 851 context_->SetDefersLoading(value);
869 } 852 }
870 853
871 void WebURLLoaderImpl::didChangePriority(WebURLRequest::Priority new_priority, 854 void WebURLLoaderImpl::didChangePriority(WebURLRequest::Priority new_priority,
872 int intra_priority_value) { 855 int intra_priority_value) {
873 context_->DidChangePriority(new_priority, intra_priority_value); 856 context_->DidChangePriority(new_priority, intra_priority_value);
874 } 857 }
875 858
876 } // namespace content 859 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698