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(); |
} |