| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/extensions/permissions/chrome_permission_message_provide
r.h" | 5 #include "chrome/common/extensions/permissions/chrome_permission_message_provide
r.h" |
| 6 | 6 |
| 7 #include "base/stl_util.h" | 7 #include "base/stl_util.h" |
| 8 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
| 9 #include "extensions/common/extensions_client.h" | 9 #include "extensions/common/extensions_client.h" |
| 10 #include "extensions/common/permissions/permission_message.h" | 10 #include "extensions/common/permissions/permission_message.h" |
| 11 #include "extensions/common/permissions/permission_message_util.h" | 11 #include "extensions/common/permissions/permission_message_util.h" |
| 12 #include "extensions/common/permissions/permission_set.h" | 12 #include "extensions/common/permissions/permission_set.h" |
| 13 #include "extensions/common/url_pattern.h" | 13 #include "extensions/common/url_pattern.h" |
| 14 #include "extensions/common/url_pattern_set.h" | 14 #include "extensions/common/url_pattern_set.h" |
| 15 #include "grit/generated_resources.h" | 15 #include "grit/generated_resources.h" |
| 16 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" | |
| 17 #include "ui/base/l10n/l10n_util.h" | 16 #include "ui/base/l10n/l10n_util.h" |
| 18 #include "url/gurl.h" | 17 #include "url/gurl.h" |
| 19 | 18 |
| 20 namespace extensions { | 19 namespace extensions { |
| 21 | 20 |
| 22 namespace { | 21 namespace { |
| 23 | 22 |
| 24 typedef std::set<PermissionMessage> PermissionMsgSet; | 23 typedef std::set<PermissionMessage> PermissionMsgSet; |
| 25 | 24 |
| 26 bool ShouldWarnAllHosts(const PermissionSet* permissions) { | 25 bool ShouldWarnAllHosts(const PermissionSet* permissions) { |
| 27 if (permissions->HasEffectiveAccessToAllHosts()) | 26 return permissions->HasAccessToMostHosts(); |
| 28 return true; | |
| 29 | |
| 30 const URLPatternSet& effective_hosts = permissions->effective_hosts(); | |
| 31 for (URLPatternSet::const_iterator iter = effective_hosts.begin(); | |
| 32 iter != effective_hosts.end(); | |
| 33 ++iter) { | |
| 34 // If this doesn't even match subdomains, it can't possibly imply all hosts. | |
| 35 if (!iter->match_subdomains()) | |
| 36 continue; | |
| 37 | |
| 38 // If iter->host() is a recognized TLD, this will be 0. We don't include | |
| 39 // private TLDs, so that, e.g., *.appspot.com does not imply all hosts. | |
| 40 size_t registry_length = | |
| 41 net::registry_controlled_domains::GetRegistryLength( | |
| 42 iter->host(), | |
| 43 net::registry_controlled_domains::EXCLUDE_UNKNOWN_REGISTRIES, | |
| 44 net::registry_controlled_domains::EXCLUDE_PRIVATE_REGISTRIES); | |
| 45 // If there was more than just a TLD in the host (e.g., *.foobar.com), it | |
| 46 // doesn't imply all hosts. | |
| 47 if (registry_length > 0) | |
| 48 continue; | |
| 49 | |
| 50 // At this point the host could either be just a TLD ("com") or some unknown | |
| 51 // TLD-like string ("notatld"). To disambiguate between them construct a | |
| 52 // fake URL, and check the registry. This returns 0 if the TLD is | |
| 53 // unrecognized, or the length of the recognized TLD. | |
| 54 registry_length = net::registry_controlled_domains::GetRegistryLength( | |
| 55 base::StringPrintf("foo.%s", iter->host().c_str()), | |
| 56 net::registry_controlled_domains::EXCLUDE_UNKNOWN_REGISTRIES, | |
| 57 net::registry_controlled_domains::EXCLUDE_PRIVATE_REGISTRIES); | |
| 58 // If we recognized this TLD, then this is a pattern like *.com, and it | |
| 59 // should imply all hosts. | |
| 60 if (registry_length > 0) | |
| 61 return true; | |
| 62 } | |
| 63 | |
| 64 return false; | |
| 65 } | 27 } |
| 66 | 28 |
| 67 template<typename T> | 29 template<typename T> |
| 68 typename T::iterator FindMessageByID(T& messages, int id) { | 30 typename T::iterator FindMessageByID(T& messages, int id) { |
| 69 for (typename T::iterator it = messages.begin(); | 31 for (typename T::iterator it = messages.begin(); |
| 70 it != messages.end(); ++it) { | 32 it != messages.end(); ++it) { |
| 71 if (it->id() == id) | 33 if (it->id() == id) |
| 72 return it; | 34 return it; |
| 73 } | 35 } |
| 74 return messages.end(); | 36 return messages.end(); |
| (...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 391 std::set<std::string> old_hosts_set( | 353 std::set<std::string> old_hosts_set( |
| 392 permission_message_util::GetDistinctHosts(old_list, false, false)); | 354 permission_message_util::GetDistinctHosts(old_list, false, false)); |
| 393 std::set<std::string> new_hosts_only = | 355 std::set<std::string> new_hosts_only = |
| 394 base::STLSetDifference<std::set<std::string> >(new_hosts_set, | 356 base::STLSetDifference<std::set<std::string> >(new_hosts_set, |
| 395 old_hosts_set); | 357 old_hosts_set); |
| 396 | 358 |
| 397 return !new_hosts_only.empty(); | 359 return !new_hosts_only.empty(); |
| 398 } | 360 } |
| 399 | 361 |
| 400 } // namespace extensions | 362 } // namespace extensions |
| OLD | NEW |