| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/common/content_settings_pattern.h" | 5 #include "chrome/common/content_settings_pattern.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/strings/string_split.h" | 10 #include "base/strings/string_split.h" |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 | 172 |
| 173 return ContentSettingsPattern(parts_, is_valid_); | 173 return ContentSettingsPattern(parts_, is_valid_); |
| 174 } | 174 } |
| 175 | 175 |
| 176 // static | 176 // static |
| 177 bool ContentSettingsPattern::Builder::Canonicalize(PatternParts* parts) { | 177 bool ContentSettingsPattern::Builder::Canonicalize(PatternParts* parts) { |
| 178 // Canonicalize the scheme part. | 178 // Canonicalize the scheme part. |
| 179 const std::string scheme(StringToLowerASCII(parts->scheme)); | 179 const std::string scheme(StringToLowerASCII(parts->scheme)); |
| 180 parts->scheme = scheme; | 180 parts->scheme = scheme; |
| 181 | 181 |
| 182 if (parts->scheme == std::string(content::kFileScheme) && | 182 if (parts->scheme == std::string(url::kFileScheme) && |
| 183 !parts->is_path_wildcard) { | 183 !parts->is_path_wildcard) { |
| 184 GURL url(std::string(content::kFileScheme) + | 184 GURL url(std::string(url::kFileScheme) + |
| 185 std::string(content::kStandardSchemeSeparator) + parts->path); | 185 std::string(content::kStandardSchemeSeparator) + parts->path); |
| 186 parts->path = url.path(); | 186 parts->path = url.path(); |
| 187 } | 187 } |
| 188 | 188 |
| 189 // Canonicalize the host part. | 189 // Canonicalize the host part. |
| 190 const std::string host(parts->host); | 190 const std::string host(parts->host); |
| 191 url::CanonHostInfo host_info; | 191 url::CanonHostInfo host_info; |
| 192 std::string canonicalized_host(net::CanonicalizeHost(host, &host_info)); | 192 std::string canonicalized_host(net::CanonicalizeHost(host, &host_info)); |
| 193 if (host_info.IsIPAddress() && parts->has_domain_wildcard) | 193 if (host_info.IsIPAddress() && parts->has_domain_wildcard) |
| 194 return false; | 194 return false; |
| 195 canonicalized_host = net::TrimEndingDot(canonicalized_host); | 195 canonicalized_host = net::TrimEndingDot(canonicalized_host); |
| 196 | 196 |
| 197 parts->host = ""; | 197 parts->host = ""; |
| 198 if ((host.find('*') == std::string::npos) && | 198 if ((host.find('*') == std::string::npos) && |
| 199 !canonicalized_host.empty()) { | 199 !canonicalized_host.empty()) { |
| 200 // Valid host. | 200 // Valid host. |
| 201 parts->host += canonicalized_host; | 201 parts->host += canonicalized_host; |
| 202 } | 202 } |
| 203 return true; | 203 return true; |
| 204 } | 204 } |
| 205 | 205 |
| 206 // static | 206 // static |
| 207 bool ContentSettingsPattern::Builder::Validate(const PatternParts& parts) { | 207 bool ContentSettingsPattern::Builder::Validate(const PatternParts& parts) { |
| 208 // Sanity checks first: {scheme, port} wildcards imply empty {scheme, port}. | 208 // Sanity checks first: {scheme, port} wildcards imply empty {scheme, port}. |
| 209 if ((parts.is_scheme_wildcard && !parts.scheme.empty()) || | 209 if ((parts.is_scheme_wildcard && !parts.scheme.empty()) || |
| 210 (parts.is_port_wildcard && !parts.port.empty())) { | 210 (parts.is_port_wildcard && !parts.port.empty())) { |
| 211 NOTREACHED(); | 211 NOTREACHED(); |
| 212 return false; | 212 return false; |
| 213 } | 213 } |
| 214 | 214 |
| 215 // file:// URL patterns have an empty host and port. | 215 // file:// URL patterns have an empty host and port. |
| 216 if (parts.scheme == std::string(content::kFileScheme)) { | 216 if (parts.scheme == std::string(url::kFileScheme)) { |
| 217 if (parts.has_domain_wildcard || !parts.host.empty() || !parts.port.empty()) | 217 if (parts.has_domain_wildcard || !parts.host.empty() || !parts.port.empty()) |
| 218 return false; | 218 return false; |
| 219 if (parts.is_path_wildcard) | 219 if (parts.is_path_wildcard) |
| 220 return parts.path.empty(); | 220 return parts.path.empty(); |
| 221 return (!parts.path.empty() && | 221 return (!parts.path.empty() && |
| 222 parts.path != "/" && | 222 parts.path != "/" && |
| 223 parts.path.find("*") == std::string::npos); | 223 parts.path.find("*") == std::string::npos); |
| 224 } | 224 } |
| 225 | 225 |
| 226 // If the pattern is for an extension URL test if it is valid. | 226 // If the pattern is for an extension URL test if it is valid. |
| (...skipping 20 matching lines...) Expand all Loading... |
| 247 parts.scheme != std::string(url::kHttpsScheme)) { | 247 parts.scheme != std::string(url::kHttpsScheme)) { |
| 248 return false; | 248 return false; |
| 249 } | 249 } |
| 250 return true; | 250 return true; |
| 251 } | 251 } |
| 252 | 252 |
| 253 // static | 253 // static |
| 254 bool ContentSettingsPattern::Builder::LegacyValidate( | 254 bool ContentSettingsPattern::Builder::LegacyValidate( |
| 255 const PatternParts& parts) { | 255 const PatternParts& parts) { |
| 256 // If the pattern is for a "file-pattern" test if it is valid. | 256 // If the pattern is for a "file-pattern" test if it is valid. |
| 257 if (parts.scheme == std::string(content::kFileScheme) && | 257 if (parts.scheme == std::string(url::kFileScheme) && |
| 258 !parts.is_scheme_wildcard && | 258 !parts.is_scheme_wildcard && |
| 259 parts.host.empty() && | 259 parts.host.empty() && |
| 260 parts.port.empty()) | 260 parts.port.empty()) |
| 261 return true; | 261 return true; |
| 262 | 262 |
| 263 // If the pattern is for an extension URL test if it is valid. | 263 // If the pattern is for an extension URL test if it is valid. |
| 264 if (parts.scheme == std::string(extensions::kExtensionScheme) && | 264 if (parts.scheme == std::string(extensions::kExtensionScheme) && |
| 265 !parts.is_scheme_wildcard && | 265 !parts.is_scheme_wildcard && |
| 266 !parts.host.empty() && | 266 !parts.host.empty() && |
| 267 !parts.has_domain_wildcard && | 267 !parts.has_domain_wildcard && |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 450 return false; | 450 return false; |
| 451 } | 451 } |
| 452 | 452 |
| 453 // File URLs have no host. Matches if the pattern has the path wildcard set, | 453 // File URLs have no host. Matches if the pattern has the path wildcard set, |
| 454 // or if the path in the URL is identical to the one in the pattern. | 454 // or if the path in the URL is identical to the one in the pattern. |
| 455 // For filesystem:file URLs, the path used is the filesystem type, so all | 455 // For filesystem:file URLs, the path used is the filesystem type, so all |
| 456 // filesystem:file:///temporary/... are equivalent. | 456 // filesystem:file:///temporary/... are equivalent. |
| 457 // TODO(markusheintz): Content settings should be defined for all files on | 457 // TODO(markusheintz): Content settings should be defined for all files on |
| 458 // a machine. Unless there is a good use case for supporting paths for file | 458 // a machine. Unless there is a good use case for supporting paths for file |
| 459 // patterns, stop supporting path for file patterns. | 459 // patterns, stop supporting path for file patterns. |
| 460 if (!parts_.is_scheme_wildcard && scheme == content::kFileScheme) | 460 if (!parts_.is_scheme_wildcard && scheme == url::kFileScheme) |
| 461 return parts_.is_path_wildcard || | 461 return parts_.is_path_wildcard || |
| 462 parts_.path == std::string(local_url->path()); | 462 parts_.path == std::string(local_url->path()); |
| 463 | 463 |
| 464 // Match the host part. | 464 // Match the host part. |
| 465 const std::string host(net::TrimEndingDot(local_url->host())); | 465 const std::string host(net::TrimEndingDot(local_url->host())); |
| 466 if (!parts_.has_domain_wildcard) { | 466 if (!parts_.has_domain_wildcard) { |
| 467 if (parts_.host != host) | 467 if (parts_.host != host) |
| 468 return false; | 468 return false; |
| 469 } else { | 469 } else { |
| 470 if (!IsSubDomainOrEqual(host, parts_.host)) | 470 if (!IsSubDomainOrEqual(host, parts_.host)) |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 674 if (!parts.is_port_wildcard && other_parts.is_port_wildcard) | 674 if (!parts.is_port_wildcard && other_parts.is_port_wildcard) |
| 675 return ContentSettingsPattern::PREDECESSOR; | 675 return ContentSettingsPattern::PREDECESSOR; |
| 676 | 676 |
| 677 int result = parts.port.compare(other_parts.port); | 677 int result = parts.port.compare(other_parts.port); |
| 678 if (result == 0) | 678 if (result == 0) |
| 679 return ContentSettingsPattern::IDENTITY; | 679 return ContentSettingsPattern::IDENTITY; |
| 680 if (result > 0) | 680 if (result > 0) |
| 681 return ContentSettingsPattern::DISJOINT_ORDER_PRE; | 681 return ContentSettingsPattern::DISJOINT_ORDER_PRE; |
| 682 return ContentSettingsPattern::DISJOINT_ORDER_POST; | 682 return ContentSettingsPattern::DISJOINT_ORDER_POST; |
| 683 } | 683 } |
| OLD | NEW |