gecko/browser/devtools/webconsole/panel.js
Mihai Sucan b255378927 Bug 877262 - Part 2: move the Web Console files over to the new jetpack-based loader; r=dcamp
--HG--
rename : browser/devtools/shared/AutocompletePopup.jsm => browser/devtools/shared/autocomplete-popup.js
rename : browser/devtools/webconsole/HUDService.jsm => browser/devtools/webconsole/hudservice.js
rename : browser/devtools/webconsole/NetworkPanel.jsm => browser/devtools/webconsole/network-panel.js
rename : browser/devtools/webconsole/WebConsolePanel.jsm => browser/devtools/webconsole/panel.js
rename : toolkit/devtools/webconsole/WebConsoleClient.jsm => toolkit/devtools/webconsole/client.js
rename : toolkit/devtools/webconsole/NetworkHelper.jsm => toolkit/devtools/webconsole/network-helper.js
rename : toolkit/devtools/webconsole/WebConsoleUtils.jsm => toolkit/devtools/webconsole/utils.js
2013-08-03 13:29:48 +03:00

106 lines
3.0 KiB
JavaScript

/* 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 {Cc, Ci, Cu} = require("chrome");
loader.lazyGetter(this, "promise", () => require("sdk/core/promise"));
loader.lazyGetter(this, "HUDService", () => require("devtools/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,
/**
* Open is effectively an asynchronous constructor.
*
* @return object
* A promise that is resolved when the Web Console completes opening.
*/
open: function WCP_open()
{
let parentDoc = this._toolbox.doc;
let iframe = parentDoc.getElementById("toolbox-panel-iframe-webconsole");
iframe.className = "web-console-frame";
// 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((aTarget) => {
this._frameWindow._remoteTarget = aTarget;
let webConsoleUIWindow = iframe.contentWindow.wrappedJSObject;
let chromeWindow = iframe.ownerDocument.defaultView;
return HUDService.openWebConsole(this.target, webConsoleUIWindow,
chromeWindow);
})
.then((aWebConsole) => {
this.hud = aWebConsole;
this._isReady = true;
this.emit("ready");
return this;
}, (aReason) => {
let msg = "WebConsolePanel open failed. " +
aReason.error + ": " + aReason.message;
dump(msg + "\n");
Cu.reportError(msg);
});
},
get target() this._toolbox.target,
_isReady: false,
get isReady() this._isReady,
destroy: function WCP_destroy()
{
if (this._destroyer) {
return this._destroyer;
}
this._destroyer = this.hud.destroy();
this._destroyer.then(() => this.emit("destroyed"));
return this._destroyer;
},
};