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

Unified Diff: third_party/WebKit/Source/platform/weborigin/SecurityPolicy.cpp

Issue 2674973006: Move parsing of referrer policy header values to SecurityPolicy (Closed)
Patch Set: Created 3 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/Source/platform/weborigin/SecurityPolicy.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/platform/weborigin/SecurityPolicy.cpp
diff --git a/third_party/WebKit/Source/platform/weborigin/SecurityPolicy.cpp b/third_party/WebKit/Source/platform/weborigin/SecurityPolicy.cpp
index 4ead5ec82b5e21db37474a6738a69d3fba17ba65..0e88444bad831533cd74b5ba0e7762035d236c4b 100644
--- a/third_party/WebKit/Source/platform/weborigin/SecurityPolicy.cpp
+++ b/third_party/WebKit/Source/platform/weborigin/SecurityPolicy.cpp
@@ -46,11 +46,6 @@ using OriginAccessWhiteList = Vector<OriginAccessEntry>;
using OriginAccessMap = HashMap<String, std::unique_ptr<OriginAccessWhiteList>>;
using OriginSet = HashSet<String>;
-enum ReferrerPolicyLegacyKeywordsSupport {
- SupportReferrerPolicyLegacyKeywords,
- DoNotSupportReferrerPolicyLegacyKeywords,
-};
-
static OriginAccessMap& originAccessMap() {
DEFINE_STATIC_LOCAL(OriginAccessMap, originAccessMap, ());
return originAccessMap;
@@ -61,42 +56,6 @@ static OriginSet& trustworthyOriginSet() {
return trustworthyOriginSet;
}
-static bool referrerPolicyFromStringImpl(
- const String& policy,
- ReferrerPolicyLegacyKeywordsSupport legacyKeywordsSupport,
- ReferrerPolicy* result) {
- DCHECK(!policy.isNull());
- bool supportLegacyKeywords =
- (legacyKeywordsSupport == SupportReferrerPolicyLegacyKeywords);
-
- if (equalIgnoringASCIICase(policy, "no-referrer") ||
- (supportLegacyKeywords && equalIgnoringASCIICase(policy, "never"))) {
- *result = ReferrerPolicyNever;
- return true;
- }
- if (equalIgnoringASCIICase(policy, "unsafe-url") ||
- (supportLegacyKeywords && equalIgnoringASCIICase(policy, "always"))) {
- *result = ReferrerPolicyAlways;
- return true;
- }
- if (equalIgnoringASCIICase(policy, "origin")) {
- *result = ReferrerPolicyOrigin;
- return true;
- }
- if (equalIgnoringASCIICase(policy, "origin-when-cross-origin") ||
- (supportLegacyKeywords &&
- equalIgnoringASCIICase(policy, "origin-when-crossorigin"))) {
- *result = ReferrerPolicyOriginWhenCrossOrigin;
- return true;
- }
- if (equalIgnoringASCIICase(policy, "no-referrer-when-downgrade") ||
- (supportLegacyKeywords && equalIgnoringASCIICase(policy, "default"))) {
- *result = ReferrerPolicyNoReferrerWhenDowngrade;
- return true;
- }
- return false;
-}
-
void SecurityPolicy::init() {
originAccessMap();
trustworthyOriginSet();
@@ -297,17 +256,63 @@ void SecurityPolicy::resetOriginAccessWhitelists() {
originAccessMap().clear();
}
-bool SecurityPolicy::referrerPolicyFromString(const String& policy,
- ReferrerPolicy* result) {
- return referrerPolicyFromStringImpl(
- policy, DoNotSupportReferrerPolicyLegacyKeywords, result);
+bool SecurityPolicy::referrerPolicyFromString(
+ const String& policy,
+ ReferrerPolicyLegacyKeywordsSupport legacyKeywordsSupport,
+ ReferrerPolicy* result) {
+ DCHECK(!policy.isNull());
+ bool supportLegacyKeywords =
+ (legacyKeywordsSupport == SupportReferrerPolicyLegacyKeywords);
+
+ if (equalIgnoringASCIICase(policy, "no-referrer") ||
+ (supportLegacyKeywords && equalIgnoringASCIICase(policy, "never"))) {
+ *result = ReferrerPolicyNever;
+ return true;
+ }
+ if (equalIgnoringASCIICase(policy, "unsafe-url") ||
+ (supportLegacyKeywords && equalIgnoringASCIICase(policy, "always"))) {
+ *result = ReferrerPolicyAlways;
+ return true;
+ }
+ if (equalIgnoringASCIICase(policy, "origin")) {
+ *result = ReferrerPolicyOrigin;
+ return true;
+ }
+ if (equalIgnoringASCIICase(policy, "origin-when-cross-origin") ||
+ (supportLegacyKeywords &&
+ equalIgnoringASCIICase(policy, "origin-when-crossorigin"))) {
+ *result = ReferrerPolicyOriginWhenCrossOrigin;
+ return true;
+ }
+ if (equalIgnoringASCIICase(policy, "no-referrer-when-downgrade") ||
+ (supportLegacyKeywords && equalIgnoringASCIICase(policy, "default"))) {
+ *result = ReferrerPolicyNoReferrerWhenDowngrade;
+ return true;
+ }
+ return false;
}
-bool SecurityPolicy::referrerPolicyFromStringWithLegacyKeywords(
- const String& policy,
+bool SecurityPolicy::referrerPolicyFromHeaderValue(
+ const String& headerValue,
+ ReferrerPolicyLegacyKeywordsSupport legacyKeywordsSupport,
ReferrerPolicy* result) {
- return referrerPolicyFromStringImpl(
- policy, SupportReferrerPolicyLegacyKeywords, result);
+ ReferrerPolicy referrerPolicy = ReferrerPolicyDefault;
+
+ Vector<String> tokens;
+ headerValue.split(',', true, tokens);
+ for (const auto& token : tokens) {
+ ReferrerPolicy currentResult;
+ if (SecurityPolicy::referrerPolicyFromString(token, legacyKeywordsSupport,
+ &currentResult)) {
+ referrerPolicy = currentResult;
+ }
+ }
+
+ if (referrerPolicy == ReferrerPolicyDefault)
+ return false;
+
+ *result = referrerPolicy;
+ return true;
}
} // namespace blink
« no previous file with comments | « third_party/WebKit/Source/platform/weborigin/SecurityPolicy.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698