summaryrefslogtreecommitdiffstats
path: root/devtools/client/webconsole/panel.js
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /devtools/client/webconsole/panel.js
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip
Add m-esr52 at 52.6.0
Diffstat (limited to 'devtools/client/webconsole/panel.js')
-rw-r--r--devtools/client/webconsole/panel.js118
1 files changed, 118 insertions, 0 deletions
diff --git a/devtools/client/webconsole/panel.js b/devtools/client/webconsole/panel.js
new file mode 100644
index 000000000..3e3a4f4b9
--- /dev/null
+++ b/devtools/client/webconsole/panel.js
@@ -0,0 +1,118 @@
+/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
+/* vim: set ft= javascript ts=2 et sw=2 tw=80: */
+/* 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";
+
+const promise = require("promise");
+
+loader.lazyGetter(this, "HUDService", () => require("devtools/client/webconsole/hudservice"));
+loader.lazyGetter(this, "EventEmitter", () => require("devtools/shared/event-emitter"));
+
+/**
+ * A DevToolPanel that controls the Web Console.
+ */
+function WebConsolePanel(iframeWindow, toolbox) {
+ this._frameWindow = iframeWindow;
+ this._toolbox = toolbox;
+ EventEmitter.decorate(this);
+}
+
+exports.WebConsolePanel = WebConsolePanel;
+
+WebConsolePanel.prototype = {
+ hud: null,
+
+ /**
+ * Called by the WebConsole's onkey command handler.
+ * If the WebConsole is opened, check if the JSTerm's input line has focus.
+ * If not, focus it.
+ */
+ focusInput: function () {
+ this.hud.jsterm.focus();
+ },
+
+ /**
+ * Open is effectively an asynchronous constructor.
+ *
+ * @return object
+ * A promise that is resolved when the Web Console completes opening.
+ */
+ open: function () {
+ let parentDoc = this._toolbox.doc;
+ let iframe = parentDoc.getElementById("toolbox-panel-iframe-webconsole");
+
+ // Make sure the iframe content window is ready.
+ let deferredIframe = promise.defer();
+ let win, doc;
+ if ((win = iframe.contentWindow) &&
+ (doc = win.document) &&
+ doc.readyState == "complete") {
+ deferredIframe.resolve(null);
+ } else {
+ iframe.addEventListener("load", function onIframeLoad() {
+ iframe.removeEventListener("load", onIframeLoad, true);
+ deferredIframe.resolve(null);
+ }, true);
+ }
+
+ // Local debugging needs to make the target remote.
+ let promiseTarget;
+ if (!this.target.isRemote) {
+ promiseTarget = this.target.makeRemote();
+ } else {
+ promiseTarget = promise.resolve(this.target);
+ }
+
+ // 1. Wait for the iframe to load.
+ // 2. Wait for the remote target.
+ // 3. Open the Web Console.
+ return deferredIframe.promise
+ .then(() => promiseTarget)
+ .then((target) => {
+ this._frameWindow._remoteTarget = target;
+
+ let webConsoleUIWindow = iframe.contentWindow.wrappedJSObject;
+ let chromeWindow = iframe.ownerDocument.defaultView;
+ return HUDService.openWebConsole(this.target, webConsoleUIWindow,
+ chromeWindow);
+ })
+ .then((webConsole) => {
+ this.hud = webConsole;
+ this._isReady = true;
+ this.emit("ready");
+ return this;
+ }, (reason) => {
+ let msg = "WebConsolePanel open failed. " +
+ reason.error + ": " + reason.message;
+ dump(msg + "\n");
+ console.error(msg);
+ });
+ },
+
+ get target() {
+ return this._toolbox.target;
+ },
+
+ _isReady: false,
+ get isReady() {
+ return this._isReady;
+ },
+
+ destroy: function () {
+ if (this._destroyer) {
+ return this._destroyer;
+ }
+
+ this._destroyer = this.hud.destroy();
+ this._destroyer.then(() => {
+ this._frameWindow = null;
+ this._toolbox = null;
+ this.emit("destroyed");
+ });
+
+ return this._destroyer;
+ },
+};