| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/crypto/signature_verifier.h" | 9 #include "base/crypto/signature_verifier.h" |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 // already. | 209 // already. |
| 210 bool got_response_; | 210 bool got_response_; |
| 211 }; | 211 }; |
| 212 | 212 |
| 213 ExtensionsService::ExtensionsService(Profile* profile, | 213 ExtensionsService::ExtensionsService(Profile* profile, |
| 214 MessageLoop* frontend_loop, | 214 MessageLoop* frontend_loop, |
| 215 MessageLoop* backend_loop) | 215 MessageLoop* backend_loop) |
| 216 : extension_prefs_(new ExtensionPrefs(profile->GetPrefs())), | 216 : extension_prefs_(new ExtensionPrefs(profile->GetPrefs())), |
| 217 backend_loop_(backend_loop), | 217 backend_loop_(backend_loop), |
| 218 install_directory_(profile->GetPath().AppendASCII(kInstallDirectoryName)), | 218 install_directory_(profile->GetPath().AppendASCII(kInstallDirectoryName)), |
| 219 extensions_enabled_( | 219 extensions_enabled_(false), |
| 220 CommandLine::ForCurrentProcess()-> | |
| 221 HasSwitch(switches::kEnableExtensions)), | |
| 222 show_extensions_prompts_(true), | 220 show_extensions_prompts_(true), |
| 223 ready_(false) { | 221 ready_(false) { |
| 224 // We pass ownership of this object to the Backend. | 222 // We pass ownership of this object to the Backend. |
| 225 DictionaryValue* extensions = extension_prefs_->CopyCurrentExtensions(); | 223 DictionaryValue* extensions = extension_prefs_->CopyCurrentExtensions(); |
| 226 backend_ = new ExtensionsServiceBackend( | 224 backend_ = new ExtensionsServiceBackend( |
| 227 install_directory_, g_browser_process->resource_dispatcher_host(), | 225 install_directory_, g_browser_process->resource_dispatcher_host(), |
| 228 frontend_loop, extensions); | 226 frontend_loop, extensions, extensions_enabled()); |
| 229 } | 227 } |
| 230 | 228 |
| 231 ExtensionsService::~ExtensionsService() { | 229 ExtensionsService::~ExtensionsService() { |
| 232 UnloadAllExtensions(); | 230 UnloadAllExtensions(); |
| 233 } | 231 } |
| 234 | 232 |
| 233 void ExtensionsService::SetExtensionsEnabled(bool enabled) { |
| 234 extensions_enabled_ = true; |
| 235 backend_loop_->PostTask(FROM_HERE, NewRunnableMethod(backend_.get(), |
| 236 &ExtensionsServiceBackend::set_extensions_enabled, enabled)); |
| 237 } |
| 238 |
| 235 void ExtensionsService::Init() { | 239 void ExtensionsService::Init() { |
| 236 DCHECK(extensions_.size() == 0); | 240 DCHECK(extensions_.size() == 0); |
| 237 | 241 |
| 238 // Start up the extension event routers. | 242 // Start up the extension event routers. |
| 239 ExtensionBrowserEventRouter::GetInstance()->Init(); | 243 ExtensionBrowserEventRouter::GetInstance()->Init(); |
| 240 | 244 |
| 241 LoadAllExtensions(); | 245 LoadAllExtensions(); |
| 242 | 246 |
| 243 // TODO(erikkay) this should probably be deferred to a future point | 247 // TODO(erikkay) this should probably be deferred to a future point |
| 244 // rather than running immediately at startup. | 248 // rather than running immediately at startup. |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 347 ready_ = true; | 351 ready_ = true; |
| 348 NotificationService::current()->Notify( | 352 NotificationService::current()->Notify( |
| 349 NotificationType::EXTENSIONS_READY, | 353 NotificationType::EXTENSIONS_READY, |
| 350 Source<ExtensionsService>(this), | 354 Source<ExtensionsService>(this), |
| 351 NotificationService::NoDetails()); | 355 NotificationService::NoDetails()); |
| 352 } | 356 } |
| 353 | 357 |
| 354 void ExtensionsService::OnExtensionsLoaded(ExtensionList* new_extensions) { | 358 void ExtensionsService::OnExtensionsLoaded(ExtensionList* new_extensions) { |
| 355 scoped_ptr<ExtensionList> cleanup(new_extensions); | 359 scoped_ptr<ExtensionList> cleanup(new_extensions); |
| 356 | 360 |
| 357 // Filter out any extensions we don't want to enable. Themes are always | 361 // Filter out any extensions that shouldn't be loaded. Themes are always |
| 358 // enabled, but other extensions are only loaded if --enable-extensions is | 362 // loaded, but other extensions are only loaded if the extensions system is |
| 359 // present. | 363 // enabled. |
| 360 ExtensionList enabled_extensions; | 364 ExtensionList enabled_extensions; |
| 361 for (ExtensionList::iterator iter = new_extensions->begin(); | 365 for (ExtensionList::iterator iter = new_extensions->begin(); |
| 362 iter != new_extensions->end(); ++iter) { | 366 iter != new_extensions->end(); ++iter) { |
| 363 if (extensions_enabled() || (*iter)->IsTheme()) { | 367 if (extensions_enabled() || (*iter)->IsTheme() || |
| 368 (*iter)->location() == Extension::EXTERNAL_REGISTRY) { |
| 364 Extension* old = GetExtensionById((*iter)->id()); | 369 Extension* old = GetExtensionById((*iter)->id()); |
| 365 if (old) { | 370 if (old) { |
| 366 if ((*iter)->version()->CompareTo(*(old->version())) > 0) { | 371 if ((*iter)->version()->CompareTo(*(old->version())) > 0) { |
| 367 // To upgrade an extension in place, unload the old one and | 372 // To upgrade an extension in place, unload the old one and |
| 368 // then load the new one. | 373 // then load the new one. |
| 369 // TODO(erikkay) issue 12399 | 374 // TODO(erikkay) issue 12399 |
| 370 UnloadExtension(old->id()); | 375 UnloadExtension(old->id()); |
| 371 } else { | 376 } else { |
| 372 // We already have the extension of the same or older version. | 377 // We already have the extension of the same or older version. |
| 373 LOG(WARNING) << "Duplicate extension load attempt: " << (*iter)->id(); | 378 LOG(WARNING) << "Duplicate extension load attempt: " << (*iter)->id(); |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 444 Extension::Location location, ExternalExtensionProvider* test_provider) { | 449 Extension::Location location, ExternalExtensionProvider* test_provider) { |
| 445 backend_loop_->PostTask(FROM_HERE, NewRunnableMethod(backend_.get(), | 450 backend_loop_->PostTask(FROM_HERE, NewRunnableMethod(backend_.get(), |
| 446 &ExtensionsServiceBackend::SetProviderForTesting, | 451 &ExtensionsServiceBackend::SetProviderForTesting, |
| 447 location, test_provider)); | 452 location, test_provider)); |
| 448 } | 453 } |
| 449 | 454 |
| 450 // ExtensionsServicesBackend | 455 // ExtensionsServicesBackend |
| 451 | 456 |
| 452 ExtensionsServiceBackend::ExtensionsServiceBackend( | 457 ExtensionsServiceBackend::ExtensionsServiceBackend( |
| 453 const FilePath& install_directory, ResourceDispatcherHost* rdh, | 458 const FilePath& install_directory, ResourceDispatcherHost* rdh, |
| 454 MessageLoop* frontend_loop, DictionaryValue* extension_prefs) | 459 MessageLoop* frontend_loop, DictionaryValue* extension_prefs, |
| 460 bool extensions_enabled) |
| 455 : frontend_(NULL), | 461 : frontend_(NULL), |
| 456 install_directory_(install_directory), | 462 install_directory_(install_directory), |
| 457 resource_dispatcher_host_(rdh), | 463 resource_dispatcher_host_(rdh), |
| 458 alert_on_error_(false), | 464 alert_on_error_(false), |
| 459 frontend_loop_(frontend_loop) { | 465 frontend_loop_(frontend_loop), |
| 466 extensions_enabled_(false) { |
| 460 external_extension_providers_[Extension::EXTERNAL_PREF] = | 467 external_extension_providers_[Extension::EXTERNAL_PREF] = |
| 461 linked_ptr<ExternalExtensionProvider>( | 468 linked_ptr<ExternalExtensionProvider>( |
| 462 new ExternalPrefExtensionProvider(extension_prefs)); | 469 new ExternalPrefExtensionProvider(extension_prefs)); |
| 463 #if defined(OS_WIN) | 470 #if defined(OS_WIN) |
| 464 external_extension_providers_[Extension::EXTERNAL_REGISTRY] = | 471 external_extension_providers_[Extension::EXTERNAL_REGISTRY] = |
| 465 linked_ptr<ExternalExtensionProvider>( | 472 linked_ptr<ExternalExtensionProvider>( |
| 466 new ExternalRegistryExtensionProvider()); | 473 new ExternalRegistryExtensionProvider()); |
| 467 #endif | 474 #endif |
| 468 } | 475 } |
| 469 | 476 |
| (...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 949 const std::vector< Tuple2<SkBitmap, FilePath> >& images) { | 956 const std::vector< Tuple2<SkBitmap, FilePath> >& images) { |
| 950 Extension extension; | 957 Extension extension; |
| 951 std::string error; | 958 std::string error; |
| 952 if (!extension.InitFromValue(manifest, | 959 if (!extension.InitFromValue(manifest, |
| 953 true, // require ID | 960 true, // require ID |
| 954 &error)) { | 961 &error)) { |
| 955 ReportExtensionInstallError(extension_path, "Invalid extension manifest."); | 962 ReportExtensionInstallError(extension_path, "Invalid extension manifest."); |
| 956 return; | 963 return; |
| 957 } | 964 } |
| 958 | 965 |
| 959 if (!frontend_->extensions_enabled() && !extension.IsTheme()) { | |
| 960 #if defined(OS_WIN) | |
| 961 if (frontend_->show_extensions_prompts()) { | |
| 962 win_util::MessageBox(GetForegroundWindow(), | |
| 963 L"Extensions are not enabled. Add --enable-extensions to the " | |
| 964 L"command-line to enable extensions.\n\n" | |
| 965 L"This is a temporary message and it will be removed when extensions " | |
| 966 L"UI is finalized.", | |
| 967 l10n_util::GetString(IDS_PRODUCT_NAME).c_str(), MB_OK); | |
| 968 } | |
| 969 #endif | |
| 970 ReportExtensionInstallError(extension_path, | |
| 971 "Extensions are not enabled."); | |
| 972 return; | |
| 973 } | |
| 974 | |
| 975 Extension::Location location = Extension::INTERNAL; | 966 Extension::Location location = Extension::INTERNAL; |
| 976 LookupExternalExtension(extension.id(), NULL, &location); | 967 LookupExternalExtension(extension.id(), NULL, &location); |
| 968 |
| 969 // We currently only allow themes and registry-installed extensions to be |
| 970 // installed. |
| 971 if (!extensions_enabled_ && |
| 972 !extension.IsTheme() && |
| 973 location != Extension::EXTERNAL_REGISTRY) { |
| 974 ReportExtensionInstallError(extension_path, |
| 975 "Extensions are not enabled (yet!)"); |
| 976 return; |
| 977 } |
| 978 |
| 977 #if defined(OS_WIN) | 979 #if defined(OS_WIN) |
| 978 bool from_external = Extension::IsExternalLocation(location); | 980 if (!extension.IsTheme() && |
| 979 | 981 !Extension::IsExternalLocation(location) && |
| 980 if (!extension.IsTheme() && !from_external && | |
| 981 frontend_->show_extensions_prompts() && | 982 frontend_->show_extensions_prompts() && |
| 982 win_util::MessageBox(GetForegroundWindow(), | 983 win_util::MessageBox(GetForegroundWindow(), |
| 983 L"Are you sure you want to install this extension?\n\n" | 984 L"Are you sure you want to install this extension?\n\n" |
| 984 L"This is a temporary message and it will be removed when extensions " | 985 L"This is a temporary message and it will be removed when extensions " |
| 985 L"UI is finalized.", | 986 L"UI is finalized.", |
| 986 l10n_util::GetString(IDS_PRODUCT_NAME).c_str(), | 987 l10n_util::GetString(IDS_PRODUCT_NAME).c_str(), |
| 987 MB_OKCANCEL) != IDOK) { | 988 MB_OKCANCEL) != IDOK) { |
| 988 ReportExtensionInstallError(extension_path, | 989 ReportExtensionInstallError(extension_path, |
| 989 "User did not allow extension to be installed."); | 990 "User did not allow extension to be installed."); |
| 990 return; | 991 return; |
| (...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1273 Extension::InstallType install_type = | 1274 Extension::InstallType install_type = |
| 1274 CompareToInstalledVersion(id, version->GetString(), ¤t_version); | 1275 CompareToInstalledVersion(id, version->GetString(), ¤t_version); |
| 1275 | 1276 |
| 1276 if (install_type == Extension::DOWNGRADE) | 1277 if (install_type == Extension::DOWNGRADE) |
| 1277 return false; | 1278 return false; |
| 1278 | 1279 |
| 1279 return (install_type == Extension::UPGRADE || | 1280 return (install_type == Extension::UPGRADE || |
| 1280 install_type == Extension::NEW_INSTALL || | 1281 install_type == Extension::NEW_INSTALL || |
| 1281 NeedsReinstall(id, current_version)); | 1282 NeedsReinstall(id, current_version)); |
| 1282 } | 1283 } |
| OLD | NEW |