2013-09-10 18:43:44 -07:00
|
|
|
|
/* -*- js2-basic-offset: 2; indent-tabs-mode: nil; -*- */
|
2012-07-26 08:06:04 -07:00
|
|
|
|
/* vim: set 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";
|
|
|
|
|
|
2013-08-03 03:29:48 -07:00
|
|
|
|
const {Cc, Ci, Cu} = require("chrome");
|
|
|
|
|
|
|
|
|
|
let WebConsoleUtils = require("devtools/toolkit/webconsole/utils").Utils;
|
|
|
|
|
|
|
|
|
|
loader.lazyServiceGetter(this, "clipboardHelper",
|
|
|
|
|
"@mozilla.org/widget/clipboardhelper;1",
|
|
|
|
|
"nsIClipboardHelper");
|
|
|
|
|
loader.lazyImporter(this, "Services", "resource://gre/modules/Services.jsm");
|
|
|
|
|
loader.lazyGetter(this, "promise", () => require("sdk/core/promise"));
|
|
|
|
|
loader.lazyGetter(this, "EventEmitter", () => require("devtools/shared/event-emitter"));
|
|
|
|
|
loader.lazyGetter(this, "AutocompletePopup",
|
|
|
|
|
() => require("devtools/shared/autocomplete-popup").AutocompletePopup);
|
|
|
|
|
loader.lazyGetter(this, "ToolSidebar",
|
|
|
|
|
() => require("devtools/framework/sidebar").ToolSidebar);
|
|
|
|
|
loader.lazyGetter(this, "NetworkPanel",
|
|
|
|
|
() => require("devtools/webconsole/network-panel").NetworkPanel);
|
2013-08-02 10:19:23 -07:00
|
|
|
|
loader.lazyGetter(this, "ConsoleOutput",
|
|
|
|
|
() => require("devtools/webconsole/console-output").ConsoleOutput);
|
|
|
|
|
loader.lazyGetter(this, "Messages",
|
|
|
|
|
() => require("devtools/webconsole/console-output").Messages);
|
2013-09-25 09:03:17 -07:00
|
|
|
|
loader.lazyImporter(this, "EnvironmentClient", "resource://gre/modules/devtools/dbg-client.jsm");
|
2013-08-13 09:08:30 -07:00
|
|
|
|
loader.lazyImporter(this, "ObjectClient", "resource://gre/modules/devtools/dbg-client.jsm");
|
2013-08-03 03:29:48 -07:00
|
|
|
|
loader.lazyImporter(this, "VariablesView", "resource:///modules/devtools/VariablesView.jsm");
|
|
|
|
|
loader.lazyImporter(this, "VariablesViewController", "resource:///modules/devtools/VariablesViewController.jsm");
|
2013-09-14 03:43:44 -07:00
|
|
|
|
loader.lazyImporter(this, "PluralForm", "resource://gre/modules/PluralForm.jsm");
|
2013-04-09 02:46:30 -07:00
|
|
|
|
|
2012-09-26 10:07:57 -07:00
|
|
|
|
const STRINGS_URI = "chrome://browser/locale/devtools/webconsole.properties";
|
|
|
|
|
let l10n = new WebConsoleUtils.l10n(STRINGS_URI);
|
2012-07-26 08:06:04 -07:00
|
|
|
|
|
2013-09-13 05:06:46 -07:00
|
|
|
|
const XHTML_NS = "http://www.w3.org/1999/xhtml";
|
2012-07-26 08:06:04 -07:00
|
|
|
|
|
2013-09-13 05:06:46 -07:00
|
|
|
|
const MIXED_CONTENT_LEARN_MORE = "https://developer.mozilla.org/docs/Security/MixedContent";
|
2012-07-26 08:06:04 -07:00
|
|
|
|
|
2013-08-29 08:22:18 -07:00
|
|
|
|
const INSECURE_PASSWORDS_LEARN_MORE = "https://developer.mozilla.org/docs/Security/InsecurePasswords";
|
|
|
|
|
|
|
|
|
|
const STRICT_TRANSPORT_SECURITY_LEARN_MORE = "https://developer.mozilla.org/docs/Security/HTTP_Strict_Transport_Security";
|
2013-08-06 07:14:51 -07:00
|
|
|
|
|
2012-09-26 10:02:04 -07:00
|
|
|
|
const HELP_URL = "https://developer.mozilla.org/docs/Tools/Web_Console/Helpers";
|
|
|
|
|
|
2013-04-09 02:46:30 -07:00
|
|
|
|
const VARIABLES_VIEW_URL = "chrome://browser/content/devtools/widgets/VariablesView.xul";
|
|
|
|
|
|
|
|
|
|
const CONSOLE_DIR_VIEW_HEIGHT = 0.6;
|
|
|
|
|
|
|
|
|
|
const IGNORED_SOURCE_URLS = ["debugger eval code", "self-hosted"];
|
|
|
|
|
|
2012-07-26 08:06:04 -07:00
|
|
|
|
// The amount of time in milliseconds that must pass between messages to
|
|
|
|
|
// trigger the display of a new group.
|
|
|
|
|
const NEW_GROUP_DELAY = 5000;
|
|
|
|
|
|
|
|
|
|
// The amount of time in milliseconds that we wait before performing a live
|
|
|
|
|
// search.
|
|
|
|
|
const SEARCH_DELAY = 200;
|
|
|
|
|
|
|
|
|
|
// The number of lines that are displayed in the console output by default, for
|
|
|
|
|
// each category. The user can change this number by adjusting the hidden
|
|
|
|
|
// "devtools.hud.loglimit.{network,cssparser,exception,console}" preferences.
|
|
|
|
|
const DEFAULT_LOG_LIMIT = 200;
|
|
|
|
|
|
|
|
|
|
// The various categories of messages. We start numbering at zero so we can
|
|
|
|
|
// use these as indexes into the MESSAGE_PREFERENCE_KEYS matrix below.
|
|
|
|
|
const CATEGORY_NETWORK = 0;
|
|
|
|
|
const CATEGORY_CSS = 1;
|
|
|
|
|
const CATEGORY_JS = 2;
|
|
|
|
|
const CATEGORY_WEBDEV = 3;
|
|
|
|
|
const CATEGORY_INPUT = 4; // always on
|
|
|
|
|
const CATEGORY_OUTPUT = 5; // always on
|
2013-04-22 18:07:36 -07:00
|
|
|
|
const CATEGORY_SECURITY = 6;
|
2012-07-26 08:06:04 -07:00
|
|
|
|
|
|
|
|
|
// The possible message severities. As before, we start at zero so we can use
|
|
|
|
|
// these as indexes into MESSAGE_PREFERENCE_KEYS.
|
|
|
|
|
const SEVERITY_ERROR = 0;
|
|
|
|
|
const SEVERITY_WARNING = 1;
|
|
|
|
|
const SEVERITY_INFO = 2;
|
|
|
|
|
const SEVERITY_LOG = 3;
|
|
|
|
|
|
|
|
|
|
// The fragment of a CSS class name that identifies each category.
|
|
|
|
|
const CATEGORY_CLASS_FRAGMENTS = [
|
|
|
|
|
"network",
|
|
|
|
|
"cssparser",
|
|
|
|
|
"exception",
|
|
|
|
|
"console",
|
|
|
|
|
"input",
|
|
|
|
|
"output",
|
2013-04-22 18:07:36 -07:00
|
|
|
|
"security",
|
2012-07-26 08:06:04 -07:00
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
// The fragment of a CSS class name that identifies each severity.
|
|
|
|
|
const SEVERITY_CLASS_FRAGMENTS = [
|
|
|
|
|
"error",
|
|
|
|
|
"warn",
|
|
|
|
|
"info",
|
|
|
|
|
"log",
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
// The preference keys to use for each category/severity combination, indexed
|
|
|
|
|
// first by category (rows) and then by severity (columns).
|
|
|
|
|
//
|
|
|
|
|
// Most of these rather idiosyncratic names are historical and predate the
|
|
|
|
|
// division of message type into "category" and "severity".
|
|
|
|
|
const MESSAGE_PREFERENCE_KEYS = [
|
|
|
|
|
// Error Warning Info Log
|
2013-07-09 07:45:56 -07:00
|
|
|
|
[ "network", "netwarn", null, "networkinfo", ], // Network
|
2012-07-26 08:06:04 -07:00
|
|
|
|
[ "csserror", "cssparser", null, null, ], // CSS
|
2013-06-19 12:04:05 -07:00
|
|
|
|
[ "exception", "jswarn", null, "jslog", ], // JS
|
2012-07-26 08:06:04 -07:00
|
|
|
|
[ "error", "warn", "info", "log", ], // Web Developer
|
|
|
|
|
[ null, null, null, null, ], // Input
|
|
|
|
|
[ null, null, null, null, ], // Output
|
2013-04-22 18:07:36 -07:00
|
|
|
|
[ "secerror", "secwarn", null, null, ], // Security
|
2012-07-26 08:06:04 -07:00
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
// A mapping from the console API log event levels to the Web Console
|
|
|
|
|
// severities.
|
|
|
|
|
const LEVELS = {
|
|
|
|
|
error: SEVERITY_ERROR,
|
|
|
|
|
warn: SEVERITY_WARNING,
|
|
|
|
|
info: SEVERITY_INFO,
|
|
|
|
|
log: SEVERITY_LOG,
|
|
|
|
|
trace: SEVERITY_LOG,
|
|
|
|
|
debug: SEVERITY_LOG,
|
|
|
|
|
dir: SEVERITY_LOG,
|
|
|
|
|
group: SEVERITY_LOG,
|
|
|
|
|
groupCollapsed: SEVERITY_LOG,
|
|
|
|
|
groupEnd: SEVERITY_LOG,
|
|
|
|
|
time: SEVERITY_LOG,
|
|
|
|
|
timeEnd: SEVERITY_LOG
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// The lowest HTTP response code (inclusive) that is considered an error.
|
|
|
|
|
const MIN_HTTP_ERROR_CODE = 400;
|
|
|
|
|
// The highest HTTP response code (inclusive) that is considered an error.
|
|
|
|
|
const MAX_HTTP_ERROR_CODE = 599;
|
|
|
|
|
|
|
|
|
|
// Constants used for defining the direction of JSTerm input history navigation.
|
|
|
|
|
const HISTORY_BACK = -1;
|
|
|
|
|
const HISTORY_FORWARD = 1;
|
|
|
|
|
|
|
|
|
|
// The indent of a console group in pixels.
|
|
|
|
|
const GROUP_INDENT = 12;
|
|
|
|
|
|
|
|
|
|
// The number of messages to display in a single display update. If we display
|
|
|
|
|
// too many messages at once we slow the Firefox UI too much.
|
|
|
|
|
const MESSAGES_IN_INTERVAL = DEFAULT_LOG_LIMIT;
|
|
|
|
|
|
|
|
|
|
// The delay between display updates - tells how often we should *try* to push
|
|
|
|
|
// new messages to screen. This value is optimistic, updates won't always
|
|
|
|
|
// happen. Keep this low so the Web Console output feels live.
|
|
|
|
|
const OUTPUT_INTERVAL = 50; // milliseconds
|
|
|
|
|
|
|
|
|
|
// When the output queue has more than MESSAGES_IN_INTERVAL items we throttle
|
|
|
|
|
// output updates to this number of milliseconds. So during a lot of output we
|
|
|
|
|
// update every N milliseconds given here.
|
|
|
|
|
const THROTTLE_UPDATES = 1000; // milliseconds
|
|
|
|
|
|
|
|
|
|
// The preference prefix for all of the Web Console filters.
|
|
|
|
|
const FILTER_PREFS_PREFIX = "devtools.webconsole.filter.";
|
|
|
|
|
|
2012-08-22 13:18:48 -07:00
|
|
|
|
// The minimum font size.
|
|
|
|
|
const MIN_FONT_SIZE = 10;
|
|
|
|
|
|
2013-04-11 05:27:49 -07:00
|
|
|
|
// The maximum length of strings to be displayed by the Web Console.
|
|
|
|
|
const MAX_LONG_STRING_LENGTH = 200000;
|
|
|
|
|
|
2012-11-16 10:16:18 -08:00
|
|
|
|
const PREF_CONNECTION_TIMEOUT = "devtools.debugger.remote-timeout";
|
2013-06-03 10:57:13 -07:00
|
|
|
|
const PREF_PERSISTLOG = "devtools.webconsole.persistlog";
|
2012-11-16 10:16:18 -08:00
|
|
|
|
|
2012-07-26 08:06:04 -07:00
|
|
|
|
/**
|
2013-01-11 09:31:09 -08:00
|
|
|
|
* A WebConsoleFrame instance is an interactive console initialized *per target*
|
2012-07-26 08:06:04 -07:00
|
|
|
|
* that displays console log data as well as provides an interactive terminal to
|
2013-01-11 09:31:09 -08:00
|
|
|
|
* manipulate the target's document content.
|
2012-07-26 08:06:04 -07:00
|
|
|
|
*
|
|
|
|
|
* The WebConsoleFrame is responsible for the actual Web Console UI
|
|
|
|
|
* implementation.
|
|
|
|
|
*
|
2013-08-02 10:11:57 -07:00
|
|
|
|
* @constructor
|
2012-07-26 08:06:04 -07:00
|
|
|
|
* @param object aWebConsoleOwner
|
|
|
|
|
* The WebConsole owner object.
|
|
|
|
|
*/
|
2012-11-30 00:07:59 -08:00
|
|
|
|
function WebConsoleFrame(aWebConsoleOwner)
|
2012-07-26 08:06:04 -07:00
|
|
|
|
{
|
|
|
|
|
this.owner = aWebConsoleOwner;
|
|
|
|
|
this.hudId = this.owner.hudId;
|
2013-08-03 03:29:48 -07:00
|
|
|
|
this.window = this.owner.iframeWindow;
|
2012-07-26 08:06:04 -07:00
|
|
|
|
|
2013-04-22 18:07:36 -07:00
|
|
|
|
this._repeatNodes = {};
|
2012-07-26 08:06:04 -07:00
|
|
|
|
this._outputQueue = [];
|
|
|
|
|
this._pruneCategoriesQueue = {};
|
|
|
|
|
this._networkRequests = {};
|
2013-06-20 06:29:01 -07:00
|
|
|
|
this.filterPrefs = {};
|
2012-07-26 08:06:04 -07:00
|
|
|
|
|
2013-08-02 10:19:23 -07:00
|
|
|
|
this.output = new ConsoleOutput(this);
|
|
|
|
|
|
2012-07-26 08:06:04 -07:00
|
|
|
|
this._toggleFilter = this._toggleFilter.bind(this);
|
2012-10-05 09:15:51 -07:00
|
|
|
|
this._flushMessageQueue = this._flushMessageQueue.bind(this);
|
|
|
|
|
|
|
|
|
|
this._outputTimer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
|
|
|
|
|
this._outputTimerInitialized = false;
|
2013-04-10 08:22:29 -07:00
|
|
|
|
|
|
|
|
|
EventEmitter.decorate(this);
|
2012-07-26 08:06:04 -07:00
|
|
|
|
}
|
2013-08-03 03:29:48 -07:00
|
|
|
|
exports.WebConsoleFrame = WebConsoleFrame;
|
2012-07-26 08:06:04 -07:00
|
|
|
|
|
|
|
|
|
WebConsoleFrame.prototype = {
|
|
|
|
|
/**
|
|
|
|
|
* The WebConsole instance that owns this frame.
|
2013-08-03 03:29:48 -07:00
|
|
|
|
* @see hudservice.js::WebConsole
|
2012-07-26 08:06:04 -07:00
|
|
|
|
* @type object
|
|
|
|
|
*/
|
|
|
|
|
owner: null,
|
|
|
|
|
|
2012-09-26 10:07:57 -07:00
|
|
|
|
/**
|
|
|
|
|
* Proxy between the Web Console and the remote Web Console instance. This
|
|
|
|
|
* object holds methods used for connecting, listening and disconnecting from
|
|
|
|
|
* the remote server, using the remote debugging protocol.
|
|
|
|
|
*
|
|
|
|
|
* @see WebConsoleConnectionProxy
|
|
|
|
|
* @type object
|
|
|
|
|
*/
|
|
|
|
|
proxy: null,
|
|
|
|
|
|
2012-07-26 08:06:04 -07:00
|
|
|
|
/**
|
|
|
|
|
* Getter for the xul:popupset that holds any popups we open.
|
|
|
|
|
* @type nsIDOMElement
|
|
|
|
|
*/
|
|
|
|
|
get popupset() this.owner.mainPopupSet,
|
|
|
|
|
|
2013-04-09 02:47:23 -07:00
|
|
|
|
/**
|
2013-07-11 00:12:20 -07:00
|
|
|
|
* Holds the initialization promise object.
|
2013-04-09 02:47:23 -07:00
|
|
|
|
* @private
|
|
|
|
|
* @type object
|
|
|
|
|
*/
|
|
|
|
|
_initDefer: null,
|
|
|
|
|
|
2012-07-26 08:06:04 -07:00
|
|
|
|
/**
|
|
|
|
|
* Holds the network requests currently displayed by the Web Console. Each key
|
|
|
|
|
* represents the connection ID and the value is network request information.
|
|
|
|
|
* @private
|
|
|
|
|
* @type object
|
|
|
|
|
*/
|
|
|
|
|
_networkRequests: null,
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Last time when we displayed any message in the output.
|
|
|
|
|
*
|
|
|
|
|
* @private
|
|
|
|
|
* @type number
|
|
|
|
|
* Timestamp in milliseconds since the Unix epoch.
|
|
|
|
|
*/
|
|
|
|
|
_lastOutputFlush: 0,
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Message nodes are stored here in a queue for later display.
|
|
|
|
|
*
|
|
|
|
|
* @private
|
|
|
|
|
* @type array
|
|
|
|
|
*/
|
|
|
|
|
_outputQueue: null,
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Keep track of the categories we need to prune from time to time.
|
|
|
|
|
*
|
|
|
|
|
* @private
|
|
|
|
|
* @type array
|
|
|
|
|
*/
|
|
|
|
|
_pruneCategoriesQueue: null,
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Function invoked whenever the output queue is emptied. This is used by some
|
|
|
|
|
* tests.
|
|
|
|
|
*
|
|
|
|
|
* @private
|
|
|
|
|
* @type function
|
|
|
|
|
*/
|
|
|
|
|
_flushCallback: null,
|
|
|
|
|
|
2012-10-05 09:15:51 -07:00
|
|
|
|
/**
|
|
|
|
|
* Timer used for flushing the messages output queue.
|
|
|
|
|
*
|
|
|
|
|
* @private
|
|
|
|
|
* @type nsITimer
|
|
|
|
|
*/
|
|
|
|
|
_outputTimer: null,
|
|
|
|
|
_outputTimerInitialized: null,
|
|
|
|
|
|
2012-07-26 08:06:04 -07:00
|
|
|
|
/**
|
2013-04-22 18:07:36 -07:00
|
|
|
|
* Store for tracking repeated nodes.
|
2012-07-26 08:06:04 -07:00
|
|
|
|
* @private
|
|
|
|
|
* @type object
|
|
|
|
|
*/
|
2013-04-22 18:07:36 -07:00
|
|
|
|
_repeatNodes: null,
|
2012-07-26 08:06:04 -07:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Preferences for filtering messages by type.
|
|
|
|
|
* @see this._initDefaultFilterPrefs()
|
|
|
|
|
* @type object
|
|
|
|
|
*/
|
|
|
|
|
filterPrefs: null,
|
|
|
|
|
|
2013-06-20 06:29:01 -07:00
|
|
|
|
/**
|
|
|
|
|
* Prefix used for filter preferences.
|
|
|
|
|
* @private
|
|
|
|
|
* @type string
|
|
|
|
|
*/
|
|
|
|
|
_filterPrefsPrefix: FILTER_PREFS_PREFIX,
|
|
|
|
|
|
2012-07-26 08:06:04 -07:00
|
|
|
|
/**
|
|
|
|
|
* The nesting depth of the currently active console group.
|
|
|
|
|
*/
|
|
|
|
|
groupDepth: 0,
|
|
|
|
|
|
2012-10-05 04:54:43 -07:00
|
|
|
|
/**
|
2013-01-11 09:31:09 -08:00
|
|
|
|
* The current target location.
|
2012-10-05 04:54:43 -07:00
|
|
|
|
* @type string
|
|
|
|
|
*/
|
|
|
|
|
contentLocation: "",
|
|
|
|
|
|
2012-07-26 08:06:04 -07:00
|
|
|
|
/**
|
|
|
|
|
* The JSTerm object that manage the console's input.
|
|
|
|
|
* @see JSTerm
|
|
|
|
|
* @type object
|
|
|
|
|
*/
|
|
|
|
|
jsterm: null,
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The element that holds all of the messages we display.
|
|
|
|
|
* @type nsIDOMElement
|
|
|
|
|
*/
|
|
|
|
|
outputNode: null,
|
|
|
|
|
|
2013-08-02 10:19:23 -07:00
|
|
|
|
/**
|
|
|
|
|
* The ConsoleOutput instance that manages all output.
|
|
|
|
|
* @type object
|
|
|
|
|
*/
|
|
|
|
|
output: null,
|
|
|
|
|
|
2012-07-26 08:06:04 -07:00
|
|
|
|
/**
|
|
|
|
|
* The input element that allows the user to filter messages by string.
|
|
|
|
|
* @type nsIDOMElement
|
|
|
|
|
*/
|
|
|
|
|
filterBox: null,
|
|
|
|
|
|
2012-09-26 10:02:04 -07:00
|
|
|
|
/**
|
|
|
|
|
* Getter for the debugger WebConsoleClient.
|
|
|
|
|
* @type object
|
|
|
|
|
*/
|
|
|
|
|
get webConsoleClient() this.proxy ? this.proxy.webConsoleClient : null,
|
|
|
|
|
|
2013-01-11 09:31:09 -08:00
|
|
|
|
_destroyer: null,
|
|
|
|
|
|
2013-06-26 13:35:39 -07:00
|
|
|
|
// Used in tests.
|
2012-07-26 08:06:04 -07:00
|
|
|
|
_saveRequestAndResponseBodies: false,
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Tells whether to save the bodies of network requests and responses.
|
|
|
|
|
* Disabled by default to save memory.
|
2013-06-26 13:35:39 -07:00
|
|
|
|
*
|
|
|
|
|
* @return boolean
|
|
|
|
|
* The saveRequestAndResponseBodies pref value.
|
2012-07-26 08:06:04 -07:00
|
|
|
|
*/
|
2013-06-26 13:35:39 -07:00
|
|
|
|
getSaveRequestAndResponseBodies:
|
|
|
|
|
function WCF_getSaveRequestAndResponseBodies() {
|
2013-07-11 00:12:20 -07:00
|
|
|
|
let deferred = promise.defer();
|
2013-06-26 13:35:39 -07:00
|
|
|
|
let toGet = [
|
|
|
|
|
"NetworkMonitor.saveRequestAndResponseBodies"
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
// Make sure the web console client connection is established first.
|
|
|
|
|
this.webConsoleClient.getPreferences(toGet, aResponse => {
|
|
|
|
|
if (!aResponse.error) {
|
|
|
|
|
this._saveRequestAndResponseBodies = aResponse.preferences[toGet[0]];
|
|
|
|
|
deferred.resolve(this._saveRequestAndResponseBodies);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
deferred.reject(aResponse.error);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return deferred.promise;
|
|
|
|
|
},
|
2012-07-26 08:06:04 -07:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Setter for saving of network request and response bodies.
|
|
|
|
|
*
|
|
|
|
|
* @param boolean aValue
|
|
|
|
|
* The new value you want to set.
|
|
|
|
|
*/
|
2013-06-26 13:35:39 -07:00
|
|
|
|
setSaveRequestAndResponseBodies:
|
|
|
|
|
function WCF_setSaveRequestAndResponseBodies(aValue) {
|
2013-07-11 00:12:20 -07:00
|
|
|
|
let deferred = promise.defer();
|
2012-10-05 04:54:43 -07:00
|
|
|
|
let newValue = !!aValue;
|
2013-06-26 13:35:39 -07:00
|
|
|
|
let toSet = {
|
2012-10-05 04:54:43 -07:00
|
|
|
|
"NetworkMonitor.saveRequestAndResponseBodies": newValue,
|
2012-07-26 08:06:04 -07:00
|
|
|
|
};
|
|
|
|
|
|
2013-06-26 13:35:39 -07:00
|
|
|
|
// Make sure the web console client connection is established first.
|
|
|
|
|
this.webConsoleClient.setPreferences(toSet, aResponse => {
|
2012-10-05 04:54:43 -07:00
|
|
|
|
if (!aResponse.error) {
|
|
|
|
|
this._saveRequestAndResponseBodies = newValue;
|
2013-06-26 13:35:39 -07:00
|
|
|
|
deferred.resolve(aResponse);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
deferred.reject(aResponse.error);
|
2012-10-05 04:54:43 -07:00
|
|
|
|
}
|
2013-06-26 13:35:39 -07:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return deferred.promise;
|
2012-07-26 08:06:04 -07:00
|
|
|
|
},
|
|
|
|
|
|
2013-06-03 10:57:13 -07:00
|
|
|
|
/**
|
2013-06-23 06:11:00 -07:00
|
|
|
|
* Getter for the persistent logging preference.
|
2013-06-03 10:57:13 -07:00
|
|
|
|
* @type boolean
|
|
|
|
|
*/
|
|
|
|
|
get persistLog() {
|
2013-06-23 06:11:00 -07:00
|
|
|
|
return Services.prefs.getBoolPref(PREF_PERSISTLOG);
|
2013-06-03 10:57:13 -07:00
|
|
|
|
},
|
|
|
|
|
|
2012-09-26 10:07:57 -07:00
|
|
|
|
/**
|
2013-01-11 09:31:09 -08:00
|
|
|
|
* Initialize the WebConsoleFrame instance.
|
|
|
|
|
* @return object
|
2013-07-11 00:12:20 -07:00
|
|
|
|
* A promise object for the initialization.
|
2012-09-26 10:07:57 -07:00
|
|
|
|
*/
|
2013-01-11 09:31:09 -08:00
|
|
|
|
init: function WCF_init()
|
2012-09-26 10:07:57 -07:00
|
|
|
|
{
|
2013-01-11 09:31:09 -08:00
|
|
|
|
this._initUI();
|
|
|
|
|
return this._initConnection();
|
2012-09-26 10:07:57 -07:00
|
|
|
|
},
|
|
|
|
|
|
2012-11-16 10:16:18 -08:00
|
|
|
|
/**
|
2013-01-11 09:31:09 -08:00
|
|
|
|
* Connect to the server using the remote debugging protocol.
|
|
|
|
|
*
|
2012-11-16 10:16:18 -08:00
|
|
|
|
* @private
|
2013-01-11 09:31:09 -08:00
|
|
|
|
* @return object
|
2013-07-11 00:12:20 -07:00
|
|
|
|
* A promise object that is resolved/reject based on the connection
|
2013-01-11 09:31:09 -08:00
|
|
|
|
* result.
|
2012-11-16 10:16:18 -08:00
|
|
|
|
*/
|
2013-01-11 09:31:09 -08:00
|
|
|
|
_initConnection: function WCF__initConnection()
|
2012-11-16 10:16:18 -08:00
|
|
|
|
{
|
2013-04-09 02:47:23 -07:00
|
|
|
|
if (this._initDefer) {
|
|
|
|
|
return this._initDefer.promise;
|
|
|
|
|
}
|
2012-11-16 10:16:18 -08:00
|
|
|
|
|
2013-07-11 00:12:20 -07:00
|
|
|
|
this._initDefer = promise.defer();
|
2013-01-11 09:31:09 -08:00
|
|
|
|
this.proxy = new WebConsoleConnectionProxy(this, this.owner.target);
|
2012-11-16 10:16:18 -08:00
|
|
|
|
|
2013-04-09 02:47:23 -07:00
|
|
|
|
this.proxy.connect().then(() => { // on success
|
|
|
|
|
this._initDefer.resolve(this);
|
|
|
|
|
}, (aReason) => { // on failure
|
2013-01-11 09:31:09 -08:00
|
|
|
|
let node = this.createMessageNode(CATEGORY_JS, SEVERITY_ERROR,
|
|
|
|
|
aReason.error + ": " + aReason.message);
|
|
|
|
|
this.outputMessage(CATEGORY_JS, node);
|
2013-04-09 02:47:23 -07:00
|
|
|
|
this._initDefer.reject(aReason);
|
|
|
|
|
}).then(() => {
|
2013-01-11 09:31:09 -08:00
|
|
|
|
let id = WebConsoleUtils.supportsString(this.hudId);
|
|
|
|
|
Services.obs.notifyObservers(id, "web-console-created", null);
|
2013-04-09 02:47:23 -07:00
|
|
|
|
});
|
2013-01-11 09:31:09 -08:00
|
|
|
|
|
2013-04-09 02:47:23 -07:00
|
|
|
|
return this._initDefer.promise;
|
2012-11-16 10:16:18 -08:00
|
|
|
|
},
|
|
|
|
|
|
2012-07-26 08:06:04 -07:00
|
|
|
|
/**
|
|
|
|
|
* Find the Web Console UI elements and setup event listeners as needed.
|
|
|
|
|
* @private
|
|
|
|
|
*/
|
|
|
|
|
_initUI: function WCF__initUI()
|
|
|
|
|
{
|
2013-01-11 09:31:09 -08:00
|
|
|
|
this.document = this.window.document;
|
|
|
|
|
this.rootElement = this.document.documentElement;
|
|
|
|
|
|
|
|
|
|
this._initDefaultFilterPrefs();
|
|
|
|
|
|
|
|
|
|
// Register the controller to handle "select all" properly.
|
|
|
|
|
this._commandController = new CommandController(this);
|
|
|
|
|
this.window.controllers.insertControllerAt(0, this._commandController);
|
|
|
|
|
|
2013-08-02 10:11:57 -07:00
|
|
|
|
this._contextMenuHandler = new ConsoleContextMenu(this);
|
|
|
|
|
|
2012-07-26 08:06:04 -07:00
|
|
|
|
let doc = this.document;
|
|
|
|
|
|
|
|
|
|
this.filterBox = doc.querySelector(".hud-filter-box");
|
2013-09-05 09:34:22 -07:00
|
|
|
|
this.outputNode = doc.getElementById("output-container");
|
2012-08-22 13:18:48 -07:00
|
|
|
|
this.completeNode = doc.querySelector(".jsterm-complete-node");
|
|
|
|
|
this.inputNode = doc.querySelector(".jsterm-input-node");
|
2012-07-26 08:06:04 -07:00
|
|
|
|
|
|
|
|
|
this._setFilterTextBoxEvents();
|
|
|
|
|
this._initFilterButtons();
|
|
|
|
|
|
2013-09-15 02:12:27 -07:00
|
|
|
|
let fontSize = this.owner._browserConsole ?
|
|
|
|
|
Services.prefs.getIntPref("devtools.webconsole.fontSize") : 0;
|
2012-08-22 13:18:48 -07:00
|
|
|
|
|
|
|
|
|
if (fontSize != 0) {
|
|
|
|
|
fontSize = Math.max(MIN_FONT_SIZE, fontSize);
|
|
|
|
|
|
|
|
|
|
this.outputNode.style.fontSize = fontSize + "px";
|
|
|
|
|
this.completeNode.style.fontSize = fontSize + "px";
|
|
|
|
|
this.inputNode.style.fontSize = fontSize + "px";
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-15 02:12:27 -07:00
|
|
|
|
if (this.owner._browserConsole) {
|
|
|
|
|
for (let id of ["Enlarge", "Reduce", "Reset"]) {
|
|
|
|
|
this.document.getElementById("cmd_fullZoom" + id)
|
|
|
|
|
.removeAttribute("disabled");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-26 13:35:39 -07:00
|
|
|
|
let updateSaveBodiesPrefUI = (aElement) => {
|
|
|
|
|
this.getSaveRequestAndResponseBodies().then(aValue => {
|
|
|
|
|
aElement.setAttribute("checked", aValue);
|
|
|
|
|
this.emit("save-bodies-ui-toggled");
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let reverseSaveBodiesPref = ({ target: aElement }) => {
|
|
|
|
|
this.getSaveRequestAndResponseBodies().then(aValue => {
|
|
|
|
|
this.setSaveRequestAndResponseBodies(!aValue);
|
|
|
|
|
aElement.setAttribute("checked", aValue);
|
|
|
|
|
this.emit("save-bodies-pref-reversed");
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2012-07-26 08:06:04 -07:00
|
|
|
|
let saveBodies = doc.getElementById("saveBodies");
|
2013-06-26 13:35:39 -07:00
|
|
|
|
saveBodies.addEventListener("click", reverseSaveBodiesPref);
|
2012-09-07 15:08:54 -07:00
|
|
|
|
saveBodies.disabled = !this.getFilterState("networkinfo") &&
|
|
|
|
|
!this.getFilterState("network");
|
2012-07-26 08:06:04 -07:00
|
|
|
|
|
2012-09-07 15:08:54 -07:00
|
|
|
|
let saveBodiesContextMenu = doc.getElementById("saveBodiesContextMenu");
|
2013-06-26 13:35:39 -07:00
|
|
|
|
saveBodiesContextMenu.addEventListener("click", reverseSaveBodiesPref);
|
2012-09-07 15:08:54 -07:00
|
|
|
|
saveBodiesContextMenu.disabled = !this.getFilterState("networkinfo") &&
|
|
|
|
|
!this.getFilterState("network");
|
|
|
|
|
|
2013-06-26 13:35:39 -07:00
|
|
|
|
saveBodies.parentNode.addEventListener("popupshowing", () => {
|
|
|
|
|
updateSaveBodiesPrefUI(saveBodies);
|
|
|
|
|
saveBodies.disabled = !this.getFilterState("networkinfo") &&
|
|
|
|
|
!this.getFilterState("network");
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
saveBodiesContextMenu.parentNode.addEventListener("popupshowing", () => {
|
|
|
|
|
updateSaveBodiesPrefUI(saveBodiesContextMenu);
|
2012-09-07 15:08:54 -07:00
|
|
|
|
saveBodiesContextMenu.disabled = !this.getFilterState("networkinfo") &&
|
|
|
|
|
!this.getFilterState("network");
|
2013-06-26 13:35:39 -07:00
|
|
|
|
});
|
2012-07-26 08:06:04 -07:00
|
|
|
|
|
|
|
|
|
let clearButton = doc.getElementsByClassName("webconsole-clear-console-button")[0];
|
2013-06-26 13:35:39 -07:00
|
|
|
|
clearButton.addEventListener("command", () => {
|
2012-09-26 10:02:04 -07:00
|
|
|
|
this.owner._onClearButton();
|
|
|
|
|
this.jsterm.clearOutput(true);
|
2013-06-26 13:35:39 -07:00
|
|
|
|
});
|
2013-01-11 09:31:09 -08:00
|
|
|
|
|
|
|
|
|
this.jsterm = new JSTerm(this);
|
|
|
|
|
this.jsterm.init();
|
|
|
|
|
this.jsterm.inputNode.focus();
|
2012-07-26 08:06:04 -07:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Initialize the default filter preferences.
|
|
|
|
|
* @private
|
|
|
|
|
*/
|
|
|
|
|
_initDefaultFilterPrefs: function WCF__initDefaultFilterPrefs()
|
|
|
|
|
{
|
2013-06-20 06:29:01 -07:00
|
|
|
|
let prefs = ["network", "networkinfo", "csserror", "cssparser", "exception",
|
|
|
|
|
"jswarn", "jslog", "error", "info", "warn", "log", "secerror",
|
2013-07-09 07:45:56 -07:00
|
|
|
|
"secwarn", "netwarn"];
|
2013-06-20 06:29:01 -07:00
|
|
|
|
for (let pref of prefs) {
|
|
|
|
|
this.filterPrefs[pref] = Services.prefs
|
|
|
|
|
.getBoolPref(this._filterPrefsPrefix + pref);
|
|
|
|
|
}
|
2012-07-26 08:06:04 -07:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
2013-06-20 06:29:01 -07:00
|
|
|
|
* Sets the events for the filter input field.
|
2012-07-26 08:06:04 -07:00
|
|
|
|
* @private
|
|
|
|
|
*/
|
|
|
|
|
_setFilterTextBoxEvents: function WCF__setFilterTextBoxEvents()
|
|
|
|
|
{
|
2013-06-20 06:29:01 -07:00
|
|
|
|
let timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
|
2012-07-26 08:06:04 -07:00
|
|
|
|
let timerEvent = this.adjustVisibilityOnSearchStringChange.bind(this);
|
|
|
|
|
|
|
|
|
|
let onChange = function _onChange() {
|
|
|
|
|
// To improve responsiveness, we let the user finish typing before we
|
|
|
|
|
// perform the search.
|
2013-06-20 06:29:01 -07:00
|
|
|
|
timer.cancel();
|
2012-07-26 08:06:04 -07:00
|
|
|
|
timer.initWithCallback(timerEvent, SEARCH_DELAY,
|
|
|
|
|
Ci.nsITimer.TYPE_ONE_SHOT);
|
2013-06-20 06:29:01 -07:00
|
|
|
|
};
|
2012-07-26 08:06:04 -07:00
|
|
|
|
|
|
|
|
|
this.filterBox.addEventListener("command", onChange, false);
|
|
|
|
|
this.filterBox.addEventListener("input", onChange, false);
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Creates one of the filter buttons on the toolbar.
|
|
|
|
|
*
|
|
|
|
|
* @private
|
|
|
|
|
* @param nsIDOMNode aParent
|
|
|
|
|
* The node to which the filter button should be appended.
|
|
|
|
|
* @param object aDescriptor
|
|
|
|
|
* A descriptor that contains info about the button. Contains "name",
|
|
|
|
|
* "category", and "prefKey" properties, and optionally a "severities"
|
|
|
|
|
* property.
|
|
|
|
|
*/
|
|
|
|
|
_initFilterButtons: function WCF__initFilterButtons()
|
|
|
|
|
{
|
|
|
|
|
let categories = this.document
|
|
|
|
|
.querySelectorAll(".webconsole-filter-button[category]");
|
|
|
|
|
Array.forEach(categories, function(aButton) {
|
|
|
|
|
aButton.addEventListener("click", this._toggleFilter, false);
|
|
|
|
|
|
|
|
|
|
let someChecked = false;
|
|
|
|
|
let severities = aButton.querySelectorAll("menuitem[prefKey]");
|
|
|
|
|
Array.forEach(severities, function(aMenuItem) {
|
|
|
|
|
aMenuItem.addEventListener("command", this._toggleFilter, false);
|
|
|
|
|
|
|
|
|
|
let prefKey = aMenuItem.getAttribute("prefKey");
|
|
|
|
|
let checked = this.filterPrefs[prefKey];
|
|
|
|
|
aMenuItem.setAttribute("checked", checked);
|
|
|
|
|
someChecked = someChecked || checked;
|
|
|
|
|
}, this);
|
|
|
|
|
|
|
|
|
|
aButton.setAttribute("checked", someChecked);
|
|
|
|
|
}, this);
|
2013-06-19 12:04:05 -07:00
|
|
|
|
|
|
|
|
|
if (!this.owner._browserConsole) {
|
|
|
|
|
// The Browser Console displays nsIConsoleMessages which are messages that
|
|
|
|
|
// end up in the JS category, but they are not errors or warnings, they
|
|
|
|
|
// are just log messages. The Web Console does not show such messages.
|
|
|
|
|
let jslog = this.document.querySelector("menuitem[prefKey=jslog]");
|
|
|
|
|
jslog.hidden = true;
|
|
|
|
|
}
|
2013-08-02 10:11:57 -07:00
|
|
|
|
|
|
|
|
|
if (Services.appinfo.OS == "Darwin") {
|
|
|
|
|
let net = this.document.querySelector("toolbarbutton[category=net]");
|
|
|
|
|
let accesskey = net.getAttribute("accesskeyMacOSX");
|
|
|
|
|
net.setAttribute("accesskey", accesskey);
|
2013-10-03 13:25:22 -07:00
|
|
|
|
|
|
|
|
|
let logging = this.document.querySelector("toolbarbutton[category=logging]");
|
|
|
|
|
logging.removeAttribute("accesskey");
|
2013-08-02 10:11:57 -07:00
|
|
|
|
}
|
2012-07-26 08:06:04 -07:00
|
|
|
|
},
|
|
|
|
|
|
2012-08-22 13:18:48 -07:00
|
|
|
|
/**
|
|
|
|
|
* Increase, decrease or reset the font size.
|
|
|
|
|
*
|
|
|
|
|
* @param string size
|
|
|
|
|
* The size of the font change. Accepted values are "+" and "-".
|
|
|
|
|
* An unmatched size assumes a font reset.
|
|
|
|
|
*/
|
|
|
|
|
changeFontSize: function WCF_changeFontSize(aSize)
|
|
|
|
|
{
|
|
|
|
|
let fontSize = this.window
|
|
|
|
|
.getComputedStyle(this.outputNode, null)
|
|
|
|
|
.getPropertyValue("font-size").replace("px", "");
|
|
|
|
|
|
|
|
|
|
if (this.outputNode.style.fontSize) {
|
|
|
|
|
fontSize = this.outputNode.style.fontSize.replace("px", "");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (aSize == "+" || aSize == "-") {
|
|
|
|
|
fontSize = parseInt(fontSize, 10);
|
|
|
|
|
|
|
|
|
|
if (aSize == "+") {
|
|
|
|
|
fontSize += 1;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
fontSize -= 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (fontSize < MIN_FONT_SIZE) {
|
|
|
|
|
fontSize = MIN_FONT_SIZE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Services.prefs.setIntPref("devtools.webconsole.fontSize", fontSize);
|
|
|
|
|
fontSize = fontSize + "px";
|
|
|
|
|
|
|
|
|
|
this.completeNode.style.fontSize = fontSize;
|
|
|
|
|
this.inputNode.style.fontSize = fontSize;
|
|
|
|
|
this.outputNode.style.fontSize = fontSize;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
this.completeNode.style.fontSize = "";
|
|
|
|
|
this.inputNode.style.fontSize = "";
|
|
|
|
|
this.outputNode.style.fontSize = "";
|
|
|
|
|
Services.prefs.clearUserPref("devtools.webconsole.fontSize");
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
2012-07-26 08:06:04 -07:00
|
|
|
|
/**
|
|
|
|
|
* The event handler that is called whenever a user switches a filter on or
|
|
|
|
|
* off.
|
|
|
|
|
*
|
|
|
|
|
* @private
|
|
|
|
|
* @param nsIDOMEvent aEvent
|
|
|
|
|
* The event that triggered the filter change.
|
|
|
|
|
*/
|
|
|
|
|
_toggleFilter: function WCF__toggleFilter(aEvent)
|
|
|
|
|
{
|
|
|
|
|
let target = aEvent.target;
|
|
|
|
|
let tagName = target.tagName;
|
|
|
|
|
if (tagName != aEvent.currentTarget.tagName) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch (tagName) {
|
|
|
|
|
case "toolbarbutton": {
|
|
|
|
|
let originalTarget = aEvent.originalTarget;
|
|
|
|
|
let classes = originalTarget.classList;
|
|
|
|
|
|
|
|
|
|
if (originalTarget.localName !== "toolbarbutton") {
|
|
|
|
|
// Oddly enough, the click event is sent to the menu button when
|
|
|
|
|
// selecting a menu item with the mouse. Detect this case and bail
|
|
|
|
|
// out.
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!classes.contains("toolbarbutton-menubutton-button") &&
|
|
|
|
|
originalTarget.getAttribute("type") === "menu-button") {
|
|
|
|
|
// This is a filter button with a drop-down. The user clicked the
|
|
|
|
|
// drop-down, so do nothing. (The menu will automatically appear
|
|
|
|
|
// without our intervention.)
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let state = target.getAttribute("checked") !== "true";
|
|
|
|
|
target.setAttribute("checked", state);
|
|
|
|
|
|
|
|
|
|
// This is a filter button with a drop-down, and the user clicked the
|
|
|
|
|
// main part of the button. Go through all the severities and toggle
|
|
|
|
|
// their associated filters.
|
|
|
|
|
let menuItems = target.querySelectorAll("menuitem");
|
|
|
|
|
for (let i = 0; i < menuItems.length; i++) {
|
|
|
|
|
menuItems[i].setAttribute("checked", state);
|
|
|
|
|
let prefKey = menuItems[i].getAttribute("prefKey");
|
|
|
|
|
this.setFilterState(prefKey, state);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case "menuitem": {
|
|
|
|
|
let state = target.getAttribute("checked") !== "true";
|
|
|
|
|
target.setAttribute("checked", state);
|
|
|
|
|
|
|
|
|
|
let prefKey = target.getAttribute("prefKey");
|
|
|
|
|
this.setFilterState(prefKey, state);
|
|
|
|
|
|
2012-09-07 15:08:54 -07:00
|
|
|
|
// Disable the log response and request body if network logging is off.
|
|
|
|
|
if (prefKey == "networkinfo" || prefKey == "network") {
|
|
|
|
|
let checkState = !this.getFilterState("networkinfo") &&
|
|
|
|
|
!this.getFilterState("network");
|
|
|
|
|
this.document.getElementById("saveBodies").disabled = checkState;
|
|
|
|
|
this.document.getElementById("saveBodiesContextMenu").disabled = checkState;
|
|
|
|
|
}
|
|
|
|
|
|
2012-07-26 08:06:04 -07:00
|
|
|
|
// Adjust the state of the button appropriately.
|
|
|
|
|
let menuPopup = target.parentNode;
|
|
|
|
|
|
|
|
|
|
let someChecked = false;
|
|
|
|
|
let menuItem = menuPopup.firstChild;
|
|
|
|
|
while (menuItem) {
|
2012-09-07 15:08:54 -07:00
|
|
|
|
if (menuItem.hasAttribute("prefKey") &&
|
|
|
|
|
menuItem.getAttribute("checked") === "true") {
|
2012-07-26 08:06:04 -07:00
|
|
|
|
someChecked = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
menuItem = menuItem.nextSibling;
|
|
|
|
|
}
|
|
|
|
|
let toolbarButton = menuPopup.parentNode;
|
|
|
|
|
toolbarButton.setAttribute("checked", someChecked);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Set the filter state for a specific toggle button.
|
|
|
|
|
*
|
|
|
|
|
* @param string aToggleType
|
|
|
|
|
* @param boolean aState
|
|
|
|
|
* @returns void
|
|
|
|
|
*/
|
|
|
|
|
setFilterState: function WCF_setFilterState(aToggleType, aState)
|
|
|
|
|
{
|
|
|
|
|
this.filterPrefs[aToggleType] = aState;
|
|
|
|
|
this.adjustVisibilityForMessageType(aToggleType, aState);
|
2013-06-20 06:29:01 -07:00
|
|
|
|
Services.prefs.setBoolPref(this._filterPrefsPrefix + aToggleType, aState);
|
2012-07-26 08:06:04 -07:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the filter state for a specific toggle button.
|
|
|
|
|
*
|
|
|
|
|
* @param string aToggleType
|
|
|
|
|
* @returns boolean
|
|
|
|
|
*/
|
|
|
|
|
getFilterState: function WCF_getFilterState(aToggleType)
|
|
|
|
|
{
|
|
|
|
|
return this.filterPrefs[aToggleType];
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Check that the passed string matches the filter arguments.
|
|
|
|
|
*
|
|
|
|
|
* @param String aString
|
|
|
|
|
* to search for filter words in.
|
|
|
|
|
* @param String aFilter
|
|
|
|
|
* is a string containing all of the words to filter on.
|
|
|
|
|
* @returns boolean
|
|
|
|
|
*/
|
|
|
|
|
stringMatchesFilters: function WCF_stringMatchesFilters(aString, aFilter)
|
|
|
|
|
{
|
|
|
|
|
if (!aFilter || !aString) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let searchStr = aString.toLowerCase();
|
|
|
|
|
let filterStrings = aFilter.toLowerCase().split(/\s+/);
|
|
|
|
|
return !filterStrings.some(function (f) {
|
|
|
|
|
return searchStr.indexOf(f) == -1;
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Turns the display of log nodes on and off appropriately to reflect the
|
|
|
|
|
* adjustment of the message type filter named by @aPrefKey.
|
|
|
|
|
*
|
|
|
|
|
* @param string aPrefKey
|
|
|
|
|
* The preference key for the message type being filtered: one of the
|
|
|
|
|
* values in the MESSAGE_PREFERENCE_KEYS table.
|
|
|
|
|
* @param boolean aState
|
|
|
|
|
* True if the filter named by @aMessageType is being turned on; false
|
|
|
|
|
* otherwise.
|
|
|
|
|
* @returns void
|
|
|
|
|
*/
|
|
|
|
|
adjustVisibilityForMessageType:
|
|
|
|
|
function WCF_adjustVisibilityForMessageType(aPrefKey, aState)
|
|
|
|
|
{
|
|
|
|
|
let outputNode = this.outputNode;
|
|
|
|
|
let doc = this.document;
|
|
|
|
|
|
2013-09-05 09:34:22 -07:00
|
|
|
|
// Look for message nodes (".message") with the given preference key
|
|
|
|
|
// (filter="error", filter="cssparser", etc.) and add or remove the
|
|
|
|
|
// "filtered-by-type" class, which turns on or off the display.
|
2012-07-26 08:06:04 -07:00
|
|
|
|
|
2013-09-05 09:34:22 -07:00
|
|
|
|
let xpath = ".//*[contains(@class, 'message') and " +
|
|
|
|
|
"@filter='" + aPrefKey + "']";
|
2012-07-26 08:06:04 -07:00
|
|
|
|
let result = doc.evaluate(xpath, outputNode, null,
|
|
|
|
|
Ci.nsIDOMXPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
|
|
|
|
|
for (let i = 0; i < result.snapshotLength; i++) {
|
|
|
|
|
let node = result.snapshotItem(i);
|
|
|
|
|
if (aState) {
|
2013-09-05 09:34:22 -07:00
|
|
|
|
node.classList.remove("filtered-by-type");
|
2012-07-26 08:06:04 -07:00
|
|
|
|
}
|
|
|
|
|
else {
|
2013-09-05 09:34:22 -07:00
|
|
|
|
node.classList.add("filtered-by-type");
|
2012-07-26 08:06:04 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Turns the display of log nodes on and off appropriately to reflect the
|
|
|
|
|
* adjustment of the search string.
|
|
|
|
|
*/
|
|
|
|
|
adjustVisibilityOnSearchStringChange:
|
|
|
|
|
function WCF_adjustVisibilityOnSearchStringChange()
|
|
|
|
|
{
|
2013-09-05 09:34:22 -07:00
|
|
|
|
let nodes = this.outputNode.getElementsByClassName("message");
|
2012-07-26 08:06:04 -07:00
|
|
|
|
let searchString = this.filterBox.value;
|
|
|
|
|
|
|
|
|
|
for (let i = 0, n = nodes.length; i < n; ++i) {
|
|
|
|
|
let node = nodes[i];
|
|
|
|
|
|
|
|
|
|
// hide nodes that match the strings
|
|
|
|
|
let text = node.clipboardText;
|
|
|
|
|
|
|
|
|
|
// if the text matches the words in aSearchString...
|
|
|
|
|
if (this.stringMatchesFilters(text, searchString)) {
|
2013-09-05 09:34:22 -07:00
|
|
|
|
node.classList.remove("filtered-by-string");
|
2012-07-26 08:06:04 -07:00
|
|
|
|
}
|
|
|
|
|
else {
|
2013-09-05 09:34:22 -07:00
|
|
|
|
node.classList.add("filtered-by-string");
|
2012-07-26 08:06:04 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Applies the user's filters to a newly-created message node via CSS
|
|
|
|
|
* classes.
|
|
|
|
|
*
|
|
|
|
|
* @param nsIDOMNode aNode
|
|
|
|
|
* The newly-created message node.
|
|
|
|
|
* @return boolean
|
|
|
|
|
* True if the message was filtered or false otherwise.
|
|
|
|
|
*/
|
|
|
|
|
filterMessageNode: function WCF_filterMessageNode(aNode)
|
|
|
|
|
{
|
|
|
|
|
let isFiltered = false;
|
|
|
|
|
|
|
|
|
|
// Filter by the message type.
|
|
|
|
|
let prefKey = MESSAGE_PREFERENCE_KEYS[aNode.category][aNode.severity];
|
|
|
|
|
if (prefKey && !this.getFilterState(prefKey)) {
|
|
|
|
|
// The node is filtered by type.
|
2013-09-05 09:34:22 -07:00
|
|
|
|
aNode.classList.add("filtered-by-type");
|
2012-07-26 08:06:04 -07:00
|
|
|
|
isFiltered = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Filter on the search string.
|
|
|
|
|
let search = this.filterBox.value;
|
|
|
|
|
let text = aNode.clipboardText;
|
|
|
|
|
|
|
|
|
|
// if string matches the filter text
|
|
|
|
|
if (!this.stringMatchesFilters(text, search)) {
|
2013-09-05 09:34:22 -07:00
|
|
|
|
aNode.classList.add("filtered-by-string");
|
2012-07-26 08:06:04 -07:00
|
|
|
|
isFiltered = true;
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-05 09:34:22 -07:00
|
|
|
|
if (isFiltered && aNode.classList.contains("inlined-variables-view")) {
|
2013-05-10 03:15:11 -07:00
|
|
|
|
aNode.classList.add("hidden-message");
|
|
|
|
|
}
|
|
|
|
|
|
2012-07-26 08:06:04 -07:00
|
|
|
|
return isFiltered;
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Merge the attributes of the two nodes that are about to be filtered.
|
|
|
|
|
* Increment the number of repeats of aOriginal.
|
|
|
|
|
*
|
|
|
|
|
* @param nsIDOMNode aOriginal
|
|
|
|
|
* The Original Node. The one being merged into.
|
|
|
|
|
* @param nsIDOMNode aFiltered
|
|
|
|
|
* The node being filtered out because it is repeated.
|
|
|
|
|
*/
|
|
|
|
|
mergeFilteredMessageNode:
|
|
|
|
|
function WCF_mergeFilteredMessageNode(aOriginal, aFiltered)
|
|
|
|
|
{
|
2013-09-05 09:34:22 -07:00
|
|
|
|
let repeatNode = aOriginal.getElementsByClassName("repeats")[0];
|
2012-07-26 08:06:04 -07:00
|
|
|
|
if (!repeatNode) {
|
|
|
|
|
return; // no repeat node, return early.
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let occurrences = parseInt(repeatNode.getAttribute("value")) + 1;
|
|
|
|
|
repeatNode.setAttribute("value", occurrences);
|
2013-09-13 05:06:46 -07:00
|
|
|
|
repeatNode.textContent = occurrences;
|
2013-09-14 03:43:44 -07:00
|
|
|
|
let str = l10n.getStr("messageRepeats.tooltip2");
|
|
|
|
|
repeatNode.title = PluralForm.get(occurrences, str)
|
|
|
|
|
.replace("#1", occurrences);
|
2012-07-26 08:06:04 -07:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
2013-01-31 09:19:06 -08:00
|
|
|
|
* Filter the message node from the output if it is a repeat.
|
2012-07-26 08:06:04 -07:00
|
|
|
|
*
|
2013-01-31 09:19:06 -08:00
|
|
|
|
* @private
|
2012-07-26 08:06:04 -07:00
|
|
|
|
* @param nsIDOMNode aNode
|
|
|
|
|
* The message node to be filtered or not.
|
2013-04-10 08:22:29 -07:00
|
|
|
|
* @returns nsIDOMNode|null
|
|
|
|
|
* Returns the duplicate node if the message was filtered, null
|
|
|
|
|
* otherwise.
|
2012-07-26 08:06:04 -07:00
|
|
|
|
*/
|
2013-01-31 09:19:06 -08:00
|
|
|
|
_filterRepeatedMessage: function WCF__filterRepeatedMessage(aNode)
|
2012-07-26 08:06:04 -07:00
|
|
|
|
{
|
2013-09-05 09:34:22 -07:00
|
|
|
|
let repeatNode = aNode.getElementsByClassName("repeats")[0];
|
2013-02-05 08:44:41 -08:00
|
|
|
|
if (!repeatNode) {
|
2013-04-10 08:22:29 -07:00
|
|
|
|
return null;
|
2013-02-05 08:44:41 -08:00
|
|
|
|
}
|
|
|
|
|
|
2013-01-31 09:19:06 -08:00
|
|
|
|
let uid = repeatNode._uid;
|
|
|
|
|
let dupeNode = null;
|
2012-07-26 08:06:04 -07:00
|
|
|
|
|
2013-09-05 09:34:22 -07:00
|
|
|
|
if (aNode.category == CATEGORY_CSS ||
|
|
|
|
|
aNode.category == CATEGORY_SECURITY) {
|
2013-04-22 18:07:36 -07:00
|
|
|
|
dupeNode = this._repeatNodes[uid];
|
2013-01-31 09:19:06 -08:00
|
|
|
|
if (!dupeNode) {
|
2013-04-22 18:07:36 -07:00
|
|
|
|
this._repeatNodes[uid] = aNode;
|
2013-01-31 09:19:06 -08:00
|
|
|
|
}
|
2012-09-14 13:12:57 -07:00
|
|
|
|
}
|
2013-09-05 09:34:22 -07:00
|
|
|
|
else if ((aNode.category == CATEGORY_WEBDEV ||
|
|
|
|
|
aNode.category == CATEGORY_JS) &&
|
|
|
|
|
aNode.category != CATEGORY_NETWORK &&
|
|
|
|
|
!aNode.classList.contains("inlined-variables-view")) {
|
2013-01-31 09:19:06 -08:00
|
|
|
|
let lastMessage = this.outputNode.lastChild;
|
|
|
|
|
if (!lastMessage) {
|
2013-04-10 08:22:29 -07:00
|
|
|
|
return null;
|
2013-01-31 09:19:06 -08:00
|
|
|
|
}
|
2012-09-14 13:12:57 -07:00
|
|
|
|
|
2013-09-05 09:34:22 -07:00
|
|
|
|
let lastRepeatNode = lastMessage.getElementsByClassName("repeats")[0];
|
2013-02-05 08:44:41 -08:00
|
|
|
|
if (lastRepeatNode && lastRepeatNode._uid == uid) {
|
2013-01-31 09:19:06 -08:00
|
|
|
|
dupeNode = lastMessage;
|
2012-09-14 13:12:57 -07:00
|
|
|
|
}
|
2013-01-31 09:19:06 -08:00
|
|
|
|
}
|
2012-09-14 13:12:57 -07:00
|
|
|
|
|
2013-01-31 09:19:06 -08:00
|
|
|
|
if (dupeNode) {
|
|
|
|
|
this.mergeFilteredMessageNode(dupeNode, aNode);
|
2013-04-10 08:22:29 -07:00
|
|
|
|
return dupeNode;
|
2012-07-26 08:06:04 -07:00
|
|
|
|
}
|
|
|
|
|
|
2013-04-10 08:22:29 -07:00
|
|
|
|
return null;
|
2012-07-26 08:06:04 -07:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Display cached messages that may have been collected before the UI is
|
|
|
|
|
* displayed.
|
|
|
|
|
*
|
|
|
|
|
* @param array aRemoteMessages
|
|
|
|
|
* Array of cached messages coming from the remote Web Console
|
|
|
|
|
* content instance.
|
|
|
|
|
*/
|
2012-09-26 10:02:04 -07:00
|
|
|
|
displayCachedMessages: function WCF_displayCachedMessages(aRemoteMessages)
|
2012-07-26 08:06:04 -07:00
|
|
|
|
{
|
|
|
|
|
if (!aRemoteMessages.length) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
aRemoteMessages.forEach(function(aMessage) {
|
|
|
|
|
switch (aMessage._type) {
|
|
|
|
|
case "PageError": {
|
2013-05-17 14:30:20 -07:00
|
|
|
|
let category = Utils.categoryForScriptError(aMessage);
|
2012-07-26 08:06:04 -07:00
|
|
|
|
this.outputMessage(category, this.reportPageError,
|
|
|
|
|
[category, aMessage]);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2013-05-28 08:24:31 -07:00
|
|
|
|
case "LogMessage":
|
|
|
|
|
this.handleLogMessage(aMessage);
|
|
|
|
|
break;
|
2012-07-26 08:06:04 -07:00
|
|
|
|
case "ConsoleAPI":
|
|
|
|
|
this.outputMessage(CATEGORY_WEBDEV, this.logConsoleAPIMessage,
|
|
|
|
|
[aMessage]);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}, this);
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
2012-09-26 10:02:04 -07:00
|
|
|
|
* Logs a message to the Web Console that originates from the Web Console
|
|
|
|
|
* server.
|
2012-07-26 08:06:04 -07:00
|
|
|
|
*
|
|
|
|
|
* @param object aMessage
|
2012-09-26 10:02:04 -07:00
|
|
|
|
* The message received from the server.
|
2013-05-08 11:54:57 -07:00
|
|
|
|
* @return nsIDOMElement|null
|
2012-07-26 08:06:04 -07:00
|
|
|
|
* The message element to display in the Web Console output.
|
|
|
|
|
*/
|
|
|
|
|
logConsoleAPIMessage: function WCF_logConsoleAPIMessage(aMessage)
|
|
|
|
|
{
|
|
|
|
|
let body = null;
|
|
|
|
|
let clipboardText = null;
|
2013-01-15 06:02:25 -08:00
|
|
|
|
let sourceURL = aMessage.filename;
|
|
|
|
|
let sourceLine = aMessage.lineNumber;
|
2012-09-26 10:02:04 -07:00
|
|
|
|
let level = aMessage.level;
|
|
|
|
|
let args = aMessage.arguments;
|
2013-04-09 02:46:30 -07:00
|
|
|
|
let objectActors = new Set();
|
2012-07-26 08:06:04 -07:00
|
|
|
|
|
2013-01-15 06:02:25 -08:00
|
|
|
|
// Gather the actor IDs.
|
2013-04-09 02:46:30 -07:00
|
|
|
|
args.forEach((aValue) => {
|
|
|
|
|
if (WebConsoleUtils.isActorGrip(aValue)) {
|
|
|
|
|
objectActors.add(aValue.actor);
|
2013-01-15 06:02:25 -08:00
|
|
|
|
}
|
2013-04-09 02:46:30 -07:00
|
|
|
|
});
|
2013-01-15 06:02:25 -08:00
|
|
|
|
|
2012-07-26 08:06:04 -07:00
|
|
|
|
switch (level) {
|
|
|
|
|
case "log":
|
|
|
|
|
case "info":
|
|
|
|
|
case "warn":
|
|
|
|
|
case "error":
|
|
|
|
|
case "debug":
|
2013-04-09 02:46:30 -07:00
|
|
|
|
case "dir": {
|
2012-09-26 10:02:04 -07:00
|
|
|
|
body = { arguments: args };
|
|
|
|
|
let clipboardArray = [];
|
2013-04-09 02:46:30 -07:00
|
|
|
|
args.forEach((aValue) => {
|
|
|
|
|
clipboardArray.push(VariablesView.getString(aValue));
|
|
|
|
|
if (aValue && typeof aValue == "object" &&
|
|
|
|
|
aValue.type == "longString") {
|
|
|
|
|
clipboardArray.push(l10n.getStr("longStringEllipsis"));
|
2012-09-26 10:02:04 -07:00
|
|
|
|
}
|
2013-04-09 02:46:30 -07:00
|
|
|
|
});
|
2012-09-26 10:02:04 -07:00
|
|
|
|
clipboardText = clipboardArray.join(" ");
|
2012-07-26 08:06:04 -07:00
|
|
|
|
break;
|
2012-09-26 10:02:04 -07:00
|
|
|
|
}
|
2012-07-26 08:06:04 -07:00
|
|
|
|
|
2012-09-26 10:02:04 -07:00
|
|
|
|
case "trace": {
|
2013-01-15 06:02:25 -08:00
|
|
|
|
let filename = WebConsoleUtils.abbreviateSourceURL(aMessage.filename);
|
|
|
|
|
let functionName = aMessage.functionName ||
|
2012-07-26 08:06:04 -07:00
|
|
|
|
l10n.getStr("stacktrace.anonymousFunction");
|
|
|
|
|
|
2013-09-05 09:29:13 -07:00
|
|
|
|
body = this.document.createElementNS(XHTML_NS, "a");
|
|
|
|
|
body.setAttribute("aria-haspopup", true);
|
|
|
|
|
body.href = "#";
|
|
|
|
|
body.draggable = false;
|
|
|
|
|
body.textContent = l10n.getFormatStr("stacktrace.outputMessage",
|
|
|
|
|
[filename, functionName,
|
|
|
|
|
sourceLine]);
|
|
|
|
|
|
|
|
|
|
this._addMessageLinkCallback(body, () => {
|
|
|
|
|
this.jsterm.openVariablesView({
|
|
|
|
|
rawObject: aMessage.stacktrace,
|
|
|
|
|
autofocus: true,
|
|
|
|
|
});
|
|
|
|
|
});
|
2012-07-26 08:06:04 -07:00
|
|
|
|
|
2013-09-05 09:29:13 -07:00
|
|
|
|
clipboardText = body.textContent + "\n";
|
2012-07-26 08:06:04 -07:00
|
|
|
|
|
2013-01-15 06:02:25 -08:00
|
|
|
|
aMessage.stacktrace.forEach(function(aFrame) {
|
2012-07-26 08:06:04 -07:00
|
|
|
|
clipboardText += aFrame.filename + " :: " +
|
|
|
|
|
aFrame.functionName + " :: " +
|
|
|
|
|
aFrame.lineNumber + "\n";
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
clipboardText = clipboardText.trimRight();
|
|
|
|
|
break;
|
2012-09-26 10:02:04 -07:00
|
|
|
|
}
|
2012-07-26 08:06:04 -07:00
|
|
|
|
|
|
|
|
|
case "group":
|
|
|
|
|
case "groupCollapsed":
|
2013-01-15 06:02:25 -08:00
|
|
|
|
clipboardText = body = aMessage.groupName;
|
2012-07-26 08:06:04 -07:00
|
|
|
|
this.groupDepth++;
|
|
|
|
|
break;
|
|
|
|
|
|
2013-04-09 02:46:30 -07:00
|
|
|
|
case "groupEnd":
|
|
|
|
|
if (this.groupDepth > 0) {
|
|
|
|
|
this.groupDepth--;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
2013-01-15 06:02:25 -08:00
|
|
|
|
case "time": {
|
|
|
|
|
let timer = aMessage.timer;
|
|
|
|
|
if (!timer) {
|
2013-05-08 11:54:57 -07:00
|
|
|
|
return null;
|
2012-07-26 08:06:04 -07:00
|
|
|
|
}
|
2013-01-15 06:02:25 -08:00
|
|
|
|
if (timer.error) {
|
|
|
|
|
Cu.reportError(l10n.getStr(timer.error));
|
2013-05-08 11:54:57 -07:00
|
|
|
|
return null;
|
2012-07-26 08:06:04 -07:00
|
|
|
|
}
|
2013-01-15 06:02:25 -08:00
|
|
|
|
body = l10n.getFormatStr("timerStarted", [timer.name]);
|
2012-07-26 08:06:04 -07:00
|
|
|
|
clipboardText = body;
|
|
|
|
|
break;
|
2013-01-15 06:02:25 -08:00
|
|
|
|
}
|
2012-07-26 08:06:04 -07:00
|
|
|
|
|
2013-01-15 06:02:25 -08:00
|
|
|
|
case "timeEnd": {
|
|
|
|
|
let timer = aMessage.timer;
|
|
|
|
|
if (!timer) {
|
2013-05-08 11:54:57 -07:00
|
|
|
|
return null;
|
2012-07-26 08:06:04 -07:00
|
|
|
|
}
|
2013-04-30 11:35:07 -07:00
|
|
|
|
let duration = Math.round(timer.duration * 100) / 100;
|
|
|
|
|
body = l10n.getFormatStr("timeEnd", [timer.name, duration]);
|
2012-07-26 08:06:04 -07:00
|
|
|
|
clipboardText = body;
|
|
|
|
|
break;
|
2013-01-15 06:02:25 -08:00
|
|
|
|
}
|
2012-07-26 08:06:04 -07:00
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
Cu.reportError("Unknown Console API log level: " + level);
|
2013-05-08 11:54:57 -07:00
|
|
|
|
return null;
|
2012-07-26 08:06:04 -07:00
|
|
|
|
}
|
|
|
|
|
|
2013-01-15 06:02:25 -08:00
|
|
|
|
// Release object actors for arguments coming from console API methods that
|
|
|
|
|
// we ignore their arguments.
|
|
|
|
|
switch (level) {
|
|
|
|
|
case "group":
|
|
|
|
|
case "groupCollapsed":
|
|
|
|
|
case "groupEnd":
|
|
|
|
|
case "trace":
|
|
|
|
|
case "time":
|
|
|
|
|
case "timeEnd":
|
2013-04-09 02:46:30 -07:00
|
|
|
|
for (let actor of objectActors) {
|
|
|
|
|
this._releaseObject(actor);
|
|
|
|
|
}
|
|
|
|
|
objectActors.clear();
|
2013-01-15 06:02:25 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (level == "groupEnd") {
|
2013-05-08 11:54:57 -07:00
|
|
|
|
return null; // no need to continue
|
2013-01-15 06:02:25 -08:00
|
|
|
|
}
|
|
|
|
|
|
2012-07-26 08:06:04 -07:00
|
|
|
|
let node = this.createMessageNode(CATEGORY_WEBDEV, LEVELS[level], body,
|
|
|
|
|
sourceURL, sourceLine, clipboardText,
|
|
|
|
|
level, aMessage.timeStamp);
|
2013-05-25 02:25:36 -07:00
|
|
|
|
if (aMessage.private) {
|
|
|
|
|
node.setAttribute("private", true);
|
|
|
|
|
}
|
2012-07-26 08:06:04 -07:00
|
|
|
|
|
2013-04-09 02:46:30 -07:00
|
|
|
|
if (objectActors.size > 0) {
|
2012-09-26 10:02:04 -07:00
|
|
|
|
node._objectActors = objectActors;
|
2013-05-02 08:21:45 -07:00
|
|
|
|
|
2013-09-05 09:34:22 -07:00
|
|
|
|
let repeatNode = node.getElementsByClassName("repeats")[0];
|
2013-05-02 08:21:45 -07:00
|
|
|
|
repeatNode._uid += [...objectActors].join("-");
|
2012-09-26 10:02:04 -07:00
|
|
|
|
}
|
|
|
|
|
|
2012-07-26 08:06:04 -07:00
|
|
|
|
if (level == "trace") {
|
2013-01-15 06:02:25 -08:00
|
|
|
|
node._stacktrace = aMessage.stacktrace;
|
2012-07-26 08:06:04 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return node;
|
|
|
|
|
},
|
|
|
|
|
|
2012-09-26 10:02:04 -07:00
|
|
|
|
/**
|
|
|
|
|
* Handle ConsoleAPICall objects received from the server. This method outputs
|
|
|
|
|
* the window.console API call.
|
|
|
|
|
*
|
|
|
|
|
* @param object aMessage
|
|
|
|
|
* The console API message received from the server.
|
|
|
|
|
*/
|
|
|
|
|
handleConsoleAPICall: function WCF_handleConsoleAPICall(aMessage)
|
|
|
|
|
{
|
|
|
|
|
this.outputMessage(CATEGORY_WEBDEV, this.logConsoleAPIMessage, [aMessage]);
|
|
|
|
|
},
|
|
|
|
|
|
2012-08-03 13:14:01 -07:00
|
|
|
|
/**
|
|
|
|
|
* The click event handler for objects shown inline coming from the
|
|
|
|
|
* window.console API.
|
|
|
|
|
*
|
|
|
|
|
* @private
|
|
|
|
|
* @param nsIDOMNode aAnchor
|
|
|
|
|
* The object inspector anchor element. This is the clickable element
|
|
|
|
|
* in the console.log message we display.
|
2012-09-26 10:02:04 -07:00
|
|
|
|
* @param object aObjectActor
|
|
|
|
|
* The object actor grip.
|
2012-08-03 13:14:01 -07:00
|
|
|
|
*/
|
2013-04-09 02:46:30 -07:00
|
|
|
|
_consoleLogClick: function WCF__consoleLogClick(aAnchor, aObjectActor)
|
2012-08-03 13:14:01 -07:00
|
|
|
|
{
|
2013-05-02 04:53:11 -07:00
|
|
|
|
this.jsterm.openVariablesView({
|
2013-04-09 02:46:30 -07:00
|
|
|
|
label: aAnchor.textContent,
|
|
|
|
|
objectActor: aObjectActor,
|
2013-05-02 04:53:11 -07:00
|
|
|
|
autofocus: true,
|
|
|
|
|
});
|
2012-08-03 13:14:01 -07:00
|
|
|
|
},
|
|
|
|
|
|
2012-07-26 08:06:04 -07:00
|
|
|
|
/**
|
|
|
|
|
* Reports an error in the page source, either JavaScript or CSS.
|
|
|
|
|
*
|
|
|
|
|
* @param nsIScriptError aScriptError
|
|
|
|
|
* The error message to report.
|
|
|
|
|
* @return nsIDOMElement|undefined
|
|
|
|
|
* The message element to display in the Web Console output.
|
|
|
|
|
*/
|
|
|
|
|
reportPageError: function WCF_reportPageError(aCategory, aScriptError)
|
|
|
|
|
{
|
|
|
|
|
// Warnings and legacy strict errors become warnings; other types become
|
|
|
|
|
// errors.
|
|
|
|
|
let severity = SEVERITY_ERROR;
|
2012-09-26 10:07:57 -07:00
|
|
|
|
if (aScriptError.warning || aScriptError.strict) {
|
2012-07-26 08:06:04 -07:00
|
|
|
|
severity = SEVERITY_WARNING;
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-04 08:47:39 -07:00
|
|
|
|
let objectActors = new Set();
|
|
|
|
|
|
|
|
|
|
// Gather the actor IDs.
|
|
|
|
|
for (let prop of ["errorMessage", "lineText"]) {
|
|
|
|
|
let grip = aScriptError[prop];
|
|
|
|
|
if (WebConsoleUtils.isActorGrip(grip)) {
|
|
|
|
|
objectActors.add(grip.actor);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let errorMessage = aScriptError.errorMessage;
|
|
|
|
|
if (errorMessage.type && errorMessage.type == "longString") {
|
|
|
|
|
errorMessage = errorMessage.initial;
|
|
|
|
|
}
|
|
|
|
|
|
2012-07-26 08:06:04 -07:00
|
|
|
|
let node = this.createMessageNode(aCategory, severity,
|
2013-06-04 08:47:39 -07:00
|
|
|
|
errorMessage,
|
2012-07-26 08:06:04 -07:00
|
|
|
|
aScriptError.sourceName,
|
|
|
|
|
aScriptError.lineNumber, null, null,
|
|
|
|
|
aScriptError.timeStamp);
|
2013-08-06 07:14:51 -07:00
|
|
|
|
|
|
|
|
|
// Select the body of the message node that is displayed in the console
|
2013-09-05 09:34:22 -07:00
|
|
|
|
let msgBody = node.getElementsByClassName("body")[0];
|
2013-08-06 07:14:51 -07:00
|
|
|
|
// Add the more info link node to messages that belong to certain categories
|
|
|
|
|
this.addMoreInfoLink(msgBody, aScriptError);
|
|
|
|
|
|
2013-05-25 02:25:36 -07:00
|
|
|
|
if (aScriptError.private) {
|
|
|
|
|
node.setAttribute("private", true);
|
|
|
|
|
}
|
2013-06-04 08:47:39 -07:00
|
|
|
|
|
|
|
|
|
if (objectActors.size > 0) {
|
|
|
|
|
node._objectActors = objectActors;
|
|
|
|
|
}
|
|
|
|
|
|
2012-07-26 08:06:04 -07:00
|
|
|
|
return node;
|
|
|
|
|
},
|
|
|
|
|
|
2012-09-26 10:07:57 -07:00
|
|
|
|
/**
|
|
|
|
|
* Handle PageError objects received from the server. This method outputs the
|
|
|
|
|
* given error.
|
|
|
|
|
*
|
|
|
|
|
* @param nsIScriptError aPageError
|
|
|
|
|
* The error received from the server.
|
|
|
|
|
*/
|
|
|
|
|
handlePageError: function WCF_handlePageError(aPageError)
|
|
|
|
|
{
|
2013-05-17 14:30:20 -07:00
|
|
|
|
let category = Utils.categoryForScriptError(aPageError);
|
2012-09-26 10:07:57 -07:00
|
|
|
|
this.outputMessage(category, this.reportPageError, [category, aPageError]);
|
|
|
|
|
},
|
|
|
|
|
|
2013-05-28 08:24:31 -07:00
|
|
|
|
/**
|
|
|
|
|
* Handle log messages received from the server. This method outputs the given
|
|
|
|
|
* message.
|
|
|
|
|
*
|
|
|
|
|
* @param object aPacket
|
|
|
|
|
* The message packet received from the server.
|
|
|
|
|
*/
|
|
|
|
|
handleLogMessage: function WCF_handleLogMessage(aPacket)
|
|
|
|
|
{
|
2013-06-04 08:47:39 -07:00
|
|
|
|
if (aPacket.message) {
|
|
|
|
|
this.outputMessage(CATEGORY_JS, this._reportLogMessage, [aPacket]);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Display log messages received from the server.
|
|
|
|
|
*
|
|
|
|
|
* @private
|
|
|
|
|
* @param object aPacket
|
|
|
|
|
* The message packet received from the server.
|
|
|
|
|
* @return nsIDOMElement
|
|
|
|
|
* The message element to render for the given log message.
|
|
|
|
|
*/
|
|
|
|
|
_reportLogMessage: function WCF__reportLogMessage(aPacket)
|
|
|
|
|
{
|
|
|
|
|
let msg = aPacket.message;
|
|
|
|
|
if (msg.type && msg.type == "longString") {
|
|
|
|
|
msg = msg.initial;
|
|
|
|
|
}
|
|
|
|
|
let node = this.createMessageNode(CATEGORY_JS, SEVERITY_LOG, msg, null,
|
|
|
|
|
null, null, null, aPacket.timeStamp);
|
|
|
|
|
if (WebConsoleUtils.isActorGrip(aPacket.message)) {
|
|
|
|
|
node._objectActors = new Set([aPacket.message.actor]);
|
|
|
|
|
}
|
|
|
|
|
return node;
|
2013-05-28 08:24:31 -07:00
|
|
|
|
},
|
|
|
|
|
|
2012-07-26 08:06:04 -07:00
|
|
|
|
/**
|
2012-10-05 04:54:43 -07:00
|
|
|
|
* Log network event.
|
2012-07-26 08:06:04 -07:00
|
|
|
|
*
|
2012-10-05 04:54:43 -07:00
|
|
|
|
* @param object aActorId
|
|
|
|
|
* The network event actor ID to log.
|
2013-05-08 11:54:57 -07:00
|
|
|
|
* @return nsIDOMElement|null
|
2012-07-26 08:06:04 -07:00
|
|
|
|
* The message element to display in the Web Console output.
|
|
|
|
|
*/
|
2012-10-05 04:54:43 -07:00
|
|
|
|
logNetEvent: function WCF_logNetEvent(aActorId)
|
2012-07-26 08:06:04 -07:00
|
|
|
|
{
|
2012-10-05 04:54:43 -07:00
|
|
|
|
let networkInfo = this._networkRequests[aActorId];
|
2012-07-26 08:06:04 -07:00
|
|
|
|
if (!networkInfo) {
|
2013-05-08 11:54:57 -07:00
|
|
|
|
return null;
|
2012-07-26 08:06:04 -07:00
|
|
|
|
}
|
|
|
|
|
|
2012-10-05 04:54:43 -07:00
|
|
|
|
let request = networkInfo.request;
|
2013-09-13 05:06:46 -07:00
|
|
|
|
let clipboardText = request.method + " " + request.url;
|
2012-07-26 08:06:04 -07:00
|
|
|
|
let severity = SEVERITY_LOG;
|
|
|
|
|
let mixedRequest =
|
2012-10-05 04:54:43 -07:00
|
|
|
|
WebConsoleUtils.isMixedHTTPSRequest(request.url, this.contentLocation);
|
2012-07-26 08:06:04 -07:00
|
|
|
|
if (mixedRequest) {
|
|
|
|
|
severity = SEVERITY_WARNING;
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-13 05:06:46 -07:00
|
|
|
|
let methodNode = this.document.createElementNS(XHTML_NS, "span");
|
2013-09-05 09:34:22 -07:00
|
|
|
|
methodNode.className = "method";
|
2013-09-13 05:06:46 -07:00
|
|
|
|
methodNode.textContent = request.method + " ";
|
2012-07-26 08:06:04 -07:00
|
|
|
|
|
|
|
|
|
let messageNode = this.createMessageNode(CATEGORY_NETWORK, severity,
|
2013-09-13 05:06:46 -07:00
|
|
|
|
methodNode, null, null,
|
|
|
|
|
clipboardText);
|
2013-05-25 02:25:36 -07:00
|
|
|
|
if (networkInfo.private) {
|
|
|
|
|
messageNode.setAttribute("private", true);
|
|
|
|
|
}
|
2012-10-05 04:54:43 -07:00
|
|
|
|
messageNode._connectionId = aActorId;
|
2012-09-18 09:08:29 -07:00
|
|
|
|
messageNode.url = request.url;
|
2012-07-26 08:06:04 -07:00
|
|
|
|
|
2013-09-13 05:06:46 -07:00
|
|
|
|
let body = methodNode.parentNode;
|
|
|
|
|
body.setAttribute("aria-haspopup", true);
|
|
|
|
|
|
|
|
|
|
let displayUrl = request.url;
|
|
|
|
|
let pos = displayUrl.indexOf("?");
|
|
|
|
|
if (pos > -1) {
|
|
|
|
|
displayUrl = displayUrl.substr(0, pos);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let urlNode = this.document.createElementNS(XHTML_NS, "a");
|
2013-09-05 09:34:22 -07:00
|
|
|
|
urlNode.className = "url";
|
2013-09-13 05:06:46 -07:00
|
|
|
|
urlNode.setAttribute("title", request.url);
|
2013-09-05 09:29:13 -07:00
|
|
|
|
urlNode.href = request.url;
|
2013-09-13 05:06:46 -07:00
|
|
|
|
urlNode.textContent = displayUrl;
|
2013-09-05 09:29:13 -07:00
|
|
|
|
urlNode.draggable = false;
|
2013-09-13 05:06:46 -07:00
|
|
|
|
body.appendChild(urlNode);
|
|
|
|
|
body.appendChild(this.document.createTextNode(" "));
|
|
|
|
|
|
|
|
|
|
if (mixedRequest) {
|
2013-09-05 09:34:22 -07:00
|
|
|
|
messageNode.classList.add("mixed-content");
|
2013-09-13 05:06:46 -07:00
|
|
|
|
this.makeMixedContentNode(body);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let statusNode = this.document.createElementNS(XHTML_NS, "a");
|
2013-09-05 09:34:22 -07:00
|
|
|
|
statusNode.className = "status";
|
2013-09-13 05:06:46 -07:00
|
|
|
|
body.appendChild(statusNode);
|
|
|
|
|
|
2013-09-05 09:29:13 -07:00
|
|
|
|
let onClick = () => {
|
2012-07-26 08:06:04 -07:00
|
|
|
|
if (!messageNode._panelOpen) {
|
2012-10-05 04:54:43 -07:00
|
|
|
|
this.openNetworkPanel(messageNode, networkInfo);
|
2012-07-26 08:06:04 -07:00
|
|
|
|
}
|
2013-09-05 09:29:13 -07:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
this._addMessageLinkCallback(urlNode, onClick);
|
|
|
|
|
this._addMessageLinkCallback(statusNode, onClick);
|
2012-07-26 08:06:04 -07:00
|
|
|
|
|
|
|
|
|
networkInfo.node = messageNode;
|
|
|
|
|
|
2012-10-05 04:54:43 -07:00
|
|
|
|
this._updateNetMessage(aActorId);
|
2012-07-26 08:06:04 -07:00
|
|
|
|
|
|
|
|
|
return messageNode;
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Create a mixed content warning Node.
|
|
|
|
|
*
|
|
|
|
|
* @param aLinkNode
|
|
|
|
|
* Parent to the requested urlNode.
|
|
|
|
|
*/
|
|
|
|
|
makeMixedContentNode: function WCF_makeMixedContentNode(aLinkNode)
|
|
|
|
|
{
|
|
|
|
|
let mixedContentWarning = "[" + l10n.getStr("webConsoleMixedContentWarning") + "]";
|
|
|
|
|
|
|
|
|
|
// Mixed content warning message links to a Learn More page
|
2013-09-13 05:06:46 -07:00
|
|
|
|
let mixedContentWarningNode = this.document.createElementNS(XHTML_NS, "a");
|
|
|
|
|
mixedContentWarningNode.title = MIXED_CONTENT_LEARN_MORE;
|
2013-09-05 09:29:13 -07:00
|
|
|
|
mixedContentWarningNode.href = MIXED_CONTENT_LEARN_MORE;
|
2013-09-05 09:34:22 -07:00
|
|
|
|
mixedContentWarningNode.className = "learn-more-link";
|
2013-09-13 05:06:46 -07:00
|
|
|
|
mixedContentWarningNode.textContent = mixedContentWarning;
|
2013-09-05 09:29:13 -07:00
|
|
|
|
mixedContentWarningNode.draggable = false;
|
2012-07-26 08:06:04 -07:00
|
|
|
|
|
|
|
|
|
aLinkNode.appendChild(mixedContentWarningNode);
|
|
|
|
|
|
2013-09-05 09:29:13 -07:00
|
|
|
|
this._addMessageLinkCallback(mixedContentWarningNode, (aNode, aEvent) => {
|
2012-07-26 08:06:04 -07:00
|
|
|
|
aEvent.stopPropagation();
|
2013-09-05 09:29:13 -07:00
|
|
|
|
this.owner.openLink(MIXED_CONTENT_LEARN_MORE);
|
|
|
|
|
});
|
2012-07-26 08:06:04 -07:00
|
|
|
|
},
|
|
|
|
|
|
2013-08-06 07:14:51 -07:00
|
|
|
|
/**
|
|
|
|
|
* Adds a more info link node to messages based on the nsIScriptError object
|
|
|
|
|
* that we need to report to the console
|
|
|
|
|
*
|
|
|
|
|
* @param aNode
|
|
|
|
|
* The node to which we will be adding the more info link node
|
|
|
|
|
* @param aScriptError
|
|
|
|
|
* The script error object that we are reporting to the console
|
|
|
|
|
*/
|
|
|
|
|
addMoreInfoLink: function WCF_addMoreInfoLink(aNode, aScriptError)
|
|
|
|
|
{
|
2013-08-26 08:26:43 -07:00
|
|
|
|
let url;
|
2013-08-29 08:22:18 -07:00
|
|
|
|
switch (aScriptError.category) {
|
|
|
|
|
case "Insecure Password Field":
|
|
|
|
|
url = INSECURE_PASSWORDS_LEARN_MORE;
|
|
|
|
|
break;
|
|
|
|
|
case "Mixed Content Message":
|
|
|
|
|
case "Mixed Content Blocker":
|
2013-08-26 08:26:43 -07:00
|
|
|
|
url = MIXED_CONTENT_LEARN_MORE;
|
2013-08-29 08:22:18 -07:00
|
|
|
|
break;
|
|
|
|
|
case "Invalid HSTS Headers":
|
|
|
|
|
url = STRICT_TRANSPORT_SECURITY_LEARN_MORE;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
2013-08-26 08:26:43 -07:00
|
|
|
|
// Unknown category. Return without adding more info node.
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.addLearnMoreWarningNode(aNode, url);
|
2013-08-06 07:14:51 -07:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/*
|
2013-08-26 08:26:43 -07:00
|
|
|
|
* Appends a clickable warning node to the node passed
|
2013-08-06 07:14:51 -07:00
|
|
|
|
* as a parameter to the function. When a user clicks on the appended
|
2013-08-26 08:26:43 -07:00
|
|
|
|
* warning node, the browser navigates to the provided url.
|
|
|
|
|
*
|
|
|
|
|
* @param aNode
|
|
|
|
|
* The node to which we will be adding a clickable warning node.
|
|
|
|
|
* @param aURL
|
|
|
|
|
* The url which points to the page where the user can learn more
|
|
|
|
|
* about security issues associated with the specific message that's
|
|
|
|
|
* being logged.
|
|
|
|
|
*/
|
|
|
|
|
addLearnMoreWarningNode:
|
|
|
|
|
function WCF_addLearnMoreWarningNode(aNode, aURL)
|
2013-08-06 07:14:51 -07:00
|
|
|
|
{
|
2013-09-13 05:06:46 -07:00
|
|
|
|
let moreInfoLabel = "[" + l10n.getStr("webConsoleMoreInfoLabel") + "]";
|
|
|
|
|
|
|
|
|
|
let warningNode = this.document.createElementNS(XHTML_NS, "a");
|
|
|
|
|
warningNode.title = aURL;
|
2013-09-05 09:29:13 -07:00
|
|
|
|
warningNode.href = aURL;
|
|
|
|
|
warningNode.draggable = false;
|
2013-09-13 05:06:46 -07:00
|
|
|
|
warningNode.textContent = moreInfoLabel;
|
2013-09-05 09:34:22 -07:00
|
|
|
|
warningNode.className = "learn-more-link";
|
2013-08-06 07:14:51 -07:00
|
|
|
|
|
2013-09-05 09:29:13 -07:00
|
|
|
|
this._addMessageLinkCallback(warningNode, (aNode, aEvent) => {
|
2013-08-06 07:14:51 -07:00
|
|
|
|
aEvent.stopPropagation();
|
2013-09-05 09:29:13 -07:00
|
|
|
|
this.owner.openLink(aURL);
|
|
|
|
|
});
|
2013-08-06 07:14:51 -07:00
|
|
|
|
|
2013-09-13 05:06:46 -07:00
|
|
|
|
aNode.appendChild(warningNode);
|
2013-08-06 07:14:51 -07:00
|
|
|
|
},
|
|
|
|
|
|
2012-07-26 08:06:04 -07:00
|
|
|
|
/**
|
|
|
|
|
* Log file activity.
|
|
|
|
|
*
|
|
|
|
|
* @param string aFileURI
|
|
|
|
|
* The file URI that was loaded.
|
|
|
|
|
* @return nsIDOMElement|undefined
|
|
|
|
|
* The message element to display in the Web Console output.
|
|
|
|
|
*/
|
|
|
|
|
logFileActivity: function WCF_logFileActivity(aFileURI)
|
|
|
|
|
{
|
2013-09-13 05:06:46 -07:00
|
|
|
|
let urlNode = this.document.createElementNS(XHTML_NS, "a");
|
2012-07-26 08:06:04 -07:00
|
|
|
|
urlNode.setAttribute("title", aFileURI);
|
2013-09-05 09:34:22 -07:00
|
|
|
|
urlNode.className = "url";
|
2013-09-13 05:06:46 -07:00
|
|
|
|
urlNode.textContent = aFileURI;
|
2013-09-05 09:29:13 -07:00
|
|
|
|
urlNode.draggable = false;
|
|
|
|
|
urlNode.href = aFileURI;
|
2012-07-26 08:06:04 -07:00
|
|
|
|
|
|
|
|
|
let outputNode = this.createMessageNode(CATEGORY_NETWORK, SEVERITY_LOG,
|
|
|
|
|
urlNode, null, null, aFileURI);
|
|
|
|
|
|
2013-09-05 09:29:13 -07:00
|
|
|
|
this._addMessageLinkCallback(urlNode, () => {
|
2012-09-25 10:32:11 -07:00
|
|
|
|
this.owner.viewSource(aFileURI);
|
2013-09-05 09:29:13 -07:00
|
|
|
|
});
|
2012-07-26 08:06:04 -07:00
|
|
|
|
|
|
|
|
|
return outputNode;
|
|
|
|
|
},
|
|
|
|
|
|
2012-10-05 04:54:43 -07:00
|
|
|
|
/**
|
|
|
|
|
* Handle the file activity messages coming from the remote Web Console.
|
|
|
|
|
*
|
|
|
|
|
* @param string aFileURI
|
|
|
|
|
* The file URI that was requested.
|
|
|
|
|
*/
|
|
|
|
|
handleFileActivity: function WCF_handleFileActivity(aFileURI)
|
|
|
|
|
{
|
|
|
|
|
this.outputMessage(CATEGORY_NETWORK, this.logFileActivity, [aFileURI]);
|
|
|
|
|
},
|
|
|
|
|
|
2012-07-26 08:06:04 -07:00
|
|
|
|
/**
|
2013-04-11 05:27:49 -07:00
|
|
|
|
* Inform user that the window.console API has been replaced by a script
|
2012-07-26 08:06:04 -07:00
|
|
|
|
* in a content page.
|
|
|
|
|
*/
|
|
|
|
|
logWarningAboutReplacedAPI: function WCF_logWarningAboutReplacedAPI()
|
|
|
|
|
{
|
2012-09-26 10:02:04 -07:00
|
|
|
|
let node = this.createMessageNode(CATEGORY_JS, SEVERITY_WARNING,
|
|
|
|
|
l10n.getStr("ConsoleAPIDisabled"));
|
|
|
|
|
this.outputMessage(CATEGORY_JS, node);
|
2012-07-26 08:06:04 -07:00
|
|
|
|
},
|
|
|
|
|
|
2013-04-11 05:27:49 -07:00
|
|
|
|
/**
|
|
|
|
|
* Inform user that the string he tries to view is too long.
|
|
|
|
|
*/
|
|
|
|
|
logWarningAboutStringTooLong: function WCF_logWarningAboutStringTooLong()
|
|
|
|
|
{
|
|
|
|
|
let node = this.createMessageNode(CATEGORY_JS, SEVERITY_WARNING,
|
|
|
|
|
l10n.getStr("longStringTooLong"));
|
|
|
|
|
this.outputMessage(CATEGORY_JS, node);
|
|
|
|
|
},
|
|
|
|
|
|
2012-07-26 08:06:04 -07:00
|
|
|
|
/**
|
2012-10-05 04:54:43 -07:00
|
|
|
|
* Handle the network events coming from the remote Web Console.
|
2012-07-26 08:06:04 -07:00
|
|
|
|
*
|
2012-10-05 04:54:43 -07:00
|
|
|
|
* @param object aActor
|
|
|
|
|
* The NetworkEventActor grip.
|
|
|
|
|
*/
|
|
|
|
|
handleNetworkEvent: function WCF_handleNetworkEvent(aActor)
|
|
|
|
|
{
|
|
|
|
|
let networkInfo = {
|
|
|
|
|
node: null,
|
|
|
|
|
actor: aActor.actor,
|
|
|
|
|
discardRequestBody: true,
|
|
|
|
|
discardResponseBody: true,
|
|
|
|
|
startedDateTime: aActor.startedDateTime,
|
|
|
|
|
request: {
|
|
|
|
|
url: aActor.url,
|
|
|
|
|
method: aActor.method,
|
|
|
|
|
},
|
|
|
|
|
response: {},
|
|
|
|
|
timings: {},
|
|
|
|
|
updates: [], // track the list of network event updates
|
2013-05-25 02:25:36 -07:00
|
|
|
|
private: aActor.private,
|
2012-10-05 04:54:43 -07:00
|
|
|
|
};
|
2012-07-26 08:06:04 -07:00
|
|
|
|
|
2012-10-05 04:54:43 -07:00
|
|
|
|
this._networkRequests[aActor.actor] = networkInfo;
|
|
|
|
|
this.outputMessage(CATEGORY_NETWORK, this.logNetEvent, [aActor.actor]);
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Handle network event updates coming from the server.
|
|
|
|
|
*
|
|
|
|
|
* @param string aActorId
|
|
|
|
|
* The network event actor ID.
|
|
|
|
|
* @param string aType
|
|
|
|
|
* Update type.
|
|
|
|
|
* @param object aPacket
|
|
|
|
|
* Update details.
|
|
|
|
|
*/
|
|
|
|
|
handleNetworkEventUpdate:
|
|
|
|
|
function WCF_handleNetworkEventUpdate(aActorId, aType, aPacket)
|
|
|
|
|
{
|
|
|
|
|
let networkInfo = this._networkRequests[aActorId];
|
|
|
|
|
if (!networkInfo) {
|
2012-07-26 08:06:04 -07:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2012-10-05 04:54:43 -07:00
|
|
|
|
networkInfo.updates.push(aType);
|
|
|
|
|
|
|
|
|
|
switch (aType) {
|
|
|
|
|
case "requestHeaders":
|
|
|
|
|
networkInfo.request.headersSize = aPacket.headersSize;
|
|
|
|
|
break;
|
|
|
|
|
case "requestPostData":
|
|
|
|
|
networkInfo.discardRequestBody = aPacket.discardRequestBody;
|
|
|
|
|
networkInfo.request.bodySize = aPacket.dataSize;
|
|
|
|
|
break;
|
|
|
|
|
case "responseStart":
|
|
|
|
|
networkInfo.response.httpVersion = aPacket.response.httpVersion;
|
|
|
|
|
networkInfo.response.status = aPacket.response.status;
|
|
|
|
|
networkInfo.response.statusText = aPacket.response.statusText;
|
|
|
|
|
networkInfo.response.headersSize = aPacket.response.headersSize;
|
|
|
|
|
networkInfo.discardResponseBody = aPacket.response.discardResponseBody;
|
|
|
|
|
break;
|
|
|
|
|
case "responseContent":
|
|
|
|
|
networkInfo.response.content = {
|
|
|
|
|
mimeType: aPacket.mimeType,
|
|
|
|
|
};
|
|
|
|
|
networkInfo.response.bodySize = aPacket.contentSize;
|
|
|
|
|
networkInfo.discardResponseBody = aPacket.discardResponseBody;
|
|
|
|
|
break;
|
|
|
|
|
case "eventTimings":
|
|
|
|
|
networkInfo.totalTime = aPacket.totalTime;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2012-07-26 08:06:04 -07:00
|
|
|
|
|
2013-09-13 05:06:46 -07:00
|
|
|
|
if (networkInfo.node && this._updateNetMessage(aActorId)) {
|
|
|
|
|
this.emit("messages-updated", new Set([networkInfo.node]));
|
2012-07-26 08:06:04 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// For unit tests we pass the HTTP activity object to the test callback,
|
|
|
|
|
// once requests complete.
|
|
|
|
|
if (this.owner.lastFinishedRequestCallback &&
|
2012-10-05 04:54:43 -07:00
|
|
|
|
networkInfo.updates.indexOf("responseContent") > -1 &&
|
|
|
|
|
networkInfo.updates.indexOf("eventTimings") > -1) {
|
|
|
|
|
this.owner.lastFinishedRequestCallback(networkInfo, this);
|
2012-07-26 08:06:04 -07:00
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Update an output message to reflect the latest state of a network request,
|
2012-10-05 04:54:43 -07:00
|
|
|
|
* given a network event actor ID.
|
2012-07-26 08:06:04 -07:00
|
|
|
|
*
|
|
|
|
|
* @private
|
2012-10-05 04:54:43 -07:00
|
|
|
|
* @param string aActorId
|
|
|
|
|
* The network event actor ID for which you want to update the message.
|
2013-09-13 05:06:46 -07:00
|
|
|
|
* @return boolean
|
|
|
|
|
* |true| if the message node was updated, or |false| otherwise.
|
2012-07-26 08:06:04 -07:00
|
|
|
|
*/
|
2012-10-05 04:54:43 -07:00
|
|
|
|
_updateNetMessage: function WCF__updateNetMessage(aActorId)
|
2012-07-26 08:06:04 -07:00
|
|
|
|
{
|
2012-10-05 04:54:43 -07:00
|
|
|
|
let networkInfo = this._networkRequests[aActorId];
|
2012-07-26 08:06:04 -07:00
|
|
|
|
if (!networkInfo || !networkInfo.node) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let messageNode = networkInfo.node;
|
2012-10-05 04:54:43 -07:00
|
|
|
|
let updates = networkInfo.updates;
|
|
|
|
|
let hasEventTimings = updates.indexOf("eventTimings") > -1;
|
|
|
|
|
let hasResponseStart = updates.indexOf("responseStart") > -1;
|
|
|
|
|
let request = networkInfo.request;
|
|
|
|
|
let response = networkInfo.response;
|
2013-09-13 05:06:46 -07:00
|
|
|
|
let updated = false;
|
2012-10-05 04:54:43 -07:00
|
|
|
|
|
|
|
|
|
if (hasEventTimings || hasResponseStart) {
|
2012-07-26 08:06:04 -07:00
|
|
|
|
let status = [];
|
|
|
|
|
if (response.httpVersion && response.status) {
|
|
|
|
|
status = [response.httpVersion, response.status, response.statusText];
|
|
|
|
|
}
|
2012-10-05 04:54:43 -07:00
|
|
|
|
if (hasEventTimings) {
|
|
|
|
|
status.push(l10n.getFormatStr("NetworkPanel.durationMS",
|
|
|
|
|
[networkInfo.totalTime]));
|
2012-07-26 08:06:04 -07:00
|
|
|
|
}
|
|
|
|
|
let statusText = "[" + status.join(" ") + "]";
|
|
|
|
|
|
2013-09-05 09:34:22 -07:00
|
|
|
|
let statusNode = messageNode.getElementsByClassName("status")[0];
|
2013-09-13 05:06:46 -07:00
|
|
|
|
statusNode.textContent = statusText;
|
2012-07-26 08:06:04 -07:00
|
|
|
|
|
|
|
|
|
messageNode.clipboardText = [request.method, request.url, statusText]
|
|
|
|
|
.join(" ");
|
|
|
|
|
|
2012-10-05 04:54:43 -07:00
|
|
|
|
if (hasResponseStart && response.status >= MIN_HTTP_ERROR_CODE &&
|
2012-07-26 08:06:04 -07:00
|
|
|
|
response.status <= MAX_HTTP_ERROR_CODE) {
|
|
|
|
|
this.setMessageType(messageNode, CATEGORY_NETWORK, SEVERITY_ERROR);
|
|
|
|
|
}
|
2013-09-13 05:06:46 -07:00
|
|
|
|
|
|
|
|
|
updated = true;
|
2012-07-26 08:06:04 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (messageNode._netPanel) {
|
|
|
|
|
messageNode._netPanel.update();
|
|
|
|
|
}
|
2013-09-13 05:06:46 -07:00
|
|
|
|
|
|
|
|
|
return updated;
|
2012-07-26 08:06:04 -07:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Opens a NetworkPanel.
|
|
|
|
|
*
|
|
|
|
|
* @param nsIDOMNode aNode
|
|
|
|
|
* The message node you want the panel to be anchored to.
|
|
|
|
|
* @param object aHttpActivity
|
|
|
|
|
* The HTTP activity object that holds network request and response
|
|
|
|
|
* information. This object is given to the NetworkPanel constructor.
|
|
|
|
|
* @return object
|
|
|
|
|
* The new NetworkPanel instance.
|
|
|
|
|
*/
|
|
|
|
|
openNetworkPanel: function WCF_openNetworkPanel(aNode, aHttpActivity)
|
|
|
|
|
{
|
2012-10-05 04:54:43 -07:00
|
|
|
|
let actor = aHttpActivity.actor;
|
|
|
|
|
|
|
|
|
|
if (actor) {
|
|
|
|
|
this.webConsoleClient.getRequestHeaders(actor, function(aResponse) {
|
|
|
|
|
if (aResponse.error) {
|
|
|
|
|
Cu.reportError("WCF_openNetworkPanel getRequestHeaders:" +
|
|
|
|
|
aResponse.error);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2012-07-26 08:06:04 -07:00
|
|
|
|
|
2012-10-05 04:54:43 -07:00
|
|
|
|
aHttpActivity.request.headers = aResponse.headers;
|
2012-07-26 08:06:04 -07:00
|
|
|
|
|
2012-10-05 04:54:43 -07:00
|
|
|
|
this.webConsoleClient.getRequestCookies(actor, onRequestCookies);
|
|
|
|
|
}.bind(this));
|
|
|
|
|
}
|
2012-07-26 08:06:04 -07:00
|
|
|
|
|
2012-10-05 04:54:43 -07:00
|
|
|
|
let onRequestCookies = function(aResponse) {
|
|
|
|
|
if (aResponse.error) {
|
|
|
|
|
Cu.reportError("WCF_openNetworkPanel getRequestCookies:" +
|
|
|
|
|
aResponse.error);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
aHttpActivity.request.cookies = aResponse.cookies;
|
|
|
|
|
|
|
|
|
|
this.webConsoleClient.getResponseHeaders(actor, onResponseHeaders);
|
|
|
|
|
}.bind(this);
|
|
|
|
|
|
|
|
|
|
let onResponseHeaders = function(aResponse) {
|
|
|
|
|
if (aResponse.error) {
|
|
|
|
|
Cu.reportError("WCF_openNetworkPanel getResponseHeaders:" +
|
|
|
|
|
aResponse.error);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
aHttpActivity.response.headers = aResponse.headers;
|
|
|
|
|
|
|
|
|
|
this.webConsoleClient.getResponseCookies(actor, onResponseCookies);
|
|
|
|
|
}.bind(this);
|
|
|
|
|
|
|
|
|
|
let onResponseCookies = function(aResponse) {
|
|
|
|
|
if (aResponse.error) {
|
|
|
|
|
Cu.reportError("WCF_openNetworkPanel getResponseCookies:" +
|
|
|
|
|
aResponse.error);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2012-07-26 08:06:04 -07:00
|
|
|
|
|
2012-10-05 04:54:43 -07:00
|
|
|
|
aHttpActivity.response.cookies = aResponse.cookies;
|
|
|
|
|
|
|
|
|
|
this.webConsoleClient.getRequestPostData(actor, onRequestPostData);
|
|
|
|
|
}.bind(this);
|
|
|
|
|
|
|
|
|
|
let onRequestPostData = function(aResponse) {
|
|
|
|
|
if (aResponse.error) {
|
|
|
|
|
Cu.reportError("WCF_openNetworkPanel getRequestPostData:" +
|
|
|
|
|
aResponse.error);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
aHttpActivity.request.postData = aResponse.postData;
|
|
|
|
|
aHttpActivity.discardRequestBody = aResponse.postDataDiscarded;
|
|
|
|
|
|
|
|
|
|
this.webConsoleClient.getResponseContent(actor, onResponseContent);
|
|
|
|
|
}.bind(this);
|
|
|
|
|
|
|
|
|
|
let onResponseContent = function(aResponse) {
|
|
|
|
|
if (aResponse.error) {
|
|
|
|
|
Cu.reportError("WCF_openNetworkPanel getResponseContent:" +
|
|
|
|
|
aResponse.error);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
aHttpActivity.response.content = aResponse.content;
|
|
|
|
|
aHttpActivity.discardResponseBody = aResponse.contentDiscarded;
|
|
|
|
|
|
|
|
|
|
this.webConsoleClient.getEventTimings(actor, onEventTimings);
|
|
|
|
|
}.bind(this);
|
|
|
|
|
|
|
|
|
|
let onEventTimings = function(aResponse) {
|
|
|
|
|
if (aResponse.error) {
|
|
|
|
|
Cu.reportError("WCF_openNetworkPanel getEventTimings:" +
|
|
|
|
|
aResponse.error);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
aHttpActivity.timings = aResponse.timings;
|
|
|
|
|
|
|
|
|
|
openPanel();
|
|
|
|
|
}.bind(this);
|
|
|
|
|
|
|
|
|
|
let openPanel = function() {
|
|
|
|
|
aNode._netPanel = netPanel;
|
|
|
|
|
|
|
|
|
|
let panel = netPanel.panel;
|
|
|
|
|
panel.openPopup(aNode, "after_pointer", 0, 0, false, false);
|
|
|
|
|
panel.sizeTo(450, 500);
|
|
|
|
|
panel.setAttribute("hudId", this.hudId);
|
|
|
|
|
|
|
|
|
|
panel.addEventListener("popuphiding", function WCF_netPanel_onHide() {
|
|
|
|
|
panel.removeEventListener("popuphiding", WCF_netPanel_onHide);
|
|
|
|
|
|
|
|
|
|
aNode._panelOpen = false;
|
|
|
|
|
aNode._netPanel = null;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
aNode._panelOpen = true;
|
|
|
|
|
}.bind(this);
|
|
|
|
|
|
2012-11-05 08:41:59 -08:00
|
|
|
|
let netPanel = new NetworkPanel(this.popupset, aHttpActivity, this);
|
2012-10-05 04:54:43 -07:00
|
|
|
|
netPanel.linkNode = aNode;
|
|
|
|
|
|
|
|
|
|
if (!actor) {
|
|
|
|
|
openPanel();
|
|
|
|
|
}
|
2012-07-26 08:06:04 -07:00
|
|
|
|
|
|
|
|
|
return netPanel;
|
|
|
|
|
},
|
|
|
|
|
|
2012-10-05 04:54:43 -07:00
|
|
|
|
/**
|
|
|
|
|
* Handler for page location changes.
|
|
|
|
|
*
|
|
|
|
|
* @param string aURI
|
|
|
|
|
* New page location.
|
|
|
|
|
* @param string aTitle
|
|
|
|
|
* New page title.
|
|
|
|
|
*/
|
|
|
|
|
onLocationChange: function WCF_onLocationChange(aURI, aTitle)
|
|
|
|
|
{
|
|
|
|
|
this.contentLocation = aURI;
|
2012-11-30 00:07:59 -08:00
|
|
|
|
if (this.owner.onLocationChange) {
|
|
|
|
|
this.owner.onLocationChange(aURI, aTitle);
|
|
|
|
|
}
|
2012-10-05 04:54:43 -07:00
|
|
|
|
},
|
|
|
|
|
|
2013-08-02 10:19:23 -07:00
|
|
|
|
/**
|
|
|
|
|
* Handler for the tabNavigated notification.
|
|
|
|
|
*
|
|
|
|
|
* @param string aEvent
|
|
|
|
|
* Event name.
|
|
|
|
|
* @param object aPacket
|
|
|
|
|
* Notification packet received from the server.
|
|
|
|
|
*/
|
|
|
|
|
handleTabNavigated: function WCF_handleTabNavigated(aEvent, aPacket)
|
|
|
|
|
{
|
|
|
|
|
if (aEvent == "will-navigate") {
|
|
|
|
|
if (this.persistLog) {
|
|
|
|
|
let marker = new Messages.NavigationMarker(aPacket.url, Date.now());
|
|
|
|
|
this.output.addMessage(marker);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
this.jsterm.clearOutput();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (aPacket.url) {
|
|
|
|
|
this.onLocationChange(aPacket.url, aPacket.title);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (aEvent == "navigate" && !aPacket.nativeConsoleAPI) {
|
|
|
|
|
this.logWarningAboutReplacedAPI();
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
2012-07-26 08:06:04 -07:00
|
|
|
|
/**
|
|
|
|
|
* Output a message node. This filters a node appropriately, then sends it to
|
|
|
|
|
* the output, regrouping and pruning output as necessary.
|
|
|
|
|
*
|
|
|
|
|
* Note: this call is async - the given message node may not be displayed when
|
|
|
|
|
* you call this method.
|
|
|
|
|
*
|
|
|
|
|
* @param integer aCategory
|
|
|
|
|
* The category of the message you want to output. See the CATEGORY_*
|
|
|
|
|
* constants.
|
|
|
|
|
* @param function|nsIDOMElement aMethodOrNode
|
|
|
|
|
* The method that creates the message element to send to the output or
|
|
|
|
|
* the actual element. If a method is given it will be bound to the HUD
|
|
|
|
|
* object and the arguments will be |aArguments|.
|
|
|
|
|
* @param array [aArguments]
|
|
|
|
|
* If a method is given to output the message element then the method
|
|
|
|
|
* will be invoked with the list of arguments given here.
|
|
|
|
|
*/
|
|
|
|
|
outputMessage: function WCF_outputMessage(aCategory, aMethodOrNode, aArguments)
|
|
|
|
|
{
|
|
|
|
|
if (!this._outputQueue.length) {
|
|
|
|
|
// If the queue is empty we consider that now was the last output flush.
|
|
|
|
|
// This avoid an immediate output flush when the timer executes.
|
|
|
|
|
this._lastOutputFlush = Date.now();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this._outputQueue.push([aCategory, aMethodOrNode, aArguments]);
|
|
|
|
|
|
2012-10-05 09:15:51 -07:00
|
|
|
|
if (!this._outputTimerInitialized) {
|
|
|
|
|
this._initOutputTimer();
|
2012-07-26 08:06:04 -07:00
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Try to flush the output message queue. This takes the messages in the
|
|
|
|
|
* output queue and displays them. Outputting stops at MESSAGES_IN_INTERVAL.
|
|
|
|
|
* Further output is queued to happen later - see OUTPUT_INTERVAL.
|
|
|
|
|
*
|
|
|
|
|
* @private
|
|
|
|
|
*/
|
|
|
|
|
_flushMessageQueue: function WCF__flushMessageQueue()
|
|
|
|
|
{
|
2012-10-05 09:15:51 -07:00
|
|
|
|
if (!this._outputTimer) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2012-07-26 08:06:04 -07:00
|
|
|
|
let timeSinceFlush = Date.now() - this._lastOutputFlush;
|
|
|
|
|
if (this._outputQueue.length > MESSAGES_IN_INTERVAL &&
|
|
|
|
|
timeSinceFlush < THROTTLE_UPDATES) {
|
2012-10-05 09:15:51 -07:00
|
|
|
|
this._initOutputTimer();
|
2012-07-26 08:06:04 -07:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Determine how many messages we can display now.
|
|
|
|
|
let toDisplay = Math.min(this._outputQueue.length, MESSAGES_IN_INTERVAL);
|
|
|
|
|
if (toDisplay < 1) {
|
2012-10-05 09:15:51 -07:00
|
|
|
|
this._outputTimerInitialized = false;
|
2012-07-26 08:06:04 -07:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Try to prune the message queue.
|
|
|
|
|
let shouldPrune = false;
|
|
|
|
|
if (this._outputQueue.length > toDisplay && this._pruneOutputQueue()) {
|
|
|
|
|
toDisplay = Math.min(this._outputQueue.length, toDisplay);
|
|
|
|
|
shouldPrune = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let batch = this._outputQueue.splice(0, toDisplay);
|
|
|
|
|
if (!batch.length) {
|
2012-10-05 09:15:51 -07:00
|
|
|
|
this._outputTimerInitialized = false;
|
2012-07-26 08:06:04 -07:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let outputNode = this.outputNode;
|
|
|
|
|
let lastVisibleNode = null;
|
2013-09-13 05:06:46 -07:00
|
|
|
|
let scrollNode = outputNode.parentNode;
|
2012-07-26 08:06:04 -07:00
|
|
|
|
let scrolledToBottom = Utils.isOutputScrolledToBottom(outputNode);
|
|
|
|
|
let hudIdSupportsString = WebConsoleUtils.supportsString(this.hudId);
|
|
|
|
|
|
|
|
|
|
// Output the current batch of messages.
|
2013-04-11 05:27:49 -07:00
|
|
|
|
let newMessages = new Set();
|
|
|
|
|
let updatedMessages = new Set();
|
2012-07-26 08:06:04 -07:00
|
|
|
|
for (let item of batch) {
|
2013-04-10 08:22:29 -07:00
|
|
|
|
let result = this._outputMessageFromQueue(hudIdSupportsString, item);
|
|
|
|
|
if (result) {
|
2013-04-11 05:27:49 -07:00
|
|
|
|
if (result.isRepeated) {
|
|
|
|
|
updatedMessages.add(result.isRepeated);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
newMessages.add(result.node);
|
|
|
|
|
}
|
2013-04-10 08:22:29 -07:00
|
|
|
|
if (result.visible && result.node == this.outputNode.lastChild) {
|
|
|
|
|
lastVisibleNode = result.node;
|
|
|
|
|
}
|
2012-07-26 08:06:04 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let oldScrollHeight = 0;
|
|
|
|
|
|
|
|
|
|
// Prune messages if needed. We do not do this for every flush call to
|
|
|
|
|
// improve performance.
|
|
|
|
|
let removedNodes = 0;
|
|
|
|
|
if (shouldPrune || !this._outputQueue.length) {
|
2013-09-13 05:06:46 -07:00
|
|
|
|
oldScrollHeight = scrollNode.scrollHeight;
|
2012-07-26 08:06:04 -07:00
|
|
|
|
|
|
|
|
|
let categories = Object.keys(this._pruneCategoriesQueue);
|
|
|
|
|
categories.forEach(function _pruneOutput(aCategory) {
|
|
|
|
|
removedNodes += this.pruneOutputIfNecessary(aCategory);
|
|
|
|
|
}, this);
|
|
|
|
|
this._pruneCategoriesQueue = {};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let isInputOutput = lastVisibleNode &&
|
2013-09-05 09:34:22 -07:00
|
|
|
|
(lastVisibleNode.category == CATEGORY_INPUT ||
|
|
|
|
|
lastVisibleNode.category == CATEGORY_OUTPUT);
|
2012-07-26 08:06:04 -07:00
|
|
|
|
|
|
|
|
|
// Scroll to the new node if it is not filtered, and if the output node is
|
|
|
|
|
// scrolled at the bottom or if the new node is a jsterm input/output
|
|
|
|
|
// message.
|
|
|
|
|
if (lastVisibleNode && (scrolledToBottom || isInputOutput)) {
|
|
|
|
|
Utils.scrollToVisible(lastVisibleNode);
|
|
|
|
|
}
|
|
|
|
|
else if (!scrolledToBottom && removedNodes > 0 &&
|
2013-09-13 05:06:46 -07:00
|
|
|
|
oldScrollHeight != scrollNode.scrollHeight) {
|
2012-07-26 08:06:04 -07:00
|
|
|
|
// If there were pruned messages and if scroll is not at the bottom, then
|
|
|
|
|
// we need to adjust the scroll location.
|
2013-09-13 05:06:46 -07:00
|
|
|
|
scrollNode.scrollTop -= oldScrollHeight - scrollNode.scrollHeight;
|
2012-07-26 08:06:04 -07:00
|
|
|
|
}
|
|
|
|
|
|
2013-04-11 05:27:49 -07:00
|
|
|
|
if (newMessages.size) {
|
|
|
|
|
this.emit("messages-added", newMessages);
|
|
|
|
|
}
|
|
|
|
|
if (updatedMessages.size) {
|
|
|
|
|
this.emit("messages-updated", updatedMessages);
|
|
|
|
|
}
|
2013-04-10 08:22:29 -07:00
|
|
|
|
|
2012-07-26 08:06:04 -07:00
|
|
|
|
// If the queue is not empty, schedule another flush.
|
|
|
|
|
if (this._outputQueue.length > 0) {
|
2012-10-05 09:15:51 -07:00
|
|
|
|
this._initOutputTimer();
|
2012-07-26 08:06:04 -07:00
|
|
|
|
}
|
|
|
|
|
else {
|
2012-10-05 09:15:51 -07:00
|
|
|
|
this._outputTimerInitialized = false;
|
2013-09-13 05:06:46 -07:00
|
|
|
|
if (this._flushCallback) {
|
|
|
|
|
try {
|
|
|
|
|
this._flushCallback();
|
|
|
|
|
}
|
|
|
|
|
catch (ex) {
|
|
|
|
|
console.error(ex);
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-07-26 08:06:04 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this._lastOutputFlush = Date.now();
|
|
|
|
|
},
|
|
|
|
|
|
2012-10-05 09:15:51 -07:00
|
|
|
|
/**
|
|
|
|
|
* Initialize the output timer.
|
|
|
|
|
* @private
|
|
|
|
|
*/
|
|
|
|
|
_initOutputTimer: function WCF__initOutputTimer()
|
|
|
|
|
{
|
|
|
|
|
if (!this._outputTimer) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this._outputTimerInitialized = true;
|
|
|
|
|
this._outputTimer.initWithCallback(this._flushMessageQueue,
|
|
|
|
|
OUTPUT_INTERVAL,
|
|
|
|
|
Ci.nsITimer.TYPE_ONE_SHOT);
|
|
|
|
|
},
|
|
|
|
|
|
2012-07-26 08:06:04 -07:00
|
|
|
|
/**
|
|
|
|
|
* Output a message from the queue.
|
|
|
|
|
*
|
|
|
|
|
* @private
|
|
|
|
|
* @param nsISupportsString aHudIdSupportsString
|
|
|
|
|
* The HUD ID as an nsISupportsString.
|
|
|
|
|
* @param array aItem
|
|
|
|
|
* An item from the output queue - this item represents a message.
|
2013-04-10 08:22:29 -07:00
|
|
|
|
* @return object
|
|
|
|
|
* An object that holds the following properties:
|
|
|
|
|
* - node: the DOM element of the message.
|
|
|
|
|
* - isRepeated: the DOM element of the original message, if this is
|
|
|
|
|
* a repeated message, otherwise null.
|
|
|
|
|
* - visible: boolean that tells if the message is visible.
|
2012-07-26 08:06:04 -07:00
|
|
|
|
*/
|
|
|
|
|
_outputMessageFromQueue:
|
|
|
|
|
function WCF__outputMessageFromQueue(aHudIdSupportsString, aItem)
|
|
|
|
|
{
|
|
|
|
|
let [category, methodOrNode, args] = aItem;
|
|
|
|
|
|
|
|
|
|
let node = typeof methodOrNode == "function" ?
|
|
|
|
|
methodOrNode.apply(this, args || []) :
|
|
|
|
|
methodOrNode;
|
|
|
|
|
if (!node) {
|
2013-04-10 08:22:29 -07:00
|
|
|
|
return null;
|
2012-07-26 08:06:04 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let afterNode = node._outputAfterNode;
|
|
|
|
|
if (afterNode) {
|
|
|
|
|
delete node._outputAfterNode;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let isFiltered = this.filterMessageNode(node);
|
|
|
|
|
|
2013-01-31 09:19:06 -08:00
|
|
|
|
let isRepeated = this._filterRepeatedMessage(node);
|
2012-07-26 08:06:04 -07:00
|
|
|
|
|
2013-04-10 08:22:29 -07:00
|
|
|
|
let visible = !isRepeated && !isFiltered;
|
2012-07-26 08:06:04 -07:00
|
|
|
|
if (!isRepeated) {
|
|
|
|
|
this.outputNode.insertBefore(node,
|
|
|
|
|
afterNode ? afterNode.nextSibling : null);
|
|
|
|
|
this._pruneCategoriesQueue[node.category] = true;
|
2013-04-10 08:22:29 -07:00
|
|
|
|
|
|
|
|
|
let nodeID = node.getAttribute("id");
|
|
|
|
|
Services.obs.notifyObservers(aHudIdSupportsString,
|
|
|
|
|
"web-console-message-created", nodeID);
|
|
|
|
|
|
2012-07-26 08:06:04 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (node._onOutput) {
|
|
|
|
|
node._onOutput();
|
|
|
|
|
delete node._onOutput;
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-10 08:22:29 -07:00
|
|
|
|
return {
|
|
|
|
|
visible: visible,
|
|
|
|
|
node: node,
|
|
|
|
|
isRepeated: isRepeated,
|
|
|
|
|
};
|
2012-07-26 08:06:04 -07:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Prune the queue of messages to display. This avoids displaying messages
|
|
|
|
|
* that will be removed at the end of the queue anyway.
|
|
|
|
|
* @private
|
|
|
|
|
*/
|
|
|
|
|
_pruneOutputQueue: function WCF__pruneOutputQueue()
|
|
|
|
|
{
|
|
|
|
|
let nodes = {};
|
|
|
|
|
|
|
|
|
|
// Group the messages per category.
|
|
|
|
|
this._outputQueue.forEach(function(aItem, aIndex) {
|
|
|
|
|
let [category] = aItem;
|
|
|
|
|
if (!(category in nodes)) {
|
|
|
|
|
nodes[category] = [];
|
|
|
|
|
}
|
|
|
|
|
nodes[category].push(aIndex);
|
|
|
|
|
}, this);
|
|
|
|
|
|
|
|
|
|
let pruned = 0;
|
|
|
|
|
|
|
|
|
|
// Loop through the categories we found and prune if needed.
|
|
|
|
|
for (let category in nodes) {
|
|
|
|
|
let limit = Utils.logLimitForCategory(category);
|
|
|
|
|
let indexes = nodes[category];
|
|
|
|
|
if (indexes.length > limit) {
|
|
|
|
|
let n = Math.max(0, indexes.length - limit);
|
|
|
|
|
pruned += n;
|
|
|
|
|
for (let i = n - 1; i >= 0; i--) {
|
|
|
|
|
this._pruneItemFromQueue(this._outputQueue[indexes[i]]);
|
|
|
|
|
this._outputQueue.splice(indexes[i], 1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return pruned;
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Prune an item from the output queue.
|
|
|
|
|
*
|
|
|
|
|
* @private
|
|
|
|
|
* @param array aItem
|
|
|
|
|
* The item you want to remove from the output queue.
|
|
|
|
|
*/
|
|
|
|
|
_pruneItemFromQueue: function WCF__pruneItemFromQueue(aItem)
|
|
|
|
|
{
|
|
|
|
|
let [category, methodOrNode, args] = aItem;
|
2013-04-09 02:46:30 -07:00
|
|
|
|
if (typeof methodOrNode != "function" && methodOrNode._objectActors) {
|
|
|
|
|
for (let actor of methodOrNode._objectActors) {
|
|
|
|
|
this._releaseObject(actor);
|
|
|
|
|
}
|
|
|
|
|
methodOrNode._objectActors.clear();
|
2012-07-26 08:06:04 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (category == CATEGORY_NETWORK) {
|
|
|
|
|
let connectionId = null;
|
2012-10-05 04:54:43 -07:00
|
|
|
|
if (methodOrNode == this.logNetEvent) {
|
2012-07-26 08:06:04 -07:00
|
|
|
|
connectionId = args[0];
|
|
|
|
|
}
|
|
|
|
|
else if (typeof methodOrNode != "function") {
|
|
|
|
|
connectionId = methodOrNode._connectionId;
|
|
|
|
|
}
|
|
|
|
|
if (connectionId && connectionId in this._networkRequests) {
|
|
|
|
|
delete this._networkRequests[connectionId];
|
2012-10-05 04:54:43 -07:00
|
|
|
|
this._releaseObject(connectionId);
|
2012-07-26 08:06:04 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (category == CATEGORY_WEBDEV &&
|
|
|
|
|
methodOrNode == this.logConsoleAPIMessage) {
|
2013-04-09 02:46:30 -07:00
|
|
|
|
args[0].arguments.forEach((aValue) => {
|
|
|
|
|
if (WebConsoleUtils.isActorGrip(aValue)) {
|
2012-09-26 10:02:04 -07:00
|
|
|
|
this._releaseObject(aValue.actor);
|
|
|
|
|
}
|
2013-04-09 02:46:30 -07:00
|
|
|
|
});
|
2012-07-26 08:06:04 -07:00
|
|
|
|
}
|
2013-06-04 08:47:39 -07:00
|
|
|
|
else if (category == CATEGORY_JS &&
|
|
|
|
|
methodOrNode == this.reportPageError) {
|
|
|
|
|
let pageError = args[1];
|
|
|
|
|
for (let prop of ["errorMessage", "lineText"]) {
|
|
|
|
|
let grip = pageError[prop];
|
|
|
|
|
if (WebConsoleUtils.isActorGrip(grip)) {
|
|
|
|
|
this._releaseObject(grip.actor);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (category == CATEGORY_JS &&
|
|
|
|
|
methodOrNode == this._reportLogMessage) {
|
|
|
|
|
if (WebConsoleUtils.isActorGrip(args[0].message)) {
|
|
|
|
|
this._releaseObject(args[0].message.actor);
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-07-26 08:06:04 -07:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Ensures that the number of message nodes of type aCategory don't exceed that
|
|
|
|
|
* category's line limit by removing old messages as needed.
|
|
|
|
|
*
|
|
|
|
|
* @param integer aCategory
|
|
|
|
|
* The category of message nodes to prune if needed.
|
|
|
|
|
* @return number
|
|
|
|
|
* The number of removed nodes.
|
|
|
|
|
*/
|
|
|
|
|
pruneOutputIfNecessary: function WCF_pruneOutputIfNecessary(aCategory)
|
|
|
|
|
{
|
|
|
|
|
let logLimit = Utils.logLimitForCategory(aCategory);
|
2013-09-05 09:34:22 -07:00
|
|
|
|
let messageNodes = this.outputNode.querySelectorAll(".message[category=" +
|
|
|
|
|
CATEGORY_CLASS_FRAGMENTS[aCategory] + "]");
|
2012-07-26 08:06:04 -07:00
|
|
|
|
let n = Math.max(0, messageNodes.length - logLimit);
|
|
|
|
|
let toRemove = Array.prototype.slice.call(messageNodes, 0, n);
|
|
|
|
|
toRemove.forEach(this.removeOutputMessage, this);
|
|
|
|
|
|
|
|
|
|
return n;
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Remove a given message from the output.
|
|
|
|
|
*
|
|
|
|
|
* @param nsIDOMNode aNode
|
|
|
|
|
* The message node you want to remove.
|
|
|
|
|
*/
|
|
|
|
|
removeOutputMessage: function WCF_removeOutputMessage(aNode)
|
|
|
|
|
{
|
2013-04-09 02:46:30 -07:00
|
|
|
|
if (aNode._objectActors) {
|
|
|
|
|
for (let actor of aNode._objectActors) {
|
|
|
|
|
this._releaseObject(actor);
|
|
|
|
|
}
|
|
|
|
|
aNode._objectActors.clear();
|
2012-07-26 08:06:04 -07:00
|
|
|
|
}
|
|
|
|
|
|
2013-09-05 09:34:22 -07:00
|
|
|
|
if (aNode.category == CATEGORY_CSS ||
|
|
|
|
|
aNode.category == CATEGORY_SECURITY) {
|
|
|
|
|
let repeatNode = aNode.getElementsByClassName("repeats")[0];
|
2013-02-05 08:44:41 -08:00
|
|
|
|
if (repeatNode && repeatNode._uid) {
|
2013-04-22 18:07:36 -07:00
|
|
|
|
delete this._repeatNodes[repeatNode._uid];
|
2013-02-05 08:44:41 -08:00
|
|
|
|
}
|
2012-07-26 08:06:04 -07:00
|
|
|
|
}
|
2012-10-05 04:54:43 -07:00
|
|
|
|
else if (aNode._connectionId &&
|
2013-09-05 09:34:22 -07:00
|
|
|
|
aNode.category == CATEGORY_NETWORK) {
|
2012-07-26 08:06:04 -07:00
|
|
|
|
delete this._networkRequests[aNode._connectionId];
|
2012-10-05 04:54:43 -07:00
|
|
|
|
this._releaseObject(aNode._connectionId);
|
2012-07-26 08:06:04 -07:00
|
|
|
|
}
|
2013-09-05 09:34:22 -07:00
|
|
|
|
else if (aNode.classList.contains("inlined-variables-view")) {
|
2013-04-09 02:46:30 -07:00
|
|
|
|
let view = aNode._variablesView;
|
2013-06-14 10:42:52 -07:00
|
|
|
|
if (view) {
|
|
|
|
|
view.controller.releaseActors();
|
2013-04-09 02:46:30 -07:00
|
|
|
|
}
|
|
|
|
|
aNode._variablesView = null;
|
2012-07-26 08:06:04 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (aNode.parentNode) {
|
|
|
|
|
aNode.parentNode.removeChild(aNode);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Given a category and message body, creates a DOM node to represent an
|
|
|
|
|
* incoming message. The timestamp is automatically added.
|
|
|
|
|
*
|
|
|
|
|
* @param number aCategory
|
|
|
|
|
* The category of the message: one of the CATEGORY_* constants.
|
|
|
|
|
* @param number aSeverity
|
|
|
|
|
* The severity of the message: one of the SEVERITY_* constants;
|
|
|
|
|
* @param string|nsIDOMNode aBody
|
|
|
|
|
* The body of the message, either a simple string or a DOM node.
|
|
|
|
|
* @param string aSourceURL [optional]
|
|
|
|
|
* The URL of the source file that emitted the error.
|
|
|
|
|
* @param number aSourceLine [optional]
|
|
|
|
|
* The line number on which the error occurred. If zero or omitted,
|
|
|
|
|
* there is no line number associated with this message.
|
|
|
|
|
* @param string aClipboardText [optional]
|
|
|
|
|
* The text that should be copied to the clipboard when this node is
|
|
|
|
|
* copied. If omitted, defaults to the body text. If `aBody` is not
|
|
|
|
|
* a string, then the clipboard text must be supplied.
|
|
|
|
|
* @param number aLevel [optional]
|
|
|
|
|
* The level of the console API message.
|
|
|
|
|
* @param number aTimeStamp [optional]
|
|
|
|
|
* The timestamp to use for this message node. If omitted, the current
|
|
|
|
|
* date and time is used.
|
|
|
|
|
* @return nsIDOMNode
|
2013-09-13 05:06:46 -07:00
|
|
|
|
* The message node: a DIV ready to be inserted into the Web Console
|
|
|
|
|
* output node.
|
2012-07-26 08:06:04 -07:00
|
|
|
|
*/
|
|
|
|
|
createMessageNode:
|
|
|
|
|
function WCF_createMessageNode(aCategory, aSeverity, aBody, aSourceURL,
|
|
|
|
|
aSourceLine, aClipboardText, aLevel, aTimeStamp)
|
|
|
|
|
{
|
|
|
|
|
if (typeof aBody != "string" && aClipboardText == null && aBody.innerText) {
|
|
|
|
|
aClipboardText = aBody.innerText;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Make the icon container, which is a vertical box. Its purpose is to
|
|
|
|
|
// ensure that the icon stays anchored at the top of the message even for
|
|
|
|
|
// long multi-line messages.
|
2013-09-13 05:06:46 -07:00
|
|
|
|
let iconContainer = this.document.createElementNS(XHTML_NS, "span");
|
2013-09-05 09:34:22 -07:00
|
|
|
|
iconContainer.className = "icon";
|
2012-07-26 08:06:04 -07:00
|
|
|
|
|
|
|
|
|
// Create the message body, which contains the actual text of the message.
|
2013-09-13 05:06:46 -07:00
|
|
|
|
let bodyNode = this.document.createElementNS(XHTML_NS, "span");
|
2013-09-05 09:34:22 -07:00
|
|
|
|
bodyNode.className = "body devtools-monospace";
|
2012-07-26 08:06:04 -07:00
|
|
|
|
|
2013-04-09 02:46:30 -07:00
|
|
|
|
// Store the body text, since it is needed later for the variables view.
|
2012-07-26 08:06:04 -07:00
|
|
|
|
let body = aBody;
|
|
|
|
|
// If a string was supplied for the body, turn it into a DOM node and an
|
|
|
|
|
// associated clipboard string now.
|
|
|
|
|
aClipboardText = aClipboardText ||
|
|
|
|
|
(aBody + (aSourceURL ? " @ " + aSourceURL : "") +
|
|
|
|
|
(aSourceLine ? ":" + aSourceLine : ""));
|
|
|
|
|
|
2013-09-13 05:06:46 -07:00
|
|
|
|
let timestamp = aTimeStamp || Date.now();
|
|
|
|
|
|
2012-08-03 13:14:01 -07:00
|
|
|
|
// Create the containing node and append all its elements to it.
|
2013-09-13 05:06:46 -07:00
|
|
|
|
let node = this.document.createElementNS(XHTML_NS, "div");
|
|
|
|
|
node.id = "console-msg-" + gSequenceId();
|
2013-09-05 09:34:22 -07:00
|
|
|
|
node.className = "message";
|
2013-09-13 05:06:46 -07:00
|
|
|
|
node.clipboardText = aClipboardText;
|
|
|
|
|
node.timestamp = timestamp;
|
|
|
|
|
this.setMessageType(node, aCategory, aSeverity);
|
2012-08-03 13:14:01 -07:00
|
|
|
|
|
|
|
|
|
if (aBody instanceof Ci.nsIDOMNode) {
|
|
|
|
|
bodyNode.appendChild(aBody);
|
2012-08-03 02:01:14 -07:00
|
|
|
|
}
|
2012-08-03 13:14:01 -07:00
|
|
|
|
else {
|
|
|
|
|
let str = undefined;
|
|
|
|
|
if (aLevel == "dir") {
|
2013-04-09 02:46:30 -07:00
|
|
|
|
str = VariablesView.getString(aBody.arguments[0]);
|
2012-08-03 13:14:01 -07:00
|
|
|
|
}
|
|
|
|
|
else if (["log", "info", "warn", "error", "debug"].indexOf(aLevel) > -1 &&
|
|
|
|
|
typeof aBody == "object") {
|
|
|
|
|
this._makeConsoleLogMessageBody(node, bodyNode, aBody);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
str = aBody;
|
|
|
|
|
}
|
2012-08-03 02:01:14 -07:00
|
|
|
|
|
2012-08-03 13:14:01 -07:00
|
|
|
|
if (str !== undefined) {
|
|
|
|
|
aBody = this.document.createTextNode(str);
|
|
|
|
|
bodyNode.appendChild(aBody);
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-07-26 08:06:04 -07:00
|
|
|
|
|
2013-09-13 05:06:46 -07:00
|
|
|
|
// Add the message repeats node only when needed.
|
|
|
|
|
let repeatNode = null;
|
|
|
|
|
if (aCategory != CATEGORY_INPUT && aCategory != CATEGORY_OUTPUT &&
|
|
|
|
|
aCategory != CATEGORY_NETWORK) {
|
|
|
|
|
repeatNode = this.document.createElementNS(XHTML_NS, "span");
|
|
|
|
|
repeatNode.setAttribute("value", "1");
|
2013-09-05 09:34:22 -07:00
|
|
|
|
repeatNode.className = "repeats";
|
2013-09-13 05:06:46 -07:00
|
|
|
|
repeatNode.textContent = 1;
|
|
|
|
|
repeatNode._uid = [bodyNode.textContent, aCategory, aSeverity, aLevel,
|
|
|
|
|
aSourceURL, aSourceLine].join(":");
|
|
|
|
|
}
|
2012-07-26 08:06:04 -07:00
|
|
|
|
|
|
|
|
|
// Create the timestamp.
|
2013-09-13 05:06:46 -07:00
|
|
|
|
let timestampNode = this.document.createElementNS(XHTML_NS, "span");
|
2013-09-05 09:34:22 -07:00
|
|
|
|
timestampNode.className = "timestamp devtools-monospace";
|
2013-09-13 05:06:46 -07:00
|
|
|
|
// Apply the current group by indenting appropriately.
|
|
|
|
|
timestampNode.style.marginRight = this.groupDepth * GROUP_INDENT + "px";
|
2013-08-26 01:24:41 -07:00
|
|
|
|
|
2012-07-26 08:06:04 -07:00
|
|
|
|
let timestampString = l10n.timestampString(timestamp);
|
2013-09-13 05:06:46 -07:00
|
|
|
|
timestampNode.textContent = timestampString + " ";
|
2012-07-26 08:06:04 -07:00
|
|
|
|
|
|
|
|
|
// Create the source location (e.g. www.example.com:6) that sits on the
|
|
|
|
|
// right side of the message, if applicable.
|
|
|
|
|
let locationNode;
|
2013-04-09 02:46:30 -07:00
|
|
|
|
if (aSourceURL && IGNORED_SOURCE_URLS.indexOf(aSourceURL) == -1) {
|
2012-07-26 08:06:04 -07:00
|
|
|
|
locationNode = this.createLocationNode(aSourceURL, aSourceLine);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
node.appendChild(timestampNode);
|
|
|
|
|
node.appendChild(iconContainer);
|
2013-04-09 02:46:30 -07:00
|
|
|
|
|
|
|
|
|
// Display the variables view after the message node.
|
2012-07-26 08:06:04 -07:00
|
|
|
|
if (aLevel == "dir") {
|
2013-09-13 05:06:46 -07:00
|
|
|
|
bodyNode.style.height = (this.window.innerHeight *
|
|
|
|
|
CONSOLE_DIR_VIEW_HEIGHT) + "px";
|
2013-04-09 02:46:30 -07:00
|
|
|
|
|
|
|
|
|
let options = {
|
|
|
|
|
objectActor: body.arguments[0],
|
2013-09-13 05:06:46 -07:00
|
|
|
|
targetElement: bodyNode,
|
2013-04-09 02:46:30 -07:00
|
|
|
|
hideFilterInput: true,
|
|
|
|
|
};
|
2013-05-10 03:15:11 -07:00
|
|
|
|
this.jsterm.openVariablesView(options).then((aView) => {
|
|
|
|
|
node._variablesView = aView;
|
|
|
|
|
if (node.classList.contains("hidden-message")) {
|
|
|
|
|
node.classList.remove("hidden-message");
|
|
|
|
|
}
|
|
|
|
|
});
|
2013-04-09 02:46:30 -07:00
|
|
|
|
|
2013-09-05 09:34:22 -07:00
|
|
|
|
node.classList.add("inlined-variables-view");
|
2012-07-26 08:06:04 -07:00
|
|
|
|
}
|
2013-09-13 05:06:46 -07:00
|
|
|
|
|
|
|
|
|
node.appendChild(bodyNode);
|
|
|
|
|
if (repeatNode) {
|
|
|
|
|
node.appendChild(repeatNode);
|
2012-07-26 08:06:04 -07:00
|
|
|
|
}
|
|
|
|
|
if (locationNode) {
|
|
|
|
|
node.appendChild(locationNode);
|
|
|
|
|
}
|
2013-09-19 11:03:10 -07:00
|
|
|
|
node.appendChild(this.document.createTextNode("\n"));
|
2012-07-26 08:06:04 -07:00
|
|
|
|
|
|
|
|
|
return node;
|
|
|
|
|
},
|
|
|
|
|
|
2012-08-03 13:14:01 -07:00
|
|
|
|
/**
|
|
|
|
|
* Make the message body for console.log() calls.
|
|
|
|
|
*
|
|
|
|
|
* @private
|
|
|
|
|
* @param nsIDOMElement aMessage
|
|
|
|
|
* The message element that holds the output for the given call.
|
|
|
|
|
* @param nsIDOMElement aContainer
|
|
|
|
|
* The specific element that will hold each part of the console.log
|
|
|
|
|
* output.
|
|
|
|
|
* @param object aBody
|
|
|
|
|
* The object given by this.logConsoleAPIMessage(). This object holds
|
2012-09-26 10:02:04 -07:00
|
|
|
|
* the call information that we need to display - mainly the arguments
|
|
|
|
|
* array of the given API call.
|
2012-08-03 13:14:01 -07:00
|
|
|
|
*/
|
|
|
|
|
_makeConsoleLogMessageBody:
|
|
|
|
|
function WCF__makeConsoleLogMessageBody(aMessage, aContainer, aBody)
|
|
|
|
|
{
|
|
|
|
|
Object.defineProperty(aMessage, "_panelOpen", {
|
|
|
|
|
get: function() {
|
2013-09-13 05:06:46 -07:00
|
|
|
|
let nodes = aContainer.getElementsByTagName("a");
|
2012-08-03 13:14:01 -07:00
|
|
|
|
return Array.prototype.some.call(nodes, function(aNode) {
|
|
|
|
|
return aNode._panelOpen;
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
enumerable: true,
|
|
|
|
|
configurable: false
|
|
|
|
|
});
|
|
|
|
|
|
2012-09-26 10:02:04 -07:00
|
|
|
|
aBody.arguments.forEach(function(aItem) {
|
2012-08-03 13:14:01 -07:00
|
|
|
|
if (aContainer.firstChild) {
|
|
|
|
|
aContainer.appendChild(this.document.createTextNode(" "));
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-09 02:46:30 -07:00
|
|
|
|
let text = VariablesView.getString(aItem);
|
|
|
|
|
let inspectable = !VariablesView.isPrimitive({ value: aItem });
|
2012-09-26 10:02:04 -07:00
|
|
|
|
|
2013-04-09 02:46:30 -07:00
|
|
|
|
if (aItem && typeof aItem != "object" || !inspectable) {
|
2012-08-03 13:14:01 -07:00
|
|
|
|
aContainer.appendChild(this.document.createTextNode(text));
|
2012-11-05 08:41:59 -08:00
|
|
|
|
|
2013-05-08 11:54:57 -07:00
|
|
|
|
if (aItem.type && aItem.type == "longString") {
|
2013-09-13 05:06:46 -07:00
|
|
|
|
let ellipsis = this.document.createElementNS(XHTML_NS, "a");
|
2012-11-05 08:41:59 -08:00
|
|
|
|
ellipsis.classList.add("longStringEllipsis");
|
|
|
|
|
ellipsis.textContent = l10n.getStr("longStringEllipsis");
|
2013-09-05 09:29:13 -07:00
|
|
|
|
ellipsis.href = "#";
|
|
|
|
|
ellipsis.draggable = false;
|
2012-11-05 08:41:59 -08:00
|
|
|
|
|
2013-04-09 02:46:30 -07:00
|
|
|
|
let formatter = function(s) '"' + s + '"';
|
|
|
|
|
|
2012-11-05 08:41:59 -08:00
|
|
|
|
this._addMessageLinkCallback(ellipsis,
|
2013-04-09 02:46:30 -07:00
|
|
|
|
this._longStringClick.bind(this, aMessage, aItem, formatter));
|
2012-11-05 08:41:59 -08:00
|
|
|
|
|
|
|
|
|
aContainer.appendChild(ellipsis);
|
|
|
|
|
}
|
2012-08-03 13:14:01 -07:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2012-09-26 10:02:04 -07:00
|
|
|
|
// For inspectable objects.
|
2013-09-13 05:06:46 -07:00
|
|
|
|
let elem = this.document.createElementNS(XHTML_NS, "a");
|
2012-08-03 13:14:01 -07:00
|
|
|
|
elem.setAttribute("aria-haspopup", "true");
|
2013-09-13 05:06:46 -07:00
|
|
|
|
elem.textContent = text;
|
2013-09-05 09:29:13 -07:00
|
|
|
|
elem.href = "#";
|
|
|
|
|
elem.draggable = false;
|
2012-08-03 13:14:01 -07:00
|
|
|
|
|
|
|
|
|
this._addMessageLinkCallback(elem,
|
2013-04-09 02:46:30 -07:00
|
|
|
|
this._consoleLogClick.bind(this, elem, aItem));
|
2012-08-03 13:14:01 -07:00
|
|
|
|
|
|
|
|
|
aContainer.appendChild(elem);
|
|
|
|
|
}, this);
|
|
|
|
|
},
|
|
|
|
|
|
2012-11-05 08:41:59 -08:00
|
|
|
|
/**
|
|
|
|
|
* Click event handler for the ellipsis shown immediately after a long string.
|
|
|
|
|
* This method retrieves the full string and updates the console output to
|
|
|
|
|
* show it.
|
|
|
|
|
*
|
|
|
|
|
* @private
|
|
|
|
|
* @param nsIDOMElement aMessage
|
|
|
|
|
* The message element.
|
|
|
|
|
* @param object aActor
|
|
|
|
|
* The LongStringActor instance we work with.
|
|
|
|
|
* @param [function] aFormatter
|
|
|
|
|
* Optional function you can use to format the string received from the
|
|
|
|
|
* server, before being displayed in the console.
|
|
|
|
|
* @param nsIDOMElement aEllipsis
|
|
|
|
|
* The DOM element the user can click on to expand the string.
|
|
|
|
|
*/
|
|
|
|
|
_longStringClick:
|
2013-09-05 09:29:13 -07:00
|
|
|
|
function WCF__longStringClick(aMessage, aActor, aFormatter, aEllipsis)
|
2012-11-05 08:41:59 -08:00
|
|
|
|
{
|
|
|
|
|
if (!aFormatter) {
|
|
|
|
|
aFormatter = function(s) s;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let longString = this.webConsoleClient.longString(aActor);
|
2013-04-11 05:27:49 -07:00
|
|
|
|
let toIndex = Math.min(longString.length, MAX_LONG_STRING_LENGTH);
|
|
|
|
|
longString.substring(longString.initial.length, toIndex,
|
2012-11-05 08:41:59 -08:00
|
|
|
|
function WCF__onSubstring(aResponse) {
|
|
|
|
|
if (aResponse.error) {
|
|
|
|
|
Cu.reportError("WCF__longStringClick substring failure: " +
|
|
|
|
|
aResponse.error);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let node = aEllipsis.previousSibling;
|
|
|
|
|
node.textContent = aFormatter(longString.initial + aResponse.substring);
|
|
|
|
|
aEllipsis.parentNode.removeChild(aEllipsis);
|
|
|
|
|
|
|
|
|
|
if (aMessage.category == CATEGORY_WEBDEV ||
|
|
|
|
|
aMessage.category == CATEGORY_OUTPUT) {
|
|
|
|
|
aMessage.clipboardText = aMessage.textContent;
|
|
|
|
|
}
|
2013-04-11 05:27:49 -07:00
|
|
|
|
|
|
|
|
|
this.emit("messages-updated", new Set([aMessage]));
|
|
|
|
|
|
|
|
|
|
if (toIndex != longString.length) {
|
|
|
|
|
this.logWarningAboutStringTooLong();
|
|
|
|
|
}
|
|
|
|
|
}.bind(this));
|
2012-11-05 08:41:59 -08:00
|
|
|
|
},
|
|
|
|
|
|
2012-07-26 08:06:04 -07:00
|
|
|
|
/**
|
2013-09-13 05:06:46 -07:00
|
|
|
|
* Creates the anchor that displays the textual location of an incoming
|
2012-07-26 08:06:04 -07:00
|
|
|
|
* message.
|
|
|
|
|
*
|
|
|
|
|
* @param string aSourceURL
|
|
|
|
|
* The URL of the source file responsible for the error.
|
|
|
|
|
* @param number aSourceLine [optional]
|
|
|
|
|
* The line number on which the error occurred. If zero or omitted,
|
|
|
|
|
* there is no line number associated with this message.
|
|
|
|
|
* @return nsIDOMNode
|
2013-09-13 05:06:46 -07:00
|
|
|
|
* The new anchor element, ready to be added to the message node.
|
2012-07-26 08:06:04 -07:00
|
|
|
|
*/
|
|
|
|
|
createLocationNode: function WCF_createLocationNode(aSourceURL, aSourceLine)
|
|
|
|
|
{
|
2013-09-13 05:06:46 -07:00
|
|
|
|
let locationNode = this.document.createElementNS(XHTML_NS, "a");
|
2012-07-26 08:06:04 -07:00
|
|
|
|
|
|
|
|
|
// Create the text, which consists of an abbreviated version of the URL
|
2012-09-14 13:12:57 -07:00
|
|
|
|
// plus an optional line number. Scratchpad URLs should not be abbreviated.
|
2013-05-30 12:23:11 -07:00
|
|
|
|
let displayLocation;
|
|
|
|
|
let fullURL;
|
2013-09-05 09:29:13 -07:00
|
|
|
|
let isScratchpad = false;
|
2012-09-14 13:12:57 -07:00
|
|
|
|
|
|
|
|
|
if (/^Scratchpad\/\d+$/.test(aSourceURL)) {
|
2013-05-30 12:23:11 -07:00
|
|
|
|
displayLocation = aSourceURL;
|
|
|
|
|
fullURL = aSourceURL;
|
2013-09-05 09:29:13 -07:00
|
|
|
|
isScratchpad = true;
|
2012-09-14 13:12:57 -07:00
|
|
|
|
}
|
|
|
|
|
else {
|
2013-05-30 12:23:11 -07:00
|
|
|
|
fullURL = aSourceURL.split(" -> ").pop();
|
|
|
|
|
displayLocation = WebConsoleUtils.abbreviateSourceURL(fullURL);
|
2012-09-14 13:12:57 -07:00
|
|
|
|
}
|
|
|
|
|
|
2012-07-26 08:06:04 -07:00
|
|
|
|
if (aSourceLine) {
|
2013-05-30 12:23:11 -07:00
|
|
|
|
displayLocation += ":" + aSourceLine;
|
2012-11-16 08:28:20 -08:00
|
|
|
|
locationNode.sourceLine = aSourceLine;
|
2012-07-26 08:06:04 -07:00
|
|
|
|
}
|
2012-09-14 13:12:57 -07:00
|
|
|
|
|
2013-09-13 05:06:46 -07:00
|
|
|
|
locationNode.textContent = " " + displayLocation;
|
2013-09-05 09:29:13 -07:00
|
|
|
|
locationNode.href = isScratchpad ? "#" : fullURL;
|
|
|
|
|
locationNode.draggable = false;
|
2012-07-26 08:06:04 -07:00
|
|
|
|
locationNode.setAttribute("title", aSourceURL);
|
2013-09-05 09:34:22 -07:00
|
|
|
|
locationNode.className = "location devtools-monospace";
|
2012-07-26 08:06:04 -07:00
|
|
|
|
|
|
|
|
|
// Make the location clickable.
|
2013-09-05 09:29:13 -07:00
|
|
|
|
this._addMessageLinkCallback(locationNode, () => {
|
|
|
|
|
if (isScratchpad) {
|
2013-10-04 12:44:09 -07:00
|
|
|
|
this.owner.viewSourceInScratchpad(aSourceURL);
|
2012-07-26 08:06:04 -07:00
|
|
|
|
}
|
2012-09-25 10:32:11 -07:00
|
|
|
|
else if (locationNode.parentNode.category == CATEGORY_CSS) {
|
2013-05-30 12:23:11 -07:00
|
|
|
|
this.owner.viewSourceInStyleEditor(fullURL, aSourceLine);
|
2012-09-25 10:32:11 -07:00
|
|
|
|
}
|
2012-12-16 15:10:44 -08:00
|
|
|
|
else if (locationNode.parentNode.category == CATEGORY_JS ||
|
|
|
|
|
locationNode.parentNode.category == CATEGORY_WEBDEV) {
|
2013-05-30 12:23:11 -07:00
|
|
|
|
this.owner.viewSourceInDebugger(fullURL, aSourceLine);
|
2012-12-16 15:10:44 -08:00
|
|
|
|
}
|
2012-09-25 10:32:11 -07:00
|
|
|
|
else {
|
2013-05-30 12:23:11 -07:00
|
|
|
|
this.owner.viewSource(fullURL, aSourceLine);
|
2012-09-25 10:32:11 -07:00
|
|
|
|
}
|
2013-09-05 09:29:13 -07:00
|
|
|
|
});
|
2012-07-26 08:06:04 -07:00
|
|
|
|
|
|
|
|
|
return locationNode;
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
2013-09-05 09:34:22 -07:00
|
|
|
|
* Adjusts the category and severity of the given message.
|
2012-07-26 08:06:04 -07:00
|
|
|
|
*
|
|
|
|
|
* @param nsIDOMNode aMessageNode
|
|
|
|
|
* The message node to alter.
|
2013-09-05 09:34:22 -07:00
|
|
|
|
* @param number aCategory
|
|
|
|
|
* The category for the message; one of the CATEGORY_ constants.
|
|
|
|
|
* @param number aSeverity
|
|
|
|
|
* The severity for the message; one of the SEVERITY_ constants.
|
2012-07-26 08:06:04 -07:00
|
|
|
|
* @return void
|
|
|
|
|
*/
|
|
|
|
|
setMessageType:
|
2013-09-05 09:34:22 -07:00
|
|
|
|
function WCF_setMessageType(aMessageNode, aCategory, aSeverity)
|
2012-07-26 08:06:04 -07:00
|
|
|
|
{
|
2013-09-05 09:34:22 -07:00
|
|
|
|
aMessageNode.category = aCategory;
|
|
|
|
|
aMessageNode.severity = aSeverity;
|
|
|
|
|
aMessageNode.setAttribute("category", CATEGORY_CLASS_FRAGMENTS[aCategory]);
|
|
|
|
|
aMessageNode.setAttribute("severity", SEVERITY_CLASS_FRAGMENTS[aSeverity]);
|
|
|
|
|
aMessageNode.setAttribute("filter", MESSAGE_PREFERENCE_KEYS[aCategory][aSeverity]);
|
2012-07-26 08:06:04 -07:00
|
|
|
|
},
|
|
|
|
|
|
2012-08-03 13:14:01 -07:00
|
|
|
|
/**
|
|
|
|
|
* Add the mouse event handlers needed to make a link.
|
|
|
|
|
*
|
|
|
|
|
* @private
|
|
|
|
|
* @param nsIDOMNode aNode
|
|
|
|
|
* The node for which you want to add the event handlers.
|
|
|
|
|
* @param function aCallback
|
|
|
|
|
* The function you want to invoke on click.
|
|
|
|
|
*/
|
|
|
|
|
_addMessageLinkCallback: function WCF__addMessageLinkCallback(aNode, aCallback)
|
|
|
|
|
{
|
2012-07-26 08:06:04 -07:00
|
|
|
|
aNode.addEventListener("mousedown", function(aEvent) {
|
2013-09-05 09:29:13 -07:00
|
|
|
|
this._mousedown = true;
|
2012-07-26 08:06:04 -07:00
|
|
|
|
this._startX = aEvent.clientX;
|
|
|
|
|
this._startY = aEvent.clientY;
|
|
|
|
|
}, false);
|
|
|
|
|
|
|
|
|
|
aNode.addEventListener("click", function(aEvent) {
|
2013-09-05 09:29:13 -07:00
|
|
|
|
let mousedown = this._mousedown;
|
|
|
|
|
this._mousedown = false;
|
|
|
|
|
|
|
|
|
|
// Do not allow middle/right-click or 2+ clicks.
|
|
|
|
|
if (aEvent.detail != 1 || aEvent.button != 0) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
aEvent.preventDefault();
|
|
|
|
|
|
|
|
|
|
// If this event started with a mousedown event and it ends at a different
|
|
|
|
|
// location, we consider this text selection.
|
|
|
|
|
if (mousedown && this._startX != aEvent.clientX &&
|
|
|
|
|
this._startY != aEvent.clientY) {
|
2012-07-26 08:06:04 -07:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
aCallback(this, aEvent);
|
|
|
|
|
}, false);
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Copies the selected items to the system clipboard.
|
2012-09-19 14:38:30 -07:00
|
|
|
|
*
|
|
|
|
|
* @param object aOptions
|
|
|
|
|
* - linkOnly:
|
|
|
|
|
* An optional flag to copy only URL without timestamp and
|
|
|
|
|
* other meta-information. Default is false.
|
2012-07-26 08:06:04 -07:00
|
|
|
|
*/
|
2012-09-19 14:38:30 -07:00
|
|
|
|
copySelectedItems: function WCF_copySelectedItems(aOptions)
|
2012-07-26 08:06:04 -07:00
|
|
|
|
{
|
2013-09-13 05:06:46 -07:00
|
|
|
|
aOptions = aOptions || { linkOnly: false, contextmenu: false };
|
2012-09-19 14:38:30 -07:00
|
|
|
|
|
2012-07-26 08:06:04 -07:00
|
|
|
|
// Gather up the selected items and concatenate their clipboard text.
|
|
|
|
|
let strings = [];
|
|
|
|
|
|
2013-09-13 05:06:46 -07:00
|
|
|
|
let children = this.output.getSelectedMessages();
|
|
|
|
|
if (!children.length && aOptions.contextmenu) {
|
|
|
|
|
children = [this._contextMenuHandler.lastClickedMessage];
|
|
|
|
|
}
|
2012-07-26 08:06:04 -07:00
|
|
|
|
|
2013-09-13 05:06:46 -07:00
|
|
|
|
for (let item of children) {
|
2012-07-26 08:06:04 -07:00
|
|
|
|
// Ensure the selected item hasn't been filtered by type or string.
|
2013-09-05 09:34:22 -07:00
|
|
|
|
if (!item.classList.contains("filtered-by-type") &&
|
|
|
|
|
!item.classList.contains("filtered-by-string")) {
|
2012-07-26 08:06:04 -07:00
|
|
|
|
let timestampString = l10n.timestampString(item.timestamp);
|
2012-09-19 14:38:30 -07:00
|
|
|
|
if (aOptions.linkOnly) {
|
|
|
|
|
strings.push(item.url);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
strings.push("[" + timestampString + "] " + item.clipboardText);
|
|
|
|
|
}
|
2012-07-26 08:06:04 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
clipboardHelper.copyString(strings.join("\n"), this.document);
|
|
|
|
|
},
|
|
|
|
|
|
2012-09-26 10:02:04 -07:00
|
|
|
|
/**
|
|
|
|
|
* Object properties provider. This function gives you the properties of the
|
|
|
|
|
* remote object you want.
|
|
|
|
|
*
|
|
|
|
|
* @param string aActor
|
|
|
|
|
* The object actor ID from which you want the properties.
|
|
|
|
|
* @param function aCallback
|
|
|
|
|
* Function you want invoked once the properties are received.
|
|
|
|
|
*/
|
|
|
|
|
objectPropertiesProvider:
|
|
|
|
|
function WCF_objectPropertiesProvider(aActor, aCallback)
|
|
|
|
|
{
|
|
|
|
|
this.webConsoleClient.inspectObjectProperties(aActor,
|
|
|
|
|
function(aResponse) {
|
|
|
|
|
if (aResponse.error) {
|
|
|
|
|
Cu.reportError("Failed to retrieve the object properties from the " +
|
|
|
|
|
"server. Error: " + aResponse.error);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
aCallback(aResponse.properties);
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
2012-10-05 04:54:43 -07:00
|
|
|
|
* Release an actor.
|
2012-09-26 10:02:04 -07:00
|
|
|
|
*
|
|
|
|
|
* @private
|
|
|
|
|
* @param string aActor
|
2012-10-05 04:54:43 -07:00
|
|
|
|
* The actor ID you want to release.
|
2012-09-26 10:02:04 -07:00
|
|
|
|
*/
|
|
|
|
|
_releaseObject: function WCF__releaseObject(aActor)
|
|
|
|
|
{
|
2012-10-05 09:15:51 -07:00
|
|
|
|
if (this.proxy) {
|
|
|
|
|
this.proxy.releaseActor(aActor);
|
|
|
|
|
}
|
2012-09-26 10:02:04 -07:00
|
|
|
|
},
|
|
|
|
|
|
2012-09-18 09:08:29 -07:00
|
|
|
|
/**
|
|
|
|
|
* Open the selected item's URL in a new tab.
|
|
|
|
|
*/
|
|
|
|
|
openSelectedItemInTab: function WCF_openSelectedItemInTab()
|
|
|
|
|
{
|
2013-09-13 05:06:46 -07:00
|
|
|
|
let item = this.output.getSelectedMessages(1)[0] ||
|
|
|
|
|
this._contextMenuHandler.lastClickedMessage;
|
2012-09-18 09:08:29 -07:00
|
|
|
|
|
|
|
|
|
if (!item || !item.url) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.owner.openLink(item.url);
|
|
|
|
|
},
|
|
|
|
|
|
2012-07-26 08:06:04 -07:00
|
|
|
|
/**
|
2013-01-11 09:31:09 -08:00
|
|
|
|
* Destroy the WebConsoleFrame object. Call this method to avoid memory leaks
|
|
|
|
|
* when the Web Console is closed.
|
2012-09-26 10:07:57 -07:00
|
|
|
|
*
|
2013-01-11 09:31:09 -08:00
|
|
|
|
* @return object
|
2013-07-11 00:12:20 -07:00
|
|
|
|
* A promise that is resolved when the WebConsoleFrame instance is
|
2013-01-11 09:31:09 -08:00
|
|
|
|
* destroyed.
|
2012-07-26 08:06:04 -07:00
|
|
|
|
*/
|
2013-01-11 09:31:09 -08:00
|
|
|
|
destroy: function WCF_destroy()
|
2012-07-26 08:06:04 -07:00
|
|
|
|
{
|
2013-01-11 09:31:09 -08:00
|
|
|
|
if (this._destroyer) {
|
|
|
|
|
return this._destroyer.promise;
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-11 00:12:20 -07:00
|
|
|
|
this._destroyer = promise.defer();
|
2013-01-11 09:31:09 -08:00
|
|
|
|
|
2013-04-22 18:07:36 -07:00
|
|
|
|
this._repeatNodes = {};
|
2012-10-05 09:15:51 -07:00
|
|
|
|
this._outputQueue = [];
|
|
|
|
|
this._pruneCategoriesQueue = {};
|
|
|
|
|
this._networkRequests = {};
|
|
|
|
|
|
|
|
|
|
if (this._outputTimerInitialized) {
|
|
|
|
|
this._outputTimerInitialized = false;
|
|
|
|
|
this._outputTimer.cancel();
|
|
|
|
|
}
|
|
|
|
|
this._outputTimer = null;
|
|
|
|
|
|
2013-01-11 09:31:09 -08:00
|
|
|
|
if (this.jsterm) {
|
|
|
|
|
this.jsterm.destroy();
|
|
|
|
|
this.jsterm = null;
|
2012-11-16 10:16:18 -08:00
|
|
|
|
}
|
2013-08-02 10:19:23 -07:00
|
|
|
|
this.output.destroy();
|
|
|
|
|
this.output = null;
|
|
|
|
|
|
2013-08-02 10:11:57 -07:00
|
|
|
|
if (this._contextMenuHandler) {
|
|
|
|
|
this._contextMenuHandler.destroy();
|
|
|
|
|
this._contextMenuHandler = null;
|
|
|
|
|
}
|
2013-01-11 09:31:09 -08:00
|
|
|
|
|
|
|
|
|
this._commandController = null;
|
|
|
|
|
|
|
|
|
|
let onDestroy = function() {
|
|
|
|
|
this._destroyer.resolve(null);
|
|
|
|
|
}.bind(this);
|
2012-11-16 10:16:18 -08:00
|
|
|
|
|
2012-09-26 10:07:57 -07:00
|
|
|
|
if (this.proxy) {
|
2013-01-11 09:31:09 -08:00
|
|
|
|
this.proxy.disconnect().then(onDestroy);
|
2012-10-05 09:15:51 -07:00
|
|
|
|
this.proxy = null;
|
2012-09-26 10:07:57 -07:00
|
|
|
|
}
|
2013-01-11 09:31:09 -08:00
|
|
|
|
else {
|
|
|
|
|
onDestroy();
|
2012-07-26 08:06:04 -07:00
|
|
|
|
}
|
2012-10-05 09:15:51 -07:00
|
|
|
|
|
2013-01-11 09:31:09 -08:00
|
|
|
|
return this._destroyer.promise;
|
2012-07-26 08:06:04 -07:00
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
|
2013-06-14 10:42:52 -07:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @see VariablesView.simpleValueEvalMacro
|
|
|
|
|
*/
|
|
|
|
|
function simpleValueEvalMacro(aItem, aCurrentString)
|
|
|
|
|
{
|
|
|
|
|
return VariablesView.simpleValueEvalMacro(aItem, aCurrentString, "_self");
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @see VariablesView.overrideValueEvalMacro
|
|
|
|
|
*/
|
|
|
|
|
function overrideValueEvalMacro(aItem, aCurrentString)
|
|
|
|
|
{
|
|
|
|
|
return VariablesView.overrideValueEvalMacro(aItem, aCurrentString, "_self");
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @see VariablesView.getterOrSetterEvalMacro
|
|
|
|
|
*/
|
|
|
|
|
function getterOrSetterEvalMacro(aItem, aCurrentString)
|
|
|
|
|
{
|
|
|
|
|
return VariablesView.getterOrSetterEvalMacro(aItem, aCurrentString, "_self");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-07-26 08:06:04 -07:00
|
|
|
|
/**
|
|
|
|
|
* Create a JSTerminal (a JavaScript command line). This is attached to an
|
|
|
|
|
* existing HeadsUpDisplay (a Web Console instance). This code is responsible
|
|
|
|
|
* with handling command line input, code evaluation and result output.
|
|
|
|
|
*
|
|
|
|
|
* @constructor
|
|
|
|
|
* @param object aWebConsoleFrame
|
|
|
|
|
* The WebConsoleFrame object that owns this JSTerm instance.
|
|
|
|
|
*/
|
|
|
|
|
function JSTerm(aWebConsoleFrame)
|
|
|
|
|
{
|
|
|
|
|
this.hud = aWebConsoleFrame;
|
|
|
|
|
this.hudId = this.hud.hudId;
|
|
|
|
|
|
|
|
|
|
this.lastCompletion = { value: null };
|
|
|
|
|
this.history = [];
|
2013-05-30 09:16:41 -07:00
|
|
|
|
|
|
|
|
|
// Holds the number of entries in history. This value is incremented in
|
|
|
|
|
// this.execute().
|
|
|
|
|
this.historyIndex = 0; // incremented on this.execute()
|
|
|
|
|
|
|
|
|
|
// Holds the index of the history entry that the user is currently viewing.
|
|
|
|
|
// This is reset to this.history.length when this.execute() is invoked.
|
|
|
|
|
this.historyPlaceHolder = 0;
|
2013-04-09 02:46:30 -07:00
|
|
|
|
this._objectActorsInVariablesViews = new Map();
|
|
|
|
|
|
2013-06-17 04:10:46 -07:00
|
|
|
|
this._keyPress = this._keyPress.bind(this);
|
|
|
|
|
this._inputEventHandler = this._inputEventHandler.bind(this);
|
|
|
|
|
this._focusEventHandler = this._focusEventHandler.bind(this);
|
2013-05-02 04:53:11 -07:00
|
|
|
|
this._onKeypressInVariablesView = this._onKeypressInVariablesView.bind(this);
|
2013-04-09 02:46:30 -07:00
|
|
|
|
|
|
|
|
|
EventEmitter.decorate(this);
|
2012-07-26 08:06:04 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
JSTerm.prototype = {
|
2013-04-09 02:46:30 -07:00
|
|
|
|
SELECTED_FRAME: -1,
|
|
|
|
|
|
2012-07-26 08:06:04 -07:00
|
|
|
|
/**
|
|
|
|
|
* Stores the data for the last completion.
|
|
|
|
|
* @type object
|
|
|
|
|
*/
|
|
|
|
|
lastCompletion: null,
|
|
|
|
|
|
2013-08-01 12:31:36 -07:00
|
|
|
|
/**
|
|
|
|
|
* Array that caches the user input suggestions received from the server.
|
|
|
|
|
* @private
|
|
|
|
|
* @type array
|
|
|
|
|
*/
|
|
|
|
|
_autocompleteCache: null,
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The input that caused the last request to the server, whose response is
|
|
|
|
|
* cached in the _autocompleteCache array.
|
|
|
|
|
* @private
|
|
|
|
|
* @type string
|
|
|
|
|
*/
|
|
|
|
|
_autocompleteQuery: null,
|
|
|
|
|
|
2013-04-09 02:46:30 -07:00
|
|
|
|
/**
|
|
|
|
|
* The Web Console sidebar.
|
|
|
|
|
* @see this._createSidebar()
|
|
|
|
|
* @see Sidebar.jsm
|
|
|
|
|
*/
|
|
|
|
|
sidebar: null,
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The Variables View instance shown in the sidebar.
|
|
|
|
|
* @private
|
|
|
|
|
* @type object
|
|
|
|
|
*/
|
|
|
|
|
_variablesView: null,
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Tells if you want the variables view UI updates to be lazy or not. Tests
|
|
|
|
|
* disable lazy updates.
|
|
|
|
|
*
|
|
|
|
|
* @private
|
|
|
|
|
* @type boolean
|
|
|
|
|
*/
|
|
|
|
|
_lazyVariablesView: true,
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Holds a map between VariablesView instances and sets of ObjectActor IDs
|
|
|
|
|
* that have been retrieved from the server. This allows us to release the
|
|
|
|
|
* objects when needed.
|
|
|
|
|
*
|
|
|
|
|
* @private
|
|
|
|
|
* @type Map
|
|
|
|
|
*/
|
|
|
|
|
_objectActorsInVariablesViews: null,
|
|
|
|
|
|
2012-07-26 08:06:04 -07:00
|
|
|
|
/**
|
|
|
|
|
* Last input value.
|
|
|
|
|
* @type string
|
|
|
|
|
*/
|
|
|
|
|
lastInputValue: "",
|
|
|
|
|
|
2013-06-17 04:10:46 -07:00
|
|
|
|
/**
|
2013-06-21 09:01:02 -07:00
|
|
|
|
* Tells if the input node changed since the last focus.
|
2013-06-17 04:10:46 -07:00
|
|
|
|
*
|
|
|
|
|
* @private
|
|
|
|
|
* @type boolean
|
|
|
|
|
*/
|
|
|
|
|
_inputChanged: false,
|
|
|
|
|
|
2013-06-21 09:01:02 -07:00
|
|
|
|
/**
|
|
|
|
|
* Tells if the autocomplete popup was navigated since the last open.
|
|
|
|
|
*
|
|
|
|
|
* @private
|
|
|
|
|
* @type boolean
|
|
|
|
|
*/
|
|
|
|
|
_autocompletePopupNavigated: false,
|
|
|
|
|
|
2012-07-26 08:06:04 -07:00
|
|
|
|
/**
|
|
|
|
|
* History of code that was executed.
|
|
|
|
|
* @type array
|
|
|
|
|
*/
|
|
|
|
|
history: null,
|
2013-01-11 09:31:09 -08:00
|
|
|
|
autocompletePopup: null,
|
|
|
|
|
inputNode: null,
|
|
|
|
|
completeNode: null,
|
|
|
|
|
|
2012-07-26 08:06:04 -07:00
|
|
|
|
/**
|
|
|
|
|
* Getter for the element that holds the messages we display.
|
|
|
|
|
* @type nsIDOMElement
|
|
|
|
|
*/
|
|
|
|
|
get outputNode() this.hud.outputNode,
|
|
|
|
|
|
2012-09-26 10:02:04 -07:00
|
|
|
|
/**
|
|
|
|
|
* Getter for the debugger WebConsoleClient.
|
|
|
|
|
* @type object
|
|
|
|
|
*/
|
|
|
|
|
get webConsoleClient() this.hud.webConsoleClient,
|
|
|
|
|
|
2012-07-26 08:06:04 -07:00
|
|
|
|
COMPLETE_FORWARD: 0,
|
|
|
|
|
COMPLETE_BACKWARD: 1,
|
|
|
|
|
COMPLETE_HINT_ONLY: 2,
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Initialize the JSTerminal UI.
|
|
|
|
|
*/
|
2013-01-11 09:31:09 -08:00
|
|
|
|
init: function JST_init()
|
2012-07-26 08:06:04 -07:00
|
|
|
|
{
|
2013-04-09 02:47:23 -07:00
|
|
|
|
let chromeDocument = this.hud.owner.chromeWindow.document;
|
2013-01-28 13:32:35 -08:00
|
|
|
|
let autocompleteOptions = {
|
|
|
|
|
onSelect: this.onAutocompleteSelect.bind(this),
|
|
|
|
|
onClick: this.acceptProposedCompletion.bind(this),
|
|
|
|
|
panelId: "webConsole_autocompletePopup",
|
|
|
|
|
listBoxId: "webConsole_autocompletePopupListBox",
|
2013-03-14 11:04:05 -07:00
|
|
|
|
position: "before_start",
|
|
|
|
|
theme: "light",
|
|
|
|
|
direction: "ltr",
|
|
|
|
|
autoSelect: true
|
2013-01-28 13:32:35 -08:00
|
|
|
|
};
|
|
|
|
|
this.autocompletePopup = new AutocompletePopup(chromeDocument,
|
|
|
|
|
autocompleteOptions);
|
2013-01-11 09:31:09 -08:00
|
|
|
|
|
2012-07-26 08:06:04 -07:00
|
|
|
|
let doc = this.hud.document;
|
|
|
|
|
this.completeNode = doc.querySelector(".jsterm-complete-node");
|
|
|
|
|
this.inputNode = doc.querySelector(".jsterm-input-node");
|
|
|
|
|
this.inputNode.addEventListener("keypress", this._keyPress, false);
|
|
|
|
|
this.inputNode.addEventListener("input", this._inputEventHandler, false);
|
|
|
|
|
this.inputNode.addEventListener("keyup", this._inputEventHandler, false);
|
2013-06-17 04:10:46 -07:00
|
|
|
|
this.inputNode.addEventListener("focus", this._focusEventHandler, false);
|
2012-07-26 08:06:04 -07:00
|
|
|
|
|
|
|
|
|
this.lastInputValue && this.setInputValue(this.lastInputValue);
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
2012-09-26 10:02:04 -07:00
|
|
|
|
* The JavaScript evaluation response handler.
|
2012-07-26 08:06:04 -07:00
|
|
|
|
*
|
|
|
|
|
* @private
|
2012-09-26 10:02:04 -07:00
|
|
|
|
* @param nsIDOMElement [aAfterNode]
|
|
|
|
|
* Optional DOM element after which the evaluation result will be
|
|
|
|
|
* inserted.
|
2012-07-26 08:06:04 -07:00
|
|
|
|
* @param function [aCallback]
|
|
|
|
|
* Optional function to invoke when the evaluation result is added to
|
|
|
|
|
* the output.
|
|
|
|
|
* @param object aResponse
|
2012-09-26 10:02:04 -07:00
|
|
|
|
* The message received from the server.
|
2012-07-26 08:06:04 -07:00
|
|
|
|
*/
|
|
|
|
|
_executeResultCallback:
|
2012-09-26 10:02:04 -07:00
|
|
|
|
function JST__executeResultCallback(aAfterNode, aCallback, aResponse)
|
2012-07-26 08:06:04 -07:00
|
|
|
|
{
|
2012-10-05 09:15:51 -07:00
|
|
|
|
if (!this.hud) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2013-04-09 02:46:30 -07:00
|
|
|
|
if (aResponse.error) {
|
|
|
|
|
Cu.reportError("Evaluation error " + aResponse.error + ": " +
|
|
|
|
|
aResponse.message);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
let errorMessage = aResponse.exceptionMessage;
|
2012-09-26 10:02:04 -07:00
|
|
|
|
let result = aResponse.result;
|
2013-04-09 02:46:30 -07:00
|
|
|
|
let inspectable = false;
|
|
|
|
|
if (result && !VariablesView.isPrimitive({ value: result })) {
|
|
|
|
|
inspectable = true;
|
|
|
|
|
}
|
2012-09-26 10:02:04 -07:00
|
|
|
|
let helperResult = aResponse.helperResult;
|
|
|
|
|
let helperHasRawOutput = !!(helperResult || {}).rawOutput;
|
2013-04-09 02:46:30 -07:00
|
|
|
|
let resultString = VariablesView.getString(result);
|
2012-09-26 10:02:04 -07:00
|
|
|
|
|
|
|
|
|
if (helperResult && helperResult.type) {
|
|
|
|
|
switch (helperResult.type) {
|
|
|
|
|
case "clearOutput":
|
|
|
|
|
this.clearOutput();
|
|
|
|
|
break;
|
|
|
|
|
case "inspectObject":
|
2013-04-09 02:46:30 -07:00
|
|
|
|
if (aAfterNode) {
|
|
|
|
|
if (!aAfterNode._objectActors) {
|
|
|
|
|
aAfterNode._objectActors = new Set();
|
|
|
|
|
}
|
|
|
|
|
aAfterNode._objectActors.add(helperResult.object.actor);
|
|
|
|
|
}
|
|
|
|
|
this.openVariablesView({
|
|
|
|
|
label: VariablesView.getString(helperResult.object),
|
|
|
|
|
objectActor: helperResult.object,
|
|
|
|
|
});
|
2012-09-26 10:02:04 -07:00
|
|
|
|
break;
|
|
|
|
|
case "error":
|
|
|
|
|
try {
|
|
|
|
|
errorMessage = l10n.getStr(helperResult.message);
|
|
|
|
|
}
|
|
|
|
|
catch (ex) {
|
|
|
|
|
errorMessage = helperResult.message;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case "help":
|
|
|
|
|
this.hud.owner.openLink(HELP_URL);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-07-26 08:06:04 -07:00
|
|
|
|
|
|
|
|
|
// Hide undefined results coming from JSTerm helper functions.
|
2012-09-26 10:02:04 -07:00
|
|
|
|
if (!errorMessage && result && typeof result == "object" &&
|
|
|
|
|
result.type == "undefined" &&
|
|
|
|
|
helperResult && !helperHasRawOutput) {
|
|
|
|
|
aCallback && aCallback();
|
2012-07-26 08:06:04 -07:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2012-09-26 10:02:04 -07:00
|
|
|
|
let node;
|
|
|
|
|
|
|
|
|
|
if (errorMessage) {
|
|
|
|
|
node = this.writeOutput(errorMessage, CATEGORY_OUTPUT, SEVERITY_ERROR,
|
|
|
|
|
aAfterNode, aResponse.timestamp);
|
2012-07-26 08:06:04 -07:00
|
|
|
|
}
|
2012-09-26 10:02:04 -07:00
|
|
|
|
else if (inspectable) {
|
|
|
|
|
node = this.writeOutputJS(resultString,
|
|
|
|
|
this._evalOutputClick.bind(this, aResponse),
|
|
|
|
|
aAfterNode, aResponse.timestamp);
|
2012-07-26 08:06:04 -07:00
|
|
|
|
}
|
|
|
|
|
else {
|
2012-09-26 10:02:04 -07:00
|
|
|
|
node = this.writeOutput(resultString, CATEGORY_OUTPUT, SEVERITY_LOG,
|
|
|
|
|
aAfterNode, aResponse.timestamp);
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-13 05:06:46 -07:00
|
|
|
|
if (aCallback) {
|
|
|
|
|
let oldFlushCallback = this.hud._flushCallback;
|
|
|
|
|
this.hud._flushCallback = () => {
|
|
|
|
|
aCallback(node);
|
|
|
|
|
if (oldFlushCallback) {
|
|
|
|
|
oldFlushCallback();
|
|
|
|
|
this.hud._flushCallback = oldFlushCallback;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
this.hud._flushCallback = null;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-09 02:46:30 -07:00
|
|
|
|
node._objectActors = new Set();
|
|
|
|
|
|
|
|
|
|
let error = aResponse.exception;
|
|
|
|
|
if (WebConsoleUtils.isActorGrip(error)) {
|
|
|
|
|
node._objectActors.add(error.actor);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (WebConsoleUtils.isActorGrip(result)) {
|
|
|
|
|
node._objectActors.add(result.actor);
|
2012-11-05 08:41:59 -08:00
|
|
|
|
|
|
|
|
|
if (result.type == "longString") {
|
2013-04-09 02:46:30 -07:00
|
|
|
|
// Add an ellipsis to expand the short string if the object is not
|
|
|
|
|
// inspectable.
|
2012-11-05 08:41:59 -08:00
|
|
|
|
|
2013-09-05 09:34:22 -07:00
|
|
|
|
let body = node.getElementsByClassName("body")[0];
|
2013-09-13 05:06:46 -07:00
|
|
|
|
let ellipsis = this.hud.document.createElementNS(XHTML_NS, "a");
|
2012-11-05 08:41:59 -08:00
|
|
|
|
ellipsis.classList.add("longStringEllipsis");
|
|
|
|
|
ellipsis.textContent = l10n.getStr("longStringEllipsis");
|
2013-09-05 09:29:13 -07:00
|
|
|
|
ellipsis.href = "#";
|
|
|
|
|
ellipsis.draggable = false;
|
2012-11-05 08:41:59 -08:00
|
|
|
|
|
2013-04-09 02:46:30 -07:00
|
|
|
|
let formatter = function(s) '"' + s + '"';
|
|
|
|
|
let onclick = this.hud._longStringClick.bind(this.hud, node, result,
|
|
|
|
|
formatter);
|
|
|
|
|
this.hud._addMessageLinkCallback(ellipsis, onclick);
|
2012-11-05 08:41:59 -08:00
|
|
|
|
|
|
|
|
|
body.appendChild(ellipsis);
|
|
|
|
|
|
|
|
|
|
node.clipboardText += " " + ellipsis.textContent;
|
|
|
|
|
}
|
2012-07-26 08:06:04 -07:00
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Execute a string. Execution happens asynchronously in the content process.
|
|
|
|
|
*
|
|
|
|
|
* @param string [aExecuteString]
|
|
|
|
|
* The string you want to execute. If this is not provided, the current
|
|
|
|
|
* user input is used - taken from |this.inputNode.value|.
|
|
|
|
|
* @param function [aCallback]
|
|
|
|
|
* Optional function to invoke when the result is displayed.
|
|
|
|
|
*/
|
|
|
|
|
execute: function JST_execute(aExecuteString, aCallback)
|
|
|
|
|
{
|
|
|
|
|
// attempt to execute the content of the inputNode
|
|
|
|
|
aExecuteString = aExecuteString || this.inputNode.value;
|
|
|
|
|
if (!aExecuteString) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let node = this.writeOutput(aExecuteString, CATEGORY_INPUT, SEVERITY_LOG);
|
2012-09-26 10:02:04 -07:00
|
|
|
|
let onResult = this._executeResultCallback.bind(this, node, aCallback);
|
2012-07-26 08:06:04 -07:00
|
|
|
|
|
2013-04-09 02:46:30 -07:00
|
|
|
|
let options = { frame: this.SELECTED_FRAME };
|
|
|
|
|
this.requestEvaluation(aExecuteString, options).then(onResult, onResult);
|
2012-07-26 08:06:04 -07:00
|
|
|
|
|
2013-05-30 09:16:41 -07:00
|
|
|
|
// Append a new value in the history of executed code, or overwrite the most
|
|
|
|
|
// recent entry. The most recent entry may contain the last edited input
|
|
|
|
|
// value that was not evaluated yet.
|
|
|
|
|
this.history[this.historyIndex++] = aExecuteString;
|
2012-07-26 08:06:04 -07:00
|
|
|
|
this.historyPlaceHolder = this.history.length;
|
|
|
|
|
this.setInputValue("");
|
|
|
|
|
this.clearCompletion();
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
2013-04-09 02:46:30 -07:00
|
|
|
|
* Request a JavaScript string evaluation from the server.
|
|
|
|
|
*
|
|
|
|
|
* @param string aString
|
|
|
|
|
* String to execute.
|
|
|
|
|
* @param object [aOptions]
|
|
|
|
|
* Options for evaluation:
|
|
|
|
|
* - bindObjectActor: tells the ObjectActor ID for which you want to do
|
|
|
|
|
* the evaluation. The Debugger.Object of the OA will be bound to
|
|
|
|
|
* |_self| during evaluation, such that it's usable in the string you
|
|
|
|
|
* execute.
|
|
|
|
|
* - frame: tells the stackframe depth to evaluate the string in. If
|
|
|
|
|
* the jsdebugger is paused, you can pick the stackframe to be used for
|
|
|
|
|
* evaluation. Use |this.SELECTED_FRAME| to always pick the
|
|
|
|
|
* user-selected stackframe.
|
|
|
|
|
* If you do not provide a |frame| the string will be evaluated in the
|
|
|
|
|
* global content window.
|
|
|
|
|
* @return object
|
2013-07-11 00:12:20 -07:00
|
|
|
|
* A promise object that is resolved when the server response is
|
2013-04-09 02:46:30 -07:00
|
|
|
|
* received.
|
|
|
|
|
*/
|
|
|
|
|
requestEvaluation: function JST_requestEvaluation(aString, aOptions = {})
|
|
|
|
|
{
|
2013-07-11 00:12:20 -07:00
|
|
|
|
let deferred = promise.defer();
|
2013-04-09 02:46:30 -07:00
|
|
|
|
|
|
|
|
|
function onResult(aResponse) {
|
|
|
|
|
if (!aResponse.error) {
|
|
|
|
|
deferred.resolve(aResponse);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
deferred.reject(aResponse);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let frameActor = null;
|
|
|
|
|
if ("frame" in aOptions) {
|
|
|
|
|
frameActor = this.getFrameActor(aOptions.frame);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let evalOptions = {
|
|
|
|
|
bindObjectActor: aOptions.bindObjectActor,
|
|
|
|
|
frameActor: frameActor,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
this.webConsoleClient.evaluateJS(aString, onResult, evalOptions);
|
|
|
|
|
return deferred.promise;
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Retrieve the FrameActor ID given a frame depth.
|
|
|
|
|
*
|
|
|
|
|
* @param number aFrame
|
|
|
|
|
* Frame depth.
|
|
|
|
|
* @return string|null
|
|
|
|
|
* The FrameActor ID for the given frame depth.
|
|
|
|
|
*/
|
|
|
|
|
getFrameActor: function JST_getFrameActor(aFrame)
|
|
|
|
|
{
|
|
|
|
|
let state = this.hud.owner.getDebuggerFrames();
|
|
|
|
|
if (!state) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let grip;
|
|
|
|
|
if (aFrame == this.SELECTED_FRAME) {
|
|
|
|
|
grip = state.frames[state.selected];
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
grip = state.frames[aFrame];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return grip ? grip.actor : null;
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Opens a new variables view that allows the inspection of the given object.
|
2012-07-26 08:06:04 -07:00
|
|
|
|
*
|
|
|
|
|
* @param object aOptions
|
2013-04-09 02:46:30 -07:00
|
|
|
|
* Options for the variables view:
|
|
|
|
|
* - objectActor: grip of the ObjectActor you want to show in the
|
|
|
|
|
* variables view.
|
|
|
|
|
* - rawObject: the raw object you want to show in the variables view.
|
|
|
|
|
* - label: label to display in the variables view for inspected
|
|
|
|
|
* object.
|
|
|
|
|
* - hideFilterInput: optional boolean, |true| if you want to hide the
|
|
|
|
|
* variables view filter input.
|
|
|
|
|
* - targetElement: optional nsIDOMElement to append the variables view
|
|
|
|
|
* to. An iframe element is used as a container for the view. If this
|
|
|
|
|
* option is not used, then the variables view opens in the sidebar.
|
2013-05-02 04:53:11 -07:00
|
|
|
|
* - autofocus: optional boolean, |true| if you want to give focus to
|
|
|
|
|
* the variables view window after open, |false| otherwise.
|
2012-07-26 08:06:04 -07:00
|
|
|
|
* @return object
|
2013-07-11 00:12:20 -07:00
|
|
|
|
* A promise object that is resolved when the variables view has
|
2013-04-09 02:46:30 -07:00
|
|
|
|
* opened. The new variables view instance is given to the callbacks.
|
2012-07-26 08:06:04 -07:00
|
|
|
|
*/
|
2013-04-09 02:46:30 -07:00
|
|
|
|
openVariablesView: function JST_openVariablesView(aOptions)
|
2012-07-26 08:06:04 -07:00
|
|
|
|
{
|
2013-04-09 02:46:30 -07:00
|
|
|
|
let onContainerReady = (aWindow) => {
|
|
|
|
|
let container = aWindow.document.querySelector("#variables");
|
|
|
|
|
let view = this._variablesView;
|
|
|
|
|
if (!view || aOptions.targetElement) {
|
|
|
|
|
let viewOptions = {
|
|
|
|
|
container: container,
|
|
|
|
|
hideFilterInput: aOptions.hideFilterInput,
|
|
|
|
|
};
|
|
|
|
|
view = this._createVariablesView(viewOptions);
|
|
|
|
|
if (!aOptions.targetElement) {
|
|
|
|
|
this._variablesView = view;
|
2013-05-02 04:53:11 -07:00
|
|
|
|
aWindow.addEventListener("keypress", this._onKeypressInVariablesView);
|
2013-04-09 02:46:30 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
aOptions.view = view;
|
|
|
|
|
this._updateVariablesView(aOptions);
|
2013-05-02 04:53:11 -07:00
|
|
|
|
|
2013-05-10 03:15:11 -07:00
|
|
|
|
if (!aOptions.targetElement && aOptions.autofocus) {
|
|
|
|
|
aWindow.focus();
|
|
|
|
|
}
|
2013-05-02 04:53:11 -07:00
|
|
|
|
|
2013-04-09 02:46:30 -07:00
|
|
|
|
this.emit("variablesview-open", view, aOptions);
|
|
|
|
|
return view;
|
|
|
|
|
};
|
2012-07-26 08:06:04 -07:00
|
|
|
|
|
2013-07-11 00:12:20 -07:00
|
|
|
|
let openPromise;
|
2013-04-09 02:46:30 -07:00
|
|
|
|
if (aOptions.targetElement) {
|
2013-07-11 00:12:20 -07:00
|
|
|
|
let deferred = promise.defer();
|
|
|
|
|
openPromise = deferred.promise;
|
2013-04-09 02:46:30 -07:00
|
|
|
|
let document = aOptions.targetElement.ownerDocument;
|
2013-09-13 05:06:46 -07:00
|
|
|
|
let iframe = document.createElementNS(XHTML_NS, "iframe");
|
2013-04-09 02:46:30 -07:00
|
|
|
|
|
|
|
|
|
iframe.addEventListener("load", function onIframeLoad(aEvent) {
|
|
|
|
|
iframe.removeEventListener("load", onIframeLoad, true);
|
|
|
|
|
deferred.resolve(iframe.contentWindow);
|
|
|
|
|
}, true);
|
|
|
|
|
|
|
|
|
|
iframe.flex = 1;
|
|
|
|
|
iframe.setAttribute("src", VARIABLES_VIEW_URL);
|
|
|
|
|
aOptions.targetElement.appendChild(iframe);
|
|
|
|
|
}
|
|
|
|
|
else {
|
2013-05-02 04:53:11 -07:00
|
|
|
|
if (!this.sidebar) {
|
|
|
|
|
this._createSidebar();
|
|
|
|
|
}
|
2013-07-11 00:12:20 -07:00
|
|
|
|
openPromise = this._addVariablesViewSidebarTab();
|
2013-04-09 02:46:30 -07:00
|
|
|
|
}
|
|
|
|
|
|
2013-07-11 00:12:20 -07:00
|
|
|
|
return openPromise.then(onContainerReady);
|
2013-04-09 02:46:30 -07:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Create the Web Console sidebar.
|
|
|
|
|
*
|
2013-04-11 13:59:08 -07:00
|
|
|
|
* @see devtools/framework/sidebar.js
|
2013-04-09 02:46:30 -07:00
|
|
|
|
* @private
|
|
|
|
|
*/
|
|
|
|
|
_createSidebar: function JST__createSidebar()
|
|
|
|
|
{
|
2013-05-02 04:53:11 -07:00
|
|
|
|
let tabbox = this.hud.document.querySelector("#webconsole-sidebar");
|
2013-06-13 16:41:00 -07:00
|
|
|
|
this.sidebar = new ToolSidebar(tabbox, this, "webconsole");
|
2013-04-09 02:46:30 -07:00
|
|
|
|
this.sidebar.show();
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Add the variables view tab to the sidebar.
|
|
|
|
|
*
|
|
|
|
|
* @private
|
|
|
|
|
* @return object
|
2013-07-11 00:12:20 -07:00
|
|
|
|
* A promise object for the adding of the new tab.
|
2013-04-09 02:46:30 -07:00
|
|
|
|
*/
|
|
|
|
|
_addVariablesViewSidebarTab: function JST__addVariablesViewSidebarTab()
|
|
|
|
|
{
|
2013-07-11 00:12:20 -07:00
|
|
|
|
let deferred = promise.defer();
|
2013-04-09 02:46:30 -07:00
|
|
|
|
|
|
|
|
|
let onTabReady = () => {
|
|
|
|
|
let window = this.sidebar.getWindowForTab("variablesview");
|
|
|
|
|
deferred.resolve(window);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
let tab = this.sidebar.getTab("variablesview");
|
|
|
|
|
if (tab) {
|
|
|
|
|
if (this.sidebar.getCurrentTabID() == "variablesview") {
|
|
|
|
|
onTabReady();
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
this.sidebar.once("variablesview-selected", onTabReady);
|
|
|
|
|
this.sidebar.select("variablesview");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
this.sidebar.once("variablesview-ready", onTabReady);
|
|
|
|
|
this.sidebar.addTab("variablesview", VARIABLES_VIEW_URL, true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return deferred.promise;
|
|
|
|
|
},
|
|
|
|
|
|
2013-05-02 04:53:11 -07:00
|
|
|
|
/**
|
|
|
|
|
* The keypress event handler for the Variables View sidebar. Currently this
|
|
|
|
|
* is used for removing the sidebar when Escape is pressed.
|
|
|
|
|
*
|
|
|
|
|
* @private
|
|
|
|
|
* @param nsIDOMEvent aEvent
|
|
|
|
|
* The keypress DOM event object.
|
|
|
|
|
*/
|
|
|
|
|
_onKeypressInVariablesView: function JST__onKeypressInVariablesView(aEvent)
|
|
|
|
|
{
|
|
|
|
|
let tag = aEvent.target.nodeName;
|
|
|
|
|
if (aEvent.keyCode != Ci.nsIDOMKeyEvent.DOM_VK_ESCAPE || aEvent.shiftKey ||
|
|
|
|
|
aEvent.altKey || aEvent.ctrlKey || aEvent.metaKey ||
|
|
|
|
|
["input", "textarea", "select", "textbox"].indexOf(tag) > -1) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this._sidebarDestroy();
|
|
|
|
|
this.inputNode.focus();
|
|
|
|
|
},
|
|
|
|
|
|
2013-04-09 02:46:30 -07:00
|
|
|
|
/**
|
|
|
|
|
* Create a variables view instance.
|
|
|
|
|
*
|
|
|
|
|
* @private
|
|
|
|
|
* @param object aOptions
|
|
|
|
|
* Options for the new Variables View instance:
|
|
|
|
|
* - container: the DOM element where the variables view is inserted.
|
|
|
|
|
* - hideFilterInput: boolean, if true the variables filter input is
|
|
|
|
|
* hidden.
|
|
|
|
|
* @return object
|
|
|
|
|
* The new Variables View instance.
|
|
|
|
|
*/
|
|
|
|
|
_createVariablesView: function JST__createVariablesView(aOptions)
|
|
|
|
|
{
|
|
|
|
|
let view = new VariablesView(aOptions.container);
|
|
|
|
|
view.searchPlaceholder = l10n.getStr("propertiesFilterPlaceholder");
|
|
|
|
|
view.emptyText = l10n.getStr("emptyPropertiesList");
|
|
|
|
|
view.searchEnabled = !aOptions.hideFilterInput;
|
|
|
|
|
view.lazyEmpty = this._lazyVariablesView;
|
|
|
|
|
view.lazyAppend = this._lazyVariablesView;
|
2013-06-14 10:42:52 -07:00
|
|
|
|
|
|
|
|
|
VariablesViewController.attach(view, {
|
2013-09-25 09:03:17 -07:00
|
|
|
|
getEnvironmentClient: aGrip => {
|
|
|
|
|
return new EnvironmentClient(this.hud.proxy.client, aGrip);
|
|
|
|
|
},
|
2013-08-13 09:08:30 -07:00
|
|
|
|
getObjectClient: aGrip => {
|
|
|
|
|
return new ObjectClient(this.hud.proxy.client, aGrip);
|
2013-06-14 10:42:52 -07:00
|
|
|
|
},
|
|
|
|
|
getLongStringClient: aGrip => {
|
|
|
|
|
return this.webConsoleClient.longString(aGrip);
|
|
|
|
|
},
|
|
|
|
|
releaseActor: aActor => {
|
|
|
|
|
this.hud._releaseObject(aActor);
|
|
|
|
|
},
|
|
|
|
|
simpleValueEvalMacro: simpleValueEvalMacro,
|
|
|
|
|
overrideValueEvalMacro: overrideValueEvalMacro,
|
|
|
|
|
getterOrSetterEvalMacro: getterOrSetterEvalMacro,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Relay events from the VariablesView.
|
|
|
|
|
view.on("fetched", (aEvent, aType, aVar) => {
|
|
|
|
|
this.emit("variablesview-fetched", aVar);
|
|
|
|
|
});
|
|
|
|
|
|
2013-04-09 02:46:30 -07:00
|
|
|
|
return view;
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Update the variables view.
|
|
|
|
|
*
|
|
|
|
|
* @private
|
|
|
|
|
* @param object aOptions
|
|
|
|
|
* Options for updating the variables view:
|
|
|
|
|
* - view: the view you want to update.
|
|
|
|
|
* - objectActor: the grip of the new ObjectActor you want to show in
|
|
|
|
|
* the view.
|
|
|
|
|
* - rawObject: the new raw object you want to show.
|
|
|
|
|
* - label: the new label for the inspected object.
|
|
|
|
|
*/
|
|
|
|
|
_updateVariablesView: function JST__updateVariablesView(aOptions)
|
|
|
|
|
{
|
|
|
|
|
let view = aOptions.view;
|
|
|
|
|
view.createHierarchy();
|
|
|
|
|
view.empty();
|
|
|
|
|
|
2013-06-14 10:42:52 -07:00
|
|
|
|
// We need to avoid pruning the object inspection starting point.
|
|
|
|
|
// That one is pruned when the console message is removed.
|
|
|
|
|
view.controller.releaseActors(aActor => {
|
|
|
|
|
return view._consoleLastObjectActor != aActor;
|
|
|
|
|
});
|
2013-04-09 02:46:30 -07:00
|
|
|
|
|
|
|
|
|
if (aOptions.objectActor) {
|
|
|
|
|
// Make sure eval works in the correct context.
|
|
|
|
|
view.eval = this._variablesViewEvaluate.bind(this, aOptions);
|
|
|
|
|
view.switch = this._variablesViewSwitch.bind(this, aOptions);
|
|
|
|
|
view.delete = this._variablesViewDelete.bind(this, aOptions);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
view.eval = null;
|
|
|
|
|
view.switch = null;
|
|
|
|
|
view.delete = null;
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-01 13:17:20 -07:00
|
|
|
|
let { variable, expanded } = view.controller.setSingleVariable(aOptions);
|
|
|
|
|
variable.evaluationMacro = simpleValueEvalMacro;
|
2013-04-09 02:46:30 -07:00
|
|
|
|
|
|
|
|
|
if (aOptions.objectActor) {
|
|
|
|
|
view._consoleLastObjectActor = aOptions.objectActor.actor;
|
|
|
|
|
}
|
|
|
|
|
else if (aOptions.rawObject) {
|
|
|
|
|
view._consoleLastObjectActor = null;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
throw new Error("Variables View cannot open without giving it an object " +
|
|
|
|
|
"display.");
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-01 13:17:20 -07:00
|
|
|
|
expanded.then(() => {
|
|
|
|
|
this.emit("variablesview-updated", view, aOptions);
|
|
|
|
|
});
|
2013-04-09 02:46:30 -07:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The evaluation function used by the variables view when editing a property
|
|
|
|
|
* value.
|
|
|
|
|
*
|
|
|
|
|
* @private
|
|
|
|
|
* @param object aOptions
|
|
|
|
|
* The options used for |this._updateVariablesView()|.
|
|
|
|
|
* @param string aString
|
|
|
|
|
* The string that the variables view wants to evaluate.
|
|
|
|
|
*/
|
|
|
|
|
_variablesViewEvaluate: function JST__variablesViewEvaluate(aOptions, aString)
|
|
|
|
|
{
|
|
|
|
|
let updater = this._updateVariablesView.bind(this, aOptions);
|
|
|
|
|
let onEval = this._silentEvalCallback.bind(this, updater);
|
|
|
|
|
|
|
|
|
|
let evalOptions = {
|
|
|
|
|
frame: this.SELECTED_FRAME,
|
|
|
|
|
bindObjectActor: aOptions.objectActor.actor,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
this.requestEvaluation(aString, evalOptions).then(onEval, onEval);
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The property deletion function used by the variables view when a property
|
|
|
|
|
* is deleted.
|
|
|
|
|
*
|
|
|
|
|
* @private
|
|
|
|
|
* @param object aOptions
|
|
|
|
|
* The options used for |this._updateVariablesView()|.
|
|
|
|
|
* @param object aVar
|
|
|
|
|
* The Variable object instance for the deleted property.
|
|
|
|
|
*/
|
|
|
|
|
_variablesViewDelete: function JST__variablesViewDelete(aOptions, aVar)
|
|
|
|
|
{
|
|
|
|
|
let onEval = this._silentEvalCallback.bind(this, null);
|
|
|
|
|
|
|
|
|
|
let evalOptions = {
|
|
|
|
|
frame: this.SELECTED_FRAME,
|
|
|
|
|
bindObjectActor: aOptions.objectActor.actor,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
this.requestEvaluation("delete _self" + aVar.symbolicName, evalOptions)
|
|
|
|
|
.then(onEval, onEval);
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The property rename function used by the variables view when a property
|
|
|
|
|
* is renamed.
|
|
|
|
|
*
|
|
|
|
|
* @private
|
|
|
|
|
* @param object aOptions
|
|
|
|
|
* The options used for |this._updateVariablesView()|.
|
|
|
|
|
* @param object aVar
|
|
|
|
|
* The Variable object instance for the renamed property.
|
|
|
|
|
* @param string aNewName
|
|
|
|
|
* The new name for the property.
|
|
|
|
|
*/
|
|
|
|
|
_variablesViewSwitch:
|
|
|
|
|
function JST__variablesViewSwitch(aOptions, aVar, aNewName)
|
|
|
|
|
{
|
|
|
|
|
let updater = this._updateVariablesView.bind(this, aOptions);
|
|
|
|
|
let onEval = this._silentEvalCallback.bind(this, updater);
|
|
|
|
|
|
|
|
|
|
let evalOptions = {
|
|
|
|
|
frame: this.SELECTED_FRAME,
|
|
|
|
|
bindObjectActor: aOptions.objectActor.actor,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
let newSymbolicName = aVar.ownerView.symbolicName + '["' + aNewName + '"]';
|
|
|
|
|
if (newSymbolicName == aVar.symbolicName) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let code = "_self" + newSymbolicName + " = _self" + aVar.symbolicName + ";" +
|
|
|
|
|
"delete _self" + aVar.symbolicName;
|
|
|
|
|
|
|
|
|
|
this.requestEvaluation(code, evalOptions).then(onEval, onEval);
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* A noop callback for JavaScript evaluation. This method releases any
|
|
|
|
|
* result ObjectActors that come from the server for evaluation requests. This
|
|
|
|
|
* is used for editing, renaming and deleting properties in the variables
|
|
|
|
|
* view.
|
|
|
|
|
*
|
|
|
|
|
* Exceptions are displayed in the output.
|
|
|
|
|
*
|
|
|
|
|
* @private
|
|
|
|
|
* @param function aCallback
|
|
|
|
|
* Function to invoke once the response is received.
|
|
|
|
|
* @param object aResponse
|
|
|
|
|
* The response packet received from the server.
|
|
|
|
|
*/
|
|
|
|
|
_silentEvalCallback: function JST__silentEvalCallback(aCallback, aResponse)
|
|
|
|
|
{
|
|
|
|
|
if (aResponse.error) {
|
|
|
|
|
Cu.reportError("Web Console evaluation failed. " + aResponse.error + ":" +
|
|
|
|
|
aResponse.message);
|
|
|
|
|
|
|
|
|
|
aCallback && aCallback(aResponse);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let exception = aResponse.exception;
|
|
|
|
|
if (exception) {
|
|
|
|
|
let node = this.writeOutput(aResponse.exceptionMessage,
|
|
|
|
|
CATEGORY_OUTPUT, SEVERITY_ERROR,
|
|
|
|
|
null, aResponse.timestamp);
|
|
|
|
|
node._objectActors = new Set();
|
|
|
|
|
if (WebConsoleUtils.isActorGrip(exception)) {
|
|
|
|
|
node._objectActors.add(exception.actor);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let helper = aResponse.helperResult || { type: null };
|
|
|
|
|
let helperGrip = null;
|
|
|
|
|
if (helper.type == "inspectObject") {
|
|
|
|
|
helperGrip = helper.object;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let grips = [aResponse.result, helperGrip];
|
|
|
|
|
for (let grip of grips) {
|
|
|
|
|
if (WebConsoleUtils.isActorGrip(grip)) {
|
|
|
|
|
this.hud._releaseObject(grip.actor);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
aCallback && aCallback(aResponse);
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
2012-07-26 08:06:04 -07:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Writes a JS object to the JSTerm outputNode.
|
|
|
|
|
*
|
|
|
|
|
* @param string aOutputMessage
|
|
|
|
|
* The message to display.
|
|
|
|
|
* @param function [aCallback]
|
|
|
|
|
* Optional function to invoke when users click the message.
|
|
|
|
|
* @param nsIDOMNode [aNodeAfter]
|
|
|
|
|
* Optional DOM node after which you want to insert the new message.
|
|
|
|
|
* This is used when execution results need to be inserted immediately
|
|
|
|
|
* after the user input.
|
|
|
|
|
* @param number [aTimestamp]
|
|
|
|
|
* Optional timestamp to show for the output message (millisconds since
|
|
|
|
|
* the UNIX epoch). If no timestamp is provided then Date.now() is
|
|
|
|
|
* used.
|
|
|
|
|
* @return nsIDOMNode
|
|
|
|
|
* The new message node.
|
|
|
|
|
*/
|
|
|
|
|
writeOutputJS:
|
|
|
|
|
function JST_writeOutputJS(aOutputMessage, aCallback, aNodeAfter, aTimestamp)
|
|
|
|
|
{
|
2013-09-05 09:29:13 -07:00
|
|
|
|
let link = null;
|
2012-07-26 08:06:04 -07:00
|
|
|
|
if (aCallback) {
|
2013-09-05 09:29:13 -07:00
|
|
|
|
link = this.hud.document.createElementNS(XHTML_NS, "a");
|
|
|
|
|
link.setAttribute("aria-haspopup", true);
|
|
|
|
|
link.textContent = aOutputMessage;
|
|
|
|
|
link.href = "#";
|
|
|
|
|
link.draggable = false;
|
|
|
|
|
this.hud._addMessageLinkCallback(link, aCallback);
|
2012-07-26 08:06:04 -07:00
|
|
|
|
}
|
2013-09-05 09:29:13 -07:00
|
|
|
|
|
|
|
|
|
return this.writeOutput(link || aOutputMessage, CATEGORY_OUTPUT,
|
|
|
|
|
SEVERITY_LOG, aNodeAfter, aTimestamp);
|
2012-07-26 08:06:04 -07:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Writes a message to the HUD that originates from the interactive
|
|
|
|
|
* JavaScript console.
|
|
|
|
|
*
|
2013-09-05 09:29:13 -07:00
|
|
|
|
* @param nsIDOMNode|string aOutputMessage
|
2012-07-26 08:06:04 -07:00
|
|
|
|
* The message to display.
|
|
|
|
|
* @param number aCategory
|
|
|
|
|
* The category of message: one of the CATEGORY_ constants.
|
|
|
|
|
* @param number aSeverity
|
|
|
|
|
* The severity of message: one of the SEVERITY_ constants.
|
|
|
|
|
* @param nsIDOMNode [aNodeAfter]
|
|
|
|
|
* Optional DOM node after which you want to insert the new message.
|
|
|
|
|
* This is used when execution results need to be inserted immediately
|
|
|
|
|
* after the user input.
|
|
|
|
|
* @param number [aTimestamp]
|
|
|
|
|
* Optional timestamp to show for the output message (millisconds since
|
|
|
|
|
* the UNIX epoch). If no timestamp is provided then Date.now() is
|
|
|
|
|
* used.
|
|
|
|
|
* @return nsIDOMNode
|
|
|
|
|
* The new message node.
|
|
|
|
|
*/
|
|
|
|
|
writeOutput:
|
|
|
|
|
function JST_writeOutput(aOutputMessage, aCategory, aSeverity, aNodeAfter,
|
|
|
|
|
aTimestamp)
|
|
|
|
|
{
|
|
|
|
|
let node = this.hud.createMessageNode(aCategory, aSeverity, aOutputMessage,
|
|
|
|
|
null, null, null, null, aTimestamp);
|
|
|
|
|
node._outputAfterNode = aNodeAfter;
|
|
|
|
|
this.hud.outputMessage(aCategory, node);
|
|
|
|
|
return node;
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Clear the Web Console output.
|
|
|
|
|
*
|
2013-06-21 09:01:02 -07:00
|
|
|
|
* This method emits the "messages-cleared" notification.
|
|
|
|
|
*
|
2012-07-26 08:06:04 -07:00
|
|
|
|
* @param boolean aClearStorage
|
|
|
|
|
* True if you want to clear the console messages storage associated to
|
|
|
|
|
* this Web Console.
|
|
|
|
|
*/
|
|
|
|
|
clearOutput: function JST_clearOutput(aClearStorage)
|
|
|
|
|
{
|
|
|
|
|
let hud = this.hud;
|
|
|
|
|
let outputNode = hud.outputNode;
|
|
|
|
|
let node;
|
|
|
|
|
while ((node = outputNode.firstChild)) {
|
|
|
|
|
hud.removeOutputMessage(node);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hud.groupDepth = 0;
|
|
|
|
|
hud._outputQueue.forEach(hud._pruneItemFromQueue, hud);
|
|
|
|
|
hud._outputQueue = [];
|
|
|
|
|
hud._networkRequests = {};
|
2013-04-22 18:07:36 -07:00
|
|
|
|
hud._repeatNodes = {};
|
2012-07-26 08:06:04 -07:00
|
|
|
|
|
|
|
|
|
if (aClearStorage) {
|
2012-09-26 10:02:04 -07:00
|
|
|
|
this.webConsoleClient.clearMessagesCache();
|
2012-07-26 08:06:04 -07:00
|
|
|
|
}
|
2013-06-21 09:01:02 -07:00
|
|
|
|
|
|
|
|
|
this.emit("messages-cleared");
|
2012-07-26 08:06:04 -07:00
|
|
|
|
},
|
|
|
|
|
|
2013-05-25 02:25:36 -07:00
|
|
|
|
/**
|
|
|
|
|
* Remove all of the private messages from the Web Console output.
|
2013-06-21 09:01:02 -07:00
|
|
|
|
*
|
|
|
|
|
* This method emits the "private-messages-cleared" notification.
|
2013-05-25 02:25:36 -07:00
|
|
|
|
*/
|
|
|
|
|
clearPrivateMessages: function JST_clearPrivateMessages()
|
|
|
|
|
{
|
2013-09-05 09:34:22 -07:00
|
|
|
|
let nodes = this.hud.outputNode.querySelectorAll(".message[private]");
|
2013-05-25 02:25:36 -07:00
|
|
|
|
for (let node of nodes) {
|
|
|
|
|
this.hud.removeOutputMessage(node);
|
|
|
|
|
}
|
|
|
|
|
this.emit("private-messages-cleared");
|
|
|
|
|
},
|
|
|
|
|
|
2012-07-26 08:06:04 -07:00
|
|
|
|
/**
|
|
|
|
|
* Updates the size of the input field (command line) to fit its contents.
|
|
|
|
|
*
|
|
|
|
|
* @returns void
|
|
|
|
|
*/
|
|
|
|
|
resizeInput: function JST_resizeInput()
|
|
|
|
|
{
|
|
|
|
|
let inputNode = this.inputNode;
|
|
|
|
|
|
|
|
|
|
// Reset the height so that scrollHeight will reflect the natural height of
|
|
|
|
|
// the contents of the input field.
|
|
|
|
|
inputNode.style.height = "auto";
|
|
|
|
|
|
|
|
|
|
// Now resize the input field to fit its contents.
|
|
|
|
|
let scrollHeight = inputNode.inputField.scrollHeight;
|
|
|
|
|
if (scrollHeight > 0) {
|
|
|
|
|
inputNode.style.height = scrollHeight + "px";
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Sets the value of the input field (command line), and resizes the field to
|
|
|
|
|
* fit its contents. This method is preferred over setting "inputNode.value"
|
|
|
|
|
* directly, because it correctly resizes the field.
|
|
|
|
|
*
|
|
|
|
|
* @param string aNewValue
|
|
|
|
|
* The new value to set.
|
|
|
|
|
* @returns void
|
|
|
|
|
*/
|
|
|
|
|
setInputValue: function JST_setInputValue(aNewValue)
|
|
|
|
|
{
|
|
|
|
|
this.inputNode.value = aNewValue;
|
|
|
|
|
this.lastInputValue = aNewValue;
|
|
|
|
|
this.completeNode.value = "";
|
|
|
|
|
this.resizeInput();
|
2013-06-17 04:10:46 -07:00
|
|
|
|
this._inputChanged = true;
|
2012-07-26 08:06:04 -07:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The inputNode "input" and "keyup" event handler.
|
2013-06-17 04:10:46 -07:00
|
|
|
|
* @private
|
2012-07-26 08:06:04 -07:00
|
|
|
|
*/
|
2013-06-17 04:10:46 -07:00
|
|
|
|
_inputEventHandler: function JST__inputEventHandler()
|
2012-07-26 08:06:04 -07:00
|
|
|
|
{
|
|
|
|
|
if (this.lastInputValue != this.inputNode.value) {
|
|
|
|
|
this.resizeInput();
|
|
|
|
|
this.complete(this.COMPLETE_HINT_ONLY);
|
|
|
|
|
this.lastInputValue = this.inputNode.value;
|
2013-06-17 04:10:46 -07:00
|
|
|
|
this._inputChanged = true;
|
2012-07-26 08:06:04 -07:00
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The inputNode "keypress" event handler.
|
|
|
|
|
*
|
2013-06-17 04:10:46 -07:00
|
|
|
|
* @private
|
2012-07-26 08:06:04 -07:00
|
|
|
|
* @param nsIDOMEvent aEvent
|
|
|
|
|
*/
|
2013-06-17 04:10:46 -07:00
|
|
|
|
_keyPress: function JST__keyPress(aEvent)
|
2012-07-26 08:06:04 -07:00
|
|
|
|
{
|
2013-06-21 09:01:02 -07:00
|
|
|
|
let inputNode = this.inputNode;
|
|
|
|
|
let inputUpdated = false;
|
|
|
|
|
|
2012-07-26 08:06:04 -07:00
|
|
|
|
if (aEvent.ctrlKey) {
|
|
|
|
|
switch (aEvent.charCode) {
|
|
|
|
|
case 97:
|
|
|
|
|
// control-a
|
2013-06-21 09:01:02 -07:00
|
|
|
|
this.clearCompletion();
|
|
|
|
|
|
2013-02-25 13:26:53 -08:00
|
|
|
|
if (Services.appinfo.OS == "WINNT") {
|
2013-06-21 09:01:02 -07:00
|
|
|
|
// Allow Select All on Windows.
|
2013-02-25 13:26:53 -08:00
|
|
|
|
break;
|
|
|
|
|
}
|
2013-06-21 09:01:02 -07:00
|
|
|
|
|
2012-12-17 05:47:23 -08:00
|
|
|
|
let lineBeginPos = 0;
|
|
|
|
|
if (this.hasMultilineInput()) {
|
|
|
|
|
// find index of closest newline <= to cursor
|
|
|
|
|
for (let i = inputNode.selectionStart-1; i >= 0; i--) {
|
|
|
|
|
if (inputNode.value.charAt(i) == "\r" ||
|
|
|
|
|
inputNode.value.charAt(i) == "\n") {
|
|
|
|
|
lineBeginPos = i+1;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
inputNode.setSelectionRange(lineBeginPos, lineBeginPos);
|
2012-07-26 08:06:04 -07:00
|
|
|
|
aEvent.preventDefault();
|
|
|
|
|
break;
|
2013-06-21 09:01:02 -07:00
|
|
|
|
|
2012-07-26 08:06:04 -07:00
|
|
|
|
case 101:
|
|
|
|
|
// control-e
|
2013-02-25 13:26:53 -08:00
|
|
|
|
if (Services.appinfo.OS == "WINNT") {
|
|
|
|
|
break;
|
|
|
|
|
}
|
2012-12-17 05:47:23 -08:00
|
|
|
|
let lineEndPos = inputNode.value.length;
|
|
|
|
|
if (this.hasMultilineInput()) {
|
|
|
|
|
// find index of closest newline >= cursor
|
|
|
|
|
for (let i = inputNode.selectionEnd; i<lineEndPos; i++) {
|
|
|
|
|
if (inputNode.value.charAt(i) == "\r" ||
|
|
|
|
|
inputNode.value.charAt(i) == "\n") {
|
|
|
|
|
lineEndPos = i;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
inputNode.setSelectionRange(lineEndPos, lineEndPos);
|
2012-07-26 08:06:04 -07:00
|
|
|
|
aEvent.preventDefault();
|
2013-06-21 09:01:02 -07:00
|
|
|
|
this.clearCompletion();
|
2012-07-26 08:06:04 -07:00
|
|
|
|
break;
|
2013-06-21 09:01:02 -07:00
|
|
|
|
|
2012-12-17 05:47:23 -08:00
|
|
|
|
case 110:
|
|
|
|
|
// Control-N differs from down arrow: it ignores autocomplete state.
|
|
|
|
|
// Note that we preserve the default 'down' navigation within
|
|
|
|
|
// multiline text.
|
|
|
|
|
if (Services.appinfo.OS == "Darwin" &&
|
|
|
|
|
this.canCaretGoNext() &&
|
|
|
|
|
this.historyPeruse(HISTORY_FORWARD)) {
|
|
|
|
|
aEvent.preventDefault();
|
2013-06-21 09:01:02 -07:00
|
|
|
|
// Ctrl-N is also used to focus the Network category button on MacOSX.
|
|
|
|
|
// The preventDefault() call doesn't prevent the focus from moving
|
|
|
|
|
// away from the input.
|
|
|
|
|
inputNode.focus();
|
2012-12-17 05:47:23 -08:00
|
|
|
|
}
|
2013-06-21 09:01:02 -07:00
|
|
|
|
this.clearCompletion();
|
2012-12-17 05:47:23 -08:00
|
|
|
|
break;
|
2013-06-21 09:01:02 -07:00
|
|
|
|
|
2012-12-17 05:47:23 -08:00
|
|
|
|
case 112:
|
|
|
|
|
// Control-P differs from up arrow: it ignores autocomplete state.
|
|
|
|
|
// Note that we preserve the default 'up' navigation within
|
|
|
|
|
// multiline text.
|
|
|
|
|
if (Services.appinfo.OS == "Darwin" &&
|
|
|
|
|
this.canCaretGoPrevious() &&
|
|
|
|
|
this.historyPeruse(HISTORY_BACK)) {
|
|
|
|
|
aEvent.preventDefault();
|
2013-06-21 09:01:02 -07:00
|
|
|
|
// Ctrl-P may also be used to focus some category button on MacOSX.
|
|
|
|
|
// The preventDefault() call doesn't prevent the focus from moving
|
|
|
|
|
// away from the input.
|
|
|
|
|
inputNode.focus();
|
2012-12-17 05:47:23 -08:00
|
|
|
|
}
|
2013-06-21 09:01:02 -07:00
|
|
|
|
this.clearCompletion();
|
2012-12-17 05:47:23 -08:00
|
|
|
|
break;
|
2012-07-26 08:06:04 -07:00
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
else if (aEvent.shiftKey &&
|
|
|
|
|
aEvent.keyCode == Ci.nsIDOMKeyEvent.DOM_VK_RETURN) {
|
|
|
|
|
// shift return
|
|
|
|
|
// TODO: expand the inputNode height by one line
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-21 09:01:02 -07:00
|
|
|
|
switch (aEvent.keyCode) {
|
2012-07-26 08:06:04 -07:00
|
|
|
|
case Ci.nsIDOMKeyEvent.DOM_VK_ESCAPE:
|
|
|
|
|
if (this.autocompletePopup.isOpen) {
|
|
|
|
|
this.clearCompletion();
|
|
|
|
|
aEvent.preventDefault();
|
|
|
|
|
}
|
2013-05-02 04:53:11 -07:00
|
|
|
|
else if (this.sidebar) {
|
|
|
|
|
this._sidebarDestroy();
|
2013-06-21 09:01:02 -07:00
|
|
|
|
aEvent.preventDefault();
|
2013-05-02 04:53:11 -07:00
|
|
|
|
}
|
2012-07-26 08:06:04 -07:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case Ci.nsIDOMKeyEvent.DOM_VK_RETURN:
|
2013-06-21 09:01:02 -07:00
|
|
|
|
if (this._autocompletePopupNavigated &&
|
|
|
|
|
this.autocompletePopup.isOpen &&
|
|
|
|
|
this.autocompletePopup.selectedIndex > -1) {
|
|
|
|
|
this.acceptProposedCompletion();
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
this.execute();
|
|
|
|
|
this._inputChanged = false;
|
|
|
|
|
}
|
2012-07-26 08:06:04 -07:00
|
|
|
|
aEvent.preventDefault();
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case Ci.nsIDOMKeyEvent.DOM_VK_UP:
|
|
|
|
|
if (this.autocompletePopup.isOpen) {
|
|
|
|
|
inputUpdated = this.complete(this.COMPLETE_BACKWARD);
|
2013-06-21 09:01:02 -07:00
|
|
|
|
if (inputUpdated) {
|
|
|
|
|
this._autocompletePopupNavigated = true;
|
|
|
|
|
}
|
2012-07-26 08:06:04 -07:00
|
|
|
|
}
|
|
|
|
|
else if (this.canCaretGoPrevious()) {
|
|
|
|
|
inputUpdated = this.historyPeruse(HISTORY_BACK);
|
|
|
|
|
}
|
|
|
|
|
if (inputUpdated) {
|
|
|
|
|
aEvent.preventDefault();
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case Ci.nsIDOMKeyEvent.DOM_VK_DOWN:
|
|
|
|
|
if (this.autocompletePopup.isOpen) {
|
|
|
|
|
inputUpdated = this.complete(this.COMPLETE_FORWARD);
|
2013-06-21 09:01:02 -07:00
|
|
|
|
if (inputUpdated) {
|
|
|
|
|
this._autocompletePopupNavigated = true;
|
|
|
|
|
}
|
2012-07-26 08:06:04 -07:00
|
|
|
|
}
|
|
|
|
|
else if (this.canCaretGoNext()) {
|
|
|
|
|
inputUpdated = this.historyPeruse(HISTORY_FORWARD);
|
|
|
|
|
}
|
|
|
|
|
if (inputUpdated) {
|
|
|
|
|
aEvent.preventDefault();
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
2013-06-21 09:01:02 -07:00
|
|
|
|
case Ci.nsIDOMKeyEvent.DOM_VK_HOME:
|
|
|
|
|
case Ci.nsIDOMKeyEvent.DOM_VK_END:
|
|
|
|
|
case Ci.nsIDOMKeyEvent.DOM_VK_LEFT:
|
|
|
|
|
if (this.autocompletePopup.isOpen || this.lastCompletion.value) {
|
|
|
|
|
this.clearCompletion();
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case Ci.nsIDOMKeyEvent.DOM_VK_RIGHT: {
|
|
|
|
|
let cursorAtTheEnd = this.inputNode.selectionStart ==
|
|
|
|
|
this.inputNode.selectionEnd &&
|
|
|
|
|
this.inputNode.selectionStart ==
|
|
|
|
|
this.inputNode.value.length;
|
|
|
|
|
let haveSuggestion = this.autocompletePopup.isOpen ||
|
|
|
|
|
this.lastCompletion.value;
|
|
|
|
|
let useCompletion = cursorAtTheEnd || this._autocompletePopupNavigated;
|
|
|
|
|
if (haveSuggestion && useCompletion &&
|
|
|
|
|
this.complete(this.COMPLETE_HINT_ONLY) &&
|
|
|
|
|
this.lastCompletion.value &&
|
|
|
|
|
this.acceptProposedCompletion()) {
|
|
|
|
|
aEvent.preventDefault();
|
|
|
|
|
}
|
|
|
|
|
if (this.autocompletePopup.isOpen) {
|
|
|
|
|
this.clearCompletion();
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
2012-07-26 08:06:04 -07:00
|
|
|
|
case Ci.nsIDOMKeyEvent.DOM_VK_TAB:
|
|
|
|
|
// Generate a completion and accept the first proposed value.
|
|
|
|
|
if (this.complete(this.COMPLETE_HINT_ONLY) &&
|
|
|
|
|
this.lastCompletion &&
|
|
|
|
|
this.acceptProposedCompletion()) {
|
|
|
|
|
aEvent.preventDefault();
|
|
|
|
|
}
|
2013-06-17 04:10:46 -07:00
|
|
|
|
else if (this._inputChanged) {
|
2012-07-26 08:06:04 -07:00
|
|
|
|
this.updateCompleteNode(l10n.getStr("Autocomplete.blank"));
|
|
|
|
|
aEvent.preventDefault();
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
2013-06-17 04:10:46 -07:00
|
|
|
|
/**
|
|
|
|
|
* The inputNode "focus" event handler.
|
|
|
|
|
* @private
|
|
|
|
|
*/
|
|
|
|
|
_focusEventHandler: function JST__focusEventHandler()
|
|
|
|
|
{
|
|
|
|
|
this._inputChanged = false;
|
|
|
|
|
},
|
|
|
|
|
|
2012-07-26 08:06:04 -07:00
|
|
|
|
/**
|
|
|
|
|
* Go up/down the history stack of input values.
|
|
|
|
|
*
|
|
|
|
|
* @param number aDirection
|
|
|
|
|
* History navigation direction: HISTORY_BACK or HISTORY_FORWARD.
|
|
|
|
|
*
|
|
|
|
|
* @returns boolean
|
|
|
|
|
* True if the input value changed, false otherwise.
|
|
|
|
|
*/
|
|
|
|
|
historyPeruse: function JST_historyPeruse(aDirection)
|
|
|
|
|
{
|
|
|
|
|
if (!this.history.length) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Up Arrow key
|
|
|
|
|
if (aDirection == HISTORY_BACK) {
|
|
|
|
|
if (this.historyPlaceHolder <= 0) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
let inputVal = this.history[--this.historyPlaceHolder];
|
2013-05-30 09:16:41 -07:00
|
|
|
|
|
|
|
|
|
// Save the current input value as the latest entry in history, only if
|
|
|
|
|
// the user is already at the last entry.
|
|
|
|
|
// Note: this code does not store changes to items that are already in
|
|
|
|
|
// history.
|
|
|
|
|
if (this.historyPlaceHolder+1 == this.historyIndex) {
|
|
|
|
|
this.history[this.historyIndex] = this.inputNode.value || "";
|
2012-07-26 08:06:04 -07:00
|
|
|
|
}
|
2013-05-30 09:16:41 -07:00
|
|
|
|
|
|
|
|
|
this.setInputValue(inputVal);
|
2012-07-26 08:06:04 -07:00
|
|
|
|
}
|
|
|
|
|
// Down Arrow key
|
|
|
|
|
else if (aDirection == HISTORY_FORWARD) {
|
2013-05-30 09:16:41 -07:00
|
|
|
|
if (this.historyPlaceHolder >= (this.history.length-1)) {
|
2012-07-26 08:06:04 -07:00
|
|
|
|
return false;
|
|
|
|
|
}
|
2013-05-30 09:16:41 -07:00
|
|
|
|
|
|
|
|
|
let inputVal = this.history[++this.historyPlaceHolder];
|
|
|
|
|
this.setInputValue(inputVal);
|
2012-07-26 08:06:04 -07:00
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
throw new Error("Invalid argument 0");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
},
|
|
|
|
|
|
2012-12-17 05:47:23 -08:00
|
|
|
|
/**
|
|
|
|
|
* Test for multiline input.
|
|
|
|
|
*
|
|
|
|
|
* @return boolean
|
|
|
|
|
* True if CR or LF found in node value; else false.
|
|
|
|
|
*/
|
|
|
|
|
hasMultilineInput: function JST_hasMultilineInput()
|
|
|
|
|
{
|
|
|
|
|
return /[\r\n]/.test(this.inputNode.value);
|
|
|
|
|
},
|
|
|
|
|
|
2012-07-26 08:06:04 -07:00
|
|
|
|
/**
|
|
|
|
|
* Check if the caret is at a location that allows selecting the previous item
|
|
|
|
|
* in history when the user presses the Up arrow key.
|
|
|
|
|
*
|
|
|
|
|
* @return boolean
|
|
|
|
|
* True if the caret is at a location that allows selecting the
|
|
|
|
|
* previous item in history when the user presses the Up arrow key,
|
|
|
|
|
* otherwise false.
|
|
|
|
|
*/
|
|
|
|
|
canCaretGoPrevious: function JST_canCaretGoPrevious()
|
|
|
|
|
{
|
|
|
|
|
let node = this.inputNode;
|
|
|
|
|
if (node.selectionStart != node.selectionEnd) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let multiline = /[\r\n]/.test(node.value);
|
|
|
|
|
return node.selectionStart == 0 ? true :
|
|
|
|
|
node.selectionStart == node.value.length && !multiline;
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Check if the caret is at a location that allows selecting the next item in
|
|
|
|
|
* history when the user presses the Down arrow key.
|
|
|
|
|
*
|
|
|
|
|
* @return boolean
|
|
|
|
|
* True if the caret is at a location that allows selecting the next
|
|
|
|
|
* item in history when the user presses the Down arrow key, otherwise
|
|
|
|
|
* false.
|
|
|
|
|
*/
|
|
|
|
|
canCaretGoNext: function JST_canCaretGoNext()
|
|
|
|
|
{
|
|
|
|
|
let node = this.inputNode;
|
|
|
|
|
if (node.selectionStart != node.selectionEnd) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let multiline = /[\r\n]/.test(node.value);
|
|
|
|
|
return node.selectionStart == node.value.length ? true :
|
|
|
|
|
node.selectionStart == 0 && !multiline;
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Completes the current typed text in the inputNode. Completion is performed
|
|
|
|
|
* only if the selection/cursor is at the end of the string. If no completion
|
|
|
|
|
* is found, the current inputNode value and cursor/selection stay.
|
|
|
|
|
*
|
|
|
|
|
* @param int aType possible values are
|
|
|
|
|
* - this.COMPLETE_FORWARD: If there is more than one possible completion
|
|
|
|
|
* and the input value stayed the same compared to the last time this
|
|
|
|
|
* function was called, then the next completion of all possible
|
|
|
|
|
* completions is used. If the value changed, then the first possible
|
|
|
|
|
* completion is used and the selection is set from the current
|
|
|
|
|
* cursor position to the end of the completed text.
|
|
|
|
|
* If there is only one possible completion, then this completion
|
|
|
|
|
* value is used and the cursor is put at the end of the completion.
|
|
|
|
|
* - this.COMPLETE_BACKWARD: Same as this.COMPLETE_FORWARD but if the
|
|
|
|
|
* value stayed the same as the last time the function was called,
|
|
|
|
|
* then the previous completion of all possible completions is used.
|
|
|
|
|
* - this.COMPLETE_HINT_ONLY: If there is more than one possible
|
|
|
|
|
* completion and the input value stayed the same compared to the
|
|
|
|
|
* last time this function was called, then the same completion is
|
|
|
|
|
* used again. If there is only one possible completion, then
|
|
|
|
|
* the inputNode.value is set to this value and the selection is set
|
|
|
|
|
* from the current cursor position to the end of the completed text.
|
|
|
|
|
* @param function aCallback
|
|
|
|
|
* Optional function invoked when the autocomplete properties are
|
|
|
|
|
* updated.
|
|
|
|
|
* @returns boolean true if there existed a completion for the current input,
|
|
|
|
|
* or false otherwise.
|
|
|
|
|
*/
|
|
|
|
|
complete: function JSTF_complete(aType, aCallback)
|
|
|
|
|
{
|
|
|
|
|
let inputNode = this.inputNode;
|
|
|
|
|
let inputValue = inputNode.value;
|
|
|
|
|
// If the inputNode has no value, then don't try to complete on it.
|
|
|
|
|
if (!inputValue) {
|
|
|
|
|
this.clearCompletion();
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-28 10:56:33 -07:00
|
|
|
|
// Only complete if the selection is empty.
|
|
|
|
|
if (inputNode.selectionStart != inputNode.selectionEnd) {
|
2012-07-26 08:06:04 -07:00
|
|
|
|
this.clearCompletion();
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Update the completion results.
|
|
|
|
|
if (this.lastCompletion.value != inputValue) {
|
|
|
|
|
this._updateCompletionResult(aType, aCallback);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let popup = this.autocompletePopup;
|
|
|
|
|
let accepted = false;
|
|
|
|
|
|
|
|
|
|
if (aType != this.COMPLETE_HINT_ONLY && popup.itemCount == 1) {
|
|
|
|
|
this.acceptProposedCompletion();
|
|
|
|
|
accepted = true;
|
|
|
|
|
}
|
|
|
|
|
else if (aType == this.COMPLETE_BACKWARD) {
|
|
|
|
|
popup.selectPreviousItem();
|
|
|
|
|
}
|
|
|
|
|
else if (aType == this.COMPLETE_FORWARD) {
|
|
|
|
|
popup.selectNextItem();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
aCallback && aCallback(this);
|
|
|
|
|
return accepted || popup.itemCount > 0;
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Update the completion result. This operation is performed asynchronously by
|
|
|
|
|
* fetching updated results from the content process.
|
|
|
|
|
*
|
|
|
|
|
* @private
|
|
|
|
|
* @param int aType
|
|
|
|
|
* Completion type. See this.complete() for details.
|
|
|
|
|
* @param function [aCallback]
|
|
|
|
|
* Optional, function to invoke when completion results are received.
|
|
|
|
|
*/
|
|
|
|
|
_updateCompletionResult:
|
|
|
|
|
function JST__updateCompletionResult(aType, aCallback)
|
|
|
|
|
{
|
|
|
|
|
if (this.lastCompletion.value == this.inputNode.value) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2012-09-26 10:02:04 -07:00
|
|
|
|
let requestId = gSequenceId();
|
|
|
|
|
let cursor = this.inputNode.selectionStart;
|
2013-08-01 12:31:36 -07:00
|
|
|
|
let input = this.inputNode.value.substring(0, cursor);
|
|
|
|
|
let cache = this._autocompleteCache;
|
|
|
|
|
|
|
|
|
|
// If the current input starts with the previous input, then we already
|
|
|
|
|
// have a list of suggestions and we just need to filter the cached
|
|
|
|
|
// suggestions. When the current input ends with a non-alphanumeric
|
|
|
|
|
// character we ask the server again for suggestions.
|
|
|
|
|
|
|
|
|
|
// Check if last character is non-alphanumeric
|
|
|
|
|
if (!/[a-zA-Z0-9]$/.test(input)) {
|
|
|
|
|
this._autocompleteQuery = null;
|
|
|
|
|
this._autocompleteCache = null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (this._autocompleteQuery && input.startsWith(this._autocompleteQuery)) {
|
|
|
|
|
let filterBy = input;
|
|
|
|
|
// Find the last non-alphanumeric if exists.
|
|
|
|
|
let lastNonAlpha = input.match(/[^a-zA-Z0-9][a-zA-Z0-9]*$/);
|
|
|
|
|
// If input contains non-alphanumerics, use the part after the last one
|
|
|
|
|
// to filter the cache
|
|
|
|
|
if (lastNonAlpha) {
|
|
|
|
|
filterBy = input.substring(input.lastIndexOf(lastNonAlpha) + 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let newList = cache.sort().filter(function(l) {
|
|
|
|
|
return l.startsWith(filterBy);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
this.lastCompletion = {
|
|
|
|
|
requestId: null,
|
|
|
|
|
completionType: aType,
|
|
|
|
|
value: null,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
let response = { matches: newList, matchProp: filterBy };
|
|
|
|
|
this._receiveAutocompleteProperties(null, aCallback, response);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2012-07-26 08:06:04 -07:00
|
|
|
|
|
|
|
|
|
this.lastCompletion = {
|
2012-09-26 10:02:04 -07:00
|
|
|
|
requestId: requestId,
|
2012-07-26 08:06:04 -07:00
|
|
|
|
completionType: aType,
|
|
|
|
|
value: null,
|
|
|
|
|
};
|
2012-09-26 10:02:04 -07:00
|
|
|
|
|
|
|
|
|
let callback = this._receiveAutocompleteProperties.bind(this, requestId,
|
|
|
|
|
aCallback);
|
|
|
|
|
this.webConsoleClient.autocomplete(input, cursor, callback);
|
2012-07-26 08:06:04 -07:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
2012-09-26 10:02:04 -07:00
|
|
|
|
* Handler for the autocompletion results. This method takes
|
|
|
|
|
* the completion result received from the server and updates the UI
|
2012-07-26 08:06:04 -07:00
|
|
|
|
* accordingly.
|
|
|
|
|
*
|
2012-09-26 10:02:04 -07:00
|
|
|
|
* @param number aRequestId
|
|
|
|
|
* Request ID.
|
2012-07-26 08:06:04 -07:00
|
|
|
|
* @param function [aCallback=null]
|
|
|
|
|
* Optional, function to invoke when the completion result is received.
|
|
|
|
|
* @param object aMessage
|
|
|
|
|
* The JSON message which holds the completion results received from
|
|
|
|
|
* the content process.
|
|
|
|
|
*/
|
|
|
|
|
_receiveAutocompleteProperties:
|
2012-09-26 10:02:04 -07:00
|
|
|
|
function JST__receiveAutocompleteProperties(aRequestId, aCallback, aMessage)
|
2012-07-26 08:06:04 -07:00
|
|
|
|
{
|
|
|
|
|
let inputNode = this.inputNode;
|
|
|
|
|
let inputValue = inputNode.value;
|
2012-09-26 10:02:04 -07:00
|
|
|
|
if (this.lastCompletion.value == inputValue ||
|
|
|
|
|
aRequestId != this.lastCompletion.requestId) {
|
2012-07-26 08:06:04 -07:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-01 12:31:36 -07:00
|
|
|
|
// Cache whatever came from the server if the last char is alphanumeric or '.'
|
|
|
|
|
let cursor = inputNode.selectionStart;
|
|
|
|
|
let inputUntilCursor = inputValue.substring(0, cursor);
|
|
|
|
|
|
|
|
|
|
if (aRequestId != null && /[a-zA-Z0-9.]$/.test(inputUntilCursor)) {
|
|
|
|
|
this._autocompleteCache = aMessage.matches;
|
|
|
|
|
this._autocompleteQuery = inputUntilCursor;
|
|
|
|
|
}
|
|
|
|
|
|
2012-07-26 08:06:04 -07:00
|
|
|
|
let matches = aMessage.matches;
|
2013-03-14 11:04:05 -07:00
|
|
|
|
let lastPart = aMessage.matchProp;
|
2012-07-26 08:06:04 -07:00
|
|
|
|
if (!matches.length) {
|
|
|
|
|
this.clearCompletion();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-14 11:04:05 -07:00
|
|
|
|
let items = matches.reverse().map(function(aMatch) {
|
|
|
|
|
return { preLabel: lastPart, label: aMatch };
|
2012-07-26 08:06:04 -07:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
let popup = this.autocompletePopup;
|
|
|
|
|
popup.setItems(items);
|
|
|
|
|
|
|
|
|
|
let completionType = this.lastCompletion.completionType;
|
|
|
|
|
this.lastCompletion = {
|
|
|
|
|
value: inputValue,
|
2013-03-14 11:04:05 -07:00
|
|
|
|
matchProp: lastPart,
|
2012-07-26 08:06:04 -07:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (items.length > 1 && !popup.isOpen) {
|
|
|
|
|
popup.openPopup(inputNode);
|
2013-06-21 09:01:02 -07:00
|
|
|
|
this._autocompletePopupNavigated = false;
|
2012-07-26 08:06:04 -07:00
|
|
|
|
}
|
|
|
|
|
else if (items.length < 2 && popup.isOpen) {
|
|
|
|
|
popup.hidePopup();
|
2013-06-21 09:01:02 -07:00
|
|
|
|
this._autocompletePopupNavigated = false;
|
2012-07-26 08:06:04 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (items.length == 1) {
|
|
|
|
|
popup.selectedIndex = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.onAutocompleteSelect();
|
|
|
|
|
|
|
|
|
|
if (completionType != this.COMPLETE_HINT_ONLY && popup.itemCount == 1) {
|
|
|
|
|
this.acceptProposedCompletion();
|
|
|
|
|
}
|
|
|
|
|
else if (completionType == this.COMPLETE_BACKWARD) {
|
|
|
|
|
popup.selectPreviousItem();
|
|
|
|
|
}
|
|
|
|
|
else if (completionType == this.COMPLETE_FORWARD) {
|
|
|
|
|
popup.selectNextItem();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
aCallback && aCallback(this);
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
onAutocompleteSelect: function JSTF_onAutocompleteSelect()
|
|
|
|
|
{
|
2013-06-28 10:56:33 -07:00
|
|
|
|
// Render the suggestion only if the cursor is at the end of the input.
|
|
|
|
|
if (this.inputNode.selectionStart != this.inputNode.value.length) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2012-07-26 08:06:04 -07:00
|
|
|
|
let currentItem = this.autocompletePopup.selectedItem;
|
|
|
|
|
if (currentItem && this.lastCompletion.value) {
|
|
|
|
|
let suffix = currentItem.label.substring(this.lastCompletion.
|
|
|
|
|
matchProp.length);
|
|
|
|
|
this.updateCompleteNode(suffix);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
this.updateCompleteNode("");
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Clear the current completion information and close the autocomplete popup,
|
|
|
|
|
* if needed.
|
|
|
|
|
*/
|
|
|
|
|
clearCompletion: function JSTF_clearCompletion()
|
|
|
|
|
{
|
|
|
|
|
this.autocompletePopup.clearItems();
|
|
|
|
|
this.lastCompletion = { value: null };
|
|
|
|
|
this.updateCompleteNode("");
|
|
|
|
|
if (this.autocompletePopup.isOpen) {
|
|
|
|
|
this.autocompletePopup.hidePopup();
|
2013-06-21 09:01:02 -07:00
|
|
|
|
this._autocompletePopupNavigated = false;
|
2012-07-26 08:06:04 -07:00
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Accept the proposed input completion.
|
|
|
|
|
*
|
|
|
|
|
* @return boolean
|
|
|
|
|
* True if there was a selected completion item and the input value
|
|
|
|
|
* was updated, false otherwise.
|
|
|
|
|
*/
|
|
|
|
|
acceptProposedCompletion: function JSTF_acceptProposedCompletion()
|
|
|
|
|
{
|
|
|
|
|
let updated = false;
|
|
|
|
|
|
|
|
|
|
let currentItem = this.autocompletePopup.selectedItem;
|
|
|
|
|
if (currentItem && this.lastCompletion.value) {
|
|
|
|
|
let suffix = currentItem.label.substring(this.lastCompletion.
|
|
|
|
|
matchProp.length);
|
2013-06-28 10:56:33 -07:00
|
|
|
|
let cursor = this.inputNode.selectionStart;
|
|
|
|
|
let value = this.inputNode.value;
|
|
|
|
|
this.setInputValue(value.substr(0, cursor) + suffix + value.substr(cursor));
|
|
|
|
|
let newCursor = cursor + suffix.length;
|
|
|
|
|
this.inputNode.selectionStart = this.inputNode.selectionEnd = newCursor;
|
2012-07-26 08:06:04 -07:00
|
|
|
|
updated = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.clearCompletion();
|
|
|
|
|
|
|
|
|
|
return updated;
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Update the node that displays the currently selected autocomplete proposal.
|
|
|
|
|
*
|
|
|
|
|
* @param string aSuffix
|
|
|
|
|
* The proposed suffix for the inputNode value.
|
|
|
|
|
*/
|
|
|
|
|
updateCompleteNode: function JSTF_updateCompleteNode(aSuffix)
|
|
|
|
|
{
|
|
|
|
|
// completion prefix = input, with non-control chars replaced by spaces
|
|
|
|
|
let prefix = aSuffix ? this.inputNode.value.replace(/[\S]/g, " ") : "";
|
|
|
|
|
this.completeNode.value = prefix + aSuffix;
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The click event handler for evaluation results in the output.
|
|
|
|
|
*
|
|
|
|
|
* @private
|
|
|
|
|
* @param object aResponse
|
2012-09-26 10:02:04 -07:00
|
|
|
|
* The JavaScript evaluation response received from the server.
|
2012-07-26 08:06:04 -07:00
|
|
|
|
*/
|
2013-04-09 02:46:30 -07:00
|
|
|
|
_evalOutputClick: function JST__evalOutputClick(aResponse)
|
2012-07-26 08:06:04 -07:00
|
|
|
|
{
|
2013-04-09 02:46:30 -07:00
|
|
|
|
this.openVariablesView({
|
|
|
|
|
label: VariablesView.getString(aResponse.result),
|
|
|
|
|
objectActor: aResponse.result,
|
2013-05-02 04:53:11 -07:00
|
|
|
|
autofocus: true,
|
2013-04-09 02:46:30 -07:00
|
|
|
|
});
|
2012-07-26 08:06:04 -07:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
2013-05-02 04:53:11 -07:00
|
|
|
|
* Destroy the sidebar.
|
|
|
|
|
* @private
|
2013-04-09 02:46:30 -07:00
|
|
|
|
*/
|
2013-05-02 04:53:11 -07:00
|
|
|
|
_sidebarDestroy: function JST__sidebarDestroy()
|
2013-04-09 02:46:30 -07:00
|
|
|
|
{
|
|
|
|
|
if (this._variablesView) {
|
2013-06-14 10:42:52 -07:00
|
|
|
|
this._variablesView.controller.releaseActors();
|
2013-04-09 02:46:30 -07:00
|
|
|
|
this._variablesView = null;
|
2012-09-26 10:02:04 -07:00
|
|
|
|
}
|
2012-07-26 08:06:04 -07:00
|
|
|
|
|
2013-04-09 02:46:30 -07:00
|
|
|
|
if (this.sidebar) {
|
2013-05-02 04:53:11 -07:00
|
|
|
|
this.sidebar.hide();
|
2013-04-09 02:46:30 -07:00
|
|
|
|
this.sidebar.destroy();
|
|
|
|
|
this.sidebar = null;
|
2012-07-26 08:06:04 -07:00
|
|
|
|
}
|
|
|
|
|
|
2013-05-02 04:53:11 -07:00
|
|
|
|
this.emit("sidebar-closed");
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Destroy the JSTerm object. Call this method to avoid memory leaks.
|
|
|
|
|
*/
|
|
|
|
|
destroy: function JST_destroy()
|
|
|
|
|
{
|
|
|
|
|
this._sidebarDestroy();
|
|
|
|
|
|
2012-07-26 08:06:04 -07:00
|
|
|
|
this.clearCompletion();
|
|
|
|
|
this.clearOutput();
|
|
|
|
|
|
|
|
|
|
this.autocompletePopup.destroy();
|
2012-10-05 09:15:51 -07:00
|
|
|
|
this.autocompletePopup = null;
|
2012-07-26 08:06:04 -07:00
|
|
|
|
|
2013-04-09 02:47:23 -07:00
|
|
|
|
let popup = this.hud.owner.chromeWindow.document
|
2013-01-11 09:31:09 -08:00
|
|
|
|
.getElementById("webConsole_autocompletePopup");
|
|
|
|
|
if (popup) {
|
|
|
|
|
popup.parentNode.removeChild(popup);
|
|
|
|
|
}
|
|
|
|
|
|
2012-07-26 08:06:04 -07:00
|
|
|
|
this.inputNode.removeEventListener("keypress", this._keyPress, false);
|
|
|
|
|
this.inputNode.removeEventListener("input", this._inputEventHandler, false);
|
|
|
|
|
this.inputNode.removeEventListener("keyup", this._inputEventHandler, false);
|
2013-06-17 04:10:46 -07:00
|
|
|
|
this.inputNode.removeEventListener("focus", this._focusEventHandler, false);
|
2012-10-05 09:15:51 -07:00
|
|
|
|
|
|
|
|
|
this.hud = null;
|
2012-07-26 08:06:04 -07:00
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Utils: a collection of globally used functions.
|
|
|
|
|
*/
|
|
|
|
|
var Utils = {
|
|
|
|
|
/**
|
2013-09-13 05:06:46 -07:00
|
|
|
|
* Scrolls a node so that it's visible in its containing element.
|
2012-07-26 08:06:04 -07:00
|
|
|
|
*
|
|
|
|
|
* @param nsIDOMNode aNode
|
|
|
|
|
* The node to make visible.
|
|
|
|
|
* @returns void
|
|
|
|
|
*/
|
|
|
|
|
scrollToVisible: function Utils_scrollToVisible(aNode)
|
|
|
|
|
{
|
2013-09-13 05:06:46 -07:00
|
|
|
|
aNode.scrollIntoView(false);
|
2012-07-26 08:06:04 -07:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Check if the given output node is scrolled to the bottom.
|
|
|
|
|
*
|
|
|
|
|
* @param nsIDOMNode aOutputNode
|
|
|
|
|
* @return boolean
|
|
|
|
|
* True if the output node is scrolled to the bottom, or false
|
|
|
|
|
* otherwise.
|
|
|
|
|
*/
|
|
|
|
|
isOutputScrolledToBottom: function Utils_isOutputScrolledToBottom(aOutputNode)
|
|
|
|
|
{
|
|
|
|
|
let lastNodeHeight = aOutputNode.lastChild ?
|
|
|
|
|
aOutputNode.lastChild.clientHeight : 0;
|
2013-09-13 05:06:46 -07:00
|
|
|
|
let scrollNode = aOutputNode.parentNode;
|
|
|
|
|
return scrollNode.scrollTop + scrollNode.clientHeight >=
|
|
|
|
|
scrollNode.scrollHeight - lastNodeHeight / 2;
|
2012-07-26 08:06:04 -07:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
2013-05-17 14:30:20 -07:00
|
|
|
|
* Determine the category of a given nsIScriptError.
|
2012-07-26 08:06:04 -07:00
|
|
|
|
*
|
2013-05-17 14:30:20 -07:00
|
|
|
|
* @param nsIScriptError aScriptError
|
|
|
|
|
* The script error you want to determine the category for.
|
2013-04-22 18:07:36 -07:00
|
|
|
|
* @return CATEGORY_JS|CATEGORY_CSS|CATEGORY_SECURITY
|
2013-05-17 14:30:20 -07:00
|
|
|
|
* Depending on the script error CATEGORY_JS, CATEGORY_CSS, or
|
2013-04-22 18:07:36 -07:00
|
|
|
|
* CATEGORY_SECURITY can be returned.
|
2012-07-26 08:06:04 -07:00
|
|
|
|
*/
|
2013-05-17 14:30:20 -07:00
|
|
|
|
categoryForScriptError: function Utils_categoryForScriptError(aScriptError)
|
2012-07-26 08:06:04 -07:00
|
|
|
|
{
|
2013-05-17 14:30:20 -07:00
|
|
|
|
switch (aScriptError.category) {
|
2012-07-26 08:06:04 -07:00
|
|
|
|
case "CSS Parser":
|
|
|
|
|
case "CSS Loader":
|
|
|
|
|
return CATEGORY_CSS;
|
|
|
|
|
|
2013-04-22 18:07:36 -07:00
|
|
|
|
case "Mixed Content Blocker":
|
2013-08-26 08:26:43 -07:00
|
|
|
|
case "Mixed Content Message":
|
2013-04-23 15:39:10 -07:00
|
|
|
|
case "CSP":
|
2013-07-26 08:36:50 -07:00
|
|
|
|
case "Invalid HSTS Headers":
|
2013-08-06 07:14:51 -07:00
|
|
|
|
case "Insecure Password Field":
|
2013-09-26 11:07:29 -07:00
|
|
|
|
case "SSL":
|
2013-04-22 18:07:36 -07:00
|
|
|
|
return CATEGORY_SECURITY;
|
|
|
|
|
|
2012-07-26 08:06:04 -07:00
|
|
|
|
default:
|
|
|
|
|
return CATEGORY_JS;
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Retrieve the limit of messages for a specific category.
|
|
|
|
|
*
|
|
|
|
|
* @param number aCategory
|
|
|
|
|
* The category of messages you want to retrieve the limit for. See the
|
|
|
|
|
* CATEGORY_* constants.
|
|
|
|
|
* @return number
|
|
|
|
|
* The number of messages allowed for the specific category.
|
|
|
|
|
*/
|
|
|
|
|
logLimitForCategory: function Utils_logLimitForCategory(aCategory)
|
|
|
|
|
{
|
|
|
|
|
let logLimit = DEFAULT_LOG_LIMIT;
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
let prefName = CATEGORY_CLASS_FRAGMENTS[aCategory];
|
|
|
|
|
logLimit = Services.prefs.getIntPref("devtools.hud.loglimit." + prefName);
|
|
|
|
|
logLimit = Math.max(logLimit, 1);
|
|
|
|
|
}
|
|
|
|
|
catch (e) { }
|
|
|
|
|
|
|
|
|
|
return logLimit;
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
// CommandController
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* A controller (an instance of nsIController) that makes editing actions
|
|
|
|
|
* behave appropriately in the context of the Web Console.
|
|
|
|
|
*/
|
|
|
|
|
function CommandController(aWebConsole)
|
|
|
|
|
{
|
|
|
|
|
this.owner = aWebConsole;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CommandController.prototype = {
|
|
|
|
|
/**
|
|
|
|
|
* Selects all the text in the HUD output.
|
|
|
|
|
*/
|
|
|
|
|
selectAll: function CommandController_selectAll()
|
|
|
|
|
{
|
2013-09-13 05:06:46 -07:00
|
|
|
|
this.owner.output.selectAllMessages();
|
2012-07-26 08:06:04 -07:00
|
|
|
|
},
|
|
|
|
|
|
2012-09-18 09:08:29 -07:00
|
|
|
|
/**
|
|
|
|
|
* Open the URL of the selected message in a new tab.
|
|
|
|
|
*/
|
|
|
|
|
openURL: function CommandController_openURL()
|
|
|
|
|
{
|
|
|
|
|
this.owner.openSelectedItemInTab();
|
|
|
|
|
},
|
|
|
|
|
|
2012-09-19 14:38:30 -07:00
|
|
|
|
copyURL: function CommandController_copyURL()
|
|
|
|
|
{
|
2013-09-13 05:06:46 -07:00
|
|
|
|
this.owner.copySelectedItems({ linkOnly: true, contextmenu: true });
|
2012-09-19 14:38:30 -07:00
|
|
|
|
},
|
|
|
|
|
|
2012-07-26 08:06:04 -07:00
|
|
|
|
supportsCommand: function CommandController_supportsCommand(aCommand)
|
|
|
|
|
{
|
2013-09-13 05:06:46 -07:00
|
|
|
|
if (!this.owner || !this.owner.output) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2012-07-26 08:06:04 -07:00
|
|
|
|
return this.isCommandEnabled(aCommand);
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
isCommandEnabled: function CommandController_isCommandEnabled(aCommand)
|
|
|
|
|
{
|
|
|
|
|
switch (aCommand) {
|
2012-09-19 14:38:30 -07:00
|
|
|
|
case "consoleCmd_openURL":
|
|
|
|
|
case "consoleCmd_copyURL": {
|
|
|
|
|
// Only enable URL-related actions if node is Net Activity.
|
2013-09-13 05:06:46 -07:00
|
|
|
|
let selectedItem = this.owner.output.getSelectedMessages(1)[0] ||
|
|
|
|
|
this.owner._contextMenuHandler.lastClickedMessage;
|
2013-05-08 11:54:57 -07:00
|
|
|
|
return selectedItem && "url" in selectedItem;
|
2012-09-18 09:08:29 -07:00
|
|
|
|
}
|
2013-06-21 09:01:02 -07:00
|
|
|
|
case "consoleCmd_clearOutput":
|
2012-07-26 08:06:04 -07:00
|
|
|
|
case "cmd_selectAll":
|
2013-06-21 09:01:02 -07:00
|
|
|
|
case "cmd_find":
|
2012-07-26 08:06:04 -07:00
|
|
|
|
return true;
|
2013-09-15 02:12:27 -07:00
|
|
|
|
case "cmd_fontSizeEnlarge":
|
|
|
|
|
case "cmd_fontSizeReduce":
|
|
|
|
|
case "cmd_fontSizeReset":
|
2013-04-09 02:47:23 -07:00
|
|
|
|
case "cmd_close":
|
|
|
|
|
return this.owner.owner._browserConsole;
|
2012-07-26 08:06:04 -07:00
|
|
|
|
}
|
2013-05-08 11:54:57 -07:00
|
|
|
|
return false;
|
2012-07-26 08:06:04 -07:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
doCommand: function CommandController_doCommand(aCommand)
|
|
|
|
|
{
|
|
|
|
|
switch (aCommand) {
|
2012-09-18 09:08:29 -07:00
|
|
|
|
case "consoleCmd_openURL":
|
|
|
|
|
this.openURL();
|
|
|
|
|
break;
|
2012-09-19 14:38:30 -07:00
|
|
|
|
case "consoleCmd_copyURL":
|
|
|
|
|
this.copyURL();
|
|
|
|
|
break;
|
2013-06-21 09:01:02 -07:00
|
|
|
|
case "consoleCmd_clearOutput":
|
|
|
|
|
this.owner.jsterm.clearOutput(true);
|
|
|
|
|
break;
|
|
|
|
|
case "cmd_find":
|
|
|
|
|
this.owner.filterBox.focus();
|
|
|
|
|
break;
|
2012-07-26 08:06:04 -07:00
|
|
|
|
case "cmd_selectAll":
|
|
|
|
|
this.selectAll();
|
|
|
|
|
break;
|
2012-08-22 13:18:48 -07:00
|
|
|
|
case "cmd_fontSizeEnlarge":
|
|
|
|
|
this.owner.changeFontSize("+");
|
|
|
|
|
break;
|
|
|
|
|
case "cmd_fontSizeReduce":
|
|
|
|
|
this.owner.changeFontSize("-");
|
|
|
|
|
break;
|
|
|
|
|
case "cmd_fontSizeReset":
|
|
|
|
|
this.owner.changeFontSize("");
|
|
|
|
|
break;
|
2013-04-09 02:47:23 -07:00
|
|
|
|
case "cmd_close":
|
|
|
|
|
this.owner.window.close();
|
|
|
|
|
break;
|
2012-07-26 08:06:04 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2012-09-26 10:07:57 -07:00
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
// Web Console connection proxy
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The WebConsoleConnectionProxy handles the connection between the Web Console
|
|
|
|
|
* and the application we connect to through the remote debug protocol.
|
|
|
|
|
*
|
|
|
|
|
* @constructor
|
|
|
|
|
* @param object aWebConsole
|
|
|
|
|
* The Web Console instance that owns this connection proxy.
|
2012-11-30 00:07:59 -08:00
|
|
|
|
* @param RemoteTarget aTarget
|
|
|
|
|
* The target that the console will connect to.
|
2012-09-26 10:07:57 -07:00
|
|
|
|
*/
|
2012-11-30 00:07:59 -08:00
|
|
|
|
function WebConsoleConnectionProxy(aWebConsole, aTarget)
|
2012-09-26 10:07:57 -07:00
|
|
|
|
{
|
|
|
|
|
this.owner = aWebConsole;
|
2012-11-30 00:07:59 -08:00
|
|
|
|
this.target = aTarget;
|
2012-09-26 10:07:57 -07:00
|
|
|
|
|
|
|
|
|
this._onPageError = this._onPageError.bind(this);
|
2013-05-28 08:24:31 -07:00
|
|
|
|
this._onLogMessage = this._onLogMessage.bind(this);
|
2012-09-26 10:02:04 -07:00
|
|
|
|
this._onConsoleAPICall = this._onConsoleAPICall.bind(this);
|
2012-10-05 04:54:43 -07:00
|
|
|
|
this._onNetworkEvent = this._onNetworkEvent.bind(this);
|
|
|
|
|
this._onNetworkEventUpdate = this._onNetworkEventUpdate.bind(this);
|
|
|
|
|
this._onFileActivity = this._onFileActivity.bind(this);
|
2012-12-17 12:06:13 -08:00
|
|
|
|
this._onTabNavigated = this._onTabNavigated.bind(this);
|
2013-01-11 09:31:09 -08:00
|
|
|
|
this._onAttachConsole = this._onAttachConsole.bind(this);
|
|
|
|
|
this._onCachedMessages = this._onCachedMessages.bind(this);
|
|
|
|
|
this._connectionTimeout = this._connectionTimeout.bind(this);
|
2013-05-25 02:25:36 -07:00
|
|
|
|
this._onLastPrivateContextExited = this._onLastPrivateContextExited.bind(this);
|
2012-09-26 10:07:57 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WebConsoleConnectionProxy.prototype = {
|
|
|
|
|
/**
|
|
|
|
|
* The owning Web Console instance.
|
|
|
|
|
*
|
|
|
|
|
* @see WebConsoleFrame
|
|
|
|
|
* @type object
|
|
|
|
|
*/
|
|
|
|
|
owner: null,
|
|
|
|
|
|
2012-12-17 12:06:13 -08:00
|
|
|
|
/**
|
|
|
|
|
* The target that the console connects to.
|
|
|
|
|
* @type RemoteTarget
|
|
|
|
|
*/
|
|
|
|
|
target: null,
|
|
|
|
|
|
2012-09-26 10:07:57 -07:00
|
|
|
|
/**
|
|
|
|
|
* The DebuggerClient object.
|
|
|
|
|
*
|
|
|
|
|
* @see DebuggerClient
|
|
|
|
|
* @type object
|
|
|
|
|
*/
|
|
|
|
|
client: null,
|
|
|
|
|
|
2012-10-05 09:15:51 -07:00
|
|
|
|
/**
|
|
|
|
|
* The WebConsoleClient object.
|
|
|
|
|
*
|
|
|
|
|
* @see WebConsoleClient
|
|
|
|
|
* @type object
|
|
|
|
|
*/
|
|
|
|
|
webConsoleClient: null,
|
|
|
|
|
|
2012-09-26 10:07:57 -07:00
|
|
|
|
/**
|
|
|
|
|
* Tells if the connection is established.
|
|
|
|
|
* @type boolean
|
|
|
|
|
*/
|
|
|
|
|
connected: false,
|
|
|
|
|
|
2013-01-11 09:31:09 -08:00
|
|
|
|
/**
|
|
|
|
|
* Timer used for the connection.
|
|
|
|
|
* @private
|
|
|
|
|
* @type object
|
|
|
|
|
*/
|
|
|
|
|
_connectTimer: null,
|
|
|
|
|
|
|
|
|
|
_connectDefer: null,
|
|
|
|
|
_disconnecter: null,
|
|
|
|
|
|
2012-09-26 10:07:57 -07:00
|
|
|
|
/**
|
|
|
|
|
* The WebConsoleActor ID.
|
|
|
|
|
*
|
|
|
|
|
* @private
|
|
|
|
|
* @type string
|
|
|
|
|
*/
|
|
|
|
|
_consoleActor: null,
|
|
|
|
|
|
2012-09-26 10:02:04 -07:00
|
|
|
|
/**
|
|
|
|
|
* Tells if the window.console object of the remote web page is the native
|
|
|
|
|
* object or not.
|
|
|
|
|
* @private
|
|
|
|
|
* @type boolean
|
|
|
|
|
*/
|
|
|
|
|
_hasNativeConsoleAPI: false,
|
|
|
|
|
|
2012-09-26 10:07:57 -07:00
|
|
|
|
/**
|
|
|
|
|
* Initialize a debugger client and connect it to the debugger server.
|
|
|
|
|
*
|
2013-01-11 09:31:09 -08:00
|
|
|
|
* @return object
|
2013-07-11 00:12:20 -07:00
|
|
|
|
* A promise object that is resolved/rejected based on the success of
|
2013-01-11 09:31:09 -08:00
|
|
|
|
* the connection initialization.
|
2012-09-26 10:07:57 -07:00
|
|
|
|
*/
|
2013-01-11 09:31:09 -08:00
|
|
|
|
connect: function WCCP_connect()
|
2012-09-26 10:07:57 -07:00
|
|
|
|
{
|
2013-01-11 09:31:09 -08:00
|
|
|
|
if (this._connectDefer) {
|
|
|
|
|
return this._connectDefer.promise;
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-11 00:12:20 -07:00
|
|
|
|
this._connectDefer = promise.defer();
|
2013-01-11 09:31:09 -08:00
|
|
|
|
|
|
|
|
|
let timeout = Services.prefs.getIntPref(PREF_CONNECTION_TIMEOUT);
|
|
|
|
|
this._connectTimer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
|
|
|
|
|
this._connectTimer.initWithCallback(this._connectionTimeout,
|
|
|
|
|
timeout, Ci.nsITimer.TYPE_ONE_SHOT);
|
|
|
|
|
|
2013-07-11 00:12:20 -07:00
|
|
|
|
let connPromise = this._connectDefer.promise;
|
|
|
|
|
connPromise.then(function _onSucess() {
|
2013-01-11 09:31:09 -08:00
|
|
|
|
this._connectTimer.cancel();
|
|
|
|
|
this._connectTimer = null;
|
|
|
|
|
}.bind(this), function _onFailure() {
|
|
|
|
|
this._connectTimer = null;
|
|
|
|
|
}.bind(this));
|
|
|
|
|
|
2013-03-06 23:30:03 -08:00
|
|
|
|
let client = this.client = this.target.client;
|
2012-09-26 10:07:57 -07:00
|
|
|
|
|
2013-05-28 08:24:31 -07:00
|
|
|
|
client.addListener("logMessage", this._onLogMessage);
|
2012-09-26 10:07:57 -07:00
|
|
|
|
client.addListener("pageError", this._onPageError);
|
2012-09-26 10:02:04 -07:00
|
|
|
|
client.addListener("consoleAPICall", this._onConsoleAPICall);
|
2012-10-05 04:54:43 -07:00
|
|
|
|
client.addListener("networkEvent", this._onNetworkEvent);
|
|
|
|
|
client.addListener("networkEventUpdate", this._onNetworkEventUpdate);
|
|
|
|
|
client.addListener("fileActivity", this._onFileActivity);
|
2013-05-25 02:25:36 -07:00
|
|
|
|
client.addListener("lastPrivateContextExited", this._onLastPrivateContextExited);
|
2013-04-10 21:55:14 -07:00
|
|
|
|
this.target.on("will-navigate", this._onTabNavigated);
|
|
|
|
|
this.target.on("navigate", this._onTabNavigated);
|
2012-09-26 10:07:57 -07:00
|
|
|
|
|
2013-04-10 21:55:14 -07:00
|
|
|
|
this._consoleActor = this.target.form.consoleActor;
|
2013-03-06 23:30:03 -08:00
|
|
|
|
if (!this.target.chrome) {
|
2013-04-10 21:55:14 -07:00
|
|
|
|
let tab = this.target.form;
|
|
|
|
|
this.owner.onLocationChange(tab.url, tab.title);
|
2012-12-17 12:06:13 -08:00
|
|
|
|
}
|
2013-04-10 21:55:14 -07:00
|
|
|
|
this._attachConsole();
|
2013-01-11 09:31:09 -08:00
|
|
|
|
|
2013-07-11 00:12:20 -07:00
|
|
|
|
return connPromise;
|
2013-01-11 09:31:09 -08:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Connection timeout handler.
|
|
|
|
|
* @private
|
|
|
|
|
*/
|
|
|
|
|
_connectionTimeout: function WCCP__connectionTimeout()
|
|
|
|
|
{
|
|
|
|
|
let error = {
|
|
|
|
|
error: "timeout",
|
|
|
|
|
message: l10n.getStr("connectionTimeout"),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
this._connectDefer.reject(error);
|
2012-09-26 10:07:57 -07:00
|
|
|
|
},
|
|
|
|
|
|
2012-12-17 12:06:13 -08:00
|
|
|
|
/**
|
|
|
|
|
* Attach to the Web Console actor.
|
|
|
|
|
* @private
|
|
|
|
|
*/
|
2013-01-11 09:31:09 -08:00
|
|
|
|
_attachConsole: function WCCP__attachConsole()
|
2012-12-17 12:06:13 -08:00
|
|
|
|
{
|
2012-10-11 11:24:57 -07:00
|
|
|
|
let listeners = ["PageError", "ConsoleAPI", "NetworkActivity",
|
2012-12-17 12:06:13 -08:00
|
|
|
|
"FileActivity"];
|
2012-10-11 11:24:57 -07:00
|
|
|
|
this.client.attachConsole(this._consoleActor, listeners,
|
2013-01-11 09:31:09 -08:00
|
|
|
|
this._onAttachConsole);
|
2012-10-11 11:24:57 -07:00
|
|
|
|
},
|
|
|
|
|
|
2012-09-26 10:07:57 -07:00
|
|
|
|
/**
|
|
|
|
|
* The "attachConsole" response handler.
|
|
|
|
|
*
|
|
|
|
|
* @private
|
|
|
|
|
* @param object aResponse
|
|
|
|
|
* The JSON response object received from the server.
|
|
|
|
|
* @param object aWebConsoleClient
|
|
|
|
|
* The WebConsoleClient instance for the attached console, for the
|
|
|
|
|
* specific tab we work with.
|
|
|
|
|
*/
|
2013-01-11 09:31:09 -08:00
|
|
|
|
_onAttachConsole: function WCCP__onAttachConsole(aResponse, aWebConsoleClient)
|
2012-09-26 10:07:57 -07:00
|
|
|
|
{
|
|
|
|
|
if (aResponse.error) {
|
|
|
|
|
Cu.reportError("attachConsole failed: " + aResponse.error + " " +
|
|
|
|
|
aResponse.message);
|
2013-01-11 09:31:09 -08:00
|
|
|
|
this._connectDefer.reject(aResponse);
|
2012-09-26 10:07:57 -07:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.webConsoleClient = aWebConsoleClient;
|
|
|
|
|
|
2012-09-26 10:02:04 -07:00
|
|
|
|
this._hasNativeConsoleAPI = aResponse.nativeConsoleAPI;
|
|
|
|
|
|
|
|
|
|
let msgs = ["PageError", "ConsoleAPI"];
|
2013-01-11 09:31:09 -08:00
|
|
|
|
this.webConsoleClient.getCachedMessages(msgs, this._onCachedMessages);
|
2012-09-26 10:02:04 -07:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The "cachedMessages" response handler.
|
|
|
|
|
*
|
|
|
|
|
* @private
|
|
|
|
|
* @param object aResponse
|
|
|
|
|
* The JSON response object received from the server.
|
|
|
|
|
*/
|
2013-01-11 09:31:09 -08:00
|
|
|
|
_onCachedMessages: function WCCP__onCachedMessages(aResponse)
|
2012-09-26 10:02:04 -07:00
|
|
|
|
{
|
|
|
|
|
if (aResponse.error) {
|
|
|
|
|
Cu.reportError("Web Console getCachedMessages error: " + aResponse.error +
|
|
|
|
|
" " + aResponse.message);
|
2013-01-11 09:31:09 -08:00
|
|
|
|
this._connectDefer.reject(aResponse);
|
2012-09-26 10:02:04 -07:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2013-01-11 09:31:09 -08:00
|
|
|
|
if (!this._connectTimer) {
|
2013-07-11 00:12:20 -07:00
|
|
|
|
// This happens if the promise is rejected (eg. a timeout), but the
|
2013-01-11 09:31:09 -08:00
|
|
|
|
// connection attempt is successful, nonetheless.
|
|
|
|
|
Cu.reportError("Web Console getCachedMessages error: invalid state.");
|
|
|
|
|
}
|
|
|
|
|
|
2012-09-26 10:02:04 -07:00
|
|
|
|
this.owner.displayCachedMessages(aResponse.messages);
|
|
|
|
|
|
|
|
|
|
if (!this._hasNativeConsoleAPI) {
|
|
|
|
|
this.owner.logWarningAboutReplacedAPI();
|
|
|
|
|
}
|
|
|
|
|
|
2012-09-26 10:07:57 -07:00
|
|
|
|
this.connected = true;
|
2013-01-11 09:31:09 -08:00
|
|
|
|
this._connectDefer.resolve(this);
|
2012-09-26 10:07:57 -07:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The "pageError" message type handler. We redirect any page errors to the UI
|
|
|
|
|
* for displaying.
|
|
|
|
|
*
|
|
|
|
|
* @private
|
|
|
|
|
* @param string aType
|
|
|
|
|
* Message type.
|
|
|
|
|
* @param object aPacket
|
|
|
|
|
* The message received from the server.
|
|
|
|
|
*/
|
|
|
|
|
_onPageError: function WCCP__onPageError(aType, aPacket)
|
|
|
|
|
{
|
|
|
|
|
if (this.owner && aPacket.from == this._consoleActor) {
|
|
|
|
|
this.owner.handlePageError(aPacket.pageError);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
2013-05-28 08:24:31 -07:00
|
|
|
|
/**
|
|
|
|
|
* The "logMessage" message type handler. We redirect any message to the UI
|
|
|
|
|
* for displaying.
|
|
|
|
|
*
|
|
|
|
|
* @private
|
|
|
|
|
* @param string aType
|
|
|
|
|
* Message type.
|
|
|
|
|
* @param object aPacket
|
|
|
|
|
* The message received from the server.
|
|
|
|
|
*/
|
|
|
|
|
_onLogMessage: function WCCP__onLogMessage(aType, aPacket)
|
|
|
|
|
{
|
|
|
|
|
if (this.owner && aPacket.from == this._consoleActor) {
|
|
|
|
|
this.owner.handleLogMessage(aPacket);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
2012-09-26 10:02:04 -07:00
|
|
|
|
/**
|
|
|
|
|
* The "consoleAPICall" message type handler. We redirect any message to
|
|
|
|
|
* the UI for displaying.
|
|
|
|
|
*
|
|
|
|
|
* @private
|
|
|
|
|
* @param string aType
|
|
|
|
|
* Message type.
|
|
|
|
|
* @param object aPacket
|
|
|
|
|
* The message received from the server.
|
|
|
|
|
*/
|
|
|
|
|
_onConsoleAPICall: function WCCP__onConsoleAPICall(aType, aPacket)
|
|
|
|
|
{
|
|
|
|
|
if (this.owner && aPacket.from == this._consoleActor) {
|
|
|
|
|
this.owner.handleConsoleAPICall(aPacket.message);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
2012-10-05 04:54:43 -07:00
|
|
|
|
/**
|
|
|
|
|
* The "networkEvent" message type handler. We redirect any message to
|
|
|
|
|
* the UI for displaying.
|
|
|
|
|
*
|
|
|
|
|
* @private
|
|
|
|
|
* @param string aType
|
|
|
|
|
* Message type.
|
|
|
|
|
* @param object aPacket
|
|
|
|
|
* The message received from the server.
|
|
|
|
|
*/
|
|
|
|
|
_onNetworkEvent: function WCCP__onNetworkEvent(aType, aPacket)
|
|
|
|
|
{
|
|
|
|
|
if (this.owner && aPacket.from == this._consoleActor) {
|
|
|
|
|
this.owner.handleNetworkEvent(aPacket.eventActor);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The "networkEventUpdate" message type handler. We redirect any message to
|
|
|
|
|
* the UI for displaying.
|
|
|
|
|
*
|
|
|
|
|
* @private
|
|
|
|
|
* @param string aType
|
|
|
|
|
* Message type.
|
|
|
|
|
* @param object aPacket
|
|
|
|
|
* The message received from the server.
|
|
|
|
|
*/
|
|
|
|
|
_onNetworkEventUpdate: function WCCP__onNetworkEvenUpdatet(aType, aPacket)
|
|
|
|
|
{
|
|
|
|
|
if (this.owner) {
|
|
|
|
|
this.owner.handleNetworkEventUpdate(aPacket.from, aPacket.updateType,
|
|
|
|
|
aPacket);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The "fileActivity" message type handler. We redirect any message to
|
|
|
|
|
* the UI for displaying.
|
|
|
|
|
*
|
|
|
|
|
* @private
|
|
|
|
|
* @param string aType
|
|
|
|
|
* Message type.
|
|
|
|
|
* @param object aPacket
|
|
|
|
|
* The message received from the server.
|
|
|
|
|
*/
|
|
|
|
|
_onFileActivity: function WCCP__onFileActivity(aType, aPacket)
|
|
|
|
|
{
|
|
|
|
|
if (this.owner && aPacket.from == this._consoleActor) {
|
|
|
|
|
this.owner.handleFileActivity(aPacket.uri);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
2013-05-25 02:25:36 -07:00
|
|
|
|
/**
|
|
|
|
|
* The "lastPrivateContextExited" message type handler. When this message is
|
|
|
|
|
* received the Web Console UI is cleared.
|
|
|
|
|
*
|
|
|
|
|
* @private
|
|
|
|
|
* @param string aType
|
|
|
|
|
* Message type.
|
|
|
|
|
* @param object aPacket
|
|
|
|
|
* The message received from the server.
|
|
|
|
|
*/
|
|
|
|
|
_onLastPrivateContextExited:
|
|
|
|
|
function WCCP__onLastPrivateContextExited(aType, aPacket)
|
|
|
|
|
{
|
|
|
|
|
if (this.owner && aPacket.from == this._consoleActor) {
|
|
|
|
|
this.owner.jsterm.clearPrivateMessages();
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
2012-10-05 04:54:43 -07:00
|
|
|
|
/**
|
2013-04-17 03:19:29 -07:00
|
|
|
|
* The "will-navigate" and "navigate" event handlers. We redirect any message
|
|
|
|
|
* to the UI for displaying.
|
2012-10-05 04:54:43 -07:00
|
|
|
|
*
|
|
|
|
|
* @private
|
2013-04-17 03:19:29 -07:00
|
|
|
|
* @param string aEvent
|
|
|
|
|
* Event type.
|
2012-10-05 04:54:43 -07:00
|
|
|
|
* @param object aPacket
|
|
|
|
|
* The message received from the server.
|
|
|
|
|
*/
|
2013-04-17 03:19:29 -07:00
|
|
|
|
_onTabNavigated: function WCCP__onTabNavigated(aEvent, aPacket)
|
2012-10-05 04:54:43 -07:00
|
|
|
|
{
|
2013-04-10 21:55:14 -07:00
|
|
|
|
if (!this.owner) {
|
2012-10-05 04:54:43 -07:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-02 10:19:23 -07:00
|
|
|
|
this.owner.handleTabNavigated(aEvent, aPacket);
|
2012-10-05 04:54:43 -07:00
|
|
|
|
},
|
|
|
|
|
|
2012-09-26 10:02:04 -07:00
|
|
|
|
/**
|
|
|
|
|
* Release an object actor.
|
|
|
|
|
*
|
|
|
|
|
* @param string aActor
|
|
|
|
|
* The actor ID to send the request to.
|
|
|
|
|
*/
|
|
|
|
|
releaseActor: function WCCP_releaseActor(aActor)
|
|
|
|
|
{
|
|
|
|
|
if (this.client) {
|
|
|
|
|
this.client.release(aActor);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
2012-09-26 10:07:57 -07:00
|
|
|
|
/**
|
|
|
|
|
* Disconnect the Web Console from the remote server.
|
|
|
|
|
*
|
2013-01-11 09:31:09 -08:00
|
|
|
|
* @return object
|
2013-07-11 00:12:20 -07:00
|
|
|
|
* A promise object that is resolved when disconnect completes.
|
2012-09-26 10:07:57 -07:00
|
|
|
|
*/
|
2013-01-11 09:31:09 -08:00
|
|
|
|
disconnect: function WCCP_disconnect()
|
2012-09-26 10:07:57 -07:00
|
|
|
|
{
|
2013-01-11 09:31:09 -08:00
|
|
|
|
if (this._disconnecter) {
|
|
|
|
|
return this._disconnecter.promise;
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-11 00:12:20 -07:00
|
|
|
|
this._disconnecter = promise.defer();
|
2013-01-11 09:31:09 -08:00
|
|
|
|
|
2012-09-26 10:07:57 -07:00
|
|
|
|
if (!this.client) {
|
2013-01-11 09:31:09 -08:00
|
|
|
|
this._disconnecter.resolve(null);
|
|
|
|
|
return this._disconnecter.promise;
|
2012-09-26 10:07:57 -07:00
|
|
|
|
}
|
|
|
|
|
|
2013-05-28 08:24:31 -07:00
|
|
|
|
this.client.removeListener("logMessage", this._onLogMessage);
|
2012-09-26 10:07:57 -07:00
|
|
|
|
this.client.removeListener("pageError", this._onPageError);
|
2012-09-26 10:02:04 -07:00
|
|
|
|
this.client.removeListener("consoleAPICall", this._onConsoleAPICall);
|
2012-10-05 04:54:43 -07:00
|
|
|
|
this.client.removeListener("networkEvent", this._onNetworkEvent);
|
|
|
|
|
this.client.removeListener("networkEventUpdate", this._onNetworkEventUpdate);
|
|
|
|
|
this.client.removeListener("fileActivity", this._onFileActivity);
|
2013-05-25 02:25:36 -07:00
|
|
|
|
this.client.removeListener("lastPrivateContextExited", this._onLastPrivateContextExited);
|
2013-04-17 03:19:29 -07:00
|
|
|
|
this.target.off("will-navigate", this._onTabNavigated);
|
|
|
|
|
this.target.off("navigate", this._onTabNavigated);
|
2012-12-17 12:06:13 -08:00
|
|
|
|
|
|
|
|
|
this.client = null;
|
|
|
|
|
this.webConsoleClient = null;
|
|
|
|
|
this.target = null;
|
|
|
|
|
this.connected = false;
|
|
|
|
|
this.owner = null;
|
2013-03-06 23:30:03 -08:00
|
|
|
|
this._disconnecter.resolve(null);
|
2012-09-26 10:07:57 -07:00
|
|
|
|
|
2013-01-11 09:31:09 -08:00
|
|
|
|
return this._disconnecter.promise;
|
2012-09-26 10:07:57 -07:00
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
|
2012-07-26 08:06:04 -07:00
|
|
|
|
function gSequenceId()
|
|
|
|
|
{
|
|
|
|
|
return gSequenceId.n++;
|
|
|
|
|
}
|
|
|
|
|
gSequenceId.n = 0;
|
|
|
|
|
|
2012-09-18 09:08:29 -07:00
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
// Context Menu
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
/*
|
2013-08-02 10:11:57 -07:00
|
|
|
|
* ConsoleContextMenu this used to handle the visibility of context menu items.
|
|
|
|
|
*
|
|
|
|
|
* @constructor
|
|
|
|
|
* @param object aOwner
|
|
|
|
|
* The WebConsoleFrame instance that owns this object.
|
2012-09-18 09:08:29 -07:00
|
|
|
|
*/
|
2013-08-02 10:11:57 -07:00
|
|
|
|
function ConsoleContextMenu(aOwner)
|
|
|
|
|
{
|
|
|
|
|
this.owner = aOwner;
|
|
|
|
|
this.popup = this.owner.document.getElementById("output-contextmenu");
|
|
|
|
|
this.build = this.build.bind(this);
|
|
|
|
|
this.popup.addEventListener("popupshowing", this.build);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ConsoleContextMenu.prototype = {
|
2013-09-13 05:06:46 -07:00
|
|
|
|
lastClickedMessage: null,
|
|
|
|
|
|
2012-09-18 09:08:29 -07:00
|
|
|
|
/*
|
|
|
|
|
* Handle to show/hide context menu item.
|
|
|
|
|
*/
|
|
|
|
|
build: function CCM_build(aEvent)
|
|
|
|
|
{
|
2013-09-13 05:06:46 -07:00
|
|
|
|
let metadata = this.getSelectionMetadata(aEvent.rangeParent);
|
2013-08-02 10:11:57 -07:00
|
|
|
|
for (let element of this.popup.children) {
|
2012-09-18 09:08:29 -07:00
|
|
|
|
element.hidden = this.shouldHideMenuItem(element, metadata);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Get selection information from the view.
|
|
|
|
|
*
|
2013-09-13 05:06:46 -07:00
|
|
|
|
* @param nsIDOMElement aClickElement
|
|
|
|
|
* The DOM element the user clicked on.
|
2012-09-18 09:08:29 -07:00
|
|
|
|
* @return object
|
|
|
|
|
* Selection metadata.
|
|
|
|
|
*/
|
2013-09-13 05:06:46 -07:00
|
|
|
|
getSelectionMetadata: function CCM_getSelectionMetadata(aClickElement)
|
2012-09-18 09:08:29 -07:00
|
|
|
|
{
|
|
|
|
|
let metadata = {
|
|
|
|
|
selectionType: "",
|
|
|
|
|
selection: new Set(),
|
|
|
|
|
};
|
2013-09-13 05:06:46 -07:00
|
|
|
|
let selectedItems = this.owner.output.getSelectedMessages();
|
|
|
|
|
if (!selectedItems.length) {
|
|
|
|
|
let clickedItem = this.owner.output.getMessageForElement(aClickElement);
|
|
|
|
|
if (clickedItem) {
|
|
|
|
|
this.lastClickedMessage = clickedItem;
|
|
|
|
|
selectedItems = [clickedItem];
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-09-18 09:08:29 -07:00
|
|
|
|
|
2013-09-13 05:06:46 -07:00
|
|
|
|
metadata.selectionType = selectedItems.length > 1 ? "multiple" : "single";
|
2012-09-18 09:08:29 -07:00
|
|
|
|
|
|
|
|
|
let selection = metadata.selection;
|
|
|
|
|
for (let item of selectedItems) {
|
|
|
|
|
switch (item.category) {
|
|
|
|
|
case CATEGORY_NETWORK:
|
|
|
|
|
selection.add("network");
|
|
|
|
|
break;
|
|
|
|
|
case CATEGORY_CSS:
|
|
|
|
|
selection.add("css");
|
|
|
|
|
break;
|
|
|
|
|
case CATEGORY_JS:
|
|
|
|
|
selection.add("js");
|
|
|
|
|
break;
|
|
|
|
|
case CATEGORY_WEBDEV:
|
|
|
|
|
selection.add("webdev");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return metadata;
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Determine if an item should be hidden.
|
|
|
|
|
*
|
|
|
|
|
* @param nsIDOMElement aMenuItem
|
|
|
|
|
* @param object aMetadata
|
|
|
|
|
* @return boolean
|
|
|
|
|
* Whether the given item should be hidden or not.
|
|
|
|
|
*/
|
|
|
|
|
shouldHideMenuItem: function CCM_shouldHideMenuItem(aMenuItem, aMetadata)
|
|
|
|
|
{
|
|
|
|
|
let selectionType = aMenuItem.getAttribute("selectiontype");
|
|
|
|
|
if (selectionType && !aMetadata.selectionType == selectionType) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let selection = aMenuItem.getAttribute("selection");
|
|
|
|
|
if (!selection) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let shouldHide = true;
|
|
|
|
|
let itemData = selection.split("|");
|
|
|
|
|
for (let type of aMetadata.selection) {
|
|
|
|
|
// check whether this menu item should show or not.
|
|
|
|
|
if (itemData.indexOf(type) !== -1) {
|
|
|
|
|
shouldHide = false;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return shouldHide;
|
|
|
|
|
},
|
2013-08-02 10:11:57 -07:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Destroy the ConsoleContextMenu object instance.
|
|
|
|
|
*/
|
|
|
|
|
destroy: function CCM_destroy()
|
|
|
|
|
{
|
|
|
|
|
this.popup.removeEventListener("popupshowing", this.build);
|
|
|
|
|
this.popup = null;
|
|
|
|
|
this.owner = null;
|
2013-09-13 05:06:46 -07:00
|
|
|
|
this.lastClickedMessage = null;
|
2013-08-02 10:11:57 -07:00
|
|
|
|
},
|
2012-09-18 09:08:29 -07:00
|
|
|
|
};
|
2013-08-02 10:11:57 -07:00
|
|
|
|
|