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

Side by Side Diff: Source/platform/weborigin/SecurityPolicy.cpp

Issue 650023003: Make generateReferrerHeader() return a Referrer instead of a String (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 2 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011 Google Inc. All rights reserved. 2 * Copyright (C) 2011 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 return true; 58 return true;
59 59
60 if (!referrerIsSecureURL) 60 if (!referrerIsSecureURL)
61 return false; 61 return false;
62 62
63 bool URLIsSecureURL = url.protocolIs("https"); 63 bool URLIsSecureURL = url.protocolIs("https");
64 64
65 return !URLIsSecureURL; 65 return !URLIsSecureURL;
66 } 66 }
67 67
68 String SecurityPolicy::generateReferrerHeader(ReferrerPolicy referrerPolicy, con st KURL& url, const String& referrer) 68 Referrer SecurityPolicy::generateReferrer(ReferrerPolicy referrerPolicy, const K URL& url, const String& referrer)
69 { 69 {
70 if (referrer.isEmpty()) 70 if (referrer.isEmpty())
71 return String(); 71 return Referrer(String(), referrerPolicy);
72 72
73 if (!(protocolIs(referrer, "https") || protocolIs(referrer, "http"))) 73 if (!(protocolIs(referrer, "https") || protocolIs(referrer, "http")))
74 return String(); 74 return Referrer(String(), referrerPolicy);
75 75
76 switch (referrerPolicy) { 76 switch (referrerPolicy) {
77 case ReferrerPolicyNever: 77 case ReferrerPolicyNever:
78 return String(); 78 return Referrer(String(), referrerPolicy);
79 case ReferrerPolicyAlways: 79 case ReferrerPolicyAlways:
80 return referrer; 80 return Referrer(referrer, referrerPolicy);
81 case ReferrerPolicyOrigin: { 81 case ReferrerPolicyOrigin: {
82 String origin = SecurityOrigin::createFromString(referrer)->toString(); 82 String origin = SecurityOrigin::createFromString(referrer)->toString();
83 if (origin == "null") 83 if (origin == "null")
84 return String(); 84 return Referrer(String(), referrerPolicy);
85 // A security origin is not a canonical URL as it lacks a path. Add / 85 // A security origin is not a canonical URL as it lacks a path. Add /
86 // to turn it into a canonical URL we can use as referrer. 86 // to turn it into a canonical URL we can use as referrer.
87 return origin + "/"; 87 return Referrer(origin + "/", referrerPolicy);
88 } 88 }
89 case ReferrerPolicyDefault: 89 case ReferrerPolicyDefault:
90 break; 90 break;
91 } 91 }
92 92
93 return shouldHideReferrer(url, referrer) ? String() : referrer; 93 return Referrer(shouldHideReferrer(url, referrer) ? String() : referrer, ref errerPolicy);
94 } 94 }
95 95
96 bool SecurityPolicy::isAccessWhiteListed(const SecurityOrigin* activeOrigin, con st SecurityOrigin* targetOrigin) 96 bool SecurityPolicy::isAccessWhiteListed(const SecurityOrigin* activeOrigin, con st SecurityOrigin* targetOrigin)
97 { 97 {
98 if (OriginAccessWhiteList* list = originAccessMap().get(activeOrigin->toStri ng())) { 98 if (OriginAccessWhiteList* list = originAccessMap().get(activeOrigin->toStri ng())) {
99 for (size_t i = 0; i < list->size(); ++i) { 99 for (size_t i = 0; i < list->size(); ++i) {
100 if (list->at(i).matchesOrigin(*targetOrigin) != OriginAccessEntry::D oesNotMatchOrigin) 100 if (list->at(i).matchesOrigin(*targetOrigin) != OriginAccessEntry::D oesNotMatchOrigin)
101 return true; 101 return true;
102 } 102 }
103 } 103 }
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 map.remove(it); 150 map.remove(it);
151 } 151 }
152 152
153 void SecurityPolicy::resetOriginAccessWhitelists() 153 void SecurityPolicy::resetOriginAccessWhitelists()
154 { 154 {
155 ASSERT(isMainThread()); 155 ASSERT(isMainThread());
156 originAccessMap().clear(); 156 originAccessMap().clear();
157 } 157 }
158 158
159 } // namespace blink 159 } // namespace blink
OLDNEW
« no previous file with comments | « Source/platform/weborigin/SecurityPolicy.h ('k') | Source/platform/weborigin/SecurityPolicyTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698