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(
namespace ChoosePath = api::developer_private::ChoosePath;
namespace GetItemsInfo = api::developer_private::GetItemsInfo;
namespace Inspect = api::developer_private::Inspect;
namespace PackDirectory = api::developer_private::PackDirectory;
namespace Reload = api::developer_private::Reload;
......@@ -612,58 +611,6 @@ void DeveloperPrivateShowPermissionsDialogFunction::Finish() {
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()
: fail_quietly_(false) {
}
......@@ -1202,9 +1149,27 @@ DeveloperPrivateOpenDevToolsFunction::Run() {
EXTENSION_FUNCTION_VALIDATE(params);
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::FromID(properties.render_process_id,
properties.render_view_id);
content::WebContents* web_contents =
rvh ? content::WebContents::FromRenderViewHost(rvh) : nullptr;
// It's possible that the render view was closed since we last updated the
......
......@@ -226,18 +226,6 @@ class DeveloperPrivateGetExtensionInfoFunction
ResponseAction Run() override;
};
class DeveloperPrivateInspectFunction : public UIThreadExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("developerPrivate.inspect",
DEVELOPERPRIVATE_INSPECT)
protected:
~DeveloperPrivateInspectFunction() override;
// ExtensionFunction:
ResponseAction Run() override;
};
class DeveloperPrivateUpdateExtensionConfigurationFunction
: public DeveloperPrivateAPIFunction {
public:
......
......@@ -759,10 +759,10 @@ cr.define('extensions', function() {
' ' + loadTimeData.getString('viewInactive') : '');
link.textContent = label;
link.clickHandler = function(e) {
chrome.developerPrivate.inspect({
extension_id: extension.id,
render_process_id: view.renderProcessId,
render_view_id: view.renderViewId,
chrome.developerPrivate.openDevTools({
extensionId: extension.id,
renderProcessId: view.renderProcessId,
renderViewId: view.renderViewId,
incognito: view.incognito
});
};
......
......@@ -29,6 +29,14 @@ namespace developerPrivate {
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 {
DOMString message;
};
......@@ -218,14 +226,6 @@ namespace developerPrivate {
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 {
DOMString extensionId;
boolean? fileAccess;
......@@ -341,12 +341,18 @@ namespace developerPrivate {
};
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.
long renderViewId;
// The ID of the process in which the error occurred.
long renderProcessId;
boolean? incognito;
// The URL in which the error occurred.
DOMString? url;
......@@ -401,11 +407,6 @@ namespace developerPrivate {
static void showPermissionsDialog(DOMString extensionId,
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.
// |extensionId| : The id of the extension to reload.
// |options| : Additional configuration parameters.
......@@ -459,7 +460,18 @@ namespace developerPrivate {
RequestFileSourceCallback callback);
// 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 {
......
......@@ -26,15 +26,38 @@ binding.registerCustomHook(function(bindingsAPI) {
// TODO(devlin): Migrate callers off developerPrivate.enable.
bindingsAPI.compiledApi.enable = chrome.management.setEnabled;
bindingsAPI.compiledApi.allowFileAccess = function(id, allow, callback) {
apiFunctions.setHandleRequest('allowFileAccess',
function(id, allow, callback) {
chrome.developerPrivate.updateExtensionConfiguration(
{extensionId: id, fileAccess: allow}, callback);
};
});
bindingsAPI.compiledApi.allowIncognito = function(id, allow, callback) {
apiFunctions.setHandleRequest('allowIncognito',
function(id, allow, callback) {
chrome.developerPrivate.updateExtensionConfiguration(
{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();
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