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

[Extensions] Combine developerPrivate.inspect and developerPrivate.openDevTools

Combine the two api functions developerPrivate.inspect and
developerPrivate.openDevTools, and provide a custom binding wrapper to
maintain compatability with developerPrivate.inspect.

BUG=461039

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

Cr-Commit-Position: refs/heads/master@{#321629}
parent 1f433a71
...@@ -194,7 +194,6 @@ bool UserCanModifyExtensionConfiguration( ...@@ -194,7 +194,6 @@ bool UserCanModifyExtensionConfiguration(
namespace ChoosePath = api::developer_private::ChoosePath; namespace ChoosePath = api::developer_private::ChoosePath;
namespace GetItemsInfo = api::developer_private::GetItemsInfo; namespace GetItemsInfo = api::developer_private::GetItemsInfo;
namespace Inspect = api::developer_private::Inspect;
namespace PackDirectory = api::developer_private::PackDirectory; namespace PackDirectory = api::developer_private::PackDirectory;
namespace Reload = api::developer_private::Reload; namespace Reload = api::developer_private::Reload;
...@@ -612,58 +611,6 @@ void DeveloperPrivateShowPermissionsDialogFunction::Finish() { ...@@ -612,58 +611,6 @@ void DeveloperPrivateShowPermissionsDialogFunction::Finish() {
Respond(NoArguments()); Respond(NoArguments());
} }
ExtensionFunction::ResponseAction DeveloperPrivateInspectFunction::Run() {
scoped_ptr<developer::Inspect::Params> params(
developer::Inspect::Params::Create(*args_));
EXTENSION_FUNCTION_VALIDATE(params);
const developer::InspectOptions& options = params->options;
int render_process_id = 0;
if (options.render_process_id.as_string &&
!base::StringToInt(*options.render_process_id.as_string,
&render_process_id)) {
return RespondNow(Error(kNoSuchRendererError));
} else if (options.render_process_id.as_integer) {
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 if (options.render_view_id.as_integer) {
render_view_id = *options.render_view_id.as_integer;
}
if (render_process_id == -1) {
// This is a lazy background page.
const Extension* extension = ExtensionRegistry::Get(
browser_context())->enabled_extensions().GetByID(options.extension_id);
if (!extension)
return RespondNow(Error(kNoSuchExtensionError));
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());
}
content::RenderViewHost* host = content::RenderViewHost::FromID(
render_process_id, render_view_id);
if (!host || !content::WebContents::FromRenderViewHost(host))
return RespondNow(Error(kNoSuchRendererError));
DevToolsWindow::OpenDevToolsWindow(
content::WebContents::FromRenderViewHost(host));
return RespondNow(NoArguments());
}
DeveloperPrivateInspectFunction::~DeveloperPrivateInspectFunction() {}
DeveloperPrivateLoadUnpackedFunction::DeveloperPrivateLoadUnpackedFunction() DeveloperPrivateLoadUnpackedFunction::DeveloperPrivateLoadUnpackedFunction()
: fail_quietly_(false) { : fail_quietly_(false) {
} }
...@@ -1202,9 +1149,27 @@ DeveloperPrivateOpenDevToolsFunction::Run() { ...@@ -1202,9 +1149,27 @@ DeveloperPrivateOpenDevToolsFunction::Run() {
EXTENSION_FUNCTION_VALIDATE(params); EXTENSION_FUNCTION_VALIDATE(params);
const developer::OpenDevToolsProperties& properties = params->properties; const developer::OpenDevToolsProperties& properties = params->properties;
if (properties.render_process_id == -1) {
// This is a lazy background page.
const Extension* extension = properties.extension_id ?
ExtensionRegistry::Get(browser_context())->enabled_extensions().GetByID(
*properties.extension_id) : nullptr;
if (!extension)
return RespondNow(Error(kNoSuchExtensionError));
Profile* profile = Profile::FromBrowserContext(browser_context());
if (properties.incognito && *properties.incognito)
profile = profile->GetOffTheRecordProfile();
// Wakes up the background page and opens the inspect window.
devtools_util::InspectBackgroundPage(extension, profile);
return RespondNow(NoArguments());
}
content::RenderViewHost* rvh = content::RenderViewHost* rvh =
content::RenderViewHost::FromID(properties.render_process_id, content::RenderViewHost::FromID(properties.render_process_id,
properties.render_view_id); properties.render_view_id);
content::WebContents* web_contents = content::WebContents* web_contents =
rvh ? content::WebContents::FromRenderViewHost(rvh) : nullptr; rvh ? content::WebContents::FromRenderViewHost(rvh) : nullptr;
// It's possible that the render view was closed since we last updated the // It's possible that the render view was closed since we last updated the
......
...@@ -226,18 +226,6 @@ class DeveloperPrivateGetExtensionInfoFunction ...@@ -226,18 +226,6 @@ class DeveloperPrivateGetExtensionInfoFunction
ResponseAction Run() override; ResponseAction Run() override;
}; };
class DeveloperPrivateInspectFunction : public UIThreadExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("developerPrivate.inspect",
DEVELOPERPRIVATE_INSPECT)
protected:
~DeveloperPrivateInspectFunction() override;
// ExtensionFunction:
ResponseAction Run() override;
};
class DeveloperPrivateUpdateExtensionConfigurationFunction class DeveloperPrivateUpdateExtensionConfigurationFunction
: public DeveloperPrivateAPIFunction { : public DeveloperPrivateAPIFunction {
public: public:
......
...@@ -759,10 +759,10 @@ cr.define('extensions', function() { ...@@ -759,10 +759,10 @@ cr.define('extensions', function() {
' ' + loadTimeData.getString('viewInactive') : ''); ' ' + loadTimeData.getString('viewInactive') : '');
link.textContent = label; link.textContent = label;
link.clickHandler = function(e) { link.clickHandler = function(e) {
chrome.developerPrivate.inspect({ chrome.developerPrivate.openDevTools({
extension_id: extension.id, extensionId: extension.id,
render_process_id: view.renderProcessId, renderProcessId: view.renderProcessId,
render_view_id: view.renderViewId, renderViewId: view.renderViewId,
incognito: view.incognito incognito: view.incognito
}); });
}; };
......
...@@ -29,6 +29,14 @@ namespace developerPrivate { ...@@ -29,6 +29,14 @@ namespace developerPrivate {
boolean generatedBackgroundPage; boolean generatedBackgroundPage;
}; };
// DEPRECATED: Use OpenDevTools.
dictionary InspectOptions {
DOMString extension_id;
(DOMString or long) render_process_id;
(DOMString or long) render_view_id;
boolean incognito;
};
dictionary InstallWarning { dictionary InstallWarning {
DOMString message; DOMString message;
}; };
...@@ -218,14 +226,6 @@ namespace developerPrivate { ...@@ -218,14 +226,6 @@ namespace developerPrivate {
boolean? includeTerminated; boolean? includeTerminated;
}; };
// TODO(devlin): Combine inspect and openDevTools?
dictionary InspectOptions {
DOMString extension_id;
(DOMString or long) render_process_id;
(DOMString or long) render_view_id;
boolean incognito;
};
dictionary ExtensionConfigurationUpdate { dictionary ExtensionConfigurationUpdate {
DOMString extensionId; DOMString extensionId;
boolean? fileAccess; boolean? fileAccess;
...@@ -341,12 +341,18 @@ namespace developerPrivate { ...@@ -341,12 +341,18 @@ namespace developerPrivate {
}; };
dictionary OpenDevToolsProperties { dictionary OpenDevToolsProperties {
// The ID of the extension. This is only needed if opening the background
// page (where renderViewId and renderProcessId are -1).
DOMString? extensionId;
// The ID of the render view in which the error occurred. // The ID of the render view in which the error occurred.
long renderViewId; long renderViewId;
// The ID of the process in which the error occurred. // The ID of the process in which the error occurred.
long renderProcessId; long renderProcessId;
boolean? incognito;
// The URL in which the error occurred. // The URL in which the error occurred.
DOMString? url; DOMString? url;
...@@ -401,11 +407,6 @@ namespace developerPrivate { ...@@ -401,11 +407,6 @@ namespace developerPrivate {
static void showPermissionsDialog(DOMString extensionId, static void showPermissionsDialog(DOMString extensionId,
optional VoidCallback callback); optional VoidCallback callback);
// Opens a developer tools inspection window.
// |options| : The details about the inspection.
static void inspect(InspectOptions options,
optional VoidCallback callback);
// Reloads a given extension. // Reloads a given extension.
// |extensionId| : The id of the extension to reload. // |extensionId| : The id of the extension to reload.
// |options| : Additional configuration parameters. // |options| : Additional configuration parameters.
...@@ -459,7 +460,18 @@ namespace developerPrivate { ...@@ -459,7 +460,18 @@ namespace developerPrivate {
RequestFileSourceCallback callback); RequestFileSourceCallback callback);
// Open the developer tools to focus on a particular error. // Open the developer tools to focus on a particular error.
static void openDevTools(OpenDevToolsProperties properties); static void openDevTools(OpenDevToolsProperties properties,
optional VoidCallback callback);
// Deprecated api methods, retained for compatability.
[nocompile] static void allowIncognito(DOMString extensionId,
boolean allow,
optional VoidCallback callback);
[nocompile] static void allowFileAccess(DOMString extensionId,
boolean allow,
optional VoidCallback callback);
[nocompile] static void inspect(InspectOptions options,
optional VoidCallback callback);
}; };
interface Events { interface Events {
......
...@@ -26,15 +26,38 @@ binding.registerCustomHook(function(bindingsAPI) { ...@@ -26,15 +26,38 @@ binding.registerCustomHook(function(bindingsAPI) {
// TODO(devlin): Migrate callers off developerPrivate.enable. // TODO(devlin): Migrate callers off developerPrivate.enable.
bindingsAPI.compiledApi.enable = chrome.management.setEnabled; bindingsAPI.compiledApi.enable = chrome.management.setEnabled;
bindingsAPI.compiledApi.allowFileAccess = function(id, allow, callback) { apiFunctions.setHandleRequest('allowFileAccess',
function(id, allow, callback) {
chrome.developerPrivate.updateExtensionConfiguration( chrome.developerPrivate.updateExtensionConfiguration(
{extensionId: id, fileAccess: allow}, callback); {extensionId: id, fileAccess: allow}, callback);
}; });
bindingsAPI.compiledApi.allowIncognito = function(id, allow, callback) { apiFunctions.setHandleRequest('allowIncognito',
function(id, allow, callback) {
chrome.developerPrivate.updateExtensionConfiguration( chrome.developerPrivate.updateExtensionConfiguration(
{extensionId: id, incognitoAccess: allow}, callback); {extensionId: id, incognitoAccess: allow}, callback);
}; });
apiFunctions.setHandleRequest('inspect', function(options, callback) {
var renderViewId = options.render_view_id;
if (typeof renderViewId == 'string') {
renderViewId = parseInt(renderViewId);
if (isNaN(renderViewId))
throw new Error('Invalid value for render_view_id');
}
var renderProcessId = options.render_process_id;
if (typeof renderProcessId == 'string') {
renderProcessId = parseInt(renderProcessId);
if (isNaN(renderProcessId))
throw new Error('Invalid value for render_process_id');
}
chrome.developerPrivate.openDevTools({
extensionId: options.extension_id,
renderProcessId: renderProcessId,
renderViewId: renderViewId,
incognito: options.incognito
}, callback);
});
}); });
exports.binding = binding.generate(); exports.binding = binding.generate();
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