| Index: content/child/web_url_loader_impl.cc
|
| diff --git a/content/child/web_url_loader_impl.cc b/content/child/web_url_loader_impl.cc
|
| index 1da8082e057769e6e964836ecb01dae4bdcc9499..7724a50e6e0c7b6bb89f0d2e5331d552d2ebe979 100644
|
| --- a/content/child/web_url_loader_impl.cc
|
| +++ b/content/child/web_url_loader_impl.cc
|
| @@ -1,6 +1,8 @@
|
| // Copyright 2014 The Chromium Authors. All rights reserved.
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
| +
|
| +// An implementation of WebURLLoader in terms of ResourceLoaderBridge.
|
|
|
| #include "content/child/web_url_loader_impl.h"
|
|
|
| @@ -14,9 +16,7 @@
|
| #include "content/child/ftp_directory_listing_response_delegate.h"
|
| #include "content/child/request_extra_data.h"
|
| #include "content/child/request_info.h"
|
| -#include "content/child/resource_dispatcher.h"
|
| #include "content/child/sync_load_response.h"
|
| -#include "content/common/resource_messages.h"
|
| #include "content/common/resource_request_body.h"
|
| #include "content/public/child/request_peer.h"
|
| #include "net/base/data_url.h"
|
| @@ -37,6 +37,7 @@
|
| #include "third_party/WebKit/public/platform/WebURLResponse.h"
|
| #include "third_party/WebKit/public/web/WebSecurityPolicy.h"
|
| #include "webkit/child/multipart_response_delegate.h"
|
| +#include "webkit/child/resource_loader_bridge.h"
|
| #include "webkit/child/weburlresponse_extradata_impl.h"
|
|
|
| using base::Time;
|
| @@ -57,6 +58,7 @@
|
| using blink::WebURLResponse;
|
| using webkit_glue::MultipartResponseDelegate;
|
| using webkit_glue::ResourceDevToolsInfo;
|
| +using webkit_glue::ResourceLoaderBridge;
|
| using webkit_glue::ResourceResponseInfo;
|
| using webkit_glue::WebURLResponseExtraDataImpl;
|
|
|
| @@ -257,7 +259,7 @@
|
|
|
| private:
|
| friend class base::RefCounted<Context>;
|
| - virtual ~Context();
|
| + virtual ~Context() {}
|
|
|
| // We can optimize the handling of data URLs in most cases.
|
| bool CanHandleDataURL(const GURL& url) const;
|
| @@ -267,21 +269,23 @@
|
| WebURLRequest request_;
|
| WebURLLoaderClient* client_;
|
| WebReferrerPolicy referrer_policy_;
|
| + scoped_ptr<ResourceLoaderBridge> bridge_;
|
| scoped_ptr<FtpDirectoryListingResponseDelegate> ftp_listing_delegate_;
|
| scoped_ptr<MultipartResponseDelegate> multipart_delegate_;
|
| - int request_id_;
|
| + scoped_ptr<ResourceLoaderBridge> completed_bridge_;
|
| };
|
|
|
| WebURLLoaderImpl::Context::Context(WebURLLoaderImpl* loader)
|
| : loader_(loader),
|
| client_(NULL),
|
| - referrer_policy_(blink::WebReferrerPolicyDefault),
|
| - request_id_(-1) {
|
| + referrer_policy_(blink::WebReferrerPolicyDefault) {
|
| }
|
|
|
| void WebURLLoaderImpl::Context::Cancel() {
|
| - if (ChildThread::current()) // NULL in unittest.
|
| - ChildThread::current()->resource_dispatcher()->Cancel(request_id_);
|
| + // The bridge will still send OnCompletedRequest, which will Release() us, so
|
| + // we don't do that here.
|
| + if (bridge_)
|
| + bridge_->Cancel();
|
|
|
| // Ensure that we do not notify the multipart delegate anymore as it has
|
| // its own pointer to the client.
|
| @@ -294,21 +298,21 @@
|
| }
|
|
|
| void WebURLLoaderImpl::Context::SetDefersLoading(bool value) {
|
| - ChildThread::current()->resource_dispatcher()->SetDefersLoading(request_id_,
|
| - value);
|
| + if (bridge_)
|
| + bridge_->SetDefersLoading(value);
|
| }
|
|
|
| void WebURLLoaderImpl::Context::DidChangePriority(
|
| - WebURLRequest::Priority new_priority,
|
| - int intra_priority_value) {
|
| - ChildThread::current()->resource_dispatcher()->DidChangePriority(
|
| - request_id_,
|
| - ConvertWebKitPriorityToNetPriority(new_priority),
|
| - intra_priority_value);
|
| + WebURLRequest::Priority new_priority, int intra_priority_value) {
|
| + if (bridge_)
|
| + bridge_->DidChangePriority(
|
| + ConvertWebKitPriorityToNetPriority(new_priority), intra_priority_value);
|
| }
|
|
|
| void WebURLLoaderImpl::Context::Start(const WebURLRequest& request,
|
| SyncLoadResponse* sync_load_response) {
|
| + DCHECK(!bridge_.get());
|
| +
|
| request_ = request; // Save the request.
|
|
|
| GURL url = request.url();
|
| @@ -396,10 +400,7 @@
|
| request_info.extra_data = request.extraData();
|
| referrer_policy_ = request.referrerPolicy();
|
| request_info.referrer_policy = request.referrerPolicy();
|
| - ResourceDispatcher* dispatcher =
|
| - ChildThread::current()->resource_dispatcher();
|
| -
|
| - scoped_refptr<ResourceRequestBody> request_body = new ResourceRequestBody;
|
| + bridge_.reset(ChildThread::current()->CreateBridge(request_info));
|
|
|
| if (!request.httpBody().isNull()) {
|
| // GET and HEAD requests shouldn't have http bodies.
|
| @@ -407,6 +408,7 @@
|
| const WebHTTPBody& httpBody = request.httpBody();
|
| size_t i = 0;
|
| WebHTTPBody::Element element;
|
| + scoped_refptr<ResourceRequestBody> request_body = new ResourceRequestBody;
|
| while (httpBody.elementAt(i++, element)) {
|
| switch (element.type) {
|
| case WebHTTPBody::Element::TypeData:
|
| @@ -448,16 +450,19 @@
|
| }
|
| }
|
| request_body->set_identifier(request.httpBody().identifier());
|
| -
|
| + bridge_->SetRequestBody(request_body.get());
|
| }
|
|
|
| if (sync_load_response) {
|
| - dispatcher->StartSync(request_info, request_body.get(), sync_load_response);
|
| + bridge_->SyncLoad(sync_load_response);
|
| return;
|
| }
|
|
|
| - AddRef(); // Balanced in OnCompletedRequest.
|
| - request_id_ = dispatcher->StartAsync(request_info, request_body.get(), this);
|
| + if (bridge_->Start(this)) {
|
| + AddRef(); // Balanced in OnCompletedRequest
|
| + } else {
|
| + bridge_.reset();
|
| + }
|
| }
|
|
|
| void WebURLLoaderImpl::Context::OnUploadProgress(uint64 position, uint64 size) {
|
| @@ -594,8 +599,8 @@
|
| }
|
| }
|
|
|
| -void WebURLLoaderImpl::Context::OnReceivedCachedMetadata(const char* data,
|
| - int len) {
|
| +void WebURLLoaderImpl::Context::OnReceivedCachedMetadata(
|
| + const char* data, int len) {
|
| if (client_)
|
| client_->didReceiveCachedMetadata(loader_, data, len);
|
| }
|
| @@ -615,6 +620,11 @@
|
| multipart_delegate_.reset(NULL);
|
| }
|
|
|
| + // Prevent any further IPC to the browser now that we're complete, but
|
| + // don't delete it to keep any downloaded temp files alive.
|
| + DCHECK(!completed_bridge_.get());
|
| + completed_bridge_.swap(bridge_);
|
| +
|
| if (client_) {
|
| if (error_code != net::OK) {
|
| client_->didFail(loader_, CreateError(request_.url(),
|
| @@ -633,13 +643,6 @@
|
| Release();
|
| }
|
|
|
| -WebURLLoaderImpl::Context::~Context() {
|
| - if (request_id_ >= 0) {
|
| - ChildThread::current()->resource_dispatcher()->RemovePendingRequest(
|
| - request_id_);
|
| - }
|
| -}
|
| -
|
| bool WebURLLoaderImpl::Context::CanHandleDataURL(const GURL& url) const {
|
| DCHECK(url.SchemeIs("data"));
|
|
|
| @@ -648,7 +651,8 @@
|
| // download.
|
| //
|
| // NOTE: We special case MIME types we can render both for performance
|
| - // reasons as well as to support unit tests.
|
| + // reasons as well as to support unit tests, which do not have an underlying
|
| + // ResourceLoaderBridge implementation.
|
|
|
| #if defined(OS_ANDROID)
|
| // For compatibility reasons on Android we need to expose top-level data://
|
|
|