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/. */
7 loader
.lazyRequireGetter(
10 "resource://devtools/client/webconsole/webconsole.js"
12 loader
.lazyGetter(this, "EventEmitter", () =>
13 require("resource://devtools/shared/event-emitter.js")
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 = {
32 * Called by the WebConsole's onkey command handler.
33 * If the WebConsole is opened, check if the JSTerm's input line has focus.
37 this.hud
.jsterm
.focus();
41 * Open is effectively an asynchronous constructor.
44 * A promise that is resolved when the Web Console completes opening.
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
, {
65 const webConsoleUIWindow
= iframe
.contentWindow
.wrappedJSObject
;
66 const chromeWindow
= iframe
.ownerDocument
.defaultView
;
68 // Open the Web Console.
69 this.hud
= new WebConsole(
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");
83 const msg
= "WebConsolePanel open failed. " + e
.error
+ ": " + e
.message
;
85 console
.error(msg
, e
);
92 return this._toolbox
.target
;
101 this._frameWindow
= null;
102 this._toolbox
= null;
103 this.emit("destroyed");