| 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 809 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 820 return extension_prefs_->IsExternalExtensionUninstalled(extension_id); | 820 return extension_prefs_->IsExternalExtensionUninstalled(extension_id); |
| 821 } | 821 } |
| 822 | 822 |
| 823 void ExtensionService::EnableExtension(const std::string& extension_id) { | 823 void ExtensionService::EnableExtension(const std::string& extension_id) { |
| 824 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 824 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 825 | 825 |
| 826 if (IsExtensionEnabled(extension_id)) | 826 if (IsExtensionEnabled(extension_id)) |
| 827 return; | 827 return; |
| 828 | 828 |
| 829 extension_prefs_->SetExtensionState(extension_id, Extension::ENABLED); | 829 extension_prefs_->SetExtensionState(extension_id, Extension::ENABLED); |
| 830 extension_prefs_->RemoveDisableReason(extension_id); | 830 extension_prefs_->ClearDisableReasons(extension_id); |
| 831 | 831 |
| 832 const Extension* extension = | 832 const Extension* extension = |
| 833 GetExtensionByIdInternal(extension_id, false, true, false); | 833 GetExtensionByIdInternal(extension_id, false, true, false); |
| 834 // This can happen if sync enables an extension that is not | 834 // This can happen if sync enables an extension that is not |
| 835 // installed yet. | 835 // installed yet. |
| 836 if (!extension) | 836 if (!extension) |
| 837 return; | 837 return; |
| 838 | 838 |
| 839 // Move it over to the enabled list. | 839 // Move it over to the enabled list. |
| 840 extensions_.Insert(make_scoped_refptr(extension)); | 840 extensions_.Insert(make_scoped_refptr(extension)); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 865 | 865 |
| 866 const Extension* extension = GetInstalledExtension(extension_id); | 866 const Extension* extension = GetInstalledExtension(extension_id); |
| 867 // |extension| can be NULL if sync disables an extension that is not | 867 // |extension| can be NULL if sync disables an extension that is not |
| 868 // installed yet. | 868 // installed yet. |
| 869 if (extension && | 869 if (extension && |
| 870 !system_->management_policy()->UserMayModifySettings(extension, NULL)) { | 870 !system_->management_policy()->UserMayModifySettings(extension, NULL)) { |
| 871 return; | 871 return; |
| 872 } | 872 } |
| 873 | 873 |
| 874 extension_prefs_->SetExtensionState(extension_id, Extension::DISABLED); | 874 extension_prefs_->SetExtensionState(extension_id, Extension::DISABLED); |
| 875 extension_prefs_->SetDisableReason(extension_id, disable_reason); | 875 extension_prefs_->AddDisableReason(extension_id, disable_reason); |
| 876 | 876 |
| 877 extension = GetExtensionByIdInternal(extension_id, true, false, true); | 877 extension = GetExtensionByIdInternal(extension_id, true, false, true); |
| 878 if (!extension) | 878 if (!extension) |
| 879 return; | 879 return; |
| 880 | 880 |
| 881 // Move it over to the disabled list. | 881 // Move it over to the disabled list. |
| 882 disabled_extensions_.Insert(make_scoped_refptr(extension)); | 882 disabled_extensions_.Insert(make_scoped_refptr(extension)); |
| 883 if (extensions_.Contains(extension->id())) | 883 if (extensions_.Contains(extension->id())) |
| 884 extensions_.Remove(extension->id()); | 884 extensions_.Remove(extension->id()); |
| 885 else | 885 else |
| (...skipping 1052 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1938 | 1938 |
| 1939 bool disabled = extension_prefs_->IsExtensionDisabled(extension->id()); | 1939 bool disabled = extension_prefs_->IsExtensionDisabled(extension->id()); |
| 1940 if (disabled) { | 1940 if (disabled) { |
| 1941 disabled_extensions_.Insert(scoped_extension); | 1941 disabled_extensions_.Insert(scoped_extension); |
| 1942 SyncExtensionChangeIfNeeded(*extension); | 1942 SyncExtensionChangeIfNeeded(*extension); |
| 1943 content::NotificationService::current()->Notify( | 1943 content::NotificationService::current()->Notify( |
| 1944 chrome::NOTIFICATION_EXTENSION_UPDATE_DISABLED, | 1944 chrome::NOTIFICATION_EXTENSION_UPDATE_DISABLED, |
| 1945 content::Source<Profile>(profile_), | 1945 content::Source<Profile>(profile_), |
| 1946 content::Details<const Extension>(extension)); | 1946 content::Details<const Extension>(extension)); |
| 1947 | 1947 |
| 1948 if (extension_prefs_->GetDisableReason(extension->id()) == | 1948 if (extension_prefs_->GetDisableReasons(extension->id()) & |
| 1949 Extension::DISABLE_PERMISSIONS_INCREASE) { | 1949 Extension::DISABLE_PERMISSIONS_INCREASE) { |
| 1950 extensions::AddExtensionDisabledError(this, extension); | 1950 extensions::AddExtensionDisabledError(this, extension); |
| 1951 } | 1951 } |
| 1952 return; | 1952 return; |
| 1953 } | 1953 } |
| 1954 | 1954 |
| 1955 // All apps that are displayed in the launcher are ordered by their ordinals | 1955 // All apps that are displayed in the launcher are ordered by their ordinals |
| 1956 // so we must ensure they have valid ordinals. | 1956 // so we must ensure they have valid ordinals. |
| 1957 if (extension->ShouldDisplayInLauncher()) | 1957 if (extension->ShouldDisplayInLauncher()) |
| 1958 extension_prefs_->extension_sorting()->EnsureValidOrdinals(extension->id()); | 1958 extension_prefs_->extension_sorting()->EnsureValidOrdinals(extension->id()); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2011 // in privileges. The extension could then release a new version that | 2011 // in privileges. The extension could then release a new version that |
| 2012 // removes the "omnibox" permission. When the user upgrades, Chrome will | 2012 // removes the "omnibox" permission. When the user upgrades, Chrome will |
| 2013 // still remember that "omnibox" had been granted, so that if the | 2013 // still remember that "omnibox" had been granted, so that if the |
| 2014 // extension once again includes "omnibox" in an upgrade, the extension | 2014 // extension once again includes "omnibox" in an upgrade, the extension |
| 2015 // can upgrade without requiring this user's approval. | 2015 // can upgrade without requiring this user's approval. |
| 2016 const Extension* old = GetExtensionByIdInternal(extension->id(), | 2016 const Extension* old = GetExtensionByIdInternal(extension->id(), |
| 2017 true, true, false); | 2017 true, true, false); |
| 2018 bool is_extension_upgrade = old != NULL; | 2018 bool is_extension_upgrade = old != NULL; |
| 2019 bool is_privilege_increase = false; | 2019 bool is_privilege_increase = false; |
| 2020 bool previously_disabled = false; | 2020 bool previously_disabled = false; |
| 2021 Extension::DisableReason disable_reason = | 2021 int disable_reasons = extension_prefs_->GetDisableReasons(extension->id()); |
| 2022 extension_prefs_->GetDisableReason(extension->id()); | |
| 2023 | 2022 |
| 2024 // We only need to compare the granted permissions to the current permissions | 2023 // We only need to compare the granted permissions to the current permissions |
| 2025 // if the extension is not allowed to silently increase its permissions. | 2024 // if the extension is not allowed to silently increase its permissions. |
| 2026 if (!extension->CanSilentlyIncreasePermissions()) { | 2025 if (!extension->CanSilentlyIncreasePermissions()) { |
| 2027 // Add all the recognized permissions if the granted permissions list | 2026 // Add all the recognized permissions if the granted permissions list |
| 2028 // hasn't been initialized yet. | 2027 // hasn't been initialized yet. |
| 2029 scoped_refptr<PermissionSet> granted_permissions = | 2028 scoped_refptr<PermissionSet> granted_permissions = |
| 2030 extension_prefs_->GetGrantedPermissions(extension->id()); | 2029 extension_prefs_->GetGrantedPermissions(extension->id()); |
| 2031 CHECK(granted_permissions.get()); | 2030 CHECK(granted_permissions.get()); |
| 2032 | 2031 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 2049 // the privileges haven't increased. | 2048 // the privileges haven't increased. |
| 2050 if (!is_privilege_increase) { | 2049 if (!is_privilege_increase) { |
| 2051 SetBeingUpgraded(old, true); | 2050 SetBeingUpgraded(old, true); |
| 2052 SetBeingUpgraded(extension, true); | 2051 SetBeingUpgraded(extension, true); |
| 2053 } | 2052 } |
| 2054 | 2053 |
| 2055 // If the extension was already disabled, suppress any alerts for becoming | 2054 // If the extension was already disabled, suppress any alerts for becoming |
| 2056 // disabled on permissions increase. | 2055 // disabled on permissions increase. |
| 2057 previously_disabled = extension_prefs_->IsExtensionDisabled(old->id()); | 2056 previously_disabled = extension_prefs_->IsExtensionDisabled(old->id()); |
| 2058 if (previously_disabled) { | 2057 if (previously_disabled) { |
| 2059 Extension::DisableReason reason = extension_prefs_->GetDisableReason( | 2058 int reasons = extension_prefs_->GetDisableReasons(old->id()); |
| 2060 old->id()); | 2059 if (reasons == Extension::DISABLE_NONE) { |
| 2061 if (reason == Extension::DISABLE_UNKNOWN) { | |
| 2062 // Initialize the reason for legacy disabled extensions from whether the | 2060 // Initialize the reason for legacy disabled extensions from whether the |
| 2063 // extension already exceeded granted permissions. | 2061 // extension already exceeded granted permissions. |
| 2064 if (extension_prefs_->DidExtensionEscalatePermissions(old->id())) | 2062 if (extension_prefs_->DidExtensionEscalatePermissions(old->id())) |
| 2065 disable_reason = Extension::DISABLE_PERMISSIONS_INCREASE; | 2063 disable_reasons = Extension::DISABLE_PERMISSIONS_INCREASE; |
| 2066 else | 2064 else |
| 2067 disable_reason = Extension::DISABLE_USER_ACTION; | 2065 disable_reasons = Extension::DISABLE_USER_ACTION; |
| 2068 } | 2066 } |
| 2069 } else { | 2067 } else { |
| 2070 disable_reason = Extension::DISABLE_PERMISSIONS_INCREASE; | 2068 disable_reasons = Extension::DISABLE_PERMISSIONS_INCREASE; |
| 2071 } | 2069 } |
| 2072 | 2070 |
| 2073 // To upgrade an extension in place, unload the old one and | 2071 // To upgrade an extension in place, unload the old one and |
| 2074 // then load the new one. | 2072 // then load the new one. |
| 2075 UnloadExtension(old->id(), extension_misc::UNLOAD_REASON_UPDATE); | 2073 UnloadExtension(old->id(), extension_misc::UNLOAD_REASON_UPDATE); |
| 2076 old = NULL; | 2074 old = NULL; |
| 2077 } | 2075 } |
| 2078 | 2076 |
| 2079 // Extension has changed permissions significantly. Disable it. A | 2077 // Extension has changed permissions significantly. Disable it. A |
| 2080 // notification should be sent by the caller. | 2078 // notification should be sent by the caller. |
| 2081 if (is_privilege_increase) { | 2079 if (is_privilege_increase) { |
| 2082 if (!extension_prefs_->DidExtensionEscalatePermissions(extension->id())) { | 2080 if (!extension_prefs_->DidExtensionEscalatePermissions(extension->id())) { |
| 2083 RecordPermissionMessagesHistogram( | 2081 RecordPermissionMessagesHistogram( |
| 2084 extension, "Extensions.Permissions_AutoDisable"); | 2082 extension, "Extensions.Permissions_AutoDisable"); |
| 2085 } | 2083 } |
| 2086 extension_prefs_->SetExtensionState(extension->id(), Extension::DISABLED); | 2084 extension_prefs_->SetExtensionState(extension->id(), Extension::DISABLED); |
| 2087 extension_prefs_->SetDidExtensionEscalatePermissions(extension, true); | 2085 extension_prefs_->SetDidExtensionEscalatePermissions(extension, true); |
| 2088 extension_prefs_->SetDisableReason(extension->id(), disable_reason); | 2086 extension_prefs_->AddDisableReason( |
| 2087 extension->id(), |
| 2088 static_cast<Extension::DisableReason>(disable_reasons)); |
| 2089 } | 2089 } |
| 2090 } | 2090 } |
| 2091 | 2091 |
| 2092 void ExtensionService::UpdateActiveExtensionsInCrashReporter() { | 2092 void ExtensionService::UpdateActiveExtensionsInCrashReporter() { |
| 2093 std::set<std::string> extension_ids; | 2093 std::set<std::string> extension_ids; |
| 2094 for (ExtensionSet::const_iterator iter = extensions_.begin(); | 2094 for (ExtensionSet::const_iterator iter = extensions_.begin(); |
| 2095 iter != extensions_.end(); ++iter) { | 2095 iter != extensions_.end(); ++iter) { |
| 2096 const Extension* extension = *iter; | 2096 const Extension* extension = *iter; |
| 2097 if (!extension->is_theme() && extension->location() != Extension::COMPONENT) | 2097 if (!extension->is_theme() && extension->location() != Extension::COMPONENT) |
| 2098 extension_ids.insert(extension->id()); | 2098 extension_ids.insert(extension->id()); |
| (...skipping 453 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2552 | 2552 |
| 2553 ExtensionService::NaClModuleInfoList::iterator | 2553 ExtensionService::NaClModuleInfoList::iterator |
| 2554 ExtensionService::FindNaClModule(const GURL& url) { | 2554 ExtensionService::FindNaClModule(const GURL& url) { |
| 2555 for (NaClModuleInfoList::iterator iter = nacl_module_list_.begin(); | 2555 for (NaClModuleInfoList::iterator iter = nacl_module_list_.begin(); |
| 2556 iter != nacl_module_list_.end(); ++iter) { | 2556 iter != nacl_module_list_.end(); ++iter) { |
| 2557 if (iter->url == url) | 2557 if (iter->url == url) |
| 2558 return iter; | 2558 return iter; |
| 2559 } | 2559 } |
| 2560 return nacl_module_list_.end(); | 2560 return nacl_module_list_.end(); |
| 2561 } | 2561 } |
| OLD | NEW |