OLD | NEW |
---|---|
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 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
309 std::set<string16> messages; | 309 std::set<string16> messages; |
310 std::set<std::string>::const_iterator i; | 310 std::set<std::string>::const_iterator i; |
311 for (i = api_permissions().begin(); i != api_permissions().end(); ++i) { | 311 for (i = api_permissions().begin(); i != api_permissions().end(); ++i) { |
312 int message_id = GetPermissionMessageId(*i); | 312 int message_id = GetPermissionMessageId(*i); |
313 if (message_id) | 313 if (message_id) |
314 messages.insert(l10n_util::GetStringUTF16(message_id)); | 314 messages.insert(l10n_util::GetStringUTF16(message_id)); |
315 } | 315 } |
316 return messages; | 316 return messages; |
317 } | 317 } |
318 | 318 |
319 std::vector<std::string> Extension::GetDistinctHosts() const { | 319 std::vector<std::string> Extension::GetDistinctHosts(bool include_rcd) const { |
320 return GetDistinctHosts(GetEffectiveHostPermissions().patterns()); | 320 return GetDistinctHosts(GetEffectiveHostPermissions().patterns(), |
321 include_rcd); | |
321 } | 322 } |
322 | 323 |
323 // static | 324 // static |
324 std::vector<std::string> Extension::GetDistinctHosts( | 325 std::vector<std::string> Extension::GetDistinctHosts( |
325 const URLPatternList& host_patterns) { | 326 const URLPatternList& host_patterns, bool include_rcd) { |
326 | |
327 // Vector because we later want to access these by index. | 327 // Vector because we later want to access these by index. |
328 std::vector<std::string> distinct_hosts; | 328 std::vector<std::string> distinct_hosts; |
329 | 329 |
330 std::set<std::string> rcd_set; | 330 std::set<std::string> rcd_set; |
331 for (size_t i = 0; i < host_patterns.size(); ++i) { | 331 for (size_t i = 0; i < host_patterns.size(); ++i) { |
332 std::string candidate = host_patterns[i].host(); | 332 std::string candidate = host_patterns[i].host(); |
333 size_t registry = net::RegistryControlledDomainService::GetRegistryLength( | 333 size_t registry = net::RegistryControlledDomainService::GetRegistryLength( |
334 candidate, false); | 334 candidate, false); |
335 if (registry && registry != std::string::npos) { | 335 if (registry && registry != std::string::npos) { |
336 std::string no_rcd(candidate, 0, candidate.size() - registry); | 336 std::string no_rcd(candidate, 0, candidate.size() - registry); |
337 if (rcd_set.count(no_rcd)) | 337 if (rcd_set.count(no_rcd)) |
338 continue; | 338 continue; |
339 rcd_set.insert(no_rcd); | 339 rcd_set.insert(no_rcd); |
340 if (!include_rcd) | |
341 candidate = no_rcd; | |
340 } | 342 } |
341 if (std::find(distinct_hosts.begin(), distinct_hosts.end(), candidate) == | 343 if (std::find(distinct_hosts.begin(), distinct_hosts.end(), candidate) == |
342 distinct_hosts.end()) { | 344 distinct_hosts.end()) { |
343 distinct_hosts.push_back(candidate); | 345 distinct_hosts.push_back(candidate); |
344 } | 346 } |
345 } | 347 } |
346 | 348 |
347 return distinct_hosts; | 349 return distinct_hosts; |
348 } | 350 } |
349 | 351 |
350 string16 Extension::GetHostPermissionMessage() const { | 352 string16 Extension::GetHostPermissionMessage() const { |
351 if (HasEffectiveAccessToAllHosts()) | 353 if (HasEffectiveAccessToAllHosts()) |
352 return l10n_util::GetStringUTF16(IDS_EXTENSION_PROMPT_WARNING_ALL_HOSTS); | 354 return l10n_util::GetStringUTF16(IDS_EXTENSION_PROMPT_WARNING_ALL_HOSTS); |
353 | 355 |
354 std::vector<std::string> hosts = GetDistinctHosts(); | 356 // Include the RCDs in the distinct hosts to make it easier on the users. |
Erik does not do reviews
2010/12/03 17:56:42
buff this comment out a bit:
"...to make it easier
jstritar
2010/12/03 21:52:55
I ended up removing this comment after switching t
| |
357 std::vector<std::string> hosts = GetDistinctHosts(true); | |
355 if (hosts.size() == 1) { | 358 if (hosts.size() == 1) { |
356 return l10n_util::GetStringFUTF16(IDS_EXTENSION_PROMPT_WARNING_1_HOST, | 359 return l10n_util::GetStringFUTF16(IDS_EXTENSION_PROMPT_WARNING_1_HOST, |
357 UTF8ToUTF16(hosts[0])); | 360 UTF8ToUTF16(hosts[0])); |
358 } else if (hosts.size() == 2) { | 361 } else if (hosts.size() == 2) { |
359 return l10n_util::GetStringFUTF16(IDS_EXTENSION_PROMPT_WARNING_2_HOSTS, | 362 return l10n_util::GetStringFUTF16(IDS_EXTENSION_PROMPT_WARNING_2_HOSTS, |
360 UTF8ToUTF16(hosts[0]), | 363 UTF8ToUTF16(hosts[0]), |
361 UTF8ToUTF16(hosts[1])); | 364 UTF8ToUTF16(hosts[1])); |
362 } else if (hosts.size() == 3) { | 365 } else if (hosts.size() == 3) { |
363 return l10n_util::GetStringFUTF16(IDS_EXTENSION_PROMPT_WARNING_3_HOSTS, | 366 return l10n_util::GetStringFUTF16(IDS_EXTENSION_PROMPT_WARNING_3_HOSTS, |
364 UTF8ToUTF16(hosts[0]), | 367 UTF8ToUTF16(hosts[0]), |
(...skipping 742 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1107 // Otherwise, if the new extension has a plugin, it's a privilege increase. | 1110 // Otherwise, if the new extension has a plugin, it's a privilege increase. |
1108 if (new_extension->HasFullPermissions()) | 1111 if (new_extension->HasFullPermissions()) |
1109 return true; | 1112 return true; |
1110 | 1113 |
1111 // If the extension hadn't been granted access to all hosts in the past, then | 1114 // If the extension hadn't been granted access to all hosts in the past, then |
1112 // see if the extension requires more host permissions. | 1115 // see if the extension requires more host permissions. |
1113 if (!HasEffectiveAccessToAllHosts(granted_extent, granted_apis)) { | 1116 if (!HasEffectiveAccessToAllHosts(granted_extent, granted_apis)) { |
1114 if (new_extension->HasEffectiveAccessToAllHosts()) | 1117 if (new_extension->HasEffectiveAccessToAllHosts()) |
1115 return true; | 1118 return true; |
1116 | 1119 |
1120 // Get the distinct hosts without the RCDs to make sure we get the same | |
1121 // hosts regardless of the URL pattern ordering. | |
1117 const ExtensionExtent new_extent = | 1122 const ExtensionExtent new_extent = |
1118 new_extension->GetEffectiveHostPermissions(); | 1123 new_extension->GetEffectiveHostPermissions(); |
1119 std::vector<std::string> new_hosts = | 1124 std::vector<std::string> new_hosts = |
1120 GetDistinctHosts(new_extent.patterns()); | 1125 GetDistinctHosts(new_extent.patterns(), false); |
1121 std::vector<std::string> old_hosts = | 1126 std::vector<std::string> old_hosts = |
1122 GetDistinctHosts(granted_extent.patterns()); | 1127 GetDistinctHosts(granted_extent.patterns(), false); |
1123 | 1128 |
1124 std::set<std::string> old_hosts_set(old_hosts.begin(), old_hosts.end()); | 1129 std::set<std::string> old_hosts_set(old_hosts.begin(), old_hosts.end()); |
1125 std::set<std::string> new_hosts_set(new_hosts.begin(), new_hosts.end()); | 1130 std::set<std::string> new_hosts_set(new_hosts.begin(), new_hosts.end()); |
1126 std::set<std::string> new_hosts_only; | 1131 std::set<std::string> new_hosts_only; |
1127 | 1132 |
1128 std::set_difference(new_hosts_set.begin(), new_hosts_set.end(), | 1133 std::set_difference(new_hosts_set.begin(), new_hosts_set.end(), |
1129 old_hosts_set.begin(), old_hosts_set.end(), | 1134 old_hosts_set.begin(), old_hosts_set.end(), |
1130 std::inserter(new_hosts_only, new_hosts_only.begin())); | 1135 std::inserter(new_hosts_only, new_hosts_only.begin())); |
1131 | 1136 |
1132 if (new_hosts_only.size()) | 1137 if (new_hosts_only.size()) |
(...skipping 1100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2233 UninstalledExtensionInfo::UninstalledExtensionInfo( | 2238 UninstalledExtensionInfo::UninstalledExtensionInfo( |
2234 const Extension& extension) | 2239 const Extension& extension) |
2235 : extension_id(extension.id()), | 2240 : extension_id(extension.id()), |
2236 extension_api_permissions(extension.api_permissions()), | 2241 extension_api_permissions(extension.api_permissions()), |
2237 is_theme(extension.is_theme()), | 2242 is_theme(extension.is_theme()), |
2238 is_app(extension.is_app()), | 2243 is_app(extension.is_app()), |
2239 converted_from_user_script(extension.converted_from_user_script()), | 2244 converted_from_user_script(extension.converted_from_user_script()), |
2240 update_url(extension.update_url()) {} | 2245 update_url(extension.update_url()) {} |
2241 | 2246 |
2242 UninstalledExtensionInfo::~UninstalledExtensionInfo() {} | 2247 UninstalledExtensionInfo::~UninstalledExtensionInfo() {} |
OLD | NEW |