summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/browser')
-rw-r--r--chrome/browser/automation/automation_provider.cc6
-rw-r--r--chrome/browser/automation/automation_provider.h1
-rw-r--r--chrome/browser/automation/automation_resource_message_filter.cc28
-rw-r--r--chrome/browser/automation/automation_resource_message_filter.h3
-rw-r--r--chrome/browser/net/url_request_mock_http_job.cc23
-rw-r--r--chrome/browser/net/url_request_mock_http_job.h1
-rw-r--r--chrome/browser/net/url_request_mock_util.cc57
-rw-r--r--chrome/browser/renderer_host/async_resource_handler.cc10
-rw-r--r--chrome/browser/renderer_host/async_resource_handler.h3
-rw-r--r--chrome/browser/renderer_host/buffered_resource_handler.cc7
-rw-r--r--chrome/browser/renderer_host/buffered_resource_handler.h3
-rw-r--r--chrome/browser/renderer_host/cross_site_resource_handler.cc7
-rw-r--r--chrome/browser/renderer_host/cross_site_resource_handler.h3
-rw-r--r--chrome/browser/renderer_host/download_resource_handler.cc4
-rw-r--r--chrome/browser/renderer_host/download_resource_handler.h3
-rw-r--r--chrome/browser/renderer_host/download_throttling_resource_handler.cc13
-rw-r--r--chrome/browser/renderer_host/download_throttling_resource_handler.h3
-rw-r--r--chrome/browser/renderer_host/resource_dispatcher_host.cc122
-rw-r--r--chrome/browser/renderer_host/resource_dispatcher_host.h5
-rw-r--r--chrome/browser/renderer_host/resource_dispatcher_host_uitest.cc17
-rw-r--r--chrome/browser/renderer_host/resource_handler.h8
-rw-r--r--chrome/browser/renderer_host/safe_browsing_resource_handler.cc10
-rw-r--r--chrome/browser/renderer_host/safe_browsing_resource_handler.h3
-rw-r--r--chrome/browser/renderer_host/save_file_resource_handler.cc4
-rw-r--r--chrome/browser/renderer_host/save_file_resource_handler.h3
-rw-r--r--chrome/browser/renderer_host/sync_resource_handler.cc11
-rw-r--r--chrome/browser/renderer_host/sync_resource_handler.h3
27 files changed, 226 insertions, 135 deletions
diff --git a/chrome/browser/automation/automation_provider.cc b/chrome/browser/automation/automation_provider.cc
index 3330b7d..67ee526 100644
--- a/chrome/browser/automation/automation_provider.cc
+++ b/chrome/browser/automation/automation_provider.cc
@@ -977,7 +977,6 @@ void AutomationProvider::OnMessageReceived(const IPC::Message& message) {
IPC_MESSAGE_HANDLER(AutomationMsg_GetFocusedViewID, GetFocusedViewID)
IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_InspectElement,
HandleInspectElementRequest)
- IPC_MESSAGE_HANDLER(AutomationMsg_SetFilteredInet, SetFilteredInet)
IPC_MESSAGE_HANDLER(AutomationMsg_DownloadDirectory, GetDownloadDirectory)
IPC_MESSAGE_HANDLER(AutomationMsg_SetProxyConfig, SetProxyConfig);
IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_OpenNewBrowserWindow,
@@ -2107,11 +2106,6 @@ void AutomationProvider::ReceivedInspectElementResponse(int num_resources) {
}
}
-void AutomationProvider::SetFilteredInet(const IPC::Message& message,
- bool enabled) {
- chrome_browser_net::SetUrlRequestMocksEnabled(enabled);
-}
-
class SetProxyConfigTask : public Task {
public:
explicit SetProxyConfigTask(net::ProxyService* proxy_service,
diff --git a/chrome/browser/automation/automation_provider.h b/chrome/browser/automation/automation_provider.h
index 1c92be6..0d9b08c 100644
--- a/chrome/browser/automation/automation_provider.h
+++ b/chrome/browser/automation/automation_provider.h
@@ -217,6 +217,7 @@ class AutomationProvider : public base::RefCounted<AutomationProvider>,
void GetShelfVisibility(int handle, bool* visible);
void SetShelfVisibility(int handle, bool visible);
void SetFilteredInet(const IPC::Message& message, bool enabled);
+ void GetFilteredInetHitCount(int* hit_count);
void SetProxyConfig(const std::string& new_proxy_config);
#if defined(OS_WIN)
diff --git a/chrome/browser/automation/automation_resource_message_filter.cc b/chrome/browser/automation/automation_resource_message_filter.cc
index 15e5325..46ee1e8 100644
--- a/chrome/browser/automation/automation_resource_message_filter.cc
+++ b/chrome/browser/automation/automation_resource_message_filter.cc
@@ -5,7 +5,16 @@
#include "chrome/browser/automation/automation_resource_message_filter.h"
#include "base/message_loop.h"
+#include "base/path_service.h"
#include "chrome/browser/automation/url_request_automation_job.h"
+#include "chrome/browser/net/url_request_failed_dns_job.h"
+#include "chrome/browser/net/url_request_mock_http_job.h"
+#include "chrome/browser/net/url_request_mock_util.h"
+#include "chrome/browser/net/url_request_slow_download_job.h"
+#include "chrome/browser/net/url_request_slow_http_job.h"
+#include "chrome/common/chrome_paths.h"
+#include "chrome/test/automation/automation_messages.h"
+#include "net/url_request/url_request_filter.h"
MessageLoop* AutomationResourceMessageFilter::io_loop_ = NULL;
@@ -54,7 +63,16 @@ bool AutomationResourceMessageFilter::OnMessageReceived(
}
}
- return false;
+ bool handled = true;
+ IPC_BEGIN_MESSAGE_MAP(AutomationResourceMessageFilter, message)
+ IPC_MESSAGE_HANDLER(AutomationMsg_SetFilteredInet,
+ OnSetFilteredInet)
+ IPC_MESSAGE_HANDLER(AutomationMsg_GetFilteredInetHitCount,
+ OnGetFilteredInetHitCount)
+ IPC_MESSAGE_UNHANDLED(handled = false)
+ IPC_END_MESSAGE_MAP()
+
+ return handled;
}
// Called on the IPC thread:
@@ -142,3 +160,11 @@ bool AutomationResourceMessageFilter::LookupRegisteredRenderView(
return found;
}
+void AutomationResourceMessageFilter::OnSetFilteredInet(bool enable) {
+ chrome_browser_net::SetUrlRequestMocksEnabled(enable);
+}
+
+void AutomationResourceMessageFilter::OnGetFilteredInetHitCount(
+ int* hit_count) {
+ *hit_count = URLRequestFilter::GetInstance()->hit_count();
+}
diff --git a/chrome/browser/automation/automation_resource_message_filter.h b/chrome/browser/automation/automation_resource_message_filter.h
index 240bafb..ebd6464 100644
--- a/chrome/browser/automation/automation_resource_message_filter.h
+++ b/chrome/browser/automation/automation_resource_message_filter.h
@@ -72,6 +72,9 @@ class AutomationResourceMessageFilter
static void UnRegisterRenderViewInIOThread(int renderer_pid, int renderer_id);
private:
+ void OnSetFilteredInet(bool enable);
+ void OnGetFilteredInetHitCount(int* hit_count);
+
// A unique renderer id is a combination of renderer process id and
// it's routing id.
struct RendererId {
diff --git a/chrome/browser/net/url_request_mock_http_job.cc b/chrome/browser/net/url_request_mock_http_job.cc
index fc654be..7e0cd71 100644
--- a/chrome/browser/net/url_request_mock_http_job.cc
+++ b/chrome/browser/net/url_request_mock_http_job.cc
@@ -46,21 +46,13 @@ GURL URLRequestMockHTTPJob::GetMockUrl(const std::wstring& path) {
FilePath URLRequestMockHTTPJob::GetOnDiskPath(const std::wstring& base_path,
URLRequest* request,
const std::string& scheme) {
- std::wstring file_url(L"file:///");
- file_url += base_path;
- const std::string& url = request->url().spec();
- // Fix up the url to be the file url we're loading from disk.
- std::string host_prefix("http://");
- host_prefix.append(kMockHostname);
- size_t host_prefix_len = host_prefix.length();
- if (url.compare(0, host_prefix_len, host_prefix.data(),
- host_prefix_len) == 0) {
- file_url += UTF8ToWide(url.substr(host_prefix_len));
- }
+ std::string file_url("file:///");
+ file_url += WideToUTF8(base_path);
+ file_url += request->url().path();
// Convert the file:/// URL to a path on disk.
FilePath file_path;
- net::FileURLToFilePath(GURL(WideToUTF8(file_url)), &file_path);
+ net::FileURLToFilePath(GURL(file_url), &file_path);
return file_path;
}
@@ -74,6 +66,13 @@ void URLRequestMockHTTPJob::GetResponseInfo(net::HttpResponseInfo* info) {
GetResponseInfoConst(info);
}
+bool URLRequestMockHTTPJob::IsRedirectResponse(GURL* location,
+ int* http_status_code) {
+ // Override the URLRequestFileJob implementation to invoke the default one
+ // based on HttpResponseInfo.
+ return URLRequestJob::IsRedirectResponse(location, http_status_code);
+}
+
// Private const version.
void URLRequestMockHTTPJob::GetResponseInfoConst(
net::HttpResponseInfo* info) const {
diff --git a/chrome/browser/net/url_request_mock_http_job.h b/chrome/browser/net/url_request_mock_http_job.h
index 36e6acb..92cc359 100644
--- a/chrome/browser/net/url_request_mock_http_job.h
+++ b/chrome/browser/net/url_request_mock_http_job.h
@@ -19,6 +19,7 @@ class URLRequestMockHTTPJob : public URLRequestFileJob {
virtual bool GetMimeType(std::string* mime_type) const;
virtual bool GetCharset(std::string* charset);
virtual void GetResponseInfo(net::HttpResponseInfo* info);
+ virtual bool IsRedirectResponse(GURL* location, int* http_status_code);
static URLRequest::ProtocolFactory Factory;
diff --git a/chrome/browser/net/url_request_mock_util.cc b/chrome/browser/net/url_request_mock_util.cc
index ad0ed09..9a559b1 100644
--- a/chrome/browser/net/url_request_mock_util.cc
+++ b/chrome/browser/net/url_request_mock_util.cc
@@ -6,11 +6,8 @@
#include <string>
-#include "base/message_loop.h"
#include "base/path_service.h"
-#include "base/task.h"
-#include "base/thread.h"
-#include "chrome/browser/browser_process.h"
+#include "chrome/browser/chrome_thread.h"
#include "chrome/browser/net/url_request_failed_dns_job.h"
#include "chrome/browser/net/url_request_mock_http_job.h"
#include "chrome/browser/net/url_request_slow_download_job.h"
@@ -18,47 +15,27 @@
#include "chrome/common/chrome_paths.h"
#include "net/url_request/url_request_filter.h"
-namespace {
+namespace chrome_browser_net {
-// Helper class for making changes to the URLRequest ProtocolFactory on the
-// IO thread.
-class SetUrlRequestMocksEnabledTask : public Task {
- public:
- explicit SetUrlRequestMocksEnabledTask(bool enabled) : enabled_(enabled) {
- }
+void SetUrlRequestMocksEnabled(bool enabled) {
+ // Since this involves changing the URLRequest ProtocolFactory, we need to
+ // run on the IO thread.
+ DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
- virtual void Run() {
- if (enabled_) {
- URLRequestFilter::GetInstance()->ClearHandlers();
+ if (enabled) {
+ URLRequestFilter::GetInstance()->ClearHandlers();
- URLRequestFailedDnsJob::AddUrlHandler();
- URLRequestSlowDownloadJob::AddUrlHandler();
+ URLRequestFailedDnsJob::AddUrlHandler();
+ URLRequestSlowDownloadJob::AddUrlHandler();
- std::wstring root_http;
- PathService::Get(chrome::DIR_TEST_DATA, &root_http);
- URLRequestMockHTTPJob::AddUrlHandler(root_http);
- URLRequestSlowHTTPJob::AddUrlHandler(root_http);
- } else {
- // Revert to the default handlers.
- URLRequestFilter::GetInstance()->ClearHandlers();
- }
+ std::wstring root_http;
+ PathService::Get(chrome::DIR_TEST_DATA, &root_http);
+ URLRequestMockHTTPJob::AddUrlHandler(root_http);
+ URLRequestSlowHTTPJob::AddUrlHandler(root_http);
+ } else {
+ // Revert to the default handlers.
+ URLRequestFilter::GetInstance()->ClearHandlers();
}
-
- private:
- bool enabled_;
-
- DISALLOW_COPY_AND_ASSIGN(SetUrlRequestMocksEnabledTask);
-};
-
-} // namespace
-
-namespace chrome_browser_net {
-
-void SetUrlRequestMocksEnabled(bool enabled) {
- // Since this involves changing the URLRequest ProtocolFactory, we want to
- // run on the IO thread.
- g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE,
- new SetUrlRequestMocksEnabledTask(enabled));
}
} // namespace chrome_browser_net
diff --git a/chrome/browser/renderer_host/async_resource_handler.cc b/chrome/browser/renderer_host/async_resource_handler.cc
index 6b69db3..dfd1f56 100644
--- a/chrome/browser/renderer_host/async_resource_handler.cc
+++ b/chrome/browser/renderer_host/async_resource_handler.cc
@@ -62,10 +62,12 @@ bool AsyncResourceHandler::OnUploadProgress(int request_id,
}
bool AsyncResourceHandler::OnRequestRedirected(int request_id,
- const GURL& new_url) {
- return receiver_->Send(new ViewMsg_Resource_ReceivedRedirect(routing_id_,
- request_id,
- new_url));
+ const GURL& new_url,
+ ResourceResponse* response,
+ bool* defer) {
+ *defer = true;
+ return receiver_->Send(new ViewMsg_Resource_ReceivedRedirect(
+ routing_id_, request_id, new_url, response->response_head));
}
bool AsyncResourceHandler::OnResponseStarted(int request_id,
diff --git a/chrome/browser/renderer_host/async_resource_handler.h b/chrome/browser/renderer_host/async_resource_handler.h
index 89ecfad..17e9260 100644
--- a/chrome/browser/renderer_host/async_resource_handler.h
+++ b/chrome/browser/renderer_host/async_resource_handler.h
@@ -26,7 +26,8 @@ class AsyncResourceHandler : public ResourceHandler {
// ResourceHandler implementation:
bool OnUploadProgress(int request_id, uint64 position, uint64 size);
- bool OnRequestRedirected(int request_id, const GURL& new_url);
+ bool OnRequestRedirected(int request_id, const GURL& new_url,
+ ResourceResponse* response, bool* defer);
bool OnResponseStarted(int request_id, ResourceResponse* response);
bool OnWillRead(int request_id, net::IOBuffer** buf, int* buf_size,
int min_size);
diff --git a/chrome/browser/renderer_host/buffered_resource_handler.cc b/chrome/browser/renderer_host/buffered_resource_handler.cc
index 8d0f17f..b1007fe 100644
--- a/chrome/browser/renderer_host/buffered_resource_handler.cc
+++ b/chrome/browser/renderer_host/buffered_resource_handler.cc
@@ -60,8 +60,11 @@ bool BufferedResourceHandler::OnUploadProgress(int request_id,
}
bool BufferedResourceHandler::OnRequestRedirected(int request_id,
- const GURL& new_url) {
- return real_handler_->OnRequestRedirected(request_id, new_url);
+ const GURL& new_url,
+ ResourceResponse* response,
+ bool* defer) {
+ return real_handler_->OnRequestRedirected(
+ request_id, new_url, response, defer);
}
bool BufferedResourceHandler::OnResponseStarted(int request_id,
diff --git a/chrome/browser/renderer_host/buffered_resource_handler.h b/chrome/browser/renderer_host/buffered_resource_handler.h
index e553aca..3799b99 100644
--- a/chrome/browser/renderer_host/buffered_resource_handler.h
+++ b/chrome/browser/renderer_host/buffered_resource_handler.h
@@ -21,7 +21,8 @@ class BufferedResourceHandler : public ResourceHandler {
// ResourceHandler implementation:
bool OnUploadProgress(int request_id, uint64 position, uint64 size);
- bool OnRequestRedirected(int request_id, const GURL& new_url);
+ bool OnRequestRedirected(int request_id, const GURL& new_url,
+ ResourceResponse* response, bool* defer);
bool OnResponseStarted(int request_id, ResourceResponse* response);
bool OnWillRead(int request_id, net::IOBuffer** buf, int* buf_size,
int min_size);
diff --git a/chrome/browser/renderer_host/cross_site_resource_handler.cc b/chrome/browser/renderer_host/cross_site_resource_handler.cc
index 7b05a72..eb688e7 100644
--- a/chrome/browser/renderer_host/cross_site_resource_handler.cc
+++ b/chrome/browser/renderer_host/cross_site_resource_handler.cc
@@ -84,10 +84,13 @@ CrossSiteResourceHandler::CrossSiteResourceHandler(
rdh_(resource_dispatcher_host) {}
bool CrossSiteResourceHandler::OnRequestRedirected(int request_id,
- const GURL& new_url) {
+ const GURL& new_url,
+ ResourceResponse* response,
+ bool* defer) {
// We should not have started the transition before being redirected.
DCHECK(!in_cross_site_transition_);
- return next_handler_->OnRequestRedirected(request_id, new_url);
+ return next_handler_->OnRequestRedirected(
+ request_id, new_url, response, defer);
}
bool CrossSiteResourceHandler::OnResponseStarted(int request_id,
diff --git a/chrome/browser/renderer_host/cross_site_resource_handler.h b/chrome/browser/renderer_host/cross_site_resource_handler.h
index b741aa0..b50e641 100644
--- a/chrome/browser/renderer_host/cross_site_resource_handler.h
+++ b/chrome/browser/renderer_host/cross_site_resource_handler.h
@@ -21,7 +21,8 @@ class CrossSiteResourceHandler : public ResourceHandler {
ResourceDispatcherHost* resource_dispatcher_host);
// ResourceHandler implementation:
- bool OnRequestRedirected(int request_id, const GURL& new_url);
+ bool OnRequestRedirected(int request_id, const GURL& new_url,
+ ResourceResponse* response, bool* defer);
bool OnResponseStarted(int request_id,
ResourceResponse* response);
bool OnWillRead(int request_id, net::IOBuffer** buf, int* buf_size,
diff --git a/chrome/browser/renderer_host/download_resource_handler.cc b/chrome/browser/renderer_host/download_resource_handler.cc
index 6661666..8b189bf 100644
--- a/chrome/browser/renderer_host/download_resource_handler.cc
+++ b/chrome/browser/renderer_host/download_resource_handler.cc
@@ -35,7 +35,9 @@ DownloadResourceHandler::DownloadResourceHandler(ResourceDispatcherHost* rdh,
// Not needed, as this event handler ought to be the final resource.
bool DownloadResourceHandler::OnRequestRedirected(int request_id,
- const GURL& url) {
+ const GURL& url,
+ ResourceResponse* response,
+ bool* defer) {
url_ = url;
return true;
}
diff --git a/chrome/browser/renderer_host/download_resource_handler.h b/chrome/browser/renderer_host/download_resource_handler.h
index d9afa42..e4613a8 100644
--- a/chrome/browser/renderer_host/download_resource_handler.h
+++ b/chrome/browser/renderer_host/download_resource_handler.h
@@ -25,7 +25,8 @@ class DownloadResourceHandler : public ResourceHandler {
bool save_as);
// Not needed, as this event handler ought to be the final resource.
- bool OnRequestRedirected(int request_id, const GURL& url);
+ bool OnRequestRedirected(int request_id, const GURL& url,
+ ResourceResponse* response, bool* defer);
// Send the download creation information to the download thread.
bool OnResponseStarted(int request_id, ResourceResponse* response);
diff --git a/chrome/browser/renderer_host/download_throttling_resource_handler.cc b/chrome/browser/renderer_host/download_throttling_resource_handler.cc
index f3ad5bb..ee286db 100644
--- a/chrome/browser/renderer_host/download_throttling_resource_handler.cc
+++ b/chrome/browser/renderer_host/download_throttling_resource_handler.cc
@@ -41,10 +41,15 @@ bool DownloadThrottlingResourceHandler::OnUploadProgress(int request_id,
return true;
}
-bool DownloadThrottlingResourceHandler::OnRequestRedirected(int request_id,
- const GURL& url) {
- if (download_handler_.get())
- return download_handler_->OnRequestRedirected(request_id, url);
+bool DownloadThrottlingResourceHandler::OnRequestRedirected(
+ int request_id,
+ const GURL& url,
+ ResourceResponse* response,
+ bool* defer) {
+ if (download_handler_.get()) {
+ return download_handler_->OnRequestRedirected(
+ request_id, url, response, defer);
+ }
url_ = url;
return true;
}
diff --git a/chrome/browser/renderer_host/download_throttling_resource_handler.h b/chrome/browser/renderer_host/download_throttling_resource_handler.h
index 5a2eea9..117b3d2 100644
--- a/chrome/browser/renderer_host/download_throttling_resource_handler.h
+++ b/chrome/browser/renderer_host/download_throttling_resource_handler.h
@@ -40,7 +40,8 @@ class DownloadThrottlingResourceHandler
virtual bool OnUploadProgress(int request_id,
uint64 position,
uint64 size);
- virtual bool OnRequestRedirected(int request_id, const GURL& url);
+ virtual bool OnRequestRedirected(int request_id, const GURL& url,
+ ResourceResponse* response, bool* defer);
virtual bool OnResponseStarted(int request_id, ResourceResponse* response);
virtual bool OnWillRead(int request_id, net::IOBuffer** buf, int* buf_size,
int min_size);
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:
diff --git a/chrome/browser/renderer_host/resource_dispatcher_host.h b/chrome/browser/renderer_host/resource_dispatcher_host.h
index b75d408..5353562 100644
--- a/chrome/browser/renderer_host/resource_dispatcher_host.h
+++ b/chrome/browser/renderer_host/resource_dispatcher_host.h
@@ -250,6 +250,10 @@ class ResourceDispatcherHost : public URLRequest::Delegate {
int request_id,
bool from_renderer);
+ // Follows a deferred redirect for the given request.
+ void FollowDeferredRedirect(int process_id,
+ int request_id);
+
// Returns true if it's ok to send the data. If there are already too many
// data messages pending, it pauses the request and returns false. In this
// case the caller should not send the data.
@@ -503,6 +507,7 @@ class ResourceDispatcherHost : public URLRequest::Delegate {
void OnDataReceivedACK(int request_id);
void OnUploadProgressACK(int request_id);
void OnCancelRequest(int request_id);
+ void OnFollowRedirect(int request_id);
// Returns true if the message passed in is a resource related message.
static bool IsResourceDispatcherHostMessage(const IPC::Message&);
diff --git a/chrome/browser/renderer_host/resource_dispatcher_host_uitest.cc b/chrome/browser/renderer_host/resource_dispatcher_host_uitest.cc
index c13d3c2..d8654fd 100644
--- a/chrome/browser/renderer_host/resource_dispatcher_host_uitest.cc
+++ b/chrome/browser/renderer_host/resource_dispatcher_host_uitest.cc
@@ -314,4 +314,21 @@ TEST_F(ResourceDispatcherTest, CrossSiteNavigationErrorPage) {
EXPECT_EQ(L"Title Of Awesomeness", tab_title);
}
+TEST_F(ResourceDispatcherTest, CrossOriginRedirectBlocked) {
+ int before = automation()->GetFilteredInetHitCount();
+ CheckTitleTest(L"cross-origin-redirect-blocked.html",
+ L"done");
+ int after = automation()->GetFilteredInetHitCount();
+ //
+ // We expect the following URL requests from this test:
+ // 1- http://mock.http/cross-origin-redirect-blocked.html
+ // 2- http://mock.http/redirect-to-title2.html
+ // 3- http://mock.http/title2.html
+ //
+ // If the redirect in #2 were not blocked, we'd also see a request
+ // for http://mock.http:4000/title2.html.
+ //
+ EXPECT_EQ(3, after - before);
+}
+
} // namespace
diff --git a/chrome/browser/renderer_host/resource_handler.h b/chrome/browser/renderer_host/resource_handler.h
index df1b8a6..76851b6 100644
--- a/chrome/browser/renderer_host/resource_handler.h
+++ b/chrome/browser/renderer_host/resource_handler.h
@@ -63,8 +63,12 @@ class ResourceHandler : public base::RefCounted<ResourceHandler> {
return true;
}
- // The request was redirected to a new URL.
- virtual bool OnRequestRedirected(int request_id, const GURL& url) = 0;
+ // The request was redirected to a new URL. |*defer| has an initial value of
+ // false. Set |*defer| to true to defer the redirect. The redirect may be
+ // followed later on via ResourceDispatcherHost::FollowDeferredRedirect.
+ virtual bool OnRequestRedirected(int request_id, const GURL& url,
+ ResourceResponse* response,
+ bool* defer) = 0;
// Response headers and meta data are available.
virtual bool OnResponseStarted(int request_id,
diff --git a/chrome/browser/renderer_host/safe_browsing_resource_handler.cc b/chrome/browser/renderer_host/safe_browsing_resource_handler.cc
index 0d2af57..c215262 100644
--- a/chrome/browser/renderer_host/safe_browsing_resource_handler.cc
+++ b/chrome/browser/renderer_host/safe_browsing_resource_handler.cc
@@ -56,8 +56,11 @@ bool SafeBrowsingResourceHandler::OnUploadProgress(int request_id,
return next_handler_->OnUploadProgress(request_id, position, size);
}
-bool SafeBrowsingResourceHandler::OnRequestRedirected(int request_id,
- const GURL& new_url) {
+bool SafeBrowsingResourceHandler::OnRequestRedirected(
+ int request_id,
+ const GURL& new_url,
+ ResourceResponse* response,
+ bool* defer) {
if (in_safe_browsing_check_) {
Release();
in_safe_browsing_check_ = false;
@@ -73,7 +76,8 @@ bool SafeBrowsingResourceHandler::OnRequestRedirected(int request_id,
// Can't pause now because it's too early, so we'll do it in OnWillRead.
}
- return next_handler_->OnRequestRedirected(request_id, new_url);
+ return next_handler_->OnRequestRedirected(
+ request_id, new_url, response, defer);
}
bool SafeBrowsingResourceHandler::OnResponseStarted(
diff --git a/chrome/browser/renderer_host/safe_browsing_resource_handler.h b/chrome/browser/renderer_host/safe_browsing_resource_handler.h
index 44018b1..e2901e8 100644
--- a/chrome/browser/renderer_host/safe_browsing_resource_handler.h
+++ b/chrome/browser/renderer_host/safe_browsing_resource_handler.h
@@ -30,7 +30,8 @@ class SafeBrowsingResourceHandler : public ResourceHandler,
// ResourceHandler implementation:
bool OnUploadProgress(int request_id, uint64 position, uint64 size);
- bool OnRequestRedirected(int request_id, const GURL& new_url);
+ bool OnRequestRedirected(int request_id, const GURL& new_url,
+ ResourceResponse* response, bool* defer);
bool OnResponseStarted(int request_id, ResourceResponse* response);
void OnGetHashTimeout();
bool OnWillRead(int request_id, net::IOBuffer** buf, int* buf_size,
diff --git a/chrome/browser/renderer_host/save_file_resource_handler.cc b/chrome/browser/renderer_host/save_file_resource_handler.cc
index 3289df1..22f3441 100644
--- a/chrome/browser/renderer_host/save_file_resource_handler.cc
+++ b/chrome/browser/renderer_host/save_file_resource_handler.cc
@@ -23,7 +23,9 @@ SaveFileResourceHandler::SaveFileResourceHandler(int render_process_host_id,
}
bool SaveFileResourceHandler::OnRequestRedirected(int request_id,
- const GURL& url) {
+ const GURL& url,
+ ResourceResponse* response,
+ bool* defer) {
final_url_ = url;
return true;
}
diff --git a/chrome/browser/renderer_host/save_file_resource_handler.h b/chrome/browser/renderer_host/save_file_resource_handler.h
index bc3548c..9a976b2 100644
--- a/chrome/browser/renderer_host/save_file_resource_handler.h
+++ b/chrome/browser/renderer_host/save_file_resource_handler.h
@@ -21,7 +21,8 @@ class SaveFileResourceHandler : public ResourceHandler {
// Saves the redirected URL to final_url_, we need to use the original
// URL to match original request.
- bool OnRequestRedirected(int request_id, const GURL& url);
+ bool OnRequestRedirected(int request_id, const GURL& url,
+ ResourceResponse* response, bool* defer);
// Sends the download creation information to the download thread.
bool OnResponseStarted(int request_id, ResourceResponse* response);
diff --git a/chrome/browser/renderer_host/sync_resource_handler.cc b/chrome/browser/renderer_host/sync_resource_handler.cc
index 01d0d8f..dd279a0 100644
--- a/chrome/browser/renderer_host/sync_resource_handler.cc
+++ b/chrome/browser/renderer_host/sync_resource_handler.cc
@@ -26,7 +26,16 @@ SyncResourceHandler::~SyncResourceHandler() {
}
bool SyncResourceHandler::OnRequestRedirected(int request_id,
- const GURL& new_url) {
+ const GURL& new_url,
+ ResourceResponse* response,
+ bool* defer) {
+ // TODO(darin): It would be much better if this could live in WebCore, but
+ // doing so requires API changes at all levels. Similar code exists in
+ // WebCore/platform/network/cf/ResourceHandleCFNet.cpp :-(
+ if (new_url.GetOrigin() != result_.final_url.GetOrigin()) {
+ LOG(ERROR) << "Cross origin redirect denied";
+ return false;
+ }
result_.final_url = new_url;
return true;
}
diff --git a/chrome/browser/renderer_host/sync_resource_handler.h b/chrome/browser/renderer_host/sync_resource_handler.h
index 8aa4681..615d7473 100644
--- a/chrome/browser/renderer_host/sync_resource_handler.h
+++ b/chrome/browser/renderer_host/sync_resource_handler.h
@@ -20,7 +20,8 @@ class SyncResourceHandler : public ResourceHandler {
IPC::Message* result_message);
~SyncResourceHandler();
- bool OnRequestRedirected(int request_id, const GURL& new_url);
+ bool OnRequestRedirected(int request_id, const GURL& new_url,
+ ResourceResponse* response, bool* defer);
bool OnResponseStarted(int request_id, ResourceResponse* response);
bool OnWillRead(int request_id, net::IOBuffer** buf, int* buf_size,
int min_size);