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 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 | 98 |
99 if (!port) | 99 if (!port) |
100 return isDefaultPortForProtocol(m_port, protocol); | 100 return isDefaultPortForProtocol(m_port, protocol); |
101 | 101 |
102 if (!m_port) | 102 if (!m_port) |
103 return isDefaultPortForProtocol(port, protocol); | 103 return isDefaultPortForProtocol(port, protocol); |
104 | 104 |
105 return false; | 105 return false; |
106 } | 106 } |
107 | 107 |
108 bool CSPSource::subsumes(CSPSource* other) { | 108 bool CSPSource::subsumes(CSPSource* other) const { |
109 if (!schemeMatches(other->m_scheme)) | 109 if (!schemeMatches(other->m_scheme)) |
110 return false; | 110 return false; |
111 | 111 |
112 if (other->isSchemeOnly() || isSchemeOnly()) | 112 if (other->isSchemeOnly() || isSchemeOnly()) |
113 return isSchemeOnly(); | 113 return isSchemeOnly(); |
114 | 114 |
115 if ((m_hostWildcard == NoWildcard && other->m_hostWildcard == HasWildcard) || | 115 if ((m_hostWildcard == NoWildcard && other->m_hostWildcard == HasWildcard) || |
116 (m_portWildcard == NoWildcard && other->m_portWildcard == HasWildcard)) { | 116 (m_portWildcard == NoWildcard && other->m_portWildcard == HasWildcard)) { |
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) { | 127 bool CSPSource::isSimilar(CSPSource* other) const { |
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 bool pathsMatch = pathMatches(other->m_path) || other->pathMatches(m_path); | 136 bool pathsMatch = pathMatches(other->m_path) || other->pathMatches(m_path); |
137 if (hostsMatch && portsMatch && pathsMatch) | 137 if (hostsMatch && portsMatch && pathsMatch) |
138 return true; | 138 return true; |
139 | 139 |
140 return false; | 140 return false; |
141 } | 141 } |
142 | 142 |
143 CSPSource* CSPSource::intersect(CSPSource* other) { | 143 CSPSource* CSPSource::intersect(CSPSource* other) const { |
144 if (!isSimilar(other)) | 144 if (!isSimilar(other)) |
145 return nullptr; | 145 return nullptr; |
146 | 146 |
147 String scheme = other->schemeMatches(m_scheme) ? m_scheme : other->m_scheme; | 147 String scheme = other->schemeMatches(m_scheme) ? m_scheme : other->m_scheme; |
148 if (isSchemeOnly() || other->isSchemeOnly()) { | 148 if (isSchemeOnly() || other->isSchemeOnly()) { |
149 CSPSource* stricter = isSchemeOnly() ? other : this; | 149 const CSPSource* stricter = isSchemeOnly() ? other : this; |
150 return new CSPSource(m_policy, scheme, stricter->m_host, stricter->m_port, | 150 return new CSPSource(m_policy, scheme, stricter->m_host, stricter->m_port, |
151 stricter->m_path, stricter->m_hostWildcard, | 151 stricter->m_path, stricter->m_hostWildcard, |
152 stricter->m_portWildcard); | 152 stricter->m_portWildcard); |
153 } | 153 } |
154 | 154 |
155 String host = m_hostWildcard == NoWildcard ? m_host : other->m_host; | 155 String host = m_hostWildcard == NoWildcard ? m_host : other->m_host; |
156 String path = other->pathMatches(m_path) ? m_path : other->m_path; | 156 String path = other->pathMatches(m_path) ? m_path : other->m_path; |
157 int port = (other->m_portWildcard == HasWildcard || !other->m_port) | 157 int port = (other->m_portWildcard == HasWildcard || !other->m_port) |
158 ? m_port | 158 ? m_port |
159 : other->m_port; | 159 : other->m_port; |
160 WildcardDisposition hostWildcard = | 160 WildcardDisposition hostWildcard = |
161 (m_hostWildcard == HasWildcard) ? other->m_hostWildcard : m_hostWildcard; | 161 (m_hostWildcard == HasWildcard) ? other->m_hostWildcard : m_hostWildcard; |
162 WildcardDisposition portWildcard = | 162 WildcardDisposition portWildcard = |
163 (m_portWildcard == HasWildcard) ? other->m_portWildcard : m_portWildcard; | 163 (m_portWildcard == HasWildcard) ? other->m_portWildcard : m_portWildcard; |
164 return new CSPSource(m_policy, scheme, host, port, path, hostWildcard, | 164 return new CSPSource(m_policy, scheme, host, port, path, hostWildcard, |
165 portWildcard); | 165 portWildcard); |
166 } | 166 } |
167 | 167 |
168 bool CSPSource::isSchemeOnly() const { | 168 bool CSPSource::isSchemeOnly() const { |
169 return m_host.isEmpty(); | 169 return m_host.isEmpty(); |
170 } | 170 } |
171 | 171 |
172 bool CSPSource::firstSubsumesSecond(HeapVector<Member<CSPSource>> listA, | 172 bool CSPSource::firstSubsumesSecond( |
173 HeapVector<Member<CSPSource>> listB) { | 173 const HeapVector<Member<CSPSource>>& listA, |
| 174 const HeapVector<Member<CSPSource>>& listB) { |
174 // Empty vector of CSPSources has an effect of 'none'. | 175 // Empty vector of CSPSources has an effect of 'none'. |
175 if (!listA.size() || !listB.size()) | 176 if (!listA.size() || !listB.size()) |
176 return !listB.size(); | 177 return !listB.size(); |
177 | 178 |
178 // Walk through all the items in |listB|, ensuring that each is subsumed by at | 179 // Walk through all the items in |listB|, ensuring that each is subsumed by at |
179 // least one item in |listA|. If any item in |listB| is not subsumed, return | 180 // least one item in |listA|. If any item in |listB| is not subsumed, return |
180 // false. | 181 // false. |
181 for (const auto& sourceB : listB) { | 182 for (const auto& sourceB : listB) { |
182 bool foundMatch = false; | 183 bool foundMatch = false; |
183 for (const auto& sourceA : listA) { | 184 for (const auto& sourceA : listA) { |
184 if ((foundMatch = sourceA->subsumes(sourceB))) | 185 if ((foundMatch = sourceA->subsumes(sourceB))) |
185 break; | 186 break; |
186 } | 187 } |
187 if (!foundMatch) | 188 if (!foundMatch) |
188 return false; | 189 return false; |
189 } | 190 } |
190 return true; | 191 return true; |
191 } | 192 } |
192 | 193 |
193 DEFINE_TRACE(CSPSource) { | 194 DEFINE_TRACE(CSPSource) { |
194 visitor->trace(m_policy); | 195 visitor->trace(m_policy); |
195 } | 196 } |
196 | 197 |
197 } // namespace blink | 198 } // namespace blink |
OLD | NEW |