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) { | |
27 if (permissions->HasEffectiveAccessToAllHosts()) | |
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 } | |
66 | |
67 template<typename T> | 25 template<typename T> |
68 typename T::iterator FindMessageByID(T& messages, int id) { | 26 typename T::iterator FindMessageByID(T& messages, int id) { |
69 for (typename T::iterator it = messages.begin(); | 27 for (typename T::iterator it = messages.begin(); |
70 it != messages.end(); ++it) { | 28 it != messages.end(); ++it) { |
71 if (it->id() == id) | 29 if (it->id() == id) |
72 return it; | 30 return it; |
73 } | 31 } |
74 return messages.end(); | 32 return messages.end(); |
75 } | 33 } |
76 | 34 |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
260 // kFileSystemDirectory as the write directory message implies it. | 218 // kFileSystemDirectory as the write directory message implies it. |
261 // TODO(sammc): Remove this. See http://crbug.com/284849. | 219 // TODO(sammc): Remove this. See http://crbug.com/284849. |
262 SuppressMessage(messages, | 220 SuppressMessage(messages, |
263 PermissionMessage::kFileSystemWriteDirectory, | 221 PermissionMessage::kFileSystemWriteDirectory, |
264 PermissionMessage::kFileSystemDirectory); | 222 PermissionMessage::kFileSystemDirectory); |
265 // A special hack: The warning message for declarativeWebRequest | 223 // A special hack: The warning message for declarativeWebRequest |
266 // permissions speaks about blocking parts of pages, which is a | 224 // permissions speaks about blocking parts of pages, which is a |
267 // subset of what the "<all_urls>" access allows. Therefore we | 225 // subset of what the "<all_urls>" access allows. Therefore we |
268 // display only the "<all_urls>" warning message if both permissions | 226 // display only the "<all_urls>" warning message if both permissions |
269 // are required. | 227 // are required. |
270 if (ShouldWarnAllHosts(permissions)) { | 228 if (permissions->ShouldWarnAllHosts()) { |
271 messages.erase( | 229 messages.erase( |
272 PermissionMessage( | 230 PermissionMessage( |
273 PermissionMessage::kDeclarativeWebRequest, base::string16())); | 231 PermissionMessage::kDeclarativeWebRequest, base::string16())); |
274 } | 232 } |
275 return messages; | 233 return messages; |
276 } | 234 } |
277 | 235 |
278 std::set<PermissionMessage> | 236 std::set<PermissionMessage> |
279 ChromePermissionMessageProvider::GetManifestPermissionMessages( | 237 ChromePermissionMessageProvider::GetManifestPermissionMessages( |
280 const PermissionSet* permissions) const { | 238 const PermissionSet* permissions) const { |
(...skipping 15 matching lines...) Expand all Loading... |
296 const PermissionSet* permissions, | 254 const PermissionSet* permissions, |
297 Manifest::Type extension_type) const { | 255 Manifest::Type extension_type) const { |
298 PermissionMsgSet messages; | 256 PermissionMsgSet messages; |
299 // Since platform apps always use isolated storage, they can't (silently) | 257 // Since platform apps always use isolated storage, they can't (silently) |
300 // access user data on other domains, so there's no need to prompt. | 258 // access user data on other domains, so there's no need to prompt. |
301 // Note: this must remain consistent with IsHostPrivilegeIncrease. | 259 // Note: this must remain consistent with IsHostPrivilegeIncrease. |
302 // See crbug.com/255229. | 260 // See crbug.com/255229. |
303 if (extension_type == Manifest::TYPE_PLATFORM_APP) | 261 if (extension_type == Manifest::TYPE_PLATFORM_APP) |
304 return messages; | 262 return messages; |
305 | 263 |
306 if (ShouldWarnAllHosts(permissions)) { | 264 if (permissions->ShouldWarnAllHosts()) { |
307 messages.insert(PermissionMessage( | 265 messages.insert(PermissionMessage( |
308 PermissionMessage::kHostsAll, | 266 PermissionMessage::kHostsAll, |
309 l10n_util::GetStringUTF16(IDS_EXTENSION_PROMPT_WARNING_ALL_HOSTS))); | 267 l10n_util::GetStringUTF16(IDS_EXTENSION_PROMPT_WARNING_ALL_HOSTS))); |
310 } else { | 268 } else { |
311 URLPatternSet regular_hosts; | 269 URLPatternSet regular_hosts; |
312 ExtensionsClient::Get()->FilterHostPermissions( | 270 ExtensionsClient::Get()->FilterHostPermissions( |
313 permissions->effective_hosts(), ®ular_hosts, &messages); | 271 permissions->effective_hosts(), ®ular_hosts, &messages); |
314 | 272 |
315 std::set<std::string> hosts = | 273 std::set<std::string> hosts = |
316 permission_message_util::GetDistinctHosts(regular_hosts, true, true); | 274 permission_message_util::GetDistinctHosts(regular_hosts, true, true); |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
391 std::set<std::string> old_hosts_set( | 349 std::set<std::string> old_hosts_set( |
392 permission_message_util::GetDistinctHosts(old_list, false, false)); | 350 permission_message_util::GetDistinctHosts(old_list, false, false)); |
393 std::set<std::string> new_hosts_only = | 351 std::set<std::string> new_hosts_only = |
394 base::STLSetDifference<std::set<std::string> >(new_hosts_set, | 352 base::STLSetDifference<std::set<std::string> >(new_hosts_set, |
395 old_hosts_set); | 353 old_hosts_set); |
396 | 354 |
397 return !new_hosts_only.empty(); | 355 return !new_hosts_only.empty(); |
398 } | 356 } |
399 | 357 |
400 } // namespace extensions | 358 } // namespace extensions |
OLD | NEW |