Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/ui/webui/extensions/extension_settings_handler.h" | 5 #include "chrome/browser/ui/webui/extensions/extension_settings_handler.h" |
| 6 | 6 |
| 7 #include "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
| 8 #include "base/base64.h" | 8 #include "base/base64.h" |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 22 #include "chrome/browser/extensions/extension_system.h" | 22 #include "chrome/browser/extensions/extension_system.h" |
| 23 #include "chrome/browser/extensions/extension_warning_set.h" | 23 #include "chrome/browser/extensions/extension_warning_set.h" |
| 24 #include "chrome/browser/extensions/lazy_background_task_queue.h" | 24 #include "chrome/browser/extensions/lazy_background_task_queue.h" |
| 25 #include "chrome/browser/extensions/unpacked_installer.h" | 25 #include "chrome/browser/extensions/unpacked_installer.h" |
| 26 #include "chrome/browser/extensions/updater/extension_updater.h" | 26 #include "chrome/browser/extensions/updater/extension_updater.h" |
| 27 #include "chrome/browser/google/google_util.h" | 27 #include "chrome/browser/google/google_util.h" |
| 28 #include "chrome/browser/prefs/pref_service.h" | 28 #include "chrome/browser/prefs/pref_service.h" |
| 29 #include "chrome/browser/profiles/profile.h" | 29 #include "chrome/browser/profiles/profile.h" |
| 30 #include "chrome/browser/tab_contents/background_contents.h" | 30 #include "chrome/browser/tab_contents/background_contents.h" |
| 31 #include "chrome/browser/ui/browser_finder.h" | 31 #include "chrome/browser/ui/browser_finder.h" |
| 32 #include "chrome/browser/ui/extensions/application_launch.h" | |
| 32 #include "chrome/browser/ui/webui/extensions/extension_icon_source.h" | 33 #include "chrome/browser/ui/webui/extensions/extension_icon_source.h" |
| 33 #include "chrome/browser/view_type_utils.h" | 34 #include "chrome/browser/view_type_utils.h" |
| 34 #include "chrome/common/chrome_notification_types.h" | 35 #include "chrome/common/chrome_notification_types.h" |
| 35 #include "chrome/common/chrome_switches.h" | 36 #include "chrome/common/chrome_switches.h" |
| 36 #include "chrome/common/extensions/extension.h" | 37 #include "chrome/common/extensions/extension.h" |
| 37 #include "chrome/common/extensions/extension_icon_set.h" | 38 #include "chrome/common/extensions/extension_icon_set.h" |
| 38 #include "chrome/common/extensions/extension_set.h" | 39 #include "chrome/common/extensions/extension_set.h" |
| 39 #include "chrome/common/pref_names.h" | 40 #include "chrome/common/pref_names.h" |
| 40 #include "chrome/common/url_constants.h" | 41 #include "chrome/common/url_constants.h" |
| 41 #include "content/public/browser/notification_service.h" | 42 #include "content/public/browser/notification_service.h" |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 64 // | 65 // |
| 65 // ExtensionSettingsHandler | 66 // ExtensionSettingsHandler |
| 66 // | 67 // |
| 67 /////////////////////////////////////////////////////////////////////////////// | 68 /////////////////////////////////////////////////////////////////////////////// |
| 68 | 69 |
| 69 ExtensionSettingsHandler::ExtensionSettingsHandler() | 70 ExtensionSettingsHandler::ExtensionSettingsHandler() |
| 70 : extension_service_(NULL), | 71 : extension_service_(NULL), |
| 71 management_policy_(NULL), | 72 management_policy_(NULL), |
| 72 ignore_notifications_(false), | 73 ignore_notifications_(false), |
| 73 deleting_rvh_(NULL), | 74 deleting_rvh_(NULL), |
| 74 registered_for_notifications_(false) { | 75 registered_for_notifications_(false), |
| 76 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { | |
| 75 } | 77 } |
| 76 | 78 |
| 77 ExtensionSettingsHandler::~ExtensionSettingsHandler() { | 79 ExtensionSettingsHandler::~ExtensionSettingsHandler() { |
| 78 // There may be pending file dialogs, we need to tell them that we've gone | 80 // There may be pending file dialogs, we need to tell them that we've gone |
| 79 // away so they don't try and call back to us. | 81 // away so they don't try and call back to us. |
| 80 if (load_extension_dialog_) | 82 if (load_extension_dialog_) |
| 81 load_extension_dialog_->ListenerDestroyed(); | 83 load_extension_dialog_->ListenerDestroyed(); |
| 82 | 84 |
| 83 registrar_.RemoveAll(); | 85 registrar_.RemoveAll(); |
| 84 } | 86 } |
| 85 | 87 |
| 86 ExtensionSettingsHandler::ExtensionSettingsHandler(ExtensionService* service, | 88 ExtensionSettingsHandler::ExtensionSettingsHandler(ExtensionService* service, |
| 87 ManagementPolicy* policy) | 89 ManagementPolicy* policy) |
| 88 : extension_service_(service), | 90 : extension_service_(service), |
| 89 management_policy_(policy), | 91 management_policy_(policy), |
| 90 ignore_notifications_(false), | 92 ignore_notifications_(false), |
| 91 deleting_rvh_(NULL), | 93 deleting_rvh_(NULL), |
| 92 registered_for_notifications_(false) { | 94 registered_for_notifications_(false), |
| 95 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { | |
| 93 } | 96 } |
| 94 | 97 |
| 95 // static | 98 // static |
| 96 void ExtensionSettingsHandler::RegisterUserPrefs(PrefService* prefs) { | 99 void ExtensionSettingsHandler::RegisterUserPrefs(PrefService* prefs) { |
| 97 prefs->RegisterBooleanPref(prefs::kExtensionsUIDeveloperMode, | 100 prefs->RegisterBooleanPref(prefs::kExtensionsUIDeveloperMode, |
| 98 false, | 101 false, |
| 99 PrefService::SYNCABLE_PREF); | 102 PrefService::SYNCABLE_PREF); |
| 100 } | 103 } |
| 101 | 104 |
| 102 DictionaryValue* ExtensionSettingsHandler::CreateExtensionDetailValue( | 105 DictionaryValue* ExtensionSettingsHandler::CreateExtensionDetailValue( |
| (...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 389 MaybeUpdateAfterNotification(); | 392 MaybeUpdateAfterNotification(); |
| 390 break; | 393 break; |
| 391 case chrome::NOTIFICATION_BACKGROUND_CONTENTS_DELETED: | 394 case chrome::NOTIFICATION_BACKGROUND_CONTENTS_DELETED: |
| 392 deleting_rvh_ = content::Details<BackgroundContents>(details)-> | 395 deleting_rvh_ = content::Details<BackgroundContents>(details)-> |
| 393 web_contents()->GetRenderViewHost(); | 396 web_contents()->GetRenderViewHost(); |
| 394 // Fall through. | 397 // Fall through. |
| 395 case chrome::NOTIFICATION_BACKGROUND_CONTENTS_NAVIGATED: | 398 case chrome::NOTIFICATION_BACKGROUND_CONTENTS_NAVIGATED: |
| 396 case chrome::NOTIFICATION_EXTENSION_HOST_CREATED: | 399 case chrome::NOTIFICATION_EXTENSION_HOST_CREATED: |
| 397 source_profile = content::Source<Profile>(source).ptr(); | 400 source_profile = content::Source<Profile>(source).ptr(); |
| 398 if (!profile->IsSameProfile(source_profile)) | 401 if (!profile->IsSameProfile(source_profile)) |
| 399 return; | 402 return; |
| 400 MaybeUpdateAfterNotification(); | 403 MaybeUpdateAfterNotification(); |
| 401 break; | 404 break; |
| 402 case chrome::NOTIFICATION_EXTENSION_LOADED: | 405 case chrome::NOTIFICATION_EXTENSION_LOADED: { |
| 406 source_profile = content::Source<Profile>(source).ptr(); | |
| 407 const Extension* extension = | |
| 408 content::Details<const Extension>(details).ptr(); | |
| 409 std::list<std::string>::iterator iter = | |
| 410 std::find(relaunch_app_ids_.begin(), relaunch_app_ids_.end(), | |
| 411 extension->id()); | |
| 412 | |
| 413 if (profile->IsSameProfile(source_profile) && | |
| 414 iter != relaunch_app_ids_.end()) { | |
| 415 relaunch_app_ids_.erase(iter); | |
| 416 extensions::LazyBackgroundTaskQueue* queue = | |
| 417 ExtensionSystem::Get(profile)->lazy_background_task_queue(); | |
| 418 if (queue->ShouldEnqueueTask(profile, extension)) { | |
|
Evan Stade
2012/06/22 22:29:50
you would expect this to work, but it doesn't, bec
| |
| 419 queue->AddPendingTask(profile, extension->id(), | |
| 420 base::Bind(&ExtensionSettingsHandler::LaunchApplication, | |
| 421 weak_factory_.GetWeakPtr())); | |
| 422 } | |
| 423 } | |
| 424 | |
| 425 MaybeUpdateAfterNotification(); | |
| 426 break; | |
| 427 } | |
| 403 case chrome::NOTIFICATION_EXTENSION_UNLOADED: | 428 case chrome::NOTIFICATION_EXTENSION_UNLOADED: |
| 404 case chrome::NOTIFICATION_EXTENSION_UPDATE_DISABLED: | 429 case chrome::NOTIFICATION_EXTENSION_UPDATE_DISABLED: |
| 405 case chrome::NOTIFICATION_EXTENSION_WARNING_CHANGED: | 430 case chrome::NOTIFICATION_EXTENSION_WARNING_CHANGED: |
| 406 case chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED: | 431 case chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED: |
| 407 case chrome::NOTIFICATION_PREF_CHANGED: | 432 case chrome::NOTIFICATION_PREF_CHANGED: |
| 408 MaybeUpdateAfterNotification(); | 433 MaybeUpdateAfterNotification(); |
| 409 break; | 434 break; |
| 410 default: | 435 default: |
| 411 NOTREACHED(); | 436 NOTREACHED(); |
| 412 } | 437 } |
| 413 } | 438 } |
| 414 | 439 |
| 440 void ExtensionSettingsHandler::LaunchApplication( | |
| 441 ExtensionHost* extension_host) { | |
| 442 if (!extension_host) | |
| 443 return; | |
| 444 | |
| 445 const Extension* extension = extension_host->extension(); | |
| 446 extension_misc::LaunchContainer launch_container = | |
| 447 extension_service_->extension_prefs()->GetLaunchContainer( | |
| 448 extension, ExtensionPrefs::LAUNCH_REGULAR); | |
| 449 | |
| 450 application_launch::OpenApplication( | |
| 451 extension_service_->profile(), extension, launch_container, GURL(), | |
| 452 NEW_BACKGROUND_TAB, NULL); | |
| 453 } | |
| 454 | |
| 415 void ExtensionSettingsHandler::ExtensionUninstallAccepted() { | 455 void ExtensionSettingsHandler::ExtensionUninstallAccepted() { |
| 416 DCHECK(!extension_id_prompting_.empty()); | 456 DCHECK(!extension_id_prompting_.empty()); |
| 417 | 457 |
| 418 bool was_terminated = false; | 458 bool was_terminated = false; |
| 419 | 459 |
| 420 // The extension can be uninstalled in another window while the UI was | 460 // The extension can be uninstalled in another window while the UI was |
| 421 // showing. Do nothing in that case. | 461 // showing. Do nothing in that case. |
| 422 const Extension* extension = | 462 const Extension* extension = |
| 423 extension_service_->GetExtensionById(extension_id_prompting_, true); | 463 extension_service_->GetExtensionById(extension_id_prompting_, true); |
| 424 if (!extension) { | 464 if (!extension) { |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 448 const ExtensionSet* extensions = extension_service_->extensions(); | 488 const ExtensionSet* extensions = extension_service_->extensions(); |
| 449 std::vector<const Extension*> unpacked_extensions; | 489 std::vector<const Extension*> unpacked_extensions; |
| 450 for (ExtensionSet::const_iterator extension = extensions->begin(); | 490 for (ExtensionSet::const_iterator extension = extensions->begin(); |
| 451 extension != extensions->end(); ++extension) { | 491 extension != extensions->end(); ++extension) { |
| 452 if ((*extension)->location() == Extension::LOAD) | 492 if ((*extension)->location() == Extension::LOAD) |
| 453 unpacked_extensions.push_back(*extension); | 493 unpacked_extensions.push_back(*extension); |
| 454 } | 494 } |
| 455 | 495 |
| 456 for (std::vector<const Extension*>::iterator iter = | 496 for (std::vector<const Extension*>::iterator iter = |
| 457 unpacked_extensions.begin(); iter != unpacked_extensions.end(); ++iter) { | 497 unpacked_extensions.begin(); iter != unpacked_extensions.end(); ++iter) { |
| 458 extension_service_->ReloadExtension((*iter)->id()); | 498 ReloadExtension(*iter); |
| 459 } | 499 } |
| 460 } | 500 } |
| 461 | 501 |
| 502 void ExtensionSettingsHandler::ReloadExtension(const Extension* extension) { | |
| 503 Profile* profile = Profile::FromWebUI(web_ui()); | |
| 504 // If the extension is a platform app, and is "running" (i.e. has at least one | |
| 505 // open render view), then mark it for relaunch later. | |
| 506 if (extension->is_platform_app() && | |
| 507 !profile->GetExtensionProcessManager()-> | |
| 508 GetRenderViewHostsWithTypeForExtension( | |
| 509 extension->id(), chrome::VIEW_TYPE_APP_SHELL).empty()) { | |
| 510 relaunch_app_ids_.push_back(extension->id()); | |
| 511 } | |
| 512 extension_service_->ReloadExtension(extension->id()); | |
| 513 } | |
| 514 | |
| 462 void ExtensionSettingsHandler::HandleRequestExtensionsData( | 515 void ExtensionSettingsHandler::HandleRequestExtensionsData( |
| 463 const ListValue* args) { | 516 const ListValue* args) { |
| 464 DictionaryValue results; | 517 DictionaryValue results; |
| 465 | 518 |
| 466 // Add the extensions to the results structure. | 519 // Add the extensions to the results structure. |
| 467 ListValue *extensions_list = new ListValue(); | 520 ListValue *extensions_list = new ListValue(); |
| 468 | 521 |
| 469 ExtensionWarningSet* warnings = extension_service_->extension_warnings(); | 522 ExtensionWarningSet* warnings = extension_service_->extension_warnings(); |
| 470 | 523 |
| 471 const ExtensionSet* extensions = extension_service_->extensions(); | 524 const ExtensionSet* extensions = extension_service_->extensions(); |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 574 // This can happen if the host has gone away since the page was displayed. | 627 // This can happen if the host has gone away since the page was displayed. |
| 575 return; | 628 return; |
| 576 } | 629 } |
| 577 | 630 |
| 578 DevToolsWindow::OpenDevToolsWindow(host); | 631 DevToolsWindow::OpenDevToolsWindow(host); |
| 579 } | 632 } |
| 580 | 633 |
| 581 void ExtensionSettingsHandler::HandleReloadMessage(const ListValue* args) { | 634 void ExtensionSettingsHandler::HandleReloadMessage(const ListValue* args) { |
| 582 std::string extension_id = UTF16ToUTF8(ExtractStringValue(args)); | 635 std::string extension_id = UTF16ToUTF8(ExtractStringValue(args)); |
| 583 CHECK(!extension_id.empty()); | 636 CHECK(!extension_id.empty()); |
| 584 extension_service_->ReloadExtension(extension_id); | 637 |
| 638 const Extension* extension = | |
| 639 extension_service_->GetExtensionById(extension_id, false); | |
| 640 ReloadExtension(extension); | |
| 585 } | 641 } |
| 586 | 642 |
| 587 void ExtensionSettingsHandler::HandleEnableMessage(const ListValue* args) { | 643 void ExtensionSettingsHandler::HandleEnableMessage(const ListValue* args) { |
| 588 CHECK_EQ(2U, args->GetSize()); | 644 CHECK_EQ(2U, args->GetSize()); |
| 589 std::string extension_id, enable_str; | 645 std::string extension_id, enable_str; |
| 590 CHECK(args->GetString(0, &extension_id)); | 646 CHECK(args->GetString(0, &extension_id)); |
| 591 CHECK(args->GetString(1, &enable_str)); | 647 CHECK(args->GetString(1, &enable_str)); |
| 592 | 648 |
| 593 const Extension* extension = | 649 const Extension* extension = |
| 594 extension_service_->GetInstalledExtension(extension_id); | 650 extension_service_->GetInstalledExtension(extension_id); |
| (...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 854 return extension_uninstall_dialog_.get(); | 910 return extension_uninstall_dialog_.get(); |
| 855 #else | 911 #else |
| 856 return NULL; | 912 return NULL; |
| 857 #endif // !defined(OS_ANDROID) | 913 #endif // !defined(OS_ANDROID) |
| 858 } | 914 } |
| 859 | 915 |
| 860 void ExtensionSettingsHandler::InspectExtensionHost(ExtensionHost* host) { | 916 void ExtensionSettingsHandler::InspectExtensionHost(ExtensionHost* host) { |
| 861 if (host) | 917 if (host) |
| 862 DevToolsWindow::OpenDevToolsWindow(host->render_view_host()); | 918 DevToolsWindow::OpenDevToolsWindow(host->render_view_host()); |
| 863 } | 919 } |
| OLD | NEW |