2016-01-25 22:19:58 +03:00
|
|
|
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
|
|
|
|
/* vim: set ft= javascript ts=2 et sw=2 tw=80: */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* 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/. */
|
2010-06-22 20:51:50 +04:00
|
|
|
|
2012-07-26 19:06:04 +04:00
|
|
|
"use strict";
|
|
|
|
|
2013-08-03 14:29:48 +04:00
|
|
|
const {Cc, Ci, Cu} = require("chrome");
|
2010-06-22 20:51:50 +04:00
|
|
|
|
2015-09-21 20:04:18 +03:00
|
|
|
var WebConsoleUtils = require("devtools/shared/webconsole/utils").Utils;
|
2015-09-15 21:19:45 +03:00
|
|
|
var Heritage = require("sdk/core/heritage");
|
2015-09-21 20:04:18 +03:00
|
|
|
var {TargetFactory} = require("devtools/client/framework/target");
|
|
|
|
var {Tools} = require("devtools/client/definitions");
|
2016-02-17 01:37:45 +03:00
|
|
|
const { Task } = require("resource://gre/modules/Task.jsm");
|
2015-09-15 21:19:45 +03:00
|
|
|
var promise = require("promise");
|
2016-02-27 15:51:10 +03:00
|
|
|
var Services = require("Services");
|
2013-01-11 21:31:09 +04:00
|
|
|
|
2016-02-11 15:29:47 +03:00
|
|
|
loader.lazyRequireGetter(this, "Telemetry", "devtools/client/shared/telemetry");
|
|
|
|
loader.lazyRequireGetter(this, "WebConsoleFrame", "devtools/client/webconsole/webconsole", true);
|
2016-02-11 15:29:47 +03:00
|
|
|
loader.lazyRequireGetter(this, "gDevTools", "devtools/client/framework/devtools", true);
|
2015-08-10 15:38:56 +03:00
|
|
|
loader.lazyRequireGetter(this, "DebuggerServer", "devtools/server/main", true);
|
2015-09-21 20:04:18 +03:00
|
|
|
loader.lazyRequireGetter(this, "DebuggerClient", "devtools/shared/client/main", true);
|
2016-02-11 15:29:47 +03:00
|
|
|
loader.lazyRequireGetter(this, "showDoorhanger", "devtools/client/shared/doorhanger", true);
|
2015-12-23 23:36:42 +03:00
|
|
|
loader.lazyRequireGetter(this, "viewSource", "devtools/client/shared/view-source");
|
2013-05-24 14:26:17 +04:00
|
|
|
|
2015-11-05 00:35:53 +03:00
|
|
|
const STRINGS_URI = "chrome://devtools/locale/webconsole.properties";
|
2016-02-13 08:56:12 +03:00
|
|
|
var l10n = new WebConsoleUtils.L10n(STRINGS_URI);
|
2012-07-26 19:06:04 +04:00
|
|
|
|
2013-04-09 13:47:23 +04:00
|
|
|
const BROWSER_CONSOLE_WINDOW_FEATURES = "chrome,titlebar,toolbar,centerscreen,resizable,dialog=no";
|
|
|
|
|
2013-06-20 17:29:01 +04:00
|
|
|
// The preference prefix for all of the Browser Console filters.
|
|
|
|
const BROWSER_CONSOLE_FILTER_PREFS_PREFIX = "devtools.browserconsole.filter.";
|
|
|
|
|
2015-09-15 21:19:45 +03:00
|
|
|
var gHudId = 0;
|
2013-11-26 23:21:43 +04:00
|
|
|
|
2010-09-09 04:08:58 +04:00
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
//// The HUD service
|
|
|
|
|
2010-06-22 20:51:50 +04:00
|
|
|
function HUD_SERVICE()
|
|
|
|
{
|
2013-08-02 21:11:57 +04:00
|
|
|
this.consoles = new Map();
|
|
|
|
this.lastFinishedRequest = { callback: null };
|
2013-01-11 21:31:09 +04:00
|
|
|
}
|
2010-11-20 22:53:14 +03:00
|
|
|
|
2013-01-11 21:31:09 +04:00
|
|
|
HUD_SERVICE.prototype =
|
|
|
|
{
|
2013-08-02 21:11:57 +04:00
|
|
|
_browserConsoleID: null,
|
|
|
|
_browserConsoleDefer: null,
|
|
|
|
|
2011-08-03 22:04:30 +04:00
|
|
|
/**
|
2013-08-02 21:11:57 +04:00
|
|
|
* Keeps a reference for each Web Console / Browser Console that is created.
|
|
|
|
* @type Map
|
2011-08-03 22:04:30 +04:00
|
|
|
*/
|
2013-08-02 21:11:57 +04:00
|
|
|
consoles: null,
|
2010-06-22 20:51:50 +04:00
|
|
|
|
|
|
|
/**
|
2013-08-02 21:11:57 +04:00
|
|
|
* Assign a function to this property to listen for every request that
|
|
|
|
* completes. Used by unit tests. The callback takes one argument: the HTTP
|
|
|
|
* activity object as received from the remote Web Console.
|
2010-06-22 20:51:50 +04:00
|
|
|
*
|
2013-08-02 21:11:57 +04:00
|
|
|
* @type object
|
|
|
|
* Includes a property named |callback|. Assign the function to the
|
|
|
|
* |callback| property of this object.
|
2010-06-22 20:51:50 +04:00
|
|
|
*/
|
2013-08-02 21:11:57 +04:00
|
|
|
lastFinishedRequest: null,
|
2010-06-22 20:51:50 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Firefox-specific current tab getter
|
|
|
|
*
|
|
|
|
* @returns nsIDOMWindow
|
|
|
|
*/
|
|
|
|
currentContext: function HS_currentContext() {
|
2012-05-31 14:30:56 +04:00
|
|
|
return Services.wm.getMostRecentWindow("navigator:browser");
|
2010-06-22 20:51:50 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2013-01-11 21:31:09 +04:00
|
|
|
* Open a Web Console for the given target.
|
|
|
|
*
|
2013-04-12 00:59:08 +04:00
|
|
|
* @see devtools/framework/target.js for details about targets.
|
2010-06-22 20:51:50 +04:00
|
|
|
*
|
2013-01-11 21:31:09 +04:00
|
|
|
* @param object aTarget
|
|
|
|
* The target that the web console will connect to.
|
2013-04-09 13:47:23 +04:00
|
|
|
* @param nsIDOMWindow aIframeWindow
|
|
|
|
* The window where the web console UI is already loaded.
|
|
|
|
* @param nsIDOMWindow aChromeWindow
|
|
|
|
* The window of the web console owner.
|
2012-05-31 14:30:56 +04:00
|
|
|
* @return object
|
2013-07-11 11:12:20 +04:00
|
|
|
* A promise object for the opening of the new WebConsole instance.
|
2010-06-22 20:51:50 +04:00
|
|
|
*/
|
2013-04-09 13:47:23 +04:00
|
|
|
openWebConsole:
|
|
|
|
function HS_openWebConsole(aTarget, aIframeWindow, aChromeWindow)
|
|
|
|
{
|
|
|
|
let hud = new WebConsole(aTarget, aIframeWindow, aChromeWindow);
|
2013-08-02 21:11:57 +04:00
|
|
|
this.consoles.set(hud.hudId, hud);
|
2013-04-09 13:47:23 +04:00
|
|
|
return hud.init();
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Open a Browser Console for the given target.
|
|
|
|
*
|
2013-08-02 21:11:57 +04:00
|
|
|
* @see devtools/framework/target.js for details about targets.
|
2013-04-09 13:47:23 +04:00
|
|
|
*
|
|
|
|
* @param object aTarget
|
|
|
|
* The target that the browser console will connect to.
|
|
|
|
* @param nsIDOMWindow aIframeWindow
|
|
|
|
* The window where the browser console UI is already loaded.
|
|
|
|
* @param nsIDOMWindow aChromeWindow
|
|
|
|
* The window of the browser console owner.
|
|
|
|
* @return object
|
2013-07-11 11:12:20 +04:00
|
|
|
* A promise object for the opening of the new BrowserConsole instance.
|
2013-04-09 13:47:23 +04:00
|
|
|
*/
|
|
|
|
openBrowserConsole:
|
|
|
|
function HS_openBrowserConsole(aTarget, aIframeWindow, aChromeWindow)
|
2010-06-22 20:51:50 +04:00
|
|
|
{
|
2013-04-09 13:47:23 +04:00
|
|
|
let hud = new BrowserConsole(aTarget, aIframeWindow, aChromeWindow);
|
2014-01-22 22:21:33 +04:00
|
|
|
this._browserConsoleID = hud.hudId;
|
2013-08-02 21:11:57 +04:00
|
|
|
this.consoles.set(hud.hudId, hud);
|
2013-01-11 21:31:09 +04:00
|
|
|
return hud.init();
|
2010-06-22 20:51:50 +04:00
|
|
|
},
|
|
|
|
|
2010-08-26 20:49:28 +04:00
|
|
|
/**
|
2013-08-02 21:11:57 +04:00
|
|
|
* Returns the Web Console object associated to a content window.
|
2010-08-26 20:49:28 +04:00
|
|
|
*
|
|
|
|
* @param nsIDOMWindow aContentWindow
|
2011-07-02 00:20:09 +04:00
|
|
|
* @returns object
|
2010-08-26 20:49:28 +04:00
|
|
|
*/
|
2011-07-02 00:20:09 +04:00
|
|
|
getHudByWindow: function HS_getHudByWindow(aContentWindow)
|
2010-08-26 20:49:28 +04:00
|
|
|
{
|
2013-08-02 21:11:57 +04:00
|
|
|
for (let [hudId, hud] of this.consoles) {
|
2013-01-11 21:31:09 +04:00
|
|
|
let target = hud.target;
|
|
|
|
if (target && target.tab && target.window === aContentWindow) {
|
|
|
|
return hud;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
2010-08-26 20:49:28 +04:00
|
|
|
},
|
|
|
|
|
2011-02-26 01:12:42 +03:00
|
|
|
/**
|
2013-08-02 21:11:57 +04:00
|
|
|
* Returns the console instance for a given id.
|
2011-02-26 01:12:42 +03:00
|
|
|
*
|
2013-08-02 21:11:57 +04:00
|
|
|
* @param string aId
|
|
|
|
* @returns Object
|
2011-02-26 01:12:42 +03:00
|
|
|
*/
|
2013-08-02 21:11:57 +04:00
|
|
|
getHudReferenceById: function HS_getHudReferenceById(aId)
|
2011-02-26 01:12:42 +03:00
|
|
|
{
|
2013-08-02 21:11:57 +04:00
|
|
|
return this.consoles.get(aId);
|
2011-02-26 01:12:42 +03:00
|
|
|
},
|
|
|
|
|
2010-08-29 08:30:49 +04:00
|
|
|
/**
|
2013-08-02 21:11:57 +04:00
|
|
|
* Find if there is a Web Console open for the current tab and return the
|
|
|
|
* instance.
|
|
|
|
* @return object|null
|
|
|
|
* The WebConsole object or null if the active tab has no open Web
|
|
|
|
* Console.
|
|
|
|
*/
|
|
|
|
getOpenWebConsole: function HS_getOpenWebConsole()
|
|
|
|
{
|
|
|
|
let tab = this.currentContext().gBrowser.selectedTab;
|
2015-08-06 15:38:10 +03:00
|
|
|
if (!tab || !TargetFactory.isKnownTab(tab)) {
|
2013-08-02 21:11:57 +04:00
|
|
|
return null;
|
|
|
|
}
|
2015-08-06 15:38:10 +03:00
|
|
|
let target = TargetFactory.forTab(tab);
|
2013-08-02 21:11:57 +04:00
|
|
|
let toolbox = gDevTools.getToolbox(target);
|
|
|
|
let panel = toolbox ? toolbox.getPanel("webconsole") : null;
|
|
|
|
return panel ? panel.hud : null;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Toggle the Browser Console.
|
|
|
|
*/
|
|
|
|
toggleBrowserConsole: function HS_toggleBrowserConsole()
|
|
|
|
{
|
|
|
|
if (this._browserConsoleID) {
|
|
|
|
let hud = this.getHudReferenceById(this._browserConsoleID);
|
|
|
|
return hud.destroy();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this._browserConsoleDefer) {
|
|
|
|
return this._browserConsoleDefer.promise;
|
|
|
|
}
|
|
|
|
|
|
|
|
this._browserConsoleDefer = promise.defer();
|
|
|
|
|
|
|
|
function connect()
|
|
|
|
{
|
|
|
|
let deferred = promise.defer();
|
|
|
|
|
|
|
|
if (!DebuggerServer.initialized) {
|
|
|
|
DebuggerServer.init();
|
|
|
|
DebuggerServer.addBrowserActors();
|
|
|
|
}
|
2015-03-04 07:47:00 +03:00
|
|
|
DebuggerServer.allowChromeProcess = true;
|
2013-08-02 21:11:57 +04:00
|
|
|
|
|
|
|
let client = new DebuggerClient(DebuggerServer.connectPipe());
|
2016-01-28 21:11:31 +03:00
|
|
|
return client.connect()
|
|
|
|
.then(() => client.getProcess())
|
|
|
|
.then(aResponse => {
|
2015-03-04 07:47:00 +03:00
|
|
|
// Set chrome:false in order to attach to the target
|
|
|
|
// (i.e. send an `attach` request to the chrome actor)
|
2016-01-28 21:11:31 +03:00
|
|
|
return { form: aResponse.form, client: client, chrome: false };
|
|
|
|
});
|
2013-08-02 21:11:57 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
let target;
|
|
|
|
function getTarget(aConnection)
|
|
|
|
{
|
2015-08-06 15:38:10 +03:00
|
|
|
return TargetFactory.forRemoteTab(aConnection);
|
2013-08-02 21:11:57 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
function openWindow(aTarget)
|
|
|
|
{
|
|
|
|
target = aTarget;
|
|
|
|
|
|
|
|
let deferred = promise.defer();
|
|
|
|
|
2015-08-06 15:38:10 +03:00
|
|
|
let win = Services.ww.openWindow(null, Tools.webConsole.url, "_blank",
|
2013-08-02 21:11:57 +04:00
|
|
|
BROWSER_CONSOLE_WINDOW_FEATURES, null);
|
|
|
|
win.addEventListener("DOMContentLoaded", function onLoad() {
|
|
|
|
win.removeEventListener("DOMContentLoaded", onLoad);
|
|
|
|
|
|
|
|
// Set the correct Browser Console title.
|
|
|
|
let root = win.document.documentElement;
|
|
|
|
root.setAttribute("title", root.getAttribute("browserConsoleTitle"));
|
|
|
|
|
|
|
|
deferred.resolve(win);
|
|
|
|
});
|
|
|
|
|
|
|
|
return deferred.promise;
|
|
|
|
}
|
|
|
|
|
2013-09-23 14:43:37 +04:00
|
|
|
connect().then(getTarget).then(openWindow).then((aWindow) => {
|
2015-03-04 07:47:00 +03:00
|
|
|
return this.openBrowserConsole(target, aWindow, aWindow)
|
2013-08-02 21:11:57 +04:00
|
|
|
.then((aBrowserConsole) => {
|
|
|
|
this._browserConsoleDefer.resolve(aBrowserConsole);
|
|
|
|
this._browserConsoleDefer = null;
|
2013-09-23 14:43:37 +04:00
|
|
|
})
|
2015-03-04 07:47:00 +03:00
|
|
|
}, console.error.bind(console));
|
2013-08-02 21:11:57 +04:00
|
|
|
|
|
|
|
return this._browserConsoleDefer.promise;
|
|
|
|
},
|
|
|
|
|
2015-02-12 11:21:02 +03:00
|
|
|
/**
|
|
|
|
* Opens or focuses the Browser Console.
|
|
|
|
*/
|
|
|
|
openBrowserConsoleOrFocus: function HS_openBrowserConsoleOrFocus()
|
|
|
|
{
|
|
|
|
let hud = this.getBrowserConsole();
|
|
|
|
if (hud) {
|
|
|
|
hud.iframeWindow.focus();
|
|
|
|
return promise.resolve(hud);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return this.toggleBrowserConsole();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2013-08-02 21:11:57 +04:00
|
|
|
/**
|
|
|
|
* Get the Browser Console instance, if open.
|
2012-05-29 16:48:05 +04:00
|
|
|
*
|
2013-08-02 21:11:57 +04:00
|
|
|
* @return object|null
|
|
|
|
* A BrowserConsole instance or null if the Browser Console is not
|
|
|
|
* open.
|
2010-08-29 08:30:49 +04:00
|
|
|
*/
|
2013-08-02 21:11:57 +04:00
|
|
|
getBrowserConsole: function HS_getBrowserConsole()
|
|
|
|
{
|
|
|
|
return this.getHudReferenceById(this._browserConsoleID);
|
|
|
|
},
|
2010-06-22 20:51:50 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2012-05-31 14:30:56 +04:00
|
|
|
/**
|
2013-01-11 21:31:09 +04:00
|
|
|
* A WebConsole instance is an interactive console initialized *per target*
|
2012-07-26 19:06:04 +04:00
|
|
|
* that displays console log data as well as provides an interactive terminal to
|
2013-01-11 21:31:09 +04:00
|
|
|
* manipulate the target's document content.
|
2012-05-31 14:30:56 +04:00
|
|
|
*
|
2013-04-09 13:47:23 +04:00
|
|
|
* This object only wraps the iframe that holds the Web Console UI. This is
|
|
|
|
* meant to be an integration point between the Firefox UI and the Web Console
|
|
|
|
* UI and features.
|
2012-07-26 19:06:04 +04:00
|
|
|
*
|
2013-01-11 21:31:09 +04:00
|
|
|
* @constructor
|
|
|
|
* @param object aTarget
|
|
|
|
* The target that the web console will connect to.
|
2013-04-09 13:47:23 +04:00
|
|
|
* @param nsIDOMWindow aIframeWindow
|
|
|
|
* The window where the web console UI is already loaded.
|
|
|
|
* @param nsIDOMWindow aChromeWindow
|
|
|
|
* The window of the web console owner.
|
2012-05-31 14:30:56 +04:00
|
|
|
*/
|
2013-04-09 13:47:23 +04:00
|
|
|
function WebConsole(aTarget, aIframeWindow, aChromeWindow)
|
2010-06-22 20:51:50 +04:00
|
|
|
{
|
2013-04-09 13:47:23 +04:00
|
|
|
this.iframeWindow = aIframeWindow;
|
|
|
|
this.chromeWindow = aChromeWindow;
|
2013-11-26 23:21:43 +04:00
|
|
|
this.hudId = "hud_" + ++gHudId;
|
2012-11-30 12:07:59 +04:00
|
|
|
this.target = aTarget;
|
2013-02-17 15:13:00 +04:00
|
|
|
|
|
|
|
this.browserWindow = this.chromeWindow.top;
|
2013-04-09 13:47:23 +04:00
|
|
|
|
2013-02-17 15:13:00 +04:00
|
|
|
let element = this.browserWindow.document.documentElement;
|
|
|
|
if (element.getAttribute("windowtype") != "navigator:browser") {
|
|
|
|
this.browserWindow = HUDService.currentContext();
|
|
|
|
}
|
2013-06-20 17:29:01 +04:00
|
|
|
|
2013-08-03 14:29:48 +04:00
|
|
|
this.ui = new WebConsoleFrame(this);
|
2010-06-22 20:51:50 +04:00
|
|
|
}
|
|
|
|
|
2012-07-26 19:06:04 +04:00
|
|
|
WebConsole.prototype = {
|
2013-04-09 13:47:23 +04:00
|
|
|
iframeWindow: null,
|
2012-10-05 20:15:51 +04:00
|
|
|
chromeWindow: null,
|
2013-04-09 13:47:23 +04:00
|
|
|
browserWindow: null,
|
2013-01-11 21:31:09 +04:00
|
|
|
hudId: null,
|
|
|
|
target: null,
|
2013-06-20 17:29:01 +04:00
|
|
|
ui: null,
|
2013-04-09 13:47:23 +04:00
|
|
|
_browserConsole: false,
|
2013-01-11 21:31:09 +04:00
|
|
|
_destroyer: null,
|
|
|
|
|
2012-06-02 14:45:32 +04:00
|
|
|
/**
|
2013-08-02 21:11:57 +04:00
|
|
|
* Getter for a function to to listen for every request that completes. Used
|
|
|
|
* by unit tests. The callback takes one argument: the HTTP activity object as
|
|
|
|
* received from the remote Web Console.
|
2012-06-02 14:45:32 +04:00
|
|
|
*
|
2012-07-26 19:06:04 +04:00
|
|
|
* @type function
|
2012-06-02 14:45:32 +04:00
|
|
|
*/
|
2015-05-24 20:41:58 +03:00
|
|
|
get lastFinishedRequestCallback()
|
|
|
|
{
|
|
|
|
return HUDService.lastFinishedRequest.callback;
|
|
|
|
},
|
2012-06-02 14:45:32 +04:00
|
|
|
|
2013-12-02 12:28:01 +04:00
|
|
|
/**
|
|
|
|
* Getter for the window that can provide various utilities that the web
|
|
|
|
* console makes use of, like opening links, managing popups, etc. In
|
|
|
|
* most cases, this will be |this.browserWindow|, but in some uses (such as
|
|
|
|
* the Browser Toolbox), there is no browser window, so an alternative window
|
|
|
|
* hosts the utilities there.
|
|
|
|
* @type nsIDOMWindow
|
|
|
|
*/
|
|
|
|
get chromeUtilsWindow()
|
|
|
|
{
|
|
|
|
if (this.browserWindow) {
|
|
|
|
return this.browserWindow;
|
|
|
|
}
|
|
|
|
return this.chromeWindow.top;
|
|
|
|
},
|
|
|
|
|
2012-05-29 16:48:05 +04:00
|
|
|
/**
|
2012-07-26 19:06:04 +04:00
|
|
|
* Getter for the xul:popupset that holds any popups we open.
|
|
|
|
* @type nsIDOMElement
|
2012-05-29 16:48:05 +04:00
|
|
|
*/
|
2012-07-26 19:06:04 +04:00
|
|
|
get mainPopupSet()
|
|
|
|
{
|
2013-12-02 12:28:01 +04:00
|
|
|
return this.chromeUtilsWindow.document.getElementById("mainPopupSet");
|
2012-07-26 19:06:04 +04:00
|
|
|
},
|
2012-05-29 16:48:05 +04:00
|
|
|
|
2012-07-26 19:06:04 +04:00
|
|
|
/**
|
|
|
|
* Getter for the output element that holds messages we display.
|
|
|
|
* @type nsIDOMElement
|
|
|
|
*/
|
|
|
|
get outputNode()
|
|
|
|
{
|
|
|
|
return this.ui ? this.ui.outputNode : null;
|
|
|
|
},
|
|
|
|
|
2013-12-02 12:28:01 +04:00
|
|
|
get gViewSourceUtils()
|
|
|
|
{
|
|
|
|
return this.chromeUtilsWindow.gViewSourceUtils;
|
|
|
|
},
|
2012-07-26 19:06:04 +04:00
|
|
|
|
|
|
|
/**
|
2013-01-11 21:31:09 +04:00
|
|
|
* Initialize the Web Console instance.
|
|
|
|
*
|
|
|
|
* @return object
|
2013-07-11 11:12:20 +04:00
|
|
|
* A promise for the initialization.
|
2012-07-26 19:06:04 +04:00
|
|
|
*/
|
2013-01-11 21:31:09 +04:00
|
|
|
init: function WC_init()
|
2012-07-26 19:06:04 +04:00
|
|
|
{
|
2013-04-09 13:47:23 +04:00
|
|
|
return this.ui.init().then(() => this);
|
2011-05-18 15:08:54 +04:00
|
|
|
},
|
|
|
|
|
2011-06-18 18:42:14 +04:00
|
|
|
/**
|
|
|
|
* Retrieve the Web Console panel title.
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
* The Web Console panel title.
|
|
|
|
*/
|
2012-07-26 19:06:04 +04:00
|
|
|
getPanelTitle: function WC_getPanelTitle()
|
2011-06-18 18:42:14 +04:00
|
|
|
{
|
2012-10-05 15:54:43 +04:00
|
|
|
let url = this.ui ? this.ui.contentLocation : "";
|
|
|
|
return l10n.getFormatStr("webConsoleWindowTitleAndURL", [url]);
|
2011-06-18 18:42:14 +04:00
|
|
|
},
|
|
|
|
|
2010-06-22 20:51:50 +04:00
|
|
|
/**
|
2012-07-26 19:06:04 +04:00
|
|
|
* The JSTerm object that manages the console's input.
|
|
|
|
* @see webconsole.js::JSTerm
|
|
|
|
* @type object
|
2010-06-22 20:51:50 +04:00
|
|
|
*/
|
2012-07-26 19:06:04 +04:00
|
|
|
get jsterm()
|
2010-06-22 20:51:50 +04:00
|
|
|
{
|
2012-07-26 19:06:04 +04:00
|
|
|
return this.ui ? this.ui.jsterm : null;
|
2010-06-22 20:51:50 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2012-07-26 19:06:04 +04:00
|
|
|
* The clear output button handler.
|
2012-09-26 21:02:04 +04:00
|
|
|
* @private
|
2010-06-22 20:51:50 +04:00
|
|
|
*/
|
2012-09-26 21:02:04 +04:00
|
|
|
_onClearButton: function WC__onClearButton()
|
2010-06-22 20:51:50 +04:00
|
|
|
{
|
2013-01-11 21:31:09 +04:00
|
|
|
if (this.target.isLocalTab) {
|
|
|
|
this.browserWindow.DeveloperToolbar.resetErrorsCount(this.target.tab);
|
|
|
|
}
|
2010-06-22 20:51:50 +04:00
|
|
|
},
|
|
|
|
|
2011-06-09 17:27:30 +04:00
|
|
|
/**
|
2012-07-26 19:06:04 +04:00
|
|
|
* Alias for the WebConsoleFrame.setFilterState() method.
|
|
|
|
* @see webconsole.js::WebConsoleFrame.setFilterState()
|
2011-06-09 17:27:30 +04:00
|
|
|
*/
|
2012-07-26 19:06:04 +04:00
|
|
|
setFilterState: function WC_setFilterState()
|
2011-06-09 17:27:30 +04:00
|
|
|
{
|
2012-07-26 19:06:04 +04:00
|
|
|
this.ui && this.ui.setFilterState.apply(this.ui, arguments);
|
2011-06-09 17:27:30 +04:00
|
|
|
},
|
|
|
|
|
2011-05-18 15:08:54 +04:00
|
|
|
/**
|
2012-07-26 19:06:04 +04:00
|
|
|
* Open a link in a new tab.
|
2011-05-18 15:08:54 +04:00
|
|
|
*
|
2012-07-26 19:06:04 +04:00
|
|
|
* @param string aLink
|
|
|
|
* The URL you want to open in a new tab.
|
2011-05-18 15:08:54 +04:00
|
|
|
*/
|
2012-07-26 19:06:04 +04:00
|
|
|
openLink: function WC_openLink(aLink)
|
2010-06-22 20:51:50 +04:00
|
|
|
{
|
2013-12-02 12:28:01 +04:00
|
|
|
this.chromeUtilsWindow.openUILinkIn(aLink, "tab");
|
2010-06-22 20:51:50 +04:00
|
|
|
},
|
|
|
|
|
2012-09-25 21:32:11 +04:00
|
|
|
/**
|
|
|
|
* Open a link in Firefox's view source.
|
|
|
|
*
|
|
|
|
* @param string aSourceURL
|
|
|
|
* The URL of the file.
|
|
|
|
* @param integer aSourceLine
|
|
|
|
* The line number which should be highlighted.
|
|
|
|
*/
|
2015-04-25 00:16:34 +03:00
|
|
|
viewSource: function WC_viewSource(aSourceURL, aSourceLine) {
|
2015-05-24 02:17:50 +03:00
|
|
|
// Attempt to access view source via a browser first, which may display it in
|
|
|
|
// a tab, if enabled.
|
|
|
|
let browserWin = Services.wm.getMostRecentWindow("navigator:browser");
|
2015-06-20 00:16:00 +03:00
|
|
|
if (browserWin && browserWin.BrowserViewSourceOfDocument) {
|
2015-05-24 02:17:50 +03:00
|
|
|
return browserWin.BrowserViewSourceOfDocument({
|
|
|
|
URL: aSourceURL,
|
|
|
|
lineNumber: aSourceLine
|
|
|
|
});
|
|
|
|
}
|
2015-04-25 00:16:34 +03:00
|
|
|
this.gViewSourceUtils.viewSource(aSourceURL, null, this.iframeWindow.document, aSourceLine || 0);
|
2012-09-25 21:32:11 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tries to open a Stylesheet file related to the web page for the web console
|
|
|
|
* instance in the Style Editor. If the file is not found, it is opened in
|
|
|
|
* source view instead.
|
|
|
|
*
|
2015-04-25 00:16:34 +03:00
|
|
|
* Manually handle the case where toolbox does not exist (Browser Console).
|
|
|
|
*
|
2012-09-25 21:32:11 +04:00
|
|
|
* @param string aSourceURL
|
|
|
|
* The URL of the file.
|
|
|
|
* @param integer aSourceLine
|
|
|
|
* The line number which you want to place the caret.
|
|
|
|
*/
|
2015-04-25 00:16:34 +03:00
|
|
|
viewSourceInStyleEditor: function WC_viewSourceInStyleEditor(aSourceURL, aSourceLine) {
|
2013-05-31 00:23:52 +04:00
|
|
|
let toolbox = gDevTools.getToolbox(this.target);
|
|
|
|
if (!toolbox) {
|
|
|
|
this.viewSource(aSourceURL, aSourceLine);
|
|
|
|
return;
|
|
|
|
}
|
2015-04-25 00:16:34 +03:00
|
|
|
toolbox.viewSourceInStyleEditor(aSourceURL, aSourceLine);
|
2012-09-25 21:32:11 +04:00
|
|
|
},
|
|
|
|
|
2012-12-17 03:10:44 +04:00
|
|
|
/**
|
|
|
|
* Tries to open a JavaScript file related to the web page for the web console
|
|
|
|
* instance in the Script Debugger. If the file is not found, it is opened in
|
|
|
|
* source view instead.
|
|
|
|
*
|
2015-04-25 00:16:34 +03:00
|
|
|
* Manually handle the case where toolbox does not exist (Browser Console).
|
|
|
|
*
|
2012-12-17 03:10:44 +04:00
|
|
|
* @param string aSourceURL
|
|
|
|
* The URL of the file.
|
|
|
|
* @param integer aSourceLine
|
|
|
|
* The line number which you want to place the caret.
|
|
|
|
*/
|
2015-04-25 00:16:34 +03:00
|
|
|
viewSourceInDebugger: function WC_viewSourceInDebugger(aSourceURL, aSourceLine) {
|
2012-12-17 03:10:44 +04:00
|
|
|
let toolbox = gDevTools.getToolbox(this.target);
|
2013-04-09 13:47:23 +04:00
|
|
|
if (!toolbox) {
|
2013-09-13 17:23:14 +04:00
|
|
|
this.viewSource(aSourceURL, aSourceLine);
|
2013-04-09 13:47:23 +04:00
|
|
|
return;
|
|
|
|
}
|
2015-04-25 00:16:34 +03:00
|
|
|
toolbox.viewSourceInDebugger(aSourceURL, aSourceLine).then(() => {
|
|
|
|
this.ui.emit("source-in-debugger-opened");
|
|
|
|
})
|
2012-12-17 03:10:44 +04:00
|
|
|
},
|
|
|
|
|
2013-10-04 23:44:09 +04:00
|
|
|
/**
|
|
|
|
* Tries to open a JavaScript file related to the web page for the web console
|
|
|
|
* instance in the corresponding Scratchpad.
|
|
|
|
*
|
|
|
|
* @param string aSourceURL
|
|
|
|
* The URL of the file which corresponds to a Scratchpad id.
|
|
|
|
*/
|
2015-04-25 00:16:34 +03:00
|
|
|
viewSourceInScratchpad: function WC_viewSourceInScratchpad(aSourceURL, aSourceLine) {
|
2015-12-23 23:36:42 +03:00
|
|
|
viewSource.viewSourceInScratchpad(aSourceURL, aSourceLine);
|
2013-10-04 23:44:09 +04:00
|
|
|
},
|
|
|
|
|
2013-03-30 15:31:10 +04:00
|
|
|
/**
|
|
|
|
* Retrieve information about the JavaScript debugger's stackframes list. This
|
|
|
|
* is used to allow the Web Console to evaluate code in the selected
|
|
|
|
* stackframe.
|
|
|
|
*
|
|
|
|
* @return object|null
|
|
|
|
* An object which holds:
|
|
|
|
* - frames: the active ThreadClient.cachedFrames array.
|
|
|
|
* - selected: depth/index of the selected stackframe in the debugger
|
|
|
|
* UI.
|
|
|
|
* If the debugger is not open or if it's not paused, then |null| is
|
|
|
|
* returned.
|
|
|
|
*/
|
|
|
|
getDebuggerFrames: function WC_getDebuggerFrames()
|
|
|
|
{
|
|
|
|
let toolbox = gDevTools.getToolbox(this.target);
|
|
|
|
if (!toolbox) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
let panel = toolbox.getPanel("jsdebugger");
|
|
|
|
if (!panel) {
|
|
|
|
return null;
|
|
|
|
}
|
2013-09-13 17:23:14 +04:00
|
|
|
let framesController = panel.panelWin.DebuggerController.StackFrames;
|
2013-03-30 15:31:10 +04:00
|
|
|
let thread = framesController.activeThread;
|
|
|
|
if (thread && thread.paused) {
|
|
|
|
return {
|
|
|
|
frames: thread.cachedFrames,
|
2013-09-13 17:23:14 +04:00
|
|
|
selected: framesController.currentFrameDepth,
|
2013-03-30 15:31:10 +04:00
|
|
|
};
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
|
2014-07-31 21:07:27 +04:00
|
|
|
/**
|
|
|
|
* Retrieves the current selection from the Inspector, if such a selection
|
|
|
|
* exists. This is used to pass the ID of the selected actor to the Web
|
|
|
|
* Console server for the $0 helper.
|
|
|
|
*
|
|
|
|
* @return object|null
|
|
|
|
* A Selection referring to the currently selected node in the
|
|
|
|
* Inspector.
|
|
|
|
* If the inspector was never opened, or no node was ever selected,
|
|
|
|
* then |null| is returned.
|
|
|
|
*/
|
|
|
|
getInspectorSelection: function WC_getInspectorSelection()
|
|
|
|
{
|
|
|
|
let toolbox = gDevTools.getToolbox(this.target);
|
|
|
|
if (!toolbox) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
let panel = toolbox.getPanel("inspector");
|
|
|
|
if (!panel || !panel.selection) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return panel.selection;
|
|
|
|
},
|
|
|
|
|
2012-05-10 17:15:10 +04:00
|
|
|
/**
|
2012-07-26 19:06:04 +04:00
|
|
|
* Destroy the object. Call this method to avoid memory leaks when the Web
|
|
|
|
* Console is closed.
|
2012-09-26 21:07:57 +04:00
|
|
|
*
|
2013-01-11 21:31:09 +04:00
|
|
|
* @return object
|
2013-07-11 11:12:20 +04:00
|
|
|
* A promise object that is resolved once the Web Console is closed.
|
2012-05-10 17:15:10 +04:00
|
|
|
*/
|
2013-01-11 21:31:09 +04:00
|
|
|
destroy: function WC_destroy()
|
2010-06-22 20:51:50 +04:00
|
|
|
{
|
2013-01-11 21:31:09 +04:00
|
|
|
if (this._destroyer) {
|
|
|
|
return this._destroyer.promise;
|
|
|
|
}
|
|
|
|
|
2013-08-02 21:11:57 +04:00
|
|
|
HUDService.consoles.delete(this.hudId);
|
2013-01-11 21:31:09 +04:00
|
|
|
|
2013-07-11 11:12:20 +04:00
|
|
|
this._destroyer = promise.defer();
|
2012-05-10 17:15:10 +04:00
|
|
|
|
2015-03-04 07:47:00 +03:00
|
|
|
// The document may already be removed
|
|
|
|
if (this.chromeUtilsWindow && this.mainPopupSet) {
|
|
|
|
let popupset = this.mainPopupSet;
|
|
|
|
let panels = popupset.querySelectorAll("panel[hudId=" + this.hudId + "]");
|
|
|
|
for (let panel of panels) {
|
|
|
|
panel.hidePopup();
|
|
|
|
}
|
2012-07-26 19:06:04 +04:00
|
|
|
}
|
2012-05-10 17:15:10 +04:00
|
|
|
|
2016-02-17 01:37:45 +03:00
|
|
|
let onDestroy = Task.async(function*() {
|
2013-01-11 21:31:09 +04:00
|
|
|
try {
|
2016-02-17 01:37:45 +03:00
|
|
|
yield this.target.activeTab.focus()
|
2012-09-26 21:07:57 +04:00
|
|
|
}
|
2013-01-11 21:31:09 +04:00
|
|
|
catch (ex) {
|
2013-03-07 11:30:03 +04:00
|
|
|
// Tab focus can fail if the tab or target is closed.
|
2012-09-26 21:07:57 +04:00
|
|
|
}
|
2012-05-10 17:15:10 +04:00
|
|
|
|
2013-01-11 21:31:09 +04:00
|
|
|
let id = WebConsoleUtils.supportsString(this.hudId);
|
|
|
|
Services.obs.notifyObservers(id, "web-console-destroyed", null);
|
|
|
|
this._destroyer.resolve(null);
|
2016-02-17 01:37:45 +03:00
|
|
|
}.bind(this));
|
2012-09-26 21:07:57 +04:00
|
|
|
|
|
|
|
if (this.ui) {
|
2013-01-11 21:31:09 +04:00
|
|
|
this.ui.destroy().then(onDestroy);
|
2012-09-26 21:07:57 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
onDestroy();
|
2012-05-10 17:15:10 +04:00
|
|
|
}
|
2013-01-11 21:31:09 +04:00
|
|
|
|
|
|
|
return this._destroyer.promise;
|
2012-07-26 19:06:04 +04:00
|
|
|
},
|
|
|
|
};
|
2012-05-10 17:15:10 +04:00
|
|
|
|
2013-04-09 13:47:23 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A BrowserConsole instance is an interactive console initialized *per target*
|
|
|
|
* that displays console log data as well as provides an interactive terminal to
|
|
|
|
* manipulate the target's document content.
|
|
|
|
*
|
|
|
|
* This object only wraps the iframe that holds the Browser Console UI. This is
|
|
|
|
* meant to be an integration point between the Firefox UI and the Browser Console
|
|
|
|
* UI and features.
|
|
|
|
*
|
|
|
|
* @constructor
|
|
|
|
* @param object aTarget
|
|
|
|
* The target that the browser console will connect to.
|
|
|
|
* @param nsIDOMWindow aIframeWindow
|
|
|
|
* The window where the browser console UI is already loaded.
|
|
|
|
* @param nsIDOMWindow aChromeWindow
|
|
|
|
* The window of the browser console owner.
|
|
|
|
*/
|
|
|
|
function BrowserConsole()
|
|
|
|
{
|
|
|
|
WebConsole.apply(this, arguments);
|
2013-05-24 14:26:17 +04:00
|
|
|
this._telemetry = new Telemetry();
|
2013-04-09 13:47:23 +04:00
|
|
|
}
|
|
|
|
|
2013-06-21 18:33:56 +04:00
|
|
|
BrowserConsole.prototype = Heritage.extend(WebConsole.prototype,
|
2013-04-09 13:47:23 +04:00
|
|
|
{
|
|
|
|
_browserConsole: true,
|
|
|
|
_bc_init: null,
|
|
|
|
_bc_destroyer: null,
|
|
|
|
|
|
|
|
$init: WebConsole.prototype.init,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initialize the Browser Console instance.
|
|
|
|
*
|
|
|
|
* @return object
|
2013-07-11 11:12:20 +04:00
|
|
|
* A promise for the initialization.
|
2013-04-09 13:47:23 +04:00
|
|
|
*/
|
|
|
|
init: function BC_init()
|
|
|
|
{
|
|
|
|
if (this._bc_init) {
|
|
|
|
return this._bc_init;
|
|
|
|
}
|
|
|
|
|
2013-06-20 17:29:01 +04:00
|
|
|
this.ui._filterPrefsPrefix = BROWSER_CONSOLE_FILTER_PREFS_PREFIX;
|
|
|
|
|
2013-04-09 13:47:23 +04:00
|
|
|
let window = this.iframeWindow;
|
2013-05-30 19:08:14 +04:00
|
|
|
|
|
|
|
// Make sure that the closing of the Browser Console window destroys this
|
|
|
|
// instance.
|
2013-04-09 13:47:23 +04:00
|
|
|
let onClose = () => {
|
|
|
|
window.removeEventListener("unload", onClose);
|
2014-10-23 04:18:31 +04:00
|
|
|
window.removeEventListener("focus", onFocus);
|
2013-04-09 13:47:23 +04:00
|
|
|
this.destroy();
|
|
|
|
};
|
|
|
|
window.addEventListener("unload", onClose);
|
|
|
|
|
2013-05-30 19:08:14 +04:00
|
|
|
// Make sure Ctrl-W closes the Browser Console window.
|
|
|
|
window.document.getElementById("cmd_close").removeAttribute("disabled");
|
2013-05-16 16:35:53 +04:00
|
|
|
|
2013-05-30 19:08:14 +04:00
|
|
|
this._telemetry.toolOpened("browserconsole");
|
2013-04-09 13:47:23 +04:00
|
|
|
|
2014-10-23 04:18:31 +04:00
|
|
|
// Create an onFocus handler just to display the dev edition promo.
|
|
|
|
// This is to prevent race conditions in some environments.
|
|
|
|
// Hook to display promotional Developer Edition doorhanger. Only displayed once.
|
|
|
|
let onFocus = () => showDoorhanger({ window, type: "deveditionpromo" });
|
|
|
|
window.addEventListener("focus", onFocus);
|
|
|
|
|
2013-05-30 19:08:14 +04:00
|
|
|
this._bc_init = this.$init();
|
2013-04-09 13:47:23 +04:00
|
|
|
return this._bc_init;
|
|
|
|
},
|
|
|
|
|
|
|
|
$destroy: WebConsole.prototype.destroy,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Destroy the object.
|
|
|
|
*
|
|
|
|
* @return object
|
2013-07-11 11:12:20 +04:00
|
|
|
* A promise object that is resolved once the Browser Console is closed.
|
2013-04-09 13:47:23 +04:00
|
|
|
*/
|
|
|
|
destroy: function BC_destroy()
|
|
|
|
{
|
|
|
|
if (this._bc_destroyer) {
|
|
|
|
return this._bc_destroyer.promise;
|
|
|
|
}
|
|
|
|
|
2013-05-24 14:26:17 +04:00
|
|
|
this._telemetry.toolClosed("browserconsole");
|
|
|
|
|
2013-07-11 11:12:20 +04:00
|
|
|
this._bc_destroyer = promise.defer();
|
2013-04-09 13:47:23 +04:00
|
|
|
|
|
|
|
let chromeWindow = this.chromeWindow;
|
|
|
|
this.$destroy().then(() =>
|
|
|
|
this.target.client.close(() => {
|
2013-08-02 21:11:57 +04:00
|
|
|
HUDService._browserConsoleID = null;
|
2013-04-09 13:47:23 +04:00
|
|
|
chromeWindow.close();
|
|
|
|
this._bc_destroyer.resolve(null);
|
|
|
|
}));
|
|
|
|
|
|
|
|
return this._bc_destroyer.promise;
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2012-11-30 12:07:59 +04:00
|
|
|
const HUDService = new HUD_SERVICE();
|
2013-08-03 14:29:48 +04:00
|
|
|
|
|
|
|
(() => {
|
2014-01-21 21:40:00 +04:00
|
|
|
let methods = ["openWebConsole", "openBrowserConsole",
|
2013-08-03 14:29:48 +04:00
|
|
|
"toggleBrowserConsole", "getOpenWebConsole",
|
2015-02-12 11:21:02 +03:00
|
|
|
"getBrowserConsole", "getHudByWindow",
|
|
|
|
"openBrowserConsoleOrFocus", "getHudReferenceById"];
|
2013-08-03 14:29:48 +04:00
|
|
|
for (let method of methods) {
|
|
|
|
exports[method] = HUDService[method].bind(HUDService);
|
|
|
|
}
|
|
|
|
|
|
|
|
exports.consoles = HUDService.consoles;
|
|
|
|
exports.lastFinishedRequest = HUDService.lastFinishedRequest;
|
|
|
|
})();
|