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

Side by Side Diff: content/public/common/referrer.h

Issue 715513004: Revert of Revert of 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CONTENT_PUBLIC_COMMON_REFERRER_H_ 5 #ifndef CONTENT_PUBLIC_COMMON_REFERRER_H_
6 #define CONTENT_PUBLIC_COMMON_REFERRER_H_ 6 #define CONTENT_PUBLIC_COMMON_REFERRER_H_
7 7
8 #include "base/command_line.h"
8 #include "base/logging.h" 9 #include "base/logging.h"
9 #include "content/common/content_export.h" 10 #include "content/common/content_export.h"
11 #include "content/public/common/content_switches.h"
10 #include "third_party/WebKit/public/platform/WebReferrerPolicy.h" 12 #include "third_party/WebKit/public/platform/WebReferrerPolicy.h"
11 #include "url/gurl.h" 13 #include "url/gurl.h"
12 14
13 namespace content { 15 namespace content {
14 16
15 // This struct holds a referrer URL, as well as the referrer policy to be 17 // This struct holds a referrer URL, as well as the referrer policy to be
16 // applied to this URL. When passing around referrers that will eventually end 18 // applied to this URL. When passing around referrers that will eventually end
17 // up being used for URL requests, always use this struct. 19 // up being used for URL requests, always use this struct.
18 struct CONTENT_EXPORT Referrer { 20 struct CONTENT_EXPORT Referrer {
19 Referrer(const GURL& url, blink::WebReferrerPolicy policy) : url(url), 21 Referrer(const GURL& url, blink::WebReferrerPolicy policy) : url(url),
20 policy(policy) { 22 policy(policy) {
21 } 23 }
22 Referrer() : policy(blink::WebReferrerPolicyDefault) { 24 Referrer() : policy(blink::WebReferrerPolicyDefault) {
23 } 25 }
24 26
25 GURL url; 27 GURL url;
26 blink::WebReferrerPolicy policy; 28 blink::WebReferrerPolicy policy;
27 29
28 static Referrer SanitizeForRequest(const GURL& request, 30 static Referrer SanitizeForRequest(const GURL& request,
29 const Referrer& referrer) { 31 const Referrer& referrer) {
30 Referrer sanitized_referrer(referrer.url.GetAsReferrer(), referrer.policy); 32 Referrer sanitized_referrer(referrer.url.GetAsReferrer(), referrer.policy);
31 33
32 if (!request.SchemeIsHTTPOrHTTPS() || 34 if (!request.SchemeIsHTTPOrHTTPS() ||
33 !sanitized_referrer.url.SchemeIsHTTPOrHTTPS()) { 35 !sanitized_referrer.url.SchemeIsHTTPOrHTTPS()) {
34 sanitized_referrer.url = GURL(); 36 sanitized_referrer.url = GURL();
35 return sanitized_referrer; 37 return sanitized_referrer;
36 } 38 }
37 39
40 bool is_downgrade =
41 sanitized_referrer.url.SchemeIsSecure() && !request.SchemeIsSecure();
42
38 switch (sanitized_referrer.policy) { 43 switch (sanitized_referrer.policy) {
39 case blink::WebReferrerPolicyDefault: 44 case blink::WebReferrerPolicyDefault:
40 if (sanitized_referrer.url.SchemeIsSecure() && 45 if (is_downgrade) {
41 !request.SchemeIsSecure()) {
42 sanitized_referrer.url = GURL(); 46 sanitized_referrer.url = GURL();
47 } else if (request.GetOrigin() != sanitized_referrer.url.GetOrigin() &&
48 base::CommandLine::ForCurrentProcess()->HasSwitch(
49 switches::kReducedReferrerGranularity)) {
50 sanitized_referrer.url = sanitized_referrer.url.GetOrigin();
43 } 51 }
44 break; 52 break;
53 case blink::WebReferrerPolicyNoReferrerWhenDowngrade:
54 if (is_downgrade)
55 sanitized_referrer.url = GURL();
56 break;
45 case blink::WebReferrerPolicyAlways: 57 case blink::WebReferrerPolicyAlways:
46 break; 58 break;
47 case blink::WebReferrerPolicyNever: 59 case blink::WebReferrerPolicyNever:
48 sanitized_referrer.url = GURL(); 60 sanitized_referrer.url = GURL();
49 break; 61 break;
50 case blink::WebReferrerPolicyOrigin: 62 case blink::WebReferrerPolicyOrigin:
51 sanitized_referrer.url = sanitized_referrer.url.GetOrigin(); 63 sanitized_referrer.url = sanitized_referrer.url.GetOrigin();
52 break; 64 break;
53 default: 65 default:
54 NOTREACHED(); 66 NOTREACHED();
55 break; 67 break;
56 } 68 }
57 return sanitized_referrer; 69 return sanitized_referrer;
58 } 70 }
59 }; 71 };
60 72
61 } // namespace content 73 } // namespace content
62 74
63 #endif // CONTENT_PUBLIC_COMMON_REFERRER_H_ 75 #endif // CONTENT_PUBLIC_COMMON_REFERRER_H_
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698