Index: content/browser/loader/resource_dispatcher_host_impl.cc |
diff --git a/content/browser/loader/resource_dispatcher_host_impl.cc b/content/browser/loader/resource_dispatcher_host_impl.cc |
index 6eeb1cae246119c52cc5f7bce74d64fd00675d7a..c0beaf7212eb1111e4f2f44acc7d2e7e39a30fd5 100644 |
--- a/content/browser/loader/resource_dispatcher_host_impl.cc |
+++ b/content/browser/loader/resource_dispatcher_host_impl.cc |
@@ -77,6 +77,7 @@ |
#include "content/common/resource_messages.h" |
#include "content/common/site_isolation_policy.h" |
#include "content/common/ssl_status_serialization.h" |
+#include "content/common/url_loader_type_converters.h" |
#include "content/common/view_messages.h" |
#include "content/public/browser/browser_thread.h" |
#include "content/public/browser/content_browser_client.h" |
@@ -582,6 +583,7 @@ ResourceDispatcherHostImpl::ResourceDispatcherHostImpl() |
ResourceDispatcherHostImpl::~ResourceDispatcherHostImpl() { |
DCHECK(outstanding_requests_stats_map_.empty()); |
DCHECK(g_resource_dispatcher_host); |
+ DCHECK_CURRENTLY_ON(BrowserThread::UI); |
g_resource_dispatcher_host = NULL; |
} |
@@ -1175,6 +1177,7 @@ void ResourceDispatcherHostImpl::OnShutdown() { |
bool ResourceDispatcherHostImpl::OnMessageReceived( |
const IPC::Message& message, |
ResourceMessageFilter* filter) { |
+ DCHECK_CURRENTLY_ON(BrowserThread::IO); |
filter_ = filter; |
bool handled = true; |
IPC_BEGIN_MESSAGE_MAP(ResourceDispatcherHostImpl, message) |
@@ -1216,6 +1219,11 @@ void ResourceDispatcherHostImpl::OnRequestResource( |
int routing_id, |
int request_id, |
const ResourceHostMsg_Request& request_data) { |
+ std::unique_ptr<mojom::URLLoader> loader = |
+ std::move(mojo_loader_for_next_load_request_); |
+ mojom::URLLoaderClientPtr client = |
+ std::move(mojo_loader_client_for_next_load_request_); |
+ |
// TODO(pkasting): Remove ScopedTracker below once crbug.com/477117 is fixed. |
tracked_objects::ScopedTracker tracking_profile( |
FROM_HERE_WITH_EXPLICIT_FUNCTION( |
@@ -1236,7 +1244,8 @@ void ResourceDispatcherHostImpl::OnRequestResource( |
request_data.render_frame_id, |
request_data.url)); |
} |
- BeginRequest(request_id, request_data, NULL, routing_id); |
+ BeginRequest(request_id, request_data, NULL, routing_id, std::move(loader), |
+ std::move(client)); |
} |
// Begins a resource request with the given params on behalf of the specified |
@@ -1367,7 +1376,9 @@ void ResourceDispatcherHostImpl::BeginRequest( |
int request_id, |
const ResourceHostMsg_Request& request_data, |
IPC::Message* sync_result, // only valid for sync |
- int route_id) { |
+ int route_id, |
+ std::unique_ptr<mojom::URLLoader> url_loader, |
+ mojom::URLLoaderClientPtr client) { |
int process_type = filter_->process_type(); |
int child_id = filter_->child_id(); |
@@ -1626,10 +1637,11 @@ void ResourceDispatcherHostImpl::BeginRequest( |
std::unique_ptr<ResourceHandler> handler(CreateResourceHandler( |
new_request.get(), request_data, sync_result, route_id, process_type, |
- child_id, resource_context)); |
+ child_id, resource_context, client)); |
if (handler) |
- BeginRequestInternal(std::move(new_request), std::move(handler)); |
+ BeginRequestInternal(std::move(new_request), std::move(handler), |
+ std::move(url_loader), std::move(client)); |
} |
std::unique_ptr<ResourceHandler> |
@@ -1640,7 +1652,8 @@ ResourceDispatcherHostImpl::CreateResourceHandler( |
int route_id, |
int process_type, |
int child_id, |
- ResourceContext* resource_context) { |
+ ResourceContext* resource_context, |
+ bool using_mojo) { |
// TODO(pkasting): Remove ScopedTracker below once crbug.com/456331 is fixed. |
tracked_objects::ScopedTracker tracking_profile( |
FROM_HERE_WITH_EXPLICIT_FUNCTION( |
@@ -1648,6 +1661,7 @@ ResourceDispatcherHostImpl::CreateResourceHandler( |
// Construct the IPC resource handler. |
std::unique_ptr<ResourceHandler> handler; |
if (sync_result) { |
+ DCHECK(!using_mojo); |
// download_to_file is not supported for synchronous requests. |
if (request_data.download_to_file) { |
bad_message::ReceivedBadMessage(filter_, bad_message::RDH_BAD_DOWNLOAD); |
@@ -1656,7 +1670,7 @@ ResourceDispatcherHostImpl::CreateResourceHandler( |
handler.reset(new SyncResourceHandler(request, sync_result, this)); |
} else { |
- handler.reset(new AsyncResourceHandler(request, this)); |
+ handler.reset(new AsyncResourceHandler(request, this, using_mojo)); |
// The RedirectToFileResourceHandler depends on being next in the chain. |
if (request_data.download_to_file) { |
@@ -1777,6 +1791,31 @@ void ResourceDispatcherHostImpl::OnDidChangePriority( |
intra_priority_value); |
} |
+void ResourceDispatcherHostImpl::OnReceivedResponseForMojo( |
+ int request_id, |
+ const ResourceResponseHead& head) { |
+ int child_id = filter_->child_id(); |
+ ResourceLoader* loader = GetLoader(child_id, request_id); |
+ DCHECK(loader); |
+ mojom::URLLoaderClient* client = loader->client(); |
+ DCHECK(client); |
+ mojom::URLResponsePtr response = mojom::URLResponse::From(head); |
+ response->body = loader->GetRequestInfo()->TakeBodyReader(); |
+ client->OnReceiveResponse(std::move(response)); |
+} |
+ |
+void ResourceDispatcherHostImpl::OnRequestCompleteForMojo( |
+ int request_id, |
+ const ResourceMsg_RequestCompleteData& data) { |
+ int child_id = filter_->child_id(); |
+ ResourceLoader* loader = GetLoader(child_id, request_id); |
+ DCHECK(loader); |
+ mojom::URLLoaderClient* client = loader->client(); |
+ DCHECK(client); |
+ |
+ client->OnComplete(mojom::URLLoaderStatus::From(data)); |
+} |
+ |
void ResourceDispatcherHostImpl::OnDataDownloadedACK(int request_id) { |
// TODO(michaeln): maybe throttle DataDownloaded messages |
} |
@@ -2062,6 +2101,19 @@ void ResourceDispatcherHostImpl::CancelRequestsForRoute( |
CancelBlockedRequestsForRoute(route_id); |
} |
} |
+ |
+ // Uninitiated URLLoader has no routing ID, so it should be deleted only when |
+ // cancel_all_routes is specified. |
+ if (cancel_all_routes) { |
+ auto it = uninitiated_url_loaders_.begin(); |
+ while (it != uninitiated_url_loaders_.end()) { |
+ if (it->second.first == child_id) { |
+ it = uninitiated_url_loaders_.erase(it); |
+ } else { |
+ ++it; |
+ } |
+ } |
+ } |
} |
// Cancels the request and removes it from the list. |
@@ -2349,6 +2401,69 @@ void ResourceDispatcherHostImpl::EnableStaleWhileRevalidateForTesting() { |
async_revalidation_manager_.reset(new AsyncRevalidationManager); |
} |
+void ResourceDispatcherHostImpl::OnRequestResourceFromMojo( |
+ int routing_id, |
+ int request_id, |
+ mojom::URLLoaderClientPtr client, |
+ const ResourceHostMsg_Request& request_data, |
+ ResourceMessageFilter* filter) { |
+ filter_ = filter; |
+ OnRequestResource(routing_id, request_id, request_data); |
+ filter_ = nullptr; |
+} |
+ |
+bool ResourceDispatcherHostImpl::SendWithMojoIfPossible( |
+ const IPC::Message& message, |
+ ResourceMessageFilter* filter) { |
+ if (IPC_MESSAGE_ID_CLASS(message.type()) != ResourceMsgStart) |
+ return false; |
+ |
+ base::PickleIterator iter(message); |
+ int request_id = -1; |
+ bool ok = iter.ReadInt(&request_id); |
+ DCHECK(ok); |
+ ResourceLoader* loader = GetLoader(filter->child_id(), request_id); |
+ if (!loader || !loader->client()) |
+ return false; |
+ |
+ DCHECK(!filter_); |
+ filter_ = filter; |
+ bool handled = true; |
+ IPC_BEGIN_MESSAGE_MAP(ResourceDispatcherHostImpl, message) |
+ IPC_MESSAGE_HANDLER(ResourceMsg_ReceivedResponse, OnReceivedResponseForMojo) |
+ IPC_MESSAGE_HANDLER(ResourceMsg_RequestComplete, OnRequestCompleteForMojo) |
+ IPC_MESSAGE_UNHANDLED(handled = false) |
+ IPC_END_MESSAGE_MAP() |
+ |
+ filter_ = nullptr; |
+ return handled; |
+} |
+ |
+void ResourceDispatcherHostImpl::AddUninitiatedURLLoader( |
+ int child_id, |
+ std::unique_ptr<mojom::URLLoader> loader) { |
+ mojom::URLLoader* raw = loader.get(); |
+ uninitiated_url_loaders_.insert( |
+ std::make_pair(raw, std::make_pair(child_id, std::move(loader)))); |
+} |
+ |
+std::unique_ptr<mojom::URLLoader> |
+ResourceDispatcherHostImpl::TakeUninitiatedURLLoader(mojom::URLLoader* loader) { |
+ auto it = uninitiated_url_loaders_.find(loader); |
+ if (it == uninitiated_url_loaders_.end()) |
+ return nullptr; |
+ std::unique_ptr<mojom::URLLoader> result = std::move(it->second.second); |
+ uninitiated_url_loaders_.erase(it); |
+ return result; |
+} |
+ |
+void ResourceDispatcherHostImpl::SetMojoLoaderAndClientrForNextLoadRequest( |
+ std::unique_ptr<mojom::URLLoader> loader, |
+ mojom::URLLoaderClientPtr client) { |
+ mojo_loader_for_next_load_request_ = std::move(loader); |
+ mojo_loader_client_for_next_load_request_ = std::move(client); |
+} |
+ |
// static |
int ResourceDispatcherHostImpl::CalculateApproximateMemoryCost( |
net::URLRequest* request) { |
@@ -2367,7 +2482,9 @@ int ResourceDispatcherHostImpl::CalculateApproximateMemoryCost( |
void ResourceDispatcherHostImpl::BeginRequestInternal( |
std::unique_ptr<net::URLRequest> request, |
- std::unique_ptr<ResourceHandler> handler) { |
+ std::unique_ptr<ResourceHandler> handler, |
+ std::unique_ptr<mojom::URLLoader> url_loader, |
+ mojom::URLLoaderClientPtr client) { |
DCHECK(!request->is_pending()); |
ResourceRequestInfoImpl* info = |
ResourceRequestInfoImpl::ForRequest(request.get()); |
@@ -2403,8 +2520,9 @@ void ResourceDispatcherHostImpl::BeginRequestInternal( |
return; |
} |
- std::unique_ptr<ResourceLoader> loader(new ResourceLoader( |
- std::move(request), std::move(handler), GetCertStore(), this)); |
+ std::unique_ptr<ResourceLoader> loader( |
+ new ResourceLoader(std::move(request), std::move(handler), GetCertStore(), |
+ std::move(url_loader), std::move(client), this)); |
GlobalFrameRoutingId id(info->GetChildID(), info->GetRenderFrameID()); |
BlockedLoadersMap::const_iterator iter = blocked_loaders_map_.find(id); |