| 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 "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "base/values.h" | 10 #include "base/values.h" |
| 11 #include "chrome/browser/browser_process.h" | 11 #include "chrome/browser/browser_process.h" |
| 12 #include "chrome/browser/chrome_thread.h" | 12 #include "chrome/browser/chrome_thread.h" |
| 13 #include "chrome/browser/extensions/crx_installer.h" | 13 #include "chrome/browser/extensions/crx_installer.h" |
| 14 #include "chrome/browser/extensions/extension_browser_event_router.h" | 14 #include "chrome/browser/extensions/extension_browser_event_router.h" |
| 15 #include "chrome/browser/extensions/extension_dom_ui.h" | 15 #include "chrome/browser/extensions/extension_dom_ui.h" |
| 16 #include "chrome/browser/extensions/extension_file_util.h" | 16 #include "chrome/browser/extensions/extension_file_util.h" |
| 17 #include "chrome/browser/extensions/extension_updater.h" | 17 #include "chrome/browser/extensions/extension_updater.h" |
| 18 #include "chrome/browser/extensions/external_extension_provider.h" | 18 #include "chrome/browser/extensions/external_extension_provider.h" |
| 19 #include "chrome/browser/extensions/external_pref_extension_provider.h" | 19 #include "chrome/browser/extensions/external_pref_extension_provider.h" |
| 20 #include "chrome/browser/profile.h" | 20 #include "chrome/browser/profile.h" |
| 21 #include "chrome/browser/net/chrome_url_request_context.h" |
| 21 #include "chrome/common/chrome_switches.h" | 22 #include "chrome/common/chrome_switches.h" |
| 22 #include "chrome/common/extensions/extension.h" | 23 #include "chrome/common/extensions/extension.h" |
| 23 #include "chrome/common/extensions/extension_error_reporter.h" | 24 #include "chrome/common/extensions/extension_error_reporter.h" |
| 24 #include "chrome/common/notification_service.h" | 25 #include "chrome/common/notification_service.h" |
| 25 #include "chrome/common/pref_names.h" | 26 #include "chrome/common/pref_names.h" |
| 26 #include "chrome/common/pref_service.h" | 27 #include "chrome/common/pref_service.h" |
| 27 #include "chrome/common/url_constants.h" | 28 #include "chrome/common/url_constants.h" |
| 28 | 29 |
| 29 #if defined(OS_WIN) | 30 #if defined(OS_WIN) |
| 30 #include "chrome/browser/extensions/external_registry_extension_provider_win.h" | 31 #include "chrome/browser/extensions/external_registry_extension_provider_win.h" |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 // Move it over to the enabled list. | 236 // Move it over to the enabled list. |
| 236 extensions_.push_back(extension); | 237 extensions_.push_back(extension); |
| 237 ExtensionList::iterator iter = std::find(disabled_extensions_.begin(), | 238 ExtensionList::iterator iter = std::find(disabled_extensions_.begin(), |
| 238 disabled_extensions_.end(), | 239 disabled_extensions_.end(), |
| 239 extension); | 240 extension); |
| 240 disabled_extensions_.erase(iter); | 241 disabled_extensions_.erase(iter); |
| 241 | 242 |
| 242 ExtensionDOMUI::RegisterChromeURLOverrides(profile_, | 243 ExtensionDOMUI::RegisterChromeURLOverrides(profile_, |
| 243 extension->GetChromeURLOverrides()); | 244 extension->GetChromeURLOverrides()); |
| 244 | 245 |
| 245 NotificationService::current()->Notify( | 246 NotifyExtensionLoaded(extension); |
| 246 NotificationType::EXTENSION_LOADED, | |
| 247 Source<ExtensionsService>(this), | |
| 248 Details<Extension>(extension)); | |
| 249 } | 247 } |
| 250 | 248 |
| 251 void ExtensionsService::DisableExtension(const std::string& extension_id) { | 249 void ExtensionsService::DisableExtension(const std::string& extension_id) { |
| 252 Extension* extension = GetExtensionByIdInternal(extension_id, true, false); | 250 Extension* extension = GetExtensionByIdInternal(extension_id, true, false); |
| 253 if (!extension) { | 251 if (!extension) { |
| 254 NOTREACHED() << "Trying to disable an extension that isn't enabled."; | 252 NOTREACHED() << "Trying to disable an extension that isn't enabled."; |
| 255 return; | 253 return; |
| 256 } | 254 } |
| 257 | 255 |
| 258 // Remember that we disabled it, unless it's temporary. | 256 // Remember that we disabled it, unless it's temporary. |
| 259 if (extension->location() != Extension::LOAD) | 257 if (extension->location() != Extension::LOAD) |
| 260 extension_prefs_->SetExtensionState(extension, Extension::DISABLED); | 258 extension_prefs_->SetExtensionState(extension, Extension::DISABLED); |
| 261 | 259 |
| 262 // Move it over to the disabled list. | 260 // Move it over to the disabled list. |
| 263 disabled_extensions_.push_back(extension); | 261 disabled_extensions_.push_back(extension); |
| 264 ExtensionList::iterator iter = std::find(extensions_.begin(), | 262 ExtensionList::iterator iter = std::find(extensions_.begin(), |
| 265 extensions_.end(), | 263 extensions_.end(), |
| 266 extension); | 264 extension); |
| 267 extensions_.erase(iter); | 265 extensions_.erase(iter); |
| 268 | 266 |
| 269 ExtensionDOMUI::UnregisterChromeURLOverrides(profile_, | 267 ExtensionDOMUI::UnregisterChromeURLOverrides(profile_, |
| 270 extension->GetChromeURLOverrides()); | 268 extension->GetChromeURLOverrides()); |
| 271 | 269 |
| 272 NotificationService::current()->Notify( | 270 NotifyExtensionUnloaded(extension); |
| 273 NotificationType::EXTENSION_UNLOADED, | |
| 274 Source<ExtensionsService>(this), | |
| 275 Details<Extension>(extension)); | |
| 276 } | 271 } |
| 277 | 272 |
| 278 void ExtensionsService::LoadExtension(const FilePath& extension_path) { | 273 void ExtensionsService::LoadExtension(const FilePath& extension_path) { |
| 279 backend_loop_->PostTask(FROM_HERE, NewRunnableMethod(backend_.get(), | 274 backend_loop_->PostTask(FROM_HERE, NewRunnableMethod(backend_.get(), |
| 280 &ExtensionsServiceBackend::LoadSingleExtension, | 275 &ExtensionsServiceBackend::LoadSingleExtension, |
| 281 extension_path, scoped_refptr<ExtensionsService>(this))); | 276 extension_path, scoped_refptr<ExtensionsService>(this))); |
| 282 } | 277 } |
| 283 | 278 |
| 284 void ExtensionsService::LoadAllExtensions() { | 279 void ExtensionsService::LoadAllExtensions() { |
| 285 // Load the previously installed extensions. | 280 // Load the previously installed extensions. |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 317 OnExtensionLoaded(extension, true); | 312 OnExtensionLoaded(extension, true); |
| 318 | 313 |
| 319 if (location == Extension::EXTERNAL_PREF || | 314 if (location == Extension::EXTERNAL_PREF || |
| 320 location == Extension::EXTERNAL_REGISTRY) { | 315 location == Extension::EXTERNAL_REGISTRY) { |
| 321 backend_loop_->PostTask(FROM_HERE, NewRunnableMethod(backend_.get(), | 316 backend_loop_->PostTask(FROM_HERE, NewRunnableMethod(backend_.get(), |
| 322 &ExtensionsServiceBackend::CheckExternalUninstall, | 317 &ExtensionsServiceBackend::CheckExternalUninstall, |
| 323 scoped_refptr<ExtensionsService>(this), id, location)); | 318 scoped_refptr<ExtensionsService>(this), id, location)); |
| 324 } | 319 } |
| 325 } | 320 } |
| 326 | 321 |
| 322 void ExtensionsService::NotifyExtensionLoaded(Extension* extension) { |
| 323 LOG(INFO) << "Sending EXTENSION_LOADED"; |
| 324 |
| 325 // The ChromeURLRequestContext needs to be first to know that the extension |
| 326 // was loaded, otherwise a race can arise where a renderer that is created |
| 327 // for the extension may try to load an extension URL with an extension id |
| 328 // that the request context doesn't yet know about. |
| 329 if (profile_ && !profile_->IsOffTheRecord()) { |
| 330 ChromeURLRequestContext* context = static_cast<ChromeURLRequestContext*>( |
| 331 profile_->GetRequestContext()); |
| 332 if (context) { |
| 333 g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE, |
| 334 NewRunnableMethod(context, |
| 335 &ChromeURLRequestContext::OnNewExtensions, |
| 336 extension->id(), |
| 337 extension->path())); |
| 338 } |
| 339 } |
| 340 |
| 341 NotificationService::current()->Notify( |
| 342 NotificationType::EXTENSION_LOADED, |
| 343 Source<ExtensionsService>(this), |
| 344 Details<Extension>(extension)); |
| 345 } |
| 346 |
| 347 void ExtensionsService::NotifyExtensionUnloaded(Extension* extension) { |
| 348 LOG(INFO) << "Sending EXTENSION_UNLOADED"; |
| 349 |
| 350 NotificationService::current()->Notify( |
| 351 NotificationType::EXTENSION_UNLOADED, |
| 352 Source<ExtensionsService>(this), |
| 353 Details<Extension>(extension)); |
| 354 |
| 355 if (profile_ && !profile_->IsOffTheRecord()) { |
| 356 ChromeURLRequestContext* context = static_cast<ChromeURLRequestContext*>( |
| 357 profile_->GetRequestContext()); |
| 358 if (context) { |
| 359 g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE, |
| 360 NewRunnableMethod(context, |
| 361 &ChromeURLRequestContext::OnUnloadedExtension, |
| 362 extension->id())); |
| 363 } |
| 364 } |
| 365 } |
| 366 |
| 327 std::vector<ExtensionAction*> ExtensionsService::GetExtensionActions( | 367 std::vector<ExtensionAction*> ExtensionsService::GetExtensionActions( |
| 328 ExtensionAction::ExtensionActionType action_type) const { | 368 ExtensionAction::ExtensionActionType action_type) const { |
| 329 std::vector<ExtensionAction*> result; | 369 std::vector<ExtensionAction*> result; |
| 330 | 370 |
| 331 // TODO(finnur): Sort the icons in some meaningful way. | 371 // TODO(finnur): Sort the icons in some meaningful way. |
| 332 for (ExtensionList::const_iterator iter = extensions_.begin(); | 372 for (ExtensionList::const_iterator iter = extensions_.begin(); |
| 333 iter != extensions_.end(); ++iter) { | 373 iter != extensions_.end(); ++iter) { |
| 334 if (action_type == ExtensionAction::PAGE_ACTION) { | 374 if (action_type == ExtensionAction::PAGE_ACTION) { |
| 335 const ExtensionActionMap* page_actions = &(*iter)->page_actions(); | 375 const ExtensionActionMap* page_actions = &(*iter)->page_actions(); |
| 336 for (ExtensionActionMap::const_iterator i(page_actions->begin()); | 376 for (ExtensionActionMap::const_iterator i(page_actions->begin()); |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 406 Source<ExtensionsService>(this), | 446 Source<ExtensionsService>(this), |
| 407 Details<Extension>(extension.get())); | 447 Details<Extension>(extension.get())); |
| 408 return; | 448 return; |
| 409 } | 449 } |
| 410 | 450 |
| 411 iter = std::find(extensions_.begin(), extensions_.end(), extension.get()); | 451 iter = std::find(extensions_.begin(), extensions_.end(), extension.get()); |
| 412 | 452 |
| 413 // Remove the extension from our list. | 453 // Remove the extension from our list. |
| 414 extensions_.erase(iter); | 454 extensions_.erase(iter); |
| 415 | 455 |
| 416 // Tell other services the extension is gone. | 456 NotifyExtensionUnloaded(extension.get()); |
| 417 NotificationService::current()->Notify(NotificationType::EXTENSION_UNLOADED, | |
| 418 Source<ExtensionsService>(this), | |
| 419 Details<Extension>(extension.get())); | |
| 420 } | 457 } |
| 421 | 458 |
| 422 void ExtensionsService::UnloadAllExtensions() { | 459 void ExtensionsService::UnloadAllExtensions() { |
| 423 ExtensionList::iterator iter; | 460 ExtensionList::iterator iter; |
| 424 for (iter = extensions_.begin(); iter != extensions_.end(); ++iter) | 461 for (iter = extensions_.begin(); iter != extensions_.end(); ++iter) |
| 425 delete *iter; | 462 delete *iter; |
| 426 extensions_.clear(); | 463 extensions_.clear(); |
| 427 | 464 |
| 428 // TODO(erikkay) should there be a notification for this? We can't use | 465 // TODO(erikkay) should there be a notification for this? We can't use |
| 429 // EXTENSION_UNLOADED since that implies that the extension has been disabled | 466 // EXTENSION_UNLOADED since that implies that the extension has been disabled |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 491 } | 528 } |
| 492 } | 529 } |
| 493 | 530 |
| 494 switch (extension_prefs_->GetExtensionState(extension->id())) { | 531 switch (extension_prefs_->GetExtensionState(extension->id())) { |
| 495 case Extension::ENABLED: | 532 case Extension::ENABLED: |
| 496 extensions_.push_back(scoped_extension.release()); | 533 extensions_.push_back(scoped_extension.release()); |
| 497 | 534 |
| 498 if (extension->location() != Extension::LOAD) | 535 if (extension->location() != Extension::LOAD) |
| 499 extension_prefs_->MigrateToPrefs(extension); | 536 extension_prefs_->MigrateToPrefs(extension); |
| 500 | 537 |
| 501 LOG(INFO) << "Sending EXTENSION_LOADED"; | 538 NotifyExtensionLoaded(extension); |
| 502 NotificationService::current()->Notify( | |
| 503 NotificationType::EXTENSION_LOADED, | |
| 504 Source<ExtensionsService>(this), | |
| 505 Details<Extension>(extension)); | |
| 506 | 539 |
| 507 if (extension->IsTheme() && extension->location() == Extension::LOAD) { | 540 if (extension->IsTheme() && extension->location() == Extension::LOAD) { |
| 508 NotificationService::current()->Notify( | 541 NotificationService::current()->Notify( |
| 509 NotificationType::THEME_INSTALLED, | 542 NotificationType::THEME_INSTALLED, |
| 510 Source<ExtensionsService>(this), | 543 Source<ExtensionsService>(this), |
| 511 Details<Extension>(extension)); | 544 Details<Extension>(extension)); |
| 512 } else { | 545 } else { |
| 513 ExtensionDOMUI::RegisterChromeURLOverrides(profile_, | 546 ExtensionDOMUI::RegisterChromeURLOverrides(profile_, |
| 514 extension->GetChromeURLOverrides()); | 547 extension->GetChromeURLOverrides()); |
| 515 } | 548 } |
| (...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 768 linked_ptr<ExternalExtensionProvider>(test_provider); | 801 linked_ptr<ExternalExtensionProvider>(test_provider); |
| 769 } | 802 } |
| 770 | 803 |
| 771 void ExtensionsServiceBackend::OnExternalExtensionFound( | 804 void ExtensionsServiceBackend::OnExternalExtensionFound( |
| 772 const std::string& id, const Version* version, const FilePath& path, | 805 const std::string& id, const Version* version, const FilePath& path, |
| 773 Extension::Location location) { | 806 Extension::Location location) { |
| 774 frontend_loop_->PostTask(FROM_HERE, NewRunnableMethod(frontend_, | 807 frontend_loop_->PostTask(FROM_HERE, NewRunnableMethod(frontend_, |
| 775 &ExtensionsService::OnExternalExtensionFound, id, version->GetString(), | 808 &ExtensionsService::OnExternalExtensionFound, id, version->GetString(), |
| 776 path, location)); | 809 path, location)); |
| 777 } | 810 } |
| OLD | NEW |