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

Unified Diff: third_party/WebKit/Source/core/frame/csp/CSPSource.cpp

Issue 2470083002: Part 2.1: Is policy list subsumed under subsuming policy? (Closed)
Patch Set: Rebasing on part1.1 Created 4 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/frame/csp/CSPSource.cpp
diff --git a/third_party/WebKit/Source/core/frame/csp/CSPSource.cpp b/third_party/WebKit/Source/core/frame/csp/CSPSource.cpp
index 05c6ecd2be802c1436efcb25646773444443c2f1..71a3e0466b17819603af5e9a4541737493ac3a11 100644
--- a/third_party/WebKit/Source/core/frame/csp/CSPSource.cpp
+++ b/third_party/WebKit/Source/core/frame/csp/CSPSource.cpp
@@ -125,6 +125,38 @@ bool CSPSource::subsumes(CSPSource* other) {
return hostIsSubsumingOf && portIsSubsumingOf && pathIsSubsumingOf;
}
+bool CSPSource::isSimilar(CSPSource* other) {
+ bool schemesMatch =
+ schemeMatches(other->m_scheme) || other->schemeMatches(m_scheme);
+ if (!schemesMatch || isSchemeOnly() || other->isSchemeOnly())
+ return schemesMatch;
+ bool hostsMatch = (m_host == other->m_host) || hostMatches(other->m_host) ||
+ other->hostMatches(m_host);
+ bool portsMatch = (other->m_portWildcard == HasWildcard) ||
+ portMatches(other->m_port, other->m_scheme);
+ bool pathsMatch = pathMatches(other->m_path) || other->pathMatches(m_path);
+ if (hostsMatch && portsMatch && pathsMatch)
+ return true;
+
+ return false;
+}
+
+CSPSource* CSPSource::getNormalized(CSPSource* other) {
+ if (!isSimilar(other))
+ return nullptr;
+
+ String scheme = other->schemeMatches(m_scheme) ? m_scheme : other->m_scheme;
amalika 2016/11/04 10:42:40 It is easier to define `isSimilar` since every par
+ String host = m_hostWildcard == NoWildcard ? m_host : other->m_host;
+ String path = other->pathMatches(m_path) ? m_path : other->m_path;
+ int port = m_portWildcard == NoWildcard ? m_port : other->m_port;
jochen (gone - plz use gerrit) 2016/11/04 13:14:51 could it happen that m_port is 0 but other->m_port
+ WildcardDisposition hostWildcard =
+ (m_hostWildcard == HasWildcard) ? other->m_hostWildcard : m_hostWildcard;
+ WildcardDisposition portWildcard =
+ (m_portWildcard == HasWildcard) ? other->m_portWildcard : m_portWildcard;
+ return new CSPSource(m_policy, scheme, host, port, path, hostWildcard,
+ portWildcard);
+}
+
bool CSPSource::isSchemeOnly() const {
return m_host.isEmpty();
}

Powered by Google App Engine
This is Rietveld 408576698