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

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

Issue 438283002: Sanitize referrer in context menus. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add test for Save Image As Created 6 years, 4 months 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 | Annotate | Revision Log
« no previous file with comments | « chrome/test/data/referrer_policy/referrer-policy-start.html ('k') | 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/logging.h"
8 #include "content/common/content_export.h" 9 #include "content/common/content_export.h"
9 #include "third_party/WebKit/public/platform/WebReferrerPolicy.h" 10 #include "third_party/WebKit/public/platform/WebReferrerPolicy.h"
10 #include "url/gurl.h" 11 #include "url/gurl.h"
11 12
12 namespace content { 13 namespace content {
13 14
14 // 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
15 // 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
16 // up being used for URL requests, always use this struct. 17 // up being used for URL requests, always use this struct.
17 struct CONTENT_EXPORT Referrer { 18 struct CONTENT_EXPORT Referrer {
18 Referrer(const GURL& url, blink::WebReferrerPolicy policy) : url(url), 19 Referrer(const GURL& url, blink::WebReferrerPolicy policy) : url(url),
19 policy(policy) { 20 policy(policy) {
20 } 21 }
21 Referrer() : policy(blink::WebReferrerPolicyDefault) { 22 Referrer() : policy(blink::WebReferrerPolicyDefault) {
22 } 23 }
23 24
24 GURL url; 25 GURL url;
25 blink::WebReferrerPolicy policy; 26 blink::WebReferrerPolicy policy;
27
28 static Referrer SanitizeForRequest(const GURL& request,
29 const Referrer& referrer) {
30 Referrer sanitized_referrer;
31 sanitized_referrer.url = referrer.url.GetAsReferrer();
32 sanitized_referrer.policy = referrer.policy;
jochen (gone - plz use gerrit) 2014/08/05 13:27:42 can you also make SerializedNavigationEntry::Sanit
nasko 2014/08/05 14:27:58 Done.
33 switch (sanitized_referrer.policy) {
34 case blink::WebReferrerPolicyDefault:
35 if (sanitized_referrer.url.SchemeIsSecure() &&
36 !request.SchemeIsSecure()) {
37 sanitized_referrer.url = GURL();
38 }
39 break;
40 case blink::WebReferrerPolicyAlways:
41 break;
42 case blink::WebReferrerPolicyNever:
43 sanitized_referrer.url = GURL();
44 break;
45 case blink::WebReferrerPolicyOrigin:
46 sanitized_referrer.url = sanitized_referrer.url.GetOrigin();
47 break;
48 default:
49 NOTREACHED();
50 break;
51 }
52 return sanitized_referrer;
53 }
26 }; 54 };
27 55
28 } // namespace content 56 } // namespace content
29 57
30 #endif // CONTENT_PUBLIC_COMMON_REFERRER_H_ 58 #endif // CONTENT_PUBLIC_COMMON_REFERRER_H_
OLDNEW
« no previous file with comments | « chrome/test/data/referrer_policy/referrer-policy-start.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698