Chromium Code Reviews| 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 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 118 } | 118 } |
| 119 | 119 |
| 120 bool hostIsSubsumingOf = | 120 bool hostIsSubsumingOf = |
| 121 (m_host == other->m_host || hostMatches(other->m_host)); | 121 (m_host == other->m_host || hostMatches(other->m_host)); |
| 122 bool portIsSubsumingOf = (m_portWildcard == HasWildcard) || | 122 bool portIsSubsumingOf = (m_portWildcard == HasWildcard) || |
| 123 portMatches(other->m_port, other->m_scheme); | 123 portMatches(other->m_port, other->m_scheme); |
| 124 bool pathIsSubsumingOf = pathMatches(other->m_path); | 124 bool pathIsSubsumingOf = pathMatches(other->m_path); |
| 125 return hostIsSubsumingOf && portIsSubsumingOf && pathIsSubsumingOf; | 125 return hostIsSubsumingOf && portIsSubsumingOf && pathIsSubsumingOf; |
| 126 } | 126 } |
| 127 | 127 |
| 128 bool CSPSource::isSimilar(CSPSource* other) { | |
| 129 bool schemesMatch = | |
| 130 schemeMatches(other->m_scheme) || other->schemeMatches(m_scheme); | |
| 131 if (!schemesMatch || isSchemeOnly() || other->isSchemeOnly()) | |
| 132 return schemesMatch; | |
| 133 bool hostsMatch = (m_host == other->m_host) || hostMatches(other->m_host) || | |
| 134 other->hostMatches(m_host); | |
| 135 bool portsMatch = (other->m_portWildcard == HasWildcard) || | |
| 136 portMatches(other->m_port, other->m_scheme); | |
| 137 bool pathsMatch = pathMatches(other->m_path) || other->pathMatches(m_path); | |
| 138 if (hostsMatch && portsMatch && pathsMatch) | |
| 139 return true; | |
| 140 | |
| 141 return false; | |
| 142 } | |
| 143 | |
| 144 CSPSource* CSPSource::getNormalized(CSPSource* other) { | |
| 145 if (!isSimilar(other)) | |
| 146 return nullptr; | |
| 147 | |
| 148 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
| |
| 149 String host = m_hostWildcard == NoWildcard ? m_host : other->m_host; | |
| 150 String path = other->pathMatches(m_path) ? m_path : other->m_path; | |
| 151 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
| |
| 152 WildcardDisposition hostWildcard = | |
| 153 (m_hostWildcard == HasWildcard) ? other->m_hostWildcard : m_hostWildcard; | |
| 154 WildcardDisposition portWildcard = | |
| 155 (m_portWildcard == HasWildcard) ? other->m_portWildcard : m_portWildcard; | |
| 156 return new CSPSource(m_policy, scheme, host, port, path, hostWildcard, | |
| 157 portWildcard); | |
| 158 } | |
| 159 | |
| 128 bool CSPSource::isSchemeOnly() const { | 160 bool CSPSource::isSchemeOnly() const { |
| 129 return m_host.isEmpty(); | 161 return m_host.isEmpty(); |
| 130 } | 162 } |
| 131 | 163 |
| 132 DEFINE_TRACE(CSPSource) { | 164 DEFINE_TRACE(CSPSource) { |
| 133 visitor->trace(m_policy); | 165 visitor->trace(m_policy); |
| 134 } | 166 } |
| 135 | 167 |
| 136 } // namespace blink | 168 } // namespace blink |
| OLD | NEW |