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

Side by Side Diff: chrome/common/extensions/extension.cc

Issue 173463: Update of the extension install UI: (Closed)
Patch Set: mpcompelte comments Created 11 years, 3 months 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
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 "app/resource_bundle.h" 7 #include "app/resource_bundle.h"
8 #include "base/basictypes.h" 8 #include "base/basictypes.h"
9 #include "base/file_path.h" 9 #include "base/file_path.h"
10 #include "base/file_util.h" 10 #include "base/file_util.h"
(...skipping 508 matching lines...) Expand 10 before | Expand all | Expand 10 after
519 output->append(kKeyBeginFooterMarker); 519 output->append(kKeyBeginFooterMarker);
520 output->append(" "); 520 output->append(" ");
521 output->append(is_public ? kPublic : kPrivate); 521 output->append(is_public ? kPublic : kPrivate);
522 output->append(" "); 522 output->append(" ");
523 output->append(kKeyInfoEndMarker); 523 output->append(kKeyInfoEndMarker);
524 output->append("\n"); 524 output->append("\n");
525 525
526 return true; 526 return true;
527 } 527 }
528 528
529 // static
530 // TODO(aa): A problem with this code is that we silently allow upgrades to
531 // extensions that require less permissions than the current version, but then
532 // we don't silently allow them to go back. In order to fix this, we would need
533 // to remember the max set of permissions we ever granted a single extension.
534 bool Extension::AllowSilentUpgrade(Extension* old_extension,
535 Extension* new_extension) {
536 // If the old extension had native code access, we don't need to go any
537 // further. Things can't get any worse.
538 if (old_extension->plugins().size() > 0)
539 return true;
540
541 // Otherwise, if the new extension has a plugin, no silent upgrade.
542 if (new_extension->plugins().size() > 0)
543 return false;
544
545 // If we are increasing the set of hosts we have access to, no silent upgrade.
546 if (!old_extension->HasAccessToAllHosts()) {
547 if (new_extension->HasAccessToAllHosts())
548 return false;
549
550 std::set<std::string> old_hosts =
551 old_extension->GetEffectiveHostPermissions();
552 std::set<std::string> new_hosts =
553 new_extension->GetEffectiveHostPermissions();
554
555 std::set<std::string> difference;
556 std::set_difference(new_hosts.begin(), new_hosts.end(),
557 old_hosts.begin(), old_hosts.end(),
558 std::insert_iterator<std::set<std::string> >(
559 difference, difference.end()));
560 if (difference.size() > 0)
561 return false;
562 }
563
564 // If we're going from not having api permissions to having them, no silent
565 // upgrade.
566 if (old_extension->api_permissions().size() == 0 &&
567 new_extension->api_permissions().size() > 0)
568 return false;
569
570 // Nothing much has changed. Allow the silent upgrade.
571 return true;
572 }
573
529 bool Extension::InitFromValue(const DictionaryValue& source, bool require_id, 574 bool Extension::InitFromValue(const DictionaryValue& source, bool require_id,
530 std::string* error) { 575 std::string* error) {
531 if (source.HasKey(keys::kPublicKey)) { 576 if (source.HasKey(keys::kPublicKey)) {
532 std::string public_key_bytes; 577 std::string public_key_bytes;
533 if (!source.GetString(keys::kPublicKey, &public_key_) || 578 if (!source.GetString(keys::kPublicKey, &public_key_) ||
534 !ParsePEMKeyBytes(public_key_, &public_key_bytes) || 579 !ParsePEMKeyBytes(public_key_, &public_key_bytes) ||
535 !GenerateIdFromPublicKey(public_key_bytes, &id_)) { 580 !GenerateIdFromPublicKey(public_key_bytes, &id_)) {
536 *error = errors::kInvalidKey; 581 *error = errors::kInvalidKey;
537 return false; 582 return false;
538 } 583 }
(...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after
982 const std::vector<std::string>& icon_paths = it->second->icon_paths(); 1027 const std::vector<std::string>& icon_paths = it->second->icon_paths();
983 for (std::vector<std::string>::const_iterator iter = icon_paths.begin(); 1028 for (std::vector<std::string>::const_iterator iter = icon_paths.begin();
984 iter != icon_paths.end(); ++iter) { 1029 iter != icon_paths.end(); ++iter) {
985 image_paths.insert(FilePath::FromWStringHack(UTF8ToWide(*iter))); 1030 image_paths.insert(FilePath::FromWStringHack(UTF8ToWide(*iter)));
986 } 1031 }
987 } 1032 }
988 1033
989 return image_paths; 1034 return image_paths;
990 } 1035 }
991 1036
992 Extension::PermissionClass Extension::GetPermissionClass() {
993 // Native code can do anything. Highest class.
994 if (!plugins_.empty())
995 return PERMISSION_CLASS_FULL;
996
997 // Access to other sites means the extension can steal cookies (login data)
998 // from those sites.
999 // TODO(mpcomplete): should we only classify for host access outside the
1000 // extension's origin? how?
1001 if (!host_permissions_.empty() || !content_scripts_.empty())
1002 return PERMISSION_CLASS_HIGH;
1003
1004 // Extension can access history data, bookmarks, other personal info.
1005 if (!api_permissions_.empty())
1006 return PERMISSION_CLASS_MEDIUM;
1007
1008 return PERMISSION_CLASS_LOW;
1009 }
1010
1011 bool Extension::GetBackgroundPageReady() { 1037 bool Extension::GetBackgroundPageReady() {
1012 return background_page_ready_ || background_url().is_empty(); 1038 return background_page_ready_ || background_url().is_empty();
1013 } 1039 }
1014 1040
1015 void Extension::SetBackgroundPageReady() { 1041 void Extension::SetBackgroundPageReady() {
1016 DCHECK(!background_url().is_empty()); 1042 DCHECK(!background_url().is_empty());
1017 background_page_ready_ = true; 1043 background_page_ready_ = true;
1018 NotificationService::current()->Notify( 1044 NotificationService::current()->Notify(
1019 NotificationType::EXTENSION_BACKGROUND_PAGE_READY, 1045 NotificationType::EXTENSION_BACKGROUND_PAGE_READY,
1020 Source<Extension>(this), 1046 Source<Extension>(this),
1021 NotificationService::NoDetails()); 1047 NotificationService::NoDetails());
1022 } 1048 }
1023 1049
1024 FilePath Extension::GetIconPath(Icons icon) { 1050 FilePath Extension::GetIconPath(Icons icon) {
1025 std::map<int, std::string>::const_iterator iter = 1051 std::map<int, std::string>::const_iterator iter =
1026 icons_.find(Extension::EXTENSION_ICON_LARGE); 1052 icons_.find(Extension::EXTENSION_ICON_LARGE);
1027 if (iter == icons_.end()) 1053 if (iter == icons_.end())
1028 return FilePath(); 1054 return FilePath();
1029 return GetResourcePath(iter->second); 1055 return GetResourcePath(iter->second);
1030 } 1056 }
1057
1058 const std::set<std::string> Extension::GetEffectiveHostPermissions() const {
1059 std::set<std::string> effective_hosts;
1060
1061 for (HostPermissions::const_iterator host = host_permissions_.begin();
1062 host != host_permissions_.end(); ++host)
1063 effective_hosts.insert(host->host());
1064
1065 for (UserScriptList::const_iterator content_script = content_scripts_.begin();
1066 content_script != content_scripts_.end(); ++content_script) {
1067 UserScript::PatternList::const_iterator pattern =
1068 content_script->url_patterns().begin();
1069 for (; pattern != content_script->url_patterns().end(); ++pattern)
1070 effective_hosts.insert(pattern->host());
1071 }
1072
1073 return effective_hosts;
1074 }
1075
1076 bool Extension::HasAccessToAllHosts() const {
1077 for (HostPermissions::const_iterator host = host_permissions_.begin();
1078 host != host_permissions_.end(); ++host) {
1079 if (host->match_subdomains() && host->host().empty())
1080 return true;
1081 }
1082
1083 for (UserScriptList::const_iterator content_script = content_scripts_.begin();
1084 content_script != content_scripts_.end(); ++content_script) {
1085 UserScript::PatternList::const_iterator pattern =
1086 content_script->url_patterns().begin();
1087 for (; pattern != content_script->url_patterns().end(); ++pattern) {
1088 if (pattern->match_subdomains() && pattern->host().empty())
1089 return true;
1090 }
1091 }
1092
1093 return false;
1094 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698