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 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
260 | 260 |
261 void ExtensionService::AddProviderForTesting( | 261 void ExtensionService::AddProviderForTesting( |
262 extensions::ExternalProviderInterface* test_provider) { | 262 extensions::ExternalProviderInterface* test_provider) { |
263 CHECK(test_provider); | 263 CHECK(test_provider); |
264 external_extension_providers_.push_back( | 264 external_extension_providers_.push_back( |
265 linked_ptr<extensions::ExternalProviderInterface>(test_provider)); | 265 linked_ptr<extensions::ExternalProviderInterface>(test_provider)); |
266 } | 266 } |
267 | 267 |
268 bool ExtensionService::OnExternalExtensionUpdateUrlFound( | 268 bool ExtensionService::OnExternalExtensionUpdateUrlFound( |
269 const std::string& id, | 269 const std::string& id, |
| 270 const std::string& install_parameter, |
270 const GURL& update_url, | 271 const GURL& update_url, |
271 Manifest::Location location, | 272 Manifest::Location location, |
272 int creation_flags, | 273 int creation_flags, |
273 bool mark_acknowledged) { | 274 bool mark_acknowledged) { |
274 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 275 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
275 CHECK(Extension::IdIsValid(id)); | 276 CHECK(Extension::IdIsValid(id)); |
276 | 277 |
277 if (Manifest::IsExternalLocation(location)) { | 278 if (Manifest::IsExternalLocation(location)) { |
278 // All extensions that are not user specific can be cached. | 279 // All extensions that are not user specific can be cached. |
279 extensions::ExtensionCache::GetInstance()->AllowCaching(id); | 280 extensions::ExtensionCache::GetInstance()->AllowCaching(id); |
280 } | 281 } |
281 | 282 |
282 const Extension* extension = GetExtensionById(id, true); | 283 const Extension* extension = GetExtensionById(id, true); |
283 if (extension) { | 284 if (extension) { |
284 // Already installed. Skip this install if the current location has | 285 // Already installed. Skip this install if the current location has |
285 // higher priority than |location|. | 286 // higher priority than |location|. |
286 Manifest::Location current = extension->location(); | 287 Manifest::Location current = extension->location(); |
287 if (current == Manifest::GetHigherPriorityLocation(current, location)) | 288 if (current == Manifest::GetHigherPriorityLocation(current, location)) |
288 return false; | 289 return false; |
289 // Otherwise, overwrite the current installation. | 290 // Otherwise, overwrite the current installation. |
290 } | 291 } |
291 | 292 |
292 // Add |id| to the set of pending extensions. If it can not be added, | 293 // Add |id| to the set of pending extensions. If it can not be added, |
293 // then there is already a pending record from a higher-priority install | 294 // then there is already a pending record from a higher-priority install |
294 // source. In this case, signal that this extension will not be | 295 // source. In this case, signal that this extension will not be |
295 // installed by returning false. | 296 // installed by returning false. |
296 if (!pending_extension_manager()->AddFromExternalUpdateUrl( | 297 if (!pending_extension_manager()->AddFromExternalUpdateUrl( |
297 id, update_url, location, creation_flags, mark_acknowledged)) { | 298 id, |
| 299 install_parameter, |
| 300 update_url, |
| 301 location, |
| 302 creation_flags, |
| 303 mark_acknowledged)) { |
298 return false; | 304 return false; |
299 } | 305 } |
300 | 306 |
301 update_once_all_providers_are_ready_ = true; | 307 update_once_all_providers_are_ready_ = true; |
302 return true; | 308 return true; |
303 } | 309 } |
304 | 310 |
305 const Extension* ExtensionService::GetInstalledExtensionByUrl( | 311 const Extension* ExtensionService::GetInstalledExtensionByUrl( |
306 const GURL& url) const { | 312 const GURL& url) const { |
307 return registry_->enabled_extensions().GetExtensionOrAppByURL(url); | 313 return registry_->enabled_extensions().GetExtensionOrAppByURL(url); |
(...skipping 1532 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1840 | 1846 |
1841 VLOG(1) << "AddComponentExtension " << extension->name(); | 1847 VLOG(1) << "AddComponentExtension " << extension->name(); |
1842 if (!old_version.IsValid() || !old_version.Equals(*extension->version())) { | 1848 if (!old_version.IsValid() || !old_version.Equals(*extension->version())) { |
1843 VLOG(1) << "Component extension " << extension->name() << " (" | 1849 VLOG(1) << "Component extension " << extension->name() << " (" |
1844 << extension->id() << ") installing/upgrading from '" | 1850 << extension->id() << ") installing/upgrading from '" |
1845 << old_version_string << "' to " << extension->version()->GetString(); | 1851 << old_version_string << "' to " << extension->version()->GetString(); |
1846 | 1852 |
1847 AddNewOrUpdatedExtension(extension, | 1853 AddNewOrUpdatedExtension(extension, |
1848 Extension::ENABLED_COMPONENT, | 1854 Extension::ENABLED_COMPONENT, |
1849 extensions::NOT_BLACKLISTED, | 1855 extensions::NOT_BLACKLISTED, |
1850 syncer::StringOrdinal()); | 1856 syncer::StringOrdinal(), |
| 1857 std::string()); |
1851 return; | 1858 return; |
1852 } | 1859 } |
1853 | 1860 |
1854 AddExtension(extension); | 1861 AddExtension(extension); |
1855 } | 1862 } |
1856 | 1863 |
1857 void ExtensionService::UpdateActivePermissions(const Extension* extension) { | 1864 void ExtensionService::UpdateActivePermissions(const Extension* extension) { |
1858 // If the extension has used the optional permissions API, it will have a | 1865 // If the extension has used the optional permissions API, it will have a |
1859 // custom set of active permissions defined in the extension prefs. Here, | 1866 // custom set of active permissions defined in the extension prefs. Here, |
1860 // we update the extension's active permissions based on the prefs. | 1867 // we update the extension's active permissions based on the prefs. |
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2100 void ExtensionService::OnExtensionInstalled( | 2107 void ExtensionService::OnExtensionInstalled( |
2101 const Extension* extension, | 2108 const Extension* extension, |
2102 const syncer::StringOrdinal& page_ordinal, | 2109 const syncer::StringOrdinal& page_ordinal, |
2103 bool has_requirement_errors, | 2110 bool has_requirement_errors, |
2104 extensions::BlacklistState blacklist_state, | 2111 extensions::BlacklistState blacklist_state, |
2105 bool wait_for_idle) { | 2112 bool wait_for_idle) { |
2106 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2113 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2107 | 2114 |
2108 const std::string& id = extension->id(); | 2115 const std::string& id = extension->id(); |
2109 bool initial_enable = ShouldEnableOnInstall(extension); | 2116 bool initial_enable = ShouldEnableOnInstall(extension); |
| 2117 std::string install_parameter; |
2110 const extensions::PendingExtensionInfo* pending_extension_info = NULL; | 2118 const extensions::PendingExtensionInfo* pending_extension_info = NULL; |
2111 if ((pending_extension_info = pending_extension_manager()->GetById(id))) { | 2119 if ((pending_extension_info = pending_extension_manager()->GetById(id))) { |
2112 if (!pending_extension_info->ShouldAllowInstall(extension)) { | 2120 if (!pending_extension_info->ShouldAllowInstall(extension)) { |
2113 pending_extension_manager()->Remove(id); | 2121 pending_extension_manager()->Remove(id); |
2114 | 2122 |
2115 LOG(WARNING) << "ShouldAllowInstall() returned false for " | 2123 LOG(WARNING) << "ShouldAllowInstall() returned false for " |
2116 << id << " of type " << extension->GetType() | 2124 << id << " of type " << extension->GetType() |
2117 << " and update URL " | 2125 << " and update URL " |
2118 << extensions::ManifestURL::GetUpdateURL(extension).spec() | 2126 << extensions::ManifestURL::GetUpdateURL(extension).spec() |
2119 << "; not installing"; | 2127 << "; not installing"; |
2120 | 2128 |
2121 // Delete the extension directory since we're not going to | 2129 // Delete the extension directory since we're not going to |
2122 // load it. | 2130 // load it. |
2123 if (!GetFileTaskRunner()->PostTask( | 2131 if (!GetFileTaskRunner()->PostTask( |
2124 FROM_HERE, | 2132 FROM_HERE, |
2125 base::Bind(&extension_file_util::DeleteFile, | 2133 base::Bind(&extension_file_util::DeleteFile, |
2126 extension->path(), true))) { | 2134 extension->path(), true))) { |
2127 NOTREACHED(); | 2135 NOTREACHED(); |
2128 } | 2136 } |
2129 return; | 2137 return; |
2130 } | 2138 } |
2131 | 2139 |
| 2140 install_parameter = pending_extension_info->install_parameter(); |
2132 pending_extension_manager()->Remove(id); | 2141 pending_extension_manager()->Remove(id); |
2133 } else { | 2142 } else { |
2134 // We explicitly want to re-enable an uninstalled external | 2143 // We explicitly want to re-enable an uninstalled external |
2135 // extension; if we're here, that means the user is manually | 2144 // extension; if we're here, that means the user is manually |
2136 // installing the extension. | 2145 // installing the extension. |
2137 if (IsExternalExtensionUninstalled(id)) { | 2146 if (IsExternalExtensionUninstalled(id)) { |
2138 initial_enable = true; | 2147 initial_enable = true; |
2139 } | 2148 } |
2140 } | 2149 } |
2141 | 2150 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2187 const Extension::State initial_state = | 2196 const Extension::State initial_state = |
2188 initial_enable ? Extension::ENABLED : Extension::DISABLED; | 2197 initial_enable ? Extension::ENABLED : Extension::DISABLED; |
2189 const bool blacklisted_for_malware = | 2198 const bool blacklisted_for_malware = |
2190 blacklist_state == extensions::BLACKLISTED_MALWARE; | 2199 blacklist_state == extensions::BLACKLISTED_MALWARE; |
2191 if (ShouldDelayExtensionUpdate(id, wait_for_idle)) { | 2200 if (ShouldDelayExtensionUpdate(id, wait_for_idle)) { |
2192 extension_prefs_->SetDelayedInstallInfo( | 2201 extension_prefs_->SetDelayedInstallInfo( |
2193 extension, | 2202 extension, |
2194 initial_state, | 2203 initial_state, |
2195 blacklisted_for_malware, | 2204 blacklisted_for_malware, |
2196 extensions::ExtensionPrefs::DELAY_REASON_WAIT_FOR_IDLE, | 2205 extensions::ExtensionPrefs::DELAY_REASON_WAIT_FOR_IDLE, |
2197 page_ordinal); | 2206 page_ordinal, |
| 2207 install_parameter); |
2198 | 2208 |
2199 // Transfer ownership of |extension|. | 2209 // Transfer ownership of |extension|. |
2200 delayed_installs_.Insert(extension); | 2210 delayed_installs_.Insert(extension); |
2201 | 2211 |
2202 // Notify observers that app update is available. | 2212 // Notify observers that app update is available. |
2203 FOR_EACH_OBSERVER(extensions::UpdateObserver, update_observers_, | 2213 FOR_EACH_OBSERVER(extensions::UpdateObserver, update_observers_, |
2204 OnAppUpdateAvailable(extension)); | 2214 OnAppUpdateAvailable(extension)); |
2205 return; | 2215 return; |
2206 } | 2216 } |
2207 | 2217 |
2208 ImportStatus status = SatisfyImports(extension); | 2218 ImportStatus status = SatisfyImports(extension); |
2209 if (installs_delayed_for_gc()) { | 2219 if (installs_delayed_for_gc()) { |
2210 extension_prefs_->SetDelayedInstallInfo( | 2220 extension_prefs_->SetDelayedInstallInfo( |
2211 extension, | 2221 extension, |
2212 initial_state, | 2222 initial_state, |
2213 blacklisted_for_malware, | 2223 blacklisted_for_malware, |
2214 extensions::ExtensionPrefs::DELAY_REASON_GC, | 2224 extensions::ExtensionPrefs::DELAY_REASON_GC, |
2215 page_ordinal); | 2225 page_ordinal, |
| 2226 install_parameter); |
2216 delayed_installs_.Insert(extension); | 2227 delayed_installs_.Insert(extension); |
2217 } else if (status != IMPORT_STATUS_OK) { | 2228 } else if (status != IMPORT_STATUS_OK) { |
2218 if (status == IMPORT_STATUS_UNSATISFIED) { | 2229 if (status == IMPORT_STATUS_UNSATISFIED) { |
2219 extension_prefs_->SetDelayedInstallInfo( | 2230 extension_prefs_->SetDelayedInstallInfo( |
2220 extension, | 2231 extension, |
2221 initial_state, | 2232 initial_state, |
2222 blacklisted_for_malware, | 2233 blacklisted_for_malware, |
2223 extensions::ExtensionPrefs::DELAY_REASON_WAIT_FOR_IMPORTS, | 2234 extensions::ExtensionPrefs::DELAY_REASON_WAIT_FOR_IMPORTS, |
2224 page_ordinal); | 2235 page_ordinal, |
| 2236 install_parameter); |
2225 delayed_installs_.Insert(extension); | 2237 delayed_installs_.Insert(extension); |
2226 } | 2238 } |
2227 } else { | 2239 } else { |
2228 AddNewOrUpdatedExtension(extension, | 2240 AddNewOrUpdatedExtension(extension, |
2229 initial_state, | 2241 initial_state, |
2230 blacklist_state, | 2242 blacklist_state, |
2231 page_ordinal); | 2243 page_ordinal, |
| 2244 install_parameter); |
2232 } | 2245 } |
2233 } | 2246 } |
2234 | 2247 |
2235 void ExtensionService::AddNewOrUpdatedExtension( | 2248 void ExtensionService::AddNewOrUpdatedExtension( |
2236 const Extension* extension, | 2249 const Extension* extension, |
2237 Extension::State initial_state, | 2250 Extension::State initial_state, |
2238 extensions::BlacklistState blacklist_state, | 2251 extensions::BlacklistState blacklist_state, |
2239 const syncer::StringOrdinal& page_ordinal) { | 2252 const syncer::StringOrdinal& page_ordinal, |
| 2253 const std::string& install_parameter) { |
2240 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2254 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2241 const bool blacklisted_for_malware = | 2255 const bool blacklisted_for_malware = |
2242 blacklist_state == extensions::BLACKLISTED_MALWARE; | 2256 blacklist_state == extensions::BLACKLISTED_MALWARE; |
2243 extension_prefs_->OnExtensionInstalled(extension, | 2257 extension_prefs_->OnExtensionInstalled(extension, |
2244 initial_state, | 2258 initial_state, |
2245 blacklisted_for_malware, | 2259 blacklisted_for_malware, |
2246 page_ordinal); | 2260 page_ordinal, |
| 2261 install_parameter); |
2247 delayed_installs_.Remove(extension->id()); | 2262 delayed_installs_.Remove(extension->id()); |
2248 if (InstallVerifier::NeedsVerification(*extension)) { | 2263 if (InstallVerifier::NeedsVerification(*extension)) { |
2249 system_->install_verifier()->Add(extension->id(), | 2264 system_->install_verifier()->Add(extension->id(), |
2250 base::Bind(LogAddVerifiedSuccess)); | 2265 base::Bind(LogAddVerifiedSuccess)); |
2251 } | 2266 } |
2252 FinishInstallation(extension); | 2267 FinishInstallation(extension); |
2253 } | 2268 } |
2254 | 2269 |
2255 void ExtensionService::MaybeFinishDelayedInstallation( | 2270 void ExtensionService::MaybeFinishDelayedInstallation( |
2256 const std::string& extension_id) { | 2271 const std::string& extension_id) { |
(...skipping 624 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2881 void ExtensionService::UnloadAllExtensionsInternal() { | 2896 void ExtensionService::UnloadAllExtensionsInternal() { |
2882 profile_->GetExtensionSpecialStoragePolicy()->RevokeRightsForAllExtensions(); | 2897 profile_->GetExtensionSpecialStoragePolicy()->RevokeRightsForAllExtensions(); |
2883 | 2898 |
2884 registry_->ClearAll(); | 2899 registry_->ClearAll(); |
2885 system_->runtime_data()->ClearAll(); | 2900 system_->runtime_data()->ClearAll(); |
2886 | 2901 |
2887 // TODO(erikkay) should there be a notification for this? We can't use | 2902 // TODO(erikkay) should there be a notification for this? We can't use |
2888 // EXTENSION_UNLOADED since that implies that the extension has been disabled | 2903 // EXTENSION_UNLOADED since that implies that the extension has been disabled |
2889 // or uninstalled. | 2904 // or uninstalled. |
2890 } | 2905 } |
OLD | NEW |