summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-06-21 18:48:12 +0000
committerjam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-06-21 18:48:12 +0000
commited425140a40a065214916fe306fb06841e1d2f85 (patch)
tree4144d5f8c7d0e88f355610fe7e2c62d5a7ec9580
parent453a17823de86dc75e39d0d24d271e953c9ffedb (diff)
downloadchromium_src-ed425140a40a065214916fe306fb06841e1d2f85.zip
chromium_src-ed425140a40a065214916fe306fb06841e1d2f85.tar.gz
chromium_src-ed425140a40a065214916fe306fb06841e1d2f85.tar.bz2
Fix a regression in sending the content settings data from r85247. The content settings needs to be sent on the IO thread, doing it on the UI thread introduces a race condition.
Review URL: http://codereview.chromium.org/7163008 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@89868 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/content_settings/content_settings_browsertest.cc25
-rw-r--r--chrome/browser/content_settings/tab_specific_content_settings.cc6
-rw-r--r--chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate.cc25
-rw-r--r--chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate.h12
-rw-r--r--chrome/test/data/redirect-cross-origin.html1
-rw-r--r--chrome/test/data/redirect-cross-origin.html.mock-http-headers2
-rw-r--r--content/browser/renderer_host/async_resource_handler.cc15
-rw-r--r--content/browser/renderer_host/async_resource_handler.h1
-rw-r--r--content/browser/renderer_host/resource_dispatcher_host.cc3
-rw-r--r--content/browser/renderer_host/resource_dispatcher_host_delegate.cc8
-rw-r--r--content/browser/renderer_host/resource_dispatcher_host_delegate.h13
-rw-r--r--content/browser/renderer_host/sync_resource_handler.cc4
12 files changed, 86 insertions, 29 deletions
diff --git a/chrome/browser/content_settings/content_settings_browsertest.cc b/chrome/browser/content_settings/content_settings_browsertest.cc
index 383dc7e..7f255ab 100644
--- a/chrome/browser/content_settings/content_settings_browsertest.cc
+++ b/chrome/browser/content_settings/content_settings_browsertest.cc
@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "base/stringprintf.h"
#include "base/utf_string_conversions.h"
#include "chrome/browser/content_settings/host_content_settings_map.h"
#include "chrome/browser/content_settings/tab_specific_content_settings.h"
@@ -45,3 +46,27 @@ IN_PROC_BROWSER_TEST_F(InProcessBrowserTest, ContentSettingsBlockDataURLs) {
EXPECT_TRUE(tab_contents->content_settings()->IsContentBlocked(
CONTENT_SETTINGS_TYPE_JAVASCRIPT));
}
+
+// Tests that if redirect across origins occurs, the new process still gets the
+// content settings before the resource headers.
+IN_PROC_BROWSER_TEST_F(InProcessBrowserTest, RedirectCrossOrigin) {
+ ASSERT_TRUE(test_server()->Start());
+
+ net::HostPortPair host_port = test_server()->host_port_pair();
+ DCHECK_EQ(host_port.host(), std::string("127.0.0.1"));
+
+ std::string redirect(base::StringPrintf(
+ "http://localhost:%d/files/redirect-cross-origin.html",
+ host_port.port()));
+ GURL test_url = test_server()->GetURL("server-redirect?" + redirect);
+
+ browser()->profile()->GetHostContentSettingsMap()->SetDefaultContentSetting(
+ CONTENT_SETTINGS_TYPE_COOKIES, CONTENT_SETTING_BLOCK);
+
+ ui_test_utils::NavigateToURL(browser(), test_url);
+
+ TabContentsWrapper* tab_contents = browser()->GetSelectedTabContentsWrapper();
+
+ EXPECT_TRUE(tab_contents->content_settings()->IsContentBlocked(
+ CONTENT_SETTINGS_TYPE_COOKIES));
+}
diff --git a/chrome/browser/content_settings/tab_specific_content_settings.cc b/chrome/browser/content_settings/tab_specific_content_settings.cc
index 59303e2..599f781 100644
--- a/chrome/browser/content_settings/tab_specific_content_settings.cc
+++ b/chrome/browser/content_settings/tab_specific_content_settings.cc
@@ -453,12 +453,6 @@ void TabSpecificContentSettings::DidStartProvisionalLoadForFrame(
if (!is_error_page)
ClearCookieSpecificContentSettings();
ClearGeolocationContentSettings();
-
- HostContentSettingsMap* map =
- tab_contents()->profile()->GetHostContentSettingsMap();
- render_view_host->Send(new ViewMsg_SetContentSettingsForLoadingURL(
- render_view_host->routing_id(), validated_url,
- map->GetContentSettings(validated_url, validated_url)));
}
void TabSpecificContentSettings::Observe(NotificationType type,
diff --git a/chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate.cc b/chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate.cc
index d047bb5..5bc48c2 100644
--- a/chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate.cc
+++ b/chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate.cc
@@ -6,18 +6,22 @@
#include "base/logging.h"
#include "chrome/browser/browser_process.h"
+#include "chrome/browser/content_settings/host_content_settings_map.h"
#include "chrome/browser/external_protocol/external_protocol_handler.h"
#include "chrome/browser/net/load_timing_observer.h"
#include "chrome/browser/prerender/prerender_manager.h"
#include "chrome/browser/prerender/prerender_tracker.h"
+#include "chrome/browser/profiles/profile_io_data.h"
#include "chrome/browser/renderer_host/safe_browsing_resource_handler.h"
#include "chrome/browser/safe_browsing/safe_browsing_service.h"
#include "chrome/browser/ui/login/login_prompt.h"
#include "chrome/common/extensions/user_script.h"
+#include "chrome/common/render_messages.h"
#include "content/browser/browser_thread.h"
#include "content/browser/resource_context.h"
#include "content/browser/renderer_host/resource_dispatcher_host.h"
#include "content/browser/renderer_host/resource_dispatcher_host_request_info.h"
+#include "content/browser/renderer_host/resource_message_filter.h"
#include "content/common/resource_messages.h"
#include "net/base/load_flags.h"
@@ -200,11 +204,28 @@ bool ChromeResourceDispatcherHostDelegate::ShouldForceDownloadResource(
}
void ChromeResourceDispatcherHostDelegate::OnResponseStarted(
- net::URLRequest* request, ResourceResponse* response) {
+ net::URLRequest* request,
+ ResourceResponse* response,
+ ResourceMessageFilter* filter) {
LoadTimingObserver::PopulateTimingInfo(request, response);
+
+ // We must send the content settings for the URL before sending response
+ // headers to the renderer.
+ const content::ResourceContext& resource_context = filter->resource_context();
+ ProfileIOData* io_data =
+ reinterpret_cast<ProfileIOData*>(resource_context.GetUserData(NULL));
+ HostContentSettingsMap* map = io_data->GetHostContentSettingsMap();
+
+ ResourceDispatcherHostRequestInfo* info =
+ resource_dispatcher_host_->InfoForRequest(request);
+ filter->Send(new ViewMsg_SetContentSettingsForLoadingURL(
+ info->route_id(), request->url(),
+ map->GetContentSettings(request->url(), request->url())));
}
void ChromeResourceDispatcherHostDelegate::OnRequestRedirected(
- net::URLRequest* request, ResourceResponse* response) {
+ net::URLRequest* request,
+ ResourceResponse* response,
+ ResourceMessageFilter* filter) {
LoadTimingObserver::PopulateTimingInfo(request, response);
}
diff --git a/chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate.h b/chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate.h
index fc0f9a0..97dfd6b 100644
--- a/chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate.h
+++ b/chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate.h
@@ -60,10 +60,14 @@ class ChromeResourceDispatcherHostDelegate
int route_id) OVERRIDE;
virtual bool ShouldForceDownloadResource(
const GURL& url, const std::string& mime_type) OVERRIDE;
- virtual void OnResponseStarted(net::URLRequest* request,
- ResourceResponse* response) OVERRIDE;
- virtual void OnRequestRedirected(net::URLRequest* request,
- ResourceResponse* response) OVERRIDE;
+ virtual void OnResponseStarted(
+ net::URLRequest* request,
+ ResourceResponse* response,
+ ResourceMessageFilter* filter) OVERRIDE;
+ virtual void OnRequestRedirected(
+ net::URLRequest* request,
+ ResourceResponse* response,
+ ResourceMessageFilter* filter) OVERRIDE;
private:
ResourceHandler* CreateSafeBrowsingResourceHandler(
diff --git a/chrome/test/data/redirect-cross-origin.html b/chrome/test/data/redirect-cross-origin.html
new file mode 100644
index 0000000..63d8dbd
--- /dev/null
+++ b/chrome/test/data/redirect-cross-origin.html
@@ -0,0 +1 @@
+b \ No newline at end of file
diff --git a/chrome/test/data/redirect-cross-origin.html.mock-http-headers b/chrome/test/data/redirect-cross-origin.html.mock-http-headers
new file mode 100644
index 0000000..cea4a16
--- /dev/null
+++ b/chrome/test/data/redirect-cross-origin.html.mock-http-headers
@@ -0,0 +1,2 @@
+HTTP/1.1 200 OK
+Set-Cookie: A=B
diff --git a/content/browser/renderer_host/async_resource_handler.cc b/content/browser/renderer_host/async_resource_handler.cc
index 21986e8..aaaedf0 100644
--- a/content/browser/renderer_host/async_resource_handler.cc
+++ b/content/browser/renderer_host/async_resource_handler.cc
@@ -17,6 +17,7 @@
#include "content/browser/renderer_host/resource_dispatcher_host_delegate.h"
#include "content/browser/renderer_host/resource_dispatcher_host_request_info.h"
#include "content/browser/renderer_host/resource_message_filter.h"
+#include "content/browser/resource_context.h"
#include "content/common/resource_response.h"
#include "content/common/resource_messages.h"
#include "content/common/view_messages.h"
@@ -79,11 +80,9 @@ AsyncResourceHandler::AsyncResourceHandler(
ResourceMessageFilter* filter,
int routing_id,
const GURL& url,
- HostZoomMap* host_zoom_map,
ResourceDispatcherHost* resource_dispatcher_host)
: filter_(filter),
routing_id_(routing_id),
- host_zoom_map_(host_zoom_map),
rdh_(resource_dispatcher_host),
next_buffer_size_(kInitialReadBufSize) {
}
@@ -106,7 +105,7 @@ bool AsyncResourceHandler::OnRequestRedirected(int request_id,
net::URLRequest* request = rdh_->GetURLRequest(
GlobalRequestID(filter_->child_id(), request_id));
if (rdh_->delegate())
- rdh_->delegate()->OnRequestRedirected(request, response);
+ rdh_->delegate()->OnRequestRedirected(request, response, filter_);
DevToolsNetLogObserver::PopulateResponseInfo(request, response);
return filter_->Send(new ResourceMsg_ReceivedRedirect(
@@ -124,16 +123,20 @@ bool AsyncResourceHandler::OnResponseStarted(int request_id,
GlobalRequestID(filter_->child_id(), request_id));
if (rdh_->delegate())
- rdh_->delegate()->OnResponseStarted(request, response);
+ rdh_->delegate()->OnResponseStarted(request, response, filter_);
DevToolsNetLogObserver::PopulateResponseInfo(request, response);
+ const content::ResourceContext& resource_context =
+ filter_->resource_context();
+ HostZoomMap* host_zoom_map = resource_context.host_zoom_map();
+
ResourceDispatcherHostRequestInfo* info = rdh_->InfoForRequest(request);
- if (info->resource_type() == ResourceType::MAIN_FRAME && host_zoom_map_) {
+ if (info->resource_type() == ResourceType::MAIN_FRAME && host_zoom_map) {
GURL request_url(request->url());
filter_->Send(new ViewMsg_SetZoomLevelForLoadingURL(
info->route_id(),
- request_url, host_zoom_map_->GetZoomLevel(net::GetHostOrSpecFromURL(
+ request_url, host_zoom_map->GetZoomLevel(net::GetHostOrSpecFromURL(
request_url))));
}
diff --git a/content/browser/renderer_host/async_resource_handler.h b/content/browser/renderer_host/async_resource_handler.h
index ea33a19..bfef818 100644
--- a/content/browser/renderer_host/async_resource_handler.h
+++ b/content/browser/renderer_host/async_resource_handler.h
@@ -22,7 +22,6 @@ class AsyncResourceHandler : public ResourceHandler {
AsyncResourceHandler(ResourceMessageFilter* filter,
int routing_id,
const GURL& url,
- HostZoomMap* host_zoom_map,
ResourceDispatcherHost* resource_dispatcher_host);
// ResourceHandler implementation:
diff --git a/content/browser/renderer_host/resource_dispatcher_host.cc b/content/browser/renderer_host/resource_dispatcher_host.cc
index 6c19527..2fcdca3 100644
--- a/content/browser/renderer_host/resource_dispatcher_host.cc
+++ b/content/browser/renderer_host/resource_dispatcher_host.cc
@@ -408,8 +408,7 @@ void ResourceDispatcherHost::BeginRequest(
filter_, request_data.url, sync_result, this);
} else {
handler = new AsyncResourceHandler(
- filter_, route_id, request_data.url, resource_context.host_zoom_map(),
- this);
+ filter_, route_id, request_data.url, this);
}
// The RedirectToFileResourceHandler depends on being next in the chain.
diff --git a/content/browser/renderer_host/resource_dispatcher_host_delegate.cc b/content/browser/renderer_host/resource_dispatcher_host_delegate.cc
index 849b6a4..784dd42 100644
--- a/content/browser/renderer_host/resource_dispatcher_host_delegate.cc
+++ b/content/browser/renderer_host/resource_dispatcher_host_delegate.cc
@@ -68,9 +68,13 @@ bool ResourceDispatcherHostDelegate::ShouldForceDownloadResource(
}
void ResourceDispatcherHostDelegate::OnResponseStarted(
- net::URLRequest* request, ResourceResponse* response) {
+ net::URLRequest* request,
+ ResourceResponse* response,
+ ResourceMessageFilter* filter) {
}
void ResourceDispatcherHostDelegate::OnRequestRedirected(
- net::URLRequest* request, ResourceResponse* response) {
+ net::URLRequest* request,
+ ResourceResponse* response,
+ ResourceMessageFilter* filter) {
}
diff --git a/content/browser/renderer_host/resource_dispatcher_host_delegate.h b/content/browser/renderer_host/resource_dispatcher_host_delegate.h
index bd25993..694d36c 100644
--- a/content/browser/renderer_host/resource_dispatcher_host_delegate.h
+++ b/content/browser/renderer_host/resource_dispatcher_host_delegate.h
@@ -13,6 +13,7 @@
class GURL;
class ResourceDispatcherHostLoginDelegate;
class ResourceHandler;
+class ResourceMessageFilter;
struct ResourceHostMsg_Request;
struct ResourceResponse;
@@ -90,12 +91,16 @@ class ResourceDispatcherHostDelegate {
const GURL& url, const std::string& mime_type);
// Informs the delegate that a response has started.
- virtual void OnResponseStarted(net::URLRequest* request,
- ResourceResponse* response);
+ virtual void OnResponseStarted(
+ net::URLRequest* request,
+ ResourceResponse* response,
+ ResourceMessageFilter* filter);
// Informs the delegate that a request has been redirected.
- virtual void OnRequestRedirected(net::URLRequest* request,
- ResourceResponse* response);
+ virtual void OnRequestRedirected(
+ net::URLRequest* request,
+ ResourceResponse* response,
+ ResourceMessageFilter* filter);
protected:
ResourceDispatcherHostDelegate();
diff --git a/content/browser/renderer_host/sync_resource_handler.cc b/content/browser/renderer_host/sync_resource_handler.cc
index 6599e22..d0dd937 100644
--- a/content/browser/renderer_host/sync_resource_handler.cc
+++ b/content/browser/renderer_host/sync_resource_handler.cc
@@ -42,7 +42,7 @@ bool SyncResourceHandler::OnRequestRedirected(int request_id,
net::URLRequest* request = rdh_->GetURLRequest(
GlobalRequestID(filter_->child_id(), request_id));
if (rdh_->delegate())
- rdh_->delegate()->OnRequestRedirected(request, response);
+ rdh_->delegate()->OnRequestRedirected(request, response, filter_);
DevToolsNetLogObserver::PopulateResponseInfo(request, response);
// TODO(darin): It would be much better if this could live in WebCore, but
@@ -61,7 +61,7 @@ bool SyncResourceHandler::OnResponseStarted(int request_id,
net::URLRequest* request = rdh_->GetURLRequest(
GlobalRequestID(filter_->child_id(), request_id));
if (rdh_->delegate())
- rdh_->delegate()->OnResponseStarted(request, response);
+ rdh_->delegate()->OnResponseStarted(request, response, filter_);
DevToolsNetLogObserver::PopulateResponseInfo(request, response);