summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordarin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-06-25 16:43:23 +0000
committerdarin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-06-25 16:43:23 +0000
commita60346fc4fcab6192854566fbd514ec469c5735e (patch)
tree502cd26a49cf1ed83e57e2c7a673f45068cf2729
parent750488e4ed4bba0772a8e997b6e89948a5ce7b7f (diff)
downloadchromium_src-a60346fc4fcab6192854566fbd514ec469c5735e.zip
chromium_src-a60346fc4fcab6192854566fbd514ec469c5735e.tar.gz
chromium_src-a60346fc4fcab6192854566fbd514ec469c5735e.tar.bz2
Move configuration of URLRequest referrer to content/browser/loader.
There are a couple of places outside of the loader where an URLRequest is configured for downloading. BeginDownload gains a Referrer param, so we can consistently apply the Referrer to the URLRequest inside ResourceDispatcherHostImpl. Review URL: https://chromiumcodereview.appspot.com/17610005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@208506 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/plugins/plugin_installer.cc2
-rw-r--r--chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate.cc3
-rw-r--r--chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate.h3
-rw-r--r--content/browser/download/download_manager_impl.cc6
-rw-r--r--content/browser/loader/resource_dispatcher_host_impl.cc47
-rw-r--r--content/browser/loader/resource_dispatcher_host_impl.h1
-rw-r--r--content/browser/renderer_host/render_message_filter.cc5
-rw-r--r--content/public/browser/resource_dispatcher_host.h2
-rw-r--r--content/public/browser/resource_dispatcher_host_delegate.cc3
-rw-r--r--content/public/browser/resource_dispatcher_host_delegate.h3
-rw-r--r--webkit/glue/webkit_glue.cc20
-rw-r--r--webkit/glue/webkit_glue.h9
12 files changed, 42 insertions, 62 deletions
diff --git a/chrome/browser/plugins/plugin_installer.cc b/chrome/browser/plugins/plugin_installer.cc
index 6cc1b39..bd68407 100644
--- a/chrome/browser/plugins/plugin_installer.cc
+++ b/chrome/browser/plugins/plugin_installer.cc
@@ -23,6 +23,7 @@
#include "content/public/browser/resource_context.h"
#include "content/public/browser/resource_dispatcher_host.h"
#include "content/public/browser/web_contents.h"
+#include "content/public/common/referrer.h"
#include "net/url_request/url_request.h"
#include "net/url_request/url_request_context.h"
@@ -46,6 +47,7 @@ void BeginDownload(
resource_context->GetRequestContext()->CreateRequest(url, NULL));
net::Error error = rdh->BeginDownload(
request.Pass(),
+ content::Referrer(),
false, // is_content_initiated
resource_context,
render_process_host_id,
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 2f33ef2..93df87e 100644
--- a/chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate.cc
+++ b/chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate.cc
@@ -207,8 +207,7 @@ bool ChromeResourceDispatcherHostDelegate::ShouldBeginRequest(
const std::string& method,
const GURL& url,
ResourceType::Type resource_type,
- content::ResourceContext* resource_context,
- const content::Referrer& referrer) {
+ content::ResourceContext* resource_context) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
// Handle a PREFETCH resource type. If prefetch is disabled, squelch the
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 9afd08a..5e81a17 100644
--- a/chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate.h
+++ b/chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate.h
@@ -42,8 +42,7 @@ class ChromeResourceDispatcherHostDelegate
const std::string& method,
const GURL& url,
ResourceType::Type resource_type,
- content::ResourceContext* resource_context,
- const content::Referrer& referrer) OVERRIDE;
+ content::ResourceContext* resource_context) OVERRIDE;
virtual void RequestBeginning(
net::URLRequest* request,
content::ResourceContext* resource_context,
diff --git a/content/browser/download/download_manager_impl.cc b/content/browser/download/download_manager_impl.cc
index 6e0930a..08e32c6 100644
--- a/content/browser/download/download_manager_impl.cc
+++ b/content/browser/download/download_manager_impl.cc
@@ -43,7 +43,6 @@
#include "net/base/upload_bytes_element_reader.h"
#include "net/base/upload_data_stream.h"
#include "net/url_request/url_request_context.h"
-#include "webkit/glue/webkit_glue.h"
namespace content {
namespace {
@@ -57,10 +56,6 @@ void BeginDownload(scoped_ptr<DownloadUrlParameters> params,
scoped_ptr<net::URLRequest> request(
params->resource_context()->GetRequestContext()->CreateRequest(
params->url(), NULL));
- if (params->referrer().url.is_valid())
- request->SetReferrer(params->referrer().url.spec());
- webkit_glue::ConfigureURLRequestForReferrerPolicy(
- request.get(), params->referrer().policy);
request->set_load_flags(request->load_flags() | params->load_flags());
request->set_method(params->method());
if (!params->post_body().empty()) {
@@ -126,6 +121,7 @@ void BeginDownload(scoped_ptr<DownloadUrlParameters> params,
ResourceDispatcherHost::Get()->BeginDownload(
request.Pass(),
+ params->referrer(),
params->content_initiated(),
params->resource_context(),
params->render_process_host_id(),
diff --git a/content/browser/loader/resource_dispatcher_host_impl.cc b/content/browser/loader/resource_dispatcher_host_impl.cc
index 531b382..e159147 100644
--- a/content/browser/loader/resource_dispatcher_host_impl.cc
+++ b/content/browser/loader/resource_dispatcher_host_impl.cc
@@ -89,7 +89,6 @@
#include "webkit/common/appcache/appcache_interfaces.h"
#include "webkit/common/blob/shareable_file_reference.h"
#include "webkit/glue/resource_request_body.h"
-#include "webkit/glue/webkit_glue.h"
using base::Time;
using base::TimeDelta;
@@ -155,10 +154,28 @@ void AbortRequestBeforeItStarts(ResourceMessageFilter* filter,
}
}
-GURL MaybeStripReferrer(const GURL& possible_referrer) {
- if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kNoReferrers))
- return GURL();
- return possible_referrer;
+void SetReferrerForRequest(net::URLRequest* request, const Referrer& referrer) {
+ if (!referrer.url.is_valid() ||
+ CommandLine::ForCurrentProcess()->HasSwitch(switches::kNoReferrers)) {
+ request->SetReferrer(std::string());
+ } else {
+ request->SetReferrer(referrer.url.spec());
+ }
+
+ net::URLRequest::ReferrerPolicy net_referrer_policy =
+ net::URLRequest::CLEAR_REFERRER_ON_TRANSITION_FROM_SECURE_TO_INSECURE;
+ switch (referrer.policy) {
+ case WebKit::WebReferrerPolicyDefault:
+ net_referrer_policy =
+ net::URLRequest::CLEAR_REFERRER_ON_TRANSITION_FROM_SECURE_TO_INSECURE;
+ break;
+ case WebKit::WebReferrerPolicyAlways:
+ case WebKit::WebReferrerPolicyNever:
+ case WebKit::WebReferrerPolicyOrigin:
+ net_referrer_policy = net::URLRequest::NEVER_CLEAR_REFERRER;
+ break;
+ }
+ request->set_referrer_policy(net_referrer_policy);
}
// Consults the RendererSecurity policy to determine whether the
@@ -450,6 +467,7 @@ void ResourceDispatcherHostImpl::CancelRequestsForContext(
net::Error ResourceDispatcherHostImpl::BeginDownload(
scoped_ptr<net::URLRequest> request,
+ const Referrer& referrer,
bool is_content_initiated,
ResourceContext* context,
int child_id,
@@ -469,7 +487,8 @@ net::Error ResourceDispatcherHostImpl::BeginDownload(
base::debug::Alias(url_buf);
CHECK(ContainsKey(active_resource_contexts_, context));
- request->SetReferrer(MaybeStripReferrer(GURL(request->referrer())).spec());
+ SetReferrerForRequest(request.get(), referrer);
+
int extra_load_flags = net::LOAD_IS_DOWNLOAD;
if (prefer_cache) {
// If there is upload data attached, only retrieve from cache because there
@@ -950,8 +969,7 @@ void ResourceDispatcherHostImpl::BeginRequest(
return;
}
- const Referrer referrer(MaybeStripReferrer(request_data.referrer),
- request_data.referrer_policy);
+ const Referrer referrer(request_data.referrer, request_data.referrer_policy);
// Allow the observer to block/handle the request.
if (delegate_ && !delegate_->ShouldBeginRequest(child_id,
@@ -959,8 +977,7 @@ void ResourceDispatcherHostImpl::BeginRequest(
request_data.method,
request_data.url,
request_data.resource_type,
- resource_context,
- referrer)) {
+ resource_context)) {
AbortRequestBeforeItStarts(filter_, sync_result, route_id, request_id);
return;
}
@@ -992,9 +1009,8 @@ void ResourceDispatcherHostImpl::BeginRequest(
request->set_method(request_data.method);
request->set_first_party_for_cookies(request_data.first_party_for_cookies);
- request->SetReferrer(referrer.url.spec());
- webkit_glue::ConfigureURLRequestForReferrerPolicy(request,
- referrer.policy);
+ SetReferrerForRequest(request, referrer);
+
net::HttpRequestHeaders headers;
headers.AddHeadersFromString(request_data.headers);
request->SetExtraRequestHeaders(headers);
@@ -1276,9 +1292,8 @@ void ResourceDispatcherHostImpl::BeginSaveFile(
scoped_ptr<net::URLRequest> request(
request_context->CreateRequest(url, NULL));
request->set_method("GET");
- request->SetReferrer(MaybeStripReferrer(referrer.url).spec());
- webkit_glue::ConfigureURLRequestForReferrerPolicy(request.get(),
- referrer.policy);
+ SetReferrerForRequest(request.get(), referrer);
+
// So far, for saving page, we need fetch content from cache, in the
// future, maybe we can use a configuration to configure this behavior.
request->set_load_flags(net::LOAD_PREFERRING_CACHE);
diff --git a/content/browser/loader/resource_dispatcher_host_impl.h b/content/browser/loader/resource_dispatcher_host_impl.h
index 0e76c1f..abff21c 100644
--- a/content/browser/loader/resource_dispatcher_host_impl.h
+++ b/content/browser/loader/resource_dispatcher_host_impl.h
@@ -80,6 +80,7 @@ class CONTENT_EXPORT ResourceDispatcherHostImpl
virtual void SetAllowCrossOriginAuthPrompt(bool value) OVERRIDE;
virtual net::Error BeginDownload(
scoped_ptr<net::URLRequest> request,
+ const Referrer& referrer,
bool is_content_initiated,
ResourceContext* context,
int child_id,
diff --git a/content/browser/renderer_host/render_message_filter.cc b/content/browser/renderer_host/render_message_filter.cc
index 794f9a8..394f916 100644
--- a/content/browser/renderer_host/render_message_filter.cc
+++ b/content/browser/renderer_host/render_message_filter.cc
@@ -63,7 +63,6 @@
#include "net/url_request/url_request_context_getter.h"
#include "third_party/WebKit/public/web/WebNotificationPresenter.h"
#include "ui/gfx/color_profile.h"
-#include "webkit/glue/webkit_glue.h"
#include "webkit/plugins/npapi/webplugin.h"
#include "webkit/plugins/plugin_constants.h"
#include "webkit/plugins/webplugininfo.h"
@@ -828,12 +827,10 @@ void RenderMessageFilter::OnDownloadUrl(const IPC::Message& message,
save_info->suggested_name = suggested_name;
scoped_ptr<net::URLRequest> request(
resource_context_->GetRequestContext()->CreateRequest(url, NULL));
- request->SetReferrer(referrer.url.spec());
- webkit_glue::ConfigureURLRequestForReferrerPolicy(
- request.get(), referrer.policy);
RecordDownloadSource(INITIATED_BY_RENDERER);
resource_dispatcher_host_->BeginDownload(
request.Pass(),
+ referrer,
true, // is_content_initiated
resource_context_,
render_process_id_,
diff --git a/content/public/browser/resource_dispatcher_host.h b/content/public/browser/resource_dispatcher_host.h
index 3b982dc..9936a63 100644
--- a/content/public/browser/resource_dispatcher_host.h
+++ b/content/public/browser/resource_dispatcher_host.h
@@ -19,6 +19,7 @@ class DownloadItem;
class ResourceContext;
class ResourceDispatcherHostDelegate;
struct DownloadSaveInfo;
+struct Referrer;
class CONTENT_EXPORT ResourceDispatcherHost {
public:
@@ -48,6 +49,7 @@ class CONTENT_EXPORT ResourceDispatcherHost {
// DownloadItem; otherwise an error code will be returned.
virtual net::Error BeginDownload(
scoped_ptr<net::URLRequest> request,
+ const Referrer& referrer,
bool is_content_initiated,
ResourceContext* context,
int child_id,
diff --git a/content/public/browser/resource_dispatcher_host_delegate.cc b/content/public/browser/resource_dispatcher_host_delegate.cc
index 9971487..e5adc80 100644
--- a/content/public/browser/resource_dispatcher_host_delegate.cc
+++ b/content/public/browser/resource_dispatcher_host_delegate.cc
@@ -14,8 +14,7 @@ bool ResourceDispatcherHostDelegate::ShouldBeginRequest(
const std::string& method,
const GURL& url,
ResourceType::Type resource_type,
- ResourceContext* resource_context,
- const Referrer& referrer) {
+ ResourceContext* resource_context) {
return true;
}
diff --git a/content/public/browser/resource_dispatcher_host_delegate.h b/content/public/browser/resource_dispatcher_host_delegate.h
index abb5f6b..1a6ddb8 100644
--- a/content/public/browser/resource_dispatcher_host_delegate.h
+++ b/content/public/browser/resource_dispatcher_host_delegate.h
@@ -52,8 +52,7 @@ class CONTENT_EXPORT ResourceDispatcherHostDelegate {
const std::string& method,
const GURL& url,
ResourceType::Type resource_type,
- ResourceContext* resource_context,
- const Referrer& referrer);
+ ResourceContext* resource_context);
// Called after ShouldBeginRequest to allow the embedder to add resource
// throttles.
diff --git a/webkit/glue/webkit_glue.cc b/webkit/glue/webkit_glue.cc
index 34d8b8a..b51bc64 100644
--- a/webkit/glue/webkit_glue.cc
+++ b/webkit/glue/webkit_glue.cc
@@ -28,7 +28,6 @@
#include "base/strings/utf_string_conversions.h"
#include "base/sys_info.h"
#include "net/base/escape.h"
-#include "net/url_request/url_request.h"
#include "skia/ext/platform_canvas.h"
#if defined(OS_MACOSX)
#include "skia/ext/skia_utils_mac.h"
@@ -174,25 +173,6 @@ bool IsInspectorProtocolVersionSupported(const std::string& version) {
WebString::fromUTF8(version));
}
-void ConfigureURLRequestForReferrerPolicy(
- net::URLRequest* request, WebKit::WebReferrerPolicy referrer_policy) {
- net::URLRequest::ReferrerPolicy net_referrer_policy =
- net::URLRequest::CLEAR_REFERRER_ON_TRANSITION_FROM_SECURE_TO_INSECURE;
- switch (referrer_policy) {
- case WebKit::WebReferrerPolicyDefault:
- net_referrer_policy =
- net::URLRequest::CLEAR_REFERRER_ON_TRANSITION_FROM_SECURE_TO_INSECURE;
- break;
-
- case WebKit::WebReferrerPolicyAlways:
- case WebKit::WebReferrerPolicyNever:
- case WebKit::WebReferrerPolicyOrigin:
- net_referrer_policy = net::URLRequest::NEVER_CLEAR_REFERRER;
- break;
- }
- request->set_referrer_policy(net_referrer_policy);
-}
-
COMPILE_ASSERT(std::numeric_limits<double>::has_quiet_NaN, has_quiet_NaN);
#if defined(OS_LINUX) || defined(OS_ANDROID)
diff --git a/webkit/glue/webkit_glue.h b/webkit/glue/webkit_glue.h
index 1a9f30b..405d3d0 100644
--- a/webkit/glue/webkit_glue.h
+++ b/webkit/glue/webkit_glue.h
@@ -17,16 +17,11 @@
#include "base/platform_file.h"
#include "base/strings/string16.h"
#include "third_party/WebKit/public/platform/WebCanvas.h"
-#include "third_party/WebKit/public/platform/WebReferrerPolicy.h"
#include "webkit/glue/webkit_glue_export.h"
class SkBitmap;
class SkCanvas;
-namespace net {
-class URLRequest;
-}
-
namespace WebKit {
struct WebFileInfo;
class WebFrame;
@@ -82,10 +77,6 @@ std::string GetInspectorProtocolVersion();
WEBKIT_GLUE_EXPORT bool IsInspectorProtocolVersionSupported(
const std::string& version);
-// Configures the URLRequest according to the referrer policy.
-WEBKIT_GLUE_EXPORT void ConfigureURLRequestForReferrerPolicy(
- net::URLRequest* request, WebKit::WebReferrerPolicy referrer_policy);
-
// Returns an estimate of the memory usage of the renderer process. Different
// platforms implement this function differently, and count in different
// allocations. Results are not comparable across platforms. The estimate is