Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1096)

Unified Diff: chrome/common/extensions/extension.cc

Issue 5642001: Fix issue that causes some extensions to be disabled right after installation. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix comment Created 10 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/common/extensions/extension.h ('k') | chrome/common/extensions/extension_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/common/extensions/extension.cc
diff --git a/chrome/common/extensions/extension.cc b/chrome/common/extensions/extension.cc
index f83202c91479d6ff02ee665eecbd99c2d37f95cf..530c0beb16f845bde9cf984d4d89ff766ae69181 100644
--- a/chrome/common/extensions/extension.cc
+++ b/chrome/common/extensions/extension.cc
@@ -320,20 +320,47 @@ std::set<string16> Extension::GetSimplePermissionMessages() const {
return messages;
}
-std::vector<std::string> Extension::GetDistinctHosts() const {
- return GetDistinctHosts(GetEffectiveHostPermissions().patterns());
+// static
+std::vector<std::string> Extension::GetDistinctHostsForDisplay(
+ const URLPatternList& list) {
+ return GetDistinctHosts(list, true);
}
// static
-std::vector<std::string> Extension::GetDistinctHosts(
- const URLPatternList& host_patterns) {
+bool Extension::IsElevatedHostList(
+ const URLPatternList& old_list, const URLPatternList& new_list) {
+ // TODO(jstritar): This is overly conservative with respect to subdomains.
+ // For example, going from *.google.com to www.google.com will be
+ // considered an elevation, even though it is not (http://crbug.com/65337).
+
+ std::vector<std::string> new_hosts = GetDistinctHosts(new_list, false);
+ std::vector<std::string> old_hosts = GetDistinctHosts(old_list, false);
+
+ std::set<std::string> old_hosts_set(old_hosts.begin(), old_hosts.end());
+ std::set<std::string> new_hosts_set(new_hosts.begin(), new_hosts.end());
+ std::set<std::string> new_hosts_only;
+
+ std::set_difference(new_hosts_set.begin(), new_hosts_set.end(),
+ old_hosts_set.begin(), old_hosts_set.end(),
+ std::inserter(new_hosts_only, new_hosts_only.begin()));
+
+ return new_hosts_only.size() > 0;
+}
+// static
+std::vector<std::string> Extension::GetDistinctHosts(
+ const URLPatternList& host_patterns, bool include_rcd) {
// Vector because we later want to access these by index.
std::vector<std::string> distinct_hosts;
std::set<std::string> rcd_set;
for (size_t i = 0; i < host_patterns.size(); ++i) {
std::string candidate = host_patterns[i].host();
+
+ // Add the subdomain wildcard back to the host, if necessary.
+ if (host_patterns[i].match_subdomains())
+ candidate = "*." + candidate;
Aaron Boodman 2010/12/13 02:06:47 Why was this change necessary? It causes a manifes
+
size_t registry = net::RegistryControlledDomainService::GetRegistryLength(
candidate, false);
if (registry && registry != std::string::npos) {
@@ -341,6 +368,8 @@ std::vector<std::string> Extension::GetDistinctHosts(
if (rcd_set.count(no_rcd))
continue;
rcd_set.insert(no_rcd);
+ if (!include_rcd)
+ candidate = no_rcd;
}
if (std::find(distinct_hosts.begin(), distinct_hosts.end(), candidate) ==
distinct_hosts.end()) {
@@ -355,7 +384,9 @@ string16 Extension::GetHostPermissionMessage() const {
if (HasEffectiveAccessToAllHosts())
return l10n_util::GetStringUTF16(IDS_EXTENSION_PROMPT_WARNING_ALL_HOSTS);
- std::vector<std::string> hosts = GetDistinctHosts();
+ std::vector<std::string> hosts = GetDistinctHostsForDisplay(
+ GetEffectiveHostPermissions().patterns());
+
if (hosts.size() == 1) {
return l10n_util::GetStringFUTF16(IDS_EXTENSION_PROMPT_WARNING_1_HOST,
UTF8ToUTF16(hosts[0]));
@@ -1120,20 +1151,8 @@ bool Extension::IsPrivilegeIncrease(const bool granted_full_access,
const ExtensionExtent new_extent =
new_extension->GetEffectiveHostPermissions();
- std::vector<std::string> new_hosts =
- GetDistinctHosts(new_extent.patterns());
- std::vector<std::string> old_hosts =
- GetDistinctHosts(granted_extent.patterns());
-
- std::set<std::string> old_hosts_set(old_hosts.begin(), old_hosts.end());
- std::set<std::string> new_hosts_set(new_hosts.begin(), new_hosts.end());
- std::set<std::string> new_hosts_only;
-
- std::set_difference(new_hosts_set.begin(), new_hosts_set.end(),
- old_hosts_set.begin(), old_hosts_set.end(),
- std::inserter(new_hosts_only, new_hosts_only.begin()));
- if (new_hosts_only.size())
+ if (IsElevatedHostList(granted_extent.patterns(), new_extent.patterns()))
return true;
}
« no previous file with comments | « chrome/common/extensions/extension.h ('k') | chrome/common/extensions/extension_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698