OLD | NEW |
---|---|
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 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
125 } | 125 } |
126 | 126 |
127 bool CSPSource::isSimilar(CSPSource* other) { | 127 bool CSPSource::isSimilar(CSPSource* other) { |
128 bool schemesMatch = | 128 bool schemesMatch = |
129 schemeMatches(other->m_scheme) || other->schemeMatches(m_scheme); | 129 schemeMatches(other->m_scheme) || other->schemeMatches(m_scheme); |
130 if (!schemesMatch || isSchemeOnly() || other->isSchemeOnly()) | 130 if (!schemesMatch || isSchemeOnly() || other->isSchemeOnly()) |
131 return schemesMatch; | 131 return schemesMatch; |
132 bool hostsMatch = (m_host == other->m_host) || hostMatches(other->m_host) || | 132 bool hostsMatch = (m_host == other->m_host) || hostMatches(other->m_host) || |
133 other->hostMatches(m_host); | 133 other->hostMatches(m_host); |
134 bool portsMatch = (other->m_portWildcard == HasWildcard) || | 134 bool portsMatch = (other->m_portWildcard == HasWildcard) || |
135 portMatches(other->m_port, other->m_scheme); | 135 portMatches(other->m_port, other->m_scheme) || |
136 other->portMatches(m_port, m_scheme); | |
136 bool pathsMatch = pathMatches(other->m_path) || other->pathMatches(m_path); | 137 bool pathsMatch = pathMatches(other->m_path) || other->pathMatches(m_path); |
137 if (hostsMatch && portsMatch && pathsMatch) | 138 if (hostsMatch && portsMatch && pathsMatch) |
138 return true; | 139 return true; |
139 | 140 |
140 return false; | 141 return false; |
141 } | 142 } |
142 | 143 |
143 CSPSource* CSPSource::intersect(CSPSource* other) { | 144 CSPSource* CSPSource::intersect(CSPSource* other) { |
144 if (!isSimilar(other)) | 145 if (!isSimilar(other)) |
145 return nullptr; | 146 return nullptr; |
146 | 147 |
147 String scheme = other->schemeMatches(m_scheme) ? m_scheme : other->m_scheme; | 148 String scheme = other->schemeMatches(m_scheme) ? m_scheme : other->m_scheme; |
148 if (isSchemeOnly() || other->isSchemeOnly()) { | 149 if (isSchemeOnly() || other->isSchemeOnly()) { |
149 CSPSource* stricter = isSchemeOnly() ? other : this; | 150 CSPSource* stricter = isSchemeOnly() ? other : this; |
150 return new CSPSource(m_policy, scheme, stricter->m_host, stricter->m_port, | 151 return new CSPSource(m_policy, scheme, stricter->m_host, stricter->m_port, |
151 stricter->m_path, stricter->m_hostWildcard, | 152 stricter->m_path, stricter->m_hostWildcard, |
152 stricter->m_portWildcard); | 153 stricter->m_portWildcard); |
153 } | 154 } |
154 | 155 |
155 String host = m_hostWildcard == NoWildcard ? m_host : other->m_host; | 156 String host = m_hostWildcard == NoWildcard ? m_host : other->m_host; |
156 String path = other->pathMatches(m_path) ? m_path : other->m_path; | 157 String path = other->pathMatches(m_path) ? m_path : other->m_path; |
157 int port = (other->m_portWildcard == HasWildcard || !other->m_port) | 158 int port = (other->m_portWildcard == HasWildcard || !other->m_port || |
159 m_scheme.length() > other->m_scheme.length()) | |
amalika
2016/12/06 09:29:13
By this point, we know that A and B are similar, i
Mike West
2016/12/06 13:41:09
Can you spell this out, please? Reading `http` and
| |
158 ? m_port | 160 ? m_port |
159 : other->m_port; | 161 : other->m_port; |
160 WildcardDisposition hostWildcard = | 162 WildcardDisposition hostWildcard = |
161 (m_hostWildcard == HasWildcard) ? other->m_hostWildcard : m_hostWildcard; | 163 (m_hostWildcard == HasWildcard) ? other->m_hostWildcard : m_hostWildcard; |
162 WildcardDisposition portWildcard = | 164 WildcardDisposition portWildcard = |
163 (m_portWildcard == HasWildcard) ? other->m_portWildcard : m_portWildcard; | 165 (m_portWildcard == HasWildcard) ? other->m_portWildcard : m_portWildcard; |
164 return new CSPSource(m_policy, scheme, host, port, path, hostWildcard, | 166 return new CSPSource(m_policy, scheme, host, port, path, hostWildcard, |
165 portWildcard); | 167 portWildcard); |
166 } | 168 } |
167 | 169 |
(...skipping 20 matching lines...) Expand all Loading... | |
188 return false; | 190 return false; |
189 } | 191 } |
190 return true; | 192 return true; |
191 } | 193 } |
192 | 194 |
193 DEFINE_TRACE(CSPSource) { | 195 DEFINE_TRACE(CSPSource) { |
194 visitor->trace(m_policy); | 196 visitor->trace(m_policy); |
195 } | 197 } |
196 | 198 |
197 } // namespace blink | 199 } // namespace blink |
OLD | NEW |