OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 using base::Time; | 127 using base::Time; |
128 using content::BrowserContext; | 128 using content::BrowserContext; |
129 using content::BrowserThread; | 129 using content::BrowserThread; |
130 using content::DevToolsAgentHost; | 130 using content::DevToolsAgentHost; |
131 using content::DevToolsAgentHostRegistry; | 131 using content::DevToolsAgentHostRegistry; |
132 using content::PluginService; | 132 using content::PluginService; |
133 using extensions::Extension; | 133 using extensions::Extension; |
134 using extensions::ExtensionIdSet; | 134 using extensions::ExtensionIdSet; |
135 using extensions::ExtensionInfo; | 135 using extensions::ExtensionInfo; |
136 using extensions::UnloadedExtensionInfo; | 136 using extensions::UnloadedExtensionInfo; |
| 137 using extensions::PermissionMessage; |
| 138 using extensions::PermissionMessages; |
| 139 using extensions::PermissionSet; |
137 | 140 |
138 namespace errors = extension_manifest_errors; | 141 namespace errors = extension_manifest_errors; |
139 | 142 |
140 namespace { | 143 namespace { |
141 | 144 |
142 #if defined(OS_LINUX) | 145 #if defined(OS_LINUX) |
143 static const int kOmniboxIconPaddingLeft = 2; | 146 static const int kOmniboxIconPaddingLeft = 2; |
144 static const int kOmniboxIconPaddingRight = 2; | 147 static const int kOmniboxIconPaddingRight = 2; |
145 #elif defined(OS_MACOSX) | 148 #elif defined(OS_MACOSX) |
146 static const int kOmniboxIconPaddingLeft = 0; | 149 static const int kOmniboxIconPaddingLeft = 0; |
(...skipping 749 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
896 } | 899 } |
897 | 900 |
898 // static | 901 // static |
899 void ExtensionService::RecordPermissionMessagesHistogram( | 902 void ExtensionService::RecordPermissionMessagesHistogram( |
900 const Extension* e, const char* histogram) { | 903 const Extension* e, const char* histogram) { |
901 // Since this is called from multiple sources, and since the Histogram macros | 904 // Since this is called from multiple sources, and since the Histogram macros |
902 // use statics, we need to manually lookup the Histogram ourselves. | 905 // use statics, we need to manually lookup the Histogram ourselves. |
903 base::Histogram* counter = base::LinearHistogram::FactoryGet( | 906 base::Histogram* counter = base::LinearHistogram::FactoryGet( |
904 histogram, | 907 histogram, |
905 1, | 908 1, |
906 ExtensionPermissionMessage::kEnumBoundary, | 909 PermissionMessage::kEnumBoundary, |
907 ExtensionPermissionMessage::kEnumBoundary + 1, | 910 PermissionMessage::kEnumBoundary + 1, |
908 base::Histogram::kUmaTargetedHistogramFlag); | 911 base::Histogram::kUmaTargetedHistogramFlag); |
909 | 912 |
910 ExtensionPermissionMessages permissions = e->GetPermissionMessages(); | 913 PermissionMessages permissions = e->GetPermissionMessages(); |
911 if (permissions.empty()) { | 914 if (permissions.empty()) { |
912 counter->Add(ExtensionPermissionMessage::kNone); | 915 counter->Add(PermissionMessage::kNone); |
913 } else { | 916 } else { |
914 for (ExtensionPermissionMessages::iterator it = permissions.begin(); | 917 for (PermissionMessages::iterator it = permissions.begin(); |
915 it != permissions.end(); ++it) | 918 it != permissions.end(); ++it) |
916 counter->Add(it->id()); | 919 counter->Add(it->id()); |
917 } | 920 } |
918 } | 921 } |
919 | 922 |
920 void ExtensionService::NotifyExtensionLoaded(const Extension* extension) { | 923 void ExtensionService::NotifyExtensionLoaded(const Extension* extension) { |
921 // The ChromeURLRequestContexts need to be first to know that the extension | 924 // The ChromeURLRequestContexts need to be first to know that the extension |
922 // was loaded, otherwise a race can arise where a renderer that is created | 925 // was loaded, otherwise a race can arise where a renderer that is created |
923 // for the extension may try to load an extension URL with an extension id | 926 // for the extension may try to load an extension URL with an extension id |
924 // that the request context doesn't yet know about. The profile is responsible | 927 // that the request context doesn't yet know about. The profile is responsible |
(...skipping 1024 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1949 | 1952 |
1950 extensions_.Insert(scoped_extension); | 1953 extensions_.Insert(scoped_extension); |
1951 SyncExtensionChangeIfNeeded(*extension); | 1954 SyncExtensionChangeIfNeeded(*extension); |
1952 NotifyExtensionLoaded(extension); | 1955 NotifyExtensionLoaded(extension); |
1953 } | 1956 } |
1954 | 1957 |
1955 void ExtensionService::InitializePermissions(const Extension* extension) { | 1958 void ExtensionService::InitializePermissions(const Extension* extension) { |
1956 // If the extension has used the optional permissions API, it will have a | 1959 // If the extension has used the optional permissions API, it will have a |
1957 // custom set of active permissions defined in the extension prefs. Here, | 1960 // custom set of active permissions defined in the extension prefs. Here, |
1958 // we update the extension's active permissions based on the prefs. | 1961 // we update the extension's active permissions based on the prefs. |
1959 scoped_refptr<ExtensionPermissionSet> active_permissions = | 1962 scoped_refptr<PermissionSet> active_permissions = |
1960 extension_prefs()->GetActivePermissions(extension->id()); | 1963 extension_prefs()->GetActivePermissions(extension->id()); |
1961 | 1964 |
1962 if (active_permissions.get()) { | 1965 if (active_permissions.get()) { |
1963 // We restrict the active permissions to be within the bounds defined in the | 1966 // We restrict the active permissions to be within the bounds defined in the |
1964 // extension's manifest. | 1967 // extension's manifest. |
1965 // a) active permissions must be a subset of optional + default permissions | 1968 // a) active permissions must be a subset of optional + default permissions |
1966 // b) active permissions must contains all default permissions | 1969 // b) active permissions must contains all default permissions |
1967 scoped_refptr<ExtensionPermissionSet> total_permissions = | 1970 scoped_refptr<PermissionSet> total_permissions = |
1968 ExtensionPermissionSet::CreateUnion( | 1971 PermissionSet::CreateUnion( |
1969 extension->required_permission_set(), | 1972 extension->required_permission_set(), |
1970 extension->optional_permission_set()); | 1973 extension->optional_permission_set()); |
1971 | 1974 |
1972 // Make sure the active permissions contain no more than optional + default. | 1975 // Make sure the active permissions contain no more than optional + default. |
1973 scoped_refptr<ExtensionPermissionSet> adjusted_active = | 1976 scoped_refptr<PermissionSet> adjusted_active = |
1974 ExtensionPermissionSet::CreateIntersection( | 1977 PermissionSet::CreateIntersection( |
1975 total_permissions.get(), active_permissions.get()); | 1978 total_permissions.get(), active_permissions.get()); |
1976 | 1979 |
1977 // Make sure the active permissions contain the default permissions. | 1980 // Make sure the active permissions contain the default permissions. |
1978 adjusted_active = ExtensionPermissionSet::CreateUnion( | 1981 adjusted_active = PermissionSet::CreateUnion( |
1979 extension->required_permission_set(), adjusted_active.get()); | 1982 extension->required_permission_set(), adjusted_active.get()); |
1980 | 1983 |
1981 extensions::PermissionsUpdater perms_updater(profile()); | 1984 extensions::PermissionsUpdater perms_updater(profile()); |
1982 perms_updater.UpdateActivePermissions(extension, adjusted_active); | 1985 perms_updater.UpdateActivePermissions(extension, adjusted_active); |
1983 } | 1986 } |
1984 | 1987 |
1985 // We keep track of all permissions the user has granted each extension. | 1988 // We keep track of all permissions the user has granted each extension. |
1986 // This allows extensions to gracefully support backwards compatibility | 1989 // This allows extensions to gracefully support backwards compatibility |
1987 // by including unknown permissions in their manifests. When the user | 1990 // by including unknown permissions in their manifests. When the user |
1988 // installs the extension, only the recognized permissions are recorded. | 1991 // installs the extension, only the recognized permissions are recorded. |
(...skipping 20 matching lines...) Expand all Loading... |
2009 bool is_privilege_increase = false; | 2012 bool is_privilege_increase = false; |
2010 bool previously_disabled = false; | 2013 bool previously_disabled = false; |
2011 Extension::DisableReason disable_reason = | 2014 Extension::DisableReason disable_reason = |
2012 extension_prefs_->GetDisableReason(extension->id()); | 2015 extension_prefs_->GetDisableReason(extension->id()); |
2013 | 2016 |
2014 // We only need to compare the granted permissions to the current permissions | 2017 // We only need to compare the granted permissions to the current permissions |
2015 // if the extension is not allowed to silently increase its permissions. | 2018 // if the extension is not allowed to silently increase its permissions. |
2016 if (!extension->CanSilentlyIncreasePermissions()) { | 2019 if (!extension->CanSilentlyIncreasePermissions()) { |
2017 // Add all the recognized permissions if the granted permissions list | 2020 // Add all the recognized permissions if the granted permissions list |
2018 // hasn't been initialized yet. | 2021 // hasn't been initialized yet. |
2019 scoped_refptr<ExtensionPermissionSet> granted_permissions = | 2022 scoped_refptr<PermissionSet> granted_permissions = |
2020 extension_prefs_->GetGrantedPermissions(extension->id()); | 2023 extension_prefs_->GetGrantedPermissions(extension->id()); |
2021 CHECK(granted_permissions.get()); | 2024 CHECK(granted_permissions.get()); |
2022 | 2025 |
2023 // Here, we check if an extension's privileges have increased in a manner | 2026 // Here, we check if an extension's privileges have increased in a manner |
2024 // that requires the user's approval. This could occur because the browser | 2027 // that requires the user's approval. This could occur because the browser |
2025 // upgraded and recognized additional privileges, or an extension upgrades | 2028 // upgraded and recognized additional privileges, or an extension upgrades |
2026 // to a version that requires additional privileges. | 2029 // to a version that requires additional privileges. |
2027 is_privilege_increase = | 2030 is_privilege_increase = |
2028 granted_permissions->HasLessPrivilegesThan( | 2031 granted_permissions->HasLessPrivilegesThan( |
2029 extension->GetActivePermissions()); | 2032 extension->GetActivePermissions()); |
(...skipping 526 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2556 | 2559 |
2557 // To coexist with certain unit tests that don't have a work-thread message | 2560 // To coexist with certain unit tests that don't have a work-thread message |
2558 // loop available at ExtensionService shutdown, we lazy-initialize this | 2561 // loop available at ExtensionService shutdown, we lazy-initialize this |
2559 // object so that those cases neither create nor destroy an | 2562 // object so that those cases neither create nor destroy an |
2560 // APIResourceController. | 2563 // APIResourceController. |
2561 if (!api_resource_controller_.get()) { | 2564 if (!api_resource_controller_.get()) { |
2562 api_resource_controller_.reset(new extensions::APIResourceController()); | 2565 api_resource_controller_.reset(new extensions::APIResourceController()); |
2563 } | 2566 } |
2564 return api_resource_controller_.get(); | 2567 return api_resource_controller_.get(); |
2565 } | 2568 } |
OLD | NEW |