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 1872 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1883 void ExtensionService::AddNewOrUpdatedExtension( | 1883 void ExtensionService::AddNewOrUpdatedExtension( |
1884 const Extension* extension, | 1884 const Extension* extension, |
1885 Extension::State initial_state, | 1885 Extension::State initial_state, |
1886 extensions::BlacklistState blacklist_state, | 1886 extensions::BlacklistState blacklist_state, |
1887 bool is_ephemeral, | 1887 bool is_ephemeral, |
1888 const syncer::StringOrdinal& page_ordinal, | 1888 const syncer::StringOrdinal& page_ordinal, |
1889 const std::string& install_parameter) { | 1889 const std::string& install_parameter) { |
1890 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1890 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1891 const bool blacklisted_for_malware = | 1891 const bool blacklisted_for_malware = |
1892 blacklist_state == extensions::BLACKLISTED_MALWARE; | 1892 blacklist_state == extensions::BLACKLISTED_MALWARE; |
1893 bool was_ephemeral = extension_prefs_->IsEphemeralApp(extension->id()); | |
1893 extension_prefs_->OnExtensionInstalled(extension, | 1894 extension_prefs_->OnExtensionInstalled(extension, |
1894 initial_state, | 1895 initial_state, |
1895 blacklisted_for_malware, | 1896 blacklisted_for_malware, |
1896 is_ephemeral, | 1897 is_ephemeral, |
1897 page_ordinal, | 1898 page_ordinal, |
1898 install_parameter); | 1899 install_parameter); |
1899 delayed_installs_.Remove(extension->id()); | 1900 delayed_installs_.Remove(extension->id()); |
1900 if (InstallVerifier::NeedsVerification(*extension)) | 1901 if (InstallVerifier::NeedsVerification(*extension)) |
1901 system_->install_verifier()->VerifyExtension(extension->id()); | 1902 system_->install_verifier()->VerifyExtension(extension->id()); |
1902 FinishInstallation(extension); | 1903 FinishInstallation(extension, was_ephemeral); |
1903 } | 1904 } |
1904 | 1905 |
1905 void ExtensionService::MaybeFinishDelayedInstallation( | 1906 void ExtensionService::MaybeFinishDelayedInstallation( |
1906 const std::string& extension_id) { | 1907 const std::string& extension_id) { |
1907 // Check if the extension already got installed. | 1908 // Check if the extension already got installed. |
1908 if (!delayed_installs_.Contains(extension_id)) | 1909 if (!delayed_installs_.Contains(extension_id)) |
1909 return; | 1910 return; |
1910 extensions::ExtensionPrefs::DelayReason reason = | 1911 extensions::ExtensionPrefs::DelayReason reason = |
1911 extension_prefs_->GetDelayedInstallReason(extension_id); | 1912 extension_prefs_->GetDelayedInstallReason(extension_id); |
1912 | 1913 |
(...skipping 24 matching lines...) Expand all Loading... | |
1937 FinishDelayedInstallation(extension_id); | 1938 FinishDelayedInstallation(extension_id); |
1938 } | 1939 } |
1939 | 1940 |
1940 void ExtensionService::FinishDelayedInstallation( | 1941 void ExtensionService::FinishDelayedInstallation( |
1941 const std::string& extension_id) { | 1942 const std::string& extension_id) { |
1942 scoped_refptr<const Extension> extension( | 1943 scoped_refptr<const Extension> extension( |
1943 GetPendingExtensionUpdate(extension_id)); | 1944 GetPendingExtensionUpdate(extension_id)); |
1944 CHECK(extension.get()); | 1945 CHECK(extension.get()); |
1945 delayed_installs_.Remove(extension_id); | 1946 delayed_installs_.Remove(extension_id); |
1946 | 1947 |
1948 bool was_ephemeral = extension_prefs_->IsEphemeralApp(extension->id()); | |
1947 if (!extension_prefs_->FinishDelayedInstallInfo(extension_id)) | 1949 if (!extension_prefs_->FinishDelayedInstallInfo(extension_id)) |
benwells
2014/05/27 01:42:56
This is interesting, looks like for delayed instal
| |
1948 NOTREACHED(); | 1950 NOTREACHED(); |
1949 | 1951 |
1950 FinishInstallation(extension.get()); | 1952 FinishInstallation(extension.get(), was_ephemeral); |
1951 } | 1953 } |
1952 | 1954 |
1953 void ExtensionService::FinishInstallation(const Extension* extension) { | 1955 void ExtensionService::FinishInstallation( |
1956 const Extension* extension, bool was_ephemeral) { | |
1954 const extensions::Extension* existing_extension = | 1957 const extensions::Extension* existing_extension = |
1955 GetInstalledExtension(extension->id()); | 1958 GetInstalledExtension(extension->id()); |
1956 bool is_update = false; | 1959 bool is_update = false; |
1957 std::string old_name; | 1960 std::string old_name; |
1958 if (existing_extension) { | 1961 if (existing_extension) { |
1959 is_update = true; | 1962 is_update = true; |
1960 old_name = existing_extension->name(); | 1963 old_name = existing_extension->name(); |
1961 } | 1964 } |
1962 extensions::InstalledExtensionInfo details(extension, is_update, old_name); | 1965 bool from_ephemeral = |
1966 was_ephemeral && !extension_prefs_->IsEphemeralApp(extension->id()); | |
1967 extensions::InstalledExtensionInfo details( | |
1968 extension, is_update, from_ephemeral, old_name); | |
1963 content::NotificationService::current()->Notify( | 1969 content::NotificationService::current()->Notify( |
1964 chrome::NOTIFICATION_EXTENSION_INSTALLED_DEPRECATED, | 1970 chrome::NOTIFICATION_EXTENSION_INSTALLED_DEPRECATED, |
1965 content::Source<Profile>(profile_), | 1971 content::Source<Profile>(profile_), |
1966 content::Details<const extensions::InstalledExtensionInfo>(&details)); | 1972 content::Details<const extensions::InstalledExtensionInfo>(&details)); |
1967 | 1973 |
1968 ExtensionRegistry::Get(profile_) | 1974 ExtensionRegistry::Get(profile_)->TriggerOnWillBeInstalled( |
1969 ->TriggerOnWillBeInstalled(extension, is_update, old_name); | 1975 extension, is_update, from_ephemeral, old_name); |
1970 | 1976 |
1971 bool unacknowledged_external = IsUnacknowledgedExternalExtension(extension); | 1977 bool unacknowledged_external = IsUnacknowledgedExternalExtension(extension); |
1972 | 1978 |
1973 // Unpacked extensions default to allowing file access, but if that has been | 1979 // Unpacked extensions default to allowing file access, but if that has been |
1974 // overridden, don't reset the value. | 1980 // overridden, don't reset the value. |
1975 if (Manifest::ShouldAlwaysAllowFileAccess(extension->location()) && | 1981 if (Manifest::ShouldAlwaysAllowFileAccess(extension->location()) && |
1976 !extension_prefs_->HasAllowFileAccessSetting(extension->id())) { | 1982 !extension_prefs_->HasAllowFileAccessSetting(extension->id())) { |
1977 extension_prefs_->SetAllowFileAccess(extension->id(), true); | 1983 extension_prefs_->SetAllowFileAccess(extension->id(), true); |
1978 } | 1984 } |
1979 | 1985 |
(...skipping 18 matching lines...) Expand all Loading... | |
1998 } | 2004 } |
1999 } | 2005 } |
2000 | 2006 |
2001 // Check extensions that may have been delayed only because this shared module | 2007 // Check extensions that may have been delayed only because this shared module |
2002 // was not available. | 2008 // was not available. |
2003 if (SharedModuleInfo::IsSharedModule(extension)) { | 2009 if (SharedModuleInfo::IsSharedModule(extension)) { |
2004 MaybeFinishDelayedInstallations(); | 2010 MaybeFinishDelayedInstallations(); |
2005 } | 2011 } |
2006 } | 2012 } |
2007 | 2013 |
2014 void ExtensionService::InstallEphemeralApp( | |
2015 const extensions::Extension* extension, bool user_acknowledged) { | |
2016 DCHECK(GetInstalledExtension(extension->id()) && | |
2017 extension_prefs_->IsEphemeralApp(extension->id())); | |
2018 | |
2019 if (user_acknowledged) { | |
2020 if (extension->RequiresSortOrdinal()) { | |
benwells
2014/05/27 01:42:56
Why don't we do this if it wasn't user_acknowledge
tmdiep
2014/05/27 01:58:54
If the app came from sync, we probably don't want
benwells
2014/05/27 03:11:11
The flag is user_acknowledged, not from_sync, so t
tmdiep
2014/05/27 03:21:53
ChromeAppSorting::Set[Page|AppLaunch]Ordinal() wil
| |
2021 // Reset the sort ordinals of the app to ensure it is added to the default | |
2022 // position, like newly installed apps would. | |
2023 extension_prefs_->app_sorting()->ClearOrdinals(extension->id()); | |
2024 extension_prefs_->app_sorting()->EnsureValidOrdinals( | |
2025 extension->id(), syncer::StringOrdinal()); | |
2026 } | |
2027 | |
2028 if (!IsExtensionEnabled(extension->id())) { | |
2029 // If the installation of this app was user acknowledged it can be | |
2030 // re-enabled if a permission increase or user action were the only | |
2031 // reasons. | |
2032 extension_prefs_->RemoveDisableReason( | |
2033 extension->id(), | |
2034 Extension::DISABLE_PERMISSIONS_INCREASE); | |
2035 extension_prefs_->RemoveDisableReason( | |
2036 extension->id(), | |
2037 Extension::DISABLE_USER_ACTION); | |
2038 if (!extension_prefs_->GetDisableReasons(extension->id())) | |
2039 EnableExtension(extension->id()); | |
2040 } | |
2041 } | |
2042 | |
2043 // Remove the ephemeral flags from the preferences. | |
2044 extension_prefs_->OnEphemeralAppInstalled(extension->id()); | |
2045 | |
2046 // Fire install-related events to allow observers to handle the promotion | |
2047 // of the ephemeral app. | |
2048 extensions::InstalledExtensionInfo details( | |
2049 extension, | |
2050 true /* is update */, | |
2051 true /* from ephemeral */, | |
2052 extension->name() /* old name */); | |
2053 content::NotificationService::current()->Notify( | |
2054 chrome::NOTIFICATION_EXTENSION_INSTALLED_DEPRECATED, | |
2055 content::Source<Profile>(profile_), | |
2056 content::Details<const extensions::InstalledExtensionInfo>(&details)); | |
2057 | |
2058 registry_->TriggerOnWillBeInstalled( | |
2059 extension, | |
2060 true /* is update */, | |
2061 true /* from ephemeral */, | |
2062 extension->name() /* old name */); | |
2063 | |
2064 content::NotificationService::current()->Notify( | |
2065 chrome::NOTIFICATION_EXTENSION_LOADED_DEPRECATED, | |
2066 content::Source<Profile>(profile_), | |
2067 content::Details<const Extension>(extension)); | |
2068 | |
2069 registry_->TriggerOnLoaded(extension); | |
2070 | |
2071 if (user_acknowledged && extension_sync_service_) | |
2072 extension_sync_service_->SyncExtensionChangeIfNeeded(*extension); | |
benwells
2014/05/27 01:42:56
Have you got any tests to check that it is synced
tmdiep
2014/05/27 01:58:54
I've only tested this manually. I'll look into a b
tmdiep
2014/05/27 07:46:05
Done - see EphemeralAppBrowserTests.
| |
2073 } | |
2074 | |
2008 const Extension* ExtensionService::GetPendingExtensionUpdate( | 2075 const Extension* ExtensionService::GetPendingExtensionUpdate( |
2009 const std::string& id) const { | 2076 const std::string& id) const { |
2010 return delayed_installs_.GetByID(id); | 2077 return delayed_installs_.GetByID(id); |
2011 } | 2078 } |
2012 | 2079 |
2013 void ExtensionService::TrackTerminatedExtension(const Extension* extension) { | 2080 void ExtensionService::TrackTerminatedExtension(const Extension* extension) { |
2014 // No need to check for duplicates; inserting a duplicate is a no-op. | 2081 // No need to check for duplicates; inserting a duplicate is a no-op. |
2015 registry_->AddTerminated(make_scoped_refptr(extension)); | 2082 registry_->AddTerminated(make_scoped_refptr(extension)); |
2016 extensions_being_terminated_.erase(extension->id()); | 2083 extensions_being_terminated_.erase(extension->id()); |
2017 UnloadExtension(extension->id(), UnloadedExtensionInfo::REASON_TERMINATE); | 2084 UnloadExtension(extension->id(), UnloadedExtensionInfo::REASON_TERMINATE); |
(...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2472 } | 2539 } |
2473 | 2540 |
2474 void ExtensionService::OnProfileDestructionStarted() { | 2541 void ExtensionService::OnProfileDestructionStarted() { |
2475 ExtensionIdSet ids_to_unload = registry_->enabled_extensions().GetIDs(); | 2542 ExtensionIdSet ids_to_unload = registry_->enabled_extensions().GetIDs(); |
2476 for (ExtensionIdSet::iterator it = ids_to_unload.begin(); | 2543 for (ExtensionIdSet::iterator it = ids_to_unload.begin(); |
2477 it != ids_to_unload.end(); | 2544 it != ids_to_unload.end(); |
2478 ++it) { | 2545 ++it) { |
2479 UnloadExtension(*it, UnloadedExtensionInfo::REASON_PROFILE_SHUTDOWN); | 2546 UnloadExtension(*it, UnloadedExtensionInfo::REASON_PROFILE_SHUTDOWN); |
2480 } | 2547 } |
2481 } | 2548 } |
OLD | NEW |