summaryrefslogtreecommitdiffstats
path: root/chrome/browser/renderer_host/resource_dispatcher_host.cc
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/browser/renderer_host/resource_dispatcher_host.cc')
-rw-r--r--chrome/browser/renderer_host/resource_dispatcher_host.cc122
1 files changed, 74 insertions, 48 deletions
diff --git a/chrome/browser/renderer_host/resource_dispatcher_host.cc b/chrome/browser/renderer_host/resource_dispatcher_host.cc
index a626f06..94bf0b6 100644
--- a/chrome/browser/renderer_host/resource_dispatcher_host.cc
+++ b/chrome/browser/renderer_host/resource_dispatcher_host.cc
@@ -227,6 +227,20 @@ bool ShouldServiceRequest(ChildProcessInfo::ProcessType process_type,
return true;
}
+void PopulateResourceResponse(URLRequest* request,
+ FilterPolicy::Type filter_policy,
+ ResourceResponse* response) {
+ response->response_head.status = request->status();
+ response->response_head.request_time = request->request_time();
+ response->response_head.response_time = request->response_time();
+ response->response_head.headers = request->response_headers();
+ request->GetCharset(&response->response_head.charset);
+ response->response_head.filter_policy = filter_policy;
+ response->response_head.content_length = request->GetExpectedContentSize();
+ response->response_head.app_cache_id = WebAppCacheContext::kNoAppCacheId;
+ request->GetMimeType(&response->response_head.mime_type);
+}
+
} // namespace
ResourceDispatcherHost::ResourceDispatcherHost(MessageLoop* io_loop)
@@ -328,6 +342,7 @@ bool ResourceDispatcherHost::OnMessageReceived(const IPC::Message& message,
IPC_MESSAGE_HANDLER(ViewHostMsg_DataReceived_ACK, OnDataReceivedACK)
IPC_MESSAGE_HANDLER(ViewHostMsg_UploadProgress_ACK, OnUploadProgressACK)
IPC_MESSAGE_HANDLER(ViewHostMsg_CancelRequest, OnCancelRequest)
+ IPC_MESSAGE_HANDLER(ViewHostMsg_FollowRedirect, OnFollowRedirect)
IPC_MESSAGE_HANDLER(ViewHostMsg_ClosePage_ACK, OnClosePageACK)
IPC_END_MESSAGE_MAP_EX()
@@ -571,6 +586,10 @@ void ResourceDispatcherHost::OnCancelRequest(int request_id) {
CancelRequest(receiver_->GetProcessId(), request_id, true, true);
}
+void ResourceDispatcherHost::OnFollowRedirect(int request_id) {
+ FollowDeferredRedirect(receiver_->GetProcessId(), request_id);
+}
+
void ResourceDispatcherHost::OnClosePageACK(
const ViewMsg_ClosePage_Params& params) {
if (params.for_cross_site_transition) {
@@ -731,47 +750,16 @@ void ResourceDispatcherHost::CancelRequest(int process_id,
CancelRequest(process_id, request_id, from_renderer, true);
}
-void ResourceDispatcherHost::CancelRequest(int process_id,
- int request_id,
- bool from_renderer,
- bool allow_delete) {
+void ResourceDispatcherHost::FollowDeferredRedirect(int process_id,
+ int request_id) {
PendingRequestList::iterator i = pending_requests_.find(
GlobalRequestID(process_id, request_id));
if (i == pending_requests_.end()) {
- // We probably want to remove this warning eventually, but I wanted to be
- // able to notice when this happens during initial development since it
- // should be rare and may indicate a bug.
- DLOG(WARNING) << "Canceling a request that wasn't found";
+ DLOG(WARNING) << "FollowDeferredRedirect for invalid request";
return;
}
- // WebKit will send us a cancel for downloads since it no longer handles them.
- // In this case, ignore the cancel since we handle downloads in the browser.
- ExtraRequestInfo* info = ExtraInfoForRequest(i->second);
- if (!from_renderer || !info->is_download) {
- if (info->login_handler) {
- info->login_handler->OnRequestCancelled();
- info->login_handler = NULL;
- }
- if (info->ssl_client_auth_handler) {
- info->ssl_client_auth_handler->OnRequestCancelled();
- info->ssl_client_auth_handler = NULL;
- }
- if (!i->second->is_pending() && allow_delete) {
- // No io is pending, canceling the request won't notify us of anything,
- // so we explicitly remove it.
- // TODO(sky): removing the request in this manner means we're not
- // notifying anyone. We need make sure the event handlers and others are
- // notified so that everything is cleaned up properly.
- RemovePendingRequest(info->process_id, info->request_id);
- } else {
- i->second->Cancel();
- }
- }
-
- // Do not remove from the pending requests, as the request will still
- // call AllDataReceived, and may even have more data before it does
- // that.
+ i->second->FollowDeferredRedirect();
}
bool ResourceDispatcherHost::WillSendData(int process_id,
@@ -779,7 +767,7 @@ bool ResourceDispatcherHost::WillSendData(int process_id,
PendingRequestList::iterator i = pending_requests_.find(
GlobalRequestID(process_id, request_id));
if (i == pending_requests_.end()) {
- NOTREACHED() << L"WillSendData for invalid request";
+ NOTREACHED() << "WillSendData for invalid request";
return false;
}
@@ -968,7 +956,10 @@ void ResourceDispatcherHost::OnReceivedRedirect(URLRequest* request,
return;
}
- if (!info->resource_handler->OnRequestRedirected(info->request_id, new_url))
+ scoped_refptr<ResourceResponse> response = new ResourceResponse;
+ PopulateResourceResponse(request, info->filter_policy, response);
+ if (!info->resource_handler->OnRequestRedirected(info->request_id, new_url,
+ response, defer_redirect))
CancelRequest(info->process_id, info->request_id, false);
}
@@ -1050,17 +1041,8 @@ void ResourceDispatcherHost::OnResponseStarted(URLRequest* request) {
bool ResourceDispatcherHost::CompleteResponseStarted(URLRequest* request) {
ExtraRequestInfo* info = ExtraInfoForRequest(request);
- scoped_refptr<ResourceResponse> response(new ResourceResponse);
-
- response->response_head.status = request->status();
- response->response_head.request_time = request->request_time();
- response->response_head.response_time = request->response_time();
- response->response_head.headers = request->response_headers();
- request->GetCharset(&response->response_head.charset);
- response->response_head.filter_policy = info->filter_policy;
- response->response_head.content_length = request->GetExpectedContentSize();
- response->response_head.app_cache_id = WebAppCacheContext::kNoAppCacheId;
- request->GetMimeType(&response->response_head.mime_type);
+ scoped_refptr<ResourceResponse> response = new ResourceResponse;
+ PopulateResourceResponse(request, info->filter_policy, response);
const URLRequest::UserData* d =
request->GetUserData(&Blacklist::kRequestDataKey);
@@ -1093,6 +1075,49 @@ bool ResourceDispatcherHost::CompleteResponseStarted(URLRequest* request) {
response.get());
}
+void ResourceDispatcherHost::CancelRequest(int process_id,
+ int request_id,
+ bool from_renderer,
+ bool allow_delete) {
+ PendingRequestList::iterator i = pending_requests_.find(
+ GlobalRequestID(process_id, request_id));
+ if (i == pending_requests_.end()) {
+ // We probably want to remove this warning eventually, but I wanted to be
+ // able to notice when this happens during initial development since it
+ // should be rare and may indicate a bug.
+ DLOG(WARNING) << "Canceling a request that wasn't found";
+ return;
+ }
+
+ // WebKit will send us a cancel for downloads since it no longer handles them.
+ // In this case, ignore the cancel since we handle downloads in the browser.
+ ExtraRequestInfo* info = ExtraInfoForRequest(i->second);
+ if (!from_renderer || !info->is_download) {
+ if (info->login_handler) {
+ info->login_handler->OnRequestCancelled();
+ info->login_handler = NULL;
+ }
+ if (info->ssl_client_auth_handler) {
+ info->ssl_client_auth_handler->OnRequestCancelled();
+ info->ssl_client_auth_handler = NULL;
+ }
+ if (!i->second->is_pending() && allow_delete) {
+ // No io is pending, canceling the request won't notify us of anything,
+ // so we explicitly remove it.
+ // TODO(sky): removing the request in this manner means we're not
+ // notifying anyone. We need make sure the event handlers and others are
+ // notified so that everything is cleaned up properly.
+ RemovePendingRequest(info->process_id, info->request_id);
+ } else {
+ i->second->Cancel();
+ }
+ }
+
+ // Do not remove from the pending requests, as the request will still
+ // call AllDataReceived, and may even have more data before it does
+ // that.
+}
+
int ResourceDispatcherHost::IncrementOutstandingRequestsMemoryCost(
int cost, int process_id) {
// Retrieve the previous value (defaulting to 0 if not found).
@@ -1675,6 +1700,7 @@ bool ResourceDispatcherHost::IsResourceDispatcherHostMessage(
switch (message.type()) {
case ViewHostMsg_RequestResource::ID:
case ViewHostMsg_CancelRequest::ID:
+ case ViewHostMsg_FollowRedirect::ID:
case ViewHostMsg_ClosePage_ACK::ID:
case ViewHostMsg_DataReceived_ACK::ID:
case ViewHostMsg_DownloadProgress_ACK::ID: