| 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" |
| 11 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.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 "ipc/ipc_message_utils.h" | 16 #include "ipc/ipc_message_utils.h" |
| 17 #include "net/base/dns_util.h" | 17 #include "net/base/dns_util.h" |
| 18 #include "net/base/net_util.h" | 18 #include "net/base/net_util.h" |
| 19 #include "url/gurl.h" | 19 #include "url/gurl.h" |
| 20 #include "url/url_canon.h" | 20 #include "url/url_canon.h" |
| 21 | 21 |
| 22 namespace { | 22 namespace { |
| 23 | 23 |
| 24 std::string GetDefaultPort(const std::string& scheme) { | 24 std::string GetDefaultPort(const std::string& scheme) { |
| 25 if (scheme == content::kHttpScheme) | 25 if (scheme == url::kHttpScheme) |
| 26 return "80"; | 26 return "80"; |
| 27 if (scheme == content::kHttpsScheme) | 27 if (scheme == url::kHttpsScheme) |
| 28 return "443"; | 28 return "443"; |
| 29 return std::string(); | 29 return std::string(); |
| 30 } | 30 } |
| 31 | 31 |
| 32 // Returns true if |sub_domain| is a sub domain or equls |domain|. E.g. | 32 // Returns true if |sub_domain| is a sub domain or equls |domain|. E.g. |
| 33 // "mail.google.com" is a sub domain of "google.com" but "evilhost.com" is not a | 33 // "mail.google.com" is a sub domain of "google.com" but "evilhost.com" is not a |
| 34 // subdomain of "host.com". | 34 // subdomain of "host.com". |
| 35 bool IsSubDomainOrEqual(const std::string& sub_domain, | 35 bool IsSubDomainOrEqual(const std::string& sub_domain, |
| 36 const std::string& domain) { | 36 const std::string& domain) { |
| 37 // The empty string serves as wildcard. Each domain is a subdomain of the | 37 // The empty string serves as wildcard. Each domain is a subdomain of the |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 236 (parts.host.empty() && !parts.has_domain_wildcard) || | 236 (parts.host.empty() && !parts.has_domain_wildcard) || |
| 237 (parts.port.empty() && !parts.is_port_wildcard)) { | 237 (parts.port.empty() && !parts.is_port_wildcard)) { |
| 238 return false; | 238 return false; |
| 239 } | 239 } |
| 240 | 240 |
| 241 if (parts.host.find("*") != std::string::npos) | 241 if (parts.host.find("*") != std::string::npos) |
| 242 return false; | 242 return false; |
| 243 | 243 |
| 244 // Test if the scheme is supported or a wildcard. | 244 // Test if the scheme is supported or a wildcard. |
| 245 if (!parts.is_scheme_wildcard && | 245 if (!parts.is_scheme_wildcard && |
| 246 parts.scheme != std::string(content::kHttpScheme) && | 246 parts.scheme != std::string(url::kHttpScheme) && |
| 247 parts.scheme != std::string(content::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(content::kFileScheme) && |
| (...skipping 13 matching lines...) Expand all Loading... |
| 271 | 271 |
| 272 // Non-file patterns are invalid if either the scheme, host or port part is | 272 // Non-file patterns are invalid if either the scheme, host or port part is |
| 273 // empty. | 273 // empty. |
| 274 if ((!parts.is_scheme_wildcard) || | 274 if ((!parts.is_scheme_wildcard) || |
| 275 (parts.host.empty() && !parts.has_domain_wildcard) || | 275 (parts.host.empty() && !parts.has_domain_wildcard) || |
| 276 (!parts.is_port_wildcard)) | 276 (!parts.is_port_wildcard)) |
| 277 return false; | 277 return false; |
| 278 | 278 |
| 279 // Test if the scheme is supported or a wildcard. | 279 // Test if the scheme is supported or a wildcard. |
| 280 if (!parts.is_scheme_wildcard && | 280 if (!parts.is_scheme_wildcard && |
| 281 parts.scheme != std::string(content::kHttpScheme) && | 281 parts.scheme != std::string(url::kHttpScheme) && |
| 282 parts.scheme != std::string(content::kHttpsScheme)) { | 282 parts.scheme != std::string(url::kHttpsScheme)) { |
| 283 return false; | 283 return false; |
| 284 } | 284 } |
| 285 return true; | 285 return true; |
| 286 } | 286 } |
| 287 | 287 |
| 288 // //////////////////////////////////////////////////////////////////////////// | 288 // //////////////////////////////////////////////////////////////////////////// |
| 289 // ContentSettingsPattern::PatternParts | 289 // ContentSettingsPattern::PatternParts |
| 290 // | 290 // |
| 291 ContentSettingsPattern::PatternParts::PatternParts() | 291 ContentSettingsPattern::PatternParts::PatternParts() |
| 292 : is_scheme_wildcard(false), | 292 : is_scheme_wildcard(false), |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 332 if (url.SchemeIsFileSystem() && url.inner_url()) { | 332 if (url.SchemeIsFileSystem() && url.inner_url()) { |
| 333 local_url = url.inner_url(); | 333 local_url = url.inner_url(); |
| 334 } | 334 } |
| 335 if (local_url->SchemeIsFile()) { | 335 if (local_url->SchemeIsFile()) { |
| 336 builder->WithScheme(local_url->scheme())->WithPath(local_url->path()); | 336 builder->WithScheme(local_url->scheme())->WithPath(local_url->path()); |
| 337 } else { | 337 } else { |
| 338 // Please keep the order of the ifs below as URLs with an IP as host can | 338 // Please keep the order of the ifs below as URLs with an IP as host can |
| 339 // also have a "http" scheme. | 339 // also have a "http" scheme. |
| 340 if (local_url->HostIsIPAddress()) { | 340 if (local_url->HostIsIPAddress()) { |
| 341 builder->WithScheme(local_url->scheme())->WithHost(local_url->host()); | 341 builder->WithScheme(local_url->scheme())->WithHost(local_url->host()); |
| 342 } else if (local_url->SchemeIs(content::kHttpScheme)) { | 342 } else if (local_url->SchemeIs(url::kHttpScheme)) { |
| 343 builder->WithSchemeWildcard()->WithDomainWildcard()->WithHost( | 343 builder->WithSchemeWildcard()->WithDomainWildcard()->WithHost( |
| 344 local_url->host()); | 344 local_url->host()); |
| 345 } else if (local_url->SchemeIs(content::kHttpsScheme)) { | 345 } else if (local_url->SchemeIs(url::kHttpsScheme)) { |
| 346 builder->WithScheme(local_url->scheme())->WithDomainWildcard()->WithHost( | 346 builder->WithScheme(local_url->scheme())->WithDomainWildcard()->WithHost( |
| 347 local_url->host()); | 347 local_url->host()); |
| 348 } else { | 348 } else { |
| 349 // Unsupported scheme | 349 // Unsupported scheme |
| 350 } | 350 } |
| 351 if (local_url->port().empty()) { | 351 if (local_url->port().empty()) { |
| 352 if (local_url->SchemeIs(content::kHttpsScheme)) | 352 if (local_url->SchemeIs(url::kHttpsScheme)) |
| 353 builder->WithPort(GetDefaultPort(content::kHttpsScheme)); | 353 builder->WithPort(GetDefaultPort(url::kHttpsScheme)); |
| 354 else | 354 else |
| 355 builder->WithPortWildcard(); | 355 builder->WithPortWildcard(); |
| 356 } else { | 356 } else { |
| 357 builder->WithPort(local_url->port()); | 357 builder->WithPort(local_url->port()); |
| 358 } | 358 } |
| 359 } | 359 } |
| 360 return builder->Build(); | 360 return builder->Build(); |
| 361 } | 361 } |
| 362 | 362 |
| 363 // static | 363 // static |
| (...skipping 310 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 |