2018-07-02 18:08:02 +03:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
var Services = require("Services");
|
|
|
|
loader.lazyRequireGetter(
|
|
|
|
this,
|
|
|
|
"Utils",
|
|
|
|
"devtools/client/webconsole/utils",
|
2019-02-15 11:16:37 +03:00
|
|
|
true
|
|
|
|
);
|
|
|
|
loader.lazyRequireGetter(
|
|
|
|
this,
|
|
|
|
"WebConsoleUI",
|
|
|
|
"devtools/client/webconsole/webconsole-ui",
|
2018-07-02 18:08:02 +03:00
|
|
|
true
|
|
|
|
);
|
|
|
|
loader.lazyRequireGetter(
|
|
|
|
this,
|
|
|
|
"gDevTools",
|
|
|
|
"devtools/client/framework/devtools",
|
2019-07-05 12:24:38 +03:00
|
|
|
true
|
2018-07-02 18:08:02 +03:00
|
|
|
);
|
|
|
|
loader.lazyRequireGetter(
|
|
|
|
this,
|
|
|
|
"viewSource",
|
|
|
|
"devtools/client/shared/view-source"
|
|
|
|
);
|
|
|
|
loader.lazyRequireGetter(
|
|
|
|
this,
|
|
|
|
"openDocLink",
|
|
|
|
"devtools/client/shared/link",
|
|
|
|
true
|
2019-07-05 12:24:38 +03:00
|
|
|
);
|
2019-09-30 12:51:44 +03:00
|
|
|
loader.lazyRequireGetter(
|
|
|
|
this,
|
|
|
|
"DevToolsUtils",
|
|
|
|
"devtools/shared/DevToolsUtils"
|
|
|
|
);
|
2019-08-01 00:56:54 +03:00
|
|
|
const EventEmitter = require("devtools/shared/event-emitter");
|
2019-10-03 01:50:25 +03:00
|
|
|
const Telemetry = require("devtools/client/shared/telemetry");
|
2018-07-02 18:08:02 +03:00
|
|
|
|
|
|
|
var gHudId = 0;
|
2019-03-05 17:10:19 +03:00
|
|
|
const isMacOS = Services.appinfo.OS === "Darwin";
|
2018-07-02 18:08:02 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A WebConsole instance is an interactive console initialized *per target*
|
|
|
|
* that displays console log data as well as provides an interactive terminal to
|
|
|
|
* manipulate the target's document content.
|
|
|
|
*
|
|
|
|
* This object only wraps the iframe that holds the Web Console UI. This is
|
|
|
|
* meant to be an integration point between the Firefox UI and the Web Console
|
|
|
|
* UI and features.
|
|
|
|
*/
|
2019-02-27 13:05:51 +03:00
|
|
|
class WebConsole {
|
|
|
|
/*
|
|
|
|
* @constructor
|
2019-08-22 11:09:59 +03:00
|
|
|
* @param object toolbox
|
|
|
|
* The toolbox where the web console is displayed.
|
2019-02-27 13:05:51 +03:00
|
|
|
* @param nsIDOMWindow iframeWindow
|
|
|
|
* The window where the web console UI is already loaded.
|
|
|
|
* @param nsIDOMWindow chromeWindow
|
|
|
|
* The window of the web console owner.
|
|
|
|
* @param bool isBrowserConsole
|
|
|
|
*/
|
2019-08-27 20:41:29 +03:00
|
|
|
constructor(toolbox, iframeWindow, chromeWindow, isBrowserConsole = false) {
|
2019-08-22 11:09:59 +03:00
|
|
|
this.toolbox = toolbox;
|
2019-02-27 13:05:51 +03:00
|
|
|
this.iframeWindow = iframeWindow;
|
|
|
|
this.chromeWindow = chromeWindow;
|
|
|
|
this.hudId = "hud_" + ++gHudId;
|
2019-09-30 12:51:44 +03:00
|
|
|
this.browserWindow = DevToolsUtils.getTopWindow(this.chromeWindow);
|
2019-07-29 11:44:08 +03:00
|
|
|
this.isBrowserConsole = isBrowserConsole;
|
2019-10-03 01:50:25 +03:00
|
|
|
this.telemetry = new Telemetry();
|
2019-02-27 13:05:51 +03:00
|
|
|
|
|
|
|
const element = this.browserWindow.document.documentElement;
|
|
|
|
if (element.getAttribute("windowtype") != gDevTools.chromeWindowType) {
|
2019-08-01 00:56:54 +03:00
|
|
|
this.browserWindow = Services.wm.getMostRecentWindow(
|
|
|
|
gDevTools.chromeWindowType
|
|
|
|
);
|
2019-02-27 13:05:51 +03:00
|
|
|
}
|
|
|
|
this.ui = new WebConsoleUI(this);
|
|
|
|
this._destroyer = null;
|
2019-08-01 00:56:54 +03:00
|
|
|
|
|
|
|
EventEmitter.decorate(this);
|
2018-07-02 18:08:02 +03:00
|
|
|
}
|
|
|
|
|
2019-10-03 01:50:25 +03:00
|
|
|
recordEvent(event, extra = {}) {
|
|
|
|
this.telemetry.recordEvent(event, "webconsole", null, {
|
|
|
|
session_id: (this.toolbox && this.toolbox.sessionId) || -1,
|
|
|
|
...extra,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-08-22 11:10:13 +03:00
|
|
|
get currentTarget() {
|
2019-08-22 11:09:59 +03:00
|
|
|
return this.toolbox.target;
|
|
|
|
}
|
|
|
|
|
2018-07-02 18:08:02 +03:00
|
|
|
/**
|
|
|
|
* Getter for the window that can provide various utilities that the web
|
|
|
|
* console makes use of, like opening links, managing popups, etc. In
|
|
|
|
* most cases, this will be |this.browserWindow|, but in some uses (such as
|
|
|
|
* the Browser Toolbox), there is no browser window, so an alternative window
|
|
|
|
* hosts the utilities there.
|
|
|
|
* @type nsIDOMWindow
|
|
|
|
*/
|
|
|
|
get chromeUtilsWindow() {
|
|
|
|
if (this.browserWindow) {
|
|
|
|
return this.browserWindow;
|
|
|
|
}
|
2019-09-30 12:51:44 +03:00
|
|
|
return DevToolsUtils.getTopWindow(this.chromeWindow);
|
2019-02-27 13:05:51 +03:00
|
|
|
}
|
2018-07-02 18:08:02 +03:00
|
|
|
|
|
|
|
get gViewSourceUtils() {
|
|
|
|
return this.chromeUtilsWindow.gViewSourceUtils;
|
2019-02-27 13:05:51 +03:00
|
|
|
}
|
2018-07-02 18:08:02 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Initialize the Web Console instance.
|
|
|
|
*
|
|
|
|
* @return object
|
|
|
|
* A promise for the initialization.
|
|
|
|
*/
|
|
|
|
init() {
|
2019-08-01 00:56:45 +03:00
|
|
|
return this.ui.init();
|
2019-02-27 13:05:51 +03:00
|
|
|
}
|
2018-07-02 18:08:02 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The JSTerm object that manages the console's input.
|
|
|
|
* @see webconsole.js::JSTerm
|
|
|
|
* @type object
|
|
|
|
*/
|
|
|
|
get jsterm() {
|
|
|
|
return this.ui ? this.ui.jsterm : null;
|
2019-02-27 13:05:51 +03:00
|
|
|
}
|
2019-02-26 17:42:13 +03:00
|
|
|
|
2019-10-03 01:50:25 +03:00
|
|
|
canRewind() {
|
2019-10-09 00:18:21 +03:00
|
|
|
const traits = this.currentTarget && this.currentTarget.traits;
|
2019-10-03 01:50:25 +03:00
|
|
|
return traits && traits.canRewind;
|
|
|
|
}
|
|
|
|
|
2019-02-27 13:09:35 +03:00
|
|
|
/**
|
|
|
|
* Get the value from the input field.
|
|
|
|
* @returns {String|null} returns null if there's no input.
|
|
|
|
*/
|
|
|
|
getInputValue() {
|
|
|
|
if (!this.jsterm) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.jsterm._getValue();
|
|
|
|
}
|
|
|
|
|
2019-10-03 01:50:25 +03:00
|
|
|
inputHasSelection() {
|
|
|
|
const { editor } = this.jsterm || {};
|
|
|
|
return editor && !!editor.getSelection();
|
|
|
|
}
|
|
|
|
|
|
|
|
getInputSelection() {
|
|
|
|
if (!this.jsterm || !this.jsterm.editor) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return this.jsterm.editor.getSelection();
|
|
|
|
}
|
|
|
|
|
2019-02-27 13:09:35 +03:00
|
|
|
/**
|
|
|
|
* Sets the value of the input field (command line)
|
|
|
|
*
|
|
|
|
* @param {String} newValue: The new value to set.
|
|
|
|
*/
|
|
|
|
setInputValue(newValue) {
|
|
|
|
if (!this.jsterm) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.jsterm._setValue(newValue);
|
|
|
|
}
|
|
|
|
|
2019-10-03 01:50:25 +03:00
|
|
|
focusInput() {
|
|
|
|
return this.jsterm && this.jsterm.focus();
|
|
|
|
}
|
|
|
|
|
2018-07-02 18:08:02 +03:00
|
|
|
/**
|
|
|
|
* Open a link in a new tab.
|
|
|
|
*
|
|
|
|
* @param string link
|
|
|
|
* The URL you want to open in a new tab.
|
|
|
|
*/
|
2019-03-05 17:10:19 +03:00
|
|
|
openLink(link, e = {}) {
|
|
|
|
openDocLink(link, {
|
|
|
|
relatedToCurrent: true,
|
|
|
|
inBackground: isMacOS ? e.metaKey : e.ctrlKey,
|
|
|
|
});
|
2019-05-27 09:24:11 +03:00
|
|
|
if (e && typeof e.stopPropagation === "function") {
|
|
|
|
e.stopPropagation();
|
|
|
|
}
|
2019-02-27 13:05:51 +03:00
|
|
|
}
|
2018-07-02 18:08:02 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Open a link in Firefox's view source.
|
|
|
|
*
|
|
|
|
* @param string sourceURL
|
|
|
|
* The URL of the file.
|
|
|
|
* @param integer sourceLine
|
|
|
|
* The line number which should be highlighted.
|
|
|
|
*/
|
|
|
|
viewSource(sourceURL, sourceLine) {
|
|
|
|
this.gViewSourceUtils.viewSource({
|
|
|
|
URL: sourceURL,
|
|
|
|
lineNumber: sourceLine || 0,
|
|
|
|
});
|
2019-02-27 13:05:51 +03:00
|
|
|
}
|
2018-07-02 18:08:02 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Tries to open a Stylesheet file related to the web page for the web console
|
|
|
|
* instance in the Style Editor. If the file is not found, it is opened in
|
|
|
|
* source view instead.
|
|
|
|
*
|
|
|
|
* Manually handle the case where toolbox does not exist (Browser Console).
|
|
|
|
*
|
|
|
|
* @param string sourceURL
|
|
|
|
* The URL of the file.
|
|
|
|
* @param integer sourceLine
|
|
|
|
* The line number which you want to place the caret.
|
|
|
|
*/
|
|
|
|
viewSourceInStyleEditor(sourceURL, sourceLine) {
|
2019-08-22 11:10:06 +03:00
|
|
|
const toolbox = this.toolbox;
|
2018-07-02 18:08:02 +03:00
|
|
|
if (!toolbox) {
|
|
|
|
this.viewSource(sourceURL, sourceLine);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
toolbox.viewSourceInStyleEditor(sourceURL, sourceLine);
|
2019-02-27 13:05:51 +03:00
|
|
|
}
|
2018-07-02 18:08:02 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Tries to open a JavaScript file related to the web page for the web console
|
|
|
|
* instance in the Script Debugger. If the file is not found, it is opened in
|
|
|
|
* source view instead.
|
|
|
|
*
|
|
|
|
* Manually handle the case where toolbox does not exist (Browser Console).
|
|
|
|
*
|
|
|
|
* @param string sourceURL
|
|
|
|
* The URL of the file.
|
|
|
|
* @param integer sourceLine
|
|
|
|
* The line number which you want to place the caret.
|
2019-03-28 16:52:28 +03:00
|
|
|
* @param integer sourceColumn
|
|
|
|
* The column number which you want to place the caret.
|
2018-07-02 18:08:02 +03:00
|
|
|
*/
|
2019-10-03 01:50:25 +03:00
|
|
|
async viewSourceInDebugger(sourceURL, sourceLine, sourceColumn) {
|
2019-08-22 11:10:06 +03:00
|
|
|
const toolbox = this.toolbox;
|
2018-07-02 18:08:02 +03:00
|
|
|
if (!toolbox) {
|
2019-03-28 16:52:28 +03:00
|
|
|
this.viewSource(sourceURL, sourceLine, sourceColumn);
|
2018-07-02 18:08:02 +03:00
|
|
|
return;
|
|
|
|
}
|
2019-10-03 01:50:25 +03:00
|
|
|
|
|
|
|
await toolbox.viewSourceInDebugger(sourceURL, sourceLine, sourceColumn);
|
|
|
|
this.ui.emit("source-in-debugger-opened");
|
2019-02-27 13:05:51 +03:00
|
|
|
}
|
2018-07-02 18:08:02 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Tries to open a JavaScript file related to the web page for the web console
|
|
|
|
* instance in the corresponding Scratchpad.
|
|
|
|
*
|
|
|
|
* @param string sourceURL
|
|
|
|
* The URL of the file which corresponds to a Scratchpad id.
|
|
|
|
*/
|
|
|
|
viewSourceInScratchpad(sourceURL, sourceLine) {
|
|
|
|
viewSource.viewSourceInScratchpad(sourceURL, sourceLine);
|
2019-02-27 13:05:51 +03:00
|
|
|
}
|
2018-07-02 18:08:02 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve information about the JavaScript debugger's stackframes list. This
|
|
|
|
* is used to allow the Web Console to evaluate code in the selected
|
|
|
|
* stackframe.
|
|
|
|
*
|
|
|
|
* @return object|null
|
|
|
|
* An object which holds:
|
2019-07-11 12:45:32 +03:00
|
|
|
* - frames: the active ThreadFront.cachedFrames array.
|
2018-07-02 18:08:02 +03:00
|
|
|
* - selected: depth/index of the selected stackframe in the debugger
|
|
|
|
* UI.
|
|
|
|
* If the debugger is not open or if it's not paused, then |null| is
|
|
|
|
* returned.
|
|
|
|
*/
|
|
|
|
getDebuggerFrames() {
|
2019-08-22 11:10:06 +03:00
|
|
|
const toolbox = this.toolbox;
|
2018-07-02 18:08:02 +03:00
|
|
|
if (!toolbox) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
const panel = toolbox.getPanel("jsdebugger");
|
|
|
|
|
|
|
|
if (!panel) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return panel.getFrames();
|
2019-02-27 13:05:51 +03:00
|
|
|
}
|
2018-07-02 18:08:02 +03:00
|
|
|
|
Bug 1491354 - Extends top-level await mapping from debugger to toolbox; r=bgrins,jlast.
This patch makes the parser-worker available at the toolbox level.
This way, the console does not have to rely on the debugger being
open to map top-level await expression.
In order to make the worker works in the toolbox, some changes
are required (passing a window object, checking inToolbox differently).
We take this as an opportunity to *not* display the async iife result,
a promise, in the console. This is made by checking if the input was
mapped, and if so, ignoring the result we get from the server.
A couple tests are added to ensure the basic usage works as expected.
This patch should be considered as a v0 for top-level await evaluation
as there are things that are not perfect here. Since we rely on console.log
the result are treated differently from other evaluation results:
- the style is different
- the result gets added to the log cache (when restarting the console,
the results will still be displayed, but not the commands).
- the results can be filtered, although evaluation results should not
- `$_` after a top-level await evaluation returns the Promise created
by the async iife, not the result that was displayed in the console.
All those should be addressed in Bug 1410820.
Differential Revision: https://phabricator.services.mozilla.com/D6038
--HG--
extra : moz-landing-system : lando
2018-09-24 11:17:30 +03:00
|
|
|
/**
|
|
|
|
* Given an expression, returns an object containing a new expression, mapped by the
|
|
|
|
* parser worker to provide additional feature for the user (top-level await,
|
|
|
|
* original languages mapping, …).
|
|
|
|
*
|
|
|
|
* @param {String} expression: The input to maybe map.
|
|
|
|
* @returns {Object|null}
|
|
|
|
* Returns null if the input can't be mapped.
|
|
|
|
* If it can, returns an object containing the following:
|
|
|
|
* - {String} expression: The mapped expression
|
|
|
|
* - {Object} mapped: An object containing the different mapping that could
|
|
|
|
* be done and if they were applied on the input.
|
|
|
|
* At the moment, contains `await`, `bindings` and
|
|
|
|
* `originalExpression`.
|
|
|
|
*/
|
|
|
|
getMappedExpression(expression) {
|
2019-08-22 11:10:06 +03:00
|
|
|
const toolbox = this.toolbox;
|
Bug 1491354 - Extends top-level await mapping from debugger to toolbox; r=bgrins,jlast.
This patch makes the parser-worker available at the toolbox level.
This way, the console does not have to rely on the debugger being
open to map top-level await expression.
In order to make the worker works in the toolbox, some changes
are required (passing a window object, checking inToolbox differently).
We take this as an opportunity to *not* display the async iife result,
a promise, in the console. This is made by checking if the input was
mapped, and if so, ignoring the result we get from the server.
A couple tests are added to ensure the basic usage works as expected.
This patch should be considered as a v0 for top-level await evaluation
as there are things that are not perfect here. Since we rely on console.log
the result are treated differently from other evaluation results:
- the style is different
- the result gets added to the log cache (when restarting the console,
the results will still be displayed, but not the commands).
- the results can be filtered, although evaluation results should not
- `$_` after a top-level await evaluation returns the Promise created
by the async iife, not the result that was displayed in the console.
All those should be addressed in Bug 1410820.
Differential Revision: https://phabricator.services.mozilla.com/D6038
--HG--
extra : moz-landing-system : lando
2018-09-24 11:17:30 +03:00
|
|
|
|
2018-10-16 16:57:32 +03:00
|
|
|
// We need to check if the debugger is open, since it may perform a variable name
|
|
|
|
// substitution for sourcemapped script (i.e. evaluated `myVar.trim()` might need to
|
|
|
|
// be transformed into `a.trim()`).
|
|
|
|
const panel = toolbox && toolbox.getPanel("jsdebugger");
|
Bug 1491354 - Extends top-level await mapping from debugger to toolbox; r=bgrins,jlast.
This patch makes the parser-worker available at the toolbox level.
This way, the console does not have to rely on the debugger being
open to map top-level await expression.
In order to make the worker works in the toolbox, some changes
are required (passing a window object, checking inToolbox differently).
We take this as an opportunity to *not* display the async iife result,
a promise, in the console. This is made by checking if the input was
mapped, and if so, ignoring the result we get from the server.
A couple tests are added to ensure the basic usage works as expected.
This patch should be considered as a v0 for top-level await evaluation
as there are things that are not perfect here. Since we rely on console.log
the result are treated differently from other evaluation results:
- the style is different
- the result gets added to the log cache (when restarting the console,
the results will still be displayed, but not the commands).
- the results can be filtered, although evaluation results should not
- `$_` after a top-level await evaluation returns the Promise created
by the async iife, not the result that was displayed in the console.
All those should be addressed in Bug 1410820.
Differential Revision: https://phabricator.services.mozilla.com/D6038
--HG--
extra : moz-landing-system : lando
2018-09-24 11:17:30 +03:00
|
|
|
if (panel) {
|
|
|
|
return panel.getMappedExpression(expression);
|
|
|
|
}
|
2018-07-02 18:08:02 +03:00
|
|
|
|
2018-10-16 16:57:32 +03:00
|
|
|
if (this.parserService && expression.includes("await ")) {
|
2019-02-01 18:19:47 +03:00
|
|
|
const shouldMapBindings = false;
|
|
|
|
const shouldMapAwait = true;
|
|
|
|
const res = this.parserService.mapExpression(
|
|
|
|
expression,
|
|
|
|
null,
|
|
|
|
null,
|
|
|
|
shouldMapBindings,
|
|
|
|
shouldMapAwait
|
|
|
|
);
|
|
|
|
return res;
|
2018-07-02 18:08:02 +03:00
|
|
|
}
|
|
|
|
|
Bug 1491354 - Extends top-level await mapping from debugger to toolbox; r=bgrins,jlast.
This patch makes the parser-worker available at the toolbox level.
This way, the console does not have to rely on the debugger being
open to map top-level await expression.
In order to make the worker works in the toolbox, some changes
are required (passing a window object, checking inToolbox differently).
We take this as an opportunity to *not* display the async iife result,
a promise, in the console. This is made by checking if the input was
mapped, and if so, ignoring the result we get from the server.
A couple tests are added to ensure the basic usage works as expected.
This patch should be considered as a v0 for top-level await evaluation
as there are things that are not perfect here. Since we rely on console.log
the result are treated differently from other evaluation results:
- the style is different
- the result gets added to the log cache (when restarting the console,
the results will still be displayed, but not the commands).
- the results can be filtered, although evaluation results should not
- `$_` after a top-level await evaluation returns the Promise created
by the async iife, not the result that was displayed in the console.
All those should be addressed in Bug 1410820.
Differential Revision: https://phabricator.services.mozilla.com/D6038
--HG--
extra : moz-landing-system : lando
2018-09-24 11:17:30 +03:00
|
|
|
return null;
|
2019-02-27 13:05:51 +03:00
|
|
|
}
|
2018-07-02 18:08:02 +03:00
|
|
|
|
2018-10-16 16:57:32 +03:00
|
|
|
get parserService() {
|
|
|
|
if (this._parserService) {
|
|
|
|
return this._parserService;
|
|
|
|
}
|
|
|
|
|
2019-05-15 17:46:09 +03:00
|
|
|
const {
|
|
|
|
ParserDispatcher,
|
2019-04-08 17:20:01 +03:00
|
|
|
} = require("devtools/client/debugger/src/workers/parser/index");
|
2018-10-16 16:57:32 +03:00
|
|
|
|
2019-05-15 17:46:09 +03:00
|
|
|
this._parserService = new ParserDispatcher();
|
2018-10-16 16:57:32 +03:00
|
|
|
this._parserService.start(
|
2019-04-08 17:20:01 +03:00
|
|
|
"resource://devtools/client/debugger/dist/parser-worker.js",
|
2018-11-19 19:33:22 +03:00
|
|
|
this.chromeUtilsWindow
|
|
|
|
);
|
2018-10-16 16:57:32 +03:00
|
|
|
return this._parserService;
|
2019-02-27 13:05:51 +03:00
|
|
|
}
|
2018-10-16 16:57:32 +03:00
|
|
|
|
2018-07-02 18:08:02 +03:00
|
|
|
/**
|
|
|
|
* Retrieves the current selection from the Inspector, if such a selection
|
|
|
|
* exists. This is used to pass the ID of the selected actor to the Web
|
|
|
|
* Console server for the $0 helper.
|
|
|
|
*
|
|
|
|
* @return object|null
|
|
|
|
* A Selection referring to the currently selected node in the
|
|
|
|
* Inspector.
|
|
|
|
* If the inspector was never opened, or no node was ever selected,
|
|
|
|
* then |null| is returned.
|
|
|
|
*/
|
|
|
|
getInspectorSelection() {
|
2019-08-22 11:10:06 +03:00
|
|
|
const toolbox = this.toolbox;
|
2018-07-02 18:08:02 +03:00
|
|
|
if (!toolbox) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
const panel = toolbox.getPanel("inspector");
|
|
|
|
if (!panel || !panel.selection) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return panel.selection;
|
2019-02-27 13:05:51 +03:00
|
|
|
}
|
2018-07-02 18:08:02 +03:00
|
|
|
|
2019-10-03 01:50:25 +03:00
|
|
|
async onViewSourceInDebugger(frame) {
|
|
|
|
if (this.toolbox) {
|
|
|
|
await this.toolbox.viewSourceInDebugger(
|
|
|
|
frame.url,
|
|
|
|
frame.line,
|
|
|
|
frame.column,
|
|
|
|
frame.sourceId
|
|
|
|
);
|
|
|
|
|
|
|
|
this.recordEvent("jump_to_source");
|
|
|
|
this.emit("source-in-debugger-opened");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async onViewSourceInScratchpad(frame) {
|
|
|
|
if (this.toolbox) {
|
|
|
|
await this.toolbox.viewSourceInScratchpad(frame.url, frame.line);
|
|
|
|
this.recordEvent("jump_to_source");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async onViewSourceInStyleEditor(frame) {
|
|
|
|
if (!this.toolbox) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
await this.toolbox.viewSourceInStyleEditor(
|
|
|
|
frame.url,
|
|
|
|
frame.line,
|
|
|
|
frame.column
|
|
|
|
);
|
|
|
|
this.recordEvent("jump_to_source");
|
|
|
|
}
|
|
|
|
|
|
|
|
async openNetworkPanel(requestId) {
|
|
|
|
if (!this.toolbox) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const netmonitor = await this.toolbox.selectTool("netmonitor");
|
|
|
|
await netmonitor.panelWin.Netmonitor.inspectRequest(requestId);
|
|
|
|
}
|
|
|
|
|
|
|
|
async resendNetworkRequest(requestId) {
|
|
|
|
if (!this.toolbox) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const api = await this.toolbox.getNetMonitorAPI();
|
|
|
|
await api.resendRequest(requestId);
|
|
|
|
}
|
|
|
|
|
|
|
|
async openNodeInInspector(grip) {
|
|
|
|
if (!this.toolbox) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const onSelectInspector = this.toolbox.selectTool(
|
|
|
|
"inspector",
|
|
|
|
"inspect_dom"
|
|
|
|
);
|
|
|
|
// TODO: Bug1574506 - Use the contextual WalkerFront for gripToNodeFront.
|
|
|
|
const walkerFront = (await this.toolbox.target.getFront("inspector"))
|
|
|
|
.walker;
|
|
|
|
const onGripNodeToFront = walkerFront.gripToNodeFront(grip);
|
|
|
|
const [front, inspector] = await Promise.all([
|
|
|
|
onGripNodeToFront,
|
|
|
|
onSelectInspector,
|
|
|
|
]);
|
|
|
|
|
|
|
|
const onInspectorUpdated = inspector.once("inspector-updated");
|
|
|
|
const onNodeFrontSet = this.toolbox.selection.setNodeFront(front, {
|
|
|
|
reason: "console",
|
|
|
|
});
|
|
|
|
|
|
|
|
await Promise.all([onNodeFrontSet, onInspectorUpdated]);
|
|
|
|
}
|
|
|
|
|
2018-07-02 18:08:02 +03:00
|
|
|
/**
|
|
|
|
* Destroy the object. Call this method to avoid memory leaks when the Web
|
|
|
|
* Console is closed.
|
|
|
|
*
|
|
|
|
* @return object
|
|
|
|
* A promise object that is resolved once the Web Console is closed.
|
|
|
|
*/
|
2019-07-31 11:12:43 +03:00
|
|
|
destroy() {
|
|
|
|
if (!this.hudId) {
|
|
|
|
return;
|
2018-07-02 18:08:02 +03:00
|
|
|
}
|
|
|
|
|
2019-07-31 11:12:43 +03:00
|
|
|
if (this.ui) {
|
|
|
|
this.ui.destroy();
|
|
|
|
}
|
2018-10-16 16:57:32 +03:00
|
|
|
|
2019-07-31 11:12:43 +03:00
|
|
|
if (this._parserService) {
|
|
|
|
this._parserService.stop();
|
|
|
|
this._parserService = null;
|
|
|
|
}
|
2018-07-02 18:08:02 +03:00
|
|
|
|
2019-07-31 11:12:43 +03:00
|
|
|
const id = Utils.supportsString(this.hudId);
|
|
|
|
Services.obs.notifyObservers(id, "web-console-destroyed");
|
|
|
|
this.hudId = null;
|
2019-08-01 00:56:54 +03:00
|
|
|
|
|
|
|
this.emit("destroyed");
|
2019-02-27 13:05:51 +03:00
|
|
|
}
|
|
|
|
}
|
2018-07-02 18:08:02 +03:00
|
|
|
|
|
|
|
module.exports = WebConsole;
|