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 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
188 external_extension_providers_.clear(); | 188 external_extension_providers_.clear(); |
189 } | 189 } |
190 | 190 |
191 void ExtensionService::AddProviderForTesting( | 191 void ExtensionService::AddProviderForTesting( |
192 extensions::ExternalProviderInterface* test_provider) { | 192 extensions::ExternalProviderInterface* test_provider) { |
193 CHECK(test_provider); | 193 CHECK(test_provider); |
194 external_extension_providers_.push_back( | 194 external_extension_providers_.push_back( |
195 linked_ptr<extensions::ExternalProviderInterface>(test_provider)); | 195 linked_ptr<extensions::ExternalProviderInterface>(test_provider)); |
196 } | 196 } |
197 | 197 |
198 void ExtensionService::BlacklistExtensionForTest( | |
199 const std::string& extension_id) { | |
200 ExtensionIdSet blocked; | |
201 ExtensionIdSet unchanged; | |
202 blocked.insert(extension_id); | |
203 UpdateBlockedExtensions(blocked, unchanged); | |
204 } | |
205 | |
198 bool ExtensionService::OnExternalExtensionUpdateUrlFound( | 206 bool ExtensionService::OnExternalExtensionUpdateUrlFound( |
199 const std::string& id, | 207 const std::string& id, |
200 const std::string& install_parameter, | 208 const std::string& install_parameter, |
201 const GURL& update_url, | 209 const GURL& update_url, |
202 Manifest::Location location, | 210 Manifest::Location location, |
203 int creation_flags, | 211 int creation_flags, |
204 bool mark_acknowledged) { | 212 bool mark_acknowledged) { |
205 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 213 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
206 CHECK(Extension::IdIsValid(id)); | 214 CHECK(Extension::IdIsValid(id)); |
207 | 215 |
(...skipping 665 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
873 | 881 |
874 if (extension_sync_service_) | 882 if (extension_sync_service_) |
875 extension_sync_service_->SyncEnableExtension(*extension); | 883 extension_sync_service_->SyncEnableExtension(*extension); |
876 } | 884 } |
877 | 885 |
878 void ExtensionService::DisableExtension( | 886 void ExtensionService::DisableExtension( |
879 const std::string& extension_id, | 887 const std::string& extension_id, |
880 Extension::DisableReason disable_reason) { | 888 Extension::DisableReason disable_reason) { |
881 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 889 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
882 | 890 |
883 // The extension may have been disabled already. | 891 // The extension may have been disabled already. Just add a disable reason. |
884 if (!IsExtensionEnabled(extension_id)) | 892 if (!IsExtensionEnabled(extension_id)) { |
893 extension_prefs_->AddDisableReason(extension_id, disable_reason); | |
tmdiep
2014/07/02 07:13:39
yoz: Are multiple disable reasons meant to be supp
Yoyo Zhou
2014/07/10 23:30:12
Yes, they are meant to be supported. This is most
| |
885 return; | 894 return; |
895 } | |
886 | 896 |
887 const Extension* extension = GetInstalledExtension(extension_id); | 897 const Extension* extension = GetInstalledExtension(extension_id); |
888 // |extension| can be NULL if sync disables an extension that is not | 898 // |extension| can be NULL if sync disables an extension that is not |
889 // installed yet. | 899 // installed yet. |
890 if (extension && | 900 if (extension && |
891 disable_reason != Extension::DISABLE_RELOAD && | 901 disable_reason != Extension::DISABLE_RELOAD && |
892 !system_->management_policy()->UserMayModifySettings(extension, NULL)) { | 902 !system_->management_policy()->UserMayModifySettings(extension, NULL)) { |
893 return; | 903 return; |
894 } | 904 } |
895 | 905 |
(...skipping 843 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1739 extension->GetType(), 100); | 1749 extension->GetType(), 100); |
1740 UMA_HISTOGRAM_ENUMERATION("Extensions.InstallSource", | 1750 UMA_HISTOGRAM_ENUMERATION("Extensions.InstallSource", |
1741 extension->location(), Manifest::NUM_LOCATIONS); | 1751 extension->location(), Manifest::NUM_LOCATIONS); |
1742 RecordPermissionMessagesHistogram(extension, | 1752 RecordPermissionMessagesHistogram(extension, |
1743 "Extensions.Permissions_Install2"); | 1753 "Extensions.Permissions_Install2"); |
1744 } else { | 1754 } else { |
1745 UMA_HISTOGRAM_ENUMERATION("Extensions.UpdateType", | 1755 UMA_HISTOGRAM_ENUMERATION("Extensions.UpdateType", |
1746 extension->GetType(), 100); | 1756 extension->GetType(), 100); |
1747 UMA_HISTOGRAM_ENUMERATION("Extensions.UpdateSource", | 1757 UMA_HISTOGRAM_ENUMERATION("Extensions.UpdateSource", |
1748 extension->location(), Manifest::NUM_LOCATIONS); | 1758 extension->location(), Manifest::NUM_LOCATIONS); |
1759 | |
1760 // A fully installed app cannot be demoted to an ephemeral app. | |
1761 if ((install_flags & extensions::kInstallFlagIsEphemeral) && | |
1762 !extension_prefs_->IsEphemeralApp(id)) { | |
1763 install_flags &= ~static_cast<int>(extensions::kInstallFlagIsEphemeral); | |
1764 } | |
1749 } | 1765 } |
1750 | 1766 |
1751 // Certain extension locations are specific enough that we can | 1767 // Certain extension locations are specific enough that we can |
1752 // auto-acknowledge any extension that came from one of them. | 1768 // auto-acknowledge any extension that came from one of them. |
1753 if (Manifest::IsPolicyLocation(extension->location()) || | 1769 if (Manifest::IsPolicyLocation(extension->location()) || |
1754 extension->location() == Manifest::EXTERNAL_COMPONENT) | 1770 extension->location() == Manifest::EXTERNAL_COMPONENT) |
1755 AcknowledgeExternalExtension(extension->id()); | 1771 AcknowledgeExternalExtension(extension->id()); |
1756 const Extension::State initial_state = | 1772 const Extension::State initial_state = |
1757 initial_enable ? Extension::ENABLED : Extension::DISABLED; | 1773 initial_enable ? Extension::ENABLED : Extension::DISABLED; |
1758 if (ShouldDelayExtensionUpdate( | 1774 if (ShouldDelayExtensionUpdate( |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1939 extension_prefs_->IsEphemeralApp(extension->id())); | 1955 extension_prefs_->IsEphemeralApp(extension->id())); |
1940 | 1956 |
1941 if (!is_from_sync) { | 1957 if (!is_from_sync) { |
1942 if (extension->RequiresSortOrdinal()) { | 1958 if (extension->RequiresSortOrdinal()) { |
1943 // Reset the sort ordinals of the app to ensure it is added to the default | 1959 // Reset the sort ordinals of the app to ensure it is added to the default |
1944 // position, like newly installed apps would. | 1960 // position, like newly installed apps would. |
1945 extension_prefs_->app_sorting()->ClearOrdinals(extension->id()); | 1961 extension_prefs_->app_sorting()->ClearOrdinals(extension->id()); |
1946 extension_prefs_->app_sorting()->EnsureValidOrdinals( | 1962 extension_prefs_->app_sorting()->EnsureValidOrdinals( |
1947 extension->id(), syncer::StringOrdinal()); | 1963 extension->id(), syncer::StringOrdinal()); |
1948 } | 1964 } |
1949 | |
1950 // Cached ephemeral apps may be updated and disabled due to permissions | |
1951 // increase. The app can be enabled as the install was user-acknowledged. | |
1952 if (extension_prefs_->DidExtensionEscalatePermissions(extension->id())) | |
1953 GrantPermissionsAndEnableExtension(extension); | |
1954 } | 1965 } |
1955 | 1966 |
1956 // Remove the ephemeral flags from the preferences. | 1967 // Remove the ephemeral flags from the preferences. |
1957 extension_prefs_->OnEphemeralAppPromoted(extension->id()); | 1968 extension_prefs_->OnEphemeralAppPromoted(extension->id()); |
1958 | 1969 |
1959 // Fire install-related events to allow observers to handle the promotion | 1970 // Fire install-related events to allow observers to handle the promotion |
1960 // of the ephemeral app. | 1971 // of the ephemeral app. |
1961 extensions::InstalledExtensionInfo details( | 1972 extensions::InstalledExtensionInfo details( |
1962 extension, | 1973 extension, |
1963 true /* is update */, | 1974 true /* is update */, |
1964 true /* from ephemeral */, | 1975 true /* from ephemeral */, |
1965 extension->name() /* old name */); | 1976 extension->name() /* old name */); |
1966 content::NotificationService::current()->Notify( | 1977 content::NotificationService::current()->Notify( |
1967 chrome::NOTIFICATION_EXTENSION_INSTALLED_DEPRECATED, | 1978 chrome::NOTIFICATION_EXTENSION_INSTALLED_DEPRECATED, |
1968 content::Source<Profile>(profile_), | 1979 content::Source<Profile>(profile_), |
1969 content::Details<const extensions::InstalledExtensionInfo>(&details)); | 1980 content::Details<const extensions::InstalledExtensionInfo>(&details)); |
1970 | 1981 |
1971 registry_->TriggerOnWillBeInstalled( | 1982 registry_->TriggerOnWillBeInstalled( |
1972 extension, | 1983 extension, |
1973 true /* is update */, | 1984 true /* is update */, |
1974 true /* from ephemeral */, | 1985 true /* from ephemeral */, |
1975 extension->name() /* old name */); | 1986 extension->name() /* old name */); |
1976 | 1987 |
1977 if (registry_->enabled_extensions().Contains(extension->id())) { | 1988 if (registry_->enabled_extensions().Contains(extension->id())) { |
1989 // If the app is already enabled and loaded, fire the load events to allow | |
1990 // observers to handle the promotion of the ephemeral app. | |
1978 content::NotificationService::current()->Notify( | 1991 content::NotificationService::current()->Notify( |
1979 chrome::NOTIFICATION_EXTENSION_LOADED_DEPRECATED, | 1992 chrome::NOTIFICATION_EXTENSION_LOADED_DEPRECATED, |
1980 content::Source<Profile>(profile_), | 1993 content::Source<Profile>(profile_), |
1981 content::Details<const Extension>(extension)); | 1994 content::Details<const Extension>(extension)); |
1982 | 1995 |
1983 registry_->TriggerOnLoaded(extension); | 1996 registry_->TriggerOnLoaded(extension); |
1997 } else { | |
1998 // Cached ephemeral apps may be updated and disabled due to permissions | |
1999 // increase. The app can be enabled (as long as no other disable reasons | |
2000 // exist) as the install was user-acknowledged. | |
2001 int disable_mask = Extension::DISABLE_NONE; | |
2002 if (!is_from_sync) | |
2003 disable_mask |= Extension::DISABLE_PERMISSIONS_INCREASE; | |
2004 | |
2005 int other_disable_reasons = | |
2006 extension_prefs_->GetDisableReasons(extension->id()) & ~disable_mask; | |
2007 if (!other_disable_reasons) { | |
2008 if (extension_prefs_->DidExtensionEscalatePermissions(extension->id())) | |
2009 GrantPermissionsAndEnableExtension(extension); | |
2010 else | |
2011 EnableExtension(extension->id()); | |
2012 } | |
1984 } | 2013 } |
1985 | 2014 |
1986 registry_->TriggerOnInstalled(extension); | 2015 registry_->TriggerOnInstalled(extension); |
1987 | 2016 |
1988 if (!is_from_sync && extension_sync_service_) | 2017 if (!is_from_sync && extension_sync_service_) |
1989 extension_sync_service_->SyncExtensionChangeIfNeeded(*extension); | 2018 extension_sync_service_->SyncExtensionChangeIfNeeded(*extension); |
1990 } | 2019 } |
1991 | 2020 |
1992 const Extension* ExtensionService::GetPendingExtensionUpdate( | 2021 const Extension* ExtensionService::GetPendingExtensionUpdate( |
1993 const std::string& id) const { | 2022 const std::string& id) const { |
(...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2456 } | 2485 } |
2457 | 2486 |
2458 void ExtensionService::OnProfileDestructionStarted() { | 2487 void ExtensionService::OnProfileDestructionStarted() { |
2459 ExtensionIdSet ids_to_unload = registry_->enabled_extensions().GetIDs(); | 2488 ExtensionIdSet ids_to_unload = registry_->enabled_extensions().GetIDs(); |
2460 for (ExtensionIdSet::iterator it = ids_to_unload.begin(); | 2489 for (ExtensionIdSet::iterator it = ids_to_unload.begin(); |
2461 it != ids_to_unload.end(); | 2490 it != ids_to_unload.end(); |
2462 ++it) { | 2491 ++it) { |
2463 UnloadExtension(*it, UnloadedExtensionInfo::REASON_PROFILE_SHUTDOWN); | 2492 UnloadExtension(*it, UnloadedExtensionInfo::REASON_PROFILE_SHUTDOWN); |
2464 } | 2493 } |
2465 } | 2494 } |
OLD | NEW |