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

Side by Side Diff: chrome/browser/extensions/extensions_service.cc

Issue 4687005: Track permissions granted to extensions in prefs (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 10 years, 1 month 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
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/browser/extensions/extensions_service.h" 5 #include "chrome/browser/extensions/extensions_service.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 933 matching lines...) Expand 10 before | Expand all | Expand 10 after
944 extension); 944 extension);
945 extensions_.erase(iter); 945 extensions_.erase(iter);
946 946
947 ExtensionDOMUI::UnregisterChromeURLOverrides(profile_, 947 ExtensionDOMUI::UnregisterChromeURLOverrides(profile_,
948 extension->GetChromeURLOverrides()); 948 extension->GetChromeURLOverrides());
949 949
950 NotifyExtensionUnloaded(extension); 950 NotifyExtensionUnloaded(extension);
951 UpdateActiveExtensionsInCrashReporter(); 951 UpdateActiveExtensionsInCrashReporter();
952 } 952 }
953 953
954 void ExtensionsService::GrantPermissions(const Extension* extension) {
955 DCHECK(extension);
956
957 std::set<std::string> effective_hosts;
958 extension->GetEffectiveHostPermissions().GetAsStringSet(&effective_hosts);
959
960 extension_prefs_->GrantPermissions(extension->id(),
961 extension->api_permissions(),
962 effective_hosts);
963 }
964
965 void ExtensionsService::GrantPermissionsAndEnableExtension(
966 const Extension* extension) {
967 DCHECK(extension);
968 GrantPermissions(extension);
969 extension_prefs_->SetDidExtensionEscalatePermissions(extension, false);
970 EnableExtension(extension->id());
971 }
972
954 void ExtensionsService::LoadExtension(const FilePath& extension_path) { 973 void ExtensionsService::LoadExtension(const FilePath& extension_path) {
955 BrowserThread::PostTask( 974 BrowserThread::PostTask(
956 BrowserThread::FILE, FROM_HERE, 975 BrowserThread::FILE, FROM_HERE,
957 NewRunnableMethod( 976 NewRunnableMethod(
958 backend_.get(), 977 backend_.get(),
959 &ExtensionsServiceBackend::LoadSingleExtension, 978 &ExtensionsServiceBackend::LoadSingleExtension,
960 extension_path, scoped_refptr<ExtensionsService>(this))); 979 extension_path, scoped_refptr<ExtensionsService>(this)));
961 } 980 }
962 981
963 void ExtensionsService::LoadComponentExtensions() { 982 void ExtensionsService::LoadComponentExtensions() {
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
1128 ReportExtensionLoadError(info.extension_path, 1147 ReportExtensionLoadError(info.extension_path,
1129 error, 1148 error,
1130 NotificationType::EXTENSION_INSTALL_ERROR, 1149 NotificationType::EXTENSION_INSTALL_ERROR,
1131 false); 1150 false);
1132 return; 1151 return;
1133 } 1152 }
1134 1153
1135 if (write_to_prefs) 1154 if (write_to_prefs)
1136 extension_prefs_->UpdateManifest(extension); 1155 extension_prefs_->UpdateManifest(extension);
1137 1156
1138 OnExtensionLoaded(extension, true); 1157 // External extensions are allowed to increase their privileges without
1139 1158 // prompting users.
1140 if (Extension::IsExternalLocation(info.extension_location)) { 1159 if (Extension::IsExternalLocation(info.extension_location)) {
1160 OnExtensionLoaded(extension, true);
1141 BrowserThread::PostTask( 1161 BrowserThread::PostTask(
1142 BrowserThread::FILE, FROM_HERE, 1162 BrowserThread::FILE, FROM_HERE,
1143 NewRunnableMethod( 1163 NewRunnableMethod(
1144 backend_.get(), 1164 backend_.get(),
1145 &ExtensionsServiceBackend::CheckExternalUninstall, 1165 &ExtensionsServiceBackend::CheckExternalUninstall,
1146 scoped_refptr<ExtensionsService>(this), 1166 scoped_refptr<ExtensionsService>(this),
1147 info.extension_id)); 1167 info.extension_id));
1168 } else {
1169 OnExtensionLoaded(extension, false);
1148 } 1170 }
1149 } 1171 }
1150 1172
1151 void ExtensionsService::NotifyExtensionLoaded(const Extension* extension) { 1173 void ExtensionsService::NotifyExtensionLoaded(const Extension* extension) {
1152 // The ChromeURLRequestContexts need to be first to know that the extension 1174 // The ChromeURLRequestContexts need to be first to know that the extension
1153 // was loaded, otherwise a race can arise where a renderer that is created 1175 // was loaded, otherwise a race can arise where a renderer that is created
1154 // for the extension may try to load an extension URL with an extension id 1176 // for the extension may try to load an extension URL with an extension id
1155 // that the request context doesn't yet know about. The profile is responsible 1177 // that the request context doesn't yet know about. The profile is responsible
1156 // for ensuring its URLRequestContexts appropriately discover the loaded 1178 // for ensuring its URLRequestContexts appropriately discover the loaded
1157 // extension. 1179 // extension.
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after
1521 old = NULL; 1543 old = NULL;
1522 1544
1523 if (!allow_silent_upgrade) { 1545 if (!allow_silent_upgrade) {
1524 // Extension has changed permissions significantly. Disable it. We 1546 // Extension has changed permissions significantly. Disable it. We
1525 // send a notification below. 1547 // send a notification below.
1526 extension_prefs_->SetExtensionState(extension, Extension::DISABLED); 1548 extension_prefs_->SetExtensionState(extension, Extension::DISABLED);
1527 extension_prefs_->SetDidExtensionEscalatePermissions(extension, true); 1549 extension_prefs_->SetDidExtensionEscalatePermissions(extension, true);
1528 } 1550 }
1529 } 1551 }
1530 1552
1553 // For gracefully handling backwards compatibility, extensions are allowed
1554 // to have unknown permissions in their manifest. We keep track of the last
1555 // known set of permissions, so that we can prompt the user when unknown
Aaron Boodman 2010/11/12 00:05:24 It might be nice to include a little example here
jstritar 2010/11/19 21:38:36 I updated the comment to make more sense and added
1556 // permissions become known.
1557 if (extension->location() == Extension::INTERNAL) {
1558 std::set<std::string> granted_apis;
1559 std::set<std::string> granted_hosts;
1560
1561 // If the granted permissions list hasn't been initialized yet (such
1562 // as when migrating from the old scheme) or privilege increases are
1563 // allowed, then just grant all recognized permissions.
1564 if (!extension_prefs_->GetGrantedPermissions(extension->id(),
1565 &granted_apis,
1566 &granted_hosts) ||
1567 allow_privilege_increase) {
1568 GrantPermissions(extension);
1569
1570 // Here, we disable the extension and prompt the user if the unknown
1571 // permissions are now recognized.
1572 } else if (Extension::IsPrivilegeIncrease(
1573 &granted_apis, &granted_hosts, extension)) {
1574 extension_prefs_->SetExtensionState(extension, Extension::DISABLED);
1575 extension_prefs_->SetDidExtensionEscalatePermissions(extension, true);
1576 }
1577 }
1578
1531 switch (extension_prefs_->GetExtensionState(extension->id())) { 1579 switch (extension_prefs_->GetExtensionState(extension->id())) {
1532 case Extension::ENABLED: 1580 case Extension::ENABLED:
1533 extensions_.push_back(scoped_extension); 1581 extensions_.push_back(scoped_extension);
1534 1582
1535 NotifyExtensionLoaded(extension); 1583 NotifyExtensionLoaded(extension);
1536 1584
1537 ExtensionDOMUI::RegisterChromeURLOverrides(profile_, 1585 ExtensionDOMUI::RegisterChromeURLOverrides(profile_,
1538 extension->GetChromeURLOverrides()); 1586 extension->GetChromeURLOverrides());
1539 break; 1587 break;
1540 case Extension::DISABLED: 1588 case Extension::DISABLED:
(...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after
1947 } 1995 }
1948 1996
1949 bool ExtensionsService::IsBeingUpgraded(const Extension* extension) { 1997 bool ExtensionsService::IsBeingUpgraded(const Extension* extension) {
1950 return extension_runtime_data_[extension->id()].being_upgraded; 1998 return extension_runtime_data_[extension->id()].being_upgraded;
1951 } 1999 }
1952 2000
1953 void ExtensionsService::SetBeingUpgraded(const Extension* extension, 2001 void ExtensionsService::SetBeingUpgraded(const Extension* extension,
1954 bool value) { 2002 bool value) {
1955 extension_runtime_data_[extension->id()].being_upgraded = value; 2003 extension_runtime_data_[extension->id()].being_upgraded = value;
1956 } 2004 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698