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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/common/extensions/extension.h ('k') | chrome/common/extensions/extension_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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.h" 5 #include "chrome/common/extensions/extension.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "app/l10n_util.h" 9 #include "app/l10n_util.h"
10 #include "base/base64.h" 10 #include "base/base64.h"
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 std::set<string16> messages; 313 std::set<string16> messages;
314 std::set<std::string>::const_iterator i; 314 std::set<std::string>::const_iterator i;
315 for (i = api_permissions().begin(); i != api_permissions().end(); ++i) { 315 for (i = api_permissions().begin(); i != api_permissions().end(); ++i) {
316 int message_id = GetPermissionMessageId(*i); 316 int message_id = GetPermissionMessageId(*i);
317 if (message_id) 317 if (message_id)
318 messages.insert(l10n_util::GetStringUTF16(message_id)); 318 messages.insert(l10n_util::GetStringUTF16(message_id));
319 } 319 }
320 return messages; 320 return messages;
321 } 321 }
322 322
323 std::vector<std::string> Extension::GetDistinctHosts() const { 323 // static
324 return GetDistinctHosts(GetEffectiveHostPermissions().patterns()); 324 std::vector<std::string> Extension::GetDistinctHostsForDisplay(
325 const URLPatternList& list) {
326 return GetDistinctHosts(list, true);
327 }
328
329 // static
330 bool Extension::IsElevatedHostList(
331 const URLPatternList& old_list, const URLPatternList& new_list) {
332 // TODO(jstritar): This is overly conservative with respect to subdomains.
333 // For example, going from *.google.com to www.google.com will be
334 // considered an elevation, even though it is not (http://crbug.com/65337).
335
336 std::vector<std::string> new_hosts = GetDistinctHosts(new_list, false);
337 std::vector<std::string> old_hosts = GetDistinctHosts(old_list, false);
338
339 std::set<std::string> old_hosts_set(old_hosts.begin(), old_hosts.end());
340 std::set<std::string> new_hosts_set(new_hosts.begin(), new_hosts.end());
341 std::set<std::string> new_hosts_only;
342
343 std::set_difference(new_hosts_set.begin(), new_hosts_set.end(),
344 old_hosts_set.begin(), old_hosts_set.end(),
345 std::inserter(new_hosts_only, new_hosts_only.begin()));
346
347 return new_hosts_only.size() > 0;
325 } 348 }
326 349
327 // static 350 // static
328 std::vector<std::string> Extension::GetDistinctHosts( 351 std::vector<std::string> Extension::GetDistinctHosts(
329 const URLPatternList& host_patterns) { 352 const URLPatternList& host_patterns, bool include_rcd) {
330
331 // Vector because we later want to access these by index. 353 // Vector because we later want to access these by index.
332 std::vector<std::string> distinct_hosts; 354 std::vector<std::string> distinct_hosts;
333 355
334 std::set<std::string> rcd_set; 356 std::set<std::string> rcd_set;
335 for (size_t i = 0; i < host_patterns.size(); ++i) { 357 for (size_t i = 0; i < host_patterns.size(); ++i) {
336 std::string candidate = host_patterns[i].host(); 358 std::string candidate = host_patterns[i].host();
359
360 // Add the subdomain wildcard back to the host, if necessary.
361 if (host_patterns[i].match_subdomains())
362 candidate = "*." + candidate;
Aaron Boodman 2010/12/13 02:06:47 Why was this change necessary? It causes a manifes
363
337 size_t registry = net::RegistryControlledDomainService::GetRegistryLength( 364 size_t registry = net::RegistryControlledDomainService::GetRegistryLength(
338 candidate, false); 365 candidate, false);
339 if (registry && registry != std::string::npos) { 366 if (registry && registry != std::string::npos) {
340 std::string no_rcd(candidate, 0, candidate.size() - registry); 367 std::string no_rcd(candidate, 0, candidate.size() - registry);
341 if (rcd_set.count(no_rcd)) 368 if (rcd_set.count(no_rcd))
342 continue; 369 continue;
343 rcd_set.insert(no_rcd); 370 rcd_set.insert(no_rcd);
371 if (!include_rcd)
372 candidate = no_rcd;
344 } 373 }
345 if (std::find(distinct_hosts.begin(), distinct_hosts.end(), candidate) == 374 if (std::find(distinct_hosts.begin(), distinct_hosts.end(), candidate) ==
346 distinct_hosts.end()) { 375 distinct_hosts.end()) {
347 distinct_hosts.push_back(candidate); 376 distinct_hosts.push_back(candidate);
348 } 377 }
349 } 378 }
350 379
351 return distinct_hosts; 380 return distinct_hosts;
352 } 381 }
353 382
354 string16 Extension::GetHostPermissionMessage() const { 383 string16 Extension::GetHostPermissionMessage() const {
355 if (HasEffectiveAccessToAllHosts()) 384 if (HasEffectiveAccessToAllHosts())
356 return l10n_util::GetStringUTF16(IDS_EXTENSION_PROMPT_WARNING_ALL_HOSTS); 385 return l10n_util::GetStringUTF16(IDS_EXTENSION_PROMPT_WARNING_ALL_HOSTS);
357 386
358 std::vector<std::string> hosts = GetDistinctHosts(); 387 std::vector<std::string> hosts = GetDistinctHostsForDisplay(
388 GetEffectiveHostPermissions().patterns());
389
359 if (hosts.size() == 1) { 390 if (hosts.size() == 1) {
360 return l10n_util::GetStringFUTF16(IDS_EXTENSION_PROMPT_WARNING_1_HOST, 391 return l10n_util::GetStringFUTF16(IDS_EXTENSION_PROMPT_WARNING_1_HOST,
361 UTF8ToUTF16(hosts[0])); 392 UTF8ToUTF16(hosts[0]));
362 } else if (hosts.size() == 2) { 393 } else if (hosts.size() == 2) {
363 return l10n_util::GetStringFUTF16(IDS_EXTENSION_PROMPT_WARNING_2_HOSTS, 394 return l10n_util::GetStringFUTF16(IDS_EXTENSION_PROMPT_WARNING_2_HOSTS,
364 UTF8ToUTF16(hosts[0]), 395 UTF8ToUTF16(hosts[0]),
365 UTF8ToUTF16(hosts[1])); 396 UTF8ToUTF16(hosts[1]));
366 } else if (hosts.size() == 3) { 397 } else if (hosts.size() == 3) {
367 return l10n_util::GetStringFUTF16(IDS_EXTENSION_PROMPT_WARNING_3_HOSTS, 398 return l10n_util::GetStringFUTF16(IDS_EXTENSION_PROMPT_WARNING_3_HOSTS,
368 UTF8ToUTF16(hosts[0]), 399 UTF8ToUTF16(hosts[0]),
(...skipping 744 matching lines...) Expand 10 before | Expand all | Expand 10 after
1113 return true; 1144 return true;
1114 1145
1115 // If the extension hadn't been granted access to all hosts in the past, then 1146 // If the extension hadn't been granted access to all hosts in the past, then
1116 // see if the extension requires more host permissions. 1147 // see if the extension requires more host permissions.
1117 if (!HasEffectiveAccessToAllHosts(granted_extent, granted_apis)) { 1148 if (!HasEffectiveAccessToAllHosts(granted_extent, granted_apis)) {
1118 if (new_extension->HasEffectiveAccessToAllHosts()) 1149 if (new_extension->HasEffectiveAccessToAllHosts())
1119 return true; 1150 return true;
1120 1151
1121 const ExtensionExtent new_extent = 1152 const ExtensionExtent new_extent =
1122 new_extension->GetEffectiveHostPermissions(); 1153 new_extension->GetEffectiveHostPermissions();
1123 std::vector<std::string> new_hosts =
1124 GetDistinctHosts(new_extent.patterns());
1125 std::vector<std::string> old_hosts =
1126 GetDistinctHosts(granted_extent.patterns());
1127 1154
1128 std::set<std::string> old_hosts_set(old_hosts.begin(), old_hosts.end()); 1155 if (IsElevatedHostList(granted_extent.patterns(), new_extent.patterns()))
1129 std::set<std::string> new_hosts_set(new_hosts.begin(), new_hosts.end());
1130 std::set<std::string> new_hosts_only;
1131
1132 std::set_difference(new_hosts_set.begin(), new_hosts_set.end(),
1133 old_hosts_set.begin(), old_hosts_set.end(),
1134 std::inserter(new_hosts_only, new_hosts_only.begin()));
1135
1136 if (new_hosts_only.size())
1137 return true; 1156 return true;
1138 } 1157 }
1139 1158
1140 std::set<std::string> new_apis = new_extension->api_permissions(); 1159 std::set<std::string> new_apis = new_extension->api_permissions();
1141 std::set<std::string> new_apis_only; 1160 std::set<std::string> new_apis_only;
1142 std::set_difference(new_apis.begin(), new_apis.end(), 1161 std::set_difference(new_apis.begin(), new_apis.end(),
1143 granted_apis.begin(), granted_apis.end(), 1162 granted_apis.begin(), granted_apis.end(),
1144 std::inserter(new_apis_only, new_apis_only.begin())); 1163 std::inserter(new_apis_only, new_apis_only.begin()));
1145 1164
1146 // Ignore API permissions that don't require user approval when deciding if 1165 // Ignore API permissions that don't require user approval when deciding if
(...skipping 1089 matching lines...) Expand 10 before | Expand all | Expand 10 after
2236 UninstalledExtensionInfo::UninstalledExtensionInfo( 2255 UninstalledExtensionInfo::UninstalledExtensionInfo(
2237 const Extension& extension) 2256 const Extension& extension)
2238 : extension_id(extension.id()), 2257 : extension_id(extension.id()),
2239 extension_api_permissions(extension.api_permissions()), 2258 extension_api_permissions(extension.api_permissions()),
2240 is_theme(extension.is_theme()), 2259 is_theme(extension.is_theme()),
2241 is_app(extension.is_app()), 2260 is_app(extension.is_app()),
2242 converted_from_user_script(extension.converted_from_user_script()), 2261 converted_from_user_script(extension.converted_from_user_script()),
2243 update_url(extension.update_url()) {} 2262 update_url(extension.update_url()) {}
2244 2263
2245 UninstalledExtensionInfo::~UninstalledExtensionInfo() {} 2264 UninstalledExtensionInfo::~UninstalledExtensionInfo() {}
OLDNEW
« 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