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/string_util.h" | 10 #include "base/string_util.h" |
11 #include "base/strings/string_split.h" | 11 #include "base/strings/string_split.h" |
12 #include "chrome/common/content_settings_pattern_parser.h" | 12 #include "chrome/common/content_settings_pattern_parser.h" |
13 #include "chrome/common/render_messages.h" | 13 #include "chrome/common/render_messages.h" |
14 #include "chrome/common/url_constants.h" | 14 #include "chrome/common/url_constants.h" |
15 #include "extensions/common/constants.h" | 15 #include "extensions/common/constants.h" |
16 #include "googleurl/src/gurl.h" | 16 #include "googleurl/src/gurl.h" |
17 #include "googleurl/src/url_canon.h" | 17 #include "googleurl/src/url_canon.h" |
18 #include "ipc/ipc_message_utils.h" | 18 #include "ipc/ipc_message_utils.h" |
19 #include "net/base/dns_util.h" | |
20 #include "net/base/net_util.h" | 19 #include "net/base/net_util.h" |
21 | 20 |
22 namespace { | 21 namespace { |
23 | 22 |
24 std::string GetDefaultPort(const std::string& scheme) { | 23 std::string GetDefaultPort(const std::string& scheme) { |
25 if (scheme == chrome::kHttpScheme) | 24 if (scheme == chrome::kHttpScheme) |
26 return "80"; | 25 return "80"; |
27 if (scheme == chrome::kHttpsScheme) | 26 if (scheme == chrome::kHttpsScheme) |
28 return "443"; | 27 return "443"; |
29 return ""; | 28 return ""; |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
71 if (i1 > i2) | 70 if (i1 > i2) |
72 return 1; | 71 return 1; |
73 | 72 |
74 if (i1 < i2) | 73 if (i1 < i2) |
75 return -1; | 74 return -1; |
76 | 75 |
77 // The domain names are identical. | 76 // The domain names are identical. |
78 return 0; | 77 return 0; |
79 } | 78 } |
80 | 79 |
80 std::string TrimEndingDots(const base::StringPiece& host) { | |
81 size_t len = host.length(); | |
82 while (len > 1 && host[len - 1] == '.') { | |
83 --len; | |
84 } | |
85 return host.substr(0, len).as_string(); | |
86 } | |
87 | |
81 typedef ContentSettingsPattern::BuilderInterface BuilderInterface; | 88 typedef ContentSettingsPattern::BuilderInterface BuilderInterface; |
82 | 89 |
83 } // namespace | 90 } // namespace |
84 | 91 |
85 // //////////////////////////////////////////////////////////////////////////// | 92 // //////////////////////////////////////////////////////////////////////////// |
86 // ContentSettingsPattern::Builder | 93 // ContentSettingsPattern::Builder |
87 // | 94 // |
88 ContentSettingsPattern::Builder::Builder(bool use_legacy_validate) | 95 ContentSettingsPattern::Builder::Builder(bool use_legacy_validate) |
89 : is_valid_(true), | 96 : is_valid_(true), |
90 use_legacy_validate_(use_legacy_validate) {} | 97 use_legacy_validate_(use_legacy_validate) {} |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
171 std::string(content::kStandardSchemeSeparator) + parts->path); | 178 std::string(content::kStandardSchemeSeparator) + parts->path); |
172 parts->path = url.path(); | 179 parts->path = url.path(); |
173 } | 180 } |
174 | 181 |
175 // Canonicalize the host part. | 182 // Canonicalize the host part. |
176 const std::string host(parts->host); | 183 const std::string host(parts->host); |
177 url_canon::CanonHostInfo host_info; | 184 url_canon::CanonHostInfo host_info; |
178 std::string canonicalized_host(net::CanonicalizeHost(host, &host_info)); | 185 std::string canonicalized_host(net::CanonicalizeHost(host, &host_info)); |
179 if (host_info.IsIPAddress() && parts->has_domain_wildcard) | 186 if (host_info.IsIPAddress() && parts->has_domain_wildcard) |
180 return false; | 187 return false; |
181 canonicalized_host = net::TrimEndingDot(canonicalized_host); | 188 canonicalized_host = TrimEndingDots(canonicalized_host); |
jochen (gone - plz use gerrit)
2013/04/02 08:09:36
this change seems wrong. I'll comment on the bug r
yhirano
2013/04/02 17:38:24
Done.
| |
182 | 189 |
183 parts->host = ""; | 190 parts->host = ""; |
184 if ((host.find('*') == std::string::npos) && | 191 if ((host.find('*') == std::string::npos) && |
185 !canonicalized_host.empty()) { | 192 !canonicalized_host.empty()) { |
186 // Valid host. | 193 // Valid host. |
187 parts->host += canonicalized_host; | 194 parts->host += canonicalized_host; |
188 } | 195 } |
189 return true; | 196 return true; |
190 } | 197 } |
191 | 198 |
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
441 // For filesystem:file URLs, the path used is the filesystem type, so all | 448 // For filesystem:file URLs, the path used is the filesystem type, so all |
442 // filesystem:file:///temporary/... are equivalent. | 449 // filesystem:file:///temporary/... are equivalent. |
443 // TODO(markusheintz): Content settings should be defined for all files on | 450 // TODO(markusheintz): Content settings should be defined for all files on |
444 // a machine. Unless there is a good use case for supporting paths for file | 451 // a machine. Unless there is a good use case for supporting paths for file |
445 // patterns, stop supporting path for file patterns. | 452 // patterns, stop supporting path for file patterns. |
446 if (!parts_.is_scheme_wildcard && scheme == chrome::kFileScheme) | 453 if (!parts_.is_scheme_wildcard && scheme == chrome::kFileScheme) |
447 return parts_.is_path_wildcard || | 454 return parts_.is_path_wildcard || |
448 parts_.path == std::string(local_url->path()); | 455 parts_.path == std::string(local_url->path()); |
449 | 456 |
450 // Match the host part. | 457 // Match the host part. |
451 const std::string host(net::TrimEndingDot(local_url->host())); | 458 const std::string host(TrimEndingDots(local_url->host())); |
452 if (!parts_.has_domain_wildcard) { | 459 if (!parts_.has_domain_wildcard) { |
453 if (parts_.host != host) | 460 if (parts_.host != host) |
454 return false; | 461 return false; |
455 } else { | 462 } else { |
456 if (!IsSubDomainOrEqual(host, parts_.host)) | 463 if (!IsSubDomainOrEqual(host, parts_.host)) |
457 return false; | 464 return false; |
458 } | 465 } |
459 | 466 |
460 // For chrome extensions URLs ignore the port. | 467 // For chrome extensions URLs ignore the port. |
461 if (parts_.scheme == std::string(extensions::kExtensionScheme)) | 468 if (parts_.scheme == std::string(extensions::kExtensionScheme)) |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
660 if (!parts.is_port_wildcard && other_parts.is_port_wildcard) | 667 if (!parts.is_port_wildcard && other_parts.is_port_wildcard) |
661 return ContentSettingsPattern::PREDECESSOR; | 668 return ContentSettingsPattern::PREDECESSOR; |
662 | 669 |
663 int result = parts.port.compare(other_parts.port); | 670 int result = parts.port.compare(other_parts.port); |
664 if (result == 0) | 671 if (result == 0) |
665 return ContentSettingsPattern::IDENTITY; | 672 return ContentSettingsPattern::IDENTITY; |
666 if (result > 0) | 673 if (result > 0) |
667 return ContentSettingsPattern::DISJOINT_ORDER_PRE; | 674 return ContentSettingsPattern::DISJOINT_ORDER_PRE; |
668 return ContentSettingsPattern::DISJOINT_ORDER_POST; | 675 return ContentSettingsPattern::DISJOINT_ORDER_POST; |
669 } | 676 } |
OLD | NEW |