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

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

Issue 7003098: Start refractoring extension permissions into ExtensionPermissionSet. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Cleanup and update ExtensionPermissionSet data model. Created 9 years, 6 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/extension_service.h" 5 #include "chrome/browser/extensions/extension_service.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <set> 8 #include <set>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
(...skipping 947 matching lines...) Expand 10 before | Expand all | Expand 10 after
958 958
959 NotifyExtensionUnloaded(extension, UnloadedExtensionInfo::DISABLE); 959 NotifyExtensionUnloaded(extension, UnloadedExtensionInfo::DISABLE);
960 } 960 }
961 961
962 void ExtensionService::GrantPermissions(const Extension* extension) { 962 void ExtensionService::GrantPermissions(const Extension* extension) {
963 CHECK(extension); 963 CHECK(extension);
964 964
965 // We only maintain the granted permissions prefs for INTERNAL extensions. 965 // We only maintain the granted permissions prefs for INTERNAL extensions.
966 CHECK_EQ(Extension::INTERNAL, extension->location()); 966 CHECK_EQ(Extension::INTERNAL, extension->location());
967 967
968 URLPatternSet effective_hosts = extension->GetEffectiveHostPermissions();
969 extension_prefs_->AddGrantedPermissions(extension->id(), 968 extension_prefs_->AddGrantedPermissions(extension->id(),
970 extension->HasFullPermissions(), 969 extension->permission_set());
971 extension->api_permissions(),
972 effective_hosts);
973 } 970 }
974 971
975 void ExtensionService::GrantPermissionsAndEnableExtension( 972 void ExtensionService::GrantPermissionsAndEnableExtension(
976 const Extension* extension) { 973 const Extension* extension) {
977 CHECK(extension); 974 CHECK(extension);
978 RecordPermissionMessagesHistogram( 975 RecordPermissionMessagesHistogram(
979 extension, "Extensions.Permissions_ReEnable"); 976 extension, "Extensions.Permissions_ReEnable");
980 GrantPermissions(extension); 977 GrantPermissions(extension);
981 extension_prefs_->SetDidExtensionEscalatePermissions(extension, false); 978 extension_prefs_->SetDidExtensionEscalatePermissions(extension, false);
982 EnableExtension(extension->id()); 979 EnableExtension(extension->id());
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
1201 } 1198 }
1202 1199
1203 // static 1200 // static
1204 void ExtensionService::RecordPermissionMessagesHistogram( 1201 void ExtensionService::RecordPermissionMessagesHistogram(
1205 const Extension* e, const char* histogram) { 1202 const Extension* e, const char* histogram) {
1206 // Since this is called from multiple sources, and since the Histogram macros 1203 // Since this is called from multiple sources, and since the Histogram macros
1207 // use statics, we need to manually lookup the Histogram ourselves. 1204 // use statics, we need to manually lookup the Histogram ourselves.
1208 base::Histogram* counter = base::LinearHistogram::FactoryGet( 1205 base::Histogram* counter = base::LinearHistogram::FactoryGet(
1209 histogram, 1206 histogram,
1210 1, 1207 1,
1211 Extension::PermissionMessage::ID_ENUM_BOUNDARY, 1208 ExtensionPermissionMessage::kEnumBoundary,
1212 Extension::PermissionMessage::ID_ENUM_BOUNDARY + 1, 1209 ExtensionPermissionMessage::kEnumBoundary + 1,
1213 base::Histogram::kUmaTargetedHistogramFlag); 1210 base::Histogram::kUmaTargetedHistogramFlag);
1214 1211
1215 std::vector<Extension::PermissionMessage> permissions = 1212 ExtensionPermissionMessages permissions = e->GetPermissionMessages();
1216 e->GetPermissionMessages();
1217 if (permissions.empty()) { 1213 if (permissions.empty()) {
1218 counter->Add(Extension::PermissionMessage::ID_NONE); 1214 counter->Add(ExtensionPermissionMessage::kNone);
1219 } else { 1215 } else {
1220 std::vector<Extension::PermissionMessage>::iterator it; 1216 for (ExtensionPermissionMessages::iterator it = permissions.begin();
1221 for (it = permissions.begin(); it != permissions.end(); ++it) 1217 it != permissions.end(); ++it)
1222 counter->Add(it->message_id()); 1218 counter->Add(it->id());
1223 } 1219 }
1224 } 1220 }
1225 1221
1226 void ExtensionService::LoadInstalledExtension(const ExtensionInfo& info, 1222 void ExtensionService::LoadInstalledExtension(const ExtensionInfo& info,
1227 bool write_to_prefs) { 1223 bool write_to_prefs) {
1228 std::string error; 1224 std::string error;
1229 scoped_refptr<const Extension> extension(NULL); 1225 scoped_refptr<const Extension> extension(NULL);
1230 if (!extension_prefs_->IsExtensionAllowedByPolicy(info.extension_id)) { 1226 if (!extension_prefs_->IsExtensionAllowedByPolicy(info.extension_id)) {
1231 error = errors::kDisabledByPolicy; 1227 error = errors::kDisabledByPolicy;
1232 } else if (info.extension_manifest.get()) { 1228 } else if (info.extension_manifest.get()) {
(...skipping 698 matching lines...) Expand 10 before | Expand all | Expand 10 after
1931 // will record the permissions it recognized, not including "omnibox." 1927 // will record the permissions it recognized, not including "omnibox."
1932 // When upgrading to Chrome 10, "omnibox" will be recognized and Chrome 1928 // When upgrading to Chrome 10, "omnibox" will be recognized and Chrome
1933 // will disable the extension and prompt the user to approve the increase 1929 // will disable the extension and prompt the user to approve the increase
1934 // in privileges. The extension could then release a new version that 1930 // in privileges. The extension could then release a new version that
1935 // removes the "omnibox" permission. When the user upgrades, Chrome will 1931 // removes the "omnibox" permission. When the user upgrades, Chrome will
1936 // still remember that "omnibox" had been granted, so that if the 1932 // still remember that "omnibox" had been granted, so that if the
1937 // extension once again includes "omnibox" in an upgrade, the extension 1933 // extension once again includes "omnibox" in an upgrade, the extension
1938 // can upgrade without requiring this user's approval. 1934 // can upgrade without requiring this user's approval.
1939 const Extension* old = GetExtensionByIdInternal(extension->id(), 1935 const Extension* old = GetExtensionByIdInternal(extension->id(),
1940 true, true, false); 1936 true, true, false);
1941 bool granted_full_access;
1942 std::set<std::string> granted_apis;
1943 URLPatternSet granted_extent;
1944
1945 bool is_extension_upgrade = old != NULL; 1937 bool is_extension_upgrade = old != NULL;
1946 bool is_privilege_increase = false; 1938 bool is_privilege_increase = false;
1947 1939
1948 // We only record the granted permissions for INTERNAL extensions, since 1940 // We only record the granted permissions for INTERNAL extensions, since
1949 // they can't silently increase privileges. 1941 // they can't silently increase privileges.
1950 if (extension->location() == Extension::INTERNAL) { 1942 if (extension->location() == Extension::INTERNAL) {
1951 // Add all the recognized permissions if the granted permissions list 1943 // Add all the recognized permissions if the granted permissions list
1952 // hasn't been initialized yet. 1944 // hasn't been initialized yet.
1953 if (!extension_prefs_->GetGrantedPermissions(extension->id(), 1945 scoped_ptr<ExtensionPermissionSet> granted_permissions(
1954 &granted_full_access, 1946 extension_prefs_->GetGrantedPermissions(extension->id()));
1955 &granted_apis, 1947 CHECK(granted_permissions.get());
1956 &granted_extent)) {
1957 GrantPermissions(extension);
1958 CHECK(extension_prefs_->GetGrantedPermissions(extension->id(),
1959 &granted_full_access,
1960 &granted_apis,
1961 &granted_extent));
1962 }
1963 1948
1964 // Here, we check if an extension's privileges have increased in a manner 1949 // Here, we check if an extension's privileges have increased in a manner
1965 // that requires the user's approval. This could occur because the browser 1950 // that requires the user's approval. This could occur because the browser
1966 // upgraded and recognized additional privileges, or an extension upgrades 1951 // upgraded and recognized additional privileges, or an extension upgrades
1967 // to a version that requires additional privileges. 1952 // to a version that requires additional privileges.
1968 is_privilege_increase = Extension::IsPrivilegeIncrease( 1953 is_privilege_increase =
1969 granted_full_access, granted_apis, granted_extent, extension); 1954 granted_permissions->HasLessPrivilegesThan(extension->permission_set());
1970 } 1955 }
1971 1956
1972 if (is_extension_upgrade) { 1957 if (is_extension_upgrade) {
1973 // Other than for unpacked extensions, CrxInstaller should have guaranteed 1958 // Other than for unpacked extensions, CrxInstaller should have guaranteed
1974 // that we aren't downgrading. 1959 // that we aren't downgrading.
1975 if (extension->location() != Extension::LOAD) 1960 if (extension->location() != Extension::LOAD)
1976 CHECK(extension->version()->CompareTo(*(old->version())) >= 0); 1961 CHECK(extension->version()->CompareTo(*(old->version())) >= 0);
1977 1962
1978 // Extensions get upgraded if the privileges are allowed to increase or 1963 // Extensions get upgraded if the privileges are allowed to increase or
1979 // the privileges haven't increased. 1964 // the privileges haven't increased.
(...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after
2430 2415
2431 ExtensionService::NaClModuleInfoList::iterator 2416 ExtensionService::NaClModuleInfoList::iterator
2432 ExtensionService::FindNaClModule(const GURL& url) { 2417 ExtensionService::FindNaClModule(const GURL& url) {
2433 for (NaClModuleInfoList::iterator iter = nacl_module_list_.begin(); 2418 for (NaClModuleInfoList::iterator iter = nacl_module_list_.begin();
2434 iter != nacl_module_list_.end(); ++iter) { 2419 iter != nacl_module_list_.end(); ++iter) {
2435 if (iter->url == url) 2420 if (iter->url == url)
2436 return iter; 2421 return iter;
2437 } 2422 }
2438 return nacl_module_list_.end(); 2423 return nacl_module_list_.end();
2439 } 2424 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698