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 // static |
320 return GetDistinctHosts(GetEffectiveHostPermissions().patterns()); | 320 std::vector<std::string> Extension::GetDistinctHostsForDisplay( |
321 const URLPatternList& list) { | |
322 return GetDistinctHosts(list, true); | |
323 } | |
324 | |
325 // static | |
326 bool Extension::IsElevatedHostList( | |
327 const URLPatternList& old_list, const URLPatternList& new_list) { | |
328 // TODO(jstritar): This is overly conservative with respect to subdomains. | |
329 // For example, going from *.google.com to www.google.com will be | |
330 // considered an elevation, even though it is not (http://crbug.com/65337). | |
Erik does not do reviews
2010/12/03 23:40:41
Good point. This seems straightforward to fix, al
| |
331 | |
332 std::vector<std::string> new_hosts = GetDistinctHosts(new_list, false); | |
333 std::vector<std::string> old_hosts = GetDistinctHosts(old_list, false); | |
334 | |
335 std::set<std::string> old_hosts_set(old_hosts.begin(), old_hosts.end()); | |
336 std::set<std::string> new_hosts_set(new_hosts.begin(), new_hosts.end()); | |
337 std::set<std::string> new_hosts_only; | |
338 | |
339 std::set_difference(new_hosts_set.begin(), new_hosts_set.end(), | |
340 old_hosts_set.begin(), old_hosts_set.end(), | |
341 std::inserter(new_hosts_only, new_hosts_only.begin())); | |
342 | |
343 return new_hosts_only.size() > 0; | |
321 } | 344 } |
322 | 345 |
323 // static | 346 // static |
324 std::vector<std::string> Extension::GetDistinctHosts( | 347 std::vector<std::string> Extension::GetDistinctHosts( |
325 const URLPatternList& host_patterns) { | 348 const URLPatternList& host_patterns, bool include_rcd) { |
326 | |
327 // Vector because we later want to access these by index. | 349 // Vector because we later want to access these by index. |
328 std::vector<std::string> distinct_hosts; | 350 std::vector<std::string> distinct_hosts; |
329 | 351 |
330 std::set<std::string> rcd_set; | 352 std::set<std::string> rcd_set; |
331 for (size_t i = 0; i < host_patterns.size(); ++i) { | 353 for (size_t i = 0; i < host_patterns.size(); ++i) { |
332 std::string candidate = host_patterns[i].host(); | 354 std::string candidate = host_patterns[i].host(); |
355 | |
356 // Add the subdomain wildcard back to the host, if necessary. | |
Erik does not do reviews
2010/12/03 23:40:41
ah, I see how this happened now.
| |
357 if (host_patterns[i].match_subdomains()) | |
358 candidate = "*." + candidate; | |
359 | |
333 size_t registry = net::RegistryControlledDomainService::GetRegistryLength( | 360 size_t registry = net::RegistryControlledDomainService::GetRegistryLength( |
334 candidate, false); | 361 candidate, false); |
335 if (registry && registry != std::string::npos) { | 362 if (registry && registry != std::string::npos) { |
336 std::string no_rcd(candidate, 0, candidate.size() - registry); | 363 std::string no_rcd(candidate, 0, candidate.size() - registry); |
337 if (rcd_set.count(no_rcd)) | 364 if (rcd_set.count(no_rcd)) |
338 continue; | 365 continue; |
339 rcd_set.insert(no_rcd); | 366 rcd_set.insert(no_rcd); |
367 if (!include_rcd) | |
368 candidate = no_rcd; | |
340 } | 369 } |
341 if (std::find(distinct_hosts.begin(), distinct_hosts.end(), candidate) == | 370 if (std::find(distinct_hosts.begin(), distinct_hosts.end(), candidate) == |
342 distinct_hosts.end()) { | 371 distinct_hosts.end()) { |
343 distinct_hosts.push_back(candidate); | 372 distinct_hosts.push_back(candidate); |
344 } | 373 } |
345 } | 374 } |
346 | 375 |
347 return distinct_hosts; | 376 return distinct_hosts; |
348 } | 377 } |
349 | 378 |
350 string16 Extension::GetHostPermissionMessage() const { | 379 string16 Extension::GetHostPermissionMessage() const { |
351 if (HasEffectiveAccessToAllHosts()) | 380 if (HasEffectiveAccessToAllHosts()) |
352 return l10n_util::GetStringUTF16(IDS_EXTENSION_PROMPT_WARNING_ALL_HOSTS); | 381 return l10n_util::GetStringUTF16(IDS_EXTENSION_PROMPT_WARNING_ALL_HOSTS); |
353 | 382 |
354 std::vector<std::string> hosts = GetDistinctHosts(); | 383 std::vector<std::string> hosts = GetDistinctHostsForDisplay( |
384 GetEffectiveHostPermissions().patterns()); | |
385 | |
355 if (hosts.size() == 1) { | 386 if (hosts.size() == 1) { |
356 return l10n_util::GetStringFUTF16(IDS_EXTENSION_PROMPT_WARNING_1_HOST, | 387 return l10n_util::GetStringFUTF16(IDS_EXTENSION_PROMPT_WARNING_1_HOST, |
357 UTF8ToUTF16(hosts[0])); | 388 UTF8ToUTF16(hosts[0])); |
358 } else if (hosts.size() == 2) { | 389 } else if (hosts.size() == 2) { |
359 return l10n_util::GetStringFUTF16(IDS_EXTENSION_PROMPT_WARNING_2_HOSTS, | 390 return l10n_util::GetStringFUTF16(IDS_EXTENSION_PROMPT_WARNING_2_HOSTS, |
360 UTF8ToUTF16(hosts[0]), | 391 UTF8ToUTF16(hosts[0]), |
361 UTF8ToUTF16(hosts[1])); | 392 UTF8ToUTF16(hosts[1])); |
362 } else if (hosts.size() == 3) { | 393 } else if (hosts.size() == 3) { |
363 return l10n_util::GetStringFUTF16(IDS_EXTENSION_PROMPT_WARNING_3_HOSTS, | 394 return l10n_util::GetStringFUTF16(IDS_EXTENSION_PROMPT_WARNING_3_HOSTS, |
364 UTF8ToUTF16(hosts[0]), | 395 UTF8ToUTF16(hosts[0]), |
(...skipping 744 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1109 return true; | 1140 return true; |
1110 | 1141 |
1111 // If the extension hadn't been granted access to all hosts in the past, then | 1142 // If the extension hadn't been granted access to all hosts in the past, then |
1112 // see if the extension requires more host permissions. | 1143 // see if the extension requires more host permissions. |
1113 if (!HasEffectiveAccessToAllHosts(granted_extent, granted_apis)) { | 1144 if (!HasEffectiveAccessToAllHosts(granted_extent, granted_apis)) { |
1114 if (new_extension->HasEffectiveAccessToAllHosts()) | 1145 if (new_extension->HasEffectiveAccessToAllHosts()) |
1115 return true; | 1146 return true; |
1116 | 1147 |
1117 const ExtensionExtent new_extent = | 1148 const ExtensionExtent new_extent = |
1118 new_extension->GetEffectiveHostPermissions(); | 1149 new_extension->GetEffectiveHostPermissions(); |
1119 std::vector<std::string> new_hosts = | |
1120 GetDistinctHosts(new_extent.patterns()); | |
1121 std::vector<std::string> old_hosts = | |
1122 GetDistinctHosts(granted_extent.patterns()); | |
1123 | 1150 |
1124 std::set<std::string> old_hosts_set(old_hosts.begin(), old_hosts.end()); | 1151 if (IsElevatedHostList(granted_extent.patterns(), new_extent.patterns())) |
1125 std::set<std::string> new_hosts_set(new_hosts.begin(), new_hosts.end()); | |
1126 std::set<std::string> new_hosts_only; | |
1127 | |
1128 std::set_difference(new_hosts_set.begin(), new_hosts_set.end(), | |
1129 old_hosts_set.begin(), old_hosts_set.end(), | |
1130 std::inserter(new_hosts_only, new_hosts_only.begin())); | |
1131 | |
1132 if (new_hosts_only.size()) | |
1133 return true; | 1152 return true; |
1134 } | 1153 } |
1135 | 1154 |
1136 std::set<std::string> new_apis = new_extension->api_permissions(); | 1155 std::set<std::string> new_apis = new_extension->api_permissions(); |
1137 std::set<std::string> new_apis_only; | 1156 std::set<std::string> new_apis_only; |
1138 std::set_difference(new_apis.begin(), new_apis.end(), | 1157 std::set_difference(new_apis.begin(), new_apis.end(), |
1139 granted_apis.begin(), granted_apis.end(), | 1158 granted_apis.begin(), granted_apis.end(), |
1140 std::inserter(new_apis_only, new_apis_only.begin())); | 1159 std::inserter(new_apis_only, new_apis_only.begin())); |
1141 | 1160 |
1142 // Ignore API permissions that don't require user approval when deciding if | 1161 // Ignore API permissions that don't require user approval when deciding if |
(...skipping 1090 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2233 UninstalledExtensionInfo::UninstalledExtensionInfo( | 2252 UninstalledExtensionInfo::UninstalledExtensionInfo( |
2234 const Extension& extension) | 2253 const Extension& extension) |
2235 : extension_id(extension.id()), | 2254 : extension_id(extension.id()), |
2236 extension_api_permissions(extension.api_permissions()), | 2255 extension_api_permissions(extension.api_permissions()), |
2237 is_theme(extension.is_theme()), | 2256 is_theme(extension.is_theme()), |
2238 is_app(extension.is_app()), | 2257 is_app(extension.is_app()), |
2239 converted_from_user_script(extension.converted_from_user_script()), | 2258 converted_from_user_script(extension.converted_from_user_script()), |
2240 update_url(extension.update_url()) {} | 2259 update_url(extension.update_url()) {} |
2241 | 2260 |
2242 UninstalledExtensionInfo::~UninstalledExtensionInfo() {} | 2261 UninstalledExtensionInfo::~UninstalledExtensionInfo() {} |
OLD | NEW |