| 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 "components/content_settings/core/common/content_settings_pattern.h" | 5 #include "components/content_settings/core/common/content_settings_pattern.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/strings/string_split.h" | 13 #include "base/strings/string_split.h" |
| 14 #include "base/strings/string_util.h" | 14 #include "base/strings/string_util.h" |
| 15 #include "components/content_settings/core/common/content_settings_pattern_parse
r.h" | 15 #include "components/content_settings/core/common/content_settings_pattern_parse
r.h" |
| 16 #include "components/crx_file/id_util.h" |
| 16 #include "net/base/url_util.h" | 17 #include "net/base/url_util.h" |
| 17 #include "url/gurl.h" | 18 #include "url/gurl.h" |
| 18 | 19 |
| 19 namespace { | 20 namespace { |
| 20 | 21 |
| 21 // The component supports only one scheme for simplicity. | 22 // The component supports only one scheme for simplicity. |
| 22 const char* non_port_non_domain_wildcard_scheme = NULL; | 23 const char* non_port_non_domain_wildcard_scheme = NULL; |
| 23 | 24 |
| 25 // Hardcode this value to avoid additional dependency. |
| 26 const char kExtensionScheme[] = "chrome-extension"; |
| 27 |
| 24 // Keep it consistent with enum SchemeType in content_settings_pattern.h. | 28 // Keep it consistent with enum SchemeType in content_settings_pattern.h. |
| 25 const char* const kSchemeNames[] = { | 29 const char* const kSchemeNames[] = { |
| 26 "wildcard", | 30 "wildcard", |
| 27 "other", | 31 "other", |
| 28 url::kHttpScheme, | 32 url::kHttpScheme, |
| 29 url::kHttpsScheme, | 33 url::kHttpsScheme, |
| 30 url::kFileScheme, | 34 url::kFileScheme, |
| 31 "chrome-extension", | 35 kExtensionScheme, |
| 32 }; | 36 }; |
| 33 | 37 |
| 34 static_assert(arraysize(kSchemeNames) == ContentSettingsPattern::SCHEME_MAX, | 38 static_assert(arraysize(kSchemeNames) == ContentSettingsPattern::SCHEME_MAX, |
| 35 "kSchemeNames should have SCHEME_MAX elements"); | 39 "kSchemeNames should have SCHEME_MAX elements"); |
| 36 | 40 |
| 37 std::string GetDefaultPort(const std::string& scheme) { | 41 std::string GetDefaultPort(const std::string& scheme) { |
| 38 if (scheme == url::kHttpScheme) | 42 if (scheme == url::kHttpScheme) |
| 39 return "80"; | 43 return "80"; |
| 40 if (scheme == url::kHttpsScheme) | 44 if (scheme == url::kHttpsScheme) |
| 41 return "443"; | 45 return "443"; |
| (...skipping 484 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 526 : is_valid_(false) { | 530 : is_valid_(false) { |
| 527 } | 531 } |
| 528 | 532 |
| 529 ContentSettingsPattern::ContentSettingsPattern( | 533 ContentSettingsPattern::ContentSettingsPattern( |
| 530 const PatternParts& parts, | 534 const PatternParts& parts, |
| 531 bool valid) | 535 bool valid) |
| 532 : parts_(parts), | 536 : parts_(parts), |
| 533 is_valid_(valid) { | 537 is_valid_(valid) { |
| 534 } | 538 } |
| 535 | 539 |
| 540 bool ContentSettingsPattern::MatchesExtensionUrls() const { |
| 541 // Check if the host pattern matches an extension ID. This can happen in two |
| 542 // cases: |
| 543 // 1. Host pattern is a valid extension ID. |
| 544 // 2. Host pattern has a wildcard and hostname is empty. This means the host |
| 545 // pattern is simply "*" and not a subdomain pattern like "[*.]google.com." |
| 546 const bool host_pattern_matches_extension_id = |
| 547 crx_file::id_util::IdIsValid(parts_.host) || |
| 548 (parts_.has_domain_wildcard && parts_.host.empty()); |
| 549 return host_pattern_matches_extension_id && |
| 550 (parts_.is_scheme_wildcard || parts_.scheme == kExtensionScheme); |
| 551 } |
| 552 |
| 536 bool ContentSettingsPattern::Matches( | 553 bool ContentSettingsPattern::Matches( |
| 537 const GURL& url) const { | 554 const GURL& url) const { |
| 538 // An invalid pattern matches nothing. | 555 // An invalid pattern matches nothing. |
| 539 if (!is_valid_) | 556 if (!is_valid_) |
| 540 return false; | 557 return false; |
| 541 | 558 |
| 542 const GURL* local_url = &url; | 559 const GURL* local_url = &url; |
| 543 if (url.SchemeIsFileSystem() && url.inner_url()) { | 560 if (url.SchemeIsFileSystem() && url.inner_url()) { |
| 544 local_url = url.inner_url(); | 561 local_url = url.inner_url(); |
| 545 } | 562 } |
| (...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 821 if (!parts.is_path_wildcard && other_parts.is_path_wildcard) | 838 if (!parts.is_path_wildcard && other_parts.is_path_wildcard) |
| 822 return ContentSettingsPattern::PREDECESSOR; | 839 return ContentSettingsPattern::PREDECESSOR; |
| 823 | 840 |
| 824 int result = parts.path.compare(other_parts.path); | 841 int result = parts.path.compare(other_parts.path); |
| 825 if (result == 0) | 842 if (result == 0) |
| 826 return ContentSettingsPattern::IDENTITY; | 843 return ContentSettingsPattern::IDENTITY; |
| 827 if (result > 0) | 844 if (result > 0) |
| 828 return ContentSettingsPattern::DISJOINT_ORDER_PRE; | 845 return ContentSettingsPattern::DISJOINT_ORDER_PRE; |
| 829 return ContentSettingsPattern::DISJOINT_ORDER_POST; | 846 return ContentSettingsPattern::DISJOINT_ORDER_POST; |
| 830 } | 847 } |
| OLD | NEW |