diff options
author | mpcomplete@chromium.org <mpcomplete@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-04-04 19:22:35 +0000 |
---|---|---|
committer | mpcomplete@chromium.org <mpcomplete@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-04-04 19:22:35 +0000 |
commit | 872b5045d897456ebcea2fe8a527740d5eab2fd2 (patch) | |
tree | 3f0079a81de212d65157ac9c36793185ad88165e /chrome | |
parent | 992cb5c742f6844b539c8ffaec3572d60d93304d (diff) | |
download | chromium_src-872b5045d897456ebcea2fe8a527740d5eab2fd2.zip chromium_src-872b5045d897456ebcea2fe8a527740d5eab2fd2.tar.gz chromium_src-872b5045d897456ebcea2fe8a527740d5eab2fd2.tar.bz2 |
Add a link to inspect an inactive transient page from the extension settings
page.
Also, registered events are now reset each time an extension is installed or
reloaded.
BUG=119621
TEST=no
Review URL: https://chromiumcodereview.appspot.com/9950105
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@130703 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
5 files changed, 91 insertions, 20 deletions
diff --git a/chrome/app/generated_resources.grd b/chrome/app/generated_resources.grd index dc4def3..008bb2b 100644 --- a/chrome/app/generated_resources.grd +++ b/chrome/app/generated_resources.grd @@ -4473,14 +4473,17 @@ Update checks have repeatedly failed for the extension "<ph name="EXTENSION_NAME <message name="IDS_EXTENSIONS_VIEW_INCOGNITO" desc="Text that signifies that the extension view is in an incognito process."> (Incognito) </message> + <message name="IDS_EXTENSIONS_VIEW_INACTIVE" desc="Text that signifies that the extension view is an inactive transient page."> + (Inactive) + </message> <message name="IDS_EXTENSIONS_ID" desc="The ID label in front of the extension ID."> ID: </message> <message name="IDS_EXTENSIONS_PATH" desc="The label in front of the extension load path."> Loaded from: </message> - <message name="IDS_EXTENSIONS_INSPECT_VIEWS" desc="The text for the label in front of the links to inspect active views."> - Inspect active views: + <message name="IDS_EXTENSIONS_INSPECT_VIEWS" desc="The text for the label in front of the links to inspect views (some of which may not be loaded yet)."> + Inspect views: </message> <message name="IDS_EXTENSIONS_ENABLE" desc="The link for enabling extensions."> Enable diff --git a/chrome/browser/extensions/extension_prefs.cc b/chrome/browser/extensions/extension_prefs.cc index 818fb2a..2c5dc80 100644 --- a/chrome/browser/extensions/extension_prefs.cc +++ b/chrome/browser/extensions/extension_prefs.cc @@ -1119,6 +1119,9 @@ void ExtensionPrefs::OnExtensionInstalled( extension->manifest()->value()->DeepCopy()); } + // Clear any events that may be registered from a previous install. + extension_dict->Remove(kRegisteredEvents, NULL); + if (extension->is_app()) { StringOrdinal new_page_ordinal = page_ordinal.IsValid() ? page_ordinal : extension_sorting_->GetNaturalAppPageOrdinal(); diff --git a/chrome/browser/resources/extensions/extension_list.js b/chrome/browser/resources/extensions/extension_list.js index 86c5390..a93bab2 100644 --- a/chrome/browser/resources/extensions/extension_list.js +++ b/chrome/browser/resources/extensions/extension_list.js @@ -209,14 +209,19 @@ cr.define('options', function() { var link = activeViews.querySelector('a'); extension.views.forEach(function(view, i) { - var label = view.path + (view.incognito ? - ' ' + localStrings.getString('viewIncognito') : ''); + var label = view.path + + (view.incognito ? + ' ' + localStrings.getString('viewIncognito') : '') + + (view.renderProcessId == -1 ? + ' ' + localStrings.getString('viewInactive') : ''); link.textContent = label; link.addEventListener('click', function(e) { // TODO(estade): remove conversion to string? chrome.send('extensionSettingsInspect', [ + String(extension.id), String(view.renderProcessId), - String(view.renderViewId) + String(view.renderViewId), + view.incognito ]); }); @@ -226,7 +231,6 @@ cr.define('options', function() { } }); } - this.appendChild(node); }, }; diff --git a/chrome/browser/ui/webui/extensions/extension_settings_handler.cc b/chrome/browser/ui/webui/extensions/extension_settings_handler.cc index 615a848..a1c9073 100644 --- a/chrome/browser/ui/webui/extensions/extension_settings_handler.cc +++ b/chrome/browser/ui/webui/extensions/extension_settings_handler.cc @@ -17,8 +17,12 @@ #include "chrome/browser/debugger/devtools_window.h" #include "chrome/browser/extensions/crx_installer.h" #include "chrome/browser/extensions/extension_disabled_ui.h" +#include "chrome/browser/extensions/extension_host.h" #include "chrome/browser/extensions/extension_service.h" +#include "chrome/browser/extensions/extension_system.h" +#include "chrome/browser/extensions/extension_system_factory.h" #include "chrome/browser/extensions/extension_warning_set.h" +#include "chrome/browser/extensions/lazy_background_task_queue.h" #include "chrome/browser/extensions/unpacked_installer.h" #include "chrome/browser/extensions/updater/extension_updater.h" #include "chrome/browser/google/google_util.h" @@ -231,6 +235,8 @@ void ExtensionSettingsHandler::GetLocalizedValues( l10n_util::GetStringUTF16(IDS_EXTENSIONS_INSPECT_VIEWS)); localized_strings->SetString("viewIncognito", l10n_util::GetStringUTF16(IDS_EXTENSIONS_VIEW_INCOGNITO)); + localized_strings->SetString("viewInactive", + l10n_util::GetStringUTF16(IDS_EXTENSIONS_VIEW_INACTIVE)); localized_strings->SetString("extensionSettingsEnable", l10n_util::GetStringUTF16(IDS_EXTENSIONS_ENABLE)); localized_strings->SetString("extensionSettingsEnabled", @@ -448,7 +454,7 @@ void ExtensionSettingsHandler::HandleRequestExtensionsData( if (ShouldShowExtension(*extension)) { extensions_list->Append(CreateExtensionDetailValue( *extension, - GetActivePagesForExtension(*extension), + GetInspectablePagesForExtension(*extension, true), warnings)); } } @@ -458,7 +464,7 @@ void ExtensionSettingsHandler::HandleRequestExtensionsData( if (ShouldShowExtension(*extension)) { extensions_list->Append(CreateExtensionDetailValue( *extension, - GetActivePagesForExtension(*extension), + GetInspectablePagesForExtension(*extension, false), warnings)); } } @@ -497,15 +503,48 @@ void ExtensionSettingsHandler::HandleToggleDeveloperMode( } void ExtensionSettingsHandler::HandleInspectMessage(const ListValue* args) { + std::string extension_id; std::string render_process_id_str; std::string render_view_id_str; int render_process_id; int render_view_id; - CHECK_EQ(2U, args->GetSize()); - CHECK(args->GetString(0, &render_process_id_str)); - CHECK(args->GetString(1, &render_view_id_str)); + bool incognito; + CHECK_EQ(4U, args->GetSize()); + CHECK(args->GetString(0, &extension_id)); + CHECK(args->GetString(1, &render_process_id_str)); + CHECK(args->GetString(2, &render_view_id_str)); + CHECK(args->GetBoolean(3, &incognito)); CHECK(base::StringToInt(render_process_id_str, &render_process_id)); CHECK(base::StringToInt(render_view_id_str, &render_view_id)); + + if (render_process_id == -1) { + // This message is for a lazy background page. Start the page if necessary. + const Extension* extension = + extension_service_->extensions()->GetByID(extension_id); + DCHECK(extension); + + Profile* profile = extension_service_->profile(); + if (incognito) + profile = profile->GetOffTheRecordProfile(); + + ExtensionProcessManager* pm = profile->GetExtensionProcessManager(); + LazyBackgroundTaskQueue* queue = + ExtensionSystemFactory::GetForProfile(profile)-> + lazy_background_task_queue(); + + ExtensionHost* host = pm->GetBackgroundHostForExtension(extension->id()); + if (host) { + InspectExtensionHost(host); + } else { + queue->AddPendingTask( + profile, extension->id(), + base::Bind(&ExtensionSettingsHandler::InspectExtensionHost, + base::Unretained(this))); + } + + return; + } + RenderViewHost* host = RenderViewHost::FromID(render_process_id, render_view_id); if (!host) { @@ -710,32 +749,46 @@ void ExtensionSettingsHandler::MaybeRegisterForNotifications() { extension_prefs())); } -std::vector<ExtensionPage> ExtensionSettingsHandler::GetActivePagesForExtension( - const Extension* extension) { +std::vector<ExtensionPage> +ExtensionSettingsHandler::GetInspectablePagesForExtension( + const Extension* extension, bool extension_is_enabled) { std::vector<ExtensionPage> result; // Get the extension process's active views. ExtensionProcessManager* process_manager = extension_service_->profile()->GetExtensionProcessManager(); - GetActivePagesForExtensionProcess( + GetInspectablePagesForExtensionProcess( process_manager->GetRenderViewHostsForExtension( extension->id()), &result); + // Include a link to start the lazy background page, if applicable. + if (extension->has_lazy_background_page() && extension_is_enabled && + !process_manager->GetBackgroundHostForExtension(extension->id())) { + result.push_back( + ExtensionPage(extension->GetBackgroundURL(), -1, -1, false)); + } + // Repeat for the incognito process, if applicable. if (extension_service_->profile()->HasOffTheRecordProfile() && extension->incognito_split_mode()) { ExtensionProcessManager* process_manager = extension_service_->profile()->GetOffTheRecordProfile()-> GetExtensionProcessManager(); - GetActivePagesForExtensionProcess( + GetInspectablePagesForExtensionProcess( process_manager->GetRenderViewHostsForExtension( extension->id()), &result); + + if (extension->has_lazy_background_page() && extension_is_enabled && + !process_manager->GetBackgroundHostForExtension(extension->id())) { + result.push_back( + ExtensionPage(extension->GetBackgroundURL(), -1, -1, true)); + } } return result; } -void ExtensionSettingsHandler::GetActivePagesForExtensionProcess( +void ExtensionSettingsHandler::GetInspectablePagesForExtensionProcess( const std::set<RenderViewHost*>& views, std::vector<ExtensionPage> *result) { for (std::set<RenderViewHost*>::const_iterator iter = views.begin(); @@ -763,3 +816,7 @@ ExtensionSettingsHandler::GetExtensionUninstallDialog() { } return extension_uninstall_dialog_.get(); } + +void ExtensionSettingsHandler::InspectExtensionHost(ExtensionHost* host) { + DevToolsWindow::OpenDevToolsWindow(host->render_view_host()); +} diff --git a/chrome/browser/ui/webui/extensions/extension_settings_handler.h b/chrome/browser/ui/webui/extensions/extension_settings_handler.h index c25954a..1cc296f 100644 --- a/chrome/browser/ui/webui/extensions/extension_settings_handler.h +++ b/chrome/browser/ui/webui/extensions/extension_settings_handler.h @@ -25,6 +25,7 @@ #include "googleurl/src/gurl.h" class Extension; +class ExtensionHost; class ExtensionService; class FilePath; class PrefService; @@ -150,10 +151,10 @@ class ExtensionSettingsHandler : public content::WebUIMessageHandler, // Register for notifications that we need to reload the page. void MaybeRegisterForNotifications(); - // Helper that lists the current active html pages for an extension. - std::vector<ExtensionPage> GetActivePagesForExtension( - const Extension* extension); - void GetActivePagesForExtensionProcess( + // Helper that lists the current inspectable html pages for an extension. + std::vector<ExtensionPage> GetInspectablePagesForExtension( + const Extension* extension, bool extension_is_enabled); + void GetInspectablePagesForExtensionProcess( const std::set<content::RenderViewHost*>& views, std::vector<ExtensionPage> *result); @@ -161,6 +162,9 @@ class ExtensionSettingsHandler : public content::WebUIMessageHandler, // needed. ExtensionUninstallDialog* GetExtensionUninstallDialog(); + // Helper to inspect an ExtensionHost after it has been loaded. + void InspectExtensionHost(ExtensionHost* host); + // Our model. Outlives us since it's owned by our containing profile. // Note: This may be NULL in unit tests. ExtensionService* extension_service_; |