gecko/browser/devtools/webconsole/WebConsolePanel.jsm
Dave Camp bf8e5ab9a8 Bug 855914 - Start using the jetpack loader in devtools. r=jwalker, f=ochameau
--HG--
rename : browser/devtools/framework/Sidebar.jsm => browser/devtools/framework/sidebar.js
rename : browser/devtools/framework/Target.jsm => browser/devtools/framework/target.js
rename : browser/devtools/framework/ToolboxHosts.jsm => browser/devtools/framework/toolbox-hosts.js
rename : browser/devtools/framework/Toolbox.jsm => browser/devtools/framework/toolbox.js
rename : browser/devtools/inspector/Breadcrumbs.jsm => browser/devtools/inspector/breadcrumbs.js
rename : browser/devtools/inspector/Highlighter.jsm => browser/devtools/inspector/highlighter.js
rename : browser/devtools/inspector/InspectorPanel.jsm => browser/devtools/inspector/inspector-panel.js
rename : browser/devtools/inspector/Selection.jsm => browser/devtools/inspector/selection.js
rename : browser/devtools/inspector/SelectorSearch.jsm => browser/devtools/inspector/selector-search.js
rename : browser/devtools/framework/ToolDefinitions.jsm => browser/devtools/main.js
rename : browser/devtools/markupview/MarkupView.jsm => browser/devtools/markupview/markup-view.js
rename : browser/devtools/shared/EventEmitter.jsm => browser/devtools/shared/event-emitter.js
rename : browser/devtools/shared/InplaceEditor.jsm => browser/devtools/shared/inplace-editor.js
rename : browser/devtools/shared/Undo.jsm => browser/devtools/shared/undo.js
rename : browser/devtools/styleinspector/CssHtmlTree.jsm => browser/devtools/styleinspector/computed-view.js
rename : browser/devtools/styleinspector/CssLogic.jsm => browser/devtools/styleinspector/css-logic.js
rename : browser/devtools/styleinspector/CssRuleView.jsm => browser/devtools/styleinspector/rule-view.js
rename : browser/devtools/styleinspector/StyleInspector.jsm => browser/devtools/styleinspector/style-inspector.js
rename : browser/devtools/tilt/TiltGL.jsm => browser/devtools/tilt/tilt-gl.js
rename : browser/devtools/tilt/TiltMath.jsm => browser/devtools/tilt/tilt-math.js
rename : browser/devtools/tilt/TiltUtils.jsm => browser/devtools/tilt/tilt-utils.js
rename : browser/devtools/tilt/TiltVisualizerStyle.jsm => browser/devtools/tilt/tilt-visualizer-style.js
rename : browser/devtools/tilt/TiltVisualizer.jsm => browser/devtools/tilt/tilt-visualizer.js
rename : browser/devtools/tilt/Tilt.jsm => browser/devtools/tilt/tilt.js
2013-04-11 13:59:08 -07:00

113 lines
3.2 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";
this.EXPORTED_SYMBOLS = [ "WebConsolePanel" ];
const { classes: Cc, interfaces: Ci, utils: Cu } = Components;
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "Promise",
"resource://gre/modules/commonjs/sdk/core/promise.js");
XPCOMUtils.defineLazyModuleGetter(this, "HUDService",
"resource:///modules/HUDService.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "EventEmitter",
"resource:///modules/devtools/shared/event-emitter.js");
/**
* A DevToolPanel that controls the Web Console.
*/
function WebConsolePanel(iframeWindow, toolbox) {
this._frameWindow = iframeWindow;
this._toolbox = toolbox;
EventEmitter.decorate(this);
}
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;
},
};