Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2822)

Unified Diff: content/public/common/referrer.cc

Issue 716813002: Referrer Policy: Update SanitizeForRequest with new default behavior. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/public/common/referrer.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/public/common/referrer.cc
diff --git a/content/public/common/referrer.cc b/content/public/common/referrer.cc
new file mode 100644
index 0000000000000000000000000000000000000000..b383fb73fc6fae4f4b820140c92bcca2e60adbf8
--- /dev/null
+++ b/content/public/common/referrer.cc
@@ -0,0 +1,54 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/command_line.h"
+#include "content/public/common/content_switches.h"
+#include "content/public/common/referrer.h"
+
+namespace content {
+
+// static.
+Referrer Referrer::SanitizeForRequest(const GURL& request,
+ const Referrer& referrer) {
+ Referrer sanitized_referrer(referrer.url.GetAsReferrer(), referrer.policy);
+
+ if (!request.SchemeIsHTTPOrHTTPS() ||
+ !sanitized_referrer.url.SchemeIsHTTPOrHTTPS()) {
+ sanitized_referrer.url = GURL();
+ return sanitized_referrer;
+ }
+
+ bool is_downgrade =
+ sanitized_referrer.url.SchemeIsSecure() && !request.SchemeIsSecure();
+
+ switch (sanitized_referrer.policy) {
+ case blink::WebReferrerPolicyDefault:
+ if (is_downgrade) {
+ sanitized_referrer.url = GURL();
+ } else if (request.GetOrigin() != sanitized_referrer.url.GetOrigin() &&
+ base::CommandLine::ForCurrentProcess()->HasSwitch(
+ switches::kReducedReferrerGranularity)) {
+ sanitized_referrer.url = sanitized_referrer.url.GetOrigin();
+ }
+ break;
+ case blink::WebReferrerPolicyNoReferrerWhenDowngrade:
+ if (is_downgrade)
+ sanitized_referrer.url = GURL();
+ break;
+ case blink::WebReferrerPolicyAlways:
+ break;
+ case blink::WebReferrerPolicyNever:
+ sanitized_referrer.url = GURL();
+ break;
+ case blink::WebReferrerPolicyOrigin:
+ sanitized_referrer.url = sanitized_referrer.url.GetOrigin();
+ break;
+ default:
+ NOTREACHED();
+ break;
+ }
+ return sanitized_referrer;
+}
+
+} // namespace content
« no previous file with comments | « content/public/common/referrer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698