mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-28 15:23:51 +00:00
Bug 1291737 - implements devtools.inspectedWindow.tabId. r=kmag
MozReview-Commit-ID: L60Ivfl8dVG --HG-- extra : rebase_source : ca1b52b791fd2cbf7302ed7c110998b7d9d6ad27
This commit is contained in:
parent
e9119d4272
commit
ad2ebb3255
@ -0,0 +1,22 @@
|
||||
/* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */
|
||||
/* vim: set sts=2 sw=2 et tw=80: */
|
||||
"use strict";
|
||||
|
||||
extensions.registerSchemaAPI("devtools.inspectedWindow", "devtools_child", context => {
|
||||
// `devtoolsToolboxInfo` is received from the child process when the root devtools view
|
||||
// has been created, and every sub-frame of that top level devtools frame will
|
||||
// receive the same information when the context has been created from the
|
||||
// `ExtensionChild.createExtensionContext` method.
|
||||
let tabId = (context.devtoolsToolboxInfo &&
|
||||
context.devtoolsToolboxInfo.inspectedWindowTabId);
|
||||
|
||||
return {
|
||||
devtools: {
|
||||
inspectedWindow: {
|
||||
get tabId() {
|
||||
return tabId;
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
});
|
@ -15,6 +15,9 @@ category webextension-scripts theme chrome://browser/content/ext-theme.js
|
||||
category webextension-scripts utils chrome://browser/content/ext-utils.js
|
||||
category webextension-scripts windows chrome://browser/content/ext-windows.js
|
||||
|
||||
# scripts specific for devtools extension contexts.
|
||||
category webextension-scripts-devtools devtools-inspectedWindow chrome://browser/content/ext-c-devtools-inspectedWindow.js
|
||||
|
||||
# scripts that must run in the same process as addon code.
|
||||
category webextension-scripts-addon contextMenus chrome://browser/content/ext-c-contextMenus.js
|
||||
category webextension-scripts-addon omnibox chrome://browser/content/ext-c-omnibox.js
|
||||
@ -28,6 +31,7 @@ category webextension-schemas commands chrome://browser/content/schemas/commands
|
||||
category webextension-schemas context_menus chrome://browser/content/schemas/context_menus.json
|
||||
category webextension-schemas context_menus_internal chrome://browser/content/schemas/context_menus_internal.json
|
||||
category webextension-schemas devtools chrome://browser/content/schemas/devtools.json
|
||||
category webextension-schemas devtools_inspected_window chrome://browser/content/schemas/devtools_inspected_window.json
|
||||
category webextension-schemas history chrome://browser/content/schemas/history.json
|
||||
category webextension-schemas omnibox chrome://browser/content/schemas/omnibox.json
|
||||
category webextension-schemas page_action chrome://browser/content/schemas/page_action.json
|
||||
|
@ -28,5 +28,6 @@ browser.jar:
|
||||
content/browser/ext-utils.js
|
||||
content/browser/ext-windows.js
|
||||
content/browser/ext-c-contextMenus.js
|
||||
content/browser/ext-c-devtools-inspectedWindow.js
|
||||
content/browser/ext-c-omnibox.js
|
||||
content/browser/ext-c-tabs.js
|
||||
|
@ -0,0 +1,273 @@
|
||||
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
[
|
||||
{
|
||||
"namespace": "devtools.inspectedWindow",
|
||||
"allowedContexts": ["devtools", "devtools_only"],
|
||||
"defaultContexts": ["devtools", "devtools_only"],
|
||||
"description": "Use the <code>chrome.devtools.inspectedWindow</code> API to interact with the inspected window: obtain the tab ID for the inspected page, evaluate the code in the context of the inspected window, reload the page, or obtain the list of resources within the page.",
|
||||
"nocompile": true,
|
||||
"types": [
|
||||
{
|
||||
"id": "Resource",
|
||||
"type": "object",
|
||||
"description": "A resource within the inspected page, such as a document, a script, or an image.",
|
||||
"properties": {
|
||||
"url": {
|
||||
"type": "string",
|
||||
"description": "The URL of the resource."
|
||||
}
|
||||
},
|
||||
"functions": [
|
||||
{
|
||||
"name": "getContent",
|
||||
"unsupported": true,
|
||||
"type": "function",
|
||||
"async": "callback",
|
||||
"description": "Gets the content of the resource.",
|
||||
"parameters": [
|
||||
{
|
||||
"name": "callback",
|
||||
"type": "function",
|
||||
"description": "A function that receives resource content when the request completes.",
|
||||
"parameters": [
|
||||
{
|
||||
"name": "content",
|
||||
"type": "string",
|
||||
"description": "Content of the resource (potentially encoded)."
|
||||
},
|
||||
{
|
||||
"name": "encoding",
|
||||
"type": "string",
|
||||
"description": "Empty if content is not encoded, encoding name otherwise. Currently, only base64 is supported."
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "setContent",
|
||||
"unsupported": true,
|
||||
"type": "function",
|
||||
"async": "callback",
|
||||
"description": "Sets the content of the resource.",
|
||||
"parameters": [
|
||||
{
|
||||
"name": "content",
|
||||
"type": "string",
|
||||
"description": "New content of the resource. Only resources with the text type are currently supported."
|
||||
},
|
||||
{
|
||||
"name": "commit",
|
||||
"type": "boolean",
|
||||
"description": "True if the user has finished editing the resource, and the new content of the resource should be persisted; false if this is a minor change sent in progress of the user editing the resource."
|
||||
},
|
||||
{
|
||||
"name": "callback",
|
||||
"type": "function",
|
||||
"description": "A function called upon request completion.",
|
||||
"optional": true,
|
||||
"parameters": [
|
||||
{
|
||||
"name": "error",
|
||||
"type": "object",
|
||||
"additionalProperties": {"type": "any"},
|
||||
"optional": true,
|
||||
"description": "Set to undefined if the resource content was set successfully; describes error otherwise."
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"properties": {
|
||||
"tabId": {
|
||||
"description": "The ID of the tab being inspected. This ID may be used with chrome.tabs.* API.",
|
||||
"type": "integer"
|
||||
}
|
||||
},
|
||||
"functions": [
|
||||
{
|
||||
"name": "eval",
|
||||
"unsupported": true,
|
||||
"type": "function",
|
||||
"description": "Evaluates a JavaScript expression in the context of the main frame of the inspected page. The expression must evaluate to a JSON-compliant object, otherwise an exception is thrown. The eval function can report either a DevTools-side error or a JavaScript exception that occurs during evaluation. In either case, the <code>result</code> parameter of the callback is <code>undefined</code>. In the case of a DevTools-side error, the <code>isException</code> parameter is non-null and has <code>isError</code> set to true and <code>code</code> set to an error code. In the case of a JavaScript error, <code>isException</code> is set to true and <code>value</code> is set to the string value of thrown object.",
|
||||
"async": "callback",
|
||||
"parameters": [
|
||||
{
|
||||
"name": "expression",
|
||||
"type": "string",
|
||||
"description": "An expression to evaluate."
|
||||
},
|
||||
{
|
||||
"name": "options",
|
||||
"type": "object",
|
||||
"optional": true,
|
||||
"description": "The options parameter can contain one or more options.",
|
||||
"properties": {
|
||||
"frameURL": {
|
||||
"type": "string",
|
||||
"unsupported": true,
|
||||
"optional": true,
|
||||
"description": "If specified, the expression is evaluated on the iframe whose URL matches the one specified. By default, the expression is evaluated in the top frame of the inspected page."
|
||||
},
|
||||
"useContentScriptContext": {
|
||||
"type": "boolean",
|
||||
"unsupported": true,
|
||||
"optional": true,
|
||||
"description": "Evaluate the expression in the context of the content script of the calling extension, provided that the content script is already injected into the inspected page. If not, the expression is not evaluated and the callback is invoked with the exception parameter set to an object that has the <code>isError</code> field set to true and the <code>code</code> field set to <code>E_NOTFOUND</code>."
|
||||
},
|
||||
"contextSecurityOrigin": {
|
||||
"type": "string",
|
||||
"unsupported": true,
|
||||
"optional": true,
|
||||
"description": "Evaluate the expression in the context of a content script of an extension that matches the specified origin. If given, contextSecurityOrigin overrides the 'true' setting on userContentScriptContext."
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "callback",
|
||||
"type": "function",
|
||||
"description": "A function called when evaluation completes.",
|
||||
"optional": true,
|
||||
"parameters": [
|
||||
{
|
||||
"name": "result",
|
||||
"type": "object",
|
||||
"additionalProperties": {"type": "any"},
|
||||
"description": "The result of evaluation."
|
||||
},
|
||||
{
|
||||
"name": "exceptionInfo",
|
||||
"type": "object",
|
||||
"description": "An object providing details if an exception occurred while evaluating the expression.",
|
||||
"properties": {
|
||||
"isError": {
|
||||
"type": "boolean",
|
||||
"description": "Set if the error occurred on the DevTools side before the expression is evaluated."
|
||||
},
|
||||
"code": {
|
||||
"type": "string",
|
||||
"description": "Set if the error occurred on the DevTools side before the expression is evaluated."
|
||||
},
|
||||
"description": {
|
||||
"type": "string",
|
||||
"description": "Set if the error occurred on the DevTools side before the expression is evaluated."
|
||||
},
|
||||
"details": {
|
||||
"type": "array",
|
||||
"items": { "type": "any" },
|
||||
"description": "Set if the error occurred on the DevTools side before the expression is evaluated, contains the array of the values that may be substituted into the description string to provide more information about the cause of the error."
|
||||
},
|
||||
"isException": {
|
||||
"type": "boolean",
|
||||
"description": "Set if the evaluated code produces an unhandled exception."
|
||||
},
|
||||
"value": {
|
||||
"type": "string",
|
||||
"description": "Set if the evaluated code produces an unhandled exception."
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "reload",
|
||||
"unsupported": true,
|
||||
"type": "function",
|
||||
"description": "Reloads the inspected page.",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "object",
|
||||
"name": "reloadOptions",
|
||||
"optional": true,
|
||||
"properties": {
|
||||
"ignoreCache": {
|
||||
"type": "boolean",
|
||||
"optional": true,
|
||||
"description": "When true, the loader will bypass the cache for all inspected page resources loaded before the <code>load</code> event is fired. The effect is similar to pressing Ctrl+Shift+R in the inspected window or within the Developer Tools window."
|
||||
},
|
||||
"userAgent": {
|
||||
"type": "string",
|
||||
"optional": true,
|
||||
"description": "If specified, the string will override the value of the <code>User-Agent</code> HTTP header that's sent while loading the resources of the inspected page. The string will also override the value of the <code>navigator.userAgent</code> property that's returned to any scripts that are running within the inspected page."
|
||||
},
|
||||
"injectedScript": {
|
||||
"type": "string",
|
||||
"optional": true,
|
||||
"description": "If specified, the script will be injected into every frame of the inspected page immediately upon load, before any of the frame's scripts. The script will not be injected after subsequent reloads—for example, if the user presses Ctrl+R."
|
||||
},
|
||||
"preprocessorScript": {
|
||||
"unsupported": true,
|
||||
"type": "string",
|
||||
"deprecated": "Please avoid using this parameter, it will be removed soon.",
|
||||
"optional": true,
|
||||
"description": "If specified, this script evaluates into a function that accepts three string arguments: the source to preprocess, the URL of the source, and a function name if the source is an DOM event handler. The preprocessorerScript function should return a string to be compiled by Chrome in place of the input source. In the case that the source is a DOM event handler, the returned source must compile to a single JS function."
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "getResources",
|
||||
"unsupported": true,
|
||||
"type": "function",
|
||||
"description": "Retrieves the list of resources from the inspected page.",
|
||||
"unsupported": true,
|
||||
"async": "callback",
|
||||
"parameters": [
|
||||
{
|
||||
"name": "callback",
|
||||
"type": "function",
|
||||
"description": "A function that receives the list of resources when the request completes.",
|
||||
"parameters": [
|
||||
{
|
||||
"name": "resources",
|
||||
"type": "array",
|
||||
"items": { "$ref": "Resource" },
|
||||
"description": "The resources within the page."
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"events": [
|
||||
{
|
||||
"name": "onResourceAdded",
|
||||
"unsupported": true,
|
||||
"type": "function",
|
||||
"description": "Fired when a new resource is added to the inspected page.",
|
||||
"parameters": [
|
||||
{
|
||||
"name": "resource",
|
||||
"$ref": "Resource"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "onResourceContentCommitted",
|
||||
"unsupported": true,
|
||||
"type": "function",
|
||||
"description": "Fired when a new revision of the resource is committed (e.g. user saves an edited version of the resource in the Developer Tools).",
|
||||
"parameters": [
|
||||
{
|
||||
"name": "resource",
|
||||
"$ref": "Resource"
|
||||
},
|
||||
{
|
||||
"name": "content",
|
||||
"type": "string",
|
||||
"description": "New content of the resource."
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
@ -10,6 +10,7 @@ browser.jar:
|
||||
content/browser/schemas/context_menus.json
|
||||
content/browser/schemas/context_menus_internal.json
|
||||
content/browser/schemas/devtools.json
|
||||
content/browser/schemas/devtools_inspected_window.json
|
||||
content/browser/schemas/history.json
|
||||
content/browser/schemas/omnibox.json
|
||||
content/browser/schemas/page_action.json
|
||||
|
@ -42,6 +42,7 @@ support-files =
|
||||
[browser_ext_contextMenus_uninstall.js]
|
||||
[browser_ext_contextMenus_urlPatterns.js]
|
||||
[browser_ext_currentWindow.js]
|
||||
[browser_ext_devtools_inspectedWindow.js]
|
||||
[browser_ext_devtools_page.js]
|
||||
[browser_ext_getViews.js]
|
||||
[browser_ext_incognito_views.js]
|
||||
|
@ -0,0 +1,110 @@
|
||||
/* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */
|
||||
/* vim: set sts=2 sw=2 et tw=80: */
|
||||
"use strict";
|
||||
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "gDevTools",
|
||||
"resource://devtools/client/framework/gDevTools.jsm");
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "devtools",
|
||||
"resource://devtools/shared/Loader.jsm");
|
||||
|
||||
/**
|
||||
* this test file ensures that:
|
||||
*
|
||||
* - the devtools page gets only a subset of the runtime API namespace.
|
||||
* - devtools.inspectedWindow.tabId is the same tabId that we can retrieve
|
||||
* in the background page using the tabs API namespace.
|
||||
* - devtools API is available in the devtools page sub-frames when a valid
|
||||
* extension URL has been loaded.
|
||||
*/
|
||||
add_task(function* test_devtools_inspectedWindow_tabId() {
|
||||
let tab = yield BrowserTestUtils.openNewForegroundTab(gBrowser, "http://mochi.test:8888/");
|
||||
|
||||
async function background() {
|
||||
browser.test.assertEq(undefined, browser.devtools,
|
||||
"No devtools APIs should be available in the background page");
|
||||
|
||||
const tabs = await browser.tabs.query({active: true, lastFocusedWindow: true});
|
||||
browser.test.sendMessage("current-tab-id", tabs[0].id);
|
||||
}
|
||||
|
||||
function devtools_page() {
|
||||
browser.test.assertEq(undefined, browser.runtime.getBackgroundPage,
|
||||
"The `runtime.getBackgroundPage` API method should be missing in a devtools_page context"
|
||||
);
|
||||
|
||||
try {
|
||||
let tabId = browser.devtools.inspectedWindow.tabId;
|
||||
browser.test.sendMessage("inspectedWindow-tab-id", tabId);
|
||||
} catch (err) {
|
||||
browser.test.sendMessage("inspectedWindow-tab-id", undefined);
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
function devtools_page_iframe() {
|
||||
try {
|
||||
let tabId = browser.devtools.inspectedWindow.tabId;
|
||||
browser.test.sendMessage("devtools_page_iframe.inspectedWindow-tab-id", tabId);
|
||||
} catch (err) {
|
||||
browser.test.fail(`Error: ${err} :: ${err.stack}`);
|
||||
browser.test.sendMessage("devtools_page_iframe.inspectedWindow-tab-id", undefined);
|
||||
}
|
||||
}
|
||||
|
||||
let extension = ExtensionTestUtils.loadExtension({
|
||||
background,
|
||||
manifest: {
|
||||
devtools_page: "devtools_page.html",
|
||||
},
|
||||
files: {
|
||||
"devtools_page.html": `<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
</head>
|
||||
<body>
|
||||
<iframe src="/devtools_page_iframe.html"></iframe>
|
||||
<script src="devtools_page.js"></script>
|
||||
</body>
|
||||
</html>`,
|
||||
"devtools_page.js": devtools_page,
|
||||
"devtools_page_iframe.html": `<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
</head>
|
||||
<body>
|
||||
<script src="devtools_page_iframe.js"></script>
|
||||
</body>
|
||||
</html>`,
|
||||
"devtools_page_iframe.js": devtools_page_iframe,
|
||||
},
|
||||
});
|
||||
|
||||
yield extension.startup();
|
||||
|
||||
let backgroundPageCurrentTabId = yield extension.awaitMessage("current-tab-id");
|
||||
|
||||
let target = devtools.TargetFactory.forTab(tab);
|
||||
|
||||
yield gDevTools.showToolbox(target, "webconsole");
|
||||
info("developer toolbox opened");
|
||||
|
||||
let devtoolsInspectedWindowTabId = yield extension.awaitMessage("inspectedWindow-tab-id");
|
||||
|
||||
is(devtoolsInspectedWindowTabId, backgroundPageCurrentTabId,
|
||||
"Got the expected tabId from devtool.inspectedWindow.tabId");
|
||||
|
||||
let devtoolsPageIframeTabId = yield extension.awaitMessage("devtools_page_iframe.inspectedWindow-tab-id");
|
||||
|
||||
is(devtoolsPageIframeTabId, backgroundPageCurrentTabId,
|
||||
"Got the expected tabId from devtool.inspectedWindow.tabId called in a devtool_page iframe");
|
||||
|
||||
yield gDevTools.closeToolbox(target);
|
||||
|
||||
yield target.destroy();
|
||||
|
||||
yield extension.unload();
|
||||
|
||||
yield BrowserTestUtils.removeTab(tab);
|
||||
});
|
Loading…
Reference in New Issue
Block a user