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

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

Issue 683233003: 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"
9 #include "base/logging.h" 8 #include "base/logging.h"
10 #include "content/common/content_export.h" 9 #include "content/common/content_export.h"
11 #include "content/public/common/content_switches.h"
12 #include "third_party/WebKit/public/platform/WebReferrerPolicy.h" 10 #include "third_party/WebKit/public/platform/WebReferrerPolicy.h"
13 #include "url/gurl.h" 11 #include "url/gurl.h"
14 12
15 namespace content { 13 namespace content {
16 14
17 // This struct holds a referrer URL, as well as the referrer policy to be 15 // This struct holds a referrer URL, as well as the referrer policy to be
18 // applied to this URL. When passing around referrers that will eventually end 16 // applied to this URL. When passing around referrers that will eventually end
19 // up being used for URL requests, always use this struct. 17 // up being used for URL requests, always use this struct.
20 struct CONTENT_EXPORT Referrer { 18 struct CONTENT_EXPORT Referrer {
21 Referrer(const GURL& url, blink::WebReferrerPolicy policy) : url(url), 19 Referrer(const GURL& url, blink::WebReferrerPolicy policy) : url(url),
22 policy(policy) { 20 policy(policy) {
23 } 21 }
24 Referrer() : policy(blink::WebReferrerPolicyDefault) { 22 Referrer() : policy(blink::WebReferrerPolicyDefault) {
25 } 23 }
26 24
27 GURL url; 25 GURL url;
28 blink::WebReferrerPolicy policy; 26 blink::WebReferrerPolicy policy;
29 27
30 static Referrer SanitizeForRequest(const GURL& request, 28 static Referrer SanitizeForRequest(const GURL& request,
31 const Referrer& referrer) { 29 const Referrer& referrer) {
32 Referrer sanitized_referrer(referrer.url.GetAsReferrer(), referrer.policy); 30 Referrer sanitized_referrer(referrer.url.GetAsReferrer(), referrer.policy);
33 31
34 if (!request.SchemeIsHTTPOrHTTPS() || 32 if (!request.SchemeIsHTTPOrHTTPS() ||
35 !sanitized_referrer.url.SchemeIsHTTPOrHTTPS()) { 33 !sanitized_referrer.url.SchemeIsHTTPOrHTTPS()) {
36 sanitized_referrer.url = GURL(); 34 sanitized_referrer.url = GURL();
37 return sanitized_referrer; 35 return sanitized_referrer;
38 } 36 }
39 37
40 bool is_downgrade =
41 sanitized_referrer.url.SchemeIsSecure() && !request.SchemeIsSecure();
42
43 switch (sanitized_referrer.policy) { 38 switch (sanitized_referrer.policy) {
44 case blink::WebReferrerPolicyDefault: 39 case blink::WebReferrerPolicyDefault:
45 if (is_downgrade) { 40 if (sanitized_referrer.url.SchemeIsSecure() &&
41 !request.SchemeIsSecure()) {
46 sanitized_referrer.url = GURL(); 42 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();
51 } 43 }
52 break; 44 break;
53 case blink::WebReferrerPolicyNoReferrerWhenDowngrade:
54 if (is_downgrade)
55 sanitized_referrer.url = GURL();
56 break;
57 case blink::WebReferrerPolicyAlways: 45 case blink::WebReferrerPolicyAlways:
58 break; 46 break;
59 case blink::WebReferrerPolicyNever: 47 case blink::WebReferrerPolicyNever:
60 sanitized_referrer.url = GURL(); 48 sanitized_referrer.url = GURL();
61 break; 49 break;
62 case blink::WebReferrerPolicyOrigin: 50 case blink::WebReferrerPolicyOrigin:
63 sanitized_referrer.url = sanitized_referrer.url.GetOrigin(); 51 sanitized_referrer.url = sanitized_referrer.url.GetOrigin();
64 break; 52 break;
65 default: 53 default:
66 NOTREACHED(); 54 NOTREACHED();
67 break; 55 break;
68 } 56 }
69 return sanitized_referrer; 57 return sanitized_referrer;
70 } 58 }
71 }; 59 };
72 60
73 } // namespace content 61 } // namespace content
74 62
75 #endif // CONTENT_PUBLIC_COMMON_REFERRER_H_ 63 #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