| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/extensions_service.h" | 5 #include "chrome/browser/extensions/extensions_service.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 // Errors are reported through ExtensionErrorReporter. On success, | 201 // Errors are reported through ExtensionErrorReporter. On success, |
| 202 // OnExtensionLoaded() is called. | 202 // OnExtensionLoaded() is called. |
| 203 // TODO(erikkay): It might be useful to be able to load a packed extension | 203 // TODO(erikkay): It might be useful to be able to load a packed extension |
| 204 // (presumably into memory) without installing it. | 204 // (presumably into memory) without installing it. |
| 205 void LoadSingleExtension(const FilePath &path, | 205 void LoadSingleExtension(const FilePath &path, |
| 206 scoped_refptr<ExtensionsService> frontend); | 206 scoped_refptr<ExtensionsService> frontend); |
| 207 | 207 |
| 208 // Check externally updated extensions for updates and install if necessary. | 208 // Check externally updated extensions for updates and install if necessary. |
| 209 // Errors are reported through ExtensionErrorReporter. Succcess is not | 209 // Errors are reported through ExtensionErrorReporter. Succcess is not |
| 210 // reported. | 210 // reported. |
| 211 void CheckForExternalUpdates(const std::set<std::string>& ids_to_ignore, | 211 void CheckForExternalUpdates(scoped_refptr<ExtensionsService> frontend); |
| 212 scoped_refptr<ExtensionsService> frontend); | |
| 213 | 212 |
| 214 // For the extension in |version_path| with |id|, check to see if it's an | 213 // For the extension in |version_path| with |id|, check to see if it's an |
| 215 // externally managed extension. If so, tell the frontend to uninstall it. | 214 // externally managed extension. If so, tell the frontend to uninstall it. |
| 216 void CheckExternalUninstall(scoped_refptr<ExtensionsService> frontend, | 215 void CheckExternalUninstall(scoped_refptr<ExtensionsService> frontend, |
| 217 const std::string& id); | 216 const std::string& id); |
| 218 | 217 |
| 219 // Clear all ExternalExtensionProviders. | 218 // Clear all ExternalExtensionProviders. |
| 220 void ClearProvidersForTesting(); | 219 void ClearProvidersForTesting(); |
| 221 | 220 |
| 222 // Adds an ExternalExtensionProvider for the service to use during testing. | 221 // Adds an ExternalExtensionProvider for the service to use during testing. |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 363 error, NotificationType::EXTENSION_INSTALL_ERROR, alert_on_error_)); | 362 error, NotificationType::EXTENSION_INSTALL_ERROR, alert_on_error_)); |
| 364 } | 363 } |
| 365 | 364 |
| 366 // Some extensions will autoupdate themselves externally from Chrome. These | 365 // Some extensions will autoupdate themselves externally from Chrome. These |
| 367 // are typically part of some larger client application package. To support | 366 // are typically part of some larger client application package. To support |
| 368 // these, the extension will register its location in the the preferences file | 367 // these, the extension will register its location in the the preferences file |
| 369 // (and also, on Windows, in the registry) and this code will periodically | 368 // (and also, on Windows, in the registry) and this code will periodically |
| 370 // check that location for a .crx file, which it will then install locally if | 369 // check that location for a .crx file, which it will then install locally if |
| 371 // a new version is available. | 370 // a new version is available. |
| 372 void ExtensionsServiceBackend::CheckForExternalUpdates( | 371 void ExtensionsServiceBackend::CheckForExternalUpdates( |
| 373 const std::set<std::string>& ids_to_ignore, | |
| 374 scoped_refptr<ExtensionsService> frontend) { | 372 scoped_refptr<ExtensionsService> frontend) { |
| 375 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 373 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 376 | 374 |
| 377 // Note that this installation is intentionally silent (since it didn't | 375 // Note that this installation is intentionally silent (since it didn't |
| 378 // go through the front-end). Extensions that are registered in this | 376 // go through the front-end). Extensions that are registered in this |
| 379 // way are effectively considered 'pre-bundled', and so implicitly | 377 // way are effectively considered 'pre-bundled', and so implicitly |
| 380 // trusted. In general, if something has HKLM or filesystem access, | 378 // trusted. In general, if something has HKLM or filesystem access, |
| 381 // they could install an extension manually themselves anyway. | 379 // they could install an extension manually themselves anyway. |
| 382 alert_on_error_ = false; | 380 alert_on_error_ = false; |
| 383 frontend_ = frontend; | 381 frontend_ = frontend; |
| 384 external_extension_added_ = false; | 382 external_extension_added_ = false; |
| 385 | 383 |
| 386 // Ask each external extension provider to give us a call back for each | 384 // Ask each external extension provider to give us a call back for each |
| 387 // extension they know about. See OnExternalExtension(File|UpdateUrl)Found. | 385 // extension they know about. See OnExternalExtension(File|UpdateUrl)Found. |
| 388 ProviderCollection::const_iterator i; | 386 ProviderCollection::const_iterator i; |
| 389 for (i = external_extension_providers_.begin(); | 387 for (i = external_extension_providers_.begin(); |
| 390 i != external_extension_providers_.end(); ++i) { | 388 i != external_extension_providers_.end(); ++i) { |
| 391 ExternalExtensionProvider* provider = i->get(); | 389 ExternalExtensionProvider* provider = i->get(); |
| 392 provider->VisitRegisteredExtension(this, ids_to_ignore); | 390 provider->VisitRegisteredExtension(this); |
| 393 } | 391 } |
| 394 | 392 |
| 395 if (external_extension_added_ && frontend->updater()) { | 393 if (external_extension_added_ && frontend->updater()) { |
| 396 BrowserThread::PostTask( | 394 BrowserThread::PostTask( |
| 397 BrowserThread::UI, FROM_HERE, | 395 BrowserThread::UI, FROM_HERE, |
| 398 NewRunnableMethod( | 396 NewRunnableMethod( |
| 399 frontend->updater(), &ExtensionUpdater::CheckNow)); | 397 frontend->updater(), &ExtensionUpdater::CheckNow)); |
| 400 } | 398 } |
| 401 } | 399 } |
| 402 | 400 |
| (...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 716 void ExtensionsService::AddPendingExtensionFromExternalUpdateUrl( | 714 void ExtensionsService::AddPendingExtensionFromExternalUpdateUrl( |
| 717 const std::string& id, const GURL& update_url, | 715 const std::string& id, const GURL& update_url, |
| 718 Extension::Location location) { | 716 Extension::Location location) { |
| 719 // Add the extension to this list of extensions to update. | 717 // Add the extension to this list of extensions to update. |
| 720 const PendingExtensionInfo::ExpectedCrxType kExpectedCrxType = | 718 const PendingExtensionInfo::ExpectedCrxType kExpectedCrxType = |
| 721 PendingExtensionInfo::UNKNOWN; | 719 PendingExtensionInfo::UNKNOWN; |
| 722 const bool kIsFromSync = false; | 720 const bool kIsFromSync = false; |
| 723 const bool kInstallSilently = true; | 721 const bool kInstallSilently = true; |
| 724 const bool kEnableOnInstall = true; | 722 const bool kEnableOnInstall = true; |
| 725 const bool kEnableIncognitoOnInstall = false; | 723 const bool kEnableIncognitoOnInstall = false; |
| 724 if (extension_prefs_->IsExtensionKilled(id)) |
| 725 return; |
| 726 | 726 |
| 727 if (GetExtensionByIdInternal(id, true, true)) { | 727 if (GetExtensionByIdInternal(id, true, true)) { |
| 728 LOG(DFATAL) << "Trying to add extension " << id | 728 LOG(DFATAL) << "Trying to add extension " << id |
| 729 << " by external update, but it is already installed."; | 729 << " by external update, but it is already installed."; |
| 730 return; | 730 return; |
| 731 } | 731 } |
| 732 | 732 |
| 733 AddPendingExtensionInternal(id, update_url, kExpectedCrxType, kIsFromSync, | 733 AddPendingExtensionInternal(id, update_url, kExpectedCrxType, kIsFromSync, |
| 734 kInstallSilently, kEnableOnInstall, | 734 kInstallSilently, kEnableOnInstall, |
| 735 kEnableIncognitoOnInstall, | 735 kEnableIncognitoOnInstall, |
| (...skipping 679 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1415 bool ExtensionsService::GetBrowserActionVisibility(const Extension* extension) { | 1415 bool ExtensionsService::GetBrowserActionVisibility(const Extension* extension) { |
| 1416 return extension_prefs_->GetBrowserActionVisibility(extension); | 1416 return extension_prefs_->GetBrowserActionVisibility(extension); |
| 1417 } | 1417 } |
| 1418 | 1418 |
| 1419 void ExtensionsService::SetBrowserActionVisibility(const Extension* extension, | 1419 void ExtensionsService::SetBrowserActionVisibility(const Extension* extension, |
| 1420 bool visible) { | 1420 bool visible) { |
| 1421 extension_prefs_->SetBrowserActionVisibility(extension, visible); | 1421 extension_prefs_->SetBrowserActionVisibility(extension, visible); |
| 1422 } | 1422 } |
| 1423 | 1423 |
| 1424 void ExtensionsService::CheckForExternalUpdates() { | 1424 void ExtensionsService::CheckForExternalUpdates() { |
| 1425 // This installs or updates externally provided extensions. | |
| 1426 // TODO(aa): Why pass this list into the provider, why not just filter it | |
| 1427 // later? | |
| 1428 std::set<std::string> killed_extensions; | |
| 1429 extension_prefs_->GetKilledExtensionIds(&killed_extensions); | |
| 1430 BrowserThread::PostTask( | 1425 BrowserThread::PostTask( |
| 1431 BrowserThread::FILE, FROM_HERE, | 1426 BrowserThread::FILE, FROM_HERE, |
| 1432 NewRunnableMethod( | 1427 NewRunnableMethod( |
| 1433 backend_.get(), &ExtensionsServiceBackend::CheckForExternalUpdates, | 1428 backend_.get(), &ExtensionsServiceBackend::CheckForExternalUpdates, |
| 1434 killed_extensions, scoped_refptr<ExtensionsService>(this))); | 1429 scoped_refptr<ExtensionsService>(this))); |
| 1435 } | 1430 } |
| 1436 | 1431 |
| 1437 void ExtensionsService::UpdateExternalPolicyExtensionProvider() { | 1432 void ExtensionsService::UpdateExternalPolicyExtensionProvider() { |
| 1438 const ListValue* list_pref = | 1433 const ListValue* list_pref = |
| 1439 profile_->GetPrefs()->GetList(prefs::kExtensionInstallForceList); | 1434 profile_->GetPrefs()->GetList(prefs::kExtensionInstallForceList); |
| 1440 ListValue* list_copy = NULL; | 1435 ListValue* list_copy = NULL; |
| 1441 if (list_pref) | 1436 if (list_pref) |
| 1442 list_copy = static_cast<ListValue*>(list_pref->DeepCopy()); | 1437 list_copy = static_cast<ListValue*>(list_pref->DeepCopy()); |
| 1443 BrowserThread::PostTask( | 1438 BrowserThread::PostTask( |
| 1444 BrowserThread::FILE, FROM_HERE, | 1439 BrowserThread::FILE, FROM_HERE, |
| (...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1914 backend_.get(), &ExtensionsServiceBackend::AddProviderForTesting, | 1909 backend_.get(), &ExtensionsServiceBackend::AddProviderForTesting, |
| 1915 test_provider)); | 1910 test_provider)); |
| 1916 } | 1911 } |
| 1917 | 1912 |
| 1918 void ExtensionsService::OnExternalExtensionFileFound( | 1913 void ExtensionsService::OnExternalExtensionFileFound( |
| 1919 const std::string& id, | 1914 const std::string& id, |
| 1920 const std::string& version, | 1915 const std::string& version, |
| 1921 const FilePath& path, | 1916 const FilePath& path, |
| 1922 Extension::Location location) { | 1917 Extension::Location location) { |
| 1923 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1918 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 1919 if (extension_prefs_->IsExtensionKilled(id)) |
| 1920 return; |
| 1924 | 1921 |
| 1925 // Before even bothering to unpack, check and see if we already have this | 1922 // Before even bothering to unpack, check and see if we already have this |
| 1926 // version. This is important because these extensions are going to get | 1923 // version. This is important because these extensions are going to get |
| 1927 // installed on every startup. | 1924 // installed on every startup. |
| 1928 const Extension* existing = GetExtensionById(id, true); | 1925 const Extension* existing = GetExtensionById(id, true); |
| 1929 scoped_ptr<Version> other(Version::GetVersionFromString(version)); | 1926 scoped_ptr<Version> other(Version::GetVersionFromString(version)); |
| 1930 if (existing) { | 1927 if (existing) { |
| 1931 switch (existing->version()->CompareTo(*other)) { | 1928 switch (existing->version()->CompareTo(*other)) { |
| 1932 case -1: // existing version is older, we should upgrade | 1929 case -1: // existing version is older, we should upgrade |
| 1933 break; | 1930 break; |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2056 } | 2053 } |
| 2057 | 2054 |
| 2058 void ExtensionsService::SetBeingUpgraded(const Extension* extension, | 2055 void ExtensionsService::SetBeingUpgraded(const Extension* extension, |
| 2059 bool value) { | 2056 bool value) { |
| 2060 extension_runtime_data_[extension->id()].being_upgraded = value; | 2057 extension_runtime_data_[extension->id()].being_upgraded = value; |
| 2061 } | 2058 } |
| 2062 | 2059 |
| 2063 PropertyBag* ExtensionsService::GetPropertyBag(const Extension* extension) { | 2060 PropertyBag* ExtensionsService::GetPropertyBag(const Extension* extension) { |
| 2064 return &extension_runtime_data_[extension->id()].property_bag; | 2061 return &extension_runtime_data_[extension->id()].property_bag; |
| 2065 } | 2062 } |
| OLD | NEW |