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 "extensions/common/permissions/permission_set.h" | 5 #include "extensions/common/permissions/permission_set.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <iterator> | 8 #include <iterator> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/strings/stringprintf.h" | |
12 #include "extensions/common/permissions/permissions_info.h" | 11 #include "extensions/common/permissions/permissions_info.h" |
13 #include "extensions/common/url_pattern.h" | 12 #include "extensions/common/url_pattern.h" |
14 #include "extensions/common/url_pattern_set.h" | 13 #include "extensions/common/url_pattern_set.h" |
15 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" | |
16 #include "url/gurl.h" | 14 #include "url/gurl.h" |
17 | 15 |
18 namespace extensions { | 16 namespace extensions { |
19 | 17 |
20 namespace { | 18 namespace { |
21 | 19 |
22 void AddPatternsAndRemovePaths(const URLPatternSet& set, URLPatternSet* out) { | 20 void AddPatternsAndRemovePaths(const URLPatternSet& set, URLPatternSet* out) { |
23 DCHECK(out); | 21 DCHECK(out); |
24 for (URLPatternSet::const_iterator i = set.begin(); i != set.end(); ++i) { | 22 for (URLPatternSet::const_iterator i = set.begin(); i != set.end(); ++i) { |
25 URLPattern p = *i; | 23 URLPattern p = *i; |
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
271 | 269 |
272 void PermissionSet::InitShouldWarnAllHosts() const { | 270 void PermissionSet::InitShouldWarnAllHosts() const { |
273 if (HasEffectiveAccessToAllHosts()) { | 271 if (HasEffectiveAccessToAllHosts()) { |
274 should_warn_all_hosts_ = WARN_ALL_HOSTS; | 272 should_warn_all_hosts_ = WARN_ALL_HOSTS; |
275 return; | 273 return; |
276 } | 274 } |
277 | 275 |
278 for (URLPatternSet::const_iterator iter = effective_hosts_.begin(); | 276 for (URLPatternSet::const_iterator iter = effective_hosts_.begin(); |
279 iter != effective_hosts_.end(); | 277 iter != effective_hosts_.end(); |
280 ++iter) { | 278 ++iter) { |
281 // If this doesn't even match subdomains, it can't possibly imply all hosts. | 279 if (iter->ImpliesAllHosts()) { |
282 if (!iter->match_subdomains()) | |
283 continue; | |
284 | |
285 // If iter->host() is a recognized TLD, this will be 0. We don't include | |
286 // private TLDs, so that, e.g., *.appspot.com does not imply all hosts. | |
287 size_t registry_length = | |
288 net::registry_controlled_domains::GetRegistryLength( | |
289 iter->host(), | |
290 net::registry_controlled_domains::EXCLUDE_UNKNOWN_REGISTRIES, | |
291 net::registry_controlled_domains::EXCLUDE_PRIVATE_REGISTRIES); | |
292 // If there was more than just a TLD in the host (e.g., *.foobar.com), it | |
293 // doesn't imply all hosts. | |
294 if (registry_length > 0) | |
295 continue; | |
296 | |
297 // At this point the host could either be just a TLD ("com") or some unknown | |
298 // TLD-like string ("notatld"). To disambiguate between them construct a | |
299 // fake URL, and check the registry. This returns 0 if the TLD is | |
300 // unrecognized, or the length of the recognized TLD. | |
301 registry_length = net::registry_controlled_domains::GetRegistryLength( | |
302 base::StringPrintf("foo.%s", iter->host().c_str()), | |
303 net::registry_controlled_domains::EXCLUDE_UNKNOWN_REGISTRIES, | |
304 net::registry_controlled_domains::EXCLUDE_PRIVATE_REGISTRIES); | |
305 // If we recognized this TLD, then this is a pattern like *.com, and it | |
306 // should imply all hosts. | |
307 if (registry_length > 0) { | |
308 should_warn_all_hosts_ = WARN_ALL_HOSTS; | 280 should_warn_all_hosts_ = WARN_ALL_HOSTS; |
309 return; | 281 return; |
310 } | 282 } |
311 } | 283 } |
312 | 284 |
313 should_warn_all_hosts_ = DONT_WARN_ALL_HOSTS; | 285 should_warn_all_hosts_ = DONT_WARN_ALL_HOSTS; |
314 } | 286 } |
315 | 287 |
316 } // namespace extensions | 288 } // namespace extensions |
OLD | NEW |