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

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 master 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 212b8ce74d3d96aa6f0850ae4276c97e303844a6..0d2dfe1a4f3665f150cde6ff3d3be7004ab91d68 100644
--- a/third_party/WebKit/Source/core/frame/csp/CSPSource.cpp
+++ b/third_party/WebKit/Source/core/frame/csp/CSPSource.cpp
@@ -124,6 +124,40 @@ bool CSPSource::subsumes(CSPSource* other) {
return hostSubsumes && portSubsumes && pathSubsumes;
}
+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::intersect(CSPSource* other) {
+ if (!isSimilar(other))
+ return nullptr;
+
+ String scheme = other->schemeMatches(m_scheme) ? m_scheme : other->m_scheme;
+ String host = m_hostWildcard == NoWildcard ? m_host : other->m_host;
+ String path = other->pathMatches(m_path) ? m_path : other->m_path;
+ int port = (other->m_portWildcard == HasWildcard || !other->m_port)
+ ? m_port
+ : 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();
}
« no previous file with comments | « third_party/WebKit/Source/core/frame/csp/CSPSource.h ('k') | third_party/WebKit/Source/core/frame/csp/CSPSourceTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698