OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 <iterator> | 8 #include <iterator> |
9 #include <set> | 9 #include <set> |
10 | 10 |
(...skipping 1988 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1999 // default extension state to DISABLED when the --disable-extensions flag | 1999 // default extension state to DISABLED when the --disable-extensions flag |
2000 // is set (http://crbug.com/29067). | 2000 // is set (http://crbug.com/29067). |
2001 if (!extensions_enabled() && | 2001 if (!extensions_enabled() && |
2002 !extension->is_theme() && | 2002 !extension->is_theme() && |
2003 extension->location() != Manifest::COMPONENT && | 2003 extension->location() != Manifest::COMPONENT && |
2004 !Manifest::IsExternalLocation(extension->location())) { | 2004 !Manifest::IsExternalLocation(extension->location())) { |
2005 return; | 2005 return; |
2006 } | 2006 } |
2007 | 2007 |
2008 bool is_extension_upgrade = false; | 2008 bool is_extension_upgrade = false; |
2009 if (const Extension* old = GetInstalledExtension(extension->id())) { | 2009 bool is_extension_installed = false; |
2010 is_extension_upgrade = true; | 2010 const Extension* old = GetInstalledExtension(extension->id()); |
2011 DCHECK_NE(extension, old); | 2011 if (old) { |
| 2012 is_extension_installed = true; |
| 2013 int version_compare_result = |
| 2014 extension->version()->CompareTo(*(old->version())); |
| 2015 is_extension_upgrade = version_compare_result > 0; |
2012 // Other than for unpacked extensions, CrxInstaller should have guaranteed | 2016 // Other than for unpacked extensions, CrxInstaller should have guaranteed |
2013 // that we aren't downgrading. | 2017 // that we aren't downgrading. |
2014 if (!Manifest::IsUnpackedLocation(extension->location())) | 2018 if (!Manifest::IsUnpackedLocation(extension->location())) |
2015 CHECK_GE(extension->version()->CompareTo(*(old->version())), 0); | 2019 CHECK_GE(version_compare_result, 0); |
2016 } | 2020 } |
2017 SetBeingUpgraded(extension, is_extension_upgrade); | 2021 SetBeingUpgraded(extension, is_extension_upgrade); |
2018 | 2022 |
2019 // The extension is now loaded, remove its data from unloaded extension map. | 2023 // The extension is now loaded, remove its data from unloaded extension map. |
2020 unloaded_extension_paths_.erase(extension->id()); | 2024 unloaded_extension_paths_.erase(extension->id()); |
2021 | 2025 |
2022 // If a terminated extension is loaded, remove it from the terminated list. | 2026 // If a terminated extension is loaded, remove it from the terminated list. |
2023 UntrackTerminatedExtension(extension->id()); | 2027 UntrackTerminatedExtension(extension->id()); |
2024 | 2028 |
2025 // If the extension was disabled for a reload, then enable it. | 2029 // If the extension was disabled for a reload, then enable it. |
2026 bool reloading = reloading_extensions_.erase(extension->id()) > 0; | 2030 bool reloading = reloading_extensions_.erase(extension->id()) > 0; |
2027 | 2031 |
2028 // Check if the extension's privileges have changed and mark the | 2032 // Check if the extension's privileges have changed and mark the |
2029 // extension disabled if necessary. | 2033 // extension disabled if necessary. |
2030 CheckPermissionsIncrease(extension, is_extension_upgrade); | 2034 CheckPermissionsIncrease(extension, is_extension_installed); |
2031 | 2035 |
2032 if (is_extension_upgrade && !reloading) { | 2036 if (is_extension_installed && !reloading) { |
2033 // To upgrade an extension in place, unload the old one and then load the | 2037 // To upgrade an extension in place, unload the old one and then load the |
2034 // new one. ReloadExtension disables the extension, which is sufficient. | 2038 // new one. ReloadExtension disables the extension, which is sufficient. |
2035 UnloadExtension(extension->id(), extension_misc::UNLOAD_REASON_UPDATE); | 2039 UnloadExtension(extension->id(), extension_misc::UNLOAD_REASON_UPDATE); |
2036 } | 2040 } |
2037 | 2041 |
2038 if (extension_prefs_->IsExtensionBlacklisted(extension->id())) { | 2042 if (extension_prefs_->IsExtensionBlacklisted(extension->id())) { |
2039 // Only prefs is checked for the blacklist. We rely on callers to check the | 2043 // Only prefs is checked for the blacklist. We rely on callers to check the |
2040 // blacklist before calling into here, e.g. CrxInstaller checks before | 2044 // blacklist before calling into here, e.g. CrxInstaller checks before |
2041 // installation then threads through the install and pending install flow | 2045 // installation then threads through the install and pending install flow |
2042 // of this class, and we check when loading installed extensions. | 2046 // of this class, and we check when loading installed extensions. |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2125 adjusted_active = PermissionSet::CreateUnion( | 2129 adjusted_active = PermissionSet::CreateUnion( |
2126 extensions::PermissionsData::GetRequiredPermissions(extension), | 2130 extensions::PermissionsData::GetRequiredPermissions(extension), |
2127 adjusted_active.get()); | 2131 adjusted_active.get()); |
2128 | 2132 |
2129 extensions::PermissionsUpdater perms_updater(profile()); | 2133 extensions::PermissionsUpdater perms_updater(profile()); |
2130 perms_updater.UpdateActivePermissions(extension, adjusted_active.get()); | 2134 perms_updater.UpdateActivePermissions(extension, adjusted_active.get()); |
2131 } | 2135 } |
2132 } | 2136 } |
2133 | 2137 |
2134 void ExtensionService::CheckPermissionsIncrease(const Extension* extension, | 2138 void ExtensionService::CheckPermissionsIncrease(const Extension* extension, |
2135 bool is_extension_upgrade) { | 2139 bool is_extension_installed) { |
2136 UpdateActivePermissions(extension); | 2140 UpdateActivePermissions(extension); |
2137 | 2141 |
2138 // We keep track of all permissions the user has granted each extension. | 2142 // We keep track of all permissions the user has granted each extension. |
2139 // This allows extensions to gracefully support backwards compatibility | 2143 // This allows extensions to gracefully support backwards compatibility |
2140 // by including unknown permissions in their manifests. When the user | 2144 // by including unknown permissions in their manifests. When the user |
2141 // installs the extension, only the recognized permissions are recorded. | 2145 // installs the extension, only the recognized permissions are recorded. |
2142 // When the unknown permissions become recognized (e.g., through browser | 2146 // When the unknown permissions become recognized (e.g., through browser |
2143 // upgrade), we can prompt the user to accept these new permissions. | 2147 // upgrade), we can prompt the user to accept these new permissions. |
2144 // Extensions can also silently upgrade to less permissions, and then | 2148 // Extensions can also silently upgrade to less permissions, and then |
2145 // silently upgrade to a version that adds these permissions back. | 2149 // silently upgrade to a version that adds these permissions back. |
2146 // | 2150 // |
2147 // For example, pretend that Chrome 10 includes a permission "omnibox" | 2151 // For example, pretend that Chrome 10 includes a permission "omnibox" |
2148 // for an API that adds suggestions to the omnibox. An extension can | 2152 // for an API that adds suggestions to the omnibox. An extension can |
2149 // maintain backwards compatibility while still having "omnibox" in the | 2153 // maintain backwards compatibility while still having "omnibox" in the |
2150 // manifest. If a user installs the extension on Chrome 9, the browser | 2154 // manifest. If a user installs the extension on Chrome 9, the browser |
2151 // will record the permissions it recognized, not including "omnibox." | 2155 // will record the permissions it recognized, not including "omnibox." |
2152 // When upgrading to Chrome 10, "omnibox" will be recognized and Chrome | 2156 // When upgrading to Chrome 10, "omnibox" will be recognized and Chrome |
2153 // will disable the extension and prompt the user to approve the increase | 2157 // will disable the extension and prompt the user to approve the increase |
2154 // in privileges. The extension could then release a new version that | 2158 // in privileges. The extension could then release a new version that |
2155 // removes the "omnibox" permission. When the user upgrades, Chrome will | 2159 // removes the "omnibox" permission. When the user upgrades, Chrome will |
2156 // still remember that "omnibox" had been granted, so that if the | 2160 // still remember that "omnibox" had been granted, so that if the |
2157 // extension once again includes "omnibox" in an upgrade, the extension | 2161 // extension once again includes "omnibox" in an upgrade, the extension |
2158 // can upgrade without requiring this user's approval. | 2162 // can upgrade without requiring this user's approval. |
2159 int disable_reasons = extension_prefs_->GetDisableReasons(extension->id()); | 2163 int disable_reasons = extension_prefs_->GetDisableReasons(extension->id()); |
2160 | 2164 |
2161 bool auto_grant_permission = | 2165 bool auto_grant_permission = |
2162 (!is_extension_upgrade && extension->was_installed_by_default()) || | 2166 (!is_extension_installed && extension->was_installed_by_default()) || |
2163 chrome::IsRunningInForcedAppMode(); | 2167 chrome::IsRunningInForcedAppMode(); |
2164 // Silently grant all active permissions to default apps only on install. | 2168 // Silently grant all active permissions to default apps only on install. |
2165 // After install they should behave like other apps. | 2169 // After install they should behave like other apps. |
2166 // Silently grant all active permissions to apps install in kiosk mode on both | 2170 // Silently grant all active permissions to apps install in kiosk mode on both |
2167 // install and update. | 2171 // install and update. |
2168 if (auto_grant_permission) | 2172 if (auto_grant_permission) |
2169 GrantPermissions(extension); | 2173 GrantPermissions(extension); |
2170 | 2174 |
2171 bool is_privilege_increase = false; | 2175 bool is_privilege_increase = false; |
2172 // We only need to compare the granted permissions to the current permissions | 2176 // We only need to compare the granted permissions to the current permissions |
2173 // if the extension is not allowed to silently increase its permissions. | 2177 // if the extension is not allowed to silently increase its permissions. |
2174 if (!extensions::PermissionsData::CanSilentlyIncreasePermissions(extension) && | 2178 if (!extensions::PermissionsData::CanSilentlyIncreasePermissions(extension) && |
2175 !auto_grant_permission) { | 2179 !auto_grant_permission) { |
2176 // Add all the recognized permissions if the granted permissions list | 2180 // Add all the recognized permissions if the granted permissions list |
2177 // hasn't been initialized yet. | 2181 // hasn't been initialized yet. |
2178 scoped_refptr<PermissionSet> granted_permissions = | 2182 scoped_refptr<PermissionSet> granted_permissions = |
2179 extension_prefs_->GetGrantedPermissions(extension->id()); | 2183 extension_prefs_->GetGrantedPermissions(extension->id()); |
2180 CHECK(granted_permissions.get()); | 2184 CHECK(granted_permissions.get()); |
2181 | 2185 |
2182 // Here, we check if an extension's privileges have increased in a manner | 2186 // Here, we check if an extension's privileges have increased in a manner |
2183 // that requires the user's approval. This could occur because the browser | 2187 // that requires the user's approval. This could occur because the browser |
2184 // upgraded and recognized additional privileges, or an extension upgrades | 2188 // upgraded and recognized additional privileges, or an extension upgrades |
2185 // to a version that requires additional privileges. | 2189 // to a version that requires additional privileges. |
2186 is_privilege_increase = granted_permissions->HasLessPrivilegesThan( | 2190 is_privilege_increase = granted_permissions->HasLessPrivilegesThan( |
2187 extension->GetActivePermissions().get(), extension->GetType()); | 2191 extension->GetActivePermissions().get(), extension->GetType()); |
2188 } | 2192 } |
2189 | 2193 |
2190 if (is_extension_upgrade) { | 2194 if (is_extension_installed) { |
2191 // If the extension was already disabled, suppress any alerts for becoming | 2195 // If the extension was already disabled, suppress any alerts for becoming |
2192 // disabled on permissions increase. | 2196 // disabled on permissions increase. |
2193 bool previously_disabled = | 2197 bool previously_disabled = |
2194 extension_prefs_->IsExtensionDisabled(extension->id()); | 2198 extension_prefs_->IsExtensionDisabled(extension->id()); |
2195 // Legacy disabled extensions do not have a disable reason. Infer that if | 2199 // Legacy disabled extensions do not have a disable reason. Infer that if |
2196 // there was no permission increase, it was likely disabled by the user. | 2200 // there was no permission increase, it was likely disabled by the user. |
2197 if (previously_disabled && disable_reasons == Extension::DISABLE_NONE && | 2201 if (previously_disabled && disable_reasons == Extension::DISABLE_NONE && |
2198 !extension_prefs_->DidExtensionEscalatePermissions(extension->id())) { | 2202 !extension_prefs_->DidExtensionEscalatePermissions(extension->id())) { |
2199 disable_reasons |= Extension::DISABLE_USER_ACTION; | 2203 disable_reasons |= Extension::DISABLE_USER_ACTION; |
2200 } | 2204 } |
(...skipping 910 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3111 } | 3115 } |
3112 | 3116 |
3113 void ExtensionService::AddUpdateObserver(extensions::UpdateObserver* observer) { | 3117 void ExtensionService::AddUpdateObserver(extensions::UpdateObserver* observer) { |
3114 update_observers_.AddObserver(observer); | 3118 update_observers_.AddObserver(observer); |
3115 } | 3119 } |
3116 | 3120 |
3117 void ExtensionService::RemoveUpdateObserver( | 3121 void ExtensionService::RemoveUpdateObserver( |
3118 extensions::UpdateObserver* observer) { | 3122 extensions::UpdateObserver* observer) { |
3119 update_observers_.RemoveObserver(observer); | 3123 update_observers_.RemoveObserver(observer); |
3120 } | 3124 } |
OLD | NEW |