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 548 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
559 | 559 |
560 if (extension && extension->was_installed_by_default()) | 560 if (extension && extension->was_installed_by_default()) |
561 creation_flags |= Extension::WAS_INSTALLED_BY_DEFAULT; | 561 creation_flags |= Extension::WAS_INSTALLED_BY_DEFAULT; |
562 | 562 |
563 if (extension && extension->was_installed_by_oem()) | 563 if (extension && extension->was_installed_by_oem()) |
564 creation_flags |= Extension::WAS_INSTALLED_BY_OEM; | 564 creation_flags |= Extension::WAS_INSTALLED_BY_OEM; |
565 | 565 |
566 if (extension && extension->was_installed_by_custodian()) | 566 if (extension && extension->was_installed_by_custodian()) |
567 creation_flags |= Extension::WAS_INSTALLED_BY_CUSTODIAN; | 567 creation_flags |= Extension::WAS_INSTALLED_BY_CUSTODIAN; |
568 | 568 |
569 if (extension) { | 569 if (extension) |
570 installer->set_is_ephemeral(extension_prefs_->IsEphemeralApp(id)); | |
571 installer->set_do_not_sync(extension_prefs_->DoNotSync(id)); | 570 installer->set_do_not_sync(extension_prefs_->DoNotSync(id)); |
572 } | |
573 | 571 |
574 installer->set_creation_flags(creation_flags); | 572 installer->set_creation_flags(creation_flags); |
575 | 573 |
576 installer->set_delete_source(file_ownership_passed); | 574 installer->set_delete_source(file_ownership_passed); |
577 installer->set_install_cause(extension_misc::INSTALL_CAUSE_UPDATE); | 575 installer->set_install_cause(extension_misc::INSTALL_CAUSE_UPDATE); |
578 installer->InstallCrxFile(file); | 576 installer->InstallCrxFile(file); |
579 | 577 |
580 if (out_crx_installer) | 578 if (out_crx_installer) |
581 *out_crx_installer = installer.get(); | 579 *out_crx_installer = installer.get(); |
582 | 580 |
(...skipping 922 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1505 CHECK(!registry_->AddDisabled(extension)); | 1503 CHECK(!registry_->AddDisabled(extension)); |
1506 EnableExtension(extension->id()); | 1504 EnableExtension(extension->id()); |
1507 } else { | 1505 } else { |
1508 // All apps that are displayed in the launcher are ordered by their ordinals | 1506 // All apps that are displayed in the launcher are ordered by their ordinals |
1509 // so we must ensure they have valid ordinals. | 1507 // so we must ensure they have valid ordinals. |
1510 if (extension->RequiresSortOrdinal()) { | 1508 if (extension->RequiresSortOrdinal()) { |
1511 AppSorting* app_sorting = | 1509 AppSorting* app_sorting = |
1512 extensions::ExtensionSystem::Get(GetBrowserContext())->app_sorting(); | 1510 extensions::ExtensionSystem::Get(GetBrowserContext())->app_sorting(); |
1513 app_sorting->SetExtensionVisible( | 1511 app_sorting->SetExtensionVisible( |
1514 extension->id(), | 1512 extension->id(), |
1515 extension->ShouldDisplayInNewTabPage() && | 1513 extension->ShouldDisplayInNewTabPage()); |
1516 !extension_prefs_->IsEphemeralApp(extension->id())); | 1514 app_sorting->EnsureValidOrdinals(extension->id(), |
1517 if (!extension_prefs_->IsEphemeralApp(extension->id())) { | 1515 syncer::StringOrdinal()); |
1518 app_sorting->EnsureValidOrdinals(extension->id(), | |
1519 syncer::StringOrdinal()); | |
1520 } | |
1521 } | 1516 } |
1522 | 1517 |
1523 registry_->AddEnabled(extension); | 1518 registry_->AddEnabled(extension); |
1524 NotifyExtensionLoaded(extension); | 1519 NotifyExtensionLoaded(extension); |
1525 } | 1520 } |
1526 system_->runtime_data()->SetBeingUpgraded(extension->id(), false); | 1521 system_->runtime_data()->SetBeingUpgraded(extension->id(), false); |
1527 } | 1522 } |
1528 | 1523 |
1529 void ExtensionService::AddComponentExtension(const Extension* extension) { | 1524 void ExtensionService::AddComponentExtension(const Extension* extension) { |
1530 const std::string old_version_string( | 1525 const std::string old_version_string( |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1755 UMA_HISTOGRAM_ENUMERATION("Extensions.InstallType", | 1750 UMA_HISTOGRAM_ENUMERATION("Extensions.InstallType", |
1756 extension->GetType(), 100); | 1751 extension->GetType(), 100); |
1757 UMA_HISTOGRAM_ENUMERATION("Extensions.InstallSource", | 1752 UMA_HISTOGRAM_ENUMERATION("Extensions.InstallSource", |
1758 extension->location(), Manifest::NUM_LOCATIONS); | 1753 extension->location(), Manifest::NUM_LOCATIONS); |
1759 RecordPermissionMessagesHistogram(extension, "Install"); | 1754 RecordPermissionMessagesHistogram(extension, "Install"); |
1760 } else { | 1755 } else { |
1761 UMA_HISTOGRAM_ENUMERATION("Extensions.UpdateType", | 1756 UMA_HISTOGRAM_ENUMERATION("Extensions.UpdateType", |
1762 extension->GetType(), 100); | 1757 extension->GetType(), 100); |
1763 UMA_HISTOGRAM_ENUMERATION("Extensions.UpdateSource", | 1758 UMA_HISTOGRAM_ENUMERATION("Extensions.UpdateSource", |
1764 extension->location(), Manifest::NUM_LOCATIONS); | 1759 extension->location(), Manifest::NUM_LOCATIONS); |
1765 | |
1766 // A fully installed app cannot be demoted to an ephemeral app. | |
1767 if ((install_flags & extensions::kInstallFlagIsEphemeral) && | |
1768 !extension_prefs_->IsEphemeralApp(id)) { | |
1769 install_flags &= ~static_cast<int>(extensions::kInstallFlagIsEphemeral); | |
1770 } | |
1771 } | 1760 } |
1772 | 1761 |
1773 const Extension::State initial_state = | 1762 const Extension::State initial_state = |
1774 disable_reasons == Extension::DISABLE_NONE ? Extension::ENABLED | 1763 disable_reasons == Extension::DISABLE_NONE ? Extension::ENABLED |
1775 : Extension::DISABLED; | 1764 : Extension::DISABLED; |
1776 if (initial_state == Extension::ENABLED) | 1765 if (initial_state == Extension::ENABLED) |
1777 extension_prefs_->SetExtensionEnabled(id); | 1766 extension_prefs_->SetExtensionEnabled(id); |
1778 else | 1767 else |
1779 extension_prefs_->SetExtensionDisabled(id, disable_reasons); | 1768 extension_prefs_->SetExtensionDisabled(id, disable_reasons); |
1780 | 1769 |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1850 CheckManagementPolicy(); | 1839 CheckManagementPolicy(); |
1851 } | 1840 } |
1852 | 1841 |
1853 void ExtensionService::AddNewOrUpdatedExtension( | 1842 void ExtensionService::AddNewOrUpdatedExtension( |
1854 const Extension* extension, | 1843 const Extension* extension, |
1855 Extension::State initial_state, | 1844 Extension::State initial_state, |
1856 int install_flags, | 1845 int install_flags, |
1857 const syncer::StringOrdinal& page_ordinal, | 1846 const syncer::StringOrdinal& page_ordinal, |
1858 const std::string& install_parameter) { | 1847 const std::string& install_parameter) { |
1859 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1848 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1860 bool was_ephemeral = extension_prefs_->IsEphemeralApp(extension->id()); | |
1861 extension_prefs_->OnExtensionInstalled( | 1849 extension_prefs_->OnExtensionInstalled( |
1862 extension, initial_state, page_ordinal, install_flags, install_parameter); | 1850 extension, initial_state, page_ordinal, install_flags, install_parameter); |
1863 delayed_installs_.Remove(extension->id()); | 1851 delayed_installs_.Remove(extension->id()); |
1864 if (InstallVerifier::NeedsVerification(*extension)) | 1852 if (InstallVerifier::NeedsVerification(*extension)) |
1865 InstallVerifier::Get(GetBrowserContext())->VerifyExtension(extension->id()); | 1853 InstallVerifier::Get(GetBrowserContext())->VerifyExtension(extension->id()); |
1866 | 1854 |
1867 const Extension* old = GetInstalledExtension(extension->id()); | 1855 const Extension* old = GetInstalledExtension(extension->id()); |
1868 if (extensions::AppDataMigrator::NeedsMigration(old, extension)) { | 1856 if (extensions::AppDataMigrator::NeedsMigration(old, extension)) { |
1869 app_data_migrator_->DoMigrationAndReply( | 1857 app_data_migrator_->DoMigrationAndReply( |
1870 old, extension, | 1858 old, extension, |
1871 base::Bind(&ExtensionService::FinishInstallation, AsWeakPtr(), | 1859 base::Bind(&ExtensionService::FinishInstallation, AsWeakPtr(), |
1872 make_scoped_refptr(extension), was_ephemeral)); | 1860 make_scoped_refptr(extension))); |
1873 return; | 1861 return; |
1874 } | 1862 } |
1875 | 1863 |
1876 FinishInstallation(extension, was_ephemeral); | 1864 FinishInstallation(extension); |
1877 } | 1865 } |
1878 | 1866 |
1879 void ExtensionService::MaybeFinishDelayedInstallation( | 1867 void ExtensionService::MaybeFinishDelayedInstallation( |
1880 const std::string& extension_id) { | 1868 const std::string& extension_id) { |
1881 // Check if the extension already got installed. | 1869 // Check if the extension already got installed. |
1882 if (!delayed_installs_.Contains(extension_id)) | 1870 if (!delayed_installs_.Contains(extension_id)) |
1883 return; | 1871 return; |
1884 extensions::ExtensionPrefs::DelayReason reason = | 1872 extensions::ExtensionPrefs::DelayReason reason = |
1885 extension_prefs_->GetDelayedInstallReason(extension_id); | 1873 extension_prefs_->GetDelayedInstallReason(extension_id); |
1886 | 1874 |
(...skipping 24 matching lines...) Expand all Loading... |
1911 FinishDelayedInstallation(extension_id); | 1899 FinishDelayedInstallation(extension_id); |
1912 } | 1900 } |
1913 | 1901 |
1914 void ExtensionService::FinishDelayedInstallation( | 1902 void ExtensionService::FinishDelayedInstallation( |
1915 const std::string& extension_id) { | 1903 const std::string& extension_id) { |
1916 scoped_refptr<const Extension> extension( | 1904 scoped_refptr<const Extension> extension( |
1917 GetPendingExtensionUpdate(extension_id)); | 1905 GetPendingExtensionUpdate(extension_id)); |
1918 CHECK(extension.get()); | 1906 CHECK(extension.get()); |
1919 delayed_installs_.Remove(extension_id); | 1907 delayed_installs_.Remove(extension_id); |
1920 | 1908 |
1921 bool was_ephemeral = extension_prefs_->IsEphemeralApp(extension->id()); | |
1922 if (!extension_prefs_->FinishDelayedInstallInfo(extension_id)) | 1909 if (!extension_prefs_->FinishDelayedInstallInfo(extension_id)) |
1923 NOTREACHED(); | 1910 NOTREACHED(); |
1924 | 1911 |
1925 FinishInstallation(extension.get(), was_ephemeral); | 1912 FinishInstallation(extension.get()); |
1926 } | 1913 } |
1927 | 1914 |
1928 void ExtensionService::FinishInstallation( | 1915 void ExtensionService::FinishInstallation( |
1929 const Extension* extension, bool was_ephemeral) { | 1916 const Extension* extension) { |
1930 const extensions::Extension* existing_extension = | 1917 const extensions::Extension* existing_extension = |
1931 GetInstalledExtension(extension->id()); | 1918 GetInstalledExtension(extension->id()); |
1932 bool is_update = false; | 1919 bool is_update = false; |
1933 std::string old_name; | 1920 std::string old_name; |
1934 if (existing_extension) { | 1921 if (existing_extension) { |
1935 is_update = true; | 1922 is_update = true; |
1936 old_name = existing_extension->name(); | 1923 old_name = existing_extension->name(); |
1937 } | 1924 } |
1938 bool from_ephemeral = | |
1939 was_ephemeral && !extension_prefs_->IsEphemeralApp(extension->id()); | |
1940 | |
1941 registry_->TriggerOnWillBeInstalled( | 1925 registry_->TriggerOnWillBeInstalled( |
1942 extension, is_update, from_ephemeral, old_name); | 1926 extension, is_update, old_name); |
1943 | 1927 |
1944 // Unpacked extensions default to allowing file access, but if that has been | 1928 // Unpacked extensions default to allowing file access, but if that has been |
1945 // overridden, don't reset the value. | 1929 // overridden, don't reset the value. |
1946 if (Manifest::ShouldAlwaysAllowFileAccess(extension->location()) && | 1930 if (Manifest::ShouldAlwaysAllowFileAccess(extension->location()) && |
1947 !extension_prefs_->HasAllowFileAccessSetting(extension->id())) { | 1931 !extension_prefs_->HasAllowFileAccessSetting(extension->id())) { |
1948 extension_prefs_->SetAllowFileAccess(extension->id(), true); | 1932 extension_prefs_->SetAllowFileAccess(extension->id(), true); |
1949 } | 1933 } |
1950 | 1934 |
1951 AddExtension(extension); | 1935 AddExtension(extension); |
1952 | 1936 |
1953 // Notify observers that need to know when an installation is complete. | 1937 // Notify observers that need to know when an installation is complete. |
1954 registry_->TriggerOnInstalled(extension, is_update); | 1938 registry_->TriggerOnInstalled(extension, is_update); |
1955 | 1939 |
1956 // Check extensions that may have been delayed only because this shared module | 1940 // Check extensions that may have been delayed only because this shared module |
1957 // was not available. | 1941 // was not available. |
1958 if (SharedModuleInfo::IsSharedModule(extension)) | 1942 if (SharedModuleInfo::IsSharedModule(extension)) |
1959 MaybeFinishDelayedInstallations(); | 1943 MaybeFinishDelayedInstallations(); |
1960 } | 1944 } |
1961 | 1945 |
1962 void ExtensionService::PromoteEphemeralApp( | |
1963 const extensions::Extension* extension, bool is_from_sync) { | |
1964 DCHECK(GetInstalledExtension(extension->id()) && | |
1965 extension_prefs_->IsEphemeralApp(extension->id())); | |
1966 | |
1967 if (extension->RequiresSortOrdinal()) { | |
1968 AppSorting* app_sorting = | |
1969 extensions::ExtensionSystem::Get(GetBrowserContext())->app_sorting(); | |
1970 app_sorting->SetExtensionVisible(extension->id(), | |
1971 extension->ShouldDisplayInNewTabPage()); | |
1972 | |
1973 if (!is_from_sync) { | |
1974 // Reset the sort ordinals of the app to ensure it is added to the default | |
1975 // position, like newly installed apps would. | |
1976 app_sorting->ClearOrdinals(extension->id()); | |
1977 } | |
1978 | |
1979 app_sorting->EnsureValidOrdinals(extension->id(), syncer::StringOrdinal()); | |
1980 } | |
1981 | |
1982 // Remove the ephemeral flags from the preferences. | |
1983 extension_prefs_->OnEphemeralAppPromoted(extension->id()); | |
1984 | |
1985 // Fire install-related events to allow observers to handle the promotion | |
1986 // of the ephemeral app. | |
1987 registry_->TriggerOnWillBeInstalled( | |
1988 extension, | |
1989 true /* is update */, | |
1990 true /* from ephemeral */, | |
1991 extension->name() /* old name */); | |
1992 | |
1993 if (registry_->enabled_extensions().Contains(extension->id())) { | |
1994 // If the app is already enabled and loaded, fire the load events to allow | |
1995 // observers to handle the promotion of the ephemeral app. | |
1996 content::NotificationService::current()->Notify( | |
1997 extensions::NOTIFICATION_EXTENSION_LOADED_DEPRECATED, | |
1998 content::Source<Profile>(profile_), | |
1999 content::Details<const Extension>(extension)); | |
2000 | |
2001 registry_->TriggerOnLoaded(extension); | |
2002 } else { | |
2003 // Cached ephemeral apps may be updated and disabled due to permissions | |
2004 // increase. The app can be enabled (as long as no other disable reasons | |
2005 // exist) as the install was user-acknowledged. | |
2006 int disable_mask = Extension::DISABLE_NONE; | |
2007 if (!is_from_sync) | |
2008 disable_mask |= Extension::DISABLE_PERMISSIONS_INCREASE; | |
2009 | |
2010 int other_disable_reasons = | |
2011 extension_prefs_->GetDisableReasons(extension->id()) & ~disable_mask; | |
2012 if (!other_disable_reasons) { | |
2013 if (extension_prefs_->DidExtensionEscalatePermissions(extension->id())) | |
2014 GrantPermissionsAndEnableExtension(extension); | |
2015 else | |
2016 EnableExtension(extension->id()); | |
2017 } | |
2018 } | |
2019 | |
2020 registry_->TriggerOnInstalled(extension, true); | |
2021 | |
2022 if (!is_from_sync) { | |
2023 ExtensionSyncService::Get(profile_)->SyncExtensionChangeIfNeeded( | |
2024 *extension); | |
2025 } | |
2026 } | |
2027 | |
2028 const Extension* ExtensionService::GetPendingExtensionUpdate( | 1946 const Extension* ExtensionService::GetPendingExtensionUpdate( |
2029 const std::string& id) const { | 1947 const std::string& id) const { |
2030 return delayed_installs_.GetByID(id); | 1948 return delayed_installs_.GetByID(id); |
2031 } | 1949 } |
2032 | 1950 |
2033 void ExtensionService::RegisterContentSettings( | 1951 void ExtensionService::RegisterContentSettings( |
2034 HostContentSettingsMap* host_content_settings_map) { | 1952 HostContentSettingsMap* host_content_settings_map) { |
2035 TRACE_EVENT0("browser,startup", "ExtensionService::RegisterContentSettings"); | 1953 TRACE_EVENT0("browser,startup", "ExtensionService::RegisterContentSettings"); |
2036 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1954 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
2037 host_content_settings_map->RegisterProvider( | 1955 host_content_settings_map->RegisterProvider( |
(...skipping 504 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2542 } | 2460 } |
2543 | 2461 |
2544 void ExtensionService::OnProfileDestructionStarted() { | 2462 void ExtensionService::OnProfileDestructionStarted() { |
2545 ExtensionIdSet ids_to_unload = registry_->enabled_extensions().GetIDs(); | 2463 ExtensionIdSet ids_to_unload = registry_->enabled_extensions().GetIDs(); |
2546 for (ExtensionIdSet::iterator it = ids_to_unload.begin(); | 2464 for (ExtensionIdSet::iterator it = ids_to_unload.begin(); |
2547 it != ids_to_unload.end(); | 2465 it != ids_to_unload.end(); |
2548 ++it) { | 2466 ++it) { |
2549 UnloadExtension(*it, UnloadedExtensionInfo::REASON_PROFILE_SHUTDOWN); | 2467 UnloadExtension(*it, UnloadedExtensionInfo::REASON_PROFILE_SHUTDOWN); |
2550 } | 2468 } |
2551 } | 2469 } |
OLD | NEW |