Backed out 2 changesets (bug 1943998) for causing wd failures @ phases.py CLOSED...
[gecko.git] / devtools / client / webconsole / panel.js
blob7229c21a9d6ecb63830714adcbe233d4e67f0918
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 "use strict";
7 loader.lazyRequireGetter(
8 this,
9 "WebConsole",
10 "resource://devtools/client/webconsole/webconsole.js"
12 loader.lazyGetter(this, "EventEmitter", () =>
13 require("resource://devtools/shared/event-emitter.js")
16 /**
17 * A DevToolPanel that controls the Web Console.
19 function WebConsolePanel(iframeWindow, toolbox, commands) {
20 this._frameWindow = iframeWindow;
21 this._toolbox = toolbox;
22 this._commands = commands;
23 EventEmitter.decorate(this);
26 exports.WebConsolePanel = WebConsolePanel;
28 WebConsolePanel.prototype = {
29 hud: null,
31 /**
32 * Called by the WebConsole's onkey command handler.
33 * If the WebConsole is opened, check if the JSTerm's input line has focus.
34 * If not, focus it.
36 focusInput() {
37 this.hud.jsterm.focus();
40 /**
41 * Open is effectively an asynchronous constructor.
43 * @return object
44 * A promise that is resolved when the Web Console completes opening.
46 async open() {
47 try {
48 const parentDoc = this._toolbox.doc;
49 const iframe = parentDoc.getElementById(
50 "toolbox-panel-iframe-webconsole"
53 // Make sure the iframe content window is ready.
54 const win = iframe.contentWindow;
55 const doc = win && win.document;
56 if (!doc || doc.readyState !== "complete") {
57 await new Promise(resolve => {
58 iframe.addEventListener("load", resolve, {
59 capture: true,
60 once: true,
61 });
62 });
65 const webConsoleUIWindow = iframe.contentWindow.wrappedJSObject;
66 const chromeWindow = iframe.ownerDocument.defaultView;
68 // Open the Web Console.
69 this.hud = new WebConsole(
70 this._toolbox,
71 this._commands,
72 webConsoleUIWindow,
73 chromeWindow
75 await this.hud.init();
77 // Pipe 'reloaded' event from WebConsoleUI to WebConsolePanel.
78 // These events are listened by the Toolbox.
79 this.hud.ui.on("reloaded", () => {
80 this.emit("reloaded");
81 });
82 } catch (e) {
83 const msg = "WebConsolePanel open failed. " + e.error + ": " + e.message;
84 dump(msg + "\n");
85 console.error(msg, e);
88 return this;
91 get currentTarget() {
92 return this._toolbox.target;
95 destroy() {
96 if (!this._toolbox) {
97 return;
99 this.hud.destroy();
100 this.hud = null;
101 this._frameWindow = null;
102 this._toolbox = null;
103 this.emit("destroyed");