| 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 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 external_extension_providers_.clear(); | 154 external_extension_providers_.clear(); |
| 155 } | 155 } |
| 156 | 156 |
| 157 void ExtensionService::AddProviderForTesting( | 157 void ExtensionService::AddProviderForTesting( |
| 158 extensions::ExternalProviderInterface* test_provider) { | 158 extensions::ExternalProviderInterface* test_provider) { |
| 159 CHECK(test_provider); | 159 CHECK(test_provider); |
| 160 external_extension_providers_.push_back( | 160 external_extension_providers_.push_back( |
| 161 linked_ptr<extensions::ExternalProviderInterface>(test_provider)); | 161 linked_ptr<extensions::ExternalProviderInterface>(test_provider)); |
| 162 } | 162 } |
| 163 | 163 |
| 164 void ExtensionService::BlacklistExtensionForTest( |
| 165 const std::string& extension_id) { |
| 166 ExtensionIdSet blocked; |
| 167 ExtensionIdSet unchanged; |
| 168 blocked.insert(extension_id); |
| 169 UpdateBlockedExtensions(blocked, unchanged); |
| 170 } |
| 171 |
| 164 bool ExtensionService::OnExternalExtensionUpdateUrlFound( | 172 bool ExtensionService::OnExternalExtensionUpdateUrlFound( |
| 165 const std::string& id, | 173 const std::string& id, |
| 166 const std::string& install_parameter, | 174 const std::string& install_parameter, |
| 167 const GURL& update_url, | 175 const GURL& update_url, |
| 168 Manifest::Location location, | 176 Manifest::Location location, |
| 169 int creation_flags, | 177 int creation_flags, |
| 170 bool mark_acknowledged) { | 178 bool mark_acknowledged) { |
| 171 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 179 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 172 CHECK(Extension::IdIsValid(id)); | 180 CHECK(Extension::IdIsValid(id)); |
| 173 | 181 |
| (...skipping 658 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 832 | 840 |
| 833 if (extension_sync_service_) | 841 if (extension_sync_service_) |
| 834 extension_sync_service_->SyncEnableExtension(*extension); | 842 extension_sync_service_->SyncEnableExtension(*extension); |
| 835 } | 843 } |
| 836 | 844 |
| 837 void ExtensionService::DisableExtension( | 845 void ExtensionService::DisableExtension( |
| 838 const std::string& extension_id, | 846 const std::string& extension_id, |
| 839 Extension::DisableReason disable_reason) { | 847 Extension::DisableReason disable_reason) { |
| 840 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 848 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 841 | 849 |
| 842 // The extension may have been disabled already. | 850 // The extension may have been disabled already. Just add a disable reason. |
| 843 if (!IsExtensionEnabled(extension_id)) | 851 if (!IsExtensionEnabled(extension_id)) { |
| 852 extension_prefs_->AddDisableReason(extension_id, disable_reason); |
| 844 return; | 853 return; |
| 854 } |
| 845 | 855 |
| 846 const Extension* extension = GetInstalledExtension(extension_id); | 856 const Extension* extension = GetInstalledExtension(extension_id); |
| 847 // |extension| can be NULL if sync disables an extension that is not | 857 // |extension| can be NULL if sync disables an extension that is not |
| 848 // installed yet. | 858 // installed yet. |
| 849 // EXTERNAL_COMPONENT extensions are not generally modifiable by users, but | 859 // EXTERNAL_COMPONENT extensions are not generally modifiable by users, but |
| 850 // can be uninstalled by the browser if the user sets extension-specific | 860 // can be uninstalled by the browser if the user sets extension-specific |
| 851 // preferences. | 861 // preferences. |
| 852 if (extension && | 862 if (extension && |
| 853 disable_reason != Extension::DISABLE_RELOAD && | 863 disable_reason != Extension::DISABLE_RELOAD && |
| 854 !system_->management_policy()->UserMayModifySettings(extension, NULL) && | 864 !system_->management_policy()->UserMayModifySettings(extension, NULL) && |
| (...skipping 790 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1645 extension->GetType(), 100); | 1655 extension->GetType(), 100); |
| 1646 UMA_HISTOGRAM_ENUMERATION("Extensions.InstallSource", | 1656 UMA_HISTOGRAM_ENUMERATION("Extensions.InstallSource", |
| 1647 extension->location(), Manifest::NUM_LOCATIONS); | 1657 extension->location(), Manifest::NUM_LOCATIONS); |
| 1648 RecordPermissionMessagesHistogram(extension, | 1658 RecordPermissionMessagesHistogram(extension, |
| 1649 "Extensions.Permissions_Install2"); | 1659 "Extensions.Permissions_Install2"); |
| 1650 } else { | 1660 } else { |
| 1651 UMA_HISTOGRAM_ENUMERATION("Extensions.UpdateType", | 1661 UMA_HISTOGRAM_ENUMERATION("Extensions.UpdateType", |
| 1652 extension->GetType(), 100); | 1662 extension->GetType(), 100); |
| 1653 UMA_HISTOGRAM_ENUMERATION("Extensions.UpdateSource", | 1663 UMA_HISTOGRAM_ENUMERATION("Extensions.UpdateSource", |
| 1654 extension->location(), Manifest::NUM_LOCATIONS); | 1664 extension->location(), Manifest::NUM_LOCATIONS); |
| 1665 |
| 1666 // A fully installed app cannot be demoted to an ephemeral app. |
| 1667 if ((install_flags & extensions::kInstallFlagIsEphemeral) && |
| 1668 !extension_prefs_->IsEphemeralApp(id)) { |
| 1669 install_flags &= ~static_cast<int>(extensions::kInstallFlagIsEphemeral); |
| 1670 } |
| 1655 } | 1671 } |
| 1656 | 1672 |
| 1657 const Extension::State initial_state = | 1673 const Extension::State initial_state = |
| 1658 initial_enable ? Extension::ENABLED : Extension::DISABLED; | 1674 initial_enable ? Extension::ENABLED : Extension::DISABLED; |
| 1659 if (ShouldDelayExtensionUpdate( | 1675 if (ShouldDelayExtensionUpdate( |
| 1660 id, | 1676 id, |
| 1661 !!(install_flags & extensions::kInstallFlagInstallImmediately))) { | 1677 !!(install_flags & extensions::kInstallFlagInstallImmediately))) { |
| 1662 extension_prefs_->SetDelayedInstallInfo( | 1678 extension_prefs_->SetDelayedInstallInfo( |
| 1663 extension, | 1679 extension, |
| 1664 initial_state, | 1680 initial_state, |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1824 if (!is_from_sync) { | 1840 if (!is_from_sync) { |
| 1825 // Reset the sort ordinals of the app to ensure it is added to the default | 1841 // Reset the sort ordinals of the app to ensure it is added to the default |
| 1826 // position, like newly installed apps would. | 1842 // position, like newly installed apps would. |
| 1827 extension_prefs_->app_sorting()->ClearOrdinals(extension->id()); | 1843 extension_prefs_->app_sorting()->ClearOrdinals(extension->id()); |
| 1828 } | 1844 } |
| 1829 | 1845 |
| 1830 extension_prefs_->app_sorting()->EnsureValidOrdinals( | 1846 extension_prefs_->app_sorting()->EnsureValidOrdinals( |
| 1831 extension->id(), syncer::StringOrdinal()); | 1847 extension->id(), syncer::StringOrdinal()); |
| 1832 } | 1848 } |
| 1833 | 1849 |
| 1834 if (!is_from_sync) { | |
| 1835 // Cached ephemeral apps may be updated and disabled due to permissions | |
| 1836 // increase. The app can be enabled as the install was user-acknowledged. | |
| 1837 if (extension_prefs_->DidExtensionEscalatePermissions(extension->id())) | |
| 1838 GrantPermissionsAndEnableExtension(extension); | |
| 1839 } | |
| 1840 | |
| 1841 // Remove the ephemeral flags from the preferences. | 1850 // Remove the ephemeral flags from the preferences. |
| 1842 extension_prefs_->OnEphemeralAppPromoted(extension->id()); | 1851 extension_prefs_->OnEphemeralAppPromoted(extension->id()); |
| 1843 | 1852 |
| 1844 // Fire install-related events to allow observers to handle the promotion | 1853 // Fire install-related events to allow observers to handle the promotion |
| 1845 // of the ephemeral app. | 1854 // of the ephemeral app. |
| 1846 extensions::InstalledExtensionInfo details( | 1855 extensions::InstalledExtensionInfo details( |
| 1847 extension, | 1856 extension, |
| 1848 true /* is update */, | 1857 true /* is update */, |
| 1849 true /* from ephemeral */, | 1858 true /* from ephemeral */, |
| 1850 extension->name() /* old name */); | 1859 extension->name() /* old name */); |
| 1851 content::NotificationService::current()->Notify( | 1860 content::NotificationService::current()->Notify( |
| 1852 chrome::NOTIFICATION_EXTENSION_WILL_BE_INSTALLED_DEPRECATED, | 1861 chrome::NOTIFICATION_EXTENSION_WILL_BE_INSTALLED_DEPRECATED, |
| 1853 content::Source<Profile>(profile_), | 1862 content::Source<Profile>(profile_), |
| 1854 content::Details<const extensions::InstalledExtensionInfo>(&details)); | 1863 content::Details<const extensions::InstalledExtensionInfo>(&details)); |
| 1855 | 1864 |
| 1856 registry_->TriggerOnWillBeInstalled( | 1865 registry_->TriggerOnWillBeInstalled( |
| 1857 extension, | 1866 extension, |
| 1858 true /* is update */, | 1867 true /* is update */, |
| 1859 true /* from ephemeral */, | 1868 true /* from ephemeral */, |
| 1860 extension->name() /* old name */); | 1869 extension->name() /* old name */); |
| 1861 | 1870 |
| 1862 if (registry_->enabled_extensions().Contains(extension->id())) { | 1871 if (registry_->enabled_extensions().Contains(extension->id())) { |
| 1872 // If the app is already enabled and loaded, fire the load events to allow |
| 1873 // observers to handle the promotion of the ephemeral app. |
| 1863 content::NotificationService::current()->Notify( | 1874 content::NotificationService::current()->Notify( |
| 1864 chrome::NOTIFICATION_EXTENSION_LOADED_DEPRECATED, | 1875 chrome::NOTIFICATION_EXTENSION_LOADED_DEPRECATED, |
| 1865 content::Source<Profile>(profile_), | 1876 content::Source<Profile>(profile_), |
| 1866 content::Details<const Extension>(extension)); | 1877 content::Details<const Extension>(extension)); |
| 1867 | 1878 |
| 1868 registry_->TriggerOnLoaded(extension); | 1879 registry_->TriggerOnLoaded(extension); |
| 1880 } else { |
| 1881 // Cached ephemeral apps may be updated and disabled due to permissions |
| 1882 // increase. The app can be enabled (as long as no other disable reasons |
| 1883 // exist) as the install was user-acknowledged. |
| 1884 int disable_mask = Extension::DISABLE_NONE; |
| 1885 if (!is_from_sync) |
| 1886 disable_mask |= Extension::DISABLE_PERMISSIONS_INCREASE; |
| 1887 |
| 1888 int other_disable_reasons = |
| 1889 extension_prefs_->GetDisableReasons(extension->id()) & ~disable_mask; |
| 1890 if (!other_disable_reasons) { |
| 1891 if (extension_prefs_->DidExtensionEscalatePermissions(extension->id())) |
| 1892 GrantPermissionsAndEnableExtension(extension); |
| 1893 else |
| 1894 EnableExtension(extension->id()); |
| 1895 } |
| 1869 } | 1896 } |
| 1870 | 1897 |
| 1871 registry_->TriggerOnInstalled(extension, true); | 1898 registry_->TriggerOnInstalled(extension, true); |
| 1872 | 1899 |
| 1873 if (!is_from_sync && extension_sync_service_) | 1900 if (!is_from_sync && extension_sync_service_) |
| 1874 extension_sync_service_->SyncExtensionChangeIfNeeded(*extension); | 1901 extension_sync_service_->SyncExtensionChangeIfNeeded(*extension); |
| 1875 } | 1902 } |
| 1876 | 1903 |
| 1877 const Extension* ExtensionService::GetPendingExtensionUpdate( | 1904 const Extension* ExtensionService::GetPendingExtensionUpdate( |
| 1878 const std::string& id) const { | 1905 const std::string& id) const { |
| (...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2327 } | 2354 } |
| 2328 | 2355 |
| 2329 void ExtensionService::OnProfileDestructionStarted() { | 2356 void ExtensionService::OnProfileDestructionStarted() { |
| 2330 ExtensionIdSet ids_to_unload = registry_->enabled_extensions().GetIDs(); | 2357 ExtensionIdSet ids_to_unload = registry_->enabled_extensions().GetIDs(); |
| 2331 for (ExtensionIdSet::iterator it = ids_to_unload.begin(); | 2358 for (ExtensionIdSet::iterator it = ids_to_unload.begin(); |
| 2332 it != ids_to_unload.end(); | 2359 it != ids_to_unload.end(); |
| 2333 ++it) { | 2360 ++it) { |
| 2334 UnloadExtension(*it, UnloadedExtensionInfo::REASON_PROFILE_SHUTDOWN); | 2361 UnloadExtension(*it, UnloadedExtensionInfo::REASON_PROFILE_SHUTDOWN); |
| 2335 } | 2362 } |
| 2336 } | 2363 } |
| OLD | NEW |