2010-06-22 16:51:50 +00:00
|
|
|
/* -*- Mode: js2; js2-basic-offset: 2; indent-tabs-mode: nil; -*- */
|
2010-07-19 13:51:51 +00:00
|
|
|
/* vim: set ft=javascript ts=2 et sw=2 tw=80: */
|
2010-06-22 16:51:50 +00:00
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is DevTools (HeadsUpDisplay) Console Code
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Mozilla Foundation
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2010
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* David Dahl <ddahl@mozilla.com> (original author)
|
|
|
|
* Rob Campbell <rcampbell@mozilla.com>
|
|
|
|
* Johnathan Nightingale <jnightingale@mozilla.com>
|
2010-07-23 23:58:52 +00:00
|
|
|
* Patrick Walton <pcwalton@mozilla.com>
|
2010-08-09 19:02:20 +00:00
|
|
|
* Julian Viereck <jviereck@mozilla.com>
|
2010-08-10 12:18:23 +00:00
|
|
|
* Mihai Șucan <mihai.sucan@gmail.com>
|
2011-08-30 12:12:02 +00:00
|
|
|
* Michael Ratcliffe <mratcliffe@mozilla.com>
|
2011-05-27 12:49:02 +00:00
|
|
|
* Joe Walker <jwalker@mozilla.com>
|
2011-11-19 17:11:10 +00:00
|
|
|
* Sonny Piers <sonny.piers@gmail.com>
|
2010-06-22 16:51:50 +00:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
|
|
|
const Cc = Components.classes;
|
|
|
|
const Ci = Components.interfaces;
|
|
|
|
const Cu = Components.utils;
|
|
|
|
|
2010-11-16 21:34:53 +00:00
|
|
|
const CONSOLEAPI_CLASS_ID = "{b49c18f8-3379-4fc0-8c90-d7772c1a9ff3}";
|
|
|
|
|
2010-06-22 16:51:50 +00:00
|
|
|
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
|
|
|
Cu.import("resource://gre/modules/Services.jsm");
|
2010-12-06 15:15:50 +00:00
|
|
|
Cu.import("resource:///modules/NetworkHelper.jsm");
|
2010-06-22 16:51:50 +00:00
|
|
|
|
2010-09-10 18:08:05 +00:00
|
|
|
var EXPORTED_SYMBOLS = ["HUDService", "ConsoleUtils"];
|
2010-06-22 16:51:50 +00:00
|
|
|
|
|
|
|
XPCOMUtils.defineLazyServiceGetter(this, "scriptError",
|
|
|
|
"@mozilla.org/scripterror;1",
|
|
|
|
"nsIScriptError");
|
|
|
|
|
|
|
|
XPCOMUtils.defineLazyServiceGetter(this, "activityDistributor",
|
|
|
|
"@mozilla.org/network/http-activity-distributor;1",
|
|
|
|
"nsIHttpActivityDistributor");
|
|
|
|
|
2010-10-13 12:05:51 +00:00
|
|
|
XPCOMUtils.defineLazyServiceGetter(this, "mimeService",
|
|
|
|
"@mozilla.org/mime;1",
|
|
|
|
"nsIMIMEService");
|
|
|
|
|
2010-12-23 15:59:19 +00:00
|
|
|
XPCOMUtils.defineLazyServiceGetter(this, "clipboardHelper",
|
|
|
|
"@mozilla.org/widget/clipboardhelper;1",
|
|
|
|
"nsIClipboardHelper");
|
|
|
|
|
2011-05-27 12:49:02 +00:00
|
|
|
XPCOMUtils.defineLazyGetter(this, "gcli", function () {
|
|
|
|
var obj = {};
|
|
|
|
Cu.import("resource:///modules/gcli.jsm", obj);
|
|
|
|
return obj.gcli;
|
|
|
|
});
|
|
|
|
|
2011-11-02 01:06:48 +00:00
|
|
|
XPCOMUtils.defineLazyGetter(this, "CssRuleView", function() {
|
|
|
|
let tmp = {};
|
|
|
|
Cu.import("resource:///modules/devtools/CssRuleView.jsm", tmp);
|
|
|
|
return tmp.CssRuleView;
|
|
|
|
});
|
|
|
|
|
2010-08-29 04:30:49 +00:00
|
|
|
XPCOMUtils.defineLazyGetter(this, "NetUtil", function () {
|
|
|
|
var obj = {};
|
|
|
|
Cu.import("resource://gre/modules/NetUtil.jsm", obj);
|
|
|
|
return obj.NetUtil;
|
|
|
|
});
|
|
|
|
|
2011-12-08 12:39:04 +00:00
|
|
|
XPCOMUtils.defineLazyGetter(this, "template", function () {
|
2011-12-08 12:08:35 +00:00
|
|
|
var obj = {};
|
|
|
|
Cu.import("resource:///modules/devtools/Templater.jsm", obj);
|
2011-12-08 12:39:04 +00:00
|
|
|
return obj.template;
|
2011-12-08 12:08:35 +00:00
|
|
|
});
|
|
|
|
|
2010-08-17 21:55:47 +00:00
|
|
|
XPCOMUtils.defineLazyGetter(this, "PropertyPanel", function () {
|
|
|
|
var obj = {};
|
|
|
|
try {
|
2010-12-06 15:15:50 +00:00
|
|
|
Cu.import("resource:///modules/PropertyPanel.jsm", obj);
|
2010-08-17 21:55:47 +00:00
|
|
|
} catch (err) {
|
|
|
|
Cu.reportError(err);
|
|
|
|
}
|
|
|
|
return obj.PropertyPanel;
|
|
|
|
});
|
|
|
|
|
2012-05-10 13:15:10 +00:00
|
|
|
XPCOMUtils.defineLazyGetter(this, "PropertyPanelAsync", function () {
|
|
|
|
let obj = {};
|
|
|
|
Cu.import("resource:///modules/PropertyPanelAsync.jsm", obj);
|
|
|
|
return obj.PropertyPanel;
|
|
|
|
});
|
|
|
|
|
|
|
|
XPCOMUtils.defineLazyGetter(this, "PropertyTreeViewAsync", function () {
|
|
|
|
let obj = {};
|
|
|
|
Cu.import("resource:///modules/PropertyPanelAsync.jsm", obj);
|
|
|
|
return obj.PropertyTreeView;
|
|
|
|
});
|
|
|
|
|
2011-05-17 15:07:33 +00:00
|
|
|
XPCOMUtils.defineLazyGetter(this, "AutocompletePopup", function () {
|
|
|
|
var obj = {};
|
|
|
|
try {
|
2011-08-26 06:42:20 +00:00
|
|
|
Cu.import("resource:///modules/AutocompletePopup.jsm", obj);
|
2011-05-17 15:07:33 +00:00
|
|
|
}
|
|
|
|
catch (err) {
|
|
|
|
Cu.reportError(err);
|
|
|
|
}
|
|
|
|
return obj.AutocompletePopup;
|
|
|
|
});
|
|
|
|
|
2012-01-12 10:12:18 +00:00
|
|
|
XPCOMUtils.defineLazyGetter(this, "ScratchpadManager", function () {
|
|
|
|
var obj = {};
|
|
|
|
try {
|
|
|
|
Cu.import("resource:///modules/devtools/scratchpad-manager.jsm", obj);
|
|
|
|
}
|
|
|
|
catch (err) {
|
|
|
|
Cu.reportError(err);
|
|
|
|
}
|
|
|
|
return obj.ScratchpadManager;
|
|
|
|
});
|
|
|
|
|
2010-09-02 21:30:45 +00:00
|
|
|
XPCOMUtils.defineLazyGetter(this, "namesAndValuesOf", function () {
|
|
|
|
var obj = {};
|
2010-12-06 15:15:50 +00:00
|
|
|
Cu.import("resource:///modules/PropertyPanel.jsm", obj);
|
2010-09-02 21:30:45 +00:00
|
|
|
return obj.namesAndValuesOf;
|
|
|
|
});
|
2010-08-17 21:55:47 +00:00
|
|
|
|
2012-05-10 13:15:10 +00:00
|
|
|
XPCOMUtils.defineLazyGetter(this, "WebConsoleUtils", function () {
|
2012-01-06 19:34:56 +00:00
|
|
|
let obj = {};
|
2012-05-10 13:15:10 +00:00
|
|
|
Cu.import("resource:///modules/WebConsoleUtils.jsm", obj);
|
|
|
|
return obj.WebConsoleUtils;
|
|
|
|
});
|
|
|
|
|
|
|
|
XPCOMUtils.defineLazyGetter(this, "l10n", function() {
|
|
|
|
return WebConsoleUtils.l10n;
|
2012-01-06 19:34:56 +00:00
|
|
|
});
|
|
|
|
|
2010-06-22 16:51:50 +00:00
|
|
|
function LogFactory(aMessagePrefix)
|
|
|
|
{
|
|
|
|
function log(aMessage) {
|
|
|
|
var _msg = aMessagePrefix + " " + aMessage + "\n";
|
|
|
|
dump(_msg);
|
|
|
|
}
|
|
|
|
return log;
|
|
|
|
}
|
|
|
|
|
|
|
|
let log = LogFactory("*** HUDService:");
|
|
|
|
|
2011-10-27 15:35:13 +00:00
|
|
|
const HUD_STRINGS_URI = "chrome://browser/locale/devtools/webconsole.properties";
|
2010-06-22 16:51:50 +00:00
|
|
|
|
|
|
|
XPCOMUtils.defineLazyGetter(this, "stringBundle", function () {
|
|
|
|
return Services.strings.createBundle(HUD_STRINGS_URI);
|
|
|
|
});
|
|
|
|
|
2010-08-09 18:35:33 +00: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;
|
|
|
|
|
2010-08-18 23:53:53 +00:00
|
|
|
// The amount of time in milliseconds that we wait before performing a live
|
|
|
|
// search.
|
|
|
|
const SEARCH_DELAY = 200;
|
|
|
|
|
2011-05-19 20:15:36 +00:00
|
|
|
// 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.
|
2010-09-09 00:08:58 +00:00
|
|
|
const DEFAULT_LOG_LIMIT = 200;
|
|
|
|
|
2010-12-23 15:59:19 +00:00
|
|
|
// 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;
|
2011-01-27 06:22:58 +00:00
|
|
|
const CATEGORY_INPUT = 4; // always on
|
|
|
|
const CATEGORY_OUTPUT = 5; // always on
|
2010-12-23 15:59:19 +00: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;
|
|
|
|
|
|
|
|
// 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,
|
2011-04-11 17:48:15 +00:00
|
|
|
trace: SEVERITY_LOG,
|
2011-06-14 11:38:11 +00:00
|
|
|
dir: SEVERITY_LOG,
|
|
|
|
group: SEVERITY_LOG,
|
|
|
|
groupCollapsed: SEVERITY_LOG,
|
2011-06-01 06:33:22 +00:00
|
|
|
groupEnd: SEVERITY_LOG,
|
|
|
|
time: SEVERITY_LOG,
|
|
|
|
timeEnd: SEVERITY_LOG
|
2010-12-23 15:59:19 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// The lowest HTTP response code (inclusive) that is considered an error.
|
|
|
|
const MIN_HTTP_ERROR_CODE = 400;
|
|
|
|
// The highest HTTP response code (exclusive) that is considered an error.
|
|
|
|
const MAX_HTTP_ERROR_CODE = 600;
|
|
|
|
|
2011-02-14 19:00:27 +00:00
|
|
|
// HTTP status codes.
|
|
|
|
const HTTP_MOVED_PERMANENTLY = 301;
|
|
|
|
const HTTP_FOUND = 302;
|
|
|
|
const HTTP_SEE_OTHER = 303;
|
|
|
|
const HTTP_TEMPORARY_REDIRECT = 307;
|
|
|
|
|
2010-12-23 15:59:19 +00:00
|
|
|
// The HTML namespace.
|
|
|
|
const HTML_NS = "http://www.w3.org/1999/xhtml";
|
|
|
|
|
|
|
|
// The XUL namespace.
|
|
|
|
const XUL_NS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
|
|
|
|
|
|
|
|
// The fragment of a CSS class name that identifies each category.
|
|
|
|
const CATEGORY_CLASS_FRAGMENTS = [
|
|
|
|
"network",
|
|
|
|
"cssparser",
|
|
|
|
"exception",
|
|
|
|
"console",
|
|
|
|
"input",
|
|
|
|
"output",
|
|
|
|
];
|
|
|
|
|
|
|
|
// 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
|
|
|
|
[ "network", null, null, "networkinfo", ], // Network
|
|
|
|
[ "csserror", "cssparser", null, null, ], // CSS
|
|
|
|
[ "exception", "jswarn", null, null, ], // JS
|
|
|
|
[ "error", "warn", "info", "log", ], // Web Developer
|
|
|
|
[ null, null, null, null, ], // Input
|
|
|
|
[ null, null, null, null, ], // Output
|
|
|
|
];
|
|
|
|
|
2010-11-10 16:10:26 +00:00
|
|
|
// Possible directions that can be passed to HUDService.animate().
|
|
|
|
const ANIMATE_OUT = 0;
|
|
|
|
const ANIMATE_IN = 1;
|
|
|
|
|
2010-10-20 17:39:44 +00:00
|
|
|
// Constants used for defining the direction of JSTerm input history navigation.
|
|
|
|
const HISTORY_BACK = -1;
|
|
|
|
const HISTORY_FORWARD = 1;
|
|
|
|
|
2010-10-12 19:13:42 +00:00
|
|
|
// The maximum number of bytes a Network ResponseListener can hold.
|
2011-01-19 14:23:07 +00:00
|
|
|
const RESPONSE_BODY_LIMIT = 1024*1024; // 1 MB
|
|
|
|
|
|
|
|
// The maximum uint32 value.
|
|
|
|
const PR_UINT32_MAX = 4294967295;
|
2010-10-12 19:13:42 +00:00
|
|
|
|
2010-11-20 19:53:14 +00:00
|
|
|
// Minimum console height, in pixels.
|
|
|
|
const MINIMUM_CONSOLE_HEIGHT = 150;
|
|
|
|
|
|
|
|
// Minimum page height, in pixels. This prevents the Web Console from
|
|
|
|
// remembering a height that covers the whole page.
|
|
|
|
const MINIMUM_PAGE_HEIGHT = 50;
|
|
|
|
|
|
|
|
// The default console height, as a ratio from the content window inner height.
|
|
|
|
const DEFAULT_CONSOLE_HEIGHT = 0.33;
|
|
|
|
|
2011-01-04 17:31:48 +00:00
|
|
|
// Constant used when checking the typeof objects.
|
|
|
|
const TYPEOF_FUNCTION = "function";
|
|
|
|
|
2012-05-10 13:15:10 +00:00
|
|
|
// This script is inserted into the content process.
|
|
|
|
const CONTENT_SCRIPT_URL = "chrome://browser/content/devtools/HUDService-content.js";
|
|
|
|
|
2010-06-22 16:51:50 +00:00
|
|
|
const ERRORS = { LOG_MESSAGE_MISSING_ARGS:
|
|
|
|
"Missing arguments: aMessage, aConsoleNode and aMessageNode are required.",
|
|
|
|
CANNOT_GET_HUD: "Cannot getHeads Up Display with provided ID",
|
|
|
|
MISSING_ARGS: "Missing arguments",
|
|
|
|
LOG_OUTPUT_FAILED: "Log Failure: Could not append messageNode to outputNode",
|
|
|
|
};
|
|
|
|
|
2011-06-14 11:38:11 +00:00
|
|
|
// The indent of a console group in pixels.
|
|
|
|
const GROUP_INDENT = 12;
|
|
|
|
|
2011-11-19 17:11:10 +00:00
|
|
|
// The pref prefix for webconsole filters
|
|
|
|
const PREFS_PREFIX = "devtools.webconsole.filter.";
|
|
|
|
|
2010-08-29 04:30:49 +00:00
|
|
|
/**
|
|
|
|
* Implements the nsIStreamListener and nsIRequestObserver interface. Used
|
|
|
|
* within the HS_httpObserverFactory function to get the response body of
|
|
|
|
* requests.
|
|
|
|
*
|
|
|
|
* The code is mostly based on code listings from:
|
|
|
|
*
|
|
|
|
* http://www.softwareishard.com/blog/firebug/
|
|
|
|
* nsitraceablechannel-intercept-http-traffic/
|
|
|
|
*
|
|
|
|
* @param object aHttpActivity
|
|
|
|
* HttpActivity object associated with this request (see
|
|
|
|
* HS_httpObserverFactory). As the response is done, the response header,
|
|
|
|
* body and status is stored on aHttpActivity.
|
|
|
|
*/
|
|
|
|
function ResponseListener(aHttpActivity) {
|
|
|
|
this.receivedData = "";
|
|
|
|
this.httpActivity = aHttpActivity;
|
|
|
|
}
|
|
|
|
|
|
|
|
ResponseListener.prototype =
|
|
|
|
{
|
|
|
|
/**
|
2011-01-19 14:23:07 +00:00
|
|
|
* The response will be written into the outputStream of this nsIPipe.
|
|
|
|
* Both ends of the pipe must be blocking.
|
2010-08-29 04:30:49 +00:00
|
|
|
*/
|
2011-01-19 14:23:07 +00:00
|
|
|
sink: null,
|
2010-08-29 04:30:49 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The HttpActivity object associated with this response.
|
|
|
|
*/
|
|
|
|
httpActivity: null,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Stores the received data as a string.
|
|
|
|
*/
|
|
|
|
receivedData: null,
|
|
|
|
|
2011-01-19 14:23:07 +00:00
|
|
|
/**
|
|
|
|
* The nsIRequest we are started for.
|
|
|
|
*/
|
|
|
|
request: null,
|
|
|
|
|
2010-08-29 04:30:49 +00:00
|
|
|
/**
|
|
|
|
* Sets the httpActivity object's response header if it isn't set already.
|
|
|
|
*
|
|
|
|
* @param nsIRequest aRequest
|
|
|
|
*/
|
|
|
|
setResponseHeader: function RL_setResponseHeader(aRequest)
|
|
|
|
{
|
|
|
|
let httpActivity = this.httpActivity;
|
|
|
|
// Check if the header isn't set yet.
|
|
|
|
if (!httpActivity.response.header) {
|
|
|
|
if (aRequest instanceof Ci.nsIHttpChannel) {
|
2010-09-02 21:30:48 +00:00
|
|
|
httpActivity.response.header = {};
|
|
|
|
try {
|
2010-08-29 04:30:49 +00:00
|
|
|
aRequest.visitResponseHeaders({
|
|
|
|
visitHeader: function(aName, aValue) {
|
|
|
|
httpActivity.response.header[aName] = aValue;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2010-09-02 21:30:48 +00:00
|
|
|
// Accessing the response header can throw an NS_ERROR_NOT_AVAILABLE
|
|
|
|
// exception. Catch it and stop it to make it not show up in the.
|
|
|
|
// This can happen if the response is not finished yet and the user
|
|
|
|
// reloades the page.
|
|
|
|
catch (ex) {
|
|
|
|
delete httpActivity.response.header;
|
|
|
|
}
|
|
|
|
}
|
2010-08-29 04:30:49 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2011-01-19 14:23:07 +00:00
|
|
|
* Set the async listener for the given nsIAsyncInputStream. This allows us to
|
|
|
|
* wait asynchronously for any data coming from the stream.
|
|
|
|
*
|
|
|
|
* @param nsIAsyncInputStream aStream
|
|
|
|
* The input stream from where we are waiting for data to come in.
|
2010-08-29 04:30:49 +00:00
|
|
|
*
|
2011-01-19 14:23:07 +00:00
|
|
|
* @param nsIInputStreamCallback aListener
|
|
|
|
* The input stream callback you want. This is an object that must have
|
|
|
|
* the onInputStreamReady() method. If the argument is null, then the
|
|
|
|
* current callback is removed.
|
|
|
|
*
|
|
|
|
* @returns void
|
|
|
|
*/
|
|
|
|
setAsyncListener: function RL_setAsyncListener(aStream, aListener)
|
|
|
|
{
|
|
|
|
// Asynchronously wait for the stream to be readable or closed.
|
|
|
|
aStream.asyncWait(aListener, 0, 0, Services.tm.mainThread);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Stores the received data, if request/response body logging is enabled. It
|
|
|
|
* also does limit the number of stored bytes, based on the
|
|
|
|
* RESPONSE_BODY_LIMIT constant.
|
|
|
|
*
|
|
|
|
* Learn more about nsIStreamListener at:
|
|
|
|
* https://developer.mozilla.org/en/XPCOM_Interface_Reference/nsIStreamListener
|
2010-08-29 04:30:49 +00:00
|
|
|
*
|
|
|
|
* @param nsIRequest aRequest
|
|
|
|
* @param nsISupports aContext
|
|
|
|
* @param nsIInputStream aInputStream
|
|
|
|
* @param unsigned long aOffset
|
|
|
|
* @param unsigned long aCount
|
|
|
|
*/
|
|
|
|
onDataAvailable: function RL_onDataAvailable(aRequest, aContext, aInputStream,
|
2011-01-19 14:23:07 +00:00
|
|
|
aOffset, aCount)
|
2010-08-29 04:30:49 +00:00
|
|
|
{
|
|
|
|
this.setResponseHeader(aRequest);
|
|
|
|
|
|
|
|
let data = NetUtil.readInputStreamToString(aInputStream, aCount);
|
2010-10-12 19:13:42 +00:00
|
|
|
|
2011-02-14 19:00:27 +00:00
|
|
|
if (!this.httpActivity.response.bodyDiscarded &&
|
2010-10-12 19:13:42 +00:00
|
|
|
this.receivedData.length < RESPONSE_BODY_LIMIT) {
|
2010-11-20 19:53:14 +00:00
|
|
|
this.receivedData += NetworkHelper.
|
|
|
|
convertToUnicode(data, aRequest.contentCharset);
|
2010-10-12 19:13:42 +00:00
|
|
|
}
|
2010-08-29 04:30:49 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* See documentation at
|
|
|
|
* https://developer.mozilla.org/En/NsIRequestObserver
|
|
|
|
*
|
|
|
|
* @param nsIRequest aRequest
|
|
|
|
* @param nsISupports aContext
|
|
|
|
*/
|
|
|
|
onStartRequest: function RL_onStartRequest(aRequest, aContext)
|
|
|
|
{
|
2011-01-19 14:23:07 +00:00
|
|
|
this.request = aRequest;
|
2011-02-14 19:00:27 +00:00
|
|
|
|
|
|
|
// Always discard the response body if logging is not enabled in the Web
|
|
|
|
// Console.
|
|
|
|
this.httpActivity.response.bodyDiscarded =
|
|
|
|
!HUDService.saveRequestAndResponseBodies;
|
|
|
|
|
|
|
|
// Check response status and discard the body for redirects.
|
|
|
|
if (!this.httpActivity.response.bodyDiscarded &&
|
|
|
|
this.httpActivity.channel instanceof Ci.nsIHttpChannel) {
|
|
|
|
switch (this.httpActivity.channel.responseStatus) {
|
|
|
|
case HTTP_MOVED_PERMANENTLY:
|
|
|
|
case HTTP_FOUND:
|
|
|
|
case HTTP_SEE_OTHER:
|
|
|
|
case HTTP_TEMPORARY_REDIRECT:
|
|
|
|
this.httpActivity.response.bodyDiscarded = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-19 14:23:07 +00:00
|
|
|
// Asynchronously wait for the data coming from the request.
|
|
|
|
this.setAsyncListener(this.sink.inputStream, this);
|
2010-08-29 04:30:49 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2011-01-19 14:23:07 +00:00
|
|
|
* Handle the onStopRequest by storing the response header is stored on the
|
|
|
|
* httpActivity object. The sink output stream is also closed.
|
2010-08-29 04:30:49 +00:00
|
|
|
*
|
2011-01-19 14:23:07 +00:00
|
|
|
* For more documentation about nsIRequestObserver go to:
|
|
|
|
* https://developer.mozilla.org/En/NsIRequestObserver
|
2010-08-29 04:30:49 +00:00
|
|
|
*
|
|
|
|
* @param nsIRequest aRequest
|
2011-01-19 14:23:07 +00:00
|
|
|
* The request we are observing.
|
2010-08-29 04:30:49 +00:00
|
|
|
* @param nsISupports aContext
|
|
|
|
* @param nsresult aStatusCode
|
|
|
|
*/
|
|
|
|
onStopRequest: function RL_onStopRequest(aRequest, aContext, aStatusCode)
|
|
|
|
{
|
2011-01-11 20:34:39 +00:00
|
|
|
// Retrieve the response headers, as they are, from the server.
|
|
|
|
let response = null;
|
|
|
|
for each (let item in HUDService.openResponseHeaders) {
|
2011-02-14 19:00:27 +00:00
|
|
|
if (item.channel === this.httpActivity.channel) {
|
2011-01-11 20:34:39 +00:00
|
|
|
response = item;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (response) {
|
|
|
|
this.httpActivity.response.header = response.headers;
|
|
|
|
delete HUDService.openResponseHeaders[response.id];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
this.setResponseHeader(aRequest);
|
|
|
|
}
|
|
|
|
|
2011-01-19 14:23:07 +00:00
|
|
|
this.sink.outputStream.close();
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Clean up the response listener once the response input stream is closed.
|
|
|
|
* This is called from onStopRequest() or from onInputStreamReady() when the
|
|
|
|
* stream is closed.
|
|
|
|
*
|
|
|
|
* @returns void
|
|
|
|
*/
|
|
|
|
onStreamClose: function RL_onStreamClose()
|
|
|
|
{
|
|
|
|
if (!this.httpActivity) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remove our listener from the request input stream.
|
|
|
|
this.setAsyncListener(this.sink.inputStream, null);
|
|
|
|
|
2011-02-14 19:00:27 +00:00
|
|
|
if (!this.httpActivity.response.bodyDiscarded &&
|
|
|
|
HUDService.saveRequestAndResponseBodies) {
|
2011-01-19 14:23:07 +00:00
|
|
|
this.httpActivity.response.body = this.receivedData;
|
|
|
|
}
|
|
|
|
|
2010-08-29 04:30:49 +00:00
|
|
|
if (HUDService.lastFinishedRequestCallback) {
|
|
|
|
HUDService.lastFinishedRequestCallback(this.httpActivity);
|
|
|
|
}
|
2010-08-29 04:31:12 +00:00
|
|
|
|
|
|
|
// Call update on all panels.
|
|
|
|
this.httpActivity.panels.forEach(function(weakRef) {
|
|
|
|
let panel = weakRef.get();
|
|
|
|
if (panel) {
|
|
|
|
panel.update();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
this.httpActivity.response.isDone = true;
|
2010-08-29 04:30:49 +00:00
|
|
|
this.httpActivity = null;
|
2010-10-12 19:13:42 +00:00
|
|
|
this.receivedData = "";
|
2011-01-19 14:23:07 +00:00
|
|
|
this.request = null;
|
|
|
|
this.sink = null;
|
|
|
|
this.inputStream = null;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The nsIInputStreamCallback for when the request input stream is ready -
|
|
|
|
* either it has more data or it is closed.
|
|
|
|
*
|
|
|
|
* @param nsIAsyncInputStream aStream
|
|
|
|
* The sink input stream from which data is coming.
|
|
|
|
*
|
|
|
|
* @returns void
|
|
|
|
*/
|
|
|
|
onInputStreamReady: function RL_onInputStreamReady(aStream)
|
|
|
|
{
|
|
|
|
if (!(aStream instanceof Ci.nsIAsyncInputStream) || !this.httpActivity) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let available = -1;
|
|
|
|
try {
|
|
|
|
// This may throw if the stream is closed normally or due to an error.
|
|
|
|
available = aStream.available();
|
|
|
|
}
|
|
|
|
catch (ex) { }
|
|
|
|
|
|
|
|
if (available != -1) {
|
|
|
|
if (available != 0) {
|
|
|
|
// Note that passing 0 as the offset here is wrong, but the
|
|
|
|
// onDataAvailable() method does not use the offset, so it does not
|
|
|
|
// matter.
|
|
|
|
this.onDataAvailable(this.request, null, aStream, 0, available);
|
|
|
|
}
|
|
|
|
this.setAsyncListener(aStream, this);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
this.onStreamClose();
|
|
|
|
}
|
2010-08-29 04:30:49 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
QueryInterface: XPCOMUtils.generateQI([
|
|
|
|
Ci.nsIStreamListener,
|
2011-01-19 14:23:07 +00:00
|
|
|
Ci.nsIInputStreamCallback,
|
|
|
|
Ci.nsIRequestObserver,
|
|
|
|
Ci.nsISupports,
|
2010-08-29 04:30:49 +00:00
|
|
|
])
|
|
|
|
}
|
|
|
|
|
2010-08-29 04:31:12 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
//// Helper for creating the network panel.
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a DOMNode and sets all the attributes of aAttributes on the created
|
|
|
|
* element.
|
|
|
|
*
|
|
|
|
* @param nsIDOMDocument aDocument
|
|
|
|
* Document to create the new DOMNode.
|
|
|
|
* @param string aTag
|
|
|
|
* Name of the tag for the DOMNode.
|
|
|
|
* @param object aAttributes
|
|
|
|
* Attributes set on the created DOMNode.
|
|
|
|
*
|
|
|
|
* @returns nsIDOMNode
|
|
|
|
*/
|
|
|
|
function createElement(aDocument, aTag, aAttributes)
|
|
|
|
{
|
|
|
|
let node = aDocument.createElement(aTag);
|
2011-05-17 15:07:33 +00:00
|
|
|
if (aAttributes) {
|
|
|
|
for (let attr in aAttributes) {
|
|
|
|
node.setAttribute(attr, aAttributes[attr]);
|
|
|
|
}
|
2010-08-29 04:31:12 +00:00
|
|
|
}
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a new DOMNode and appends it to aParent.
|
|
|
|
*
|
|
|
|
* @param nsIDOMNode aParent
|
|
|
|
* A parent node to append the created element.
|
|
|
|
* @param string aTag
|
|
|
|
* Name of the tag for the DOMNode.
|
|
|
|
* @param object aAttributes
|
|
|
|
* Attributes set on the created DOMNode.
|
|
|
|
*
|
|
|
|
* @returns nsIDOMNode
|
|
|
|
*/
|
|
|
|
function createAndAppendElement(aParent, aTag, aAttributes)
|
|
|
|
{
|
|
|
|
let node = createElement(aParent.ownerDocument, aTag, aAttributes);
|
|
|
|
aParent.appendChild(node);
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
//// NetworkPanel
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a new NetworkPanel.
|
|
|
|
*
|
|
|
|
* @param nsIDOMNode aParent
|
|
|
|
* Parent node to append the created panel to.
|
|
|
|
* @param object aHttpActivity
|
|
|
|
* HttpActivity to display in the panel.
|
|
|
|
*/
|
|
|
|
function NetworkPanel(aParent, aHttpActivity)
|
|
|
|
{
|
|
|
|
let doc = aParent.ownerDocument;
|
|
|
|
this.httpActivity = aHttpActivity;
|
|
|
|
|
|
|
|
// Create the underlaying panel
|
|
|
|
this.panel = createElement(doc, "panel", {
|
2012-05-10 13:15:10 +00:00
|
|
|
label: l10n.getStr("NetworkPanel.label"),
|
2010-08-29 04:31:12 +00:00
|
|
|
titlebar: "normal",
|
|
|
|
noautofocus: "true",
|
|
|
|
noautohide: "true",
|
|
|
|
close: "true"
|
|
|
|
});
|
|
|
|
|
2010-10-18 22:57:09 +00:00
|
|
|
// Create the iframe that displays the NetworkPanel XHTML.
|
2010-10-19 12:42:47 +00:00
|
|
|
this.iframe = createAndAppendElement(this.panel, "iframe", {
|
2010-10-07 16:11:48 +00:00
|
|
|
src: "chrome://browser/content/NetworkPanel.xhtml",
|
2010-10-18 22:57:09 +00:00
|
|
|
type: "content",
|
2010-08-29 04:31:12 +00:00
|
|
|
flex: "1"
|
|
|
|
});
|
|
|
|
|
2010-10-11 21:37:34 +00:00
|
|
|
let self = this;
|
|
|
|
|
2010-08-29 04:31:12 +00:00
|
|
|
// Destroy the panel when it's closed.
|
|
|
|
this.panel.addEventListener("popuphidden", function onPopupHide() {
|
|
|
|
self.panel.removeEventListener("popuphidden", onPopupHide, false);
|
|
|
|
self.panel.parentNode.removeChild(self.panel);
|
|
|
|
self.panel = null;
|
2010-10-19 12:42:47 +00:00
|
|
|
self.iframe = null;
|
2010-08-29 04:31:12 +00:00
|
|
|
self.document = null;
|
|
|
|
self.httpActivity = null;
|
2010-10-11 21:37:34 +00:00
|
|
|
|
|
|
|
if (self.linkNode) {
|
|
|
|
self.linkNode._panelOpen = false;
|
|
|
|
self.linkNode = null;
|
|
|
|
}
|
2010-08-29 04:31:12 +00:00
|
|
|
}, false);
|
|
|
|
|
|
|
|
// Set the document object and update the content once the panel is loaded.
|
|
|
|
this.panel.addEventListener("load", function onLoad() {
|
2010-11-16 21:34:53 +00:00
|
|
|
self.panel.removeEventListener("load", onLoad, true);
|
2010-10-19 12:42:47 +00:00
|
|
|
self.document = self.iframe.contentWindow.document;
|
2010-08-29 04:31:12 +00:00
|
|
|
self.update();
|
|
|
|
}, true);
|
|
|
|
|
|
|
|
// Create the footer.
|
|
|
|
let footer = createElement(doc, "hbox", { align: "end" });
|
|
|
|
createAndAppendElement(footer, "spacer", { flex: 1 });
|
|
|
|
|
|
|
|
createAndAppendElement(footer, "resizer", { dir: "bottomend" });
|
|
|
|
this.panel.appendChild(footer);
|
|
|
|
|
|
|
|
aParent.appendChild(this.panel);
|
|
|
|
}
|
|
|
|
|
|
|
|
NetworkPanel.prototype =
|
|
|
|
{
|
2010-08-29 04:31:49 +00:00
|
|
|
/**
|
|
|
|
* Callback is called once the NetworkPanel is processed completly. Used by
|
|
|
|
* unit tests.
|
|
|
|
*/
|
|
|
|
isDoneCallback: null,
|
|
|
|
|
2010-08-29 04:31:12 +00:00
|
|
|
/**
|
|
|
|
* The current state of the output.
|
|
|
|
*/
|
|
|
|
_state: 0,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* State variables.
|
|
|
|
*/
|
|
|
|
_INIT: 0,
|
|
|
|
_DISPLAYED_REQUEST_HEADER: 1,
|
|
|
|
_DISPLAYED_REQUEST_BODY: 2,
|
|
|
|
_DISPLAYED_RESPONSE_HEADER: 3,
|
|
|
|
_TRANSITION_CLOSED: 4,
|
|
|
|
|
2010-08-29 04:31:33 +00:00
|
|
|
_fromDataRegExp: /Content-Type\:\s*application\/x-www-form-urlencoded/,
|
|
|
|
|
2010-08-29 04:31:12 +00:00
|
|
|
/**
|
|
|
|
* Small helper function that is nearly equal to HUDService.getFormatStr
|
|
|
|
* except that it prefixes aName with "NetworkPanel.".
|
|
|
|
*
|
|
|
|
* @param string aName
|
|
|
|
* The name of an i10n string to format. This string is prefixed with
|
|
|
|
* "NetworkPanel." before calling the HUDService.getFormatStr function.
|
|
|
|
* @param array aArray
|
|
|
|
* Values used as placeholder for the i10n string.
|
|
|
|
* @returns string
|
|
|
|
* The i10n formated string.
|
|
|
|
*/
|
|
|
|
_format: function NP_format(aName, aArray)
|
|
|
|
{
|
2012-05-10 13:15:10 +00:00
|
|
|
return l10n.getFormatStr("NetworkPanel." + aName, aArray);
|
2010-08-29 04:31:12 +00:00
|
|
|
},
|
|
|
|
|
2010-10-13 12:05:51 +00:00
|
|
|
/**
|
|
|
|
* Returns the content type of the response body. This is based on the
|
|
|
|
* response.header["Content-Type"] info. If this value is not available, then
|
|
|
|
* the content type is tried to be estimated by the url file ending.
|
|
|
|
*
|
|
|
|
* @returns string or null
|
|
|
|
* Content type or null if no content type could be figured out.
|
|
|
|
*/
|
|
|
|
get _contentType()
|
|
|
|
{
|
|
|
|
let response = this.httpActivity.response;
|
|
|
|
let contentTypeValue = null;
|
|
|
|
|
|
|
|
if (response.header && response.header["Content-Type"]) {
|
|
|
|
let types = response.header["Content-Type"].split(/,|;/);
|
|
|
|
for (let i = 0; i < types.length; i++) {
|
|
|
|
let type = NetworkHelper.mimeCategoryMap[types[i]];
|
|
|
|
if (type) {
|
|
|
|
return types[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Try to get the content type from the request file extension.
|
|
|
|
let uri = NetUtil.newURI(this.httpActivity.url);
|
|
|
|
let mimeType = null;
|
|
|
|
if ((uri instanceof Ci.nsIURL) && uri.fileExtension) {
|
|
|
|
try {
|
|
|
|
mimeType = mimeService.getTypeFromExtension(uri.fileExtension);
|
|
|
|
} catch(e) {
|
|
|
|
// Added to prevent failures on OS X 64. No Flash?
|
|
|
|
Cu.reportError(e);
|
|
|
|
// Return empty string to pass unittests.
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return mimeType;
|
|
|
|
},
|
|
|
|
|
2010-08-29 04:31:12 +00:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @returns boolean
|
|
|
|
* True if the response is an image, false otherwise.
|
|
|
|
*/
|
|
|
|
get _responseIsImage()
|
|
|
|
{
|
2010-10-13 12:05:51 +00:00
|
|
|
return NetworkHelper.mimeCategoryMap[this._contentType] == "image";
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @returns boolean
|
|
|
|
* True if the response body contains text, false otherwise.
|
|
|
|
*/
|
|
|
|
get _isResponseBodyTextData()
|
|
|
|
{
|
|
|
|
let contentType = this._contentType;
|
|
|
|
|
|
|
|
if (!contentType)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (contentType.indexOf("text/") == 0) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (NetworkHelper.mimeCategoryMap[contentType]) {
|
|
|
|
case "txt":
|
|
|
|
case "js":
|
|
|
|
case "json":
|
|
|
|
case "css":
|
|
|
|
case "html":
|
|
|
|
case "svg":
|
|
|
|
case "xml":
|
2010-08-29 04:31:12 +00:00
|
|
|
return true;
|
2010-10-13 12:05:51 +00:00
|
|
|
|
|
|
|
default:
|
2010-08-29 04:31:12 +00:00
|
|
|
return false;
|
2010-09-09 18:01:04 +00:00
|
|
|
}
|
2010-08-29 04:31:12 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @returns boolean
|
|
|
|
* Returns true if the server responded that the request is already
|
|
|
|
* in the browser's cache, false otherwise.
|
|
|
|
*/
|
|
|
|
get _isResponseCached()
|
|
|
|
{
|
|
|
|
return this.httpActivity.response.status.indexOf("304") != -1;
|
|
|
|
},
|
|
|
|
|
2010-08-29 04:31:33 +00:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @returns boolean
|
|
|
|
* Returns true if the posted body contains form data.
|
|
|
|
*/
|
|
|
|
get _isRequestBodyFormData()
|
|
|
|
{
|
|
|
|
let requestBody = this.httpActivity.request.body;
|
|
|
|
return this._fromDataRegExp.test(requestBody);
|
|
|
|
},
|
|
|
|
|
2010-08-29 04:31:12 +00:00
|
|
|
/**
|
|
|
|
* Appends the node with id=aId by the text aValue.
|
|
|
|
*
|
|
|
|
* @param string aId
|
|
|
|
* @param string aValue
|
|
|
|
* @returns void
|
|
|
|
*/
|
|
|
|
_appendTextNode: function NP_appendTextNode(aId, aValue)
|
|
|
|
{
|
|
|
|
let textNode = this.document.createTextNode(aValue);
|
|
|
|
this.document.getElementById(aId).appendChild(textNode);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Generates some HTML to display the key-value pair of the aList data. The
|
|
|
|
* generated HTML is added to node with id=aParentId.
|
|
|
|
*
|
|
|
|
* @param string aParentId
|
|
|
|
* Id of the parent node to append the list to.
|
|
|
|
* @oaram object aList
|
|
|
|
* Object that holds the key-value information to display in aParentId.
|
|
|
|
* @param boolean aIgnoreCookie
|
|
|
|
* If true, the key-value named "Cookie" is not added to the list.
|
|
|
|
* @returns void
|
|
|
|
*/
|
|
|
|
_appendList: function NP_appendList(aParentId, aList, aIgnoreCookie)
|
|
|
|
{
|
|
|
|
let parent = this.document.getElementById(aParentId);
|
|
|
|
let doc = this.document;
|
|
|
|
|
|
|
|
let sortedList = {};
|
|
|
|
Object.keys(aList).sort().forEach(function(aKey) {
|
|
|
|
sortedList[aKey] = aList[aKey];
|
|
|
|
});
|
|
|
|
|
|
|
|
for (let key in sortedList) {
|
|
|
|
if (aIgnoreCookie && key == "Cookie") {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The following code creates the HTML:
|
2011-01-04 17:47:34 +00:00
|
|
|
* <tr>
|
|
|
|
* <th scope="row" class="property-name">${line}:</th>
|
|
|
|
* <td class="property-value">${aList[line]}</td>
|
|
|
|
* </tr>
|
2010-08-29 04:31:12 +00:00
|
|
|
* and adds it to parent.
|
|
|
|
*/
|
2011-01-04 17:47:34 +00:00
|
|
|
let row = doc.createElement("tr");
|
2010-08-29 04:31:12 +00:00
|
|
|
let textNode = doc.createTextNode(key + ":");
|
2011-01-04 17:47:34 +00:00
|
|
|
let th = doc.createElement("th");
|
|
|
|
th.setAttribute("scope", "row");
|
|
|
|
th.setAttribute("class", "property-name");
|
|
|
|
th.appendChild(textNode);
|
|
|
|
row.appendChild(th);
|
2010-08-29 04:31:12 +00:00
|
|
|
|
|
|
|
textNode = doc.createTextNode(sortedList[key]);
|
2011-01-04 17:47:34 +00:00
|
|
|
let td = doc.createElement("td");
|
|
|
|
td.setAttribute("class", "property-value");
|
|
|
|
td.appendChild(textNode);
|
|
|
|
row.appendChild(td);
|
2010-08-29 04:31:12 +00:00
|
|
|
|
2011-01-04 17:47:34 +00:00
|
|
|
parent.appendChild(row);
|
2010-08-29 04:31:12 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Displays the node with id=aId.
|
|
|
|
*
|
|
|
|
* @param string aId
|
|
|
|
* @returns void
|
|
|
|
*/
|
|
|
|
_displayNode: function NP_displayNode(aId)
|
|
|
|
{
|
|
|
|
this.document.getElementById(aId).style.display = "block";
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the request URL, request method, the timing information when the
|
|
|
|
* request started and the request header content on the NetworkPanel.
|
|
|
|
* If the request header contains cookie data, a list of sent cookies is
|
|
|
|
* generated and a special sent cookie section is displayed + the cookie list
|
|
|
|
* added to it.
|
|
|
|
*
|
|
|
|
* @returns void
|
|
|
|
*/
|
|
|
|
_displayRequestHeader: function NP_displayRequestHeader()
|
|
|
|
{
|
|
|
|
let timing = this.httpActivity.timing;
|
|
|
|
let request = this.httpActivity.request;
|
|
|
|
|
|
|
|
this._appendTextNode("headUrl", this.httpActivity.url);
|
|
|
|
this._appendTextNode("headMethod", this.httpActivity.method);
|
|
|
|
|
|
|
|
this._appendTextNode("requestHeadersInfo",
|
2012-05-10 13:15:10 +00:00
|
|
|
l10n.timestampString(timing.REQUEST_HEADER/1000));
|
2010-08-29 04:31:12 +00:00
|
|
|
|
|
|
|
this._appendList("requestHeadersContent", request.header, true);
|
|
|
|
|
|
|
|
if ("Cookie" in request.header) {
|
|
|
|
this._displayNode("requestCookie");
|
|
|
|
|
|
|
|
let cookies = request.header.Cookie.split(";");
|
|
|
|
let cookieList = {};
|
|
|
|
let cookieListSorted = {};
|
|
|
|
cookies.forEach(function(cookie) {
|
|
|
|
let name, value;
|
|
|
|
[name, value] = cookie.trim().split("=");
|
|
|
|
cookieList[name] = value;
|
|
|
|
});
|
|
|
|
this._appendList("requestCookieContent", cookieList);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Displays the request body section of the NetworkPanel and set the request
|
|
|
|
* body content on the NetworkPanel.
|
|
|
|
*
|
|
|
|
* @returns void
|
|
|
|
*/
|
|
|
|
_displayRequestBody: function NP_displayRequestBody() {
|
|
|
|
this._displayNode("requestBody");
|
|
|
|
this._appendTextNode("requestBodyContent", this.httpActivity.request.body);
|
|
|
|
},
|
|
|
|
|
2010-08-29 04:31:33 +00:00
|
|
|
/*
|
|
|
|
* Displays the `sent form data` section. Parses the request header for the
|
|
|
|
* submitted form data displays it inside of the `sent form data` section.
|
|
|
|
*
|
|
|
|
* @returns void
|
|
|
|
*/
|
|
|
|
_displayRequestForm: function NP_processRequestForm() {
|
|
|
|
let requestBodyLines = this.httpActivity.request.body.split("\n");
|
|
|
|
let formData = requestBodyLines[requestBodyLines.length - 1].
|
|
|
|
replace(/\+/g, " ").split("&");
|
|
|
|
|
|
|
|
function unescapeText(aText)
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
return decodeURIComponent(aText);
|
|
|
|
}
|
|
|
|
catch (ex) {
|
|
|
|
return decodeURIComponent(unescape(aText));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
let formDataObj = {};
|
|
|
|
for (let i = 0; i < formData.length; i++) {
|
|
|
|
let data = formData[i];
|
|
|
|
let idx = data.indexOf("=");
|
|
|
|
let key = data.substring(0, idx);
|
|
|
|
let value = data.substring(idx + 1);
|
|
|
|
formDataObj[unescapeText(key)] = unescapeText(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
this._appendList("requestFormDataContent", formDataObj);
|
|
|
|
this._displayNode("requestFormData");
|
|
|
|
},
|
|
|
|
|
2010-08-29 04:31:12 +00:00
|
|
|
/**
|
|
|
|
* Displays the response section of the NetworkPanel, sets the response status,
|
|
|
|
* the duration between the start of the request and the receiving of the
|
|
|
|
* response header as well as the response header content on the the NetworkPanel.
|
|
|
|
*
|
|
|
|
* @returns void
|
|
|
|
*/
|
|
|
|
_displayResponseHeader: function NP_displayResponseHeader()
|
|
|
|
{
|
|
|
|
let timing = this.httpActivity.timing;
|
|
|
|
let response = this.httpActivity.response;
|
|
|
|
|
|
|
|
this._appendTextNode("headStatus", response.status);
|
|
|
|
|
|
|
|
let deltaDuration =
|
|
|
|
Math.round((timing.RESPONSE_HEADER - timing.REQUEST_HEADER) / 1000);
|
|
|
|
this._appendTextNode("responseHeadersInfo",
|
|
|
|
this._format("durationMS", [deltaDuration]));
|
|
|
|
|
|
|
|
this._displayNode("responseContainer");
|
|
|
|
this._appendList("responseHeadersContent", response.header);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Displays the respones image section, sets the source of the image displayed
|
|
|
|
* in the image response section to the request URL and the duration between
|
|
|
|
* the receiving of the response header and the end of the request. Once the
|
|
|
|
* image is loaded, the size of the requested image is set.
|
|
|
|
*
|
|
|
|
* @returns void
|
|
|
|
*/
|
|
|
|
_displayResponseImage: function NP_displayResponseImage()
|
|
|
|
{
|
|
|
|
let self = this;
|
|
|
|
let timing = this.httpActivity.timing;
|
|
|
|
let response = this.httpActivity.response;
|
|
|
|
let cached = "";
|
|
|
|
|
|
|
|
if (this._isResponseCached) {
|
|
|
|
cached = "Cached";
|
|
|
|
}
|
|
|
|
|
|
|
|
let imageNode = this.document.getElementById("responseImage" + cached +"Node");
|
|
|
|
imageNode.setAttribute("src", this.httpActivity.url);
|
|
|
|
|
|
|
|
// This function is called to set the imageInfo.
|
|
|
|
function setImageInfo() {
|
|
|
|
let deltaDuration =
|
|
|
|
Math.round((timing.RESPONSE_COMPLETE - timing.RESPONSE_HEADER) / 1000);
|
|
|
|
self._appendTextNode("responseImage" + cached + "Info",
|
|
|
|
self._format("imageSizeDeltaDurationMS", [
|
|
|
|
imageNode.width, imageNode.height, deltaDuration
|
|
|
|
]
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if the image is already loaded.
|
|
|
|
if (imageNode.width != 0) {
|
|
|
|
setImageInfo();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Image is not loaded yet therefore add a load event.
|
|
|
|
imageNode.addEventListener("load", function imageNodeLoad() {
|
|
|
|
imageNode.removeEventListener("load", imageNodeLoad, false);
|
|
|
|
setImageInfo();
|
|
|
|
}, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
this._displayNode("responseImage" + cached);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Displays the response body section, sets the the duration between
|
|
|
|
* the receiving of the response header and the end of the request as well as
|
|
|
|
* the content of the response body on the NetworkPanel.
|
|
|
|
*
|
2010-08-29 04:31:49 +00:00
|
|
|
* @param [optional] string aCachedContent
|
|
|
|
* Cached content for this request. If this argument is set, the
|
|
|
|
* responseBodyCached section is displayed.
|
2010-08-29 04:31:12 +00:00
|
|
|
* @returns void
|
|
|
|
*/
|
2010-08-29 04:31:49 +00:00
|
|
|
_displayResponseBody: function NP_displayResponseBody(aCachedContent)
|
2010-08-29 04:31:12 +00:00
|
|
|
{
|
|
|
|
let timing = this.httpActivity.timing;
|
|
|
|
let response = this.httpActivity.response;
|
2010-08-29 04:31:49 +00:00
|
|
|
let cached = "";
|
|
|
|
if (aCachedContent) {
|
|
|
|
cached = "Cached";
|
|
|
|
}
|
2010-08-29 04:31:12 +00:00
|
|
|
|
|
|
|
let deltaDuration =
|
|
|
|
Math.round((timing.RESPONSE_COMPLETE - timing.RESPONSE_HEADER) / 1000);
|
2010-08-29 04:31:49 +00:00
|
|
|
this._appendTextNode("responseBody" + cached + "Info",
|
2010-08-29 04:31:12 +00:00
|
|
|
this._format("durationMS", [deltaDuration]));
|
|
|
|
|
2010-08-29 04:31:49 +00:00
|
|
|
this._displayNode("responseBody" + cached);
|
|
|
|
this._appendTextNode("responseBody" + cached + "Content",
|
|
|
|
aCachedContent || response.body);
|
2010-08-29 04:31:12 +00:00
|
|
|
},
|
|
|
|
|
2010-10-13 12:05:51 +00:00
|
|
|
/**
|
|
|
|
* Displays the `Unknown Content-Type hint` and sets the duration between the
|
|
|
|
* receiving of the response header on the NetworkPanel.
|
|
|
|
*
|
|
|
|
* @returns void
|
|
|
|
*/
|
|
|
|
_displayResponseBodyUnknownType: function NP_displayResponseBodyUnknownType()
|
|
|
|
{
|
|
|
|
let timing = this.httpActivity.timing;
|
|
|
|
|
|
|
|
this._displayNode("responseBodyUnknownType");
|
|
|
|
let deltaDuration =
|
|
|
|
Math.round((timing.RESPONSE_COMPLETE - timing.RESPONSE_HEADER) / 1000);
|
|
|
|
this._appendTextNode("responseBodyUnknownTypeInfo",
|
|
|
|
this._format("durationMS", [deltaDuration]));
|
|
|
|
|
|
|
|
this._appendTextNode("responseBodyUnknownTypeContent",
|
|
|
|
this._format("responseBodyUnableToDisplay.content", [this._contentType]));
|
|
|
|
},
|
|
|
|
|
2010-08-29 04:31:12 +00:00
|
|
|
/**
|
|
|
|
* Displays the `no response body` section and sets the the duration between
|
|
|
|
* the receiving of the response header and the end of the request.
|
|
|
|
*
|
|
|
|
* @returns void
|
|
|
|
*/
|
|
|
|
_displayNoResponseBody: function NP_displayNoResponseBody()
|
|
|
|
{
|
|
|
|
let timing = this.httpActivity.timing;
|
|
|
|
|
|
|
|
this._displayNode("responseNoBody");
|
|
|
|
let deltaDuration =
|
|
|
|
Math.round((timing.RESPONSE_COMPLETE - timing.RESPONSE_HEADER) / 1000);
|
|
|
|
this._appendTextNode("responseNoBodyInfo",
|
|
|
|
this._format("durationMS", [deltaDuration]));
|
|
|
|
},
|
|
|
|
|
2010-08-29 04:31:49 +00:00
|
|
|
/*
|
|
|
|
* Calls the isDoneCallback function if one is specified.
|
|
|
|
*/
|
|
|
|
_callIsDone: function() {
|
|
|
|
if (this.isDoneCallback) {
|
|
|
|
this.isDoneCallback();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2010-08-29 04:31:12 +00:00
|
|
|
/**
|
2010-10-19 12:42:47 +00:00
|
|
|
* Updates the content of the NetworkPanel's iframe.
|
2010-08-29 04:31:12 +00:00
|
|
|
*
|
|
|
|
* @returns void
|
|
|
|
*/
|
|
|
|
update: function NP_update()
|
|
|
|
{
|
|
|
|
/**
|
2010-10-19 12:42:47 +00:00
|
|
|
* After the iframe's contentWindow is ready, the document object is set.
|
2010-08-29 04:31:12 +00:00
|
|
|
* If the document object isn't set yet, then the page is loaded and nothing
|
|
|
|
* can be updated.
|
|
|
|
*/
|
|
|
|
if (!this.document) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let timing = this.httpActivity.timing;
|
|
|
|
let request = this.httpActivity.request;
|
|
|
|
let response = this.httpActivity.response;
|
|
|
|
|
|
|
|
switch (this._state) {
|
|
|
|
case this._INIT:
|
|
|
|
this._displayRequestHeader();
|
|
|
|
this._state = this._DISPLAYED_REQUEST_HEADER;
|
|
|
|
// FALL THROUGH
|
|
|
|
|
|
|
|
case this._DISPLAYED_REQUEST_HEADER:
|
|
|
|
// Process the request body if there is one.
|
2010-09-22 00:00:15 +00:00
|
|
|
if (!request.bodyDiscarded && request.body) {
|
2010-08-29 04:31:33 +00:00
|
|
|
// Check if we send some form data. If so, display the form data special.
|
|
|
|
if (this._isRequestBodyFormData) {
|
|
|
|
this._displayRequestForm();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
this._displayRequestBody();
|
|
|
|
}
|
2010-08-29 04:31:12 +00:00
|
|
|
this._state = this._DISPLAYED_REQUEST_BODY;
|
|
|
|
}
|
|
|
|
// FALL THROUGH
|
|
|
|
|
|
|
|
case this._DISPLAYED_REQUEST_BODY:
|
|
|
|
// There is always a response header. Therefore we can skip here if
|
|
|
|
// we don't have a response header yet and don't have to try updating
|
|
|
|
// anything else in the NetworkPanel.
|
|
|
|
if (!response.header) {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
this._displayResponseHeader();
|
|
|
|
this._state = this._DISPLAYED_RESPONSE_HEADER;
|
|
|
|
// FALL THROUGH
|
|
|
|
|
|
|
|
case this._DISPLAYED_RESPONSE_HEADER:
|
|
|
|
// Check if the transition is done.
|
|
|
|
if (timing.TRANSACTION_CLOSE && response.isDone) {
|
2010-09-22 00:00:15 +00:00
|
|
|
if (response.bodyDiscarded) {
|
|
|
|
this._callIsDone();
|
|
|
|
}
|
|
|
|
else if (this._responseIsImage) {
|
2010-08-29 04:31:12 +00:00
|
|
|
this._displayResponseImage();
|
2010-08-29 04:31:49 +00:00
|
|
|
this._callIsDone();
|
2010-08-29 04:31:12 +00:00
|
|
|
}
|
2010-10-13 12:05:51 +00:00
|
|
|
else if (!this._isResponseBodyTextData) {
|
|
|
|
this._displayResponseBodyUnknownType();
|
|
|
|
this._callIsDone();
|
|
|
|
}
|
2010-08-29 04:31:12 +00:00
|
|
|
else if (response.body) {
|
|
|
|
this._displayResponseBody();
|
2010-08-29 04:31:49 +00:00
|
|
|
this._callIsDone();
|
|
|
|
}
|
|
|
|
else if (this._isResponseCached) {
|
|
|
|
let self = this;
|
|
|
|
NetworkHelper.loadFromCache(this.httpActivity.url,
|
|
|
|
this.httpActivity.charset,
|
|
|
|
function(aContent) {
|
|
|
|
// If some content could be loaded from the cache, then display
|
|
|
|
// the body.
|
|
|
|
if (aContent) {
|
|
|
|
self._displayResponseBody(aContent);
|
|
|
|
self._callIsDone();
|
|
|
|
}
|
|
|
|
// Otherwise, show the "There is no response body" hint.
|
|
|
|
else {
|
|
|
|
self._displayNoResponseBody();
|
|
|
|
self._callIsDone();
|
|
|
|
}
|
|
|
|
});
|
2010-08-29 04:31:12 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
this._displayNoResponseBody();
|
2010-08-29 04:31:49 +00:00
|
|
|
this._callIsDone();
|
2010-08-29 04:31:12 +00:00
|
|
|
}
|
|
|
|
this._state = this._TRANSITION_CLOSED;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-09 00:08:58 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
//// Private utility functions for the HUD service
|
|
|
|
|
|
|
|
/**
|
2011-05-19 20:15:36 +00: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.
|
2010-09-09 00:08:58 +00:00
|
|
|
*
|
2011-07-01 20:20:09 +00:00
|
|
|
* @param aHUDId aHUDId
|
|
|
|
* The HeadsUpDisplay ID.
|
2011-05-19 20:15:36 +00:00
|
|
|
* @param integer aCategory
|
|
|
|
* The category of message nodes to limit.
|
2010-12-23 15:59:19 +00:00
|
|
|
* @return number
|
|
|
|
* The current user-selected log limit.
|
2010-09-09 00:08:58 +00:00
|
|
|
*/
|
2011-07-01 20:20:09 +00:00
|
|
|
function pruneConsoleOutputIfNecessary(aHUDId, aCategory)
|
2010-09-09 00:08:58 +00:00
|
|
|
{
|
2010-12-23 15:59:19 +00:00
|
|
|
// Get the log limit, either from the pref or from the constant.
|
2010-09-09 00:08:58 +00:00
|
|
|
let logLimit;
|
|
|
|
try {
|
2011-05-19 20:15:36 +00:00
|
|
|
let prefName = CATEGORY_CLASS_FRAGMENTS[aCategory];
|
|
|
|
logLimit = Services.prefs.getIntPref("devtools.hud.loglimit." + prefName);
|
2010-09-09 00:08:58 +00:00
|
|
|
} catch (e) {
|
|
|
|
logLimit = DEFAULT_LOG_LIMIT;
|
|
|
|
}
|
|
|
|
|
2011-07-01 20:20:09 +00:00
|
|
|
let hudRef = HUDService.getHudReferenceById(aHUDId);
|
|
|
|
let outputNode = hudRef.outputNode;
|
|
|
|
|
|
|
|
let scrollBox = outputNode.scrollBoxObject.element;
|
2011-01-12 15:56:02 +00:00
|
|
|
let oldScrollHeight = scrollBox.scrollHeight;
|
2011-07-01 20:20:09 +00:00
|
|
|
let scrolledToBottom = ConsoleUtils.isOutputScrolledToBottom(outputNode);
|
2011-01-12 15:56:02 +00:00
|
|
|
|
2010-12-23 15:59:19 +00:00
|
|
|
// Prune the nodes.
|
2011-07-01 20:20:09 +00:00
|
|
|
let messageNodes = outputNode.querySelectorAll(".webconsole-msg-" +
|
2011-05-19 20:15:36 +00:00
|
|
|
CATEGORY_CLASS_FRAGMENTS[aCategory]);
|
2011-01-12 15:56:02 +00:00
|
|
|
let removeNodes = messageNodes.length - logLimit;
|
|
|
|
for (let i = 0; i < removeNodes; i++) {
|
2012-05-10 13:15:10 +00:00
|
|
|
let node = messageNodes[i];
|
|
|
|
if (node._evalCacheId && !node._panelOpen) {
|
|
|
|
hudRef.jsterm.clearObjectCache(node._evalCacheId);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (node.classList.contains("webconsole-msg-cssparser")) {
|
2011-02-25 22:12:42 +00:00
|
|
|
let desc = messageNodes[i].childNodes[2].textContent;
|
2011-03-28 20:19:37 +00:00
|
|
|
let location = "";
|
2012-05-10 13:15:10 +00:00
|
|
|
if (node.childNodes[4]) {
|
|
|
|
location = node.childNodes[4].getAttribute("title");
|
2011-03-28 20:19:37 +00:00
|
|
|
}
|
2011-02-25 22:12:42 +00:00
|
|
|
delete hudRef.cssNodes[desc + location];
|
|
|
|
}
|
2012-05-10 13:15:10 +00:00
|
|
|
else if (node.classList.contains("webconsole-msg-inspector")) {
|
|
|
|
hudRef.pruneConsoleDirNode(node);
|
2011-06-09 13:27:30 +00:00
|
|
|
continue;
|
|
|
|
}
|
2012-05-10 13:15:10 +00:00
|
|
|
|
|
|
|
node.parentNode.removeChild(node);
|
2010-09-09 00:08:58 +00:00
|
|
|
}
|
2010-12-23 15:59:19 +00:00
|
|
|
|
2011-01-12 15:56:02 +00:00
|
|
|
if (!scrolledToBottom && removeNodes > 0 &&
|
|
|
|
oldScrollHeight != scrollBox.scrollHeight) {
|
|
|
|
scrollBox.scrollTop -= oldScrollHeight - scrollBox.scrollHeight;
|
|
|
|
}
|
|
|
|
|
2010-12-23 15:59:19 +00:00
|
|
|
return logLimit;
|
2010-09-09 00:08:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
//// The HUD service
|
|
|
|
|
2010-06-22 16:51:50 +00:00
|
|
|
function HUD_SERVICE()
|
|
|
|
{
|
|
|
|
// TODO: provide mixins for FENNEC: bug 568621
|
|
|
|
if (appName() == "FIREFOX") {
|
|
|
|
var mixins = new FirefoxApplicationHooks();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
throw new Error("Unsupported Application");
|
|
|
|
}
|
|
|
|
|
|
|
|
this.mixins = mixins;
|
|
|
|
|
2010-09-18 18:43:17 +00:00
|
|
|
// These methods access the "this" object, but they're registered as
|
|
|
|
// event listeners. So we hammer in the "this" binding.
|
|
|
|
this.onTabClose = this.onTabClose.bind(this);
|
|
|
|
this.onWindowUnload = this.onWindowUnload.bind(this);
|
2010-11-20 19:53:14 +00:00
|
|
|
|
|
|
|
// Remembers the last console height, in pixels.
|
|
|
|
this.lastConsoleHeight = Services.prefs.getIntPref("devtools.hud.height");
|
2011-01-19 14:23:07 +00:00
|
|
|
|
|
|
|
// Network response bodies are piped through a buffer of the given size (in
|
|
|
|
// bytes).
|
|
|
|
this.responsePipeSegmentSize =
|
|
|
|
Services.prefs.getIntPref("network.buffer.cache.size");
|
2011-08-03 18:04:30 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Collection of HUDIds that map to the tabs/windows/contexts
|
|
|
|
* that a HeadsUpDisplay can be activated for.
|
|
|
|
*/
|
|
|
|
this.activatedContexts = [];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Collection of outer window IDs mapping to HUD IDs.
|
|
|
|
*/
|
|
|
|
this.windowIds = {};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Each HeadsUpDisplay has a set of filter preferences
|
|
|
|
*/
|
|
|
|
this.filterPrefs = {};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Keeps a reference for each HeadsUpDisplay that is created
|
|
|
|
*/
|
|
|
|
this.hudReferences = {};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Requests that haven't finished yet.
|
|
|
|
*/
|
|
|
|
this.openRequests = {};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Response headers for requests that haven't finished yet.
|
|
|
|
*/
|
|
|
|
this.openResponseHeaders = {};
|
2010-06-22 16:51:50 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
HUD_SERVICE.prototype =
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* getter for UI commands to be used by the frontend
|
|
|
|
*
|
|
|
|
* @returns object
|
|
|
|
*/
|
|
|
|
get consoleUI() {
|
|
|
|
return HeadsUpDisplayUICommands;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The sequencer is a generator (after initialization) that returns unique
|
|
|
|
* integers
|
|
|
|
*/
|
|
|
|
sequencer: null,
|
|
|
|
|
2010-09-22 00:00:15 +00:00
|
|
|
/**
|
|
|
|
* Whether to save the bodies of network requests and responses. Disabled by
|
|
|
|
* default to save memory.
|
|
|
|
*/
|
|
|
|
saveRequestAndResponseBodies: false,
|
|
|
|
|
2010-06-22 16:51:50 +00:00
|
|
|
/**
|
|
|
|
* Tell the HUDService that a HeadsUpDisplay can be activated
|
|
|
|
* for the window or context that has 'aContextDOMId' node id
|
|
|
|
*
|
|
|
|
* @param string aContextDOMId
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
registerActiveContext: function HS_registerActiveContext(aContextDOMId)
|
|
|
|
{
|
|
|
|
this.activatedContexts.push(aContextDOMId);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Firefox-specific current tab getter
|
|
|
|
*
|
|
|
|
* @returns nsIDOMWindow
|
|
|
|
*/
|
|
|
|
currentContext: function HS_currentContext() {
|
|
|
|
return this.mixins.getCurrentContext();
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tell the HUDService that a HeadsUpDisplay should be deactivated
|
|
|
|
*
|
|
|
|
* @param string aContextDOMId
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
unregisterActiveContext: function HS_deregisterActiveContext(aContextDOMId)
|
|
|
|
{
|
|
|
|
var domId = aContextDOMId.split("_")[1];
|
|
|
|
var idx = this.activatedContexts.indexOf(domId);
|
|
|
|
if (idx > -1) {
|
|
|
|
this.activatedContexts.splice(idx, 1);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tells callers that a HeadsUpDisplay can be activated for the context
|
|
|
|
*
|
|
|
|
* @param string aContextDOMId
|
|
|
|
* @return boolean
|
|
|
|
*/
|
|
|
|
canActivateContext: function HS_canActivateContext(aContextDOMId)
|
|
|
|
{
|
|
|
|
var domId = aContextDOMId.split("_")[1];
|
|
|
|
for (var idx in this.activatedContexts) {
|
|
|
|
if (this.activatedContexts[idx] == domId){
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2010-10-12 19:13:34 +00:00
|
|
|
* Activate a HeadsUpDisplay for the given tab context.
|
2010-06-22 16:51:50 +00:00
|
|
|
*
|
2010-10-12 19:13:34 +00:00
|
|
|
* @param Element aContext the tab element.
|
2010-11-20 19:53:14 +00:00
|
|
|
* @param boolean aAnimated animate opening the Web Console?
|
2010-06-22 16:51:50 +00:00
|
|
|
* @returns void
|
|
|
|
*/
|
2010-11-20 19:53:14 +00:00
|
|
|
activateHUDForContext: function HS_activateHUDForContext(aContext, aAnimated)
|
2010-06-22 16:51:50 +00:00
|
|
|
{
|
2010-11-20 19:53:14 +00:00
|
|
|
this.wakeup();
|
|
|
|
|
2010-12-23 17:07:03 +00:00
|
|
|
let window = aContext.linkedBrowser.contentWindow;
|
2012-01-11 14:32:39 +00:00
|
|
|
let chromeDocument = aContext.ownerDocument;
|
|
|
|
let nBox = chromeDocument.defaultView.getNotificationBox(window);
|
2010-12-23 17:07:03 +00:00
|
|
|
this.registerActiveContext(nBox.id);
|
2010-11-20 19:53:14 +00:00
|
|
|
this.windowInitializer(window);
|
|
|
|
|
2011-05-18 11:08:54 +00:00
|
|
|
let hudId = "hud_" + nBox.id;
|
|
|
|
let hudRef = this.hudReferences[hudId];
|
|
|
|
|
|
|
|
if (!aAnimated || hudRef.consolePanel) {
|
|
|
|
this.disableAnimation(hudId);
|
2010-11-20 19:53:14 +00:00
|
|
|
}
|
2011-05-27 12:49:02 +00:00
|
|
|
|
|
|
|
// Create a processing instruction for GCLIs CSS stylesheet, but only if
|
|
|
|
// we don't have one for this document. Also record the context we're
|
|
|
|
// adding this for so we know when to remove it.
|
|
|
|
let procInstr = aContext.ownerDocument.gcliCssProcInstr;
|
|
|
|
if (!procInstr) {
|
|
|
|
procInstr = aContext.ownerDocument.createProcessingInstruction(
|
|
|
|
"xml-stylesheet",
|
|
|
|
"href='chrome://browser/skin/devtools/gcli.css' type='text/css'");
|
|
|
|
procInstr.contexts = [];
|
|
|
|
|
|
|
|
let root = aContext.ownerDocument.getElementsByTagName('window')[0];
|
|
|
|
root.parentNode.insertBefore(procInstr, root);
|
|
|
|
aContext.ownerDocument.gcliCssProcInstr = procInstr;
|
|
|
|
}
|
|
|
|
if (procInstr.contexts.indexOf(hudId) == -1) {
|
|
|
|
procInstr.contexts.push(hudId);
|
|
|
|
}
|
2012-05-10 17:33:54 +00:00
|
|
|
HeadsUpDisplayUICommands.refreshCommand();
|
2010-06-22 16:51:50 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2010-10-12 19:13:34 +00:00
|
|
|
* Deactivate a HeadsUpDisplay for the given tab context.
|
2010-06-22 16:51:50 +00:00
|
|
|
*
|
|
|
|
* @param nsIDOMWindow aContext
|
2010-11-20 19:53:14 +00:00
|
|
|
* @param aAnimated animate closing the web console?
|
2010-06-22 16:51:50 +00:00
|
|
|
* @returns void
|
|
|
|
*/
|
2010-11-20 19:53:14 +00:00
|
|
|
deactivateHUDForContext: function HS_deactivateHUDForContext(aContext, aAnimated)
|
2010-06-22 16:51:50 +00:00
|
|
|
{
|
2011-04-13 20:02:36 +00:00
|
|
|
let browser = aContext.linkedBrowser;
|
|
|
|
let window = browser.contentWindow;
|
2011-05-18 11:08:54 +00:00
|
|
|
let chromeDocument = aContext.ownerDocument;
|
|
|
|
let nBox = chromeDocument.defaultView.getNotificationBox(window);
|
2010-10-12 19:13:34 +00:00
|
|
|
let hudId = "hud_" + nBox.id;
|
2011-05-18 11:08:54 +00:00
|
|
|
let displayNode = chromeDocument.getElementById(hudId);
|
2012-05-10 15:01:37 +00:00
|
|
|
let hudFound = (hudId in this.hudReferences) && displayNode;
|
2010-06-22 16:51:50 +00:00
|
|
|
|
2012-05-10 15:01:37 +00:00
|
|
|
if (hudFound) {
|
2010-11-20 19:53:14 +00:00
|
|
|
if (!aAnimated) {
|
|
|
|
this.storeHeight(hudId);
|
|
|
|
}
|
|
|
|
|
2011-04-13 20:02:36 +00:00
|
|
|
let hud = this.hudReferences[hudId];
|
|
|
|
browser.webProgress.removeProgressListener(hud.progressListener);
|
|
|
|
delete hud.progressListener;
|
|
|
|
|
2011-07-07 15:19:58 +00:00
|
|
|
this.unregisterDisplay(hudId);
|
2011-04-13 20:02:36 +00:00
|
|
|
|
2010-11-20 19:53:14 +00:00
|
|
|
window.focus();
|
2012-05-10 17:33:54 +00:00
|
|
|
HeadsUpDisplayUICommands.refreshCommand();
|
2010-10-12 19:13:34 +00:00
|
|
|
}
|
2011-05-27 12:49:02 +00:00
|
|
|
|
|
|
|
// Remove this context from the list of contexts that need the GCLI CSS
|
|
|
|
// processing instruction and then remove the processing instruction if it
|
|
|
|
// isn't needed any more.
|
|
|
|
let procInstr = aContext.ownerDocument.gcliCssProcInstr;
|
|
|
|
if (procInstr) {
|
|
|
|
procInstr.contexts = procInstr.contexts.filter(function(id) {
|
|
|
|
return id !== hudId;
|
|
|
|
});
|
|
|
|
if (procInstr.contexts.length == 0 && procInstr.parentNode) {
|
|
|
|
procInstr.parentNode.removeChild(procInstr);
|
|
|
|
delete aContext.ownerDocument.gcliCssProcInstr;
|
|
|
|
}
|
|
|
|
}
|
2012-05-10 13:15:10 +00:00
|
|
|
|
2012-05-10 15:01:37 +00:00
|
|
|
if (hudFound) {
|
|
|
|
let id = WebConsoleUtils.supportsString(hudId);
|
|
|
|
Services.obs.notifyObservers(id, "web-console-destroyed", null);
|
|
|
|
}
|
2010-06-22 16:51:50 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* get a unique ID from the sequence generator
|
|
|
|
*
|
|
|
|
* @returns integer
|
|
|
|
*/
|
|
|
|
sequenceId: function HS_sequencerId()
|
|
|
|
{
|
|
|
|
if (!this.sequencer) {
|
|
|
|
this.sequencer = this.createSequencer(-1);
|
|
|
|
}
|
|
|
|
return this.sequencer.next();
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* get the default filter prefs
|
|
|
|
*
|
|
|
|
* @param string aHUDId
|
|
|
|
* @returns JS Object
|
|
|
|
*/
|
|
|
|
getDefaultFilterPrefs: function HS_getDefaultFilterPrefs(aHUDId) {
|
|
|
|
return this.filterPrefs[aHUDId];
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* get the current filter prefs
|
|
|
|
*
|
|
|
|
* @param string aHUDId
|
|
|
|
* @returns JS Object
|
|
|
|
*/
|
|
|
|
getFilterPrefs: function HS_getFilterPrefs(aHUDId) {
|
|
|
|
return this.filterPrefs[aHUDId];
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* get the filter state for a specific toggle button on a heads up display
|
|
|
|
*
|
|
|
|
* @param string aHUDId
|
|
|
|
* @param string aToggleType
|
|
|
|
* @returns boolean
|
|
|
|
*/
|
|
|
|
getFilterState: function HS_getFilterState(aHUDId, aToggleType)
|
|
|
|
{
|
|
|
|
if (!aHUDId) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
var bool = this.filterPrefs[aHUDId][aToggleType];
|
|
|
|
return bool;
|
|
|
|
}
|
|
|
|
catch (ex) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* set the filter state for a specific toggle button on a heads up display
|
|
|
|
*
|
|
|
|
* @param string aHUDId
|
|
|
|
* @param string aToggleType
|
|
|
|
* @param boolean aState
|
|
|
|
* @returns void
|
|
|
|
*/
|
|
|
|
setFilterState: function HS_setFilterState(aHUDId, aToggleType, aState)
|
|
|
|
{
|
|
|
|
this.filterPrefs[aHUDId][aToggleType] = aState;
|
2010-08-18 23:53:49 +00:00
|
|
|
this.adjustVisibilityForMessageType(aHUDId, aToggleType, aState);
|
2011-11-18 18:24:04 +00:00
|
|
|
Services.prefs.setBoolPref(PREFS_PREFIX + aToggleType, aState);
|
2010-08-18 23:53:49 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2010-12-23 15:59:19 +00:00
|
|
|
* Splits the given console messages into groups based on their timestamps.
|
2010-08-18 23:53:49 +00:00
|
|
|
*
|
2010-12-23 15:59:19 +00:00
|
|
|
* @param nsIDOMNode aOutputNode
|
|
|
|
* The output node to alter.
|
2010-08-18 23:53:49 +00:00
|
|
|
* @returns void
|
|
|
|
*/
|
2010-12-23 15:59:19 +00:00
|
|
|
regroupOutput: function HS_regroupOutput(aOutputNode)
|
|
|
|
{
|
|
|
|
// Go through the nodes and adjust the placement of "webconsole-new-group"
|
|
|
|
// classes.
|
|
|
|
|
|
|
|
let nodes = aOutputNode.querySelectorAll(".hud-msg-node" +
|
|
|
|
":not(.hud-filtered-by-string):not(.hud-filtered-by-type)");
|
|
|
|
let lastTimestamp;
|
|
|
|
for (let i = 0; i < nodes.length; i++) {
|
|
|
|
let thisTimestamp = nodes[i].timestamp;
|
|
|
|
if (lastTimestamp != null &&
|
|
|
|
thisTimestamp >= lastTimestamp + NEW_GROUP_DELAY) {
|
|
|
|
nodes[i].classList.add("webconsole-new-group");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
nodes[i].classList.remove("webconsole-new-group");
|
|
|
|
}
|
|
|
|
lastTimestamp = thisTimestamp;
|
|
|
|
}
|
2010-08-18 23:53:49 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Turns the display of log nodes on and off appropriately to reflect the
|
2010-12-23 15:59:19 +00:00
|
|
|
* adjustment of the message type filter named by @aPrefKey.
|
2010-08-18 23:53:49 +00:00
|
|
|
*
|
|
|
|
* @param string aHUDId
|
|
|
|
* The ID of the HUD to alter.
|
2010-12-23 15:59:19 +00:00
|
|
|
* @param string aPrefKey
|
|
|
|
* The preference key for the message type being filtered: one of the
|
|
|
|
* values in the MESSAGE_PREFERENCE_KEYS table.
|
2010-08-18 23:53:49 +00:00
|
|
|
* @param boolean aState
|
|
|
|
* True if the filter named by @aMessageType is being turned on; false
|
|
|
|
* otherwise.
|
|
|
|
* @returns void
|
|
|
|
*/
|
|
|
|
adjustVisibilityForMessageType:
|
2010-12-23 15:59:19 +00:00
|
|
|
function HS_adjustVisibilityForMessageType(aHUDId, aPrefKey, aState)
|
2010-08-18 23:53:49 +00:00
|
|
|
{
|
2011-07-01 16:34:48 +00:00
|
|
|
let outputNode = this.getHudReferenceById(aHUDId).outputNode;
|
2010-08-18 23:53:49 +00:00
|
|
|
let doc = outputNode.ownerDocument;
|
|
|
|
|
2010-12-23 15:59:19 +00:00
|
|
|
// Look for message nodes ("hud-msg-node") with the given preference key
|
|
|
|
// ("hud-msg-error", "hud-msg-cssparser", etc.) and add or remove the
|
|
|
|
// "hud-filtered-by-type" class, which turns on or off the display.
|
2010-11-23 17:02:00 +00:00
|
|
|
|
2010-12-23 15:59:19 +00:00
|
|
|
let xpath = ".//*[contains(@class, 'hud-msg-node') and " +
|
|
|
|
"contains(concat(@class, ' '), 'hud-" + aPrefKey + " ')]";
|
|
|
|
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) {
|
|
|
|
node.classList.remove("hud-filtered-by-type");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
node.classList.add("hud-filtered-by-type");
|
|
|
|
}
|
2010-11-23 17:02:00 +00:00
|
|
|
}
|
2010-12-23 15:59:19 +00:00
|
|
|
|
|
|
|
this.regroupOutput(outputNode);
|
2010-11-23 17:02:00 +00:00
|
|
|
},
|
|
|
|
|
2010-08-18 23:53:53 +00:00
|
|
|
/**
|
2011-02-18 19:46:59 +00:00
|
|
|
* Check that the passed string matches the filter arguments.
|
2010-08-18 23:53:53 +00:00
|
|
|
*
|
2011-02-18 19:46:59 +00:00
|
|
|
* @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
|
2010-08-18 23:53:53 +00:00
|
|
|
*/
|
2011-02-18 19:46:59 +00:00
|
|
|
stringMatchesFilters: function stringMatchesFilters(aString, aFilter)
|
2010-08-18 23:53:53 +00:00
|
|
|
{
|
2011-02-18 19:46:59 +00:00
|
|
|
if (!aFilter || !aString) {
|
|
|
|
return true;
|
2010-08-18 23:53:53 +00:00
|
|
|
}
|
|
|
|
|
2011-02-18 19:46:59 +00:00
|
|
|
let searchStr = aString.toLowerCase();
|
|
|
|
let filterStrings = aFilter.toLowerCase().split(/\s+/);
|
|
|
|
return !filterStrings.some(function (f) {
|
|
|
|
return searchStr.indexOf(f) == -1;
|
|
|
|
});
|
2010-08-18 23:53:53 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Turns the display of log nodes on and off appropriately to reflect the
|
|
|
|
* adjustment of the search string.
|
|
|
|
*
|
|
|
|
* @param string aHUDId
|
|
|
|
* The ID of the HUD to alter.
|
|
|
|
* @param string aSearchString
|
|
|
|
* The new search string.
|
|
|
|
* @returns void
|
|
|
|
*/
|
|
|
|
adjustVisibilityOnSearchStringChange:
|
|
|
|
function HS_adjustVisibilityOnSearchStringChange(aHUDId, aSearchString)
|
|
|
|
{
|
2011-07-01 16:34:48 +00:00
|
|
|
let outputNode = this.getHudReferenceById(aHUDId).outputNode;
|
2010-08-18 23:53:53 +00:00
|
|
|
|
2011-02-18 19:46:59 +00:00
|
|
|
let nodes = outputNode.querySelectorAll(".hud-msg-node");
|
2011-02-18 19:46:59 +00:00
|
|
|
|
2011-02-18 19:46:59 +00:00
|
|
|
for (let i = 0; i < nodes.length; ++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, aSearchString)) {
|
|
|
|
node.classList.remove("hud-filtered-by-string");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
node.classList.add("hud-filtered-by-string");
|
|
|
|
}
|
2010-08-18 23:54:02 +00:00
|
|
|
}
|
2010-11-23 17:02:00 +00:00
|
|
|
|
2010-12-23 15:59:19 +00:00
|
|
|
this.regroupOutput(outputNode);
|
2010-08-18 23:54:02 +00:00
|
|
|
},
|
|
|
|
|
2010-06-22 16:51:50 +00:00
|
|
|
/**
|
2010-11-17 19:21:14 +00:00
|
|
|
* Register a reference of each HeadsUpDisplay that is created
|
2010-06-22 16:51:50 +00:00
|
|
|
*/
|
2010-11-17 19:21:14 +00:00
|
|
|
registerHUDReference:
|
|
|
|
function HS_registerHUDReference(aHUD)
|
2010-06-22 16:51:50 +00:00
|
|
|
{
|
2010-11-17 19:21:14 +00:00
|
|
|
this.hudReferences[aHUD.hudId] = aHUD;
|
2010-06-22 16:51:50 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Register a new Heads Up Display
|
|
|
|
*
|
|
|
|
* @returns void
|
|
|
|
*/
|
2010-12-23 17:07:03 +00:00
|
|
|
registerDisplay: function HS_registerDisplay(aHUDId)
|
2010-06-22 16:51:50 +00:00
|
|
|
{
|
2010-12-23 17:07:03 +00:00
|
|
|
// register a display DOM node Id with the service.
|
|
|
|
if (!aHUDId){
|
2010-06-22 16:51:50 +00:00
|
|
|
throw new Error(ERRORS.MISSING_ARGS);
|
|
|
|
}
|
2011-11-19 17:11:10 +00:00
|
|
|
this.filterPrefs[aHUDId] = {
|
|
|
|
network: Services.prefs.getBoolPref(PREFS_PREFIX + "network"),
|
|
|
|
networkinfo: Services.prefs.getBoolPref(PREFS_PREFIX + "networkinfo"),
|
|
|
|
csserror: Services.prefs.getBoolPref(PREFS_PREFIX + "csserror"),
|
|
|
|
cssparser: Services.prefs.getBoolPref(PREFS_PREFIX + "cssparser"),
|
|
|
|
exception: Services.prefs.getBoolPref(PREFS_PREFIX + "exception"),
|
|
|
|
jswarn: Services.prefs.getBoolPref(PREFS_PREFIX + "jswarn"),
|
|
|
|
error: Services.prefs.getBoolPref(PREFS_PREFIX + "error"),
|
|
|
|
info: Services.prefs.getBoolPref(PREFS_PREFIX + "info"),
|
|
|
|
warn: Services.prefs.getBoolPref(PREFS_PREFIX + "warn"),
|
|
|
|
log: Services.prefs.getBoolPref(PREFS_PREFIX + "log"),
|
|
|
|
};
|
2010-06-22 16:51:50 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* When a display is being destroyed, unregister it first
|
|
|
|
*
|
2011-07-07 15:19:58 +00:00
|
|
|
* @param string aHUDId
|
|
|
|
* The ID of a HUD.
|
2010-06-22 16:51:50 +00:00
|
|
|
* @returns void
|
|
|
|
*/
|
2011-07-07 15:19:58 +00:00
|
|
|
unregisterDisplay: function HS_unregisterDisplay(aHUDId)
|
2010-06-22 16:51:50 +00:00
|
|
|
{
|
2011-07-07 15:19:58 +00:00
|
|
|
let hud = this.getHudReferenceById(aHUDId);
|
|
|
|
|
2010-08-29 04:31:12 +00:00
|
|
|
// Remove children from the output. If the output is not cleared, there can
|
|
|
|
// be leaks as some nodes has node.onclick = function; set and GC can't
|
|
|
|
// remove the nodes then.
|
2011-05-27 12:49:02 +00:00
|
|
|
if (hud.jsterm) {
|
|
|
|
hud.jsterm.clearOutput();
|
|
|
|
}
|
|
|
|
if (hud.gcliterm) {
|
|
|
|
hud.gcliterm.clearOutput();
|
|
|
|
}
|
2010-09-18 18:43:17 +00:00
|
|
|
|
2011-08-03 18:04:30 +00:00
|
|
|
hud.destroy();
|
|
|
|
|
2011-07-07 15:19:58 +00:00
|
|
|
// Make sure that the console panel does not try to call
|
|
|
|
// deactivateHUDForContext() again.
|
|
|
|
hud.consoleWindowUnregisterOnHide = false;
|
|
|
|
|
|
|
|
// Remove the HUDBox and the consolePanel if the Web Console is inside a
|
2011-07-26 20:51:10 +00:00
|
|
|
// floating panel.
|
2011-12-07 14:37:57 +00:00
|
|
|
if (hud.consolePanel && hud.consolePanel.parentNode) {
|
2011-07-07 15:19:58 +00:00
|
|
|
hud.consolePanel.parentNode.removeChild(hud.consolePanel);
|
2011-12-07 14:37:57 +00:00
|
|
|
hud.consolePanel.removeAttribute("hudId");
|
|
|
|
hud.consolePanel = null;
|
2010-06-22 16:51:50 +00:00
|
|
|
}
|
2011-05-18 11:08:54 +00:00
|
|
|
|
2011-12-07 14:37:57 +00:00
|
|
|
hud.HUDBox.parentNode.removeChild(hud.HUDBox);
|
|
|
|
|
2011-07-07 15:19:58 +00:00
|
|
|
if (hud.splitter.parentNode) {
|
|
|
|
hud.splitter.parentNode.removeChild(hud.splitter);
|
|
|
|
}
|
2011-05-18 11:08:54 +00:00
|
|
|
|
2011-05-27 12:49:02 +00:00
|
|
|
if (hud.jsterm) {
|
|
|
|
hud.jsterm.autocompletePopup.destroy();
|
|
|
|
}
|
2011-05-17 15:07:33 +00:00
|
|
|
|
2011-07-07 15:19:58 +00:00
|
|
|
delete this.hudReferences[aHUDId];
|
2010-09-13 17:15:59 +00:00
|
|
|
|
2010-12-23 17:07:03 +00:00
|
|
|
for (let windowID in this.windowIds) {
|
2011-07-07 15:19:58 +00:00
|
|
|
if (this.windowIds[windowID] == aHUDId) {
|
2010-12-23 17:07:03 +00:00
|
|
|
delete this.windowIds[windowID];
|
|
|
|
}
|
2010-06-22 16:51:50 +00:00
|
|
|
}
|
2010-11-20 19:53:14 +00:00
|
|
|
|
2011-07-07 15:19:58 +00:00
|
|
|
this.unregisterActiveContext(aHUDId);
|
2010-11-20 19:53:14 +00:00
|
|
|
|
2011-07-07 15:19:58 +00:00
|
|
|
let popupset = hud.chromeDocument.getElementById("mainPopupSet");
|
|
|
|
let panels = popupset.querySelectorAll("panel[hudId=" + aHUDId + "]");
|
2011-03-25 16:42:09 +00:00
|
|
|
for (let i = 0; i < panels.length; i++) {
|
|
|
|
panels[i].hidePopup();
|
|
|
|
}
|
|
|
|
|
2010-12-23 17:07:03 +00:00
|
|
|
if (Object.keys(this.hudReferences).length == 0) {
|
2011-07-07 15:19:58 +00:00
|
|
|
let autocompletePopup = hud.chromeDocument.
|
2011-05-17 15:07:33 +00:00
|
|
|
getElementById("webConsole_autocompletePopup");
|
|
|
|
if (autocompletePopup) {
|
|
|
|
autocompletePopup.parentNode.removeChild(autocompletePopup);
|
|
|
|
}
|
|
|
|
|
2010-11-20 19:53:14 +00:00
|
|
|
this.suspend();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* "Wake up" the Web Console activity. This is called when the first Web
|
|
|
|
* Console is open. This method initializes the various observers we have.
|
|
|
|
*
|
|
|
|
* @returns void
|
|
|
|
*/
|
|
|
|
wakeup: function HS_wakeup()
|
|
|
|
{
|
2010-12-23 17:07:03 +00:00
|
|
|
if (Object.keys(this.hudReferences).length > 0) {
|
2010-11-20 19:53:14 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// begin observing HTTP traffic
|
|
|
|
this.startHTTPObservation();
|
|
|
|
|
|
|
|
HUDWindowObserver.init();
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Suspend Web Console activity. This is called when all Web Consoles are
|
|
|
|
* closed.
|
|
|
|
*
|
|
|
|
* @returns void
|
|
|
|
*/
|
|
|
|
suspend: function HS_suspend()
|
|
|
|
{
|
|
|
|
activityDistributor.removeObserver(this.httpObserver);
|
|
|
|
delete this.httpObserver;
|
|
|
|
|
2011-01-11 20:34:39 +00:00
|
|
|
Services.obs.removeObserver(this.httpResponseExaminer,
|
|
|
|
"http-on-examine-response");
|
|
|
|
|
|
|
|
this.openRequests = {};
|
|
|
|
this.openResponseHeaders = {};
|
|
|
|
|
2010-11-20 19:53:14 +00:00
|
|
|
delete this.defaultFilterPrefs;
|
|
|
|
|
2011-08-03 18:04:30 +00:00
|
|
|
delete this.lastFinishedRequestCallback;
|
|
|
|
|
2010-11-20 19:53:14 +00:00
|
|
|
HUDWindowObserver.uninit();
|
2010-06-22 16:51:50 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Shutdown all HeadsUpDisplays on xpcom-shutdown
|
|
|
|
*
|
|
|
|
* @returns void
|
|
|
|
*/
|
|
|
|
shutdown: function HS_shutdown()
|
|
|
|
{
|
2010-12-23 17:07:03 +00:00
|
|
|
for (let hudId in this.hudReferences) {
|
2011-05-18 11:08:54 +00:00
|
|
|
this.deactivateHUDForContext(this.hudReferences[hudId].tab, false);
|
2010-06-22 16:51:50 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2010-08-26 16:49:28 +00:00
|
|
|
/**
|
2011-07-01 20:20:09 +00:00
|
|
|
* Returns the HeadsUpDisplay object associated to a content window.
|
2010-08-26 16:49:28 +00:00
|
|
|
*
|
|
|
|
* @param nsIDOMWindow aContentWindow
|
2011-07-01 20:20:09 +00:00
|
|
|
* @returns object
|
2010-08-26 16:49:28 +00:00
|
|
|
*/
|
2011-07-01 20:20:09 +00:00
|
|
|
getHudByWindow: function HS_getHudByWindow(aContentWindow)
|
2010-08-26 16:49:28 +00:00
|
|
|
{
|
2011-07-01 20:20:09 +00:00
|
|
|
let hudId = this.getHudIdByWindow(aContentWindow);
|
|
|
|
return hudId ? this.hudReferences[hudId] : null;
|
2010-08-26 16:49:28 +00:00
|
|
|
},
|
|
|
|
|
2011-02-25 22:12:42 +00:00
|
|
|
/**
|
2011-07-01 20:20:09 +00:00
|
|
|
* Returns the hudId that is corresponding to the hud activated for the
|
|
|
|
* passed aContentWindow. If there is no matching hudId null is returned.
|
2011-02-25 22:12:42 +00:00
|
|
|
*
|
2011-07-01 20:20:09 +00:00
|
|
|
* @param nsIDOMWindow aContentWindow
|
|
|
|
* @returns string or null
|
2011-02-25 22:12:42 +00:00
|
|
|
*/
|
2011-07-01 20:20:09 +00:00
|
|
|
getHudIdByWindow: function HS_getHudIdByWindow(aContentWindow)
|
2011-02-25 22:12:42 +00:00
|
|
|
{
|
2012-05-10 13:15:10 +00:00
|
|
|
let windowId = WebConsoleUtils.getOuterWindowId(aContentWindow);
|
2011-07-01 20:20:09 +00:00
|
|
|
return this.getHudIdByWindowId(windowId);
|
2011-02-25 22:12:42 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the hudReference for a given id.
|
|
|
|
*
|
|
|
|
* @param string aId
|
|
|
|
* @returns Object
|
|
|
|
*/
|
|
|
|
getHudReferenceById: function HS_getHudReferenceById(aId)
|
|
|
|
{
|
|
|
|
return aId in this.hudReferences ? this.hudReferences[aId] : null;
|
|
|
|
},
|
|
|
|
|
2010-06-22 16:51:50 +00:00
|
|
|
/**
|
2010-12-23 17:07:03 +00:00
|
|
|
* Returns the hudId that is corresponding to the given outer window ID.
|
|
|
|
*
|
|
|
|
* @param number aWindowId
|
|
|
|
* the outer window ID
|
|
|
|
* @returns string the hudId
|
2010-06-22 16:51:50 +00:00
|
|
|
*/
|
2010-12-23 17:07:03 +00:00
|
|
|
getHudIdByWindowId: function HS_getHudIdByWindowId(aWindowId)
|
2010-06-22 16:51:50 +00:00
|
|
|
{
|
2010-12-23 17:07:03 +00:00
|
|
|
return this.windowIds[aWindowId];
|
2010-06-22 16:51:50 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2011-02-25 22:12:42 +00:00
|
|
|
* Get the current filter string for the HeadsUpDisplay
|
2010-06-22 16:51:50 +00:00
|
|
|
*
|
|
|
|
* @param string aHUDId
|
|
|
|
* @returns string
|
|
|
|
*/
|
|
|
|
getFilterStringByHUDId: function HS_getFilterStringbyHUDId(aHUDId) {
|
2011-07-01 16:32:25 +00:00
|
|
|
return this.getHudReferenceById(aHUDId).filterBox.value;
|
2010-06-22 16:51:50 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update the filter text in the internal tracking object for all
|
|
|
|
* filter strings
|
|
|
|
*
|
|
|
|
* @param nsIDOMNode aTextBoxNode
|
|
|
|
* @returns void
|
|
|
|
*/
|
|
|
|
updateFilterText: function HS_updateFiltertext(aTextBoxNode)
|
|
|
|
{
|
2010-08-18 23:53:53 +00:00
|
|
|
var hudId = aTextBoxNode.getAttribute("hudId");
|
|
|
|
this.adjustVisibilityOnSearchStringChange(hudId, aTextBoxNode.value);
|
2010-06-22 16:51:50 +00:00
|
|
|
},
|
|
|
|
|
2010-09-13 17:13:54 +00:00
|
|
|
/**
|
|
|
|
* Inform user that the Web Console API has been replaced by a script
|
|
|
|
* in a content page.
|
|
|
|
*
|
|
|
|
* @param string aHUDId
|
2010-12-23 15:59:19 +00:00
|
|
|
* The ID of the Web Console to which to send the message.
|
|
|
|
* @return void
|
2010-09-13 17:13:54 +00:00
|
|
|
*/
|
|
|
|
logWarningAboutReplacedAPI:
|
|
|
|
function HS_logWarningAboutReplacedAPI(aHUDId)
|
|
|
|
{
|
2010-12-23 15:59:19 +00:00
|
|
|
let hud = this.hudReferences[aHUDId];
|
|
|
|
let chromeDocument = hud.HUDBox.ownerDocument;
|
|
|
|
let message = stringBundle.GetStringFromName("ConsoleAPIDisabled");
|
2011-01-27 06:22:58 +00:00
|
|
|
let node = ConsoleUtils.createMessageNode(chromeDocument, CATEGORY_JS,
|
2011-06-14 11:38:11 +00:00
|
|
|
SEVERITY_WARNING, message,
|
|
|
|
aHUDId);
|
2010-12-23 15:59:19 +00:00
|
|
|
ConsoleUtils.outputMessageNode(node, aHUDId);
|
|
|
|
},
|
2010-09-13 17:13:54 +00:00
|
|
|
|
2010-06-22 16:51:50 +00:00
|
|
|
/**
|
|
|
|
* Register a Gecko app's specialized ApplicationHooks object
|
|
|
|
*
|
|
|
|
* @returns void or throws "UNSUPPORTED APPLICATION" error
|
|
|
|
*/
|
|
|
|
registerApplicationHooks:
|
|
|
|
function HS_registerApplications(aAppName, aHooksObject)
|
|
|
|
{
|
|
|
|
switch(aAppName) {
|
|
|
|
case "FIREFOX":
|
|
|
|
this.applicationHooks = aHooksObject;
|
|
|
|
return;
|
|
|
|
default:
|
|
|
|
throw new Error("MOZ APPLICATION UNSUPPORTED");
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Registry of ApplicationHooks used by specified Gecko Apps
|
|
|
|
*
|
|
|
|
* @returns Specific Gecko 'ApplicationHooks' Object/Mixin
|
|
|
|
*/
|
|
|
|
applicationHooks: null,
|
|
|
|
|
2010-08-29 04:30:49 +00:00
|
|
|
/**
|
|
|
|
* Assign a function to this property to listen for finished httpRequests.
|
|
|
|
* Used by unit tests.
|
|
|
|
*/
|
|
|
|
lastFinishedRequestCallback: null,
|
|
|
|
|
2010-08-29 04:31:12 +00:00
|
|
|
/**
|
|
|
|
* Opens a NetworkPanel.
|
|
|
|
*
|
|
|
|
* @param nsIDOMNode aNode
|
|
|
|
* DOMNode to display the panel next to.
|
|
|
|
* @param object aHttpActivity
|
|
|
|
* httpActivity object. The data of this object is displayed in the
|
|
|
|
* NetworkPanel.
|
|
|
|
* @returns NetworkPanel
|
|
|
|
*/
|
2010-11-16 21:34:53 +00:00
|
|
|
openNetworkPanel: function HS_openNetworkPanel(aNode, aHttpActivity)
|
|
|
|
{
|
2010-08-29 04:31:12 +00:00
|
|
|
let doc = aNode.ownerDocument;
|
|
|
|
let parent = doc.getElementById("mainPopupSet");
|
|
|
|
let netPanel = new NetworkPanel(parent, aHttpActivity);
|
2010-10-11 21:37:34 +00:00
|
|
|
netPanel.linkNode = aNode;
|
2010-08-29 04:31:12 +00:00
|
|
|
|
|
|
|
let panel = netPanel.panel;
|
|
|
|
panel.openPopup(aNode, "after_pointer", 0, 0, false, false);
|
2011-01-04 17:47:34 +00:00
|
|
|
panel.sizeTo(450, 500);
|
2011-03-25 16:42:09 +00:00
|
|
|
panel.setAttribute("hudId", aHttpActivity.hudId);
|
2010-08-29 04:31:12 +00:00
|
|
|
aHttpActivity.panels.push(Cu.getWeakReference(netPanel));
|
|
|
|
return netPanel;
|
|
|
|
},
|
|
|
|
|
2010-06-22 16:51:50 +00:00
|
|
|
/**
|
|
|
|
* Begin observing HTTP traffic that we care about,
|
|
|
|
* namely traffic that originates inside any context that a Heads Up Display
|
|
|
|
* is active for.
|
|
|
|
*/
|
|
|
|
startHTTPObservation: function HS_httpObserverFactory()
|
|
|
|
{
|
|
|
|
// creates an observer for http traffic
|
|
|
|
var self = this;
|
|
|
|
var httpObserver = {
|
|
|
|
observeActivity :
|
2010-11-16 21:34:53 +00:00
|
|
|
function HS_SHO_observeActivity(aChannel,
|
|
|
|
aActivityType,
|
|
|
|
aActivitySubtype,
|
|
|
|
aTimestamp,
|
|
|
|
aExtraSizeData,
|
|
|
|
aExtraStringData)
|
2010-06-22 16:51:50 +00:00
|
|
|
{
|
|
|
|
if (aActivityType ==
|
2010-08-29 04:30:49 +00:00
|
|
|
activityDistributor.ACTIVITY_TYPE_HTTP_TRANSACTION ||
|
|
|
|
aActivityType ==
|
|
|
|
activityDistributor.ACTIVITY_TYPE_SOCKET_TRANSPORT) {
|
2010-06-22 16:51:50 +00:00
|
|
|
|
|
|
|
aChannel = aChannel.QueryInterface(Ci.nsIHttpChannel);
|
|
|
|
|
2010-08-29 04:30:49 +00:00
|
|
|
let transCodes = this.httpTransactionCodes;
|
|
|
|
let hudId;
|
2010-06-22 16:51:50 +00:00
|
|
|
|
|
|
|
if (aActivitySubtype ==
|
|
|
|
activityDistributor.ACTIVITY_SUBTYPE_REQUEST_HEADER ) {
|
2010-08-26 16:49:28 +00:00
|
|
|
// Try to get the source window of the request.
|
|
|
|
let win = NetworkHelper.getWindowForRequest(aChannel);
|
|
|
|
if (!win) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Try to get the hudId that is associated to the window.
|
2010-12-23 17:07:03 +00:00
|
|
|
hudId = self.getHudIdByWindow(win.top);
|
2010-08-26 16:49:28 +00:00
|
|
|
if (!hudId) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-08-29 04:30:49 +00:00
|
|
|
// The httpActivity object will hold all information concerning
|
|
|
|
// this request and later response.
|
2010-11-16 21:34:53 +00:00
|
|
|
|
2010-08-29 04:30:49 +00:00
|
|
|
let httpActivity = {
|
|
|
|
id: self.sequenceId(),
|
|
|
|
hudId: hudId,
|
|
|
|
url: aChannel.URI.spec,
|
|
|
|
method: aChannel.requestMethod,
|
2010-08-26 16:49:28 +00:00
|
|
|
channel: aChannel,
|
2010-08-29 04:31:49 +00:00
|
|
|
charset: win.document.characterSet,
|
2010-08-29 04:30:49 +00:00
|
|
|
|
2010-08-29 04:31:12 +00:00
|
|
|
panels: [],
|
2010-08-29 04:30:49 +00:00
|
|
|
request: {
|
|
|
|
header: { }
|
|
|
|
},
|
|
|
|
response: {
|
|
|
|
header: null
|
|
|
|
},
|
|
|
|
timing: {
|
|
|
|
"REQUEST_HEADER": aTimestamp
|
|
|
|
}
|
2010-08-26 16:49:28 +00:00
|
|
|
};
|
|
|
|
|
2010-08-29 04:30:49 +00:00
|
|
|
// Add a new output entry.
|
2010-12-23 15:59:19 +00:00
|
|
|
let loggedNode = self.logNetActivity(httpActivity);
|
2010-08-29 04:30:49 +00:00
|
|
|
|
|
|
|
// In some cases loggedNode can be undefined (e.g. if an image was
|
|
|
|
// requested). Don't continue in such a case.
|
|
|
|
if (!loggedNode) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
aChannel.QueryInterface(Ci.nsITraceableChannel);
|
2011-01-19 14:23:07 +00:00
|
|
|
|
|
|
|
// The response will be written into the outputStream of this pipe.
|
|
|
|
// This allows us to buffer the data we are receiving and read it
|
|
|
|
// asynchronously.
|
|
|
|
// Both ends of the pipe must be blocking.
|
|
|
|
let sink = Cc["@mozilla.org/pipe;1"].createInstance(Ci.nsIPipe);
|
|
|
|
|
|
|
|
// The streams need to be blocking because this is required by the
|
|
|
|
// stream tee.
|
|
|
|
sink.init(false, false, HUDService.responsePipeSegmentSize,
|
|
|
|
PR_UINT32_MAX, null);
|
|
|
|
|
2011-08-03 18:04:30 +00:00
|
|
|
// Add listener for the response body.
|
|
|
|
let newListener = new ResponseListener(httpActivity);
|
|
|
|
|
2011-01-19 14:23:07 +00:00
|
|
|
// Remember the input stream, so it isn't released by GC.
|
|
|
|
newListener.inputStream = sink.inputStream;
|
2011-08-03 18:04:30 +00:00
|
|
|
newListener.sink = sink;
|
|
|
|
|
|
|
|
let tee = Cc["@mozilla.org/network/stream-listener-tee;1"].
|
|
|
|
createInstance(Ci.nsIStreamListenerTee);
|
2011-01-19 14:23:07 +00:00
|
|
|
|
|
|
|
let originalListener = aChannel.setNewListener(tee);
|
|
|
|
|
|
|
|
tee.init(originalListener, sink.outputStream, newListener);
|
|
|
|
|
2010-08-29 04:30:49 +00:00
|
|
|
// Copy the request header data.
|
|
|
|
aChannel.visitRequestHeaders({
|
|
|
|
visitHeader: function(aName, aValue) {
|
|
|
|
httpActivity.request.header[aName] = aValue;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// Store the loggedNode and the httpActivity object for later reuse.
|
2011-01-24 16:05:05 +00:00
|
|
|
let linkNode = loggedNode.querySelector(".webconsole-msg-link");
|
2010-12-23 15:59:19 +00:00
|
|
|
|
|
|
|
httpActivity.messageObject = {
|
|
|
|
messageNode: loggedNode,
|
|
|
|
linkNode: linkNode
|
|
|
|
};
|
2010-08-29 04:30:49 +00:00
|
|
|
self.openRequests[httpActivity.id] = httpActivity;
|
2010-08-29 04:31:12 +00:00
|
|
|
|
|
|
|
// Make the network span clickable.
|
|
|
|
linkNode.setAttribute("aria-haspopup", "true");
|
2010-10-11 21:37:34 +00:00
|
|
|
linkNode.addEventListener("mousedown", function(aEvent) {
|
|
|
|
this._startX = aEvent.clientX;
|
|
|
|
this._startY = aEvent.clientY;
|
|
|
|
}, false);
|
|
|
|
|
|
|
|
linkNode.addEventListener("click", function(aEvent) {
|
|
|
|
if (aEvent.detail != 1 || aEvent.button != 0 ||
|
|
|
|
(this._startX != aEvent.clientX &&
|
|
|
|
this._startY != aEvent.clientY)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!this._panelOpen) {
|
|
|
|
self.openNetworkPanel(this, httpActivity);
|
|
|
|
this._panelOpen = true;
|
|
|
|
}
|
|
|
|
}, false);
|
2010-08-29 04:30:49 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Iterate over all currently ongoing requests. If aChannel can't
|
|
|
|
// be found within them, then exit this function.
|
|
|
|
let httpActivity = null;
|
2011-08-03 18:04:30 +00:00
|
|
|
for each (let item in self.openRequests) {
|
2010-08-29 04:30:49 +00:00
|
|
|
if (item.channel !== aChannel) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
httpActivity = item;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!httpActivity) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-11-20 19:53:14 +00:00
|
|
|
hudId = httpActivity.hudId;
|
|
|
|
let msgObject = httpActivity.messageObject;
|
|
|
|
|
|
|
|
let updatePanel = false;
|
2011-01-24 16:05:05 +00:00
|
|
|
let data;
|
2010-08-29 04:30:49 +00:00
|
|
|
// Store the time information for this activity subtype.
|
|
|
|
httpActivity.timing[transCodes[aActivitySubtype]] = aTimestamp;
|
|
|
|
|
|
|
|
switch (aActivitySubtype) {
|
2010-12-23 15:59:19 +00:00
|
|
|
case activityDistributor.ACTIVITY_SUBTYPE_REQUEST_BODY_SENT: {
|
2010-09-22 00:00:15 +00:00
|
|
|
if (!self.saveRequestAndResponseBodies) {
|
|
|
|
httpActivity.request.bodyDiscarded = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-11-20 19:53:14 +00:00
|
|
|
let gBrowser = msgObject.messageNode.ownerDocument.
|
|
|
|
defaultView.gBrowser;
|
|
|
|
let HUD = HUDService.hudReferences[hudId];
|
|
|
|
let browser = gBrowser.
|
|
|
|
getBrowserForDocument(HUD.contentDocument);
|
2010-08-29 04:30:49 +00:00
|
|
|
|
2010-11-20 19:53:14 +00:00
|
|
|
let sentBody = NetworkHelper.
|
|
|
|
readPostTextFromRequest(aChannel, browser);
|
2010-08-29 04:30:49 +00:00
|
|
|
if (!sentBody) {
|
|
|
|
// If the request URL is the same as the current page url, then
|
|
|
|
// we can try to get the posted text from the page directly.
|
2010-08-29 04:31:12 +00:00
|
|
|
// This check is necessary as otherwise the
|
2010-08-29 04:30:49 +00:00
|
|
|
// NetworkHelper.readPostTextFromPage
|
|
|
|
// function is called for image requests as well but these
|
|
|
|
// are not web pages and as such don't store the posted text
|
|
|
|
// in the cache of the webpage.
|
2010-11-20 19:53:14 +00:00
|
|
|
if (httpActivity.url == browser.contentWindow.location.href) {
|
|
|
|
sentBody = NetworkHelper.readPostTextFromPage(browser);
|
2010-08-29 04:30:49 +00:00
|
|
|
}
|
|
|
|
if (!sentBody) {
|
|
|
|
sentBody = "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
httpActivity.request.body = sentBody;
|
|
|
|
break;
|
2010-12-23 15:59:19 +00:00
|
|
|
}
|
2010-08-29 04:30:49 +00:00
|
|
|
|
2010-12-23 15:59:19 +00:00
|
|
|
case activityDistributor.ACTIVITY_SUBTYPE_RESPONSE_HEADER: {
|
2010-08-29 04:30:49 +00:00
|
|
|
// aExtraStringData contains the response header. The first line
|
|
|
|
// contains the response status (e.g. HTTP/1.1 200 OK).
|
|
|
|
//
|
|
|
|
// Note: The response header is not saved here. Calling the
|
|
|
|
// aChannel.visitResponseHeaders at this point sometimes
|
|
|
|
// causes an NS_ERROR_NOT_AVAILABLE exception. Therefore,
|
|
|
|
// the response header and response body is stored on the
|
|
|
|
// httpActivity object within the RL_onStopRequest function.
|
|
|
|
httpActivity.response.status =
|
|
|
|
aExtraStringData.split(/\r\n|\n|\r/)[0];
|
|
|
|
|
2011-01-24 16:05:05 +00:00
|
|
|
// Add the response status.
|
|
|
|
let linkNode = msgObject.linkNode;
|
|
|
|
let statusNode = linkNode.
|
|
|
|
querySelector(".webconsole-msg-status");
|
|
|
|
let statusText = "[" + httpActivity.response.status + "]";
|
|
|
|
statusNode.setAttribute("value", statusText);
|
2010-08-29 04:30:49 +00:00
|
|
|
|
2011-01-24 16:05:05 +00:00
|
|
|
let clipboardTextPieces =
|
|
|
|
[ httpActivity.method, httpActivity.url, statusText ];
|
2010-12-23 15:59:19 +00:00
|
|
|
msgObject.messageNode.clipboardText =
|
2011-01-24 16:05:05 +00:00
|
|
|
clipboardTextPieces.join(" ");
|
2010-08-29 04:30:49 +00:00
|
|
|
|
2010-11-20 19:53:14 +00:00
|
|
|
let status = parseInt(httpActivity.response.status.
|
|
|
|
replace(/^HTTP\/\d\.\d (\d+).+$/, "$1"));
|
|
|
|
|
2010-12-23 15:59:19 +00:00
|
|
|
if (status >= MIN_HTTP_ERROR_CODE &&
|
|
|
|
status < MAX_HTTP_ERROR_CODE) {
|
|
|
|
ConsoleUtils.setMessageType(msgObject.messageNode,
|
|
|
|
CATEGORY_NETWORK,
|
|
|
|
SEVERITY_ERROR);
|
2010-11-20 19:53:14 +00:00
|
|
|
}
|
|
|
|
|
2010-08-29 04:30:49 +00:00
|
|
|
break;
|
2010-12-23 15:59:19 +00:00
|
|
|
}
|
2010-08-29 04:30:49 +00:00
|
|
|
|
2010-12-23 15:59:19 +00:00
|
|
|
case activityDistributor.ACTIVITY_SUBTYPE_TRANSACTION_CLOSE: {
|
2010-08-29 04:30:49 +00:00
|
|
|
let timing = httpActivity.timing;
|
|
|
|
let requestDuration =
|
|
|
|
Math.round((timing.RESPONSE_COMPLETE -
|
|
|
|
timing.REQUEST_HEADER) / 1000);
|
|
|
|
|
2011-01-24 16:05:05 +00:00
|
|
|
// Add the request duration.
|
|
|
|
let linkNode = msgObject.linkNode;
|
|
|
|
let statusNode = linkNode.
|
|
|
|
querySelector(".webconsole-msg-status");
|
|
|
|
|
|
|
|
let statusText = httpActivity.response.status;
|
2012-05-10 13:15:10 +00:00
|
|
|
let timeText = l10n.getFormatStr("NetworkPanel.durationMS",
|
2011-01-24 16:05:05 +00:00
|
|
|
[ requestDuration ]);
|
|
|
|
let fullStatusText = "[" + statusText + " " + timeText + "]";
|
|
|
|
statusNode.setAttribute("value", fullStatusText);
|
|
|
|
|
|
|
|
let clipboardTextPieces =
|
|
|
|
[ httpActivity.method, httpActivity.url, fullStatusText ];
|
2010-12-23 15:59:19 +00:00
|
|
|
msgObject.messageNode.clipboardText =
|
2011-01-24 16:05:05 +00:00
|
|
|
clipboardTextPieces.join(" ");
|
2010-08-29 04:30:49 +00:00
|
|
|
|
2011-08-03 18:04:30 +00:00
|
|
|
delete httpActivity.messageObject;
|
|
|
|
delete self.openRequests[httpActivity.id];
|
2010-08-29 04:31:12 +00:00
|
|
|
updatePanel = true;
|
2010-08-29 04:30:49 +00:00
|
|
|
break;
|
2010-12-23 15:59:19 +00:00
|
|
|
}
|
2010-08-29 04:30:49 +00:00
|
|
|
}
|
2010-08-29 04:31:12 +00:00
|
|
|
|
|
|
|
if (updatePanel) {
|
|
|
|
httpActivity.panels.forEach(function(weakRef) {
|
|
|
|
let panel = weakRef.get();
|
|
|
|
if (panel) {
|
|
|
|
panel.update();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2010-06-22 16:51:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
httpTransactionCodes: {
|
|
|
|
0x5001: "REQUEST_HEADER",
|
|
|
|
0x5002: "REQUEST_BODY_SENT",
|
|
|
|
0x5003: "RESPONSE_START",
|
|
|
|
0x5004: "RESPONSE_HEADER",
|
|
|
|
0x5005: "RESPONSE_COMPLETE",
|
|
|
|
0x5006: "TRANSACTION_CLOSE",
|
2010-08-29 04:30:49 +00:00
|
|
|
|
|
|
|
0x804b0003: "STATUS_RESOLVING",
|
2011-05-21 10:03:36 +00:00
|
|
|
0x804b000b: "STATUS_RESOLVED",
|
2010-08-29 04:30:49 +00:00
|
|
|
0x804b0007: "STATUS_CONNECTING_TO",
|
|
|
|
0x804b0004: "STATUS_CONNECTED_TO",
|
|
|
|
0x804b0005: "STATUS_SENDING_TO",
|
|
|
|
0x804b000a: "STATUS_WAITING_FOR",
|
|
|
|
0x804b0006: "STATUS_RECEIVING_FROM"
|
2010-06-22 16:51:50 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2010-11-20 19:53:14 +00:00
|
|
|
this.httpObserver = httpObserver;
|
|
|
|
|
2010-06-22 16:51:50 +00:00
|
|
|
activityDistributor.addObserver(httpObserver);
|
2011-01-11 20:34:39 +00:00
|
|
|
|
|
|
|
// This is used to find the correct HTTP response headers.
|
|
|
|
Services.obs.addObserver(this.httpResponseExaminer,
|
|
|
|
"http-on-examine-response", false);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Observe notifications for the http-on-examine-response topic, coming from
|
|
|
|
* the nsIObserver service.
|
|
|
|
*
|
|
|
|
* @param string aTopic
|
|
|
|
* @param nsIHttpChannel aSubject
|
|
|
|
* @returns void
|
|
|
|
*/
|
|
|
|
httpResponseExaminer: function HS_httpResponseExaminer(aSubject, aTopic)
|
|
|
|
{
|
|
|
|
if (aTopic != "http-on-examine-response" ||
|
|
|
|
!(aSubject instanceof Ci.nsIHttpChannel)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let channel = aSubject.QueryInterface(Ci.nsIHttpChannel);
|
|
|
|
let win = NetworkHelper.getWindowForRequest(channel);
|
|
|
|
if (!win) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
let hudId = HUDService.getHudIdByWindow(win);
|
|
|
|
if (!hudId) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let response = {
|
|
|
|
id: HUDService.sequenceId(),
|
|
|
|
hudId: hudId,
|
|
|
|
channel: channel,
|
|
|
|
headers: {},
|
|
|
|
};
|
|
|
|
|
|
|
|
try {
|
|
|
|
channel.visitResponseHeaders({
|
|
|
|
visitHeader: function(aName, aValue) {
|
|
|
|
response.headers[aName] = aValue;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
catch (ex) {
|
|
|
|
delete response.headers;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (response.headers) {
|
|
|
|
HUDService.openResponseHeaders[response.id] = response;
|
|
|
|
}
|
2010-06-22 16:51:50 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2010-11-13 13:27:52 +00:00
|
|
|
* Logs network activity.
|
2010-06-22 16:51:50 +00:00
|
|
|
*
|
|
|
|
* @param object aActivityObject
|
2010-11-13 13:27:52 +00:00
|
|
|
* The activity to log.
|
2010-06-22 16:51:50 +00:00
|
|
|
* @returns void
|
|
|
|
*/
|
2010-12-23 15:59:19 +00:00
|
|
|
logNetActivity: function HS_logNetActivity(aActivityObject)
|
2010-06-22 16:51:50 +00:00
|
|
|
{
|
2010-12-23 15:59:19 +00:00
|
|
|
let hudId = aActivityObject.hudId;
|
|
|
|
let outputNode = this.hudReferences[hudId].outputNode;
|
2010-06-22 16:51:50 +00:00
|
|
|
|
2010-12-23 15:59:19 +00:00
|
|
|
let chromeDocument = outputNode.ownerDocument;
|
2011-07-26 20:51:10 +00:00
|
|
|
let msgNode = chromeDocument.createElementNS(XUL_NS, "hbox");
|
2010-06-22 16:51:50 +00:00
|
|
|
|
2011-07-26 20:51:10 +00:00
|
|
|
let methodNode = chromeDocument.createElementNS(XUL_NS, "label");
|
2011-01-24 16:05:05 +00:00
|
|
|
methodNode.setAttribute("value", aActivityObject.method);
|
|
|
|
methodNode.classList.add("webconsole-msg-body-piece");
|
|
|
|
msgNode.appendChild(methodNode);
|
2010-08-09 18:35:33 +00:00
|
|
|
|
2011-07-26 20:51:10 +00:00
|
|
|
let linkNode = chromeDocument.createElementNS(XUL_NS, "hbox");
|
2011-01-24 16:05:05 +00:00
|
|
|
linkNode.setAttribute("flex", "1");
|
|
|
|
linkNode.classList.add("webconsole-msg-body-piece");
|
|
|
|
linkNode.classList.add("webconsole-msg-link");
|
2010-12-23 15:59:19 +00:00
|
|
|
msgNode.appendChild(linkNode);
|
2010-08-09 18:35:33 +00:00
|
|
|
|
2011-07-26 20:51:10 +00:00
|
|
|
let urlNode = chromeDocument.createElementNS(XUL_NS, "label");
|
2011-01-24 16:05:05 +00:00
|
|
|
urlNode.setAttribute("crop", "center");
|
|
|
|
urlNode.setAttribute("flex", "1");
|
|
|
|
urlNode.setAttribute("title", aActivityObject.url);
|
|
|
|
urlNode.setAttribute("value", aActivityObject.url);
|
|
|
|
urlNode.classList.add("hud-clickable");
|
|
|
|
urlNode.classList.add("webconsole-msg-body-piece");
|
|
|
|
urlNode.classList.add("webconsole-msg-url");
|
|
|
|
linkNode.appendChild(urlNode);
|
|
|
|
|
2011-07-26 20:51:10 +00:00
|
|
|
let statusNode = chromeDocument.createElementNS(XUL_NS, "label");
|
2011-01-24 16:05:05 +00:00
|
|
|
statusNode.setAttribute("value", "");
|
|
|
|
statusNode.classList.add("hud-clickable");
|
|
|
|
statusNode.classList.add("webconsole-msg-body-piece");
|
|
|
|
statusNode.classList.add("webconsole-msg-status");
|
|
|
|
linkNode.appendChild(statusNode);
|
|
|
|
|
2010-12-23 15:59:19 +00:00
|
|
|
let clipboardText = aActivityObject.method + " " + aActivityObject.url;
|
2010-08-09 18:35:33 +00:00
|
|
|
|
2010-12-23 15:59:19 +00:00
|
|
|
let messageNode = ConsoleUtils.createMessageNode(chromeDocument,
|
|
|
|
CATEGORY_NETWORK,
|
|
|
|
SEVERITY_LOG,
|
|
|
|
msgNode,
|
2011-06-14 11:38:11 +00:00
|
|
|
hudId,
|
2010-12-23 15:59:19 +00:00
|
|
|
null,
|
|
|
|
null,
|
|
|
|
clipboardText);
|
2010-08-09 18:35:33 +00:00
|
|
|
|
2010-12-23 15:59:19 +00:00
|
|
|
ConsoleUtils.outputMessageNode(messageNode, aActivityObject.hudId);
|
|
|
|
return messageNode;
|
2010-06-22 16:51:50 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2010-09-13 17:15:59 +00:00
|
|
|
* Initialize the JSTerm object to create a JS Workspace by attaching the UI
|
|
|
|
* into the given parent node, using the mixin.
|
2010-06-22 16:51:50 +00:00
|
|
|
*
|
2010-09-13 17:15:59 +00:00
|
|
|
* @param nsIDOMWindow aContext the context used for evaluating user input
|
|
|
|
* @param nsIDOMNode aParentNode where to attach the JSTerm
|
|
|
|
* @param object aConsole
|
|
|
|
* Console object used within the JSTerm instance to report errors
|
|
|
|
* and log data (by calling console.error(), console.log(), etc).
|
2010-06-22 16:51:50 +00:00
|
|
|
*/
|
2010-09-13 17:15:59 +00:00
|
|
|
initializeJSTerm: function HS_initializeJSTerm(aContext, aParentNode, aConsole)
|
2010-06-22 16:51:50 +00:00
|
|
|
{
|
|
|
|
// create Initial JS Workspace:
|
|
|
|
var context = Cu.getWeakReference(aContext);
|
2010-09-13 17:15:59 +00:00
|
|
|
|
|
|
|
// Attach the UI into the target parent node using the mixin.
|
2010-06-22 16:51:50 +00:00
|
|
|
var firefoxMixin = new JSTermFirefoxMixin(context, aParentNode);
|
2010-09-13 17:15:59 +00:00
|
|
|
var jsTerm = new JSTerm(context, aParentNode, firefoxMixin, aConsole);
|
|
|
|
|
2010-06-22 16:51:50 +00:00
|
|
|
// TODO: injection of additional functionality needs re-thinking/api
|
|
|
|
// see bug 559748
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a generator that always returns a unique number for use in the
|
|
|
|
* indexes
|
|
|
|
*
|
|
|
|
* @returns Generator
|
|
|
|
*/
|
|
|
|
createSequencer: function HS_createSequencer(aInt)
|
|
|
|
{
|
|
|
|
function sequencer(aInt)
|
|
|
|
{
|
|
|
|
while(1) {
|
|
|
|
aInt++;
|
|
|
|
yield aInt;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return sequencer(aInt);
|
|
|
|
},
|
|
|
|
|
2011-01-04 17:32:44 +00:00
|
|
|
// See jsapi.h (JSErrorReport flags):
|
|
|
|
// http://mxr.mozilla.org/mozilla-central/source/js/src/jsapi.h#3429
|
2010-06-22 16:51:50 +00:00
|
|
|
scriptErrorFlags: {
|
2011-01-04 17:32:44 +00:00
|
|
|
0: "error", // JSREPORT_ERROR
|
|
|
|
1: "warn", // JSREPORT_WARNING
|
|
|
|
2: "exception", // JSREPORT_EXCEPTION
|
|
|
|
4: "error", // JSREPORT_STRICT | JSREPORT_ERROR
|
|
|
|
5: "warn", // JSREPORT_STRICT | JSREPORT_WARNING
|
|
|
|
8: "error", // JSREPORT_STRICT_MODE_ERROR
|
|
|
|
13: "warn", // JSREPORT_STRICT_MODE_ERROR | JSREPORT_WARNING | JSREPORT_ERROR
|
2010-06-22 16:51:50 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* replacement strings (L10N)
|
|
|
|
*/
|
|
|
|
scriptMsgLogLevel: {
|
2011-01-04 17:32:44 +00:00
|
|
|
0: "typeError", // JSREPORT_ERROR
|
|
|
|
1: "typeWarning", // JSREPORT_WARNING
|
|
|
|
2: "typeException", // JSREPORT_EXCEPTION
|
|
|
|
4: "typeError", // JSREPORT_STRICT | JSREPORT_ERROR
|
|
|
|
5: "typeStrict", // JSREPORT_STRICT | JSREPORT_WARNING
|
|
|
|
8: "typeError", // JSREPORT_STRICT_MODE_ERROR
|
|
|
|
13: "typeWarning", // JSREPORT_STRICT_MODE_ERROR | JSREPORT_WARNING | JSREPORT_ERROR
|
2010-06-22 16:51:50 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* onTabClose event handler function
|
|
|
|
*
|
|
|
|
* @param aEvent
|
|
|
|
* @returns void
|
|
|
|
*/
|
|
|
|
onTabClose: function HS_onTabClose(aEvent)
|
|
|
|
{
|
2011-04-13 20:02:36 +00:00
|
|
|
this.deactivateHUDForContext(aEvent.target, false);
|
2010-09-18 18:43:17 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called whenever a browser window closes. Cleans up any consoles still
|
|
|
|
* around.
|
|
|
|
*
|
|
|
|
* @param nsIDOMEvent aEvent
|
|
|
|
* The dispatched event.
|
|
|
|
* @returns void
|
|
|
|
*/
|
|
|
|
onWindowUnload: function HS_onWindowUnload(aEvent)
|
|
|
|
{
|
2011-08-03 18:04:30 +00:00
|
|
|
let window = aEvent.target.defaultView;
|
|
|
|
|
|
|
|
window.removeEventListener("unload", this.onWindowUnload, false);
|
|
|
|
|
|
|
|
let gBrowser = window.gBrowser;
|
2010-09-18 18:43:17 +00:00
|
|
|
let tabContainer = gBrowser.tabContainer;
|
|
|
|
|
2011-08-03 18:04:30 +00:00
|
|
|
tabContainer.removeEventListener("TabClose", this.onTabClose, false);
|
|
|
|
|
2010-09-18 18:43:17 +00:00
|
|
|
let tab = tabContainer.firstChild;
|
|
|
|
while (tab != null) {
|
2011-04-13 20:02:36 +00:00
|
|
|
this.deactivateHUDForContext(tab, false);
|
2010-09-18 18:43:17 +00:00
|
|
|
tab = tab.nextSibling;
|
|
|
|
}
|
2011-08-03 18:04:30 +00:00
|
|
|
|
|
|
|
if (window.webConsoleCommandController) {
|
|
|
|
window.controllers.removeController(window.webConsoleCommandController);
|
|
|
|
window.webConsoleCommandController = null;
|
|
|
|
}
|
2010-06-22 16:51:50 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* windowInitializer - checks what Gecko app is running and inits the HUD
|
|
|
|
*
|
|
|
|
* @param nsIDOMWindow aContentWindow
|
|
|
|
* @returns void
|
|
|
|
*/
|
|
|
|
windowInitializer: function HS_WindowInitalizer(aContentWindow)
|
|
|
|
{
|
|
|
|
var xulWindow = aContentWindow.QueryInterface(Ci.nsIInterfaceRequestor)
|
|
|
|
.getInterface(Ci.nsIWebNavigation)
|
2010-07-30 11:30:55 +00:00
|
|
|
.QueryInterface(Ci.nsIDocShell)
|
|
|
|
.chromeEventHandler.ownerDocument.defaultView;
|
|
|
|
|
2012-05-10 13:15:10 +00:00
|
|
|
let xulWindow = WebConsoleUtils.unwrap(xulWindow);
|
2010-07-30 11:30:55 +00:00
|
|
|
|
|
|
|
let docElem = xulWindow.document.documentElement;
|
|
|
|
if (!docElem || docElem.getAttribute("windowtype") != "navigator:browser" ||
|
|
|
|
!xulWindow.gBrowser) {
|
|
|
|
// Do not do anything unless we have a browser window.
|
|
|
|
// This may be a view-source window or other type of non-browser window.
|
|
|
|
return;
|
|
|
|
}
|
2010-06-22 16:51:50 +00:00
|
|
|
|
|
|
|
let gBrowser = xulWindow.gBrowser;
|
|
|
|
|
2010-09-10 18:08:05 +00:00
|
|
|
let _browser = gBrowser.
|
2010-10-20 17:39:44 +00:00
|
|
|
getBrowserForDocument(aContentWindow.top.document);
|
2011-08-17 21:03:41 +00:00
|
|
|
|
|
|
|
// ignore newly created documents that don't belong to a tab's browser
|
|
|
|
if (!_browser) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-06-22 16:51:50 +00:00
|
|
|
let nBox = gBrowser.getNotificationBox(_browser);
|
|
|
|
let nBoxId = nBox.getAttribute("id");
|
|
|
|
let hudId = "hud_" + nBoxId;
|
2011-05-18 11:08:54 +00:00
|
|
|
let windowUI = nBox.ownerDocument.getElementById("console_window_" + hudId);
|
|
|
|
if (windowUI) {
|
|
|
|
// The Web Console popup is already open, no need to continue.
|
2011-06-18 14:42:14 +00:00
|
|
|
if (aContentWindow == aContentWindow.top) {
|
|
|
|
let hud = this.hudReferences[hudId];
|
|
|
|
hud.reattachConsole(aContentWindow);
|
|
|
|
}
|
2011-05-18 11:08:54 +00:00
|
|
|
return;
|
|
|
|
}
|
2010-06-22 16:51:50 +00:00
|
|
|
|
|
|
|
if (!this.canActivateContext(hudId)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-08-03 18:04:30 +00:00
|
|
|
xulWindow.addEventListener("unload", this.onWindowUnload, false);
|
|
|
|
gBrowser.tabContainer.addEventListener("TabClose", this.onTabClose, false);
|
|
|
|
|
2010-12-23 17:07:03 +00:00
|
|
|
this.registerDisplay(hudId);
|
2010-06-22 16:51:50 +00:00
|
|
|
|
2010-09-13 17:15:59 +00:00
|
|
|
let hudNode;
|
|
|
|
let childNodes = nBox.childNodes;
|
2010-06-22 16:51:50 +00:00
|
|
|
|
2010-09-13 17:15:59 +00:00
|
|
|
for (let i = 0; i < childNodes.length; i++) {
|
|
|
|
let id = childNodes[i].getAttribute("id");
|
|
|
|
// `id` is a string with the format "hud_<number>".
|
|
|
|
if (id.split("_")[0] == "hud") {
|
|
|
|
hudNode = childNodes[i];
|
|
|
|
break;
|
2010-06-22 16:51:50 +00:00
|
|
|
}
|
2010-09-13 17:15:59 +00:00
|
|
|
}
|
2010-06-22 16:51:50 +00:00
|
|
|
|
2010-09-13 17:15:59 +00:00
|
|
|
let hud;
|
|
|
|
// If there is no HUD for this tab create a new one.
|
|
|
|
if (!hudNode) {
|
|
|
|
// get nBox object and call new HUD
|
|
|
|
let config = { parentNode: nBox,
|
2012-01-06 19:34:56 +00:00
|
|
|
contentWindow: aContentWindow.top
|
2010-09-13 17:15:59 +00:00
|
|
|
};
|
2010-06-22 16:51:50 +00:00
|
|
|
|
2010-09-13 17:15:59 +00:00
|
|
|
hud = new HeadsUpDisplay(config);
|
2010-06-22 16:51:50 +00:00
|
|
|
|
2010-11-17 19:21:14 +00:00
|
|
|
HUDService.registerHUDReference(hud);
|
2012-05-10 13:15:10 +00:00
|
|
|
let windowId = WebConsoleUtils.getOuterWindowId(aContentWindow.top);
|
2010-12-23 17:07:03 +00:00
|
|
|
this.windowIds[windowId] = hudId;
|
2011-04-13 20:02:36 +00:00
|
|
|
|
|
|
|
hud.progressListener = new ConsoleProgressListener(hudId);
|
|
|
|
|
|
|
|
_browser.webProgress.addProgressListener(hud.progressListener,
|
|
|
|
Ci.nsIWebProgress.NOTIFY_STATE_ALL);
|
2010-06-22 16:51:50 +00:00
|
|
|
}
|
2010-09-13 17:15:59 +00:00
|
|
|
else {
|
2010-11-17 19:21:14 +00:00
|
|
|
hud = this.hudReferences[hudId];
|
2010-11-16 21:34:53 +00:00
|
|
|
if (aContentWindow == aContentWindow.top) {
|
|
|
|
// TODO: name change?? doesn't actually re-attach the console
|
|
|
|
hud.reattachConsole(aContentWindow);
|
|
|
|
}
|
2010-09-13 17:15:59 +00:00
|
|
|
}
|
|
|
|
|
2011-02-08 07:18:18 +00:00
|
|
|
// Need to detect that the console component has been paved over.
|
2012-05-10 13:15:10 +00:00
|
|
|
let consoleObject = WebConsoleUtils.unwrap(aContentWindow).console;
|
2011-02-08 07:18:18 +00:00
|
|
|
if (!("__mozillaConsole__" in consoleObject))
|
2010-09-13 17:15:59 +00:00
|
|
|
this.logWarningAboutReplacedAPI(hudId);
|
|
|
|
|
2010-09-10 18:08:05 +00:00
|
|
|
// register the controller to handle "select all" properly
|
|
|
|
this.createController(xulWindow);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds the command controller to the XUL window if it's not already present.
|
|
|
|
*
|
|
|
|
* @param nsIDOMWindow aWindow
|
|
|
|
* The browser XUL window.
|
|
|
|
* @returns void
|
|
|
|
*/
|
|
|
|
createController: function HUD_createController(aWindow)
|
|
|
|
{
|
2011-08-03 18:04:30 +00:00
|
|
|
if (aWindow.webConsoleCommandController == null) {
|
|
|
|
aWindow.webConsoleCommandController = new CommandController(aWindow);
|
|
|
|
aWindow.controllers.insertControllerAt(0,
|
|
|
|
aWindow.webConsoleCommandController);
|
2010-09-10 18:08:05 +00:00
|
|
|
}
|
2010-11-10 16:10:26 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Animates the Console appropriately.
|
|
|
|
*
|
|
|
|
* @param string aHUDId The ID of the console.
|
|
|
|
* @param string aDirection Whether to animate the console appearing
|
|
|
|
* (ANIMATE_IN) or disappearing (ANIMATE_OUT).
|
|
|
|
* @param function aCallback An optional callback, which will be called with
|
|
|
|
* the "transitionend" event passed as a parameter once the animation
|
|
|
|
* finishes.
|
|
|
|
*/
|
|
|
|
animate: function HS_animate(aHUDId, aDirection, aCallback)
|
|
|
|
{
|
2011-07-01 16:34:48 +00:00
|
|
|
let hudBox = this.getHudReferenceById(aHUDId).HUDBox;
|
2010-11-20 19:53:14 +00:00
|
|
|
if (!hudBox.classList.contains("animated")) {
|
|
|
|
if (aCallback) {
|
|
|
|
aCallback();
|
|
|
|
}
|
2010-11-10 16:10:26 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (aDirection) {
|
|
|
|
case ANIMATE_OUT:
|
|
|
|
hudBox.style.height = 0;
|
|
|
|
break;
|
|
|
|
case ANIMATE_IN:
|
2010-11-20 19:53:14 +00:00
|
|
|
this.resetHeight(aHUDId);
|
2010-11-10 16:10:26 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aCallback) {
|
|
|
|
hudBox.addEventListener("transitionend", aCallback, false);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Disables all animation for a console, for unit testing. After this call,
|
|
|
|
* the console will instantly take on a reasonable height, and the close
|
|
|
|
* animation will not occur.
|
|
|
|
*
|
|
|
|
* @param string aHUDId The ID of the console.
|
|
|
|
*/
|
|
|
|
disableAnimation: function HS_disableAnimation(aHUDId)
|
|
|
|
{
|
2010-11-20 19:53:14 +00:00
|
|
|
let hudBox = HUDService.hudReferences[aHUDId].HUDBox;
|
|
|
|
if (hudBox.classList.contains("animated")) {
|
|
|
|
hudBox.classList.remove("animated");
|
|
|
|
this.resetHeight(aHUDId);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reset the height of the Web Console.
|
|
|
|
*
|
|
|
|
* @param string aHUDId The ID of the Web Console.
|
|
|
|
*/
|
|
|
|
resetHeight: function HS_resetHeight(aHUDId)
|
|
|
|
{
|
|
|
|
let HUD = this.hudReferences[aHUDId];
|
|
|
|
let innerHeight = HUD.contentWindow.innerHeight;
|
2011-05-18 11:08:54 +00:00
|
|
|
let chromeWindow = HUD.chromeDocument.defaultView;
|
|
|
|
if (!HUD.consolePanel) {
|
|
|
|
let splitterStyle = chromeWindow.getComputedStyle(HUD.splitter, null);
|
|
|
|
innerHeight += parseInt(splitterStyle.height) +
|
|
|
|
parseInt(splitterStyle.borderTopWidth) +
|
|
|
|
parseInt(splitterStyle.borderBottomWidth);
|
|
|
|
}
|
2010-11-20 19:53:14 +00:00
|
|
|
|
|
|
|
let boxStyle = chromeWindow.getComputedStyle(HUD.HUDBox, null);
|
|
|
|
innerHeight += parseInt(boxStyle.height) +
|
|
|
|
parseInt(boxStyle.borderTopWidth) +
|
|
|
|
parseInt(boxStyle.borderBottomWidth);
|
|
|
|
|
|
|
|
let height = this.lastConsoleHeight > 0 ? this.lastConsoleHeight :
|
|
|
|
Math.ceil(innerHeight * DEFAULT_CONSOLE_HEIGHT);
|
|
|
|
|
|
|
|
if ((innerHeight - height) < MINIMUM_PAGE_HEIGHT) {
|
|
|
|
height = innerHeight - MINIMUM_PAGE_HEIGHT;
|
|
|
|
}
|
|
|
|
else if (height < MINIMUM_CONSOLE_HEIGHT) {
|
|
|
|
height = MINIMUM_CONSOLE_HEIGHT;
|
|
|
|
}
|
|
|
|
|
|
|
|
HUD.HUDBox.style.height = height + "px";
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remember the height of the given Web Console, such that it can later be
|
|
|
|
* reused when other Web Consoles are open.
|
|
|
|
*
|
|
|
|
* @param string aHUDId The ID of the Web Console.
|
|
|
|
*/
|
|
|
|
storeHeight: function HS_storeHeight(aHUDId)
|
|
|
|
{
|
|
|
|
let hudBox = this.hudReferences[aHUDId].HUDBox;
|
|
|
|
let window = hudBox.ownerDocument.defaultView;
|
|
|
|
let style = window.getComputedStyle(hudBox, null);
|
|
|
|
let height = parseInt(style.height);
|
|
|
|
height += parseInt(style.borderTopWidth);
|
|
|
|
height += parseInt(style.borderBottomWidth);
|
|
|
|
this.lastConsoleHeight = height;
|
|
|
|
|
|
|
|
let pref = Services.prefs.getIntPref("devtools.hud.height");
|
|
|
|
if (pref > -1) {
|
|
|
|
Services.prefs.setIntPref("devtools.hud.height", height);
|
|
|
|
}
|
|
|
|
},
|
2010-12-23 15:59:19 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Copies the selected items to the system clipboard.
|
|
|
|
*
|
|
|
|
* @param nsIDOMNode aOutputNode
|
|
|
|
* The output node.
|
|
|
|
* @returns void
|
|
|
|
*/
|
|
|
|
copySelectedItems: function HS_copySelectedItems(aOutputNode)
|
|
|
|
{
|
|
|
|
// Gather up the selected items and concatenate their clipboard text.
|
|
|
|
|
|
|
|
let strings = [];
|
2011-02-03 17:06:50 +00:00
|
|
|
let newGroup = false;
|
2011-04-19 17:40:36 +00:00
|
|
|
|
|
|
|
let children = aOutputNode.children;
|
|
|
|
|
|
|
|
for (let i = 0; i < children.length; i++) {
|
|
|
|
let item = children[i];
|
|
|
|
if (!item.selected) {
|
|
|
|
continue;
|
|
|
|
}
|
2010-12-23 15:59:19 +00:00
|
|
|
|
2011-03-02 16:02:59 +00:00
|
|
|
// Add dashes between groups so that group boundaries show up in the
|
2010-12-23 15:59:19 +00:00
|
|
|
// copied output.
|
|
|
|
if (i > 0 && item.classList.contains("webconsole-new-group")) {
|
2011-02-03 17:06:50 +00:00
|
|
|
newGroup = true;
|
2010-12-23 15:59:19 +00:00
|
|
|
}
|
|
|
|
|
2011-02-03 17:06:50 +00:00
|
|
|
// Ensure the selected item hasn't been filtered by type or string.
|
|
|
|
if (!item.classList.contains("hud-filtered-by-type") &&
|
|
|
|
!item.classList.contains("hud-filtered-by-string")) {
|
2012-05-10 13:15:10 +00:00
|
|
|
let timestampString = l10n.timestampString(item.timestamp);
|
2011-02-03 17:06:50 +00:00
|
|
|
if (newGroup) {
|
2011-03-02 16:02:59 +00:00
|
|
|
strings.push("--");
|
2011-02-03 17:06:50 +00:00
|
|
|
newGroup = false;
|
|
|
|
}
|
|
|
|
strings.push("[" + timestampString + "] " + item.clipboardText);
|
|
|
|
}
|
2010-12-23 15:59:19 +00:00
|
|
|
}
|
|
|
|
clipboardHelper.copyString(strings.join("\n"));
|
|
|
|
}
|
2010-06-22 16:51:50 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// HeadsUpDisplay
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
/*
|
|
|
|
* HeadsUpDisplay is an interactive console initialized *per tab* that
|
|
|
|
* displays console log data as well as provides an interactive terminal to
|
|
|
|
* manipulate the current tab's document content.
|
|
|
|
* */
|
|
|
|
function HeadsUpDisplay(aConfig)
|
|
|
|
{
|
|
|
|
// sample config: { parentNode: aDOMNode,
|
|
|
|
// // or
|
|
|
|
// parentNodeId: "myHUDParent123",
|
|
|
|
//
|
|
|
|
// placement: "appendChild"
|
|
|
|
// // or
|
|
|
|
// placement: "insertBefore",
|
|
|
|
// placementChildNodeIndex: 0,
|
|
|
|
// }
|
|
|
|
|
|
|
|
this.HUDBox = null;
|
|
|
|
|
|
|
|
if (aConfig.parentNode) {
|
|
|
|
// TODO: need to replace these DOM calls with internal functions
|
|
|
|
// that operate on each application's node structure
|
|
|
|
// better yet, we keep these functions in a "bridgeModule" or the HUDService
|
|
|
|
// to keep a registry of nodeGetters for each application
|
|
|
|
// see bug 568647
|
|
|
|
this.parentNode = aConfig.parentNode;
|
|
|
|
this.notificationBox = aConfig.parentNode;
|
|
|
|
this.chromeDocument = aConfig.parentNode.ownerDocument;
|
|
|
|
this.contentWindow = aConfig.contentWindow;
|
|
|
|
this.uriSpec = aConfig.contentWindow.location.href;
|
|
|
|
this.hudId = "hud_" + aConfig.parentNode.getAttribute("id");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// parentNodeId is the node's id where we attach the HUD
|
|
|
|
// TODO: is the "navigator:browser" below used in all Gecko Apps?
|
|
|
|
// see bug 568647
|
|
|
|
let windowEnum = Services.wm.getEnumerator("navigator:browser");
|
|
|
|
let parentNode;
|
|
|
|
let contentDocument;
|
|
|
|
let contentWindow;
|
|
|
|
let chromeDocument;
|
|
|
|
|
|
|
|
// TODO: the following part is still very Firefox specific
|
|
|
|
// see bug 568647
|
|
|
|
|
|
|
|
while (windowEnum.hasMoreElements()) {
|
|
|
|
let window = windowEnum.getNext();
|
|
|
|
try {
|
|
|
|
let gBrowser = window.gBrowser;
|
|
|
|
let _browsers = gBrowser.browsers;
|
|
|
|
let browserLen = _browsers.length;
|
|
|
|
|
|
|
|
for (var i = 0; i < browserLen; i++) {
|
|
|
|
var _notificationBox = gBrowser.getNotificationBox(_browsers[i]);
|
|
|
|
this.notificationBox = _notificationBox;
|
|
|
|
|
|
|
|
if (_notificationBox.getAttribute("id") == aConfig.parentNodeId) {
|
|
|
|
this.parentNodeId = _notificationBox.getAttribute("id");
|
|
|
|
this.hudId = "hud_" + this.parentNodeId;
|
|
|
|
|
|
|
|
parentNode = _notificationBox;
|
|
|
|
|
|
|
|
this.contentDocument =
|
|
|
|
_notificationBox.childNodes[0].contentDocument;
|
|
|
|
this.contentWindow =
|
|
|
|
_notificationBox.childNodes[0].contentWindow;
|
|
|
|
this.uriSpec = aConfig.contentWindow.location.href;
|
|
|
|
|
|
|
|
this.chromeDocument =
|
|
|
|
_notificationBox.ownerDocument;
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (ex) {
|
|
|
|
Cu.reportError(ex);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (parentNode) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!parentNode) {
|
|
|
|
throw new Error(this.ERRORS.PARENTNODE_NOT_FOUND);
|
|
|
|
}
|
|
|
|
this.parentNode = parentNode;
|
2011-05-18 11:08:54 +00:00
|
|
|
this.notificationBox = parentNode;
|
2010-06-22 16:51:50 +00:00
|
|
|
}
|
|
|
|
|
2010-08-13 17:36:05 +00:00
|
|
|
// create textNode Factory:
|
2010-06-22 16:51:50 +00:00
|
|
|
this.textFactory = NodeFactory("text", "xul", this.chromeDocument);
|
|
|
|
|
2011-07-01 16:43:50 +00:00
|
|
|
this.chromeWindow = this.chromeDocument.defaultView;
|
2012-05-10 13:15:10 +00:00
|
|
|
this.browser = this.tab.linkedBrowser;
|
|
|
|
this.messageManager = this.browser.messageManager;
|
|
|
|
|
|
|
|
// Track callback functions registered for specific async requests sent to the
|
|
|
|
// content process.
|
|
|
|
this.asyncRequests = {};
|
2010-08-10 12:37:29 +00:00
|
|
|
|
2010-06-22 16:51:50 +00:00
|
|
|
// create a panel dynamically and attach to the parentNode
|
2011-05-18 11:08:54 +00:00
|
|
|
this.createHUD();
|
2010-06-22 16:51:50 +00:00
|
|
|
|
2010-08-09 18:35:33 +00:00
|
|
|
this.HUDBox.lastTimestamp = 0;
|
2010-06-22 16:51:50 +00:00
|
|
|
// create the JSTerm input element
|
|
|
|
try {
|
|
|
|
this.createConsoleInput(this.contentWindow, this.consoleWrap, this.outputNode);
|
2011-05-27 12:49:02 +00:00
|
|
|
if (this.jsterm) {
|
|
|
|
this.jsterm.inputNode.focus();
|
|
|
|
}
|
|
|
|
if (this.gcliterm) {
|
|
|
|
this.gcliterm.inputNode.focus();
|
|
|
|
}
|
2010-06-22 16:51:50 +00:00
|
|
|
}
|
|
|
|
catch (ex) {
|
|
|
|
Cu.reportError(ex);
|
|
|
|
}
|
2011-02-25 22:12:42 +00:00
|
|
|
|
|
|
|
// A cache for tracking repeated CSS Nodes.
|
|
|
|
this.cssNodes = {};
|
2012-05-10 13:15:10 +00:00
|
|
|
|
|
|
|
this._setupMessageManager();
|
2010-06-22 16:51:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
HeadsUpDisplay.prototype = {
|
2012-05-10 13:15:10 +00:00
|
|
|
/**
|
|
|
|
* Message names that the HUD listens for. These messages come from the remote
|
|
|
|
* Web Console content script.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @type array
|
|
|
|
*/
|
|
|
|
_messageListeners: ["JSTerm:EvalObject", "WebConsole:ConsoleAPI",
|
2012-05-10 15:01:37 +00:00
|
|
|
"WebConsole:CachedMessages", "WebConsole:PageError"],
|
2010-11-16 21:34:53 +00:00
|
|
|
|
2011-05-18 11:08:54 +00:00
|
|
|
consolePanel: null,
|
|
|
|
|
2011-06-14 11:38:11 +00:00
|
|
|
/**
|
|
|
|
* The nesting depth of the currently active console group.
|
|
|
|
*/
|
|
|
|
groupDepth: 0,
|
|
|
|
|
2011-05-18 11:08:54 +00:00
|
|
|
get mainPopupSet()
|
|
|
|
{
|
|
|
|
return this.chromeDocument.getElementById("mainPopupSet");
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the tab associated to the HeadsUpDisplay object.
|
|
|
|
*/
|
|
|
|
get tab()
|
|
|
|
{
|
2011-07-26 20:51:10 +00:00
|
|
|
// TODO: we should only keep a reference to the tab object and use
|
2011-05-18 11:08:54 +00:00
|
|
|
// getters to determine the rest of objects we need - the chrome window,
|
|
|
|
// document, etc. We should simplify the entire code to use only a single
|
|
|
|
// tab object ref. See bug 656231.
|
|
|
|
let tab = null;
|
|
|
|
let id = this.notificationBox.id;
|
|
|
|
Array.some(this.chromeDocument.defaultView.gBrowser.tabs, function(aTab) {
|
|
|
|
if (aTab.linkedPanel == id) {
|
|
|
|
tab = aTab;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return tab;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a panel to open the web console if it should float above
|
|
|
|
* the content in its own window.
|
|
|
|
*/
|
|
|
|
createOwnWindowPanel: function HUD_createOwnWindowPanel()
|
|
|
|
{
|
|
|
|
if (this.uiInOwnWindow) {
|
|
|
|
return this.consolePanel;
|
|
|
|
}
|
|
|
|
|
|
|
|
let width = 0;
|
|
|
|
try {
|
|
|
|
width = Services.prefs.getIntPref("devtools.webconsole.width");
|
|
|
|
}
|
|
|
|
catch (ex) {}
|
|
|
|
|
|
|
|
if (width < 1) {
|
|
|
|
width = this.HUDBox.clientWidth || this.contentWindow.innerWidth;
|
|
|
|
}
|
|
|
|
|
|
|
|
let height = this.HUDBox.clientHeight;
|
|
|
|
|
|
|
|
let top = 0;
|
|
|
|
try {
|
|
|
|
top = Services.prefs.getIntPref("devtools.webconsole.top");
|
|
|
|
}
|
|
|
|
catch (ex) {}
|
|
|
|
|
|
|
|
let left = 0;
|
|
|
|
try {
|
|
|
|
left = Services.prefs.getIntPref("devtools.webconsole.left");
|
|
|
|
}
|
|
|
|
catch (ex) {}
|
|
|
|
|
|
|
|
let panel = this.chromeDocument.createElementNS(XUL_NS, "panel");
|
|
|
|
|
|
|
|
let config = { id: "console_window_" + this.hudId,
|
2011-06-18 14:42:14 +00:00
|
|
|
label: this.getPanelTitle(),
|
2011-05-18 11:08:54 +00:00
|
|
|
titlebar: "normal",
|
|
|
|
noautohide: "true",
|
|
|
|
norestorefocus: "true",
|
|
|
|
close: "true",
|
|
|
|
flex: "1",
|
|
|
|
hudId: this.hudId,
|
|
|
|
width: width,
|
|
|
|
position: "overlap",
|
|
|
|
top: top,
|
|
|
|
left: left,
|
|
|
|
};
|
|
|
|
|
|
|
|
for (let attr in config) {
|
|
|
|
panel.setAttribute(attr, config[attr]);
|
|
|
|
}
|
|
|
|
|
|
|
|
panel.classList.add("web-console-panel");
|
|
|
|
|
|
|
|
let onPopupShown = (function HUD_onPopupShown() {
|
|
|
|
panel.removeEventListener("popupshown", onPopupShown, false);
|
|
|
|
|
|
|
|
// Make sure that the HUDBox size updates when the panel is resized.
|
|
|
|
|
|
|
|
let height = panel.clientHeight;
|
|
|
|
|
|
|
|
this.HUDBox.style.height = "auto";
|
|
|
|
this.HUDBox.setAttribute("flex", "1");
|
|
|
|
|
|
|
|
panel.setAttribute("height", height);
|
|
|
|
|
|
|
|
// Scroll the outputNode back to the last location.
|
|
|
|
if (lastIndex > -1 && lastIndex < this.outputNode.getRowCount()) {
|
|
|
|
this.outputNode.ensureIndexIsVisible(lastIndex);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.jsterm) {
|
|
|
|
this.jsterm.inputNode.focus();
|
|
|
|
}
|
2011-05-27 12:49:02 +00:00
|
|
|
if (this.gcliterm) {
|
|
|
|
this.gcliterm.inputNode.focus();
|
|
|
|
}
|
2011-05-18 11:08:54 +00:00
|
|
|
}).bind(this);
|
|
|
|
|
|
|
|
panel.addEventListener("popupshown", onPopupShown,false);
|
|
|
|
|
2011-07-28 12:51:00 +00:00
|
|
|
let onPopupHidden = (function HUD_onPopupHidden(aEvent) {
|
2011-05-18 11:08:54 +00:00
|
|
|
if (aEvent.target != panel) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-07-28 12:51:00 +00:00
|
|
|
panel.removeEventListener("popuphidden", onPopupHidden, false);
|
2011-05-18 11:08:54 +00:00
|
|
|
|
|
|
|
let width = 0;
|
|
|
|
try {
|
|
|
|
width = Services.prefs.getIntPref("devtools.webconsole.width");
|
|
|
|
}
|
|
|
|
catch (ex) { }
|
|
|
|
|
2011-07-28 12:51:00 +00:00
|
|
|
if (width > 0) {
|
2011-05-18 11:08:54 +00:00
|
|
|
Services.prefs.setIntPref("devtools.webconsole.width", panel.clientWidth);
|
|
|
|
}
|
|
|
|
|
2011-12-07 14:37:57 +00:00
|
|
|
// Are we destroying the HUD or repositioning it?
|
2011-05-18 11:08:54 +00:00
|
|
|
if (this.consoleWindowUnregisterOnHide) {
|
|
|
|
HUDService.deactivateHUDForContext(this.tab, false);
|
2011-12-07 14:37:57 +00:00
|
|
|
} else {
|
2011-05-18 11:08:54 +00:00
|
|
|
this.consoleWindowUnregisterOnHide = true;
|
|
|
|
}
|
|
|
|
}).bind(this);
|
|
|
|
|
|
|
|
panel.addEventListener("popuphidden", onPopupHidden, false);
|
|
|
|
|
|
|
|
let lastIndex = -1;
|
|
|
|
|
|
|
|
if (this.outputNode.getIndexOfFirstVisibleRow) {
|
|
|
|
lastIndex = this.outputNode.getIndexOfFirstVisibleRow() +
|
|
|
|
this.outputNode.getNumberOfVisibleRows() - 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.splitter.parentNode) {
|
|
|
|
this.splitter.parentNode.removeChild(this.splitter);
|
|
|
|
}
|
|
|
|
panel.appendChild(this.HUDBox);
|
|
|
|
|
|
|
|
let space = this.chromeDocument.createElement("spacer");
|
|
|
|
space.setAttribute("flex", "1");
|
|
|
|
|
|
|
|
let bottomBox = this.chromeDocument.createElement("hbox");
|
|
|
|
space.setAttribute("flex", "1");
|
|
|
|
|
|
|
|
let resizer = this.chromeDocument.createElement("resizer");
|
|
|
|
resizer.setAttribute("dir", "bottomend");
|
|
|
|
resizer.setAttribute("element", config.id);
|
|
|
|
|
|
|
|
bottomBox.appendChild(space);
|
|
|
|
bottomBox.appendChild(resizer);
|
|
|
|
|
|
|
|
panel.appendChild(bottomBox);
|
|
|
|
|
|
|
|
this.mainPopupSet.appendChild(panel);
|
|
|
|
|
|
|
|
Services.prefs.setCharPref("devtools.webconsole.position", "window");
|
|
|
|
|
|
|
|
panel.openPopup(null, "overlay", left, top, false, false);
|
|
|
|
|
|
|
|
this.consolePanel = panel;
|
|
|
|
this.consoleWindowUnregisterOnHide = true;
|
|
|
|
|
|
|
|
return panel;
|
|
|
|
},
|
|
|
|
|
2011-06-18 14:42:14 +00:00
|
|
|
/**
|
|
|
|
* Retrieve the Web Console panel title.
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
* The Web Console panel title.
|
|
|
|
*/
|
|
|
|
getPanelTitle: function HUD_getPanelTitle()
|
|
|
|
{
|
2012-05-10 13:15:10 +00:00
|
|
|
return l10n.getFormatStr("webConsoleWindowTitleAndURL", [this.uriSpec]);
|
2011-06-18 14:42:14 +00:00
|
|
|
},
|
|
|
|
|
2011-05-18 11:08:54 +00:00
|
|
|
positions: {
|
|
|
|
above: 0, // the childNode index
|
|
|
|
below: 2,
|
|
|
|
window: null
|
|
|
|
},
|
|
|
|
|
|
|
|
consoleWindowUnregisterOnHide: true,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Re-position the console
|
|
|
|
*/
|
|
|
|
positionConsole: function HUD_positionConsole(aPosition)
|
|
|
|
{
|
|
|
|
if (!(aPosition in this.positions)) {
|
2011-07-28 12:51:00 +00:00
|
|
|
throw new Error("Incorrect argument: " + aPosition +
|
|
|
|
". Cannot position Web Console");
|
2011-05-18 11:08:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (aPosition == "window") {
|
2011-07-28 12:51:00 +00:00
|
|
|
let closeButton = this.consoleFilterToolbar.
|
|
|
|
querySelector(".webconsole-close-button");
|
|
|
|
closeButton.setAttribute("hidden", "true");
|
2011-05-18 11:08:54 +00:00
|
|
|
this.createOwnWindowPanel();
|
|
|
|
this.positionMenuitems.window.setAttribute("checked", true);
|
|
|
|
if (this.positionMenuitems.last) {
|
|
|
|
this.positionMenuitems.last.setAttribute("checked", false);
|
|
|
|
}
|
|
|
|
this.positionMenuitems.last = this.positionMenuitems[aPosition];
|
|
|
|
this.uiInOwnWindow = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let height = this.HUDBox.clientHeight;
|
|
|
|
|
|
|
|
// get the node position index
|
|
|
|
let nodeIdx = this.positions[aPosition];
|
|
|
|
let nBox = this.notificationBox;
|
|
|
|
let node = nBox.childNodes[nodeIdx];
|
|
|
|
|
|
|
|
// check to see if console is already positioned in aPosition
|
|
|
|
if (node == this.HUDBox) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let lastIndex = -1;
|
|
|
|
|
|
|
|
if (this.outputNode.getIndexOfFirstVisibleRow) {
|
|
|
|
lastIndex = this.outputNode.getIndexOfFirstVisibleRow() +
|
|
|
|
this.outputNode.getNumberOfVisibleRows() - 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// remove the console and splitter and reposition
|
|
|
|
if (this.splitter.parentNode) {
|
|
|
|
this.splitter.parentNode.removeChild(this.splitter);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aPosition == "below") {
|
|
|
|
nBox.appendChild(this.splitter);
|
|
|
|
nBox.appendChild(this.HUDBox);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
nBox.insertBefore(this.splitter, node);
|
|
|
|
nBox.insertBefore(this.HUDBox, this.splitter);
|
|
|
|
}
|
|
|
|
|
|
|
|
this.positionMenuitems[aPosition].setAttribute("checked", true);
|
|
|
|
if (this.positionMenuitems.last) {
|
|
|
|
this.positionMenuitems.last.setAttribute("checked", false);
|
|
|
|
}
|
|
|
|
this.positionMenuitems.last = this.positionMenuitems[aPosition];
|
|
|
|
|
|
|
|
Services.prefs.setCharPref("devtools.webconsole.position", aPosition);
|
|
|
|
|
|
|
|
if (lastIndex > -1 && lastIndex < this.outputNode.getRowCount()) {
|
|
|
|
this.outputNode.ensureIndexIsVisible(lastIndex);
|
|
|
|
}
|
|
|
|
|
2011-07-28 12:51:00 +00:00
|
|
|
let closeButton = this.consoleFilterToolbar.
|
|
|
|
getElementsByClassName("webconsole-close-button")[0];
|
|
|
|
closeButton.removeAttribute("hidden");
|
|
|
|
|
2011-05-18 11:08:54 +00:00
|
|
|
this.uiInOwnWindow = false;
|
|
|
|
if (this.consolePanel) {
|
|
|
|
// must destroy the consolePanel
|
|
|
|
this.consoleWindowUnregisterOnHide = false;
|
|
|
|
this.consolePanel.hidePopup();
|
2011-12-07 14:37:57 +00:00
|
|
|
this.consolePanel.parentNode.removeChild(this.consolePanel);
|
|
|
|
this.consolePanel = null; // remove this as we're not in panel anymore
|
|
|
|
this.HUDBox.removeAttribute("flex");
|
|
|
|
this.HUDBox.removeAttribute("height");
|
|
|
|
this.HUDBox.style.height = height + "px";
|
2011-05-18 11:08:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (this.jsterm) {
|
|
|
|
this.jsterm.inputNode.focus();
|
|
|
|
}
|
2011-05-27 12:49:02 +00:00
|
|
|
if (this.gcliterm) {
|
|
|
|
this.gcliterm.inputNode.focus();
|
|
|
|
}
|
2011-05-18 11:08:54 +00:00
|
|
|
},
|
|
|
|
|
2010-07-16 14:42:53 +00:00
|
|
|
/**
|
|
|
|
* The JSTerm object that contains the console's inputNode
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
jsterm: null,
|
|
|
|
|
2011-05-27 12:49:02 +00:00
|
|
|
/**
|
|
|
|
* The GcliTerm object that contains the console's GCLI
|
|
|
|
*/
|
|
|
|
gcliterm: null,
|
|
|
|
|
2010-06-22 16:51:50 +00:00
|
|
|
/**
|
|
|
|
* creates and attaches the console input node
|
|
|
|
*
|
|
|
|
* @param nsIDOMWindow aWindow
|
|
|
|
* @returns void
|
|
|
|
*/
|
|
|
|
createConsoleInput:
|
|
|
|
function HUD_createConsoleInput(aWindow, aParentNode, aExistingConsole)
|
|
|
|
{
|
2011-05-27 12:49:02 +00:00
|
|
|
let usegcli = false;
|
|
|
|
try {
|
2012-05-10 17:33:54 +00:00
|
|
|
// usegcli = Services.prefs.getBoolPref("devtools.gcli.enable");
|
2011-05-27 12:49:02 +00:00
|
|
|
}
|
|
|
|
catch (ex) {}
|
2010-06-22 16:51:50 +00:00
|
|
|
|
|
|
|
if (appName() == "FIREFOX") {
|
2011-05-27 12:49:02 +00:00
|
|
|
if (!usegcli) {
|
|
|
|
let context = Cu.getWeakReference(aWindow);
|
|
|
|
let mixin = new JSTermFirefoxMixin(context, aParentNode,
|
|
|
|
aExistingConsole);
|
|
|
|
this.jsterm = new JSTerm(context, aParentNode, mixin, this.console);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
this.gcliterm = new GcliTerm(aWindow, this.hudId, this.chromeDocument,
|
2011-11-19 16:34:04 +00:00
|
|
|
this.console, this.hintNode, this.consoleWrap);
|
2011-05-27 12:49:02 +00:00
|
|
|
aParentNode.appendChild(this.gcliterm.element);
|
|
|
|
}
|
2010-06-22 16:51:50 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
throw new Error("Unsupported Gecko Application");
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2012-01-06 19:34:56 +00:00
|
|
|
/**
|
|
|
|
* Display cached messages that may have been collected before the UI is
|
|
|
|
* displayed.
|
|
|
|
*
|
2012-05-10 15:01:37 +00:00
|
|
|
* @private
|
2012-05-10 13:15:10 +00:00
|
|
|
* @param array aRemoteMessages
|
|
|
|
* Array of cached messages coming from the remote Web Console
|
|
|
|
* content instance.
|
2012-01-06 19:34:56 +00:00
|
|
|
*/
|
2012-05-10 15:01:37 +00:00
|
|
|
_displayCachedConsoleMessages:
|
|
|
|
function HUD__displayCachedConsoleMessages(aRemoteMessages)
|
2012-01-06 19:34:56 +00:00
|
|
|
{
|
2012-05-10 15:01:37 +00:00
|
|
|
if (!aRemoteMessages.length) {
|
|
|
|
return;
|
|
|
|
}
|
2012-01-06 19:34:56 +00:00
|
|
|
|
|
|
|
// Turn off scrolling for the moment.
|
|
|
|
ConsoleUtils.scroll = false;
|
2012-01-11 10:51:49 +00:00
|
|
|
this.outputNode.hidden = true;
|
2012-01-06 19:34:56 +00:00
|
|
|
|
2012-05-10 15:01:37 +00:00
|
|
|
aRemoteMessages.forEach(function(aMessage) {
|
|
|
|
switch (aMessage._type) {
|
|
|
|
case "PageError":
|
|
|
|
this.reportPageError(aMessage);
|
|
|
|
break;
|
|
|
|
case "ConsoleAPI":
|
|
|
|
this.logConsoleAPIMessage(aMessage);
|
|
|
|
break;
|
2012-01-11 10:51:49 +00:00
|
|
|
}
|
2012-01-06 19:34:56 +00:00
|
|
|
}, this);
|
|
|
|
|
2012-01-11 10:51:49 +00:00
|
|
|
this.outputNode.hidden = false;
|
2012-01-06 19:34:56 +00:00
|
|
|
ConsoleUtils.scroll = true;
|
|
|
|
|
|
|
|
// Scroll to bottom.
|
|
|
|
let numChildren = this.outputNode.childNodes.length;
|
2012-01-11 10:51:49 +00:00
|
|
|
if (numChildren && this.outputNode.clientHeight) {
|
|
|
|
// We also check the clientHeight to force a reflow, otherwise
|
|
|
|
// ensureIndexIsVisible() does not work after outputNode.hidden = false.
|
2012-01-06 19:34:56 +00:00
|
|
|
this.outputNode.ensureIndexIsVisible(numChildren - 1);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2010-06-22 16:51:50 +00:00
|
|
|
/**
|
|
|
|
* Re-attaches a console when the contentWindow is recreated
|
|
|
|
*
|
2010-09-13 17:15:59 +00:00
|
|
|
* @param nsIDOMWindow aContentWindow
|
2010-06-22 16:51:50 +00:00
|
|
|
* @returns void
|
|
|
|
*/
|
2010-09-13 17:15:59 +00:00
|
|
|
reattachConsole: function HUD_reattachConsole(aContentWindow)
|
2010-06-22 16:51:50 +00:00
|
|
|
{
|
2010-09-13 17:15:59 +00:00
|
|
|
this.contentWindow = aContentWindow;
|
|
|
|
this.contentDocument = this.contentWindow.document;
|
|
|
|
this.uriSpec = this.contentWindow.location.href;
|
2010-06-22 16:51:50 +00:00
|
|
|
|
2011-06-18 14:42:14 +00:00
|
|
|
if (this.consolePanel) {
|
|
|
|
this.consolePanel.label = this.getPanelTitle();
|
|
|
|
}
|
|
|
|
|
2011-05-27 12:49:02 +00:00
|
|
|
if (this.jsterm) {
|
2010-09-13 17:15:59 +00:00
|
|
|
this.jsterm.context = Cu.getWeakReference(this.contentWindow);
|
|
|
|
this.jsterm.console = this.console;
|
|
|
|
this.jsterm.createSandbox();
|
2010-06-22 16:51:50 +00:00
|
|
|
}
|
2011-05-27 12:49:02 +00:00
|
|
|
else if (this.gcliterm) {
|
|
|
|
this.gcliterm.reattachConsole(this.contentWindow, this.console);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
this.createConsoleInput(this.contentWindow, this.consoleWrap, this.outputNode);
|
|
|
|
}
|
2010-06-22 16:51:50 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Shortcut to make XUL nodes
|
|
|
|
*
|
|
|
|
* @param string aTag
|
|
|
|
* @returns nsIDOMNode
|
|
|
|
*/
|
|
|
|
makeXULNode:
|
|
|
|
function HUD_makeXULNode(aTag)
|
|
|
|
{
|
2010-08-13 17:36:05 +00:00
|
|
|
return this.chromeDocument.createElement(aTag);
|
2010-06-22 16:51:50 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Build the UI of each HeadsUpDisplay
|
|
|
|
*
|
|
|
|
* @returns nsIDOMNode
|
|
|
|
*/
|
|
|
|
makeHUDNodes: function HUD_makeHUDNodes()
|
|
|
|
{
|
|
|
|
let self = this;
|
2011-05-18 11:08:54 +00:00
|
|
|
|
|
|
|
this.splitter = this.makeXULNode("splitter");
|
|
|
|
this.splitter.setAttribute("class", "hud-splitter");
|
|
|
|
|
2010-06-22 16:51:50 +00:00
|
|
|
this.HUDBox = this.makeXULNode("vbox");
|
|
|
|
this.HUDBox.setAttribute("id", this.hudId);
|
2010-11-10 16:10:26 +00:00
|
|
|
this.HUDBox.setAttribute("class", "hud-box animated");
|
|
|
|
this.HUDBox.style.height = 0;
|
2010-06-23 15:30:51 +00:00
|
|
|
|
2010-06-22 16:51:50 +00:00
|
|
|
let outerWrap = this.makeXULNode("vbox");
|
|
|
|
outerWrap.setAttribute("class", "hud-outer-wrapper");
|
|
|
|
outerWrap.setAttribute("flex", "1");
|
|
|
|
|
|
|
|
let consoleCommandSet = this.makeXULNode("commandset");
|
|
|
|
outerWrap.appendChild(consoleCommandSet);
|
|
|
|
|
|
|
|
let consoleWrap = this.makeXULNode("vbox");
|
|
|
|
this.consoleWrap = consoleWrap;
|
|
|
|
consoleWrap.setAttribute("class", "hud-console-wrapper");
|
|
|
|
consoleWrap.setAttribute("flex", "1");
|
|
|
|
|
2010-07-30 11:30:55 +00:00
|
|
|
this.filterSpacer = this.makeXULNode("spacer");
|
|
|
|
this.filterSpacer.setAttribute("flex", "1");
|
|
|
|
|
2010-06-22 16:51:50 +00:00
|
|
|
this.filterBox = this.makeXULNode("textbox");
|
2010-08-03 01:08:11 +00:00
|
|
|
this.filterBox.setAttribute("class", "compact hud-filter-box");
|
2010-06-22 16:51:50 +00:00
|
|
|
this.filterBox.setAttribute("hudId", this.hudId);
|
2012-05-10 13:15:10 +00:00
|
|
|
this.filterBox.setAttribute("placeholder", l10n.getStr("stringFilter"));
|
2010-08-03 01:08:11 +00:00
|
|
|
this.filterBox.setAttribute("type", "search");
|
2010-06-22 16:51:50 +00:00
|
|
|
|
|
|
|
this.setFilterTextBoxEvents();
|
|
|
|
|
2010-08-10 22:04:36 +00:00
|
|
|
this.createConsoleMenu(this.consoleWrap);
|
2010-08-10 12:37:29 +00:00
|
|
|
|
2010-06-22 16:51:50 +00:00
|
|
|
this.filterPrefs = HUDService.getDefaultFilterPrefs(this.hudId);
|
|
|
|
|
|
|
|
let consoleFilterToolbar = this.makeFilterToolbar();
|
|
|
|
consoleFilterToolbar.setAttribute("id", "viewGroup");
|
|
|
|
this.consoleFilterToolbar = consoleFilterToolbar;
|
|
|
|
|
2012-01-09 15:38:48 +00:00
|
|
|
this.hintNode = this.makeXULNode("vbox");
|
2011-05-27 12:49:02 +00:00
|
|
|
this.hintNode.setAttribute("class", "gcliterm-hint-node");
|
|
|
|
|
|
|
|
let hintParentNode = this.makeXULNode("vbox");
|
|
|
|
hintParentNode.setAttribute("flex", "0");
|
|
|
|
hintParentNode.setAttribute("class", "gcliterm-hint-parent");
|
2011-11-19 16:34:04 +00:00
|
|
|
hintParentNode.setAttribute("pack", "end");
|
2011-05-27 12:49:02 +00:00
|
|
|
hintParentNode.appendChild(this.hintNode);
|
|
|
|
hintParentNode.hidden = true;
|
|
|
|
|
|
|
|
let hbox = this.makeXULNode("hbox");
|
|
|
|
hbox.setAttribute("flex", "1");
|
2011-11-19 16:34:04 +00:00
|
|
|
hbox.setAttribute("class", "gcliterm-display");
|
2011-05-27 12:49:02 +00:00
|
|
|
|
|
|
|
this.outputNode = this.makeXULNode("richlistbox");
|
|
|
|
this.outputNode.setAttribute("class", "hud-output-node");
|
|
|
|
this.outputNode.setAttribute("flex", "1");
|
|
|
|
this.outputNode.setAttribute("orient", "vertical");
|
|
|
|
this.outputNode.setAttribute("context", this.hudId + "-output-contextmenu");
|
|
|
|
this.outputNode.setAttribute("style", "direction: ltr;");
|
|
|
|
this.outputNode.setAttribute("seltype", "multiple");
|
|
|
|
|
|
|
|
hbox.appendChild(hintParentNode);
|
|
|
|
hbox.appendChild(this.outputNode);
|
|
|
|
|
|
|
|
consoleWrap.appendChild(consoleFilterToolbar);
|
|
|
|
consoleWrap.appendChild(hbox);
|
2010-08-10 12:37:29 +00:00
|
|
|
|
2010-06-22 16:51:50 +00:00
|
|
|
outerWrap.appendChild(consoleWrap);
|
|
|
|
|
2010-08-09 18:35:33 +00:00
|
|
|
this.HUDBox.lastTimestamp = 0;
|
|
|
|
|
2010-06-22 16:51:50 +00:00
|
|
|
this.jsTermParentNode = outerWrap;
|
|
|
|
this.HUDBox.appendChild(outerWrap);
|
2011-02-28 20:42:20 +00:00
|
|
|
|
2010-06-22 16:51:50 +00:00
|
|
|
return this.HUDBox;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* sets the click events for all binary toggle filter buttons
|
|
|
|
*
|
|
|
|
* @returns void
|
|
|
|
*/
|
|
|
|
setFilterTextBoxEvents: function HUD_setFilterTextBoxEvents()
|
|
|
|
{
|
2010-08-18 23:53:53 +00:00
|
|
|
var filterBox = this.filterBox;
|
|
|
|
function onChange()
|
2010-06-22 16:51:50 +00:00
|
|
|
{
|
2010-08-18 23:53:53 +00:00
|
|
|
// To improve responsiveness, we let the user finish typing before we
|
|
|
|
// perform the search.
|
|
|
|
|
|
|
|
if (this.timer == null) {
|
|
|
|
let timerClass = Cc["@mozilla.org/timer;1"];
|
|
|
|
this.timer = timerClass.createInstance(Ci.nsITimer);
|
|
|
|
} else {
|
|
|
|
this.timer.cancel();
|
|
|
|
}
|
|
|
|
|
|
|
|
let timerEvent = {
|
|
|
|
notify: function setFilterTextBoxEvents_timerEvent_notify() {
|
|
|
|
HUDService.updateFilterText(filterBox);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
this.timer.initWithCallback(timerEvent, SEARCH_DELAY,
|
|
|
|
Ci.nsITimer.TYPE_ONE_SHOT);
|
2010-06-22 16:51:50 +00:00
|
|
|
}
|
2010-08-18 23:53:53 +00:00
|
|
|
|
|
|
|
filterBox.addEventListener("command", onChange, false);
|
|
|
|
filterBox.addEventListener("input", onChange, false);
|
2010-06-22 16:51:50 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Make the filter toolbar where we can toggle logging filters
|
|
|
|
*
|
|
|
|
* @returns nsIDOMNode
|
|
|
|
*/
|
|
|
|
makeFilterToolbar: function HUD_makeFilterToolbar()
|
|
|
|
{
|
2010-12-02 10:50:29 +00:00
|
|
|
const BUTTONS = [
|
|
|
|
{
|
|
|
|
name: "PageNet",
|
|
|
|
category: "net",
|
|
|
|
severities: [
|
|
|
|
{ name: "ConsoleErrors", prefKey: "network" },
|
|
|
|
{ name: "ConsoleLog", prefKey: "networkinfo" }
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "PageCSS",
|
|
|
|
category: "css",
|
|
|
|
severities: [
|
|
|
|
{ name: "ConsoleErrors", prefKey: "csserror" },
|
|
|
|
{ name: "ConsoleWarnings", prefKey: "cssparser" }
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "PageJS",
|
|
|
|
category: "js",
|
|
|
|
severities: [
|
|
|
|
{ name: "ConsoleErrors", prefKey: "exception" },
|
|
|
|
{ name: "ConsoleWarnings", prefKey: "jswarn" }
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
2011-11-21 10:37:18 +00:00
|
|
|
name: "PageLogging",
|
|
|
|
category: "logging",
|
2010-12-02 10:50:29 +00:00
|
|
|
severities: [
|
|
|
|
{ name: "ConsoleErrors", prefKey: "error" },
|
|
|
|
{ name: "ConsoleWarnings", prefKey: "warn" },
|
|
|
|
{ name: "ConsoleInfo", prefKey: "info" },
|
|
|
|
{ name: "ConsoleLog", prefKey: "log" }
|
|
|
|
]
|
|
|
|
}
|
2010-08-09 18:35:33 +00:00
|
|
|
];
|
|
|
|
|
2010-06-22 16:51:50 +00:00
|
|
|
let toolbar = this.makeXULNode("toolbar");
|
|
|
|
toolbar.setAttribute("class", "hud-console-filter-toolbar");
|
2010-12-02 10:50:29 +00:00
|
|
|
toolbar.setAttribute("mode", "full");
|
2010-06-22 16:51:50 +00:00
|
|
|
|
2011-09-20 05:42:52 +00:00
|
|
|
#ifdef XP_MACOSX
|
2010-12-02 10:50:29 +00:00
|
|
|
this.makeCloseButton(toolbar);
|
2011-09-06 23:43:25 +00:00
|
|
|
#endif
|
2010-08-09 18:35:33 +00:00
|
|
|
|
2010-12-02 10:50:29 +00:00
|
|
|
for (let i = 0; i < BUTTONS.length; i++) {
|
|
|
|
this.makeFilterButton(toolbar, BUTTONS[i]);
|
|
|
|
}
|
2010-08-09 18:35:33 +00:00
|
|
|
|
2010-07-30 11:30:55 +00:00
|
|
|
toolbar.appendChild(this.filterSpacer);
|
2011-05-18 11:08:54 +00:00
|
|
|
|
|
|
|
let positionUI = this.createPositionUI();
|
|
|
|
toolbar.appendChild(positionUI);
|
|
|
|
|
2010-06-22 16:51:50 +00:00
|
|
|
toolbar.appendChild(this.filterBox);
|
2010-12-02 10:50:29 +00:00
|
|
|
this.makeClearConsoleButton(toolbar);
|
|
|
|
|
2011-09-20 05:42:52 +00:00
|
|
|
#ifndef XP_MACOSX
|
2011-09-06 23:43:25 +00:00
|
|
|
this.makeCloseButton(toolbar);
|
|
|
|
#endif
|
|
|
|
|
2010-06-22 16:51:50 +00:00
|
|
|
return toolbar;
|
|
|
|
},
|
|
|
|
|
2011-05-18 11:08:54 +00:00
|
|
|
/**
|
|
|
|
* Creates the UI for re-positioning the console
|
|
|
|
*
|
|
|
|
* @return nsIDOMNode
|
2011-07-26 20:51:10 +00:00
|
|
|
* The toolbarbutton which holds the menu that allows the user to
|
2011-05-18 11:08:54 +00:00
|
|
|
* change the console position.
|
|
|
|
*/
|
|
|
|
createPositionUI: function HUD_createPositionUI()
|
|
|
|
{
|
2011-08-03 18:04:30 +00:00
|
|
|
this._positionConsoleAbove = (function HUD_positionAbove() {
|
|
|
|
this.positionConsole("above");
|
|
|
|
}).bind(this);
|
|
|
|
|
|
|
|
this._positionConsoleBelow = (function HUD_positionBelow() {
|
|
|
|
this.positionConsole("below");
|
|
|
|
}).bind(this);
|
|
|
|
this._positionConsoleWindow = (function HUD_positionWindow() {
|
|
|
|
this.positionConsole("window");
|
|
|
|
}).bind(this);
|
2011-05-18 11:08:54 +00:00
|
|
|
|
|
|
|
let button = this.makeXULNode("toolbarbutton");
|
|
|
|
button.setAttribute("type", "menu");
|
2012-05-10 13:15:10 +00:00
|
|
|
button.setAttribute("label", l10n.getStr("webConsolePosition"));
|
|
|
|
button.setAttribute("tooltip", l10n.getStr("webConsolePositionTooltip"));
|
2011-05-18 11:08:54 +00:00
|
|
|
|
|
|
|
let menuPopup = this.makeXULNode("menupopup");
|
|
|
|
button.appendChild(menuPopup);
|
|
|
|
|
|
|
|
let itemAbove = this.makeXULNode("menuitem");
|
2012-05-10 13:15:10 +00:00
|
|
|
itemAbove.setAttribute("label", l10n.getStr("webConsolePositionAbove"));
|
2011-05-18 11:08:54 +00:00
|
|
|
itemAbove.setAttribute("type", "checkbox");
|
|
|
|
itemAbove.setAttribute("autocheck", "false");
|
2011-08-03 18:04:30 +00:00
|
|
|
itemAbove.addEventListener("command", this._positionConsoleAbove, false);
|
2011-05-18 11:08:54 +00:00
|
|
|
menuPopup.appendChild(itemAbove);
|
|
|
|
|
|
|
|
let itemBelow = this.makeXULNode("menuitem");
|
2012-05-10 13:15:10 +00:00
|
|
|
itemBelow.setAttribute("label", l10n.getStr("webConsolePositionBelow"));
|
2011-05-18 11:08:54 +00:00
|
|
|
itemBelow.setAttribute("type", "checkbox");
|
|
|
|
itemBelow.setAttribute("autocheck", "false");
|
2011-08-03 18:04:30 +00:00
|
|
|
itemBelow.addEventListener("command", this._positionConsoleBelow, false);
|
2011-05-18 11:08:54 +00:00
|
|
|
menuPopup.appendChild(itemBelow);
|
|
|
|
|
|
|
|
let itemWindow = this.makeXULNode("menuitem");
|
2012-05-10 13:15:10 +00:00
|
|
|
itemWindow.setAttribute("label", l10n.getStr("webConsolePositionWindow"));
|
2011-05-18 11:08:54 +00:00
|
|
|
itemWindow.setAttribute("type", "checkbox");
|
|
|
|
itemWindow.setAttribute("autocheck", "false");
|
2011-08-03 18:04:30 +00:00
|
|
|
itemWindow.addEventListener("command", this._positionConsoleWindow, false);
|
2011-05-18 11:08:54 +00:00
|
|
|
menuPopup.appendChild(itemWindow);
|
|
|
|
|
|
|
|
this.positionMenuitems = {
|
|
|
|
last: null,
|
|
|
|
above: itemAbove,
|
|
|
|
below: itemBelow,
|
|
|
|
window: itemWindow,
|
|
|
|
};
|
|
|
|
|
|
|
|
return button;
|
|
|
|
},
|
|
|
|
|
2010-08-10 22:04:36 +00:00
|
|
|
/**
|
2010-12-02 10:50:29 +00:00
|
|
|
* Creates the context menu on the console.
|
2010-08-10 22:04:36 +00:00
|
|
|
*
|
|
|
|
* @param nsIDOMNode aOutputNode
|
|
|
|
* The console output DOM node.
|
|
|
|
* @returns void
|
|
|
|
*/
|
|
|
|
createConsoleMenu: function HUD_createConsoleMenu(aConsoleWrapper) {
|
|
|
|
let menuPopup = this.makeXULNode("menupopup");
|
|
|
|
let id = this.hudId + "-output-contextmenu";
|
|
|
|
menuPopup.setAttribute("id", id);
|
2011-01-04 17:33:12 +00:00
|
|
|
menuPopup.addEventListener("popupshowing", function() {
|
|
|
|
saveBodiesItem.setAttribute("checked",
|
|
|
|
HUDService.saveRequestAndResponseBodies);
|
|
|
|
}, true);
|
2010-08-10 22:04:36 +00:00
|
|
|
|
2010-09-22 00:00:15 +00:00
|
|
|
let saveBodiesItem = this.makeXULNode("menuitem");
|
2012-05-10 13:15:10 +00:00
|
|
|
saveBodiesItem.setAttribute("label", l10n.getStr("saveBodies.label"));
|
2010-09-22 00:00:15 +00:00
|
|
|
saveBodiesItem.setAttribute("accesskey",
|
2012-05-10 13:15:10 +00:00
|
|
|
l10n.getStr("saveBodies.accesskey"));
|
2010-09-22 00:00:15 +00:00
|
|
|
saveBodiesItem.setAttribute("type", "checkbox");
|
|
|
|
saveBodiesItem.setAttribute("buttonType", "saveBodies");
|
|
|
|
saveBodiesItem.setAttribute("oncommand", "HUDConsoleUI.command(this);");
|
|
|
|
menuPopup.appendChild(saveBodiesItem);
|
|
|
|
|
|
|
|
menuPopup.appendChild(this.makeXULNode("menuseparator"));
|
|
|
|
|
2010-08-10 22:04:36 +00:00
|
|
|
let copyItem = this.makeXULNode("menuitem");
|
2012-05-10 13:15:10 +00:00
|
|
|
copyItem.setAttribute("label", l10n.getStr("copyCmd.label"));
|
|
|
|
copyItem.setAttribute("accesskey", l10n.getStr("copyCmd.accesskey"));
|
2010-08-10 22:04:36 +00:00
|
|
|
copyItem.setAttribute("key", "key_copy");
|
|
|
|
copyItem.setAttribute("command", "cmd_copy");
|
2010-12-23 15:59:19 +00:00
|
|
|
copyItem.setAttribute("buttonType", "copy");
|
2010-08-10 22:04:36 +00:00
|
|
|
menuPopup.appendChild(copyItem);
|
|
|
|
|
2010-09-10 18:08:05 +00:00
|
|
|
let selectAllItem = this.makeXULNode("menuitem");
|
2012-05-10 13:15:10 +00:00
|
|
|
selectAllItem.setAttribute("label", l10n.getStr("selectAllCmd.label"));
|
2010-09-10 18:08:05 +00:00
|
|
|
selectAllItem.setAttribute("accesskey",
|
2012-05-10 13:15:10 +00:00
|
|
|
l10n.getStr("selectAllCmd.accesskey"));
|
2010-09-10 18:08:05 +00:00
|
|
|
selectAllItem.setAttribute("hudId", this.hudId);
|
|
|
|
selectAllItem.setAttribute("buttonType", "selectAll");
|
|
|
|
selectAllItem.setAttribute("oncommand", "HUDConsoleUI.command(this);");
|
|
|
|
menuPopup.appendChild(selectAllItem);
|
|
|
|
|
2010-08-10 22:04:36 +00:00
|
|
|
aConsoleWrapper.appendChild(menuPopup);
|
|
|
|
aConsoleWrapper.setAttribute("context", id);
|
|
|
|
},
|
|
|
|
|
2010-12-02 10:50:29 +00:00
|
|
|
/**
|
|
|
|
* Creates one of the filter buttons on the toolbar.
|
|
|
|
*
|
|
|
|
* @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.
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
makeFilterButton: function HUD_makeFilterButton(aParent, aDescriptor)
|
2010-06-22 16:51:50 +00:00
|
|
|
{
|
2010-12-02 10:50:29 +00:00
|
|
|
let toolbarButton = this.makeXULNode("toolbarbutton");
|
|
|
|
aParent.appendChild(toolbarButton);
|
2010-06-22 16:51:50 +00:00
|
|
|
|
2010-12-02 10:50:29 +00:00
|
|
|
let toggleFilter = HeadsUpDisplayUICommands.toggleFilter;
|
|
|
|
toolbarButton.addEventListener("click", toggleFilter, false);
|
2010-07-30 11:30:55 +00:00
|
|
|
|
2010-12-02 10:50:29 +00:00
|
|
|
let name = aDescriptor.name;
|
|
|
|
toolbarButton.setAttribute("type", "menu-button");
|
2012-05-10 13:15:10 +00:00
|
|
|
toolbarButton.setAttribute("label", l10n.getStr("btn" + name));
|
|
|
|
toolbarButton.setAttribute("tooltip", l10n.getStr("tip" + name));
|
2010-12-02 10:50:29 +00:00
|
|
|
toolbarButton.setAttribute("category", aDescriptor.category);
|
|
|
|
toolbarButton.setAttribute("hudId", this.hudId);
|
|
|
|
toolbarButton.classList.add("webconsole-filter-button");
|
2010-06-22 16:51:50 +00:00
|
|
|
|
2010-12-02 10:50:29 +00:00
|
|
|
let menuPopup = this.makeXULNode("menupopup");
|
|
|
|
toolbarButton.appendChild(menuPopup);
|
|
|
|
|
2011-11-29 20:06:50 +00:00
|
|
|
let someChecked = false;
|
2010-12-02 10:50:29 +00:00
|
|
|
for (let i = 0; i < aDescriptor.severities.length; i++) {
|
|
|
|
let severity = aDescriptor.severities[i];
|
|
|
|
let menuItem = this.makeXULNode("menuitem");
|
2012-05-10 13:15:10 +00:00
|
|
|
menuItem.setAttribute("label", l10n.getStr("btn" + severity.name));
|
2010-12-02 10:50:29 +00:00
|
|
|
menuItem.setAttribute("type", "checkbox");
|
|
|
|
menuItem.setAttribute("autocheck", "false");
|
|
|
|
menuItem.setAttribute("hudId", this.hudId);
|
|
|
|
|
|
|
|
let prefKey = severity.prefKey;
|
|
|
|
menuItem.setAttribute("prefKey", prefKey);
|
|
|
|
|
|
|
|
let checked = this.filterPrefs[prefKey];
|
|
|
|
menuItem.setAttribute("checked", checked);
|
2011-11-29 20:06:50 +00:00
|
|
|
if (checked) {
|
|
|
|
someChecked = true;
|
2010-12-02 10:50:29 +00:00
|
|
|
}
|
2010-06-22 16:51:50 +00:00
|
|
|
|
2010-12-02 10:50:29 +00:00
|
|
|
menuItem.addEventListener("command", toggleFilter, false);
|
|
|
|
|
|
|
|
menuPopup.appendChild(menuItem);
|
2010-06-22 16:51:50 +00:00
|
|
|
}
|
2010-12-02 10:50:29 +00:00
|
|
|
|
2011-11-29 20:06:50 +00:00
|
|
|
toolbarButton.setAttribute("checked", someChecked);
|
2010-06-22 16:51:50 +00:00
|
|
|
},
|
|
|
|
|
2010-08-09 18:35:33 +00:00
|
|
|
/**
|
2010-12-02 10:50:29 +00:00
|
|
|
* Creates the close button on the toolbar.
|
2010-08-09 18:35:33 +00:00
|
|
|
*
|
2010-12-02 10:50:29 +00:00
|
|
|
* @param nsIDOMNode aParent
|
|
|
|
* The toolbar to attach the close button to.
|
|
|
|
* @return void
|
2010-08-09 18:35:33 +00:00
|
|
|
*/
|
2010-12-02 10:50:29 +00:00
|
|
|
makeCloseButton: function HUD_makeCloseButton(aToolbar)
|
|
|
|
{
|
2011-08-03 18:04:30 +00:00
|
|
|
this.closeButtonOnCommand = (function HUD_closeButton_onCommand() {
|
2011-05-18 11:08:54 +00:00
|
|
|
HUDService.animate(this.hudId, ANIMATE_OUT, (function() {
|
|
|
|
HUDService.deactivateHUDForContext(this.tab, true);
|
|
|
|
}).bind(this));
|
|
|
|
}).bind(this);
|
2010-12-02 10:50:29 +00:00
|
|
|
|
2011-08-03 18:04:30 +00:00
|
|
|
this.closeButton = this.makeXULNode("toolbarbutton");
|
|
|
|
this.closeButton.classList.add("webconsole-close-button");
|
|
|
|
this.closeButton.addEventListener("command",
|
|
|
|
this.closeButtonOnCommand, false);
|
|
|
|
aToolbar.appendChild(this.closeButton);
|
2010-12-02 10:50:29 +00:00
|
|
|
},
|
2010-08-09 18:35:33 +00:00
|
|
|
|
2010-12-02 10:50:29 +00:00
|
|
|
/**
|
|
|
|
* Creates the "Clear Console" button.
|
|
|
|
*
|
|
|
|
* @param nsIDOMNode aParent
|
|
|
|
* The toolbar to attach the "Clear Console" button to.
|
|
|
|
* @param string aHUDId
|
|
|
|
* The ID of the console.
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
makeClearConsoleButton: function HUD_makeClearConsoleButton(aToolbar)
|
|
|
|
{
|
|
|
|
let hudId = this.hudId;
|
|
|
|
function HUD_clearButton_onCommand() {
|
2011-05-27 12:49:02 +00:00
|
|
|
let hud = HUDService.getHudReferenceById(hudId);
|
|
|
|
if (hud.jsterm) {
|
2012-01-11 10:51:49 +00:00
|
|
|
hud.jsterm.clearOutput(true);
|
2011-05-27 12:49:02 +00:00
|
|
|
}
|
|
|
|
if (hud.gcliterm) {
|
|
|
|
hud.gcliterm.clearOutput();
|
|
|
|
}
|
2010-08-09 18:35:33 +00:00
|
|
|
}
|
2010-12-02 10:50:29 +00:00
|
|
|
|
|
|
|
let clearButton = this.makeXULNode("toolbarbutton");
|
2012-05-10 13:15:10 +00:00
|
|
|
clearButton.setAttribute("label", l10n.getStr("btnClear"));
|
2010-12-02 10:50:29 +00:00
|
|
|
clearButton.classList.add("webconsole-clear-console-button");
|
|
|
|
clearButton.addEventListener("command", HUD_clearButton_onCommand, false);
|
|
|
|
|
|
|
|
aToolbar.appendChild(clearButton);
|
2010-08-09 18:35:33 +00:00
|
|
|
},
|
|
|
|
|
2011-06-09 13:27:30 +00:00
|
|
|
/**
|
|
|
|
* Destroy the property inspector message node. This performs the necessary
|
|
|
|
* cleanup for the tree widget and removes it from the DOM.
|
|
|
|
*
|
|
|
|
* @param nsIDOMNode aMessageNode
|
|
|
|
* The message node that contains the property inspector from a
|
|
|
|
* console.dir call.
|
|
|
|
*/
|
|
|
|
pruneConsoleDirNode: function HUD_pruneConsoleDirNode(aMessageNode)
|
|
|
|
{
|
|
|
|
aMessageNode.parentNode.removeChild(aMessageNode);
|
|
|
|
let tree = aMessageNode.querySelector("tree");
|
|
|
|
tree.parentNode.removeChild(tree);
|
|
|
|
aMessageNode.propertyTreeView = null;
|
2012-05-10 13:15:10 +00:00
|
|
|
if (tree.view) {
|
|
|
|
tree.view.data = null;
|
|
|
|
}
|
2011-06-09 13:27:30 +00:00
|
|
|
tree.view = null;
|
|
|
|
},
|
|
|
|
|
2011-05-18 11:08:54 +00:00
|
|
|
/**
|
|
|
|
* Create the Web Console UI.
|
|
|
|
*
|
|
|
|
* @return nsIDOMNode
|
|
|
|
* The Web Console container element (HUDBox).
|
|
|
|
*/
|
2010-06-22 16:51:50 +00:00
|
|
|
createHUD: function HUD_createHUD()
|
|
|
|
{
|
2011-05-18 11:08:54 +00:00
|
|
|
if (!this.HUDBox) {
|
2010-06-22 16:51:50 +00:00
|
|
|
this.makeHUDNodes();
|
2011-05-18 11:08:54 +00:00
|
|
|
let positionPref = Services.prefs.getCharPref("devtools.webconsole.position");
|
|
|
|
this.positionConsole(positionPref);
|
2010-06-22 16:51:50 +00:00
|
|
|
}
|
2011-05-18 11:08:54 +00:00
|
|
|
return this.HUDBox;
|
2010-06-22 16:51:50 +00:00
|
|
|
},
|
|
|
|
|
2011-05-18 11:08:54 +00:00
|
|
|
uiInOwnWindow: false,
|
|
|
|
|
2010-11-16 21:34:53 +00:00
|
|
|
get console() { return this.contentWindow.wrappedJSObject.console; },
|
2010-06-22 16:51:50 +00:00
|
|
|
|
2012-05-10 13:15:10 +00:00
|
|
|
/**
|
|
|
|
* Logs a message to the Web Console that originates from the remote Web
|
|
|
|
* Console instance.
|
|
|
|
*
|
|
|
|
* @param object aMessage
|
|
|
|
* The message received from the remote Web Console instance.
|
|
|
|
* console service. This object needs to hold:
|
|
|
|
* - hudId - the Web Console ID.
|
|
|
|
* - apiMessage - a representation of the object sent by the console
|
|
|
|
* storage service. This object holds the console message level, the
|
|
|
|
* arguments that were passed to the console method and other
|
|
|
|
* information.
|
|
|
|
* - argumentsToString - the array of arguments passed to the console
|
|
|
|
* method, each converted to a string.
|
|
|
|
*/
|
|
|
|
logConsoleAPIMessage: function HUD_logConsoleAPIMessage(aMessage)
|
2010-06-22 16:51:50 +00:00
|
|
|
{
|
2012-05-10 13:15:10 +00:00
|
|
|
let body = null;
|
|
|
|
let clipboardText = null;
|
|
|
|
let sourceURL = null;
|
|
|
|
let sourceLine = 0;
|
|
|
|
let level = aMessage.apiMessage.level;
|
|
|
|
let args = aMessage.apiMessage.arguments;
|
|
|
|
let argsToString = aMessage.argumentsToString;
|
2010-06-22 16:51:50 +00:00
|
|
|
|
2012-05-10 13:15:10 +00:00
|
|
|
switch (level) {
|
|
|
|
case "log":
|
|
|
|
case "info":
|
|
|
|
case "warn":
|
|
|
|
case "error":
|
|
|
|
case "debug":
|
|
|
|
body = argsToString.join(" ");
|
|
|
|
sourceURL = aMessage.apiMessage.filename;
|
|
|
|
sourceLine = aMessage.apiMessage.lineNumber;
|
|
|
|
break;
|
2010-06-22 16:51:50 +00:00
|
|
|
|
2012-05-10 13:15:10 +00:00
|
|
|
case "trace":
|
|
|
|
let filename = WebConsoleUtils.abbreviateSourceURL(args[0].filename);
|
|
|
|
let functionName = args[0].functionName ||
|
|
|
|
l10n.getStr("stacktrace.anonymousFunction");
|
|
|
|
let lineNumber = args[0].lineNumber;
|
2011-08-03 18:04:30 +00:00
|
|
|
|
2012-05-10 13:15:10 +00:00
|
|
|
body = l10n.getFormatStr("stacktrace.outputMessage",
|
|
|
|
[filename, functionName, lineNumber]);
|
2011-08-03 18:04:30 +00:00
|
|
|
|
2012-05-10 13:15:10 +00:00
|
|
|
sourceURL = args[0].filename;
|
|
|
|
sourceLine = args[0].lineNumber;
|
|
|
|
|
|
|
|
clipboardText = "";
|
|
|
|
|
|
|
|
args.forEach(function(aFrame) {
|
|
|
|
clipboardText += aFrame.filename + " :: " +
|
|
|
|
aFrame.functionName + " :: " +
|
|
|
|
aFrame.lineNumber + "\n";
|
|
|
|
});
|
|
|
|
|
|
|
|
clipboardText = clipboardText.trimRight();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "dir":
|
|
|
|
body = {
|
|
|
|
cacheId: aMessage.objectsCacheId,
|
|
|
|
resultString: argsToString[0],
|
|
|
|
remoteObject: args[0],
|
|
|
|
remoteObjectProvider:
|
|
|
|
this.jsterm.remoteObjectProvider.bind(this.jsterm),
|
|
|
|
};
|
|
|
|
clipboardText = body.resultString;
|
|
|
|
sourceURL = aMessage.apiMessage.filename;
|
|
|
|
sourceLine = aMessage.apiMessage.lineNumber;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "group":
|
|
|
|
case "groupCollapsed":
|
|
|
|
clipboardText = body = args;
|
|
|
|
sourceURL = aMessage.apiMessage.filename;
|
|
|
|
sourceLine = aMessage.apiMessage.lineNumber;
|
|
|
|
this.groupDepth++;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "groupEnd":
|
|
|
|
if (this.groupDepth > 0) {
|
|
|
|
this.groupDepth--;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
|
|
|
|
case "time":
|
|
|
|
if (!args) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (args.error) {
|
|
|
|
Cu.reportError(l10n.getStr(args.error));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
body = l10n.getFormatStr("timerStarted", [args.name]);
|
|
|
|
clipboardText = body;
|
|
|
|
sourceURL = aMessage.apiMessage.filename;
|
|
|
|
sourceLine = aMessage.apiMessage.lineNumber;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "timeEnd":
|
|
|
|
if (!args) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
body = l10n.getFormatStr("timeEnd", [args.name, args.duration]);
|
|
|
|
clipboardText = body;
|
|
|
|
sourceURL = aMessage.apiMessage.filename;
|
|
|
|
sourceLine = aMessage.apiMessage.lineNumber;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
Cu.reportError("Unknown Console API log level: " + level);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let node = ConsoleUtils.createMessageNode(this.chromeDocument,
|
|
|
|
CATEGORY_WEBDEV,
|
|
|
|
LEVELS[level],
|
|
|
|
body,
|
|
|
|
this.hudId,
|
|
|
|
sourceURL,
|
|
|
|
sourceLine,
|
|
|
|
clipboardText,
|
|
|
|
level,
|
|
|
|
aMessage.timeStamp);
|
|
|
|
|
|
|
|
// Make the node bring up the property panel, to allow the user to inspect
|
|
|
|
// the stack trace.
|
|
|
|
if (level == "trace") {
|
|
|
|
node._stacktrace = args;
|
|
|
|
|
|
|
|
this.makeOutputMessageLink(node, function _traceNodeClickCallback() {
|
|
|
|
if (node._panelOpen) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let options = {
|
|
|
|
anchor: node,
|
|
|
|
data: { object: node._stacktrace },
|
|
|
|
};
|
|
|
|
|
|
|
|
let propPanel = this.jsterm.openPropertyPanelAsync(options);
|
|
|
|
propPanel.panel.setAttribute("hudId", this.hudId);
|
|
|
|
}.bind(this));
|
|
|
|
}
|
|
|
|
|
|
|
|
ConsoleUtils.outputMessageNode(node, this.hudId);
|
|
|
|
|
|
|
|
if (level == "dir") {
|
|
|
|
// Initialize the inspector message node, by setting the PropertyTreeView
|
|
|
|
// object on the tree view. This has to be done *after* the node is
|
|
|
|
// shown, because the tree binding must be attached first.
|
|
|
|
let tree = node.querySelector("tree");
|
|
|
|
tree.view = node.propertyTreeView;
|
|
|
|
|
|
|
|
// Make sure the cached evaluated object will be purged when the node is
|
|
|
|
// removed.
|
|
|
|
node._evalCacheId = aMessage.objectsCacheId;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2012-05-10 15:01:37 +00:00
|
|
|
/**
|
|
|
|
* Reports an error in the page source, either JavaScript or CSS.
|
|
|
|
*
|
|
|
|
* @param nsIScriptError aScriptError
|
|
|
|
* The error message to report.
|
|
|
|
*/
|
|
|
|
reportPageError: function HUD_reportPageError(aScriptError)
|
|
|
|
{
|
|
|
|
if (!aScriptError.outerWindowID) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let category;
|
|
|
|
|
|
|
|
switch (aScriptError.category) {
|
|
|
|
// We ignore chrome-originating errors as we only care about content.
|
|
|
|
case "XPConnect JavaScript":
|
|
|
|
case "component javascript":
|
|
|
|
case "chrome javascript":
|
|
|
|
case "chrome registration":
|
|
|
|
case "XBL":
|
|
|
|
case "XBL Prototype Handler":
|
|
|
|
case "XBL Content Sink":
|
|
|
|
case "xbl javascript":
|
|
|
|
return;
|
|
|
|
|
|
|
|
case "CSS Parser":
|
|
|
|
case "CSS Loader":
|
|
|
|
category = CATEGORY_CSS;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
category = CATEGORY_JS;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Warnings and legacy strict errors become warnings; other types become
|
|
|
|
// errors.
|
|
|
|
let severity = SEVERITY_ERROR;
|
|
|
|
if ((aScriptError.flags & aScriptError.warningFlag) ||
|
|
|
|
(aScriptError.flags & aScriptError.strictFlag)) {
|
|
|
|
severity = SEVERITY_WARNING;
|
|
|
|
}
|
|
|
|
|
|
|
|
let node = ConsoleUtils.createMessageNode(this.chromeDocument,
|
|
|
|
category,
|
|
|
|
severity,
|
|
|
|
aScriptError.errorMessage,
|
|
|
|
this.hudId,
|
|
|
|
aScriptError.sourceName,
|
|
|
|
aScriptError.lineNumber,
|
|
|
|
null,
|
|
|
|
null,
|
|
|
|
aScriptError.timeStamp);
|
|
|
|
|
|
|
|
ConsoleUtils.outputMessageNode(node, this.hudId);
|
|
|
|
},
|
|
|
|
|
2012-05-10 13:15:10 +00:00
|
|
|
ERRORS: {
|
|
|
|
HUD_BOX_DOES_NOT_EXIST: "Heads Up Display does not exist",
|
|
|
|
TAB_ID_REQUIRED: "Tab DOM ID is required",
|
|
|
|
PARENTNODE_NOT_FOUND: "parentNode element not found"
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Setup the message manager used to communicate with the Web Console content
|
|
|
|
* script. This method loads the content script, adds the message listeners
|
|
|
|
* and initializes the connection to the content script.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
_setupMessageManager: function HUD__setupMessageManager()
|
|
|
|
{
|
|
|
|
this.messageManager.loadFrameScript(CONTENT_SCRIPT_URL, true);
|
|
|
|
|
|
|
|
this._messageListeners.forEach(function(aName) {
|
|
|
|
this.messageManager.addMessageListener(aName, this);
|
|
|
|
}, this);
|
|
|
|
|
|
|
|
let message = {
|
|
|
|
hudId: this.hudId,
|
2012-05-10 15:01:37 +00:00
|
|
|
features: ["ConsoleAPI", "JSTerm", "PageError"],
|
|
|
|
cachedMessages: ["ConsoleAPI", "PageError"],
|
2012-05-10 13:15:10 +00:00
|
|
|
};
|
|
|
|
this.sendMessageToContent("WebConsole:Init", message);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handler for all of the messages coming from the Web Console content script.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @param object aMessage
|
|
|
|
* A MessageManager object that holds the remote message.
|
|
|
|
*/
|
|
|
|
receiveMessage: function HUD_receiveMessage(aMessage)
|
|
|
|
{
|
|
|
|
if (!aMessage.json || aMessage.json.hudId != this.hudId) {
|
|
|
|
Cu.reportError("JSTerm: received message " + aMessage.name +
|
|
|
|
" from wrong hudId.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (aMessage.name) {
|
|
|
|
case "JSTerm:EvalObject":
|
|
|
|
this._receiveMessageWithCallback(aMessage.json);
|
|
|
|
break;
|
|
|
|
case "WebConsole:ConsoleAPI":
|
|
|
|
this.logConsoleAPIMessage(aMessage.json);
|
|
|
|
break;
|
2012-05-10 15:01:37 +00:00
|
|
|
case "WebConsole:PageError":
|
|
|
|
this.reportPageError(aMessage.json.pageError);
|
|
|
|
break;
|
2012-05-10 13:15:10 +00:00
|
|
|
case "WebConsole:CachedMessages":
|
2012-05-10 15:01:37 +00:00
|
|
|
this._displayCachedConsoleMessages(aMessage.json.messages);
|
2012-05-10 13:15:10 +00:00
|
|
|
this._onInitComplete();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Callback method for when the Web Console initialization is complete. For
|
|
|
|
* now this method sends the web-console-created notification using the
|
|
|
|
* nsIObserverService.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
_onInitComplete: function HUD__onInitComplete()
|
|
|
|
{
|
|
|
|
let id = WebConsoleUtils.supportsString(this.hudId);
|
|
|
|
Services.obs.notifyObservers(id, "web-console-created", null);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handler for messages that have an associated callback function. The
|
|
|
|
* this.sendMessageToContent() allows one to provide a function to be invoked
|
|
|
|
* when the content script replies to the message previously sent. This is the
|
|
|
|
* method that invokes the callback.
|
|
|
|
*
|
|
|
|
* @see this.sendMessageToContent
|
|
|
|
* @private
|
|
|
|
* @param object aResponse
|
|
|
|
* Message object received from the content script.
|
|
|
|
*/
|
|
|
|
_receiveMessageWithCallback:
|
|
|
|
function HUD__receiveMessageWithCallback(aResponse)
|
|
|
|
{
|
|
|
|
if (aResponse.id in this.asyncRequests) {
|
|
|
|
let request = this.asyncRequests[aResponse.id];
|
|
|
|
request.callback(aResponse, request.message);
|
|
|
|
delete this.asyncRequests[aResponse.id];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
Cu.reportError("receiveMessageWithCallback response for stale request " +
|
|
|
|
"ID " + aResponse.id);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Send a message to the content script.
|
|
|
|
*
|
|
|
|
* @param string aName
|
|
|
|
* The name of the message you want to send.
|
|
|
|
*
|
|
|
|
* @param object aMessage
|
|
|
|
* The message object you want to send. This object needs to have no
|
|
|
|
* cyclic references and it needs to be JSON-stringifiable.
|
|
|
|
*
|
|
|
|
* @param function [aCallback]
|
|
|
|
* Optional function you want to have called when the content script
|
|
|
|
* replies to your message. Your callback receives two arguments:
|
|
|
|
* (1) the response object from the content script and (2) the message
|
|
|
|
* you sent to the content script (which is aMessage here).
|
|
|
|
*/
|
|
|
|
sendMessageToContent:
|
|
|
|
function HUD_sendMessageToContent(aName, aMessage, aCallback)
|
|
|
|
{
|
|
|
|
aMessage.hudId = this.hudId;
|
|
|
|
if (!("id" in aMessage)) {
|
|
|
|
aMessage.id = "HUDChrome-" + HUDService.sequenceId();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aCallback) {
|
|
|
|
this.asyncRequests[aMessage.id] = {
|
|
|
|
name: aName,
|
|
|
|
message: aMessage,
|
|
|
|
callback: aCallback,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
this.messageManager.sendAsyncMessage(aName, aMessage);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Make a link given an output element.
|
|
|
|
*
|
|
|
|
* @param nsIDOMNode aNode
|
|
|
|
* The message element you want to make a link for.
|
|
|
|
* @param function aCallback
|
|
|
|
* The function you want invoked when the user clicks on the message
|
|
|
|
* element.
|
|
|
|
*/
|
|
|
|
makeOutputMessageLink: function HUD_makeOutputMessageLink(aNode, aCallback)
|
|
|
|
{
|
|
|
|
let linkNode;
|
|
|
|
if (aNode.category === CATEGORY_NETWORK) {
|
|
|
|
linkNode = aNode.querySelector(".webconsole-msg-link");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
linkNode = aNode.querySelector(".webconsole-msg-body");
|
|
|
|
linkNode.classList.add("hud-clickable");
|
|
|
|
}
|
|
|
|
|
|
|
|
linkNode.setAttribute("aria-haspopup", "true");
|
|
|
|
|
|
|
|
aNode.addEventListener("mousedown", function(aEvent) {
|
|
|
|
this._startX = aEvent.clientX;
|
|
|
|
this._startY = aEvent.clientY;
|
|
|
|
}, false);
|
|
|
|
|
|
|
|
aNode.addEventListener("click", function(aEvent) {
|
|
|
|
if (aEvent.detail != 1 || aEvent.button != 0 ||
|
|
|
|
(this._startX != aEvent.clientX &&
|
|
|
|
this._startY != aEvent.clientY)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
aCallback(this, aEvent);
|
|
|
|
}, false);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Destroy the HUD object. Call this method to avoid memory leaks when the Web
|
|
|
|
* Console is closed.
|
|
|
|
*/
|
|
|
|
destroy: function HUD_destroy()
|
|
|
|
{
|
|
|
|
this.sendMessageToContent("WebConsole:Destroy", {hudId: this.hudId});
|
|
|
|
|
|
|
|
this._messageListeners.forEach(function(aName) {
|
|
|
|
this.messageManager.removeMessageListener(aName, this);
|
|
|
|
}, this);
|
|
|
|
|
|
|
|
if (this.jsterm) {
|
|
|
|
this.jsterm.destroy();
|
|
|
|
}
|
|
|
|
if (this.gcliterm) {
|
|
|
|
this.gcliterm.destroy();
|
|
|
|
}
|
|
|
|
|
|
|
|
delete this.asyncRequests;
|
|
|
|
delete this.messageManager;
|
|
|
|
delete this.browser;
|
|
|
|
|
|
|
|
this.positionMenuitems.above.removeEventListener("command",
|
|
|
|
this._positionConsoleAbove, false);
|
2011-08-03 18:04:30 +00:00
|
|
|
this.positionMenuitems.below.removeEventListener("command",
|
|
|
|
this._positionConsoleBelow, false);
|
|
|
|
this.positionMenuitems.window.removeEventListener("command",
|
|
|
|
this._positionConsoleWindow, false);
|
|
|
|
|
|
|
|
this.closeButton.removeEventListener("command",
|
|
|
|
this.closeButtonOnCommand, false);
|
|
|
|
},
|
2010-06-22 16:51:50 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2010-08-13 17:36:05 +00:00
|
|
|
* Creates a DOM Node factory for XUL nodes - as well as textNodes
|
2010-09-07 22:37:47 +00:00
|
|
|
* @param aFactoryType "xul" or "text"
|
|
|
|
* @param ignored This parameter is currently ignored, and will be removed
|
|
|
|
* See bug 594304
|
|
|
|
* @param aDocument The document, the factory is to generate nodes from
|
|
|
|
* @return DOM Node Factory function
|
2010-06-22 16:51:50 +00:00
|
|
|
*/
|
2010-09-07 22:37:47 +00:00
|
|
|
function NodeFactory(aFactoryType, ignored, aDocument)
|
2010-06-22 16:51:50 +00:00
|
|
|
{
|
|
|
|
// aDocument is presumed to be a XULDocument
|
|
|
|
if (aFactoryType == "text") {
|
2010-09-07 22:37:47 +00:00
|
|
|
return function factory(aText)
|
|
|
|
{
|
2010-06-22 16:51:50 +00:00
|
|
|
return aDocument.createTextNode(aText);
|
|
|
|
}
|
|
|
|
}
|
2010-09-07 22:37:47 +00:00
|
|
|
else if (aFactoryType == "xul") {
|
|
|
|
return function factory(aTag)
|
|
|
|
{
|
|
|
|
return aDocument.createElement(aTag);
|
2010-06-22 16:51:50 +00:00
|
|
|
}
|
|
|
|
}
|
2010-09-07 22:37:47 +00:00
|
|
|
else {
|
|
|
|
throw new Error('NodeFactory: Unknown factory type: ' + aFactoryType);
|
|
|
|
}
|
2010-06-22 16:51:50 +00:00
|
|
|
}
|
|
|
|
|
2010-07-19 14:38:07 +00:00
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// JS Completer
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
const STATE_NORMAL = 0;
|
|
|
|
const STATE_QUOTE = 2;
|
|
|
|
const STATE_DQUOTE = 3;
|
|
|
|
|
|
|
|
const OPEN_BODY = '{[('.split('');
|
|
|
|
const CLOSE_BODY = '}])'.split('');
|
|
|
|
const OPEN_CLOSE_BODY = {
|
|
|
|
'{': '}',
|
|
|
|
'[': ']',
|
|
|
|
'(': ')'
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Analyses a given string to find the last statement that is interesting for
|
|
|
|
* later completion.
|
|
|
|
*
|
|
|
|
* @param string aStr
|
|
|
|
* A string to analyse.
|
|
|
|
*
|
|
|
|
* @returns object
|
|
|
|
* If there was an error in the string detected, then a object like
|
|
|
|
*
|
|
|
|
* { err: "ErrorMesssage" }
|
|
|
|
*
|
|
|
|
* is returned, otherwise a object like
|
|
|
|
*
|
|
|
|
* {
|
|
|
|
* state: STATE_NORMAL|STATE_QUOTE|STATE_DQUOTE,
|
|
|
|
* startPos: index of where the last statement begins
|
|
|
|
* }
|
|
|
|
*/
|
|
|
|
function findCompletionBeginning(aStr)
|
|
|
|
{
|
|
|
|
let bodyStack = [];
|
|
|
|
|
|
|
|
let state = STATE_NORMAL;
|
|
|
|
let start = 0;
|
|
|
|
let c;
|
|
|
|
for (let i = 0; i < aStr.length; i++) {
|
|
|
|
c = aStr[i];
|
|
|
|
|
|
|
|
switch (state) {
|
|
|
|
// Normal JS state.
|
|
|
|
case STATE_NORMAL:
|
|
|
|
if (c == '"') {
|
|
|
|
state = STATE_DQUOTE;
|
|
|
|
}
|
|
|
|
else if (c == '\'') {
|
|
|
|
state = STATE_QUOTE;
|
|
|
|
}
|
|
|
|
else if (c == ';') {
|
|
|
|
start = i + 1;
|
|
|
|
}
|
|
|
|
else if (c == ' ') {
|
|
|
|
start = i + 1;
|
|
|
|
}
|
|
|
|
else if (OPEN_BODY.indexOf(c) != -1) {
|
|
|
|
bodyStack.push({
|
|
|
|
token: c,
|
|
|
|
start: start
|
|
|
|
});
|
|
|
|
start = i + 1;
|
|
|
|
}
|
|
|
|
else if (CLOSE_BODY.indexOf(c) != -1) {
|
|
|
|
var last = bodyStack.pop();
|
2010-11-15 11:46:38 +00:00
|
|
|
if (!last || OPEN_CLOSE_BODY[last.token] != c) {
|
2010-07-19 14:38:07 +00:00
|
|
|
return {
|
|
|
|
err: "syntax error"
|
|
|
|
};
|
|
|
|
}
|
|
|
|
if (c == '}') {
|
|
|
|
start = i + 1;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
start = last.start;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
// Double quote state > " <
|
|
|
|
case STATE_DQUOTE:
|
|
|
|
if (c == '\\') {
|
|
|
|
i ++;
|
|
|
|
}
|
|
|
|
else if (c == '\n') {
|
|
|
|
return {
|
|
|
|
err: "unterminated string literal"
|
|
|
|
};
|
|
|
|
}
|
|
|
|
else if (c == '"') {
|
|
|
|
state = STATE_NORMAL;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
// Single quoate state > ' <
|
|
|
|
case STATE_QUOTE:
|
|
|
|
if (c == '\\') {
|
|
|
|
i ++;
|
|
|
|
}
|
|
|
|
else if (c == '\n') {
|
|
|
|
return {
|
|
|
|
err: "unterminated string literal"
|
|
|
|
};
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if (c == '\'') {
|
|
|
|
state = STATE_NORMAL;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
state: state,
|
|
|
|
startPos: start
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Provides a list of properties, that are possible matches based on the passed
|
|
|
|
* scope and inputValue.
|
|
|
|
*
|
|
|
|
* @param object aScope
|
|
|
|
* Scope to use for the completion.
|
|
|
|
*
|
|
|
|
* @param string aInputValue
|
|
|
|
* Value that should be completed.
|
|
|
|
*
|
|
|
|
* @returns null or object
|
|
|
|
* If no completion valued could be computed, null is returned,
|
|
|
|
* otherwise a object with the following form is returned:
|
|
|
|
* {
|
|
|
|
* matches: [ string, string, string ],
|
|
|
|
* matchProp: Last part of the inputValue that was used to find
|
|
|
|
* the matches-strings.
|
|
|
|
* }
|
|
|
|
*/
|
|
|
|
function JSPropertyProvider(aScope, aInputValue)
|
|
|
|
{
|
2012-05-10 13:15:10 +00:00
|
|
|
let obj = WebConsoleUtils.unwrap(aScope);
|
2010-07-19 14:38:07 +00:00
|
|
|
|
|
|
|
// Analyse the aInputValue and find the beginning of the last part that
|
|
|
|
// should be completed.
|
|
|
|
let beginning = findCompletionBeginning(aInputValue);
|
|
|
|
|
|
|
|
// There was an error analysing the string.
|
|
|
|
if (beginning.err) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the current state is not STATE_NORMAL, then we are inside of an string
|
|
|
|
// which means that no completion is possible.
|
|
|
|
if (beginning.state != STATE_NORMAL) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
let completionPart = aInputValue.substring(beginning.startPos);
|
|
|
|
|
|
|
|
// Don't complete on just an empty string.
|
|
|
|
if (completionPart.trim() == "") {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
let properties = completionPart.split('.');
|
|
|
|
let matchProp;
|
|
|
|
if (properties.length > 1) {
|
2011-05-17 15:07:33 +00:00
|
|
|
matchProp = properties.pop().trimLeft();
|
|
|
|
for (let i = 0; i < properties.length; i++) {
|
|
|
|
let prop = properties[i].trim();
|
2010-07-19 14:38:07 +00:00
|
|
|
|
2011-05-19 20:15:36 +00:00
|
|
|
// If obj is undefined or null, then there is no chance to run completion
|
2011-05-17 15:07:33 +00:00
|
|
|
// on it. Exit here.
|
|
|
|
if (typeof obj === "undefined" || obj === null) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if prop is a getter function on obj. Functions can change other
|
|
|
|
// stuff so we can't execute them to get the next object. Stop here.
|
2012-05-10 13:15:10 +00:00
|
|
|
if (WebConsoleUtils.isNonNativeGetter(obj, prop)) {
|
2011-05-27 18:58:05 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
obj = obj[prop];
|
|
|
|
}
|
|
|
|
catch (ex) {
|
2011-05-17 15:07:33 +00:00
|
|
|
return null;
|
2010-07-19 14:38:07 +00:00
|
|
|
}
|
2011-05-17 15:07:33 +00:00
|
|
|
}
|
2010-07-19 14:38:07 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
matchProp = properties[0].trimLeft();
|
|
|
|
}
|
|
|
|
|
2011-05-19 20:15:36 +00:00
|
|
|
// If obj is undefined or null, then there is no chance to run
|
2010-07-19 14:38:07 +00:00
|
|
|
// completion on it. Exit here.
|
|
|
|
if (typeof obj === "undefined" || obj === null) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2011-03-25 16:42:09 +00:00
|
|
|
// Skip Iterators and Generators.
|
2012-05-10 13:15:10 +00:00
|
|
|
if (WebConsoleUtils.isIteratorOrGenerator(obj)) {
|
2011-03-25 16:42:09 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2010-07-19 14:38:07 +00:00
|
|
|
let matches = [];
|
2011-05-17 15:07:33 +00:00
|
|
|
for (let prop in obj) {
|
|
|
|
if (prop.indexOf(matchProp) == 0) {
|
|
|
|
matches.push(prop);
|
|
|
|
}
|
2010-07-19 14:38:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
matchProp: matchProp,
|
2011-05-17 15:07:33 +00:00
|
|
|
matches: matches.sort(),
|
2010-07-19 14:38:07 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2010-06-22 16:51:50 +00:00
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// JSTerm
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2010-09-02 21:30:45 +00:00
|
|
|
/**
|
|
|
|
* JSTermHelper
|
|
|
|
*
|
|
|
|
* Defines a set of functions ("helper functions") that are available from the
|
|
|
|
* WebConsole but not from the webpage.
|
|
|
|
* A list of helper functions used by Firebug can be found here:
|
|
|
|
* http://getfirebug.com/wiki/index.php/Command_Line_API
|
|
|
|
*/
|
|
|
|
function JSTermHelper(aJSTerm)
|
|
|
|
{
|
2010-10-28 16:01:36 +00:00
|
|
|
/**
|
|
|
|
* Returns the result of document.getElementById(aId).
|
|
|
|
*
|
|
|
|
* @param string aId
|
|
|
|
* A string that is passed to window.document.getElementById.
|
|
|
|
* @returns nsIDOMNode or null
|
|
|
|
*/
|
|
|
|
aJSTerm.sandbox.$ = function JSTH_$(aId)
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
return aJSTerm._window.document.getElementById(aId);
|
|
|
|
}
|
|
|
|
catch (ex) {
|
|
|
|
aJSTerm.console.error(ex.message);
|
|
|
|
}
|
|
|
|
};
|
2010-09-02 21:30:45 +00:00
|
|
|
|
2010-10-28 16:01:36 +00:00
|
|
|
/**
|
|
|
|
* Returns the result of document.querySelectorAll(aSelector).
|
|
|
|
*
|
|
|
|
* @param string aSelector
|
|
|
|
* A string that is passed to window.document.querySelectorAll.
|
|
|
|
* @returns array of nsIDOMNode
|
|
|
|
*/
|
|
|
|
aJSTerm.sandbox.$$ = function JSTH_$$(aSelector)
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
return aJSTerm._window.document.querySelectorAll(aSelector);
|
|
|
|
}
|
|
|
|
catch (ex) {
|
|
|
|
aJSTerm.console.error(ex.message);
|
|
|
|
}
|
|
|
|
};
|
2010-09-02 21:30:45 +00:00
|
|
|
|
2010-10-28 16:01:36 +00:00
|
|
|
/**
|
|
|
|
* Runs a xPath query and returns all matched nodes.
|
|
|
|
*
|
|
|
|
* @param string aXPath
|
|
|
|
* xPath search query to execute.
|
|
|
|
* @param [optional] nsIDOMNode aContext
|
|
|
|
* Context to run the xPath query on. Uses window.document if not set.
|
|
|
|
* @returns array of nsIDOMNode
|
|
|
|
*/
|
|
|
|
aJSTerm.sandbox.$x = function JSTH_$x(aXPath, aContext)
|
|
|
|
{
|
|
|
|
let nodes = [];
|
|
|
|
let doc = aJSTerm._window.document;
|
|
|
|
let aContext = aContext || doc;
|
2010-09-02 21:30:45 +00:00
|
|
|
|
2010-10-28 16:01:36 +00:00
|
|
|
try {
|
|
|
|
let results = doc.evaluate(aXPath, aContext, null,
|
|
|
|
Ci.nsIDOMXPathResult.ANY_TYPE, null);
|
2010-09-02 21:30:45 +00:00
|
|
|
|
2010-10-28 16:01:36 +00:00
|
|
|
let node;
|
|
|
|
while (node = results.iterateNext()) {
|
|
|
|
nodes.push(node);
|
2010-09-02 21:30:45 +00:00
|
|
|
}
|
2010-10-28 16:01:36 +00:00
|
|
|
}
|
|
|
|
catch (ex) {
|
|
|
|
aJSTerm.console.error(ex.message);
|
|
|
|
}
|
2010-09-02 21:30:45 +00:00
|
|
|
|
2010-10-28 16:01:36 +00:00
|
|
|
return nodes;
|
|
|
|
};
|
2010-09-02 21:30:45 +00:00
|
|
|
|
2011-08-02 13:43:10 +00:00
|
|
|
/**
|
|
|
|
* Returns the currently selected object in the highlighter.
|
|
|
|
*
|
|
|
|
* @returns nsIDOMNode or null
|
|
|
|
*/
|
|
|
|
Object.defineProperty(aJSTerm.sandbox, "$0", {
|
|
|
|
get: function() {
|
|
|
|
let mw = HUDService.currentContext();
|
|
|
|
try {
|
|
|
|
return mw.InspectorUI.selection;
|
|
|
|
}
|
|
|
|
catch (ex) {
|
|
|
|
aJSTerm.console.error(ex.message);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
enumerable: true,
|
|
|
|
configurable: false
|
|
|
|
});
|
|
|
|
|
2010-10-28 16:01:36 +00:00
|
|
|
/**
|
|
|
|
* Clears the output of the JSTerm.
|
|
|
|
*/
|
|
|
|
aJSTerm.sandbox.clear = function JSTH_clear()
|
|
|
|
{
|
2010-12-14 18:51:16 +00:00
|
|
|
aJSTerm.helperEvaluated = true;
|
2012-01-11 10:51:49 +00:00
|
|
|
aJSTerm.clearOutput(true);
|
2010-10-28 16:01:36 +00:00
|
|
|
};
|
2010-09-02 21:30:45 +00:00
|
|
|
|
2010-10-28 16:01:36 +00:00
|
|
|
/**
|
|
|
|
* Returns the result of Object.keys(aObject).
|
|
|
|
*
|
|
|
|
* @param object aObject
|
|
|
|
* Object to return the property names from.
|
|
|
|
* @returns array of string
|
|
|
|
*/
|
|
|
|
aJSTerm.sandbox.keys = function JSTH_keys(aObject)
|
|
|
|
{
|
|
|
|
try {
|
2012-05-10 13:15:10 +00:00
|
|
|
return Object.keys(WebConsoleUtils.unwrap(aObject));
|
2010-10-28 16:01:36 +00:00
|
|
|
}
|
|
|
|
catch (ex) {
|
|
|
|
aJSTerm.console.error(ex.message);
|
|
|
|
}
|
|
|
|
};
|
2010-09-02 21:30:45 +00:00
|
|
|
|
2010-10-28 16:01:36 +00:00
|
|
|
/**
|
|
|
|
* Returns the values of all properties on aObject.
|
|
|
|
*
|
|
|
|
* @param object aObject
|
|
|
|
* Object to display the values from.
|
|
|
|
* @returns array of string
|
|
|
|
*/
|
|
|
|
aJSTerm.sandbox.values = function JSTH_values(aObject)
|
|
|
|
{
|
|
|
|
let arrValues = [];
|
2012-05-10 13:15:10 +00:00
|
|
|
let obj = WebConsoleUtils.unwrap(aObject);
|
2010-09-02 21:30:45 +00:00
|
|
|
|
2010-10-28 16:01:36 +00:00
|
|
|
try {
|
2010-11-10 16:10:25 +00:00
|
|
|
for (let prop in obj) {
|
|
|
|
arrValues.push(obj[prop]);
|
2010-09-02 21:30:45 +00:00
|
|
|
}
|
2010-10-28 16:01:36 +00:00
|
|
|
}
|
|
|
|
catch (ex) {
|
|
|
|
aJSTerm.console.error(ex.message);
|
|
|
|
}
|
|
|
|
return arrValues;
|
|
|
|
};
|
2010-09-02 21:30:45 +00:00
|
|
|
|
2010-11-02 12:58:37 +00:00
|
|
|
/**
|
|
|
|
* Opens a help window in MDC
|
|
|
|
*/
|
|
|
|
aJSTerm.sandbox.help = function JSTH_help()
|
|
|
|
{
|
2010-12-14 18:51:16 +00:00
|
|
|
aJSTerm.helperEvaluated = true;
|
2010-11-02 12:58:37 +00:00
|
|
|
aJSTerm._window.open(
|
|
|
|
"https://developer.mozilla.org/AppLinks/WebConsoleHelp?locale=" +
|
|
|
|
aJSTerm._window.navigator.language, "help", "");
|
|
|
|
};
|
|
|
|
|
2010-10-28 16:01:36 +00:00
|
|
|
/**
|
|
|
|
* Inspects the passed aObject. This is done by opening the PropertyPanel.
|
|
|
|
*
|
|
|
|
* @param object aObject
|
|
|
|
* Object to inspect.
|
|
|
|
* @returns void
|
|
|
|
*/
|
|
|
|
aJSTerm.sandbox.inspect = function JSTH_inspect(aObject)
|
|
|
|
{
|
2010-12-14 18:51:16 +00:00
|
|
|
aJSTerm.helperEvaluated = true;
|
2012-05-10 13:15:10 +00:00
|
|
|
let propPanel = aJSTerm.openPropertyPanel(null,
|
|
|
|
WebConsoleUtils.unwrap(aObject));
|
2011-03-25 16:42:09 +00:00
|
|
|
propPanel.panel.setAttribute("hudId", aJSTerm.hudId);
|
2010-10-28 16:01:36 +00:00
|
|
|
};
|
2010-09-02 21:30:45 +00:00
|
|
|
|
2011-11-02 01:06:48 +00:00
|
|
|
aJSTerm.sandbox.inspectrules = function JSTH_inspectrules(aNode)
|
|
|
|
{
|
|
|
|
aJSTerm.helperEvaluated = true;
|
2012-01-27 18:24:57 +00:00
|
|
|
let doc = aJSTerm.inputNode.ownerDocument;
|
2011-11-02 01:06:48 +00:00
|
|
|
let win = doc.defaultView;
|
|
|
|
let panel = createElement(doc, "panel", {
|
|
|
|
label: "CSS Rules",
|
|
|
|
titlebar: "normal",
|
|
|
|
noautofocus: "true",
|
|
|
|
noautohide: "true",
|
|
|
|
close: "true",
|
|
|
|
width: 350,
|
|
|
|
height: (win.screen.height / 2)
|
|
|
|
});
|
|
|
|
|
|
|
|
let iframe = createAndAppendElement(panel, "iframe", {
|
2011-11-05 19:31:00 +00:00
|
|
|
src: "chrome://browser/content/devtools/cssruleview.xul",
|
2011-11-02 01:06:48 +00:00
|
|
|
flex: "1",
|
|
|
|
});
|
|
|
|
|
|
|
|
panel.addEventListener("load", function onLoad() {
|
|
|
|
panel.removeEventListener("load", onLoad, true);
|
|
|
|
let doc = iframe.contentDocument;
|
|
|
|
let view = new CssRuleView(doc);
|
2011-11-05 19:31:00 +00:00
|
|
|
doc.documentElement.appendChild(view.element);
|
2011-11-02 01:06:48 +00:00
|
|
|
view.highlight(aNode);
|
|
|
|
}, true);
|
|
|
|
|
|
|
|
let parent = doc.getElementById("mainPopupSet");
|
|
|
|
parent.appendChild(panel);
|
|
|
|
|
|
|
|
panel.addEventListener("popuphidden", function onHide() {
|
|
|
|
panel.removeEventListener("popuphidden", onHide);
|
|
|
|
parent.removeChild(panel);
|
|
|
|
});
|
|
|
|
|
|
|
|
let footer = createElement(doc, "hbox", { align: "end" });
|
|
|
|
createAndAppendElement(footer, "spacer", { flex: 1});
|
|
|
|
createAndAppendElement(footer, "resizer", { dir: "bottomend" });
|
|
|
|
panel.appendChild(footer);
|
|
|
|
|
|
|
|
let anchor = win.gBrowser.selectedBrowser;
|
|
|
|
panel.openPopup(anchor, "end_before", 0, 0, false, false);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2010-10-28 16:01:36 +00:00
|
|
|
/**
|
|
|
|
* Prints aObject to the output.
|
|
|
|
*
|
|
|
|
* @param object aObject
|
|
|
|
* Object to print to the output.
|
|
|
|
* @returns void
|
|
|
|
*/
|
|
|
|
aJSTerm.sandbox.pprint = function JSTH_pprint(aObject)
|
|
|
|
{
|
2010-12-14 18:51:16 +00:00
|
|
|
aJSTerm.helperEvaluated = true;
|
2010-10-28 16:01:36 +00:00
|
|
|
if (aObject === null || aObject === undefined || aObject === true || aObject === false) {
|
2012-05-10 13:15:10 +00:00
|
|
|
aJSTerm.console.error(l10n.getStr("helperFuncUnsupportedTypeError"));
|
2010-10-28 16:01:36 +00:00
|
|
|
return;
|
|
|
|
}
|
2011-01-04 17:31:48 +00:00
|
|
|
else if (typeof aObject === TYPEOF_FUNCTION) {
|
|
|
|
aJSTerm.writeOutput(aObject + "\n", CATEGORY_OUTPUT, SEVERITY_LOG);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-10-28 16:01:36 +00:00
|
|
|
let output = [];
|
2012-05-10 13:15:10 +00:00
|
|
|
let pairs = namesAndValuesOf(WebConsoleUtils.unwrap(aObject));
|
2010-09-02 21:30:45 +00:00
|
|
|
|
2010-10-28 16:01:36 +00:00
|
|
|
pairs.forEach(function(pair) {
|
|
|
|
output.push(" " + pair.display);
|
|
|
|
});
|
2010-09-02 21:30:45 +00:00
|
|
|
|
2010-12-23 15:59:19 +00:00
|
|
|
aJSTerm.writeOutput(output.join("\n"), CATEGORY_OUTPUT, SEVERITY_LOG);
|
2010-10-28 16:01:36 +00:00
|
|
|
};
|
2010-12-14 18:51:16 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Print a string to the output, as-is.
|
|
|
|
*
|
|
|
|
* @param string aString
|
|
|
|
* A string you want to output.
|
|
|
|
* @returns void
|
|
|
|
*/
|
|
|
|
aJSTerm.sandbox.print = function JSTH_print(aString)
|
|
|
|
{
|
|
|
|
aJSTerm.helperEvaluated = true;
|
2010-12-23 15:59:19 +00:00
|
|
|
aJSTerm.writeOutput("" + aString, CATEGORY_OUTPUT, SEVERITY_LOG);
|
2010-12-14 18:51:16 +00:00
|
|
|
};
|
2010-09-02 21:30:45 +00:00
|
|
|
}
|
|
|
|
|
2010-06-22 16:51:50 +00:00
|
|
|
/**
|
|
|
|
* JSTerm
|
|
|
|
*
|
|
|
|
* JavaScript Terminal: creates input nodes for console code interpretation
|
|
|
|
* and 'JS Workspaces'
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2010-09-13 17:15:59 +00:00
|
|
|
* Create a JSTerminal or attach a JSTerm input node to an existing output node,
|
|
|
|
* given by the parent node.
|
2010-06-22 16:51:50 +00:00
|
|
|
*
|
|
|
|
* @param object aContext
|
|
|
|
* Usually nsIDOMWindow, but doesn't have to be
|
2010-09-13 17:15:59 +00:00
|
|
|
* @param nsIDOMNode aParentNode where to attach the JSTerm
|
2010-06-22 16:51:50 +00:00
|
|
|
* @param object aMixin
|
|
|
|
* Gecko-app (or Jetpack) specific utility object
|
2010-09-13 17:15:59 +00:00
|
|
|
* @param object aConsole
|
|
|
|
* Console object to use within the JSTerm.
|
2010-06-22 16:51:50 +00:00
|
|
|
*/
|
2010-09-13 17:15:59 +00:00
|
|
|
function JSTerm(aContext, aParentNode, aMixin, aConsole)
|
2010-06-22 16:51:50 +00:00
|
|
|
{
|
|
|
|
// set the context, attach the UI by appending to aParentNode
|
|
|
|
|
|
|
|
this.application = appName();
|
|
|
|
this.context = aContext;
|
|
|
|
this.parentNode = aParentNode;
|
|
|
|
this.mixins = aMixin;
|
2010-09-13 17:15:59 +00:00
|
|
|
this.console = aConsole;
|
2012-01-27 18:24:57 +00:00
|
|
|
this.document = aParentNode.ownerDocument
|
2010-06-22 16:51:50 +00:00
|
|
|
|
|
|
|
this.setTimeout = aParentNode.ownerDocument.defaultView.setTimeout;
|
|
|
|
|
2010-12-23 15:59:19 +00:00
|
|
|
let node = aParentNode;
|
|
|
|
while (!node.hasAttribute("id")) {
|
|
|
|
node = node.parentNode;
|
|
|
|
}
|
|
|
|
this.hudId = node.getAttribute("id");
|
|
|
|
|
2012-05-10 15:01:37 +00:00
|
|
|
this.history = [];
|
2010-06-22 16:51:50 +00:00
|
|
|
this.historyIndex = 0;
|
|
|
|
this.historyPlaceHolder = 0; // this.history.length;
|
|
|
|
this.log = LogFactory("*** JSTerm:");
|
2011-05-17 15:07:33 +00:00
|
|
|
this.autocompletePopup = new AutocompletePopup(aParentNode.ownerDocument);
|
|
|
|
this.autocompletePopup.onSelect = this.onAutocompleteSelect.bind(this);
|
|
|
|
this.autocompletePopup.onClick = this.acceptProposedCompletion.bind(this);
|
2010-06-22 16:51:50 +00:00
|
|
|
this.init();
|
|
|
|
}
|
|
|
|
|
|
|
|
JSTerm.prototype = {
|
2012-05-10 13:15:10 +00:00
|
|
|
lastInputValue: "",
|
2010-07-19 14:38:07 +00:00
|
|
|
propertyProvider: JSPropertyProvider,
|
|
|
|
|
|
|
|
COMPLETE_FORWARD: 0,
|
|
|
|
COMPLETE_BACKWARD: 1,
|
|
|
|
COMPLETE_HINT_ONLY: 2,
|
|
|
|
|
2010-06-22 16:51:50 +00:00
|
|
|
init: function JST_init()
|
|
|
|
{
|
|
|
|
this.createSandbox();
|
2011-05-17 14:39:59 +00:00
|
|
|
|
2010-06-22 16:51:50 +00:00
|
|
|
this.inputNode = this.mixins.inputNode;
|
|
|
|
this.outputNode = this.mixins.outputNode;
|
2010-10-05 11:01:44 +00:00
|
|
|
this.completeNode = this.mixins.completeNode;
|
2011-05-17 14:39:59 +00:00
|
|
|
|
2011-08-03 18:04:30 +00:00
|
|
|
this._keyPress = this.keyPress.bind(this);
|
|
|
|
this._inputEventHandler = this.inputEventHandler.bind(this);
|
|
|
|
|
2011-05-17 14:39:59 +00:00
|
|
|
this.inputNode.addEventListener("keypress",
|
2011-08-03 18:04:30 +00:00
|
|
|
this._keyPress, false);
|
2011-05-17 14:39:59 +00:00
|
|
|
this.inputNode.addEventListener("input",
|
2011-08-03 18:04:30 +00:00
|
|
|
this._inputEventHandler, false);
|
2011-05-17 14:39:59 +00:00
|
|
|
this.inputNode.addEventListener("keyup",
|
2011-08-03 18:04:30 +00:00
|
|
|
this._inputEventHandler, false);
|
2010-06-22 16:51:50 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
get codeInputString()
|
|
|
|
{
|
|
|
|
return this.inputNode.value;
|
|
|
|
},
|
|
|
|
|
|
|
|
generateUI: function JST_generateUI()
|
|
|
|
{
|
|
|
|
this.mixins.generateUI();
|
|
|
|
},
|
|
|
|
|
|
|
|
attachUI: function JST_attachUI()
|
|
|
|
{
|
|
|
|
this.mixins.attachUI();
|
|
|
|
},
|
|
|
|
|
|
|
|
createSandbox: function JST_setupSandbox()
|
|
|
|
{
|
|
|
|
// create a JS Sandbox out of this.context
|
2010-10-28 16:01:36 +00:00
|
|
|
this.sandbox = new Cu.Sandbox(this._window,
|
|
|
|
{ sandboxPrototype: this._window, wantXrays: false });
|
2010-06-22 16:51:50 +00:00
|
|
|
this.sandbox.console = this.console;
|
2010-10-28 16:01:36 +00:00
|
|
|
JSTermHelper(this);
|
2010-06-22 16:51:50 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
get _window()
|
|
|
|
{
|
2011-07-15 10:31:34 +00:00
|
|
|
return this.context.get().QueryInterface(Ci.nsIDOMWindow);
|
2010-06-22 16:51:50 +00:00
|
|
|
},
|
2010-11-16 21:34:53 +00:00
|
|
|
|
2010-08-17 21:55:47 +00:00
|
|
|
/**
|
2011-05-27 18:58:05 +00:00
|
|
|
* Evaluates a string in the sandbox.
|
2010-08-17 21:55:47 +00:00
|
|
|
*
|
|
|
|
* @param string aString
|
|
|
|
* String to evaluate in the sandbox.
|
|
|
|
* @returns something
|
|
|
|
* The result of the evaluation.
|
|
|
|
*/
|
|
|
|
evalInSandbox: function JST_evalInSandbox(aString)
|
|
|
|
{
|
2010-11-02 12:58:37 +00:00
|
|
|
// The help function needs to be easy to guess, so we make the () optional
|
|
|
|
if (aString.trim() === "help" || aString.trim() === "?") {
|
|
|
|
aString = "help()";
|
|
|
|
}
|
2011-02-18 17:09:11 +00:00
|
|
|
|
2012-05-10 13:15:10 +00:00
|
|
|
let window = WebConsoleUtils.unwrap(this.sandbox.window);
|
2011-02-18 17:09:11 +00:00
|
|
|
let $ = null, $$ = null;
|
|
|
|
|
|
|
|
// We prefer to execute the page-provided implementations for the $() and
|
|
|
|
// $$() functions.
|
|
|
|
if (typeof window.$ == "function") {
|
|
|
|
$ = this.sandbox.$;
|
|
|
|
delete this.sandbox.$;
|
|
|
|
}
|
|
|
|
if (typeof window.$$ == "function") {
|
|
|
|
$$ = this.sandbox.$$;
|
|
|
|
delete this.sandbox.$$;
|
|
|
|
}
|
|
|
|
|
|
|
|
let result = Cu.evalInSandbox(aString, this.sandbox, "1.8", "Web Console", 1);
|
|
|
|
|
|
|
|
if ($) {
|
|
|
|
this.sandbox.$ = $;
|
|
|
|
}
|
|
|
|
if ($$) {
|
|
|
|
this.sandbox.$$ = $$;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
2010-08-17 21:55:47 +00:00
|
|
|
},
|
|
|
|
|
2010-06-22 16:51:50 +00:00
|
|
|
|
2010-07-16 15:10:36 +00:00
|
|
|
execute: function JST_execute(aExecuteString)
|
2010-06-22 16:51:50 +00:00
|
|
|
{
|
|
|
|
// attempt to execute the content of the inputNode
|
2010-08-17 21:55:47 +00:00
|
|
|
aExecuteString = aExecuteString || this.inputNode.value;
|
|
|
|
if (!aExecuteString) {
|
2010-12-23 15:59:19 +00:00
|
|
|
this.writeOutput("no value to execute", CATEGORY_OUTPUT, SEVERITY_LOG);
|
2010-06-22 16:51:50 +00:00
|
|
|
return;
|
|
|
|
}
|
2010-07-16 15:10:36 +00:00
|
|
|
|
2010-12-23 15:59:19 +00:00
|
|
|
this.writeOutput(aExecuteString, CATEGORY_INPUT, SEVERITY_LOG);
|
2010-07-16 15:10:36 +00:00
|
|
|
|
2010-06-22 16:51:50 +00:00
|
|
|
try {
|
2010-12-14 18:51:16 +00:00
|
|
|
this.helperEvaluated = false;
|
|
|
|
let result = this.evalInSandbox(aExecuteString);
|
2010-06-22 16:51:50 +00:00
|
|
|
|
2010-12-14 18:51:16 +00:00
|
|
|
// Hide undefined results coming from helpers.
|
|
|
|
let shouldShow = !(result === undefined && this.helperEvaluated);
|
|
|
|
if (shouldShow) {
|
2012-05-10 13:15:10 +00:00
|
|
|
let inspectable = WebConsoleUtils.isObjectInspectable(result);
|
|
|
|
let resultString = WebConsoleUtils.formatResult(result);
|
2010-12-14 18:51:16 +00:00
|
|
|
|
|
|
|
if (inspectable) {
|
|
|
|
this.writeOutputJS(aExecuteString, result, resultString);
|
|
|
|
}
|
|
|
|
else {
|
2010-12-23 15:59:19 +00:00
|
|
|
this.writeOutput(resultString, CATEGORY_OUTPUT, SEVERITY_LOG);
|
2010-12-14 18:51:16 +00:00
|
|
|
}
|
2010-07-16 15:55:35 +00:00
|
|
|
}
|
2010-06-22 16:51:50 +00:00
|
|
|
}
|
|
|
|
catch (ex) {
|
2010-12-23 15:59:19 +00:00
|
|
|
this.writeOutput("" + ex, CATEGORY_OUTPUT, SEVERITY_ERROR);
|
2010-06-22 16:51:50 +00:00
|
|
|
}
|
|
|
|
|
2010-08-17 21:55:47 +00:00
|
|
|
this.history.push(aExecuteString);
|
2010-06-22 16:51:50 +00:00
|
|
|
this.historyIndex++;
|
|
|
|
this.historyPlaceHolder = this.history.length;
|
2010-09-09 00:08:49 +00:00
|
|
|
this.setInputValue("");
|
2011-05-17 15:07:33 +00:00
|
|
|
this.clearCompletion();
|
2010-06-22 16:51:50 +00:00
|
|
|
},
|
|
|
|
|
2010-08-17 21:55:47 +00:00
|
|
|
/**
|
|
|
|
* Opens a new PropertyPanel. The panel has two buttons: "Update" reexecutes
|
|
|
|
* the passed aEvalString and places the result inside of the tree. The other
|
|
|
|
* button closes the panel.
|
|
|
|
*
|
|
|
|
* @param string aEvalString
|
|
|
|
* String that was used to eval the aOutputObject. Used as title
|
|
|
|
* and to update the tree content.
|
|
|
|
* @param object aOutputObject
|
|
|
|
* Object to display/inspect inside of the tree.
|
|
|
|
* @param nsIDOMNode aAnchor
|
|
|
|
* A node to popup the panel next to (using "after_pointer").
|
|
|
|
* @returns object the created and opened propertyPanel.
|
|
|
|
*/
|
|
|
|
openPropertyPanel: function JST_openPropertyPanel(aEvalString, aOutputObject,
|
|
|
|
aAnchor)
|
|
|
|
{
|
|
|
|
let self = this;
|
|
|
|
let propPanel;
|
2011-02-14 19:00:21 +00:00
|
|
|
// The property panel has one button:
|
|
|
|
// `Update`: reexecutes the string executed on the command line. The
|
2010-08-17 21:55:47 +00:00
|
|
|
// result will be inspected by this panel.
|
|
|
|
let buttons = [];
|
|
|
|
|
|
|
|
// If there is a evalString passed to this function, then add a `Update`
|
|
|
|
// button to the panel so that the evalString can be reexecuted to update
|
|
|
|
// the content of the panel.
|
|
|
|
if (aEvalString !== null) {
|
|
|
|
buttons.push({
|
2012-05-10 13:15:10 +00:00
|
|
|
label: l10n.getStr("update.button"),
|
|
|
|
accesskey: l10n.getStr("update.accesskey"),
|
2010-08-17 21:55:47 +00:00
|
|
|
oncommand: function () {
|
|
|
|
try {
|
|
|
|
var result = self.evalInSandbox(aEvalString);
|
|
|
|
|
|
|
|
if (result !== undefined) {
|
|
|
|
// TODO: This updates the value of the tree.
|
|
|
|
// However, the states of opened nodes is not saved.
|
|
|
|
// See bug 586246.
|
|
|
|
propPanel.treeView.data = result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (ex) {
|
|
|
|
self.console.error(ex);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2012-01-27 18:24:57 +00:00
|
|
|
let doc = self.document;
|
2010-08-17 21:55:47 +00:00
|
|
|
let parent = doc.getElementById("mainPopupSet");
|
|
|
|
let title = (aEvalString
|
2012-05-10 13:15:10 +00:00
|
|
|
? l10n.getFormatStr("jsPropertyInspectTitle", [aEvalString])
|
|
|
|
: l10n.getStr("jsPropertyTitle"));
|
2011-02-14 19:00:21 +00:00
|
|
|
|
2010-08-17 21:55:47 +00:00
|
|
|
propPanel = new PropertyPanel(parent, doc, title, aOutputObject, buttons);
|
2011-02-14 19:00:21 +00:00
|
|
|
propPanel.linkNode = aAnchor;
|
2010-08-17 21:55:47 +00:00
|
|
|
|
|
|
|
let panel = propPanel.panel;
|
|
|
|
panel.openPopup(aAnchor, "after_pointer", 0, 0, false, false);
|
2011-01-28 12:22:31 +00:00
|
|
|
panel.sizeTo(350, 450);
|
2010-08-17 21:55:47 +00:00
|
|
|
return propPanel;
|
|
|
|
},
|
|
|
|
|
2012-05-10 13:15:10 +00:00
|
|
|
/**
|
|
|
|
* Opens a new property panel that allows the inspection of the given object.
|
|
|
|
* The object information can be retrieved both async and sync, depending on
|
|
|
|
* the given options.
|
|
|
|
*
|
|
|
|
* @param object aOptions
|
|
|
|
* Property panel options:
|
|
|
|
* - title:
|
|
|
|
* Panel title.
|
|
|
|
* - anchor:
|
|
|
|
* The DOM element you want the panel to be anchored to.
|
|
|
|
* - updateButtonCallback:
|
|
|
|
* An optional function you want invoked when the user clicks the
|
|
|
|
* Update button. If this function is not provided the Update button is
|
|
|
|
* not shown.
|
|
|
|
* - data:
|
|
|
|
* An object that represents the object you want to inspect. Please see
|
|
|
|
* the PropertyPanelAsync documentation - this object is passed to the
|
|
|
|
* PropertyPanelAsync constructor
|
|
|
|
* @param object aResponse
|
|
|
|
* The response object to display/inspect inside of the tree.
|
|
|
|
* @param nsIDOMNode aAnchor
|
|
|
|
* A node to popup the panel next to (using "after_pointer").
|
|
|
|
* @return object
|
|
|
|
* The new instance of PropertyPanelAsync.
|
|
|
|
*/
|
|
|
|
openPropertyPanelAsync: function JST_openPropertyPanelAsync(aOptions)
|
|
|
|
{
|
|
|
|
// The property panel has one button:
|
|
|
|
// `Update`: reexecutes the string executed on the command line. The
|
|
|
|
// result will be inspected by this panel.
|
|
|
|
let buttons = [];
|
|
|
|
|
|
|
|
if (aOptions.updateButtonCallback) {
|
|
|
|
buttons.push({
|
|
|
|
label: l10n.getStr("update.button"),
|
|
|
|
accesskey: l10n.getStr("update.accesskey"),
|
|
|
|
oncommand: aOptions.updateButtonCallback,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
let parent = this.document.getElementById("mainPopupSet");
|
|
|
|
let title = aOptions.title ?
|
|
|
|
l10n.getFormatStr("jsPropertyInspectTitle", [aOptions.title]) :
|
|
|
|
l10n.getStr("jsPropertyTitle");
|
|
|
|
|
|
|
|
let propPanel = new PropertyPanelAsync(parent, title, aOptions.data, buttons);
|
|
|
|
|
|
|
|
propPanel.panel.openPopup(aOptions.anchor, "after_pointer", 0, 0, false, false);
|
|
|
|
propPanel.panel.sizeTo(350, 450);
|
|
|
|
|
|
|
|
if (aOptions.anchor) {
|
|
|
|
propPanel.panel.addEventListener("popuphiding", function onPopupHide() {
|
|
|
|
propPanel.panel.removeEventListener("popuphiding", onPopupHide, false);
|
|
|
|
aOptions.anchor._panelOpen = false;
|
|
|
|
}, false);
|
|
|
|
aOptions.anchor._panelOpen = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return propPanel;
|
|
|
|
},
|
|
|
|
|
2010-08-17 21:55:47 +00:00
|
|
|
/**
|
|
|
|
* Writes a JS object to the JSTerm outputNode. If the user clicks on the
|
|
|
|
* written object, openPropertyPanel is called to open up a panel to inspect
|
|
|
|
* the object.
|
|
|
|
*
|
|
|
|
* @param string aEvalString
|
|
|
|
* String that was evaluated to get the aOutputObject.
|
2010-12-14 18:51:16 +00:00
|
|
|
* @param object aResultObject
|
|
|
|
* The evaluation result object.
|
|
|
|
* @param object aOutputString
|
|
|
|
* The output string to be written to the outputNode.
|
2010-08-17 21:55:47 +00:00
|
|
|
*/
|
2010-12-14 18:51:16 +00:00
|
|
|
writeOutputJS: function JST_writeOutputJS(aEvalString, aOutputObject, aOutputString)
|
2010-08-17 21:55:47 +00:00
|
|
|
{
|
2012-01-27 18:24:57 +00:00
|
|
|
let node = ConsoleUtils.createMessageNode(this.document,
|
2010-12-23 15:59:19 +00:00
|
|
|
CATEGORY_OUTPUT,
|
|
|
|
SEVERITY_LOG,
|
2011-06-14 11:38:11 +00:00
|
|
|
aOutputString,
|
|
|
|
this.hudId);
|
2010-08-17 21:55:47 +00:00
|
|
|
|
2010-12-23 15:59:19 +00:00
|
|
|
let linkNode = node.querySelector(".webconsole-msg-body");
|
2010-10-11 21:37:34 +00:00
|
|
|
|
2010-12-23 15:59:19 +00:00
|
|
|
linkNode.classList.add("hud-clickable");
|
|
|
|
linkNode.setAttribute("aria-haspopup", "true");
|
|
|
|
|
|
|
|
// Make the object bring up the property panel.
|
2010-10-11 21:37:34 +00:00
|
|
|
node.addEventListener("mousedown", function(aEvent) {
|
|
|
|
this._startX = aEvent.clientX;
|
|
|
|
this._startY = aEvent.clientY;
|
|
|
|
}, false);
|
|
|
|
|
2010-12-23 15:59:19 +00:00
|
|
|
let self = this;
|
2010-10-11 21:37:34 +00:00
|
|
|
node.addEventListener("click", function(aEvent) {
|
|
|
|
if (aEvent.detail != 1 || aEvent.button != 0 ||
|
|
|
|
(this._startX != aEvent.clientX &&
|
|
|
|
this._startY != aEvent.clientY)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!this._panelOpen) {
|
2011-03-25 16:42:09 +00:00
|
|
|
let propPanel = self.openPropertyPanel(aEvalString, aOutputObject, this);
|
|
|
|
propPanel.panel.setAttribute("hudId", self.hudId);
|
2010-10-11 21:37:34 +00:00
|
|
|
this._panelOpen = true;
|
|
|
|
}
|
|
|
|
}, false);
|
2010-08-17 21:55:47 +00:00
|
|
|
|
2010-12-23 15:59:19 +00:00
|
|
|
ConsoleUtils.outputMessageNode(node, this.hudId);
|
2010-08-17 21:55:47 +00:00
|
|
|
},
|
|
|
|
|
2010-07-28 18:15:34 +00:00
|
|
|
/**
|
|
|
|
* Writes a message to the HUD that originates from the interactive
|
|
|
|
* JavaScript console.
|
|
|
|
*
|
|
|
|
* @param string aOutputMessage
|
|
|
|
* The message to display.
|
2010-12-23 15:59:19 +00:00
|
|
|
* @param number aCategory
|
|
|
|
* The category of message: one of the CATEGORY_ constants.
|
|
|
|
* @param number aSeverity
|
|
|
|
* The severity of message: one of the SEVERITY_ constants.
|
2010-07-28 18:15:34 +00:00
|
|
|
* @returns void
|
|
|
|
*/
|
2010-12-23 15:59:19 +00:00
|
|
|
writeOutput: function JST_writeOutput(aOutputMessage, aCategory, aSeverity)
|
2010-06-22 16:51:50 +00:00
|
|
|
{
|
2012-01-27 18:24:57 +00:00
|
|
|
let node = ConsoleUtils.createMessageNode(this.document,
|
2010-12-23 15:59:19 +00:00
|
|
|
aCategory, aSeverity,
|
2011-06-14 11:38:11 +00:00
|
|
|
aOutputMessage, this.hudId);
|
2010-07-28 18:15:34 +00:00
|
|
|
|
2010-12-23 15:59:19 +00:00
|
|
|
ConsoleUtils.outputMessageNode(node, this.hudId);
|
2010-06-22 16:51:50 +00:00
|
|
|
},
|
|
|
|
|
2012-01-11 10:51:49 +00:00
|
|
|
/**
|
|
|
|
* Clear the Web Console output.
|
|
|
|
*
|
|
|
|
* @param boolean aClearStorage
|
|
|
|
* True if you want to clear the console messages storage associated to
|
|
|
|
* this Web Console.
|
|
|
|
*/
|
|
|
|
clearOutput: function JST_clearOutput(aClearStorage)
|
2010-07-16 15:10:36 +00:00
|
|
|
{
|
2011-07-07 15:19:58 +00:00
|
|
|
let hud = HUDService.getHudReferenceById(this.hudId);
|
|
|
|
hud.cssNodes = {};
|
2011-02-25 22:12:42 +00:00
|
|
|
|
2012-05-10 13:15:10 +00:00
|
|
|
let outputNode = hud.outputNode;
|
|
|
|
let node;
|
|
|
|
while ((node = outputNode.firstChild)) {
|
|
|
|
if (node._evalCacheId && !node._panelOpen) {
|
|
|
|
this.clearObjectCache(node._evalCacheId);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (node.classList &&
|
|
|
|
node.classList.contains("webconsole-msg-inspector")) {
|
|
|
|
hud.pruneConsoleDirNode(node);
|
2011-06-09 13:27:30 +00:00
|
|
|
}
|
|
|
|
else {
|
2012-05-10 13:15:10 +00:00
|
|
|
outputNode.removeChild(node);
|
2011-06-09 13:27:30 +00:00
|
|
|
}
|
2011-02-25 22:12:42 +00:00
|
|
|
}
|
2010-07-16 15:10:36 +00:00
|
|
|
|
2011-07-07 15:19:58 +00:00
|
|
|
hud.HUDBox.lastTimestamp = 0;
|
2011-11-17 10:57:37 +00:00
|
|
|
hud.groupDepth = 0;
|
2012-01-11 10:51:49 +00:00
|
|
|
|
|
|
|
if (aClearStorage) {
|
2012-05-10 13:15:10 +00:00
|
|
|
hud.sendMessageToContent("ConsoleAPI:ClearCache", {});
|
2012-01-11 10:51:49 +00:00
|
|
|
}
|
2010-07-16 15:10:36 +00:00
|
|
|
},
|
|
|
|
|
2010-09-09 00:08:49 +00: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;
|
2011-06-23 13:40:38 +00:00
|
|
|
this.lastInputValue = aNewValue;
|
2010-12-09 20:18:26 +00:00
|
|
|
this.completeNode.value = "";
|
2010-09-09 00:08:49 +00:00
|
|
|
this.resizeInput();
|
|
|
|
},
|
|
|
|
|
2011-05-17 14:39:59 +00:00
|
|
|
/**
|
|
|
|
* The inputNode "input" and "keyup" event handler.
|
|
|
|
*
|
|
|
|
* @param nsIDOMEvent aEvent
|
|
|
|
*/
|
|
|
|
inputEventHandler: function JSTF_inputEventHandler(aEvent)
|
2010-08-10 22:04:43 +00:00
|
|
|
{
|
2011-05-17 14:39:59 +00:00
|
|
|
if (this.lastInputValue != this.inputNode.value) {
|
|
|
|
this.resizeInput();
|
|
|
|
this.complete(this.COMPLETE_HINT_ONLY);
|
|
|
|
this.lastInputValue = this.inputNode.value;
|
2010-08-10 22:04:43 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2011-05-17 14:39:59 +00:00
|
|
|
/**
|
|
|
|
* The inputNode "keypress" event handler.
|
|
|
|
*
|
|
|
|
* @param nsIDOMEvent aEvent
|
|
|
|
*/
|
|
|
|
keyPress: function JSTF_keyPress(aEvent)
|
2010-06-22 16:51:50 +00:00
|
|
|
{
|
2011-05-17 14:39:59 +00:00
|
|
|
if (aEvent.ctrlKey) {
|
|
|
|
switch (aEvent.charCode) {
|
|
|
|
case 97:
|
|
|
|
// control-a
|
|
|
|
this.inputNode.setSelectionRange(0, 0);
|
|
|
|
aEvent.preventDefault();
|
|
|
|
break;
|
|
|
|
case 101:
|
|
|
|
// control-e
|
|
|
|
this.inputNode.setSelectionRange(this.inputNode.value.length,
|
|
|
|
this.inputNode.value.length);
|
|
|
|
aEvent.preventDefault();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2010-06-22 16:51:50 +00:00
|
|
|
}
|
2011-05-17 14:39:59 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if (aEvent.shiftKey &&
|
|
|
|
aEvent.keyCode == Ci.nsIDOMKeyEvent.DOM_VK_RETURN) {
|
|
|
|
// shift return
|
|
|
|
// TODO: expand the inputNode height by one line
|
|
|
|
return;
|
|
|
|
}
|
2010-10-05 11:01:44 +00:00
|
|
|
|
2011-05-17 15:07:33 +00:00
|
|
|
let inputUpdated = false;
|
|
|
|
|
2011-05-17 14:39:59 +00:00
|
|
|
switch(aEvent.keyCode) {
|
2011-05-17 15:07:33 +00:00
|
|
|
case Ci.nsIDOMKeyEvent.DOM_VK_ESCAPE:
|
|
|
|
if (this.autocompletePopup.isOpen) {
|
|
|
|
this.clearCompletion();
|
|
|
|
aEvent.preventDefault();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2011-05-17 14:39:59 +00:00
|
|
|
case Ci.nsIDOMKeyEvent.DOM_VK_RETURN:
|
2011-12-13 13:47:31 +00:00
|
|
|
if (this.autocompletePopup.isOpen && this.autocompletePopup.selectedIndex > -1) {
|
2011-05-17 15:07:33 +00:00
|
|
|
this.acceptProposedCompletion();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
this.execute();
|
|
|
|
}
|
2011-05-17 14:39:59 +00:00
|
|
|
aEvent.preventDefault();
|
|
|
|
break;
|
2010-10-05 11:01:44 +00:00
|
|
|
|
2011-05-17 14:39:59 +00:00
|
|
|
case Ci.nsIDOMKeyEvent.DOM_VK_UP:
|
2011-05-17 15:07:33 +00:00
|
|
|
if (this.autocompletePopup.isOpen) {
|
|
|
|
inputUpdated = this.complete(this.COMPLETE_BACKWARD);
|
|
|
|
}
|
|
|
|
else if (this.canCaretGoPrevious()) {
|
|
|
|
inputUpdated = this.historyPeruse(HISTORY_BACK);
|
|
|
|
}
|
|
|
|
if (inputUpdated) {
|
|
|
|
aEvent.preventDefault();
|
2011-05-17 14:39:59 +00:00
|
|
|
}
|
|
|
|
break;
|
2010-10-05 11:01:44 +00:00
|
|
|
|
2011-05-17 14:39:59 +00:00
|
|
|
case Ci.nsIDOMKeyEvent.DOM_VK_DOWN:
|
2011-05-17 15:07:33 +00:00
|
|
|
if (this.autocompletePopup.isOpen) {
|
|
|
|
inputUpdated = this.complete(this.COMPLETE_FORWARD);
|
|
|
|
}
|
|
|
|
else if (this.canCaretGoNext()) {
|
|
|
|
inputUpdated = this.historyPeruse(HISTORY_FORWARD);
|
|
|
|
}
|
|
|
|
if (inputUpdated) {
|
|
|
|
aEvent.preventDefault();
|
2011-05-17 14:39:59 +00:00
|
|
|
}
|
|
|
|
break;
|
2010-10-05 11:01:44 +00:00
|
|
|
|
2011-05-17 14:39:59 +00:00
|
|
|
case Ci.nsIDOMKeyEvent.DOM_VK_TAB:
|
2011-05-17 15:07:33 +00:00
|
|
|
// Generate a completion and accept the first proposed value.
|
|
|
|
if (this.complete(this.COMPLETE_HINT_ONLY) &&
|
|
|
|
this.lastCompletion &&
|
|
|
|
this.acceptProposedCompletion()) {
|
|
|
|
aEvent.preventDefault();
|
2011-05-17 14:39:59 +00:00
|
|
|
}
|
2011-12-20 17:49:39 +00:00
|
|
|
else {
|
2012-05-10 13:15:10 +00:00
|
|
|
this.updateCompleteNode(l10n.getStr("Autocomplete.blank"));
|
2011-12-20 17:49:39 +00:00
|
|
|
aEvent.preventDefault();
|
|
|
|
}
|
2011-05-17 14:39:59 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
2010-06-22 16:51:50 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2010-10-20 17:39:44 +00: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)
|
|
|
|
{
|
2010-06-22 16:51:50 +00:00
|
|
|
if (!this.history.length) {
|
2010-10-20 17:39:44 +00:00
|
|
|
return false;
|
2010-06-22 16:51:50 +00:00
|
|
|
}
|
2010-07-16 15:00:38 +00:00
|
|
|
|
2010-06-22 16:51:50 +00:00
|
|
|
// Up Arrow key
|
2010-10-20 17:39:44 +00:00
|
|
|
if (aDirection == HISTORY_BACK) {
|
2010-07-16 15:00:38 +00:00
|
|
|
if (this.historyPlaceHolder <= 0) {
|
2010-10-20 17:39:44 +00:00
|
|
|
return false;
|
2010-06-22 16:51:50 +00:00
|
|
|
}
|
|
|
|
|
2010-07-16 15:00:38 +00:00
|
|
|
let inputVal = this.history[--this.historyPlaceHolder];
|
2010-06-22 16:51:50 +00:00
|
|
|
if (inputVal){
|
2010-09-09 00:08:49 +00:00
|
|
|
this.setInputValue(inputVal);
|
2010-06-22 16:51:50 +00:00
|
|
|
}
|
|
|
|
}
|
2010-07-16 15:00:38 +00:00
|
|
|
// Down Arrow key
|
2010-10-20 17:39:44 +00:00
|
|
|
else if (aDirection == HISTORY_FORWARD) {
|
2010-07-16 15:00:38 +00:00
|
|
|
if (this.historyPlaceHolder == this.history.length - 1) {
|
|
|
|
this.historyPlaceHolder ++;
|
2010-09-09 00:08:49 +00:00
|
|
|
this.setInputValue("");
|
2010-06-22 16:51:50 +00:00
|
|
|
}
|
2010-07-16 15:00:38 +00:00
|
|
|
else if (this.historyPlaceHolder >= (this.history.length)) {
|
2010-10-20 17:39:44 +00:00
|
|
|
return false;
|
2010-07-16 15:00:38 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
let inputVal = this.history[++this.historyPlaceHolder];
|
|
|
|
if (inputVal){
|
2010-09-09 00:08:49 +00:00
|
|
|
this.setInputValue(inputVal);
|
2010-07-16 15:00:38 +00:00
|
|
|
}
|
2010-06-22 16:51:50 +00:00
|
|
|
}
|
|
|
|
}
|
2010-10-20 17:39:44 +00:00
|
|
|
else {
|
|
|
|
throw new Error("Invalid argument 0");
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2010-06-22 16:51:50 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
refocus: function JSTF_refocus()
|
|
|
|
{
|
|
|
|
this.inputNode.blur();
|
|
|
|
this.inputNode.focus();
|
|
|
|
},
|
|
|
|
|
2010-10-20 17:39:44 +00:00
|
|
|
/**
|
2011-03-25 16:42:09 +00: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.
|
2010-10-20 17:39:44 +00:00
|
|
|
*
|
2011-03-25 16:42:09 +00:00
|
|
|
* @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.
|
2010-10-20 17:39:44 +00:00
|
|
|
*/
|
2011-03-25 16:42:09 +00:00
|
|
|
canCaretGoPrevious: function JST_canCaretGoPrevious()
|
2010-06-22 16:51:50 +00:00
|
|
|
{
|
2011-03-25 16:42:09 +00:00
|
|
|
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;
|
2010-06-22 16:51:50 +00:00
|
|
|
},
|
|
|
|
|
2010-10-20 17:39:44 +00:00
|
|
|
/**
|
2011-03-25 16:42:09 +00:00
|
|
|
* Check if the caret is at a location that allows selecting the next item in
|
|
|
|
* history when the user presses the Down arrow key.
|
2010-10-20 17:39:44 +00:00
|
|
|
*
|
2011-03-25 16:42:09 +00:00
|
|
|
* @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.
|
2010-10-20 17:39:44 +00:00
|
|
|
*/
|
2011-03-25 16:42:09 +00:00
|
|
|
canCaretGoNext: function JST_canCaretGoNext()
|
2010-06-22 16:51:50 +00:00
|
|
|
{
|
2011-03-25 16:42:09 +00:00
|
|
|
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;
|
2010-06-22 16:51:50 +00:00
|
|
|
},
|
|
|
|
|
2012-05-10 15:01:37 +00:00
|
|
|
history: null,
|
2010-06-22 16:51:50 +00:00
|
|
|
|
2010-07-19 14:38:07 +00:00
|
|
|
// Stores the data for the last completion.
|
|
|
|
lastCompletion: null,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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 type 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.
|
|
|
|
*
|
2010-10-11 21:37:23 +00:00
|
|
|
* @returns boolean true if there existed a completion for the current input,
|
|
|
|
* or false otherwise.
|
2010-07-19 14:38:07 +00:00
|
|
|
*/
|
|
|
|
complete: function JSTF_complete(type)
|
|
|
|
{
|
|
|
|
let inputNode = this.inputNode;
|
|
|
|
let inputValue = inputNode.value;
|
2010-08-09 19:02:20 +00:00
|
|
|
// If the inputNode has no value, then don't try to complete on it.
|
|
|
|
if (!inputValue) {
|
2011-05-17 15:07:33 +00:00
|
|
|
this.clearCompletion();
|
2010-10-11 21:37:23 +00:00
|
|
|
return false;
|
2010-08-09 19:02:20 +00:00
|
|
|
}
|
2010-07-19 14:38:07 +00:00
|
|
|
|
2010-10-05 11:01:44 +00:00
|
|
|
// Only complete if the selection is empty and at the end of the input.
|
|
|
|
if (inputNode.selectionStart == inputNode.selectionEnd &&
|
|
|
|
inputNode.selectionEnd != inputValue.length) {
|
2011-05-17 15:07:33 +00:00
|
|
|
this.clearCompletion();
|
2010-10-11 21:37:23 +00:00
|
|
|
return false;
|
2010-07-19 14:38:07 +00:00
|
|
|
}
|
|
|
|
|
2011-05-17 15:07:33 +00:00
|
|
|
let popup = this.autocompletePopup;
|
2010-07-19 14:38:07 +00:00
|
|
|
|
2011-05-17 15:07:33 +00:00
|
|
|
if (!this.lastCompletion || this.lastCompletion.value != inputValue) {
|
|
|
|
let properties = this.propertyProvider(this.sandbox.window, inputValue);
|
|
|
|
if (!properties || !properties.matches.length) {
|
|
|
|
this.clearCompletion();
|
|
|
|
return false;
|
2010-07-19 14:38:07 +00:00
|
|
|
}
|
2011-05-17 15:07:33 +00:00
|
|
|
|
|
|
|
let items = properties.matches.map(function(aMatch) {
|
|
|
|
return {label: aMatch};
|
|
|
|
});
|
|
|
|
popup.setItems(items);
|
|
|
|
this.lastCompletion = {value: inputValue,
|
|
|
|
matchProp: properties.matchProp};
|
|
|
|
|
|
|
|
if (items.length > 1 && !popup.isOpen) {
|
|
|
|
popup.openPopup(this.inputNode);
|
2010-07-19 14:38:07 +00:00
|
|
|
}
|
2011-05-17 15:07:33 +00:00
|
|
|
else if (items.length < 2 && popup.isOpen) {
|
|
|
|
popup.hidePopup();
|
|
|
|
}
|
|
|
|
|
2011-12-13 13:47:31 +00:00
|
|
|
if (items.length == 1) {
|
|
|
|
popup.selectedIndex = 0;
|
2010-07-19 14:38:07 +00:00
|
|
|
}
|
2011-12-13 13:47:31 +00:00
|
|
|
this.onAutocompleteSelect();
|
2010-07-19 14:38:07 +00:00
|
|
|
}
|
|
|
|
|
2011-05-17 15:07:33 +00:00
|
|
|
let accepted = false;
|
|
|
|
|
|
|
|
if (type != this.COMPLETE_HINT_ONLY && popup.itemCount == 1) {
|
2010-10-05 11:01:44 +00:00
|
|
|
this.acceptProposedCompletion();
|
2011-05-17 15:07:33 +00:00
|
|
|
accepted = true;
|
2010-10-05 11:01:44 +00:00
|
|
|
}
|
2011-05-17 15:07:33 +00:00
|
|
|
else if (type == this.COMPLETE_BACKWARD) {
|
|
|
|
this.autocompletePopup.selectPreviousItem();
|
|
|
|
}
|
|
|
|
else if (type == this.COMPLETE_FORWARD) {
|
|
|
|
this.autocompletePopup.selectNextItem();
|
|
|
|
}
|
|
|
|
|
|
|
|
return accepted || popup.itemCount > 0;
|
|
|
|
},
|
2010-07-19 14:38:07 +00:00
|
|
|
|
2011-05-17 15:07:33 +00:00
|
|
|
onAutocompleteSelect: function JSTF_onAutocompleteSelect()
|
|
|
|
{
|
|
|
|
let currentItem = this.autocompletePopup.selectedItem;
|
|
|
|
if (currentItem && this.lastCompletion) {
|
|
|
|
let suffix = currentItem.label.substring(this.lastCompletion.
|
|
|
|
matchProp.length);
|
|
|
|
this.updateCompleteNode(suffix);
|
2010-07-19 14:38:07 +00:00
|
|
|
}
|
2010-10-05 11:01:44 +00:00
|
|
|
else {
|
|
|
|
this.updateCompleteNode("");
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2011-05-17 15:07:33 +00:00
|
|
|
/**
|
|
|
|
* Clear the current completion information and close the autocomplete popup,
|
|
|
|
* if needed.
|
|
|
|
*/
|
|
|
|
clearCompletion: function JSTF_clearCompletion()
|
2010-10-05 11:01:44 +00:00
|
|
|
{
|
2011-05-17 15:07:33 +00:00
|
|
|
this.autocompletePopup.clearItems();
|
|
|
|
this.lastCompletion = null;
|
2010-10-05 11:01:44 +00:00
|
|
|
this.updateCompleteNode("");
|
2011-05-17 15:07:33 +00:00
|
|
|
if (this.autocompletePopup.isOpen) {
|
|
|
|
this.autocompletePopup.hidePopup();
|
|
|
|
}
|
2010-10-05 11:01:44 +00:00
|
|
|
},
|
|
|
|
|
2011-05-17 15:07:33 +00: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()
|
2010-10-05 11:01:44 +00:00
|
|
|
{
|
2011-05-17 15:07:33 +00:00
|
|
|
let updated = false;
|
|
|
|
|
|
|
|
let currentItem = this.autocompletePopup.selectedItem;
|
|
|
|
if (currentItem && this.lastCompletion) {
|
|
|
|
let suffix = currentItem.label.substring(this.lastCompletion.
|
|
|
|
matchProp.length);
|
|
|
|
this.setInputValue(this.inputNode.value + suffix);
|
|
|
|
updated = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.clearCompletion();
|
|
|
|
|
|
|
|
return updated;
|
|
|
|
},
|
2010-10-05 11:01:44 +00:00
|
|
|
|
2011-05-17 15:07:33 +00:00
|
|
|
/**
|
|
|
|
* 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)
|
|
|
|
{
|
2010-12-21 09:31:31 +00:00
|
|
|
// completion prefix = input, with non-control chars replaced by spaces
|
2011-05-17 15:07:33 +00:00
|
|
|
let prefix = aSuffix ? this.inputNode.value.replace(/[\S]/g, " ") : "";
|
|
|
|
this.completeNode.value = prefix + aSuffix;
|
2010-10-05 11:01:44 +00:00
|
|
|
},
|
2011-08-03 18:04:30 +00:00
|
|
|
|
2012-05-10 13:15:10 +00:00
|
|
|
/**
|
|
|
|
* Clear the object cache from the Web Console content instance.
|
|
|
|
*
|
|
|
|
* @param string aCacheId
|
|
|
|
* The cache ID you want to clear. Multiple objects are cached into one
|
|
|
|
* group which is given an ID.
|
|
|
|
*/
|
|
|
|
clearObjectCache: function JST_clearObjectCache(aCacheId)
|
|
|
|
{
|
|
|
|
let hud = HUDService.getHudReferenceById(this.hudId);
|
|
|
|
hud.sendMessageToContent("JSTerm:ClearObjectCache", {cacheId: aCacheId});
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The remote object provider allows you to retrieve a given object from
|
|
|
|
* a specific cache and have your callback invoked when the desired object is
|
|
|
|
* received from the Web Console content instance.
|
|
|
|
*
|
|
|
|
* @param string aCacheId
|
|
|
|
* Retrieve the desired object from this cache ID.
|
|
|
|
* @param string aObjectId
|
|
|
|
* The ID of the object you want.
|
|
|
|
* @param string aResultCacheId
|
|
|
|
* The ID of the cache where you want any object references to be
|
|
|
|
* stored into.
|
|
|
|
* @param function aCallback
|
|
|
|
* The function you want invoked when the desired object is retrieved.
|
|
|
|
*/
|
|
|
|
remoteObjectProvider:
|
|
|
|
function JST_remoteObjectProvider(aCacheId, aObjectId, aResultCacheId,
|
|
|
|
aCallback) {
|
|
|
|
let message = {
|
|
|
|
cacheId: aCacheId,
|
|
|
|
objectId: aObjectId,
|
|
|
|
resultCacheId: aResultCacheId,
|
|
|
|
};
|
|
|
|
|
|
|
|
let hud = HUDService.getHudReferenceById(this.hudId);
|
|
|
|
hud.sendMessageToContent("JSTerm:GetEvalObject", message, aCallback);
|
|
|
|
},
|
|
|
|
|
2011-08-03 18:04:30 +00:00
|
|
|
/**
|
|
|
|
* Destroy the JSTerm object. Call this method to avoid memory leaks.
|
|
|
|
*/
|
|
|
|
destroy: function JST_destroy()
|
|
|
|
{
|
|
|
|
this.inputNode.removeEventListener("keypress", this._keyPress, false);
|
|
|
|
this.inputNode.removeEventListener("input", this._inputEventHandler, false);
|
|
|
|
this.inputNode.removeEventListener("keyup", this._inputEventHandler, false);
|
|
|
|
},
|
2010-06-22 16:51:50 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2010-12-23 15:59:19 +00:00
|
|
|
* Generates and attaches the JS Terminal part of the Web Console, which
|
|
|
|
* essentially consists of the interactive JavaScript input facility.
|
2010-06-22 16:51:50 +00:00
|
|
|
*
|
2010-12-23 15:59:19 +00:00
|
|
|
* @param nsWeakPtr<nsIDOMWindow> aContext
|
|
|
|
* A weak pointer to the DOM window that contains the Web Console.
|
|
|
|
* @param nsIDOMNode aParentNode
|
|
|
|
* The Web Console wrapper node.
|
|
|
|
* @param nsIDOMNode aExistingConsole
|
|
|
|
* The Web Console output node.
|
|
|
|
* @return void
|
2010-06-22 16:51:50 +00:00
|
|
|
*/
|
|
|
|
function
|
|
|
|
JSTermFirefoxMixin(aContext,
|
|
|
|
aParentNode,
|
2010-12-23 15:59:19 +00:00
|
|
|
aExistingConsole)
|
2010-06-22 16:51:50 +00:00
|
|
|
{
|
|
|
|
// aExisting Console is the existing outputNode to use in favor of
|
|
|
|
// creating a new outputNode - this is so we can just attach the inputNode to
|
|
|
|
// a normal HeadsUpDisplay console output, and re-use code.
|
|
|
|
this.context = aContext;
|
|
|
|
this.parentNode = aParentNode;
|
|
|
|
this.existingConsoleNode = aExistingConsole;
|
|
|
|
this.setTimeout = aParentNode.ownerDocument.defaultView.setTimeout;
|
|
|
|
|
|
|
|
if (aParentNode.ownerDocument) {
|
|
|
|
this.xulElementFactory =
|
|
|
|
NodeFactory("xul", "xul", aParentNode.ownerDocument);
|
|
|
|
|
|
|
|
this.textFactory = NodeFactory("text", "xul", aParentNode.ownerDocument);
|
|
|
|
this.generateUI();
|
|
|
|
this.attachUI();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
throw new Error("aParentNode should be a DOM node with an ownerDocument property ");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
JSTermFirefoxMixin.prototype = {
|
|
|
|
/**
|
|
|
|
* Generates and attaches the UI for an entire JS Workspace or
|
|
|
|
* just the input node used under the console output
|
|
|
|
*
|
|
|
|
* @returns void
|
|
|
|
*/
|
|
|
|
generateUI: function JSTF_generateUI()
|
|
|
|
{
|
2010-10-05 11:01:44 +00:00
|
|
|
this.completeNode = this.xulElementFactory("textbox");
|
|
|
|
this.completeNode.setAttribute("class", "jsterm-complete-node");
|
|
|
|
this.completeNode.setAttribute("multiline", "true");
|
|
|
|
this.completeNode.setAttribute("rows", "1");
|
2011-05-27 12:49:02 +00:00
|
|
|
this.completeNode.setAttribute("tabindex", "-1");
|
2010-10-05 11:01:44 +00:00
|
|
|
|
|
|
|
this.inputNode = this.xulElementFactory("textbox");
|
|
|
|
this.inputNode.setAttribute("class", "jsterm-input-node");
|
|
|
|
this.inputNode.setAttribute("multiline", "true");
|
|
|
|
this.inputNode.setAttribute("rows", "1");
|
|
|
|
|
|
|
|
let inputStack = this.xulElementFactory("stack");
|
|
|
|
inputStack.setAttribute("class", "jsterm-stack-node");
|
|
|
|
inputStack.setAttribute("flex", "1");
|
|
|
|
inputStack.appendChild(this.completeNode);
|
|
|
|
inputStack.appendChild(this.inputNode);
|
2010-06-22 16:51:50 +00:00
|
|
|
|
|
|
|
if (this.existingConsoleNode == undefined) {
|
2011-05-27 12:49:02 +00:00
|
|
|
throw new Error("This can't happen");
|
2010-06-22 16:51:50 +00:00
|
|
|
}
|
2010-10-05 11:01:44 +00:00
|
|
|
|
2011-05-27 12:49:02 +00:00
|
|
|
this.outputNode = this.existingConsoleNode;
|
|
|
|
|
|
|
|
this.term = this.xulElementFactory("hbox");
|
|
|
|
this.term.setAttribute("class", "jsterm-input-container");
|
|
|
|
this.term.setAttribute("style", "direction: ltr;");
|
|
|
|
this.term.appendChild(inputStack);
|
2010-06-22 16:51:50 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
get inputValue()
|
|
|
|
{
|
|
|
|
return this.inputNode.value;
|
|
|
|
},
|
|
|
|
|
|
|
|
attachUI: function JSTF_attachUI()
|
|
|
|
{
|
|
|
|
this.parentNode.appendChild(this.term);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Firefox-specific Application Hooks.
|
|
|
|
* Each Gecko-based application will need an object like this in
|
|
|
|
* order to use the Heads Up Display
|
|
|
|
*/
|
|
|
|
function FirefoxApplicationHooks()
|
|
|
|
{ }
|
|
|
|
|
|
|
|
FirefoxApplicationHooks.prototype = {
|
|
|
|
/**
|
|
|
|
* gets the current contentWindow (Firefox-specific)
|
|
|
|
*
|
|
|
|
* @returns nsIDOMWindow
|
|
|
|
*/
|
|
|
|
getCurrentContext: function FAH_getCurrentContext()
|
|
|
|
{
|
|
|
|
return Services.wm.getMostRecentWindow("navigator:browser");
|
2010-12-23 17:07:03 +00:00
|
|
|
},
|
2010-06-22 16:51:50 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Utility functions used by multiple callers
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ConsoleUtils: a collection of globally used functions
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
ConsoleUtils = {
|
2012-01-06 19:34:56 +00:00
|
|
|
/**
|
|
|
|
* Flag to turn on and off scrolling.
|
|
|
|
*/
|
|
|
|
scroll: true,
|
|
|
|
|
2010-08-13 17:36:05 +00:00
|
|
|
/**
|
|
|
|
* Scrolls a node so that it's visible in its containing XUL "scrollbox"
|
|
|
|
* element.
|
|
|
|
*
|
|
|
|
* @param nsIDOMNode aNode
|
|
|
|
* The node to make visible.
|
|
|
|
* @returns void
|
|
|
|
*/
|
|
|
|
scrollToVisible: function ConsoleUtils_scrollToVisible(aNode) {
|
2012-01-06 19:34:56 +00:00
|
|
|
if (!this.scroll) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-12-23 15:59:19 +00:00
|
|
|
// Find the enclosing richlistbox node.
|
|
|
|
let richListBoxNode = aNode.parentNode;
|
|
|
|
while (richListBoxNode.tagName != "richlistbox") {
|
|
|
|
richListBoxNode = richListBoxNode.parentNode;
|
2010-08-13 17:36:05 +00:00
|
|
|
}
|
|
|
|
|
2010-12-23 15:59:19 +00:00
|
|
|
// Use the scroll box object interface to ensure the element is visible.
|
|
|
|
let boxObject = richListBoxNode.scrollBoxObject;
|
2010-08-13 17:36:05 +00:00
|
|
|
let nsIScrollBoxObject = boxObject.QueryInterface(Ci.nsIScrollBoxObject);
|
|
|
|
nsIScrollBoxObject.ensureElementIsVisible(aNode);
|
2010-11-13 13:27:52 +00:00
|
|
|
},
|
|
|
|
|
2010-12-23 15:59:19 +00:00
|
|
|
/**
|
|
|
|
* Given a category and message body, creates a DOM node to represent an
|
|
|
|
* incoming message. The timestamp is automatically added.
|
|
|
|
*
|
|
|
|
* @param nsIDOMDocument aDocument
|
|
|
|
* The document in which to create the node.
|
|
|
|
* @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.
|
2011-06-14 11:38:11 +00:00
|
|
|
* @param number aHUDId
|
|
|
|
* The HeadsUpDisplay ID.
|
2010-12-23 15:59:19 +00:00
|
|
|
* @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.
|
2011-06-09 13:27:30 +00:00
|
|
|
* @param number aLevel [optional]
|
|
|
|
* The level of the console API message.
|
2012-01-11 10:51:49 +00:00
|
|
|
* @param number aTimeStamp [optional]
|
|
|
|
* The timestamp to use for this message node. If omitted, the current
|
|
|
|
* date and time is used.
|
2010-12-23 15:59:19 +00:00
|
|
|
* @return nsIDOMNode
|
|
|
|
* The message node: a XUL richlistitem ready to be inserted into
|
|
|
|
* the Web Console output node.
|
|
|
|
*/
|
|
|
|
createMessageNode:
|
|
|
|
function ConsoleUtils_createMessageNode(aDocument, aCategory, aSeverity,
|
2011-06-14 11:38:11 +00:00
|
|
|
aBody, aHUDId, aSourceURL,
|
2012-01-11 10:51:49 +00:00
|
|
|
aSourceLine, aClipboardText, aLevel,
|
|
|
|
aTimeStamp) {
|
2011-05-27 12:49:02 +00:00
|
|
|
if (typeof aBody != "string" && aClipboardText == null && aBody.innerText) {
|
|
|
|
aClipboardText = aBody.innerText;
|
2010-12-23 15:59:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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.
|
2011-07-26 20:51:10 +00:00
|
|
|
let iconContainer = aDocument.createElementNS(XUL_NS, "vbox");
|
2010-12-23 15:59:19 +00:00
|
|
|
iconContainer.classList.add("webconsole-msg-icon-container");
|
2011-06-14 11:38:11 +00:00
|
|
|
// Apply the curent group by indenting appropriately.
|
|
|
|
let hud = HUDService.getHudReferenceById(aHUDId);
|
|
|
|
iconContainer.style.marginLeft = hud.groupDepth * GROUP_INDENT + "px";
|
2010-12-23 15:59:19 +00:00
|
|
|
|
|
|
|
// Make the icon node. It's sprited and the actual region of the image is
|
|
|
|
// determined by CSS rules.
|
2011-07-26 20:51:10 +00:00
|
|
|
let iconNode = aDocument.createElementNS(XUL_NS, "image");
|
2010-12-23 15:59:19 +00:00
|
|
|
iconNode.classList.add("webconsole-msg-icon");
|
|
|
|
iconContainer.appendChild(iconNode);
|
|
|
|
|
|
|
|
// Make the spacer that positions the icon.
|
2011-07-26 20:51:10 +00:00
|
|
|
let spacer = aDocument.createElementNS(XUL_NS, "spacer");
|
2010-12-23 15:59:19 +00:00
|
|
|
spacer.setAttribute("flex", "1");
|
|
|
|
iconContainer.appendChild(spacer);
|
|
|
|
|
|
|
|
// Create the message body, which contains the actual text of the message.
|
2011-07-26 20:51:10 +00:00
|
|
|
let bodyNode = aDocument.createElementNS(XUL_NS, "description");
|
2010-12-23 15:59:19 +00:00
|
|
|
bodyNode.setAttribute("flex", "1");
|
|
|
|
bodyNode.classList.add("webconsole-msg-body");
|
|
|
|
|
2011-06-09 13:27:30 +00:00
|
|
|
// Store the body text, since it is needed later for the property tree
|
|
|
|
// case.
|
|
|
|
let body = aBody;
|
2010-12-23 15:59:19 +00:00
|
|
|
// 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 : ""));
|
2012-05-10 13:15:10 +00:00
|
|
|
if (!(aBody instanceof Ci.nsIDOMNode)) {
|
|
|
|
aBody = aDocument.createTextNode(aLevel == "dir" ?
|
|
|
|
aBody.resultString : aBody);
|
|
|
|
}
|
2010-12-23 15:59:19 +00:00
|
|
|
|
2011-05-27 12:49:02 +00:00
|
|
|
if (!aBody.nodeType) {
|
|
|
|
aBody = aDocument.createTextNode(aBody.toString());
|
|
|
|
}
|
|
|
|
if (typeof aBody == "string") {
|
|
|
|
aBody = aDocument.createTextNode(aBody);
|
|
|
|
}
|
|
|
|
|
2010-12-23 15:59:19 +00:00
|
|
|
bodyNode.appendChild(aBody);
|
|
|
|
|
2011-07-26 20:51:10 +00:00
|
|
|
let repeatContainer = aDocument.createElementNS(XUL_NS, "hbox");
|
2011-07-25 13:36:36 +00:00
|
|
|
repeatContainer.setAttribute("align", "start");
|
2011-07-26 20:51:10 +00:00
|
|
|
let repeatNode = aDocument.createElementNS(XUL_NS, "label");
|
2011-02-25 22:12:42 +00:00
|
|
|
repeatNode.setAttribute("value", "1");
|
|
|
|
repeatNode.classList.add("webconsole-msg-repeat");
|
2011-07-25 13:36:36 +00:00
|
|
|
repeatContainer.appendChild(repeatNode);
|
2011-02-25 22:12:42 +00:00
|
|
|
|
2010-12-23 15:59:19 +00:00
|
|
|
// Create the timestamp.
|
2011-07-26 20:51:10 +00:00
|
|
|
let timestampNode = aDocument.createElementNS(XUL_NS, "label");
|
2010-12-23 15:59:19 +00:00
|
|
|
timestampNode.classList.add("webconsole-timestamp");
|
2012-05-10 13:15:10 +00:00
|
|
|
let timestamp = aTimeStamp || Date.now();
|
|
|
|
let timestampString = l10n.timestampString(timestamp);
|
2010-12-23 15:59:19 +00:00
|
|
|
timestampNode.setAttribute("value", timestampString);
|
|
|
|
|
|
|
|
// Create the source location (e.g. www.example.com:6) that sits on the
|
|
|
|
// right side of the message, if applicable.
|
|
|
|
let locationNode;
|
|
|
|
if (aSourceURL) {
|
|
|
|
locationNode = this.createLocationNode(aDocument, aSourceURL,
|
|
|
|
aSourceLine);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create the containing node and append all its elements to it.
|
2011-07-26 20:51:10 +00:00
|
|
|
let node = aDocument.createElementNS(XUL_NS, "richlistitem");
|
2010-12-23 15:59:19 +00:00
|
|
|
node.clipboardText = aClipboardText;
|
|
|
|
node.classList.add("hud-msg-node");
|
|
|
|
|
|
|
|
node.timestamp = timestamp;
|
|
|
|
ConsoleUtils.setMessageType(node, aCategory, aSeverity);
|
|
|
|
|
2011-06-09 13:27:30 +00:00
|
|
|
node.appendChild(timestampNode);
|
|
|
|
node.appendChild(iconContainer);
|
|
|
|
// Display the object tree after the message node.
|
|
|
|
if (aLevel == "dir") {
|
|
|
|
// Make the body container, which is a vertical box, for grouping the text
|
|
|
|
// and tree widgets.
|
|
|
|
let bodyContainer = aDocument.createElement("vbox");
|
|
|
|
bodyContainer.setAttribute("flex", "1");
|
|
|
|
bodyContainer.appendChild(bodyNode);
|
|
|
|
// Create the tree.
|
|
|
|
let tree = createElement(aDocument, "tree", {
|
|
|
|
flex: 1,
|
|
|
|
hidecolumnpicker: "true"
|
|
|
|
});
|
|
|
|
|
|
|
|
let treecols = aDocument.createElement("treecols");
|
|
|
|
let treecol = createElement(aDocument, "treecol", {
|
|
|
|
primary: "true",
|
|
|
|
flex: 1,
|
|
|
|
hideheader: "true",
|
|
|
|
ignoreincolumnpicker: "true"
|
|
|
|
});
|
|
|
|
treecols.appendChild(treecol);
|
|
|
|
tree.appendChild(treecols);
|
|
|
|
|
|
|
|
tree.appendChild(aDocument.createElement("treechildren"));
|
|
|
|
|
|
|
|
bodyContainer.appendChild(tree);
|
|
|
|
node.appendChild(bodyContainer);
|
|
|
|
node.classList.add("webconsole-msg-inspector");
|
|
|
|
// Create the treeView object.
|
2012-05-10 13:15:10 +00:00
|
|
|
let treeView = node.propertyTreeView = new PropertyTreeViewAsync();
|
|
|
|
|
|
|
|
treeView.data = {
|
|
|
|
rootCacheId: body.cacheId,
|
|
|
|
panelCacheId: body.cacheId,
|
|
|
|
remoteObject: body.remoteObject,
|
|
|
|
remoteObjectProvider: body.remoteObjectProvider,
|
|
|
|
};
|
|
|
|
|
2011-06-09 13:27:30 +00:00
|
|
|
tree.setAttribute("rows", treeView.rowCount);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
node.appendChild(bodyNode);
|
|
|
|
}
|
|
|
|
node.appendChild(repeatContainer);
|
2010-12-23 15:59:19 +00:00
|
|
|
if (locationNode) {
|
2011-06-09 13:27:30 +00:00
|
|
|
node.appendChild(locationNode);
|
2010-12-23 15:59:19 +00:00
|
|
|
}
|
|
|
|
|
2011-02-28 20:42:28 +00:00
|
|
|
node.setAttribute("id", "console-msg-" + HUDService.sequenceId());
|
|
|
|
|
2010-12-23 15:59:19 +00:00
|
|
|
return node;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adjusts the category and severity of the given message, clearing the old
|
|
|
|
* category and severity if present.
|
|
|
|
*
|
|
|
|
* @param nsIDOMNode aMessageNode
|
|
|
|
* The message node to alter.
|
|
|
|
* @param number aNewCategory
|
|
|
|
* The new category for the message; one of the CATEGORY_ constants.
|
|
|
|
* @param number aNewSeverity
|
|
|
|
* The new severity for the message; one of the SEVERITY_ constants.
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
setMessageType:
|
|
|
|
function ConsoleUtils_setMessageType(aMessageNode, aNewCategory,
|
|
|
|
aNewSeverity) {
|
|
|
|
// Remove the old CSS classes, if applicable.
|
|
|
|
if ("category" in aMessageNode) {
|
|
|
|
let oldCategory = aMessageNode.category;
|
|
|
|
let oldSeverity = aMessageNode.severity;
|
|
|
|
aMessageNode.classList.remove("webconsole-msg-" +
|
|
|
|
CATEGORY_CLASS_FRAGMENTS[oldCategory]);
|
|
|
|
aMessageNode.classList.remove("webconsole-msg-" +
|
|
|
|
SEVERITY_CLASS_FRAGMENTS[oldSeverity]);
|
|
|
|
let key = "hud-" + MESSAGE_PREFERENCE_KEYS[oldCategory][oldSeverity];
|
|
|
|
aMessageNode.classList.remove(key);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add in the new CSS classes.
|
|
|
|
aMessageNode.category = aNewCategory;
|
|
|
|
aMessageNode.severity = aNewSeverity;
|
|
|
|
aMessageNode.classList.add("webconsole-msg-" +
|
|
|
|
CATEGORY_CLASS_FRAGMENTS[aNewCategory]);
|
|
|
|
aMessageNode.classList.add("webconsole-msg-" +
|
|
|
|
SEVERITY_CLASS_FRAGMENTS[aNewSeverity]);
|
|
|
|
let key = "hud-" + MESSAGE_PREFERENCE_KEYS[aNewCategory][aNewSeverity];
|
|
|
|
aMessageNode.classList.add(key);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates the XUL label that displays the textual location of an incoming
|
|
|
|
* message.
|
|
|
|
*
|
|
|
|
* @param nsIDOMDocument aDocument
|
|
|
|
* The document in which to create the node.
|
|
|
|
* @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
|
|
|
|
* The new XUL label node, ready to be added to the message node.
|
|
|
|
*/
|
|
|
|
createLocationNode:
|
|
|
|
function ConsoleUtils_createLocationNode(aDocument, aSourceURL,
|
|
|
|
aSourceLine) {
|
2011-07-26 20:51:10 +00:00
|
|
|
let locationNode = aDocument.createElementNS(XUL_NS, "label");
|
2010-12-23 15:59:19 +00:00
|
|
|
|
|
|
|
// Create the text, which consists of an abbreviated version of the URL
|
|
|
|
// plus an optional line number.
|
2012-05-10 13:15:10 +00:00
|
|
|
let text = WebConsoleUtils.abbreviateSourceURL(aSourceURL);
|
2010-12-23 15:59:19 +00:00
|
|
|
if (aSourceLine) {
|
|
|
|
text += ":" + aSourceLine;
|
|
|
|
}
|
|
|
|
locationNode.setAttribute("value", text);
|
|
|
|
|
|
|
|
// Style appropriately.
|
|
|
|
locationNode.setAttribute("crop", "center");
|
|
|
|
locationNode.setAttribute("title", aSourceURL);
|
|
|
|
locationNode.classList.add("webconsole-location");
|
|
|
|
locationNode.classList.add("text-link");
|
|
|
|
|
|
|
|
// Make the location clickable.
|
|
|
|
locationNode.addEventListener("click", function() {
|
2011-06-08 14:48:40 +00:00
|
|
|
if (aSourceURL == "Scratchpad") {
|
|
|
|
let win = Services.wm.getMostRecentWindow("devtools:scratchpad");
|
|
|
|
if (win) {
|
|
|
|
win.focus();
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2010-12-23 15:59:19 +00:00
|
|
|
let viewSourceUtils = aDocument.defaultView.gViewSourceUtils;
|
|
|
|
viewSourceUtils.viewSource(aSourceURL, null, aDocument, aSourceLine);
|
|
|
|
}, true);
|
|
|
|
|
|
|
|
return locationNode;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Applies the user's filters to a newly-created message node via CSS
|
|
|
|
* classes.
|
|
|
|
*
|
|
|
|
* @param nsIDOMNode aNode
|
|
|
|
* The newly-created message node.
|
|
|
|
* @param string aHUDId
|
|
|
|
* The ID of the HUD which this node is to be inserted into.
|
|
|
|
*/
|
2011-02-25 22:12:42 +00:00
|
|
|
filterMessageNode: function ConsoleUtils_filterMessageNode(aNode, aHUDId) {
|
2010-12-23 15:59:19 +00:00
|
|
|
// Filter by the message type.
|
|
|
|
let prefKey = MESSAGE_PREFERENCE_KEYS[aNode.category][aNode.severity];
|
|
|
|
if (prefKey && !HUDService.getFilterState(aHUDId, prefKey)) {
|
|
|
|
// The node is filtered by type.
|
|
|
|
aNode.classList.add("hud-filtered-by-type");
|
|
|
|
}
|
2011-02-18 19:46:59 +00:00
|
|
|
|
|
|
|
// Filter on the search string.
|
|
|
|
let search = HUDService.getFilterStringByHUDId(aHUDId);
|
|
|
|
let text = aNode.clipboardText;
|
|
|
|
|
|
|
|
// if string matches the filter text
|
|
|
|
if (!HUDService.stringMatchesFilters(text, search)) {
|
|
|
|
aNode.classList.add("hud-filtered-by-string");
|
|
|
|
}
|
2010-12-23 15:59:19 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2011-02-25 22:12:42 +00:00
|
|
|
* 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 ConsoleUtils_mergeFilteredMessageNode(aOriginal, aFiltered) {
|
2011-07-25 13:36:36 +00:00
|
|
|
// childNodes[3].firstChild is the node containing the number of repetitions
|
|
|
|
// of a node.
|
|
|
|
let repeatNode = aOriginal.childNodes[3].firstChild;
|
2011-02-25 22:12:42 +00:00
|
|
|
if (!repeatNode) {
|
|
|
|
return aOriginal; // no repeat node, return early.
|
|
|
|
}
|
|
|
|
|
|
|
|
let occurrences = parseInt(repeatNode.getAttribute("value")) + 1;
|
|
|
|
repeatNode.setAttribute("value", occurrences);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Filter the css node from the output node if it is a repeat. CSS messages
|
|
|
|
* are merged with previous messages if they occurred in the past.
|
|
|
|
*
|
|
|
|
* @param nsIDOMNode aNode
|
|
|
|
* The message node to be filtered or not.
|
|
|
|
* @param nsIDOMNode aOutput
|
|
|
|
* The outputNode of the HUD.
|
|
|
|
* @returns boolean
|
|
|
|
* true if the message is filtered, false otherwise.
|
|
|
|
*/
|
|
|
|
filterRepeatedCSS:
|
|
|
|
function ConsoleUtils_filterRepeatedCSS(aNode, aOutput, aHUDId) {
|
|
|
|
let hud = HUDService.getHudReferenceById(aHUDId);
|
|
|
|
|
|
|
|
// childNodes[2] is the description node containing the text of the message.
|
|
|
|
let description = aNode.childNodes[2].textContent;
|
|
|
|
let location;
|
|
|
|
|
|
|
|
// childNodes[4] represents the location (source URL) of the error message.
|
|
|
|
// The full source URL is stored in the title attribute.
|
|
|
|
if (aNode.childNodes[4]) {
|
|
|
|
// browser_webconsole_bug_595934_message_categories.js
|
|
|
|
location = aNode.childNodes[4].getAttribute("title");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
location = "";
|
|
|
|
}
|
|
|
|
|
|
|
|
let dupe = hud.cssNodes[description + location];
|
|
|
|
if (!dupe) {
|
|
|
|
// no matching nodes
|
|
|
|
hud.cssNodes[description + location] = aNode;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.mergeFilteredMessageNode(dupe, aNode);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Filter the console node from the output node if it is a repeat. Console
|
|
|
|
* messages are filtered from the output if and only if they match the
|
|
|
|
* immediately preceding message. The output node's last occurrence should
|
|
|
|
* have its timestamp updated.
|
|
|
|
*
|
|
|
|
* @param nsIDOMNode aNode
|
|
|
|
* The message node to be filtered or not.
|
|
|
|
* @param nsIDOMNode aOutput
|
|
|
|
* The outputNode of the HUD.
|
|
|
|
* @return boolean
|
|
|
|
* true if the message is filtered, false otherwise.
|
|
|
|
*/
|
|
|
|
filterRepeatedConsole:
|
|
|
|
function ConsoleUtils_filterRepeatedConsole(aNode, aOutput) {
|
|
|
|
let lastMessage = aOutput.lastChild;
|
|
|
|
|
2011-07-26 20:51:10 +00:00
|
|
|
// childNodes[2] is the description element
|
2011-06-09 13:27:30 +00:00
|
|
|
if (lastMessage && !aNode.classList.contains("webconsole-msg-inspector") &&
|
2011-02-25 22:12:42 +00:00
|
|
|
aNode.childNodes[2].textContent ==
|
|
|
|
lastMessage.childNodes[2].textContent) {
|
2011-03-01 12:43:46 +00:00
|
|
|
this.mergeFilteredMessageNode(lastMessage, aNode);
|
2011-02-25 22:12:42 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
2011-03-28 20:19:37 +00:00
|
|
|
/**
|
|
|
|
* Filters a node appropriately, then sends it to the output, regrouping and
|
2010-12-23 15:59:19 +00:00
|
|
|
* pruning output as necessary.
|
|
|
|
*
|
|
|
|
* @param nsIDOMNode aNode
|
|
|
|
* The message node to send to the output.
|
|
|
|
* @param string aHUDId
|
|
|
|
* The ID of the HUD in which to insert this node.
|
|
|
|
*/
|
|
|
|
outputMessageNode: function ConsoleUtils_outputMessageNode(aNode, aHUDId) {
|
|
|
|
ConsoleUtils.filterMessageNode(aNode, aHUDId);
|
|
|
|
let outputNode = HUDService.hudReferences[aHUDId].outputNode;
|
2011-01-12 15:56:02 +00:00
|
|
|
|
|
|
|
let scrolledToBottom = ConsoleUtils.isOutputScrolledToBottom(outputNode);
|
|
|
|
|
2011-02-25 22:12:42 +00:00
|
|
|
let isRepeated = false;
|
|
|
|
if (aNode.classList.contains("webconsole-msg-cssparser")) {
|
|
|
|
isRepeated = this.filterRepeatedCSS(aNode, outputNode, aHUDId);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!isRepeated &&
|
|
|
|
(aNode.classList.contains("webconsole-msg-console") ||
|
|
|
|
aNode.classList.contains("webconsole-msg-exception") ||
|
|
|
|
aNode.classList.contains("webconsole-msg-error"))) {
|
2011-06-09 13:27:30 +00:00
|
|
|
isRepeated = this.filterRepeatedConsole(aNode, outputNode);
|
2011-02-25 22:12:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!isRepeated) {
|
|
|
|
outputNode.appendChild(aNode);
|
|
|
|
}
|
|
|
|
|
2010-12-23 15:59:19 +00:00
|
|
|
HUDService.regroupOutput(outputNode);
|
|
|
|
|
2011-07-01 20:20:09 +00:00
|
|
|
if (pruneConsoleOutputIfNecessary(aHUDId, aNode.category) == 0) {
|
2010-12-23 15:59:19 +00:00
|
|
|
// We can't very well scroll to make the message node visible if the log
|
|
|
|
// limit is zero and the node was destroyed in the first place.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-01-12 15:56:02 +00:00
|
|
|
let isInputOutput = aNode.classList.contains("webconsole-msg-input") ||
|
|
|
|
aNode.classList.contains("webconsole-msg-output");
|
|
|
|
let isFiltered = aNode.classList.contains("hud-filtered-by-string") ||
|
|
|
|
aNode.classList.contains("hud-filtered-by-type");
|
|
|
|
|
|
|
|
// 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.
|
2011-02-25 22:12:42 +00:00
|
|
|
if (!isFiltered && !isRepeated && (scrolledToBottom || isInputOutput)) {
|
2010-12-23 15:59:19 +00:00
|
|
|
ConsoleUtils.scrollToVisible(aNode);
|
|
|
|
}
|
2011-02-28 20:42:20 +00:00
|
|
|
|
2012-05-10 13:15:10 +00:00
|
|
|
let id = WebConsoleUtils.supportsString(aHUDId);
|
2011-02-28 20:42:20 +00:00
|
|
|
let nodeID = aNode.getAttribute("id");
|
|
|
|
Services.obs.notifyObservers(id, "web-console-message-created", nodeID);
|
2010-12-23 15:59:19 +00:00
|
|
|
},
|
|
|
|
|
2011-01-12 15:56:02 +00: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 ConsoleUtils_isOutputScrolledToBottom(aOutputNode)
|
|
|
|
{
|
|
|
|
let lastNodeHeight = aOutputNode.lastChild ?
|
|
|
|
aOutputNode.lastChild.clientHeight : 0;
|
|
|
|
let scrollBox = aOutputNode.scrollBoxObject.element;
|
|
|
|
|
|
|
|
return scrollBox.scrollTop + scrollBox.clientHeight >=
|
|
|
|
scrollBox.scrollHeight - lastNodeHeight / 2;
|
|
|
|
},
|
2010-06-22 16:51:50 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// HeadsUpDisplayUICommands
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
HeadsUpDisplayUICommands = {
|
2012-05-10 17:33:54 +00:00
|
|
|
refreshCommand: function UIC_refreshCommand() {
|
|
|
|
var window = HUDService.currentContext();
|
|
|
|
let command = window.document.getElementById("Tools:WebConsole");
|
|
|
|
if (this.getOpenHUD() != null) {
|
|
|
|
command.setAttribute("checked", true);
|
|
|
|
} else {
|
|
|
|
command.removeAttribute("checked");
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2010-06-22 16:51:50 +00:00
|
|
|
toggleHUD: function UIC_toggleHUD() {
|
|
|
|
var window = HUDService.currentContext();
|
|
|
|
var gBrowser = window.gBrowser;
|
|
|
|
var linkedBrowser = gBrowser.selectedTab.linkedBrowser;
|
|
|
|
var tabId = gBrowser.getNotificationBox(linkedBrowser).getAttribute("id");
|
|
|
|
var hudId = "hud_" + tabId;
|
2010-11-10 16:10:26 +00:00
|
|
|
var ownerDocument = gBrowser.selectedTab.ownerDocument;
|
|
|
|
var hud = ownerDocument.getElementById(hudId);
|
2011-05-18 11:08:54 +00:00
|
|
|
var hudRef = HUDService.hudReferences[hudId];
|
|
|
|
|
|
|
|
if (hudRef && hud) {
|
|
|
|
if (hudRef.consolePanel) {
|
2011-12-07 14:37:57 +00:00
|
|
|
hudRef.consolePanel.hidePopup();
|
2011-05-18 11:08:54 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
HUDService.storeHeight(hudId);
|
|
|
|
|
|
|
|
HUDService.animate(hudId, ANIMATE_OUT, function() {
|
|
|
|
// If the user closes the console while the console is animating away,
|
|
|
|
// then these callbacks will queue up, but all the callbacks after the
|
|
|
|
// first will have no console to operate on. This test handles this
|
|
|
|
// case gracefully.
|
|
|
|
if (ownerDocument.getElementById(hudId)) {
|
|
|
|
HUDService.deactivateHUDForContext(gBrowser.selectedTab, true);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2010-06-22 16:51:50 +00:00
|
|
|
}
|
|
|
|
else {
|
2010-11-20 19:53:14 +00:00
|
|
|
HUDService.activateHUDForContext(gBrowser.selectedTab, true);
|
2010-11-10 16:10:26 +00:00
|
|
|
HUDService.animate(hudId, ANIMATE_IN);
|
2010-06-22 16:51:50 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2011-04-20 08:18:00 +00:00
|
|
|
/**
|
|
|
|
* Find the hudId for the active chrome window.
|
|
|
|
* @return string|null
|
|
|
|
* The hudId or null if the active chrome window has no open Web
|
|
|
|
* Console.
|
|
|
|
*/
|
|
|
|
getOpenHUD: function UIC_getOpenHUD() {
|
|
|
|
let chromeWindow = HUDService.currentContext();
|
|
|
|
let contentWindow = chromeWindow.gBrowser.selectedBrowser.contentWindow;
|
|
|
|
return HUDService.getHudIdByWindow(contentWindow);
|
|
|
|
},
|
|
|
|
|
2010-12-02 10:50:29 +00:00
|
|
|
/**
|
|
|
|
* The event handler that is called whenever a user switches a filter on or
|
|
|
|
* off.
|
|
|
|
*
|
|
|
|
* @param nsIDOMEvent aEvent
|
|
|
|
* The event that triggered the filter change.
|
|
|
|
* @return boolean
|
|
|
|
*/
|
|
|
|
toggleFilter: function UIC_toggleFilter(aEvent) {
|
|
|
|
let hudId = this.getAttribute("hudId");
|
|
|
|
switch (this.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 = this.getAttribute("checked") !== "true";
|
|
|
|
this.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 = this.querySelectorAll("menuitem");
|
|
|
|
for (let i = 0; i < menuItems.length; i++) {
|
|
|
|
menuItems[i].setAttribute("checked", state);
|
|
|
|
let prefKey = menuItems[i].getAttribute("prefKey");
|
|
|
|
HUDService.setFilterState(hudId, prefKey, state);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case "menuitem": {
|
|
|
|
let state = this.getAttribute("checked") !== "true";
|
|
|
|
this.setAttribute("checked", state);
|
|
|
|
|
|
|
|
let prefKey = this.getAttribute("prefKey");
|
|
|
|
HUDService.setFilterState(hudId, prefKey, state);
|
|
|
|
|
|
|
|
// Adjust the state of the button appropriately.
|
|
|
|
let menuPopup = this.parentNode;
|
|
|
|
|
2011-11-24 03:02:23 +00:00
|
|
|
let someChecked = false;
|
2010-12-02 10:50:29 +00:00
|
|
|
let menuItem = menuPopup.firstChild;
|
|
|
|
while (menuItem) {
|
2011-11-24 03:02:23 +00:00
|
|
|
if (menuItem.getAttribute("checked") === "true") {
|
|
|
|
someChecked = true;
|
2010-12-02 10:50:29 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
menuItem = menuItem.nextSibling;
|
|
|
|
}
|
|
|
|
let toolbarButton = menuPopup.parentNode;
|
2011-11-24 03:02:23 +00:00
|
|
|
toolbarButton.setAttribute("checked", someChecked);
|
2010-12-02 10:50:29 +00:00
|
|
|
break;
|
|
|
|
}
|
2010-06-22 16:51:50 +00:00
|
|
|
}
|
2010-12-02 10:50:29 +00:00
|
|
|
|
|
|
|
return true;
|
2010-06-22 16:51:50 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
command: function UIC_command(aButton) {
|
|
|
|
var filter = aButton.getAttribute("buttonType");
|
|
|
|
var hudId = aButton.getAttribute("hudId");
|
2010-09-10 18:08:05 +00:00
|
|
|
switch (filter) {
|
2010-12-23 15:59:19 +00:00
|
|
|
case "copy": {
|
|
|
|
let outputNode = HUDService.hudReferences[hudId].outputNode;
|
|
|
|
HUDService.copySelectedItems(outputNode);
|
2010-09-10 18:08:05 +00:00
|
|
|
break;
|
2010-12-23 15:59:19 +00:00
|
|
|
}
|
|
|
|
case "selectAll": {
|
|
|
|
HUDService.hudReferences[hudId].outputNode.selectAll();
|
|
|
|
break;
|
|
|
|
}
|
2010-09-22 00:00:15 +00:00
|
|
|
case "saveBodies": {
|
|
|
|
let checked = aButton.getAttribute("checked") === "true";
|
|
|
|
HUDService.saveRequestAndResponseBodies = checked;
|
|
|
|
break;
|
|
|
|
}
|
2010-06-22 16:51:50 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A Console log entry
|
|
|
|
*
|
|
|
|
* @param JSObject aConfig, object literal with ConsolEntry properties
|
|
|
|
* @param integer aId
|
|
|
|
* @returns void
|
|
|
|
*/
|
|
|
|
|
|
|
|
function ConsoleEntry(aConfig, id)
|
|
|
|
{
|
|
|
|
if (!aConfig.logLevel && aConfig.message) {
|
|
|
|
throw new Error("Missing Arguments when creating a console entry");
|
|
|
|
}
|
|
|
|
|
|
|
|
this.config = aConfig;
|
|
|
|
this.id = id;
|
|
|
|
for (var prop in aConfig) {
|
|
|
|
if (!(typeof aConfig[prop] == "function")){
|
|
|
|
this[prop] = aConfig[prop];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aConfig.logLevel == "network") {
|
|
|
|
this.transactions = { };
|
|
|
|
if (aConfig.activity) {
|
|
|
|
this.transactions[aConfig.activity.stage] = aConfig.activity;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
ConsoleEntry.prototype = {
|
|
|
|
|
|
|
|
updateTransaction: function CE_updateTransaction(aActivity) {
|
|
|
|
this.transactions[aActivity.stage] = aActivity;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// HUDWindowObserver
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
HUDWindowObserver = {
|
2012-05-10 15:01:37 +00:00
|
|
|
QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver]),
|
2010-06-22 16:51:50 +00:00
|
|
|
|
|
|
|
init: function HWO_init()
|
|
|
|
{
|
|
|
|
Services.obs.addObserver(this, "content-document-global-created", false);
|
2012-05-10 15:01:37 +00:00
|
|
|
Services.obs.addObserver(this, "quit-application-granted", false);
|
2010-06-22 16:51:50 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
observe: function HWO_observe(aSubject, aTopic, aData)
|
|
|
|
{
|
|
|
|
if (aTopic == "content-document-global-created") {
|
|
|
|
HUDService.windowInitializer(aSubject);
|
|
|
|
}
|
2012-05-10 15:01:37 +00:00
|
|
|
else if (aTopic == "quit-application-granted") {
|
|
|
|
HUDService.shutdown();
|
2010-06-22 16:51:50 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
uninit: function HWO_uninit()
|
|
|
|
{
|
|
|
|
Services.obs.removeObserver(this, "content-document-global-created");
|
2012-05-10 15:01:37 +00:00
|
|
|
Services.obs.removeObserver(this, "quit-application-granted");
|
2010-06-22 16:51:50 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2010-09-10 18:08:05 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// CommandController
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A controller (an instance of nsIController) that makes editing actions
|
|
|
|
* behave appropriately in the context of the Web Console.
|
|
|
|
*/
|
|
|
|
function CommandController(aWindow) {
|
|
|
|
this.window = aWindow;
|
|
|
|
}
|
|
|
|
|
|
|
|
CommandController.prototype = {
|
|
|
|
/**
|
|
|
|
* Returns the HUD output node that currently has the focus, or null if the
|
|
|
|
* currently-focused element isn't inside the output node.
|
|
|
|
*
|
|
|
|
* @returns nsIDOMNode
|
|
|
|
* The currently-focused output node.
|
|
|
|
*/
|
|
|
|
_getFocusedOutputNode: function CommandController_getFocusedOutputNode()
|
|
|
|
{
|
2010-12-23 15:59:19 +00:00
|
|
|
let element = this.window.document.commandDispatcher.focusedElement;
|
|
|
|
if (element && element.classList.contains("hud-output-node")) {
|
|
|
|
return element;
|
2010-09-10 18:08:05 +00:00
|
|
|
}
|
2010-12-23 15:59:19 +00:00
|
|
|
return null;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Copies the currently-selected entries in the Web Console output to the
|
|
|
|
* clipboard.
|
|
|
|
*
|
|
|
|
* @param nsIDOMNode aOutputNode
|
|
|
|
* The Web Console output node.
|
|
|
|
* @returns void
|
|
|
|
*/
|
|
|
|
copy: function CommandController_copy(aOutputNode)
|
|
|
|
{
|
|
|
|
HUDService.copySelectedItems(aOutputNode);
|
2010-09-10 18:08:05 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Selects all the text in the HUD output.
|
|
|
|
*
|
|
|
|
* @param nsIDOMNode aOutputNode
|
|
|
|
* The HUD output node.
|
|
|
|
* @returns void
|
|
|
|
*/
|
|
|
|
selectAll: function CommandController_selectAll(aOutputNode)
|
|
|
|
{
|
2010-12-23 15:59:19 +00:00
|
|
|
aOutputNode.selectAll();
|
2010-09-10 18:08:05 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
supportsCommand: function CommandController_supportsCommand(aCommand)
|
|
|
|
{
|
2011-08-03 18:04:30 +00:00
|
|
|
return this.isCommandEnabled(aCommand);
|
2010-09-10 18:08:05 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
isCommandEnabled: function CommandController_isCommandEnabled(aCommand)
|
|
|
|
{
|
2010-12-23 15:59:19 +00:00
|
|
|
let outputNode = this._getFocusedOutputNode();
|
|
|
|
if (!outputNode) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (aCommand) {
|
|
|
|
case "cmd_copy":
|
|
|
|
// Only enable "copy" if nodes are selected.
|
|
|
|
return outputNode.selectedCount > 0;
|
|
|
|
case "cmd_selectAll":
|
|
|
|
// "Select All" is always enabled.
|
|
|
|
return true;
|
|
|
|
}
|
2010-09-10 18:08:05 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
doCommand: function CommandController_doCommand(aCommand)
|
|
|
|
{
|
2010-12-23 15:59:19 +00:00
|
|
|
let outputNode = this._getFocusedOutputNode();
|
|
|
|
switch (aCommand) {
|
|
|
|
case "cmd_copy":
|
|
|
|
this.copy(outputNode);
|
|
|
|
break;
|
|
|
|
case "cmd_selectAll":
|
|
|
|
this.selectAll(outputNode);
|
|
|
|
break;
|
|
|
|
}
|
2010-09-10 18:08:05 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2011-04-13 20:02:36 +00:00
|
|
|
/**
|
|
|
|
* A WebProgressListener that listens for location changes, to update HUDService
|
|
|
|
* state information on page navigation.
|
|
|
|
*
|
|
|
|
* @constructor
|
|
|
|
* @param string aHudId
|
|
|
|
* The HeadsUpDisplay ID.
|
|
|
|
*/
|
|
|
|
function ConsoleProgressListener(aHudId)
|
|
|
|
{
|
|
|
|
this.hudId = aHudId;
|
|
|
|
}
|
|
|
|
|
|
|
|
ConsoleProgressListener.prototype = {
|
|
|
|
QueryInterface: XPCOMUtils.generateQI([Ci.nsIWebProgressListener,
|
|
|
|
Ci.nsISupportsWeakReference]),
|
|
|
|
|
|
|
|
onStateChange: function CPL_onStateChange(aProgress, aRequest, aState,
|
|
|
|
aStatus)
|
|
|
|
{
|
|
|
|
if (!(aState & Ci.nsIWebProgressListener.STATE_START)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let uri = null;
|
|
|
|
if (aRequest instanceof Ci.imgIRequest) {
|
|
|
|
let imgIRequest = aRequest.QueryInterface(Ci.imgIRequest);
|
|
|
|
uri = imgIRequest.URI;
|
|
|
|
}
|
|
|
|
else if (aRequest instanceof Ci.nsIChannel) {
|
|
|
|
let nsIChannel = aRequest.QueryInterface(Ci.nsIChannel);
|
|
|
|
uri = nsIChannel.URI;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!uri || !uri.schemeIs("file") && !uri.schemeIs("ftp")) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let outputNode = HUDService.hudReferences[this.hudId].outputNode;
|
|
|
|
|
|
|
|
let chromeDocument = outputNode.ownerDocument;
|
|
|
|
let msgNode = chromeDocument.createElementNS(HTML_NS, "html:span");
|
|
|
|
|
|
|
|
// Create the clickable URL part of the message.
|
|
|
|
let linkNode = chromeDocument.createElementNS(HTML_NS, "html:span");
|
|
|
|
linkNode.appendChild(chromeDocument.createTextNode(uri.spec));
|
|
|
|
linkNode.classList.add("hud-clickable");
|
|
|
|
linkNode.classList.add("webconsole-msg-url");
|
|
|
|
|
|
|
|
linkNode.addEventListener("mousedown", function(aEvent) {
|
|
|
|
this._startX = aEvent.clientX;
|
|
|
|
this._startY = aEvent.clientY;
|
|
|
|
}, false);
|
|
|
|
|
|
|
|
linkNode.addEventListener("click", function(aEvent) {
|
|
|
|
if (aEvent.detail == 1 && aEvent.button == 0 &&
|
|
|
|
this._startX == aEvent.clientX && this._startY == aEvent.clientY) {
|
|
|
|
let viewSourceUtils = chromeDocument.defaultView.gViewSourceUtils;
|
|
|
|
viewSourceUtils.viewSource(uri.spec, null, chromeDocument);
|
|
|
|
}
|
|
|
|
}, false);
|
|
|
|
|
|
|
|
msgNode.appendChild(linkNode);
|
|
|
|
|
|
|
|
let messageNode = ConsoleUtils.createMessageNode(chromeDocument,
|
|
|
|
CATEGORY_NETWORK,
|
|
|
|
SEVERITY_LOG,
|
|
|
|
msgNode,
|
2011-06-14 11:38:11 +00:00
|
|
|
this.hudId,
|
2011-04-13 20:02:36 +00:00
|
|
|
null,
|
|
|
|
null,
|
|
|
|
uri.spec);
|
|
|
|
|
|
|
|
ConsoleUtils.outputMessageNode(messageNode, this.hudId);
|
|
|
|
},
|
|
|
|
|
|
|
|
onLocationChange: function() {},
|
|
|
|
onStatusChange: function() {},
|
|
|
|
onProgressChange: function() {},
|
|
|
|
onSecurityChange: function() {},
|
|
|
|
};
|
|
|
|
|
2010-06-22 16:51:50 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
// appName
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the app's name so we can properly dispatch app-specific
|
|
|
|
* methods per API call
|
|
|
|
* @returns Gecko application name
|
|
|
|
*/
|
|
|
|
function appName()
|
|
|
|
{
|
|
|
|
let APP_ID = Services.appinfo.QueryInterface(Ci.nsIXULRuntime).ID;
|
|
|
|
|
|
|
|
let APP_ID_TABLE = {
|
|
|
|
"{ec8030f7-c20a-464f-9b0e-13a3a9e97384}": "FIREFOX" ,
|
|
|
|
"{3550f703-e582-4d05-9a08-453d09bdfdc6}": "THUNDERBIRD",
|
|
|
|
"{a23983c0-fd0e-11dc-95ff-0800200c9a66}": "FENNEC" ,
|
|
|
|
"{92650c4d-4b8e-4d2a-b7eb-24ecf4f6b63a}": "SEAMONKEY",
|
|
|
|
};
|
|
|
|
|
|
|
|
let name = APP_ID_TABLE[APP_ID];
|
|
|
|
|
|
|
|
if (name){
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
throw new Error("appName: UNSUPPORTED APPLICATION UUID");
|
|
|
|
}
|
|
|
|
|
2012-01-11 10:51:49 +00:00
|
|
|
XPCOMUtils.defineLazyGetter(this, "HUDService", function () {
|
|
|
|
try {
|
|
|
|
return new HUD_SERVICE();
|
|
|
|
}
|
|
|
|
catch (ex) {
|
|
|
|
Cu.reportError(ex);
|
|
|
|
}
|
|
|
|
});
|
2011-05-27 12:49:02 +00:00
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
// GcliTerm
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2011-10-26 14:01:35 +00:00
|
|
|
/**
|
|
|
|
* Some commands need customization - this is how we get at them.
|
|
|
|
*/
|
|
|
|
let commandExports = undefined;
|
|
|
|
|
2011-05-27 12:49:02 +00:00
|
|
|
/**
|
|
|
|
* GcliTerm
|
|
|
|
*
|
|
|
|
* Initialize GCLI by creating a set of startup options from the available
|
|
|
|
* properties.
|
|
|
|
*
|
|
|
|
* @param nsIDOMWindow aContentWindow
|
|
|
|
* The content window that we're providing as the context to commands
|
|
|
|
* @param string aHudId
|
|
|
|
* The HUD to which we should send console messages.
|
|
|
|
* @param nsIDOMDocument aDocument
|
|
|
|
* The DOM document from which to create nodes.
|
|
|
|
* @param object aConsole
|
|
|
|
* Console object to use within the GcliTerm.
|
|
|
|
* @param nsIDOMElement aHintNode
|
|
|
|
* The node to which we add GCLI's hints.
|
|
|
|
* @constructor
|
|
|
|
*/
|
2011-11-19 16:34:04 +00:00
|
|
|
function GcliTerm(aContentWindow, aHudId, aDocument, aConsole, aHintNode, aConsoleWrap)
|
2011-05-27 12:49:02 +00:00
|
|
|
{
|
|
|
|
this.context = Cu.getWeakReference(aContentWindow);
|
|
|
|
this.hudId = aHudId;
|
|
|
|
this.document = aDocument;
|
|
|
|
this.console = aConsole;
|
|
|
|
this.hintNode = aHintNode;
|
2012-01-27 18:24:57 +00:00
|
|
|
this._window = this.context.get().QueryInterface(Ci.nsIDOMWindow);
|
2011-05-27 12:49:02 +00:00
|
|
|
|
|
|
|
this.createUI();
|
|
|
|
this.createSandbox();
|
|
|
|
|
2012-05-10 17:33:54 +00:00
|
|
|
this.gcliConsole = gcli._internal.createDisplay({
|
|
|
|
contentDocument: aContentWindow.document,
|
|
|
|
chromeDocument: this.document,
|
|
|
|
outputDocument: this.document,
|
|
|
|
chromeWindow: this.document.defaultView,
|
|
|
|
|
|
|
|
hintElement: this.hintNode,
|
|
|
|
inputElement: this.inputNode,
|
|
|
|
completeElement: this.completeNode,
|
|
|
|
backgroundElement: this.inputStack,
|
|
|
|
consoleWrap: aConsoleWrap,
|
2011-05-27 12:49:02 +00:00
|
|
|
|
2012-05-10 17:33:54 +00:00
|
|
|
eval: this.evalInSandbox.bind(this),
|
2012-01-12 10:12:18 +00:00
|
|
|
|
2012-01-27 18:24:52 +00:00
|
|
|
environment: {
|
|
|
|
chromeDocument: this.document,
|
|
|
|
contentDocument: aContentWindow.document
|
|
|
|
},
|
2012-05-02 20:20:02 +00:00
|
|
|
|
2012-05-10 17:33:54 +00:00
|
|
|
tooltipClass: 'gcliterm-tooltip',
|
2012-04-25 09:12:06 +00:00
|
|
|
|
2012-05-10 17:33:54 +00:00
|
|
|
// Allow GCLI:Inputter to decide how and when to open a scratchpad window
|
|
|
|
scratchpad: {
|
|
|
|
shouldActivate: function Scratchpad_shouldActivate(aEvent) {
|
|
|
|
return aEvent.shiftKey &&
|
|
|
|
aEvent.keyCode === Ci.nsIDOMKeyEvent.DOM_VK_RETURN;
|
|
|
|
},
|
|
|
|
activate: function Scratchpad_activate(aValue) {
|
|
|
|
aValue = aValue.replace(/^\s*{\s*/, '');
|
|
|
|
ScratchpadManager.openScratchpad({ text: aValue });
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
linkText: stringBundle.GetStringFromName('scratchpad.linkText')
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
this.gcliConsole.onVisibilityChange.add(this.onVisibilityChange, this);
|
|
|
|
this.gcliConsole.onOutput.add(this.onOutput, this);
|
2011-05-27 12:49:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GcliTerm.prototype = {
|
|
|
|
/**
|
2012-05-10 17:33:54 +00:00
|
|
|
* Show or remove the hint column from the display.
|
2011-05-27 12:49:02 +00:00
|
|
|
*/
|
2012-05-10 17:33:54 +00:00
|
|
|
onVisibilityChange: function GcliTerm_onVisibilityChange(ev)
|
2011-05-27 12:49:02 +00:00
|
|
|
{
|
2012-05-10 17:33:54 +00:00
|
|
|
if (ev.visible) {
|
|
|
|
this.hintNode.parentNode.hidden = false;
|
2011-11-19 16:34:04 +00:00
|
|
|
}
|
2012-05-10 17:33:54 +00:00
|
|
|
else {
|
|
|
|
let permaHint = false;
|
|
|
|
try {
|
|
|
|
permaHint = Services.prefs.getBoolPref("devtools.gcli.permaHint");
|
|
|
|
}
|
|
|
|
catch (ex) {}
|
2011-11-19 16:34:04 +00:00
|
|
|
|
2012-05-10 17:33:54 +00:00
|
|
|
if (!permaHint) {
|
|
|
|
this.hintNode.parentNode.hidden = true;
|
|
|
|
}
|
2011-11-19 16:34:04 +00:00
|
|
|
}
|
2011-05-27 12:49:02 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Destroy the GcliTerm object. Call this method to avoid memory leaks.
|
|
|
|
*/
|
|
|
|
destroy: function Gcli_destroy()
|
|
|
|
{
|
2012-05-10 17:33:54 +00:00
|
|
|
this.gcliConsole.onVisibilityChange.remove(this.onVisibilityChange, this);
|
|
|
|
this.gcliConsole.onOutput.remove(this.onOutput, this);
|
|
|
|
this.gcliConsole.destroy();
|
2011-05-27 12:49:02 +00:00
|
|
|
|
|
|
|
delete this.context;
|
|
|
|
delete this.document;
|
|
|
|
delete this.console;
|
|
|
|
delete this.hintNode;
|
2012-01-27 18:24:57 +00:00
|
|
|
delete this._window;
|
2011-05-27 12:49:02 +00:00
|
|
|
|
|
|
|
delete this.sandbox;
|
2012-05-10 17:33:54 +00:00
|
|
|
delete this.element;
|
|
|
|
delete this.inputStack;
|
|
|
|
delete this.completeNode;
|
|
|
|
delete this.inputNode;
|
2011-05-27 12:49:02 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Re-attaches a console when the contentWindow is recreated.
|
|
|
|
*
|
|
|
|
* @param nsIDOMWindow aContentWindow
|
|
|
|
* The content window that we're providing as the context to commands
|
|
|
|
* @param object aConsole
|
|
|
|
* Console object to use within the GcliTerm.
|
|
|
|
*/
|
|
|
|
reattachConsole: function Gcli_reattachConsole(aContentWindow, aConsole)
|
|
|
|
{
|
|
|
|
this.context = Cu.getWeakReference(aContentWindow);
|
|
|
|
this.console = aConsole;
|
|
|
|
this.createSandbox();
|
2012-02-07 10:20:20 +00:00
|
|
|
|
2012-05-10 17:33:54 +00:00
|
|
|
this.gcliConsole.reattach({
|
|
|
|
contentDocument: aContentWindow.document,
|
|
|
|
environment: {
|
|
|
|
chromeDocument: this.document,
|
|
|
|
contentDocument: aContentWindow.document
|
|
|
|
},
|
|
|
|
});
|
2011-05-27 12:49:02 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Generates and attaches the GCLI Terminal part of the Web Console, which
|
|
|
|
* essentially consists of the interactive JavaScript input facility.
|
|
|
|
*/
|
|
|
|
createUI: function Gcli_createUI()
|
|
|
|
{
|
|
|
|
this.element = this.document.createElement("vbox");
|
|
|
|
this.element.setAttribute("class", "gcliterm-input-container");
|
|
|
|
this.element.setAttribute("flex", "0");
|
|
|
|
|
|
|
|
this.inputStack = this.document.createElement("stack");
|
|
|
|
this.inputStack.setAttribute("class", "gcliterm-stack-node");
|
|
|
|
this.element.appendChild(this.inputStack);
|
|
|
|
|
2012-01-09 15:38:48 +00:00
|
|
|
this.completeNode = this.document.createElementNS(HTML_NS, "div");
|
2011-05-27 12:49:02 +00:00
|
|
|
this.completeNode.setAttribute("class", "gcliterm-complete-node");
|
|
|
|
this.completeNode.setAttribute("aria-live", "polite");
|
|
|
|
this.inputStack.appendChild(this.completeNode);
|
|
|
|
|
|
|
|
this.inputNode = this.document.createElement("textbox");
|
|
|
|
this.inputNode.setAttribute("class", "gcliterm-input-node");
|
|
|
|
this.inputNode.setAttribute("rows", "1");
|
|
|
|
this.inputStack.appendChild(this.inputNode);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called by GCLI/canon when command line output changes.
|
|
|
|
*/
|
2012-05-10 17:33:54 +00:00
|
|
|
onOutput: function Gcli_onOutput(aEvent)
|
2011-05-27 12:49:02 +00:00
|
|
|
{
|
|
|
|
// When we can update the history of the console, then we should stop
|
|
|
|
// filtering incomplete reports.
|
|
|
|
if (!aEvent.output.completed) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-01-27 18:24:57 +00:00
|
|
|
this.writeOutput(aEvent.output.typed, CATEGORY_INPUT);
|
2011-05-27 12:49:02 +00:00
|
|
|
|
2012-01-27 18:24:57 +00:00
|
|
|
// This is an experiment to see how much people yell when we stop reporting
|
|
|
|
// undefined replies.
|
|
|
|
if (aEvent.output.output === undefined) {
|
2011-05-27 12:49:02 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let output = aEvent.output.output;
|
2012-01-27 18:24:57 +00:00
|
|
|
let declaredType = aEvent.output.command.returnType || "";
|
|
|
|
|
|
|
|
if (declaredType == "object") {
|
|
|
|
let actualType = typeof output;
|
|
|
|
if (output === null) {
|
|
|
|
output = "null";
|
|
|
|
}
|
|
|
|
else if (actualType == "string") {
|
|
|
|
output = "\"" + output + "\"";
|
|
|
|
}
|
|
|
|
else if (actualType == "object" || actualType == "function") {
|
|
|
|
let formatOpts = [ nameObject(output) ];
|
|
|
|
output = stringBundle.formatStringFromName('gcliterm.instanceLabel',
|
|
|
|
formatOpts, formatOpts.length);
|
|
|
|
let linkNode = this.document.createElementNS(HTML_NS, 'html:span');
|
|
|
|
linkNode.appendChild(this.document.createTextNode(output));
|
|
|
|
linkNode.classList.add("hud-clickable");
|
|
|
|
linkNode.setAttribute("aria-haspopup", "true");
|
|
|
|
|
|
|
|
// Make the object bring up the property panel.
|
|
|
|
linkNode.addEventListener("mousedown", function(aEv) {
|
|
|
|
this._startX = aEv.clientX;
|
|
|
|
this._startY = aEv.clientY;
|
|
|
|
}.bind(this), false);
|
|
|
|
|
|
|
|
linkNode.addEventListener("click", function(aEv) {
|
|
|
|
if (aEv.detail != 1 || aEv.button != 0 ||
|
|
|
|
(this._startX != aEv.clientX && this._startY != aEv.clientY)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!this._panelOpen) {
|
|
|
|
let propPanel = this.openPropertyPanel(aEvent.output.typed, aEvent.output.output, this);
|
|
|
|
propPanel.panel.setAttribute("hudId", this.hudId);
|
|
|
|
this._panelOpen = true;
|
|
|
|
}
|
|
|
|
}.bind(this), false);
|
|
|
|
|
|
|
|
output = linkNode;
|
|
|
|
}
|
|
|
|
// else if (actualType == number/boolean/undefined) do nothing
|
|
|
|
}
|
|
|
|
|
|
|
|
if (declaredType == "html" && typeof output == "string") {
|
2011-12-08 12:08:35 +00:00
|
|
|
output = this.document.createRange().createContextualFragment(
|
2011-05-27 12:49:02 +00:00
|
|
|
'<div xmlns="' + HTML_NS + '" xmlns:xul="' + XUL_NS + '">' +
|
2012-01-09 15:38:48 +00:00
|
|
|
output + '</div>');
|
2011-05-27 12:49:02 +00:00
|
|
|
}
|
2011-12-08 12:08:35 +00:00
|
|
|
|
2011-12-08 12:39:04 +00:00
|
|
|
// See https://github.com/mozilla/domtemplate/blob/master/README.md
|
|
|
|
// for docs on the template() function
|
2011-12-08 12:08:35 +00:00
|
|
|
let element = this.document.createRange().createContextualFragment(
|
2012-01-09 15:38:48 +00:00
|
|
|
'<richlistitem xmlns="' + XUL_NS + '" _clipboardText="${clipboardText}"' +
|
|
|
|
' _timestamp="${timestamp}" _id="${id}" class="hud-msg-node">' +
|
|
|
|
' <label class="webconsole-timestamp" _value="${timestampString}"/>' +
|
|
|
|
' <vbox class="webconsole-msg-icon-container" _style="${iconContainerStyle}">' +
|
2011-12-08 12:08:35 +00:00
|
|
|
' <image class="webconsole-msg-icon"/>' +
|
|
|
|
' <spacer flex="1"/>' +
|
|
|
|
' </vbox>' +
|
|
|
|
' <hbox flex="1" class="gcliterm-msg-body">${output}</hbox>' +
|
|
|
|
' <hbox align="start"><label value="1" class="webconsole-msg-repeat"/></hbox>' +
|
|
|
|
'</richlistitem>').firstChild;
|
|
|
|
|
|
|
|
let hud = HUDService.getHudReferenceById(this.hudId);
|
2012-05-10 13:15:10 +00:00
|
|
|
let timestamp = Date.now();
|
2011-12-08 12:39:04 +00:00
|
|
|
template(element, {
|
2011-12-08 12:08:35 +00:00
|
|
|
iconContainerStyle: "margin-left=" + (hud.groupDepth * GROUP_INDENT) + "px",
|
|
|
|
output: output,
|
|
|
|
timestamp: timestamp,
|
2012-05-10 13:15:10 +00:00
|
|
|
timestampString: l10n.timestampString(timestamp),
|
2011-12-08 12:08:35 +00:00
|
|
|
clipboardText: output.innerText,
|
|
|
|
id: "console-msg-" + HUDService.sequenceId()
|
|
|
|
});
|
|
|
|
|
|
|
|
ConsoleUtils.setMessageType(element, CATEGORY_OUTPUT, SEVERITY_LOG);
|
|
|
|
ConsoleUtils.outputMessageNode(element, this.hudId);
|
2011-05-27 12:49:02 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Setup the eval sandbox, should be called whenever we are attached.
|
|
|
|
*/
|
|
|
|
createSandbox: function Gcli_createSandbox()
|
|
|
|
{
|
|
|
|
// create a JS Sandbox out of this.context
|
2012-01-27 18:24:57 +00:00
|
|
|
this.sandbox = new Cu.Sandbox(this._window, {
|
|
|
|
sandboxPrototype: this._window,
|
2011-05-27 12:49:02 +00:00
|
|
|
wantXrays: false
|
|
|
|
});
|
|
|
|
this.sandbox.console = this.console;
|
2012-01-27 18:24:57 +00:00
|
|
|
|
|
|
|
JSTermHelper(this);
|
2011-05-27 12:49:02 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Evaluates a string in the sandbox.
|
|
|
|
*
|
|
|
|
* @param string aString
|
|
|
|
* String to evaluate in the sandbox
|
|
|
|
* @return The result of the evaluation
|
|
|
|
*/
|
|
|
|
evalInSandbox: function Gcli_evalInSandbox(aString)
|
|
|
|
{
|
2012-05-10 13:15:10 +00:00
|
|
|
let window = WebConsoleUtils.unwrap(this.sandbox.window);
|
2012-01-27 18:24:57 +00:00
|
|
|
let temp$ = null;
|
|
|
|
let temp$$ = null;
|
|
|
|
|
|
|
|
// We prefer to execute the page-provided implementations for the $() and
|
|
|
|
// $$() functions.
|
|
|
|
if (typeof window.$ == "function") {
|
|
|
|
temp$ = this.sandbox.$;
|
|
|
|
delete this.sandbox.$;
|
|
|
|
}
|
|
|
|
if (typeof window.$$ == "function") {
|
|
|
|
temp$$ = this.sandbox.$$;
|
|
|
|
delete this.sandbox.$$;
|
|
|
|
}
|
|
|
|
|
|
|
|
let result = Cu.evalInSandbox(aString, this.sandbox, "1.8", "Web Console", 1);
|
|
|
|
|
|
|
|
if (temp$) {
|
|
|
|
this.sandbox.$ = temp$;
|
|
|
|
}
|
|
|
|
if (temp$$) {
|
|
|
|
this.sandbox.$$ = temp$$;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
2011-05-27 12:49:02 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Writes a message to the HUD that originates from the interactive
|
|
|
|
* JavaScript console.
|
|
|
|
*
|
|
|
|
* @param string aOutputMessage
|
|
|
|
* The message to display.
|
|
|
|
* @param number aCategory
|
|
|
|
* One of the CATEGORY_ constants.
|
|
|
|
* @param number aSeverity
|
|
|
|
* One of the SEVERITY_ constants.
|
|
|
|
*/
|
2012-01-27 18:24:57 +00:00
|
|
|
writeOutput: function Gcli_writeOutput(aOutputMessage, aCategory, aSeverity, aOptions)
|
2011-05-27 12:49:02 +00:00
|
|
|
{
|
|
|
|
aOptions = aOptions || {};
|
|
|
|
|
|
|
|
let node = ConsoleUtils.createMessageNode(
|
|
|
|
this.document,
|
2012-01-27 18:24:57 +00:00
|
|
|
aCategory || CATEGORY_OUTPUT,
|
|
|
|
aSeverity || SEVERITY_LOG,
|
2011-05-27 12:49:02 +00:00
|
|
|
aOutputMessage,
|
|
|
|
this.hudId,
|
|
|
|
aOptions.sourceUrl || undefined,
|
|
|
|
aOptions.sourceLine || undefined,
|
|
|
|
aOptions.clipboardText || undefined);
|
|
|
|
|
|
|
|
ConsoleUtils.outputMessageNode(node, this.hudId);
|
|
|
|
},
|
|
|
|
|
|
|
|
clearOutput: JSTerm.prototype.clearOutput,
|
2012-01-27 18:24:57 +00:00
|
|
|
openPropertyPanel: JSTerm.prototype.openPropertyPanel,
|
2011-05-27 12:49:02 +00:00
|
|
|
|
2012-05-10 13:15:10 +00:00
|
|
|
formatResult: WebConsoleUtils.formatResult,
|
|
|
|
getResultType: WebConsoleUtils.getResultType,
|
|
|
|
formatString: WebConsoleUtils.formatResultString,
|
2012-01-27 13:42:05 +00:00
|
|
|
};
|
2012-01-27 18:24:57 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A fancy version of toString()
|
|
|
|
*/
|
|
|
|
function nameObject(aObj) {
|
|
|
|
if (aObj.constructor && aObj.constructor.name) {
|
|
|
|
return aObj.constructor.name;
|
|
|
|
}
|
|
|
|
// If that fails, use Objects toString which sometimes gives something
|
|
|
|
// better than 'Object', and at least defaults to Object if nothing better
|
|
|
|
return Object.prototype.toString.call(aObj).slice(8, -1);
|
|
|
|
}
|