OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/extension_permission_set.h" | 5 #include "chrome/common/extensions/extension_permission_set.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/memory/singleton.h" | 10 #include "base/memory/singleton.h" |
(...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
510 i != apis_.end(); ++i) { | 510 i != apis_.end(); ++i) { |
511 ExtensionAPIPermission* permission = info->GetByID(*i); | 511 ExtensionAPIPermission* permission = info->GetByID(*i); |
512 if (permission) | 512 if (permission) |
513 apis_str.insert(permission->name()); | 513 apis_str.insert(permission->name()); |
514 } | 514 } |
515 return apis_str; | 515 return apis_str; |
516 } | 516 } |
517 | 517 |
518 std::set<std::string> | 518 std::set<std::string> |
519 ExtensionPermissionSet::GetDistinctHostsForDisplay() const { | 519 ExtensionPermissionSet::GetDistinctHostsForDisplay() const { |
520 return GetDistinctHosts(effective_hosts_, true); | 520 return GetDistinctHosts(effective_hosts_, true, true); |
521 } | 521 } |
522 | 522 |
523 ExtensionPermissionMessages | 523 ExtensionPermissionMessages |
524 ExtensionPermissionSet::GetPermissionMessages() const { | 524 ExtensionPermissionSet::GetPermissionMessages() const { |
525 ExtensionPermissionMessages messages; | 525 ExtensionPermissionMessages messages; |
526 | 526 |
527 if (HasEffectiveFullAccess()) { | 527 if (HasEffectiveFullAccess()) { |
528 messages.push_back(ExtensionPermissionMessage( | 528 messages.push_back(ExtensionPermissionMessage( |
529 ExtensionPermissionMessage::kFullAccess, | 529 ExtensionPermissionMessage::kFullAccess, |
530 l10n_util::GetStringUTF16(IDS_EXTENSION_PROMPT_WARNING_FULL_ACCESS))); | 530 l10n_util::GetStringUTF16(IDS_EXTENSION_PROMPT_WARNING_FULL_ACCESS))); |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
680 return true; | 680 return true; |
681 | 681 |
682 if (HasLessAPIPrivilegesThan(permissions)) | 682 if (HasLessAPIPrivilegesThan(permissions)) |
683 return true; | 683 return true; |
684 | 684 |
685 return false; | 685 return false; |
686 } | 686 } |
687 | 687 |
688 // static | 688 // static |
689 std::set<std::string> ExtensionPermissionSet::GetDistinctHosts( | 689 std::set<std::string> ExtensionPermissionSet::GetDistinctHosts( |
690 const URLPatternSet& host_patterns, bool include_rcd) { | 690 const URLPatternSet& host_patterns, |
691 bool include_rcd, | |
692 bool exclude_file_scheme) { | |
691 // Use a vector to preserve order (also faster than a map on small sets). | 693 // Use a vector to preserve order (also faster than a map on small sets). |
692 // Each item is a host split into two parts: host without RCDs and | 694 // Each item is a host split into two parts: host without RCDs and |
693 // current best RCD. | 695 // current best RCD. |
694 typedef std::vector<std::pair<std::string, std::string> > HostVector; | 696 typedef std::vector<std::pair<std::string, std::string> > HostVector; |
695 HostVector hosts_best_rcd; | 697 HostVector hosts_best_rcd; |
696 for (URLPatternSet::const_iterator i = host_patterns.begin(); | 698 for (URLPatternSet::const_iterator i = host_patterns.begin(); |
697 i != host_patterns.end(); ++i) { | 699 i != host_patterns.end(); ++i) { |
700 if (exclude_file_scheme && i->scheme() == "file") | |
asargent_no_longer_on_chrome
2011/08/05 22:56:37
nit: change "file" to chrome::kFileScheme, save a
| |
701 continue; | |
702 | |
698 std::string host = i->host(); | 703 std::string host = i->host(); |
699 | 704 |
700 // Add the subdomain wildcard back to the host, if necessary. | 705 // Add the subdomain wildcard back to the host, if necessary. |
701 if (i->match_subdomains()) | 706 if (i->match_subdomains()) |
702 host = "*." + host; | 707 host = "*." + host; |
703 | 708 |
704 // If the host has an RCD, split it off so we can detect duplicates. | 709 // If the host has an RCD, split it off so we can detect duplicates. |
705 std::string rcd; | 710 std::string rcd; |
706 size_t reg_len = net::RegistryControlledDomainService::GetRegistryLength( | 711 size_t reg_len = net::RegistryControlledDomainService::GetRegistryLength( |
707 host, false); | 712 host, false); |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
817 // a privilege increase. | 822 // a privilege increase. |
818 if (permissions->HasEffectiveAccessToAllHosts()) | 823 if (permissions->HasEffectiveAccessToAllHosts()) |
819 return true; | 824 return true; |
820 | 825 |
821 const URLPatternSet& old_list = effective_hosts(); | 826 const URLPatternSet& old_list = effective_hosts(); |
822 const URLPatternSet& new_list = permissions->effective_hosts(); | 827 const URLPatternSet& new_list = permissions->effective_hosts(); |
823 | 828 |
824 // TODO(jstritar): This is overly conservative with respect to subdomains. | 829 // TODO(jstritar): This is overly conservative with respect to subdomains. |
825 // For example, going from *.google.com to www.google.com will be | 830 // For example, going from *.google.com to www.google.com will be |
826 // considered an elevation, even though it is not (http://crbug.com/65337). | 831 // considered an elevation, even though it is not (http://crbug.com/65337). |
827 std::set<std::string> new_hosts_set = GetDistinctHosts(new_list, false); | 832 std::set<std::string> new_hosts_set(GetDistinctHosts(new_list, false, false)); |
828 std::set<std::string> old_hosts_set = GetDistinctHosts(old_list, false); | 833 std::set<std::string> old_hosts_set(GetDistinctHosts(old_list, false, false)); |
829 std::set<std::string> new_hosts_only; | 834 std::set<std::string> new_hosts_only; |
830 | 835 |
831 std::set_difference(new_hosts_set.begin(), new_hosts_set.end(), | 836 std::set_difference(new_hosts_set.begin(), new_hosts_set.end(), |
832 old_hosts_set.begin(), old_hosts_set.end(), | 837 old_hosts_set.begin(), old_hosts_set.end(), |
833 std::inserter(new_hosts_only, new_hosts_only.begin())); | 838 std::inserter(new_hosts_only, new_hosts_only.begin())); |
834 | 839 |
835 return !new_hosts_only.empty(); | 840 return !new_hosts_only.empty(); |
836 } | 841 } |
OLD | NEW |