summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjochen@chromium.org <jochen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-05-08 23:25:22 +0000
committerjochen@chromium.org <jochen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-05-08 23:25:22 +0000
commitadbda59b25a349bab5df95cb86c1e42b9b0ed333 (patch)
tree25e1cc15ad3f3d2427884e173ebe71512028879d
parent04a8c1ae5038f7c67582fc9295c9c4eac4d61caf (diff)
downloadchromium_src-adbda59b25a349bab5df95cb86c1e42b9b0ed333.zip
chromium_src-adbda59b25a349bab5df95cb86c1e42b9b0ed333.tar.gz
chromium_src-adbda59b25a349bab5df95cb86c1e42b9b0ed333.tar.bz2
Allow for overriding the handling of the referrer header in the network stack
When a non-default referrer policy is effective, the network stack should not mess with the header BUG=124750 TEST=the test for that code path is disabled :-/ Review URL: https://chromiumcodereview.appspot.com/10309005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@135943 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--content/browser/renderer_host/resource_dispatcher_host_impl.cc2
-rw-r--r--net/url_request/url_request.cc11
-rw-r--r--net/url_request/url_request.h20
-rw-r--r--webkit/glue/webkit_glue.cc19
-rw-r--r--webkit/glue/webkit_glue.h9
-rw-r--r--webkit/tools/test_shell/simple_resource_loader_bridge.cc5
6 files changed, 65 insertions, 1 deletions
diff --git a/content/browser/renderer_host/resource_dispatcher_host_impl.cc b/content/browser/renderer_host/resource_dispatcher_host_impl.cc
index b934e38..10f74eb 100644
--- a/content/browser/renderer_host/resource_dispatcher_host_impl.cc
+++ b/content/browser/renderer_host/resource_dispatcher_host_impl.cc
@@ -83,6 +83,7 @@
#include "webkit/appcache/appcache_interfaces.h"
#include "webkit/blob/blob_storage_controller.h"
#include "webkit/blob/shareable_file_reference.h"
+#include "webkit/glue/webkit_glue.h"
using base::Time;
using base::TimeDelta;
@@ -813,6 +814,7 @@ void ResourceDispatcherHostImpl::BeginRequest(
request->set_method(request_data.method);
request->set_first_party_for_cookies(request_data.first_party_for_cookies);
request->set_referrer(referrer.url.spec());
+ webkit_glue::ConfigureURLRequestForReferrerPolicy(request, referrer.policy);
net::HttpRequestHeaders headers;
headers.AddHeadersFromString(request_data.headers);
request->SetExtraRequestHeaders(headers);
diff --git a/net/url_request/url_request.cc b/net/url_request/url_request.cc
index 2096833..3947d69 100644
--- a/net/url_request/url_request.cc
+++ b/net/url_request/url_request.cc
@@ -134,6 +134,7 @@ void URLRequest::Delegate::OnSSLCertificateError(URLRequest* request,
URLRequest::URLRequest(const GURL& url, Delegate* delegate)
: url_chain_(1, url),
method_("GET"),
+ referrer_policy_(CLEAR_REFERRER_ON_TRANSITION_FROM_SECURE_TO_INSECURE),
load_flags_(LOAD_NORMAL),
delegate_(delegate),
is_pending_(false),
@@ -377,6 +378,11 @@ GURL URLRequest::GetSanitizedReferrer() const {
return ret;
}
+void URLRequest::set_referrer_policy(ReferrerPolicy referrer_policy) {
+ DCHECK(!is_pending_);
+ referrer_policy_ = referrer_policy;
+}
+
void URLRequest::set_delegate(Delegate* delegate) {
delegate_ = delegate;
}
@@ -697,8 +703,11 @@ int URLRequest::Redirect(const GURL& location, int http_status_code) {
}
// Suppress the referrer if we're redirecting out of https.
- if (GURL(referrer_).SchemeIsSecure() && !location.SchemeIsSecure())
+ if (referrer_policy_ ==
+ CLEAR_REFERRER_ON_TRANSITION_FROM_SECURE_TO_INSECURE &&
+ GURL(referrer_).SchemeIsSecure() && !location.SchemeIsSecure()) {
referrer_.clear();
+ }
url_chain_.push_back(location);
--redirect_limit_;
diff --git a/net/url_request/url_request.h b/net/url_request/url_request.h
index 4e25d37..72f6b95 100644
--- a/net/url_request/url_request.h
+++ b/net/url_request/url_request.h
@@ -120,6 +120,21 @@ class NET_EXPORT URLRequest : NON_EXPORTED_BASE(public base::NonThreadSafe),
#undef HTTP_ATOM
};
+ // Referrer policies (see set_referrer_policy): During server redirects, the
+ // referrer header might be cleared, if the protocol changes from HTTPS to
+ // HTTP. This is the default behavior of URLRequest, corresponding to
+ // CLEAR_REFERRER_ON_TRANSITION_FROM_SECURE_TO_INSECURE. Alternatively, the
+ // referrer policy can be set to never change the referrer header. This
+ // behavior corresponds to NEVER_CLEAR_REFERRER. Embedders will want to use
+ // NEVER_CLEAR_REFERRER when implementing the meta-referrer support
+ // (http://wiki.whatwg.org/wiki/Meta_referrer) and sending requests with a
+ // non-default referrer policy. Only the default referrer policy requires
+ // the referrer to be cleared on transitions from HTTPS to HTTP.
+ enum ReferrerPolicy {
+ CLEAR_REFERRER_ON_TRANSITION_FROM_SECURE_TO_INSECURE,
+ NEVER_CLEAR_REFERRER,
+ };
+
// This class handles network interception. Use with
// (Un)RegisterRequestInterceptor.
class NET_EXPORT Interceptor {
@@ -342,6 +357,10 @@ class NET_EXPORT URLRequest : NON_EXPORTED_BASE(public base::NonThreadSafe),
// Returns the referrer header with potential username and password removed.
GURL GetSanitizedReferrer() const;
+ // The referrer policy to apply when updating the referrer during redirects.
+ // The referrer policy may only be changed before Start() is called.
+ void set_referrer_policy(ReferrerPolicy referrer_policy);
+
// Sets the delegate of the request. This value may be changed at any time,
// and it is permissible for it to be null.
void set_delegate(Delegate* delegate);
@@ -698,6 +717,7 @@ class NET_EXPORT URLRequest : NON_EXPORTED_BASE(public base::NonThreadSafe),
GURL delegate_redirect_url_;
std::string method_; // "GET", "POST", etc. Should be all uppercase.
std::string referrer_;
+ ReferrerPolicy referrer_policy_;
HttpRequestHeaders extra_request_headers_;
int load_flags_; // Flags indicating the request type for the load;
// expected values are LOAD_* enums above.
diff --git a/webkit/glue/webkit_glue.cc b/webkit/glue/webkit_glue.cc
index 496b837..c2ee25b 100644
--- a/webkit/glue/webkit_glue.cc
+++ b/webkit/glue/webkit_glue.cc
@@ -24,6 +24,7 @@
#include "base/sys_string_conversions.h"
#include "base/utf_string_conversions.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"
@@ -498,4 +499,22 @@ bool IsInspectorProtocolVersionSupported(const std::string& version) {
WebString::fromUTF8(version));
}
+void ConfigureURLRequestForReferrerPolicy(
+ net::URLRequest* request, WebKit::WebReferrerPolicy referrer_policy) {
+ net::URLRequest::ReferrerPolicy net_referrer_policy;
+ 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);
+}
+
} // namespace webkit_glue
diff --git a/webkit/glue/webkit_glue.h b/webkit/glue/webkit_glue.h
index 1dae5f3..fa2bb7d 100644
--- a/webkit/glue/webkit_glue.h
+++ b/webkit/glue/webkit_glue.h
@@ -18,12 +18,17 @@
#include "base/platform_file.h"
#include "base/string16.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebCanvas.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebReferrerPolicy.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebFileError.h"
#include "webkit/glue/webkit_glue_export.h"
class GURL;
class SkBitmap;
+namespace net {
+class URLRequest;
+}
+
namespace skia {
class PlatformCanvas;
}
@@ -154,6 +159,10 @@ 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);
+
} // namespace webkit_glue
#endif // WEBKIT_GLUE_WEBKIT_GLUE_H_
diff --git a/webkit/tools/test_shell/simple_resource_loader_bridge.cc b/webkit/tools/test_shell/simple_resource_loader_bridge.cc
index 6d5865a..074580d 100644
--- a/webkit/tools/test_shell/simple_resource_loader_bridge.cc
+++ b/webkit/tools/test_shell/simple_resource_loader_bridge.cc
@@ -68,6 +68,7 @@
#include "webkit/fileapi/file_system_dir_url_request_job.h"
#include "webkit/fileapi/file_system_url_request_job.h"
#include "webkit/glue/resource_loader_bridge.h"
+#include "webkit/glue/webkit_glue.h"
#include "webkit/tools/test_shell/simple_appcache_system.h"
#include "webkit/tools/test_shell/simple_file_system.h"
#include "webkit/tools/test_shell/simple_file_writer.h"
@@ -260,6 +261,7 @@ struct RequestParams {
GURL url;
GURL first_party_for_cookies;
GURL referrer;
+ WebKit::WebReferrerPolicy referrer_policy;
std::string headers;
int load_flags;
ResourceType::Type request_type;
@@ -411,6 +413,8 @@ class RequestProxy
request_->set_method(params->method);
request_->set_first_party_for_cookies(params->first_party_for_cookies);
request_->set_referrer(params->referrer.spec());
+ webkit_glue::ConfigureURLRequestForReferrerPolicy(
+ request_.get(), params->referrer_policy);
net::HttpRequestHeaders headers;
headers.AddHeadersFromString(params->headers);
request_->SetExtraRequestHeaders(headers);
@@ -840,6 +844,7 @@ class ResourceLoaderBridgeImpl : public ResourceLoaderBridge {
params_->url = request_info.url;
params_->first_party_for_cookies = request_info.first_party_for_cookies;
params_->referrer = request_info.referrer;
+ params_->referrer_policy = request_info.referrer_policy;
params_->headers = request_info.headers;
params_->load_flags = request_info.load_flags;
params_->request_type = request_info.request_type;