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 "chrome/browser/supervised_user/supervised_user_url_filter.h" | 5 #include "chrome/browser/supervised_user/supervised_user_url_filter.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <set> | 10 #include <set> |
(...skipping 21 matching lines...) Expand all Loading... |
32 #include "url/gurl.h" | 32 #include "url/gurl.h" |
33 #include "url/url_constants.h" | 33 #include "url/url_constants.h" |
34 | 34 |
35 #if defined(ENABLE_EXTENSIONS) | 35 #if defined(ENABLE_EXTENSIONS) |
36 #include "extensions/common/extension_urls.h" | 36 #include "extensions/common/extension_urls.h" |
37 #endif | 37 #endif |
38 | 38 |
39 using content::BrowserThread; | 39 using content::BrowserThread; |
40 using net::registry_controlled_domains::EXCLUDE_UNKNOWN_REGISTRIES; | 40 using net::registry_controlled_domains::EXCLUDE_UNKNOWN_REGISTRIES; |
41 using net::registry_controlled_domains::EXCLUDE_PRIVATE_REGISTRIES; | 41 using net::registry_controlled_domains::EXCLUDE_PRIVATE_REGISTRIES; |
42 using net::registry_controlled_domains::GetRegistryLength; | 42 using net::registry_controlled_domains::GetCanonicalHostRegistryLength; |
43 using policy::URLBlacklist; | 43 using policy::URLBlacklist; |
44 using url_matcher::URLMatcher; | 44 using url_matcher::URLMatcher; |
45 using url_matcher::URLMatcherConditionSet; | 45 using url_matcher::URLMatcherConditionSet; |
46 | 46 |
47 using HostnameHash = SupervisedUserSiteList::HostnameHash; | 47 using HostnameHash = SupervisedUserSiteList::HostnameHash; |
48 | 48 |
49 namespace { | 49 namespace { |
50 | 50 |
51 struct HashHostnameHash { | 51 struct HashHostnameHash { |
52 size_t operator()(const HostnameHash& value) const { | 52 size_t operator()(const HostnameHash& value) const { |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
273 // static | 273 // static |
274 bool SupervisedUserURLFilter::HasFilteredScheme(const GURL& url) { | 274 bool SupervisedUserURLFilter::HasFilteredScheme(const GURL& url) { |
275 for (const char* scheme : kFilteredSchemes) { | 275 for (const char* scheme : kFilteredSchemes) { |
276 if (url.scheme() == scheme) | 276 if (url.scheme() == scheme) |
277 return true; | 277 return true; |
278 } | 278 } |
279 return false; | 279 return false; |
280 } | 280 } |
281 | 281 |
282 // static | 282 // static |
283 bool SupervisedUserURLFilter::HostMatchesPattern(const std::string& host, | 283 bool SupervisedUserURLFilter::HostMatchesPattern( |
284 const std::string& pattern) { | 284 const std::string& canonical_host, |
| 285 const std::string& pattern) { |
285 std::string trimmed_pattern = pattern; | 286 std::string trimmed_pattern = pattern; |
286 std::string trimmed_host = host; | 287 std::string trimmed_host = canonical_host; |
287 if (base::EndsWith(pattern, ".*", base::CompareCase::SENSITIVE)) { | 288 if (base::EndsWith(pattern, ".*", base::CompareCase::SENSITIVE)) { |
288 size_t registry_length = GetRegistryLength( | 289 size_t registry_length = GetCanonicalHostRegistryLength( |
289 trimmed_host, EXCLUDE_UNKNOWN_REGISTRIES, EXCLUDE_PRIVATE_REGISTRIES); | 290 trimmed_host, EXCLUDE_UNKNOWN_REGISTRIES, EXCLUDE_PRIVATE_REGISTRIES); |
290 // A host without a known registry part does not match. | 291 // A host without a known registry part does not match. |
291 if (registry_length == 0) | 292 if (registry_length == 0) |
292 return false; | 293 return false; |
293 | 294 |
294 trimmed_pattern.erase(trimmed_pattern.length() - 2); | 295 trimmed_pattern.erase(trimmed_pattern.length() - 2); |
295 trimmed_host.erase(trimmed_host.length() - (registry_length + 1)); | 296 trimmed_host.erase(trimmed_host.length() - (registry_length + 1)); |
296 } | 297 } |
297 | 298 |
298 if (base::StartsWith(trimmed_pattern, "*.", base::CompareCase::SENSITIVE)) { | 299 if (base::StartsWith(trimmed_pattern, "*.", base::CompareCase::SENSITIVE)) { |
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
622 | 623 |
623 FilteringBehavior behavior = | 624 FilteringBehavior behavior = |
624 GetBehaviorFromSafeSearchClassification(classification); | 625 GetBehaviorFromSafeSearchClassification(classification); |
625 | 626 |
626 callback.Run(behavior, supervised_user_error_page::ASYNC_CHECKER, uncertain); | 627 callback.Run(behavior, supervised_user_error_page::ASYNC_CHECKER, uncertain); |
627 for (Observer& observer : observers_) { | 628 for (Observer& observer : observers_) { |
628 observer.OnURLChecked(url, behavior, | 629 observer.OnURLChecked(url, behavior, |
629 supervised_user_error_page::ASYNC_CHECKER, uncertain); | 630 supervised_user_error_page::ASYNC_CHECKER, uncertain); |
630 } | 631 } |
631 } | 632 } |
OLD | NEW |