Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(125)

Side by Side Diff: chrome/browser/ui/webui/extensions/extension_settings_handler.cc

Issue 10641017: make "reload" on chrome://extensions automatically relaunch running apps (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: hack Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/ui/webui/extensions/extension_settings_handler.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
11 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/file_util.h" 12 #include "base/file_util.h"
13 #include "base/string_number_conversions.h" 13 #include "base/string_number_conversions.h"
14 #include "base/utf_string_conversions.h" 14 #include "base/utf_string_conversions.h"
15 #include "base/values.h" 15 #include "base/values.h"
16 #include "base/version.h" 16 #include "base/version.h"
17 #include "chrome/browser/browser_process.h" 17 #include "chrome/browser/browser_process.h"
18 #include "chrome/browser/debugger/devtools_window.h" 18 #include "chrome/browser/debugger/devtools_window.h"
19 #include "chrome/browser/extensions/crx_installer.h" 19 #include "chrome/browser/extensions/crx_installer.h"
20 #include "chrome/browser/extensions/extension_disabled_ui.h" 20 #include "chrome/browser/extensions/extension_disabled_ui.h"
21 #include "chrome/browser/extensions/extension_host.h" 21 #include "chrome/browser/extensions/extension_host.h"
22 #include "chrome/browser/extensions/extension_service.h" 22 #include "chrome/browser/extensions/extension_service.h"
23 #include "chrome/browser/extensions/extension_system.h" 23 #include "chrome/browser/extensions/extension_system.h"
24 #include "chrome/browser/extensions/extension_warning_set.h" 24 #include "chrome/browser/extensions/extension_warning_set.h"
25 #include "chrome/browser/extensions/lazy_background_task_queue.h" 25 #include "chrome/browser/extensions/lazy_background_task_queue.h"
26 #include "chrome/browser/extensions/platform_app_launcher.h"
27 #include "chrome/browser/extensions/shell_window_registry.h"
26 #include "chrome/browser/extensions/unpacked_installer.h" 28 #include "chrome/browser/extensions/unpacked_installer.h"
27 #include "chrome/browser/extensions/updater/extension_updater.h" 29 #include "chrome/browser/extensions/updater/extension_updater.h"
28 #include "chrome/browser/google/google_util.h" 30 #include "chrome/browser/google/google_util.h"
29 #include "chrome/browser/managed_mode.h" 31 #include "chrome/browser/managed_mode.h"
30 #include "chrome/browser/prefs/pref_service.h" 32 #include "chrome/browser/prefs/pref_service.h"
31 #include "chrome/browser/profiles/profile.h" 33 #include "chrome/browser/profiles/profile.h"
32 #include "chrome/browser/tab_contents/background_contents.h" 34 #include "chrome/browser/tab_contents/background_contents.h"
33 #include "chrome/browser/ui/browser_finder.h" 35 #include "chrome/browser/ui/browser_finder.h"
34 #include "chrome/browser/ui/chrome_select_file_policy.h" 36 #include "chrome/browser/ui/chrome_select_file_policy.h"
37 #include "chrome/browser/ui/extensions/application_launch.h"
35 #include "chrome/browser/ui/webui/extensions/extension_icon_source.h" 38 #include "chrome/browser/ui/webui/extensions/extension_icon_source.h"
36 #include "chrome/browser/view_type_utils.h" 39 #include "chrome/browser/view_type_utils.h"
37 #include "chrome/common/chrome_notification_types.h" 40 #include "chrome/common/chrome_notification_types.h"
38 #include "chrome/common/chrome_switches.h" 41 #include "chrome/common/chrome_switches.h"
39 #include "chrome/common/extensions/extension.h" 42 #include "chrome/common/extensions/extension.h"
40 #include "chrome/common/extensions/extension_constants.h" 43 #include "chrome/common/extensions/extension_constants.h"
41 #include "chrome/common/extensions/extension_icon_set.h" 44 #include "chrome/common/extensions/extension_icon_set.h"
42 #include "chrome/common/extensions/extension_set.h" 45 #include "chrome/common/extensions/extension_set.h"
43 #include "chrome/common/pref_names.h" 46 #include "chrome/common/pref_names.h"
44 #include "chrome/common/url_constants.h" 47 #include "chrome/common/url_constants.h"
(...skipping 23 matching lines...) Expand all
68 // 71 //
69 // ExtensionSettingsHandler 72 // ExtensionSettingsHandler
70 // 73 //
71 /////////////////////////////////////////////////////////////////////////////// 74 ///////////////////////////////////////////////////////////////////////////////
72 75
73 ExtensionSettingsHandler::ExtensionSettingsHandler() 76 ExtensionSettingsHandler::ExtensionSettingsHandler()
74 : extension_service_(NULL), 77 : extension_service_(NULL),
75 management_policy_(NULL), 78 management_policy_(NULL),
76 ignore_notifications_(false), 79 ignore_notifications_(false),
77 deleting_rvh_(NULL), 80 deleting_rvh_(NULL),
78 registered_for_notifications_(false) { 81 registered_for_notifications_(false),
82 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) {
79 } 83 }
80 84
81 ExtensionSettingsHandler::~ExtensionSettingsHandler() { 85 ExtensionSettingsHandler::~ExtensionSettingsHandler() {
82 // There may be pending file dialogs, we need to tell them that we've gone 86 // There may be pending file dialogs, we need to tell them that we've gone
83 // away so they don't try and call back to us. 87 // away so they don't try and call back to us.
84 if (load_extension_dialog_) 88 if (load_extension_dialog_)
85 load_extension_dialog_->ListenerDestroyed(); 89 load_extension_dialog_->ListenerDestroyed();
86 90
87 registrar_.RemoveAll(); 91 registrar_.RemoveAll();
88 } 92 }
89 93
90 ExtensionSettingsHandler::ExtensionSettingsHandler(ExtensionService* service, 94 ExtensionSettingsHandler::ExtensionSettingsHandler(ExtensionService* service,
91 ManagementPolicy* policy) 95 ManagementPolicy* policy)
92 : extension_service_(service), 96 : extension_service_(service),
93 management_policy_(policy), 97 management_policy_(policy),
94 ignore_notifications_(false), 98 ignore_notifications_(false),
95 deleting_rvh_(NULL), 99 deleting_rvh_(NULL),
96 registered_for_notifications_(false) { 100 registered_for_notifications_(false),
101 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) {
97 } 102 }
98 103
99 // static 104 // static
100 void ExtensionSettingsHandler::RegisterUserPrefs(PrefService* prefs) { 105 void ExtensionSettingsHandler::RegisterUserPrefs(PrefService* prefs) {
101 prefs->RegisterBooleanPref(prefs::kExtensionsUIDeveloperMode, 106 prefs->RegisterBooleanPref(prefs::kExtensionsUIDeveloperMode,
102 false, 107 false,
103 PrefService::SYNCABLE_PREF); 108 PrefService::SYNCABLE_PREF);
104 } 109 }
105 110
106 DictionaryValue* ExtensionSettingsHandler::CreateExtensionDetailValue( 111 DictionaryValue* ExtensionSettingsHandler::CreateExtensionDetailValue(
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after
397 MaybeUpdateAfterNotification(); 402 MaybeUpdateAfterNotification();
398 break; 403 break;
399 case chrome::NOTIFICATION_BACKGROUND_CONTENTS_DELETED: 404 case chrome::NOTIFICATION_BACKGROUND_CONTENTS_DELETED:
400 deleting_rvh_ = content::Details<BackgroundContents>(details)-> 405 deleting_rvh_ = content::Details<BackgroundContents>(details)->
401 web_contents()->GetRenderViewHost(); 406 web_contents()->GetRenderViewHost();
402 // Fall through. 407 // Fall through.
403 case chrome::NOTIFICATION_BACKGROUND_CONTENTS_NAVIGATED: 408 case chrome::NOTIFICATION_BACKGROUND_CONTENTS_NAVIGATED:
404 case chrome::NOTIFICATION_EXTENSION_HOST_CREATED: 409 case chrome::NOTIFICATION_EXTENSION_HOST_CREATED:
405 source_profile = content::Source<Profile>(source).ptr(); 410 source_profile = content::Source<Profile>(source).ptr();
406 if (!profile->IsSameProfile(source_profile)) 411 if (!profile->IsSameProfile(source_profile))
407 return; 412 return;
408 MaybeUpdateAfterNotification(); 413 MaybeUpdateAfterNotification();
409 break; 414 break;
410 case chrome::NOTIFICATION_EXTENSION_LOADED: 415 case chrome::NOTIFICATION_EXTENSION_ENABLED: {
416 const Extension* extension =
417 content::Details<const Extension>(details).ptr();
418 RelaunchApps::iterator iter = relaunch_app_ids_.find(extension->id());
419 if (iter != relaunch_app_ids_.end())
420 iter->second = true;
421
422 break;
423 }
424 case chrome::NOTIFICATION_EXTENSION_LOADED: {
425 const Extension* extension =
426 content::Details<const Extension>(details).ptr();
427 RelaunchApps::iterator iter = relaunch_app_ids_.find(extension->id());
428
429 if (profile->IsSameProfile(source_profile) &&
430 iter != relaunch_app_ids_.end() &&
431 iter->second) {
432 relaunch_app_ids_.erase(iter);
433 extensions::LazyBackgroundTaskQueue* queue =
434 extensions::ExtensionSystem::Get(profile)->
435 lazy_background_task_queue();
436 if (queue->ShouldEnqueueTask(profile, extension)) {
437 queue->AddPendingTask(profile, extension->id(),
438 base::Bind(&ExtensionSettingsHandler::LaunchApplication,
439 weak_factory_.GetWeakPtr()));
Mihai Parparita -not on Chrome 2012/08/21 22:38:35 You can get both the Extension and Profile instanc
440 }
441 }
442
443 MaybeUpdateAfterNotification();
444 break;
445 }
411 case chrome::NOTIFICATION_EXTENSION_UNLOADED: 446 case chrome::NOTIFICATION_EXTENSION_UNLOADED:
412 case chrome::NOTIFICATION_EXTENSION_UPDATE_DISABLED: 447 case chrome::NOTIFICATION_EXTENSION_UPDATE_DISABLED:
413 case chrome::NOTIFICATION_EXTENSION_WARNING_CHANGED: 448 case chrome::NOTIFICATION_EXTENSION_WARNING_CHANGED:
414 case chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED: 449 case chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED:
415 case chrome::NOTIFICATION_PREF_CHANGED: 450 case chrome::NOTIFICATION_PREF_CHANGED:
416 MaybeUpdateAfterNotification(); 451 MaybeUpdateAfterNotification();
417 break; 452 break;
418 default: 453 default:
419 NOTREACHED(); 454 NOTREACHED();
420 } 455 }
421 } 456 }
422 457
458 void ExtensionSettingsHandler::LaunchApplication(
459 extensions::ExtensionHost* extension_host) {
460 if (!extension_host)
461 return;
462
463 const Extension* extension = extension_host->extension();
464 extensions::LaunchPlatformApp(extension_service_->profile(), extension,
465 NULL, FilePath());
466 }
467
423 void ExtensionSettingsHandler::ExtensionUninstallAccepted() { 468 void ExtensionSettingsHandler::ExtensionUninstallAccepted() {
424 DCHECK(!extension_id_prompting_.empty()); 469 DCHECK(!extension_id_prompting_.empty());
425 470
426 bool was_terminated = false; 471 bool was_terminated = false;
427 472
428 // The extension can be uninstalled in another window while the UI was 473 // The extension can be uninstalled in another window while the UI was
429 // showing. Do nothing in that case. 474 // showing. Do nothing in that case.
430 const Extension* extension = 475 const Extension* extension =
431 extension_service_->GetExtensionById(extension_id_prompting_, true); 476 extension_service_->GetExtensionById(extension_id_prompting_, true);
432 if (!extension) { 477 if (!extension) {
(...skipping 23 matching lines...) Expand all
456 const ExtensionSet* extensions = extension_service_->extensions(); 501 const ExtensionSet* extensions = extension_service_->extensions();
457 std::vector<const Extension*> unpacked_extensions; 502 std::vector<const Extension*> unpacked_extensions;
458 for (ExtensionSet::const_iterator extension = extensions->begin(); 503 for (ExtensionSet::const_iterator extension = extensions->begin();
459 extension != extensions->end(); ++extension) { 504 extension != extensions->end(); ++extension) {
460 if ((*extension)->location() == Extension::LOAD) 505 if ((*extension)->location() == Extension::LOAD)
461 unpacked_extensions.push_back(*extension); 506 unpacked_extensions.push_back(*extension);
462 } 507 }
463 508
464 for (std::vector<const Extension*>::iterator iter = 509 for (std::vector<const Extension*>::iterator iter =
465 unpacked_extensions.begin(); iter != unpacked_extensions.end(); ++iter) { 510 unpacked_extensions.begin(); iter != unpacked_extensions.end(); ++iter) {
466 extension_service_->ReloadExtension((*iter)->id()); 511 ReloadExtension(*iter);
467 } 512 }
468 } 513 }
469 514
515 void ExtensionSettingsHandler::ReloadExtension(const Extension* extension) {
516 Profile* profile = Profile::FromWebUI(web_ui());
517 // If the extension is a platform app, and is "running" (i.e. has at least one
518 // open window), then mark it for relaunch later.
519 if (extension->is_platform_app() &&
520 !extensions::ShellWindowRegistry::Get(profile)->
521 GetShellWindowsForApp(extension->id()).empty()) {
522 relaunch_app_ids_[extension->id()] = false;
523 }
524 extension_service_->ReloadExtension(extension->id());
525 }
526
470 void ExtensionSettingsHandler::HandleRequestExtensionsData( 527 void ExtensionSettingsHandler::HandleRequestExtensionsData(
471 const ListValue* args) { 528 const ListValue* args) {
472 DictionaryValue results; 529 DictionaryValue results;
473 530
474 // Add the extensions to the results structure. 531 // Add the extensions to the results structure.
475 ListValue *extensions_list = new ListValue(); 532 ListValue *extensions_list = new ListValue();
476 533
477 ExtensionWarningSet* warnings = extension_service_->extension_warnings(); 534 ExtensionWarningSet* warnings = extension_service_->extension_warnings();
478 535
479 const ExtensionSet* extensions = extension_service_->extensions(); 536 const ExtensionSet* extensions = extension_service_->extensions();
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
592 // This can happen if the host has gone away since the page was displayed. 649 // This can happen if the host has gone away since the page was displayed.
593 return; 650 return;
594 } 651 }
595 652
596 DevToolsWindow::OpenDevToolsWindow(host); 653 DevToolsWindow::OpenDevToolsWindow(host);
597 } 654 }
598 655
599 void ExtensionSettingsHandler::HandleReloadMessage(const ListValue* args) { 656 void ExtensionSettingsHandler::HandleReloadMessage(const ListValue* args) {
600 std::string extension_id = UTF16ToUTF8(ExtractStringValue(args)); 657 std::string extension_id = UTF16ToUTF8(ExtractStringValue(args));
601 CHECK(!extension_id.empty()); 658 CHECK(!extension_id.empty());
602 extension_service_->ReloadExtension(extension_id); 659
660 const Extension* extension =
661 extension_service_->GetExtensionById(extension_id, false);
662 ReloadExtension(extension);
603 } 663 }
604 664
605 void ExtensionSettingsHandler::HandleEnableMessage(const ListValue* args) { 665 void ExtensionSettingsHandler::HandleEnableMessage(const ListValue* args) {
606 CHECK_EQ(2U, args->GetSize()); 666 CHECK_EQ(2U, args->GetSize());
607 std::string extension_id, enable_str; 667 std::string extension_id, enable_str;
608 CHECK(args->GetString(0, &extension_id)); 668 CHECK(args->GetString(0, &extension_id));
609 CHECK(args->GetString(1, &enable_str)); 669 CHECK(args->GetString(1, &enable_str));
610 670
611 const Extension* extension = 671 const Extension* extension =
612 extension_service_->GetInstalledExtension(extension_id); 672 extension_service_->GetInstalledExtension(extension_id);
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
770 return; 830 return;
771 831
772 registered_for_notifications_ = true; 832 registered_for_notifications_ = true;
773 Profile* profile = Profile::FromWebUI(web_ui()); 833 Profile* profile = Profile::FromWebUI(web_ui());
774 834
775 // Register for notifications that we need to reload the page. 835 // Register for notifications that we need to reload the page.
776 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, 836 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED,
777 content::Source<Profile>(profile)); 837 content::Source<Profile>(profile));
778 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, 838 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED,
779 content::Source<Profile>(profile)); 839 content::Source<Profile>(profile));
840 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_ENABLED,
841 content::Source<Profile>(profile));
780 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UPDATE_DISABLED, 842 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UPDATE_DISABLED,
781 content::Source<Profile>(profile)); 843 content::Source<Profile>(profile));
782 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_WARNING_CHANGED, 844 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_WARNING_CHANGED,
783 content::Source<Profile>(profile)); 845 content::Source<Profile>(profile));
784 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_CREATED, 846 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_CREATED,
785 content::NotificationService::AllBrowserContextsAndSources()); 847 content::NotificationService::AllBrowserContextsAndSources());
786 registrar_.Add(this, 848 registrar_.Add(this,
787 content::NOTIFICATION_RENDER_VIEW_HOST_CREATED, 849 content::NOTIFICATION_RENDER_VIEW_HOST_CREATED,
788 content::NotificationService::AllBrowserContextsAndSources()); 850 content::NotificationService::AllBrowserContextsAndSources());
789 registrar_.Add(this, 851 registrar_.Add(this,
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
880 #else 942 #else
881 return NULL; 943 return NULL;
882 #endif // !defined(OS_ANDROID) 944 #endif // !defined(OS_ANDROID)
883 } 945 }
884 946
885 void ExtensionSettingsHandler::InspectExtensionHost( 947 void ExtensionSettingsHandler::InspectExtensionHost(
886 extensions::ExtensionHost* host) { 948 extensions::ExtensionHost* host) {
887 if (host) 949 if (host)
888 DevToolsWindow::OpenDevToolsWindow(host->render_view_host()); 950 DevToolsWindow::OpenDevToolsWindow(host->render_view_host());
889 } 951 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/extensions/extension_settings_handler.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698