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 // For platform apps, there's not a really good way to know when the | |
| 417 // background page has started up and is ready to receive the | |
| 418 // onLaunched event, so we just wait half a second. | |
|
Evan Stade
2012/06/22 05:17:51
suggestions for improvement welcome.
Aaron Boodman
2012/06/22 05:35:02
LazyBackgroundTaskQueue ?
Evan Stade
2012/06/22 19:39:51
awesome
| |
| 419 MessageLoop::current()->PostDelayedTask( | |
| 420 FROM_HERE, | |
| 421 base::Bind(&ExtensionSettingsHandler::LaunchApplication, | |
| 422 weak_factory_.GetWeakPtr(), | |
| 423 extension->id()), | |
| 424 base::TimeDelta::FromMilliseconds(500)); | |
| 425 } | |
| 426 | |
| 427 MaybeUpdateAfterNotification(); | |
| 428 break; | |
| 429 } | |
| 403 case chrome::NOTIFICATION_EXTENSION_UNLOADED: | 430 case chrome::NOTIFICATION_EXTENSION_UNLOADED: |
| 404 case chrome::NOTIFICATION_EXTENSION_UPDATE_DISABLED: | 431 case chrome::NOTIFICATION_EXTENSION_UPDATE_DISABLED: |
| 405 case chrome::NOTIFICATION_EXTENSION_WARNING_CHANGED: | 432 case chrome::NOTIFICATION_EXTENSION_WARNING_CHANGED: |
| 406 case chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED: | 433 case chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED: |
| 407 case chrome::NOTIFICATION_PREF_CHANGED: | 434 case chrome::NOTIFICATION_PREF_CHANGED: |
| 408 MaybeUpdateAfterNotification(); | 435 MaybeUpdateAfterNotification(); |
| 409 break; | 436 break; |
| 410 default: | 437 default: |
| 411 NOTREACHED(); | 438 NOTREACHED(); |
| 412 } | 439 } |
| 413 } | 440 } |
| 414 | 441 |
| 442 void ExtensionSettingsHandler::LaunchApplication( | |
| 443 const std::string& extension_id) { | |
| 444 const Extension* extension = | |
| 445 extension_service_->GetExtensionById(extension_id, false); | |
| 446 if (!extension) | |
| 447 return; | |
| 448 | |
| 449 extension_misc::LaunchContainer launch_container = | |
| 450 extension_service_->extension_prefs()->GetLaunchContainer( | |
| 451 extension, ExtensionPrefs::LAUNCH_REGULAR); | |
| 452 | |
| 453 application_launch::OpenApplication( | |
| 454 extension_service_->profile(), extension, launch_container, GURL(), | |
| 455 NEW_BACKGROUND_TAB, NULL); | |
| 456 } | |
| 457 | |
| 415 void ExtensionSettingsHandler::ExtensionUninstallAccepted() { | 458 void ExtensionSettingsHandler::ExtensionUninstallAccepted() { |
| 416 DCHECK(!extension_id_prompting_.empty()); | 459 DCHECK(!extension_id_prompting_.empty()); |
| 417 | 460 |
| 418 bool was_terminated = false; | 461 bool was_terminated = false; |
| 419 | 462 |
| 420 // The extension can be uninstalled in another window while the UI was | 463 // The extension can be uninstalled in another window while the UI was |
| 421 // showing. Do nothing in that case. | 464 // showing. Do nothing in that case. |
| 422 const Extension* extension = | 465 const Extension* extension = |
| 423 extension_service_->GetExtensionById(extension_id_prompting_, true); | 466 extension_service_->GetExtensionById(extension_id_prompting_, true); |
| 424 if (!extension) { | 467 if (!extension) { |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 448 const ExtensionSet* extensions = extension_service_->extensions(); | 491 const ExtensionSet* extensions = extension_service_->extensions(); |
| 449 std::vector<const Extension*> unpacked_extensions; | 492 std::vector<const Extension*> unpacked_extensions; |
| 450 for (ExtensionSet::const_iterator extension = extensions->begin(); | 493 for (ExtensionSet::const_iterator extension = extensions->begin(); |
| 451 extension != extensions->end(); ++extension) { | 494 extension != extensions->end(); ++extension) { |
| 452 if ((*extension)->location() == Extension::LOAD) | 495 if ((*extension)->location() == Extension::LOAD) |
| 453 unpacked_extensions.push_back(*extension); | 496 unpacked_extensions.push_back(*extension); |
| 454 } | 497 } |
| 455 | 498 |
| 456 for (std::vector<const Extension*>::iterator iter = | 499 for (std::vector<const Extension*>::iterator iter = |
| 457 unpacked_extensions.begin(); iter != unpacked_extensions.end(); ++iter) { | 500 unpacked_extensions.begin(); iter != unpacked_extensions.end(); ++iter) { |
| 458 extension_service_->ReloadExtension((*iter)->id()); | 501 ReloadExtension(*iter); |
| 459 } | 502 } |
| 460 } | 503 } |
| 461 | 504 |
| 505 void ExtensionSettingsHandler::ReloadExtension( | |
| 506 const Extension* extension) { | |
| 507 Profile* profile = Profile::FromWebUI(web_ui()); | |
| 508 // If the extension is a platform app, and is "running" (i.e. has open render | |
| 509 // views), then mark it for relaunch later. | |
|
Evan Stade
2012/06/22 05:17:51
this is kind of a hokey definition of "running", b
Aaron Boodman
2012/06/22 05:35:02
I think if there are no running render views, the
Evan Stade
2012/06/22 19:39:51
I don't want to count background pages.
Aaron Boodman
2012/06/22 20:30:54
I'm surprised that the event page is not returned
Evan Stade
2012/06/22 22:29:50
oh, it does. I was confused because the background
| |
| 510 if (extension->is_platform_app() && | |
| 511 !profile->GetExtensionProcessManager()-> | |
| 512 GetRenderViewHostsForExtension(extension->id()).empty()) { | |
| 513 relaunch_app_ids_.push_back(extension->id()); | |
| 514 } | |
| 515 extension_service_->ReloadExtension(extension->id()); | |
| 516 } | |
| 517 | |
| 462 void ExtensionSettingsHandler::HandleRequestExtensionsData( | 518 void ExtensionSettingsHandler::HandleRequestExtensionsData( |
| 463 const ListValue* args) { | 519 const ListValue* args) { |
| 464 DictionaryValue results; | 520 DictionaryValue results; |
| 465 | 521 |
| 466 // Add the extensions to the results structure. | 522 // Add the extensions to the results structure. |
| 467 ListValue *extensions_list = new ListValue(); | 523 ListValue *extensions_list = new ListValue(); |
| 468 | 524 |
| 469 ExtensionWarningSet* warnings = extension_service_->extension_warnings(); | 525 ExtensionWarningSet* warnings = extension_service_->extension_warnings(); |
| 470 | 526 |
| 471 const ExtensionSet* extensions = extension_service_->extensions(); | 527 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. | 630 // This can happen if the host has gone away since the page was displayed. |
| 575 return; | 631 return; |
| 576 } | 632 } |
| 577 | 633 |
| 578 DevToolsWindow::OpenDevToolsWindow(host); | 634 DevToolsWindow::OpenDevToolsWindow(host); |
| 579 } | 635 } |
| 580 | 636 |
| 581 void ExtensionSettingsHandler::HandleReloadMessage(const ListValue* args) { | 637 void ExtensionSettingsHandler::HandleReloadMessage(const ListValue* args) { |
| 582 std::string extension_id = UTF16ToUTF8(ExtractStringValue(args)); | 638 std::string extension_id = UTF16ToUTF8(ExtractStringValue(args)); |
| 583 CHECK(!extension_id.empty()); | 639 CHECK(!extension_id.empty()); |
| 584 extension_service_->ReloadExtension(extension_id); | 640 |
| 641 const Extension* extension = | |
| 642 extension_service_->GetExtensionById(extension_id, false); | |
| 643 ReloadExtension(extension); | |
| 585 } | 644 } |
| 586 | 645 |
| 587 void ExtensionSettingsHandler::HandleEnableMessage(const ListValue* args) { | 646 void ExtensionSettingsHandler::HandleEnableMessage(const ListValue* args) { |
| 588 CHECK_EQ(2U, args->GetSize()); | 647 CHECK_EQ(2U, args->GetSize()); |
| 589 std::string extension_id, enable_str; | 648 std::string extension_id, enable_str; |
| 590 CHECK(args->GetString(0, &extension_id)); | 649 CHECK(args->GetString(0, &extension_id)); |
| 591 CHECK(args->GetString(1, &enable_str)); | 650 CHECK(args->GetString(1, &enable_str)); |
| 592 | 651 |
| 593 const Extension* extension = | 652 const Extension* extension = |
| 594 extension_service_->GetInstalledExtension(extension_id); | 653 extension_service_->GetInstalledExtension(extension_id); |
| (...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 854 return extension_uninstall_dialog_.get(); | 913 return extension_uninstall_dialog_.get(); |
| 855 #else | 914 #else |
| 856 return NULL; | 915 return NULL; |
| 857 #endif // !defined(OS_ANDROID) | 916 #endif // !defined(OS_ANDROID) |
| 858 } | 917 } |
| 859 | 918 |
| 860 void ExtensionSettingsHandler::InspectExtensionHost(ExtensionHost* host) { | 919 void ExtensionSettingsHandler::InspectExtensionHost(ExtensionHost* host) { |
| 861 if (host) | 920 if (host) |
| 862 DevToolsWindow::OpenDevToolsWindow(host->render_view_host()); | 921 DevToolsWindow::OpenDevToolsWindow(host->render_view_host()); |
| 863 } | 922 } |
| OLD | NEW |