Commit ea4d3ab4 authored by rdevlin.cronin's avatar rdevlin.cronin Committed by Commit bot

[Extensions] Make chrome://extensions use developerPrivate for inspect

Make the chrome://extensions page use chrome.developerPrivate API for
'inspect' calls.
Also convert the api function to a UIThreadExtensionFunction.

BUG=461039

Review URL: https://codereview.chromium.org/989843002

Cr-Commit-Position: refs/heads/master@{#319748}
parent 4e4200b5
...@@ -103,10 +103,10 @@ const char kCouldNotShowSelectFileDialogError[] = ...@@ -103,10 +103,10 @@ const char kCouldNotShowSelectFileDialogError[] =
"Could not show a file chooser."; "Could not show a file chooser.";
const char kFileSelectionCanceled[] = const char kFileSelectionCanceled[] =
"File selection was canceled."; "File selection was canceled.";
const char kNoSuchRendererError[] = "No such renderer.";
const char kInvalidPathError[] = "Invalid path."; const char kInvalidPathError[] = "Invalid path.";
const char kManifestKeyIsRequiredError[] = const char kManifestKeyIsRequiredError[] =
"The 'manifestKey' argument is required for manifest files."; "The 'manifestKey' argument is required for manifest files.";
const char kNoSuchRendererError[] = "Could not find the renderer.";
const char kUnpackedAppsFolder[] = "apps_target"; const char kUnpackedAppsFolder[] = "apps_target";
const char kManifestFile[] = "manifest.json"; const char kManifestFile[] = "manifest.json";
...@@ -850,39 +850,54 @@ DeveloperPrivateShowPermissionsDialogFunction:: ...@@ -850,39 +850,54 @@ DeveloperPrivateShowPermissionsDialogFunction::
DeveloperPrivateShowPermissionsDialogFunction:: DeveloperPrivateShowPermissionsDialogFunction::
~DeveloperPrivateShowPermissionsDialogFunction() {} ~DeveloperPrivateShowPermissionsDialogFunction() {}
bool DeveloperPrivateInspectFunction::RunSync() { ExtensionFunction::ResponseAction DeveloperPrivateInspectFunction::Run() {
scoped_ptr<developer::Inspect::Params> params( scoped_ptr<developer::Inspect::Params> params(
developer::Inspect::Params::Create(*args_)); developer::Inspect::Params::Create(*args_));
EXTENSION_FUNCTION_VALIDATE(params.get() != NULL); EXTENSION_FUNCTION_VALIDATE(params);
const developer::InspectOptions& options = params->options; const developer::InspectOptions& options = params->options;
int render_process_id; int render_process_id = 0;
base::StringToInt(options.render_process_id, &render_process_id); if (options.render_process_id.as_string &&
!base::StringToInt(*options.render_process_id.as_string,
&render_process_id)) {
return RespondNow(Error(kNoSuchRendererError));
} else {
render_process_id = *options.render_process_id.as_integer;
}
int render_view_id = 0;
if (options.render_view_id.as_string &&
!base::StringToInt(*options.render_view_id.as_string, &render_view_id)) {
return RespondNow(Error(kNoSuchRendererError));
} else {
render_view_id = *options.render_view_id.as_integer;
}
if (render_process_id == -1) { if (render_process_id == -1) {
// This is a lazy background page. Identify if it is a normal // This is a lazy background page.
// or incognito background page.
const Extension* extension = ExtensionRegistry::Get( const Extension* extension = ExtensionRegistry::Get(
GetProfile())->enabled_extensions().GetByID(options.extension_id); browser_context())->enabled_extensions().GetByID(options.extension_id);
DCHECK(extension); if (!extension)
// Wakes up the background page and opens the inspect window. return RespondNow(Error(kNoSuchExtensionError));
devtools_util::InspectBackgroundPage(extension, GetProfile());
return false; Profile* profile = Profile::FromBrowserContext(browser_context());
if (options.incognito)
profile = profile->GetOffTheRecordProfile();
// Wakes up the background page and opens the inspect window.
devtools_util::InspectBackgroundPage(extension, profile);
return RespondNow(NoArguments());
} }
int render_view_id;
base::StringToInt(options.render_view_id, &render_view_id);
content::RenderViewHost* host = content::RenderViewHost::FromID( content::RenderViewHost* host = content::RenderViewHost::FromID(
render_process_id, render_view_id); render_process_id, render_view_id);
if (!host || !content::WebContents::FromRenderViewHost(host)) { if (!host || !content::WebContents::FromRenderViewHost(host))
// This can happen if the host has gone away since the page was displayed. return RespondNow(Error(kNoSuchRendererError));
return false;
}
DevToolsWindow::OpenDevToolsWindow( DevToolsWindow::OpenDevToolsWindow(
content::WebContents::FromRenderViewHost(host)); content::WebContents::FromRenderViewHost(host));
return true; return RespondNow(NoArguments());
} }
DeveloperPrivateInspectFunction::~DeveloperPrivateInspectFunction() {} DeveloperPrivateInspectFunction::~DeveloperPrivateInspectFunction() {}
......
...@@ -228,7 +228,7 @@ class DeveloperPrivateGetItemsInfoFunction ...@@ -228,7 +228,7 @@ class DeveloperPrivateGetItemsInfoFunction
bool generated_background_page); bool generated_background_page);
}; };
class DeveloperPrivateInspectFunction : public ChromeSyncExtensionFunction { class DeveloperPrivateInspectFunction : public UIThreadExtensionFunction {
public: public:
DECLARE_EXTENSION_FUNCTION("developerPrivate.inspect", DECLARE_EXTENSION_FUNCTION("developerPrivate.inspect",
DEVELOPERPRIVATE_INSPECT) DEVELOPERPRIVATE_INSPECT)
...@@ -237,7 +237,7 @@ class DeveloperPrivateInspectFunction : public ChromeSyncExtensionFunction { ...@@ -237,7 +237,7 @@ class DeveloperPrivateInspectFunction : public ChromeSyncExtensionFunction {
~DeveloperPrivateInspectFunction() override; ~DeveloperPrivateInspectFunction() override;
// ExtensionFunction: // ExtensionFunction:
bool RunSync() override; ResponseAction Run() override;
}; };
class DeveloperPrivateAllowFileAccessFunction class DeveloperPrivateAllowFileAccessFunction
......
...@@ -730,13 +730,12 @@ cr.define('extensions', function() { ...@@ -730,13 +730,12 @@ cr.define('extensions', function() {
' ' + loadTimeData.getString('viewInactive') : ''); ' ' + loadTimeData.getString('viewInactive') : '');
link.textContent = label; link.textContent = label;
link.clickHandler = function(e) { link.clickHandler = function(e) {
// TODO(estade): remove conversion to string? chrome.developerPrivate.inspect({
chrome.send('extensionSettingsInspect', [ extension_id: extension.id,
String(extension.id), render_process_id: view.renderProcessId,
String(view.renderProcessId), render_view_id: view.renderViewId,
String(view.renderViewId), incognito: view.incognito
view.incognito });
]);
}; };
link.addEventListener('click', link.clickHandler); link.addEventListener('click', link.clickHandler);
......
...@@ -22,11 +22,9 @@ ...@@ -22,11 +22,9 @@
#include "chrome/browser/background/background_contents.h" #include "chrome/browser/background/background_contents.h"
#include "chrome/browser/browser_process.h" #include "chrome/browser/browser_process.h"
#include "chrome/browser/chrome_notification_types.h" #include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/devtools/devtools_window.h"
#include "chrome/browser/extensions/api/extension_action/extension_action_api.h" #include "chrome/browser/extensions/api/extension_action/extension_action_api.h"
#include "chrome/browser/extensions/component_loader.h" #include "chrome/browser/extensions/component_loader.h"
#include "chrome/browser/extensions/crx_installer.h" #include "chrome/browser/extensions/crx_installer.h"
#include "chrome/browser/extensions/devtools_util.h"
#include "chrome/browser/extensions/error_console/error_console.h" #include "chrome/browser/extensions/error_console/error_console.h"
#include "chrome/browser/extensions/extension_action_manager.h" #include "chrome/browser/extensions/extension_action_manager.h"
#include "chrome/browser/extensions/extension_error_reporter.h" #include "chrome/browser/extensions/extension_error_reporter.h"
...@@ -731,9 +729,6 @@ void ExtensionSettingsHandler::RegisterMessages() { ...@@ -731,9 +729,6 @@ void ExtensionSettingsHandler::RegisterMessages() {
web_ui()->RegisterMessageCallback("extensionSettingsToggleDeveloperMode", web_ui()->RegisterMessageCallback("extensionSettingsToggleDeveloperMode",
base::Bind(&ExtensionSettingsHandler::HandleToggleDeveloperMode, base::Bind(&ExtensionSettingsHandler::HandleToggleDeveloperMode,
AsWeakPtr())); AsWeakPtr()));
web_ui()->RegisterMessageCallback("extensionSettingsInspect",
base::Bind(&ExtensionSettingsHandler::HandleInspectMessage,
AsWeakPtr()));
web_ui()->RegisterMessageCallback("extensionSettingsLaunch", web_ui()->RegisterMessageCallback("extensionSettingsLaunch",
base::Bind(&ExtensionSettingsHandler::HandleLaunchMessage, base::Bind(&ExtensionSettingsHandler::HandleLaunchMessage,
AsWeakPtr())); AsWeakPtr()));
...@@ -994,45 +989,6 @@ void ExtensionSettingsHandler::HandleToggleDeveloperMode( ...@@ -994,45 +989,6 @@ void ExtensionSettingsHandler::HandleToggleDeveloperMode(
developer_mode_on); developer_mode_on);
} }
void ExtensionSettingsHandler::HandleInspectMessage(
const base::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;
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.
Profile* profile = Profile::FromWebUI(web_ui());
const Extension* extension =
ExtensionRegistry::Get(profile)->enabled_extensions().GetByID(
extension_id);
DCHECK(extension);
if (incognito)
profile = profile->GetOffTheRecordProfile();
devtools_util::InspectBackgroundPage(extension, profile);
return;
}
RenderViewHost* host = RenderViewHost::FromID(render_process_id,
render_view_id);
if (!host || !WebContents::FromRenderViewHost(host)) {
// This can happen if the host has gone away since the page was displayed.
return;
}
DevToolsWindow::OpenDevToolsWindow(WebContents::FromRenderViewHost(host));
}
void ExtensionSettingsHandler::HandleLaunchMessage( void ExtensionSettingsHandler::HandleLaunchMessage(
const base::ListValue* args) { const base::ListValue* args) {
CHECK_EQ(1U, args->GetSize()); CHECK_EQ(1U, args->GetSize());
......
...@@ -151,9 +151,6 @@ class ExtensionSettingsHandler ...@@ -151,9 +151,6 @@ class ExtensionSettingsHandler
// Callback for "toggleDeveloperMode" message. // Callback for "toggleDeveloperMode" message.
void HandleToggleDeveloperMode(const base::ListValue* args); void HandleToggleDeveloperMode(const base::ListValue* args);
// Callback for "inspect" message.
void HandleInspectMessage(const base::ListValue* args);
// Callback for "launch" message. // Callback for "launch" message.
void HandleLaunchMessage(const base::ListValue* args); void HandleLaunchMessage(const base::ListValue* args);
......
...@@ -68,10 +68,11 @@ namespace developerPrivate { ...@@ -68,10 +68,11 @@ namespace developerPrivate {
ItemInspectView[] views; ItemInspectView[] views;
}; };
// TODO(devlin): Combine inspect and openDevTools?
dictionary InspectOptions { dictionary InspectOptions {
DOMString extension_id; DOMString extension_id;
DOMString render_process_id; (DOMString or long) render_process_id;
DOMString render_view_id; (DOMString or long) render_view_id;
boolean incognito; boolean incognito;
}; };
......
...@@ -67,8 +67,8 @@ var ItemInfo; ...@@ -67,8 +67,8 @@ var ItemInfo;
/** /**
* @typedef {{ * @typedef {{
* extension_id: string, * extension_id: string,
* render_process_id: string, * render_process_id: (string|number),
* render_view_id: string, * render_view_id: (string|number),
* incognito: boolean * incognito: boolean
* }} * }}
*/ */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment