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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "core/frame/csp/CSPSource.h" 5 #include "core/frame/csp/CSPSource.h"
6 6
7 #include "core/frame/UseCounter.h" 7 #include "core/frame/UseCounter.h"
8 #include "core/frame/csp/ContentSecurityPolicy.h" 8 #include "core/frame/csp/ContentSecurityPolicy.h"
9 #include "platform/weborigin/KURL.h" 9 #include "platform/weborigin/KURL.h"
10 #include "platform/weborigin/KnownPorts.h" 10 #include "platform/weborigin/KnownPorts.h"
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 return false; 117 return false;
118 } 118 }
119 119
120 bool hostSubsumes = (m_host == other->m_host || hostMatches(other->m_host)); 120 bool hostSubsumes = (m_host == other->m_host || hostMatches(other->m_host));
121 bool portSubsumes = (m_portWildcard == HasWildcard) || 121 bool portSubsumes = (m_portWildcard == HasWildcard) ||
122 portMatches(other->m_port, other->m_scheme); 122 portMatches(other->m_port, other->m_scheme);
123 bool pathSubsumes = pathMatches(other->m_path); 123 bool pathSubsumes = pathMatches(other->m_path);
124 return hostSubsumes && portSubsumes && pathSubsumes; 124 return hostSubsumes && portSubsumes && pathSubsumes;
125 } 125 }
126 126
127 bool CSPSource::isSimilar(CSPSource* other) {
128 bool schemesMatch =
129 schemeMatches(other->m_scheme) || other->schemeMatches(m_scheme);
130 if (!schemesMatch || isSchemeOnly() || other->isSchemeOnly())
131 return schemesMatch;
132 bool hostsMatch = (m_host == other->m_host) || hostMatches(other->m_host) ||
133 other->hostMatches(m_host);
134 bool portsMatch = (other->m_portWildcard == HasWildcard) ||
135 portMatches(other->m_port, other->m_scheme);
136 bool pathsMatch = pathMatches(other->m_path) || other->pathMatches(m_path);
137 if (hostsMatch && portsMatch && pathsMatch)
138 return true;
139
140 return false;
141 }
142
143 CSPSource* CSPSource::intersect(CSPSource* other) {
144 if (!isSimilar(other))
145 return nullptr;
146
147 String scheme = other->schemeMatches(m_scheme) ? m_scheme : other->m_scheme;
148 String host = m_hostWildcard == NoWildcard ? m_host : other->m_host;
149 String path = other->pathMatches(m_path) ? m_path : other->m_path;
150 int port = (other->m_portWildcard == HasWildcard || !other->m_port)
151 ? m_port
152 : other->m_port;
153 WildcardDisposition hostWildcard =
154 (m_hostWildcard == HasWildcard) ? other->m_hostWildcard : m_hostWildcard;
155 WildcardDisposition portWildcard =
156 (m_portWildcard == HasWildcard) ? other->m_portWildcard : m_portWildcard;
157 return new CSPSource(m_policy, scheme, host, port, path, hostWildcard,
158 portWildcard);
159 }
160
127 bool CSPSource::isSchemeOnly() const { 161 bool CSPSource::isSchemeOnly() const {
128 return m_host.isEmpty(); 162 return m_host.isEmpty();
129 } 163 }
130 164
131 DEFINE_TRACE(CSPSource) { 165 DEFINE_TRACE(CSPSource) {
132 visitor->trace(m_policy); 166 visitor->trace(m_policy);
133 } 167 }
134 168
135 } // namespace blink 169 } // namespace blink
OLDNEW
« 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