From 464e29230eeb8c25dfb064f14239b1288c85332b Mon Sep 17 00:00:00 2001 From: "Matt A. Tobin" Date: Fri, 2 Feb 2018 07:11:37 -0500 Subject: Issue N/A - Restore the Toolkit Error Console - Part 1: Toolkit --- toolkit/components/console/content/console.css | 74 +++ toolkit/components/console/content/console.js | 111 +++++ toolkit/components/console/content/console.xul | 101 ++++ .../components/console/content/consoleBindings.xml | 547 +++++++++++++++++++++ toolkit/components/console/jar.mn | 9 + toolkit/components/console/jsconsole-clhandler.js | 40 ++ .../console/jsconsole-clhandler.manifest | 3 + toolkit/components/console/moz.build | 14 + toolkit/components/console/tests/chrome.ini | 3 + toolkit/components/console/tests/test_hugeURIs.xul | 64 +++ 10 files changed, 966 insertions(+) create mode 100644 toolkit/components/console/content/console.css create mode 100644 toolkit/components/console/content/console.js create mode 100644 toolkit/components/console/content/console.xul create mode 100644 toolkit/components/console/content/consoleBindings.xml create mode 100644 toolkit/components/console/jar.mn create mode 100644 toolkit/components/console/jsconsole-clhandler.js create mode 100644 toolkit/components/console/jsconsole-clhandler.manifest create mode 100644 toolkit/components/console/moz.build create mode 100644 toolkit/components/console/tests/chrome.ini create mode 100644 toolkit/components/console/tests/test_hugeURIs.xul (limited to 'toolkit/components/console') diff --git a/toolkit/components/console/content/console.css b/toolkit/components/console/content/console.css new file mode 100644 index 000000000..e05f13c3e --- /dev/null +++ b/toolkit/components/console/content/console.css @@ -0,0 +1,74 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +.console-box { + -moz-binding: url("chrome://global/content/consoleBindings.xml#console-box"); + overflow: auto; +} + +.console-rows { + -moz-user-focus: normal; +} + +.console-row[type="error"], +.console-row[type="warning"] { + -moz-binding: url("chrome://global/content/consoleBindings.xml#error"); +} + +.console-row[type="message"] { + -moz-binding: url("chrome://global/content/consoleBindings.xml#message"); +} + +.console-msg-text, +.console-error-msg { + white-space: pre-wrap; +} + +.console-error-source { + -moz-binding: url("chrome://global/content/consoleBindings.xml#console-error-source"); +} + +.console-dots { + width: 1px; +} + +/* :::::::::: hiding and showing of rows for each mode :::::::::: */ + +.console-box[mode="Warnings"] > .console-box-internal > .console-rows + > .console-row[type="error"], +.console-box[mode="Messages"] > .console-box-internal > .console-rows + > .console-row[type="error"] +{ + display: none; +} + +.console-box[mode="Errors"] > .console-box-internal > .console-rows + > .console-row[type="warning"], +.console-box[mode="Messages"] > .console-box-internal > .console-rows + > .console-row[type="warning"] +{ + display: none; +} + +.console-box[mode="Errors"] > .console-box-internal > .console-rows + > .console-row[type="message"], +.console-box[mode="Warnings"] > .console-box-internal > .console-rows + > .console-row[type="message"] +{ + display: none; +} + +.filtered-by-string { + display: none; +} + +/* If line number is 0, hide the line number section */ +.lineNumberRow[line="0"] { + display: none; +} + +#TextboxEval { + direction: ltr; +} diff --git a/toolkit/components/console/content/console.js b/toolkit/components/console/content/console.js new file mode 100644 index 000000000..ad6802607 --- /dev/null +++ b/toolkit/components/console/content/console.js @@ -0,0 +1,111 @@ +// -*- indent-tabs-mode: nil; js-indent-level: 2 -*- + +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +Components.utils.import("resource://gre/modules/Services.jsm"); + +var gConsole, gConsoleBundle, gTextBoxEval, gEvaluator, gCodeToEvaluate; +var gFilter; + +/* :::::::: Console Initialization ::::::::::::::: */ + +window.onload = function() +{ + gConsole = document.getElementById("ConsoleBox"); + gConsoleBundle = document.getElementById("ConsoleBundle"); + gTextBoxEval = document.getElementById("TextboxEval"); + gEvaluator = document.getElementById("Evaluator"); + gFilter = document.getElementById("Filter"); + + updateSortCommand(gConsole.sortOrder); + updateModeCommand(gConsole.mode); + + gEvaluator.addEventListener("load", loadOrDisplayResult, true); +} + +/* :::::::: Console UI Functions ::::::::::::::: */ + +function changeFilter() +{ + gConsole.filter = gFilter.value; + + document.persist("ConsoleBox", "filter"); +} + +function changeMode(aMode) +{ + switch (aMode) { + case "Errors": + case "Warnings": + case "Messages": + gConsole.mode = aMode; + break; + case "All": + gConsole.mode = null; + } + + document.persist("ConsoleBox", "mode"); +} + +function clearConsole() +{ + gConsole.clear(); +} + +function changeSortOrder(aOrder) +{ + updateSortCommand(gConsole.sortOrder = aOrder); +} + +function updateSortCommand(aOrder) +{ + var orderString = aOrder == 'reverse' ? "Descend" : "Ascend"; + var bc = document.getElementById("Console:sort"+orderString); + bc.setAttribute("checked", true); + + orderString = aOrder == 'reverse' ? "Ascend" : "Descend"; + bc = document.getElementById("Console:sort"+orderString); + bc.setAttribute("checked", false); +} + +function updateModeCommand(aMode) +{ + /* aMode can end up invalid if it set by an extension that replaces */ + /* mode and then it is uninstalled or disabled */ + var bc = document.getElementById("Console:mode" + aMode) || + document.getElementById("Console:modeAll"); + bc.setAttribute("checked", true); +} + +function onEvalKeyPress(aEvent) +{ + if (aEvent.keyCode == 13) + evaluateTypein(); +} + +function evaluateTypein() +{ + gCodeToEvaluate = gTextBoxEval.value; + // reset the iframe first; the code will be evaluated in loadOrDisplayResult + // below, once about:blank has completed loading (see bug 385092) + gEvaluator.contentWindow.location = "about:blank"; +} + +function loadOrDisplayResult() +{ + if (gCodeToEvaluate) { + gEvaluator.contentWindow.location = "javascript: " + + gCodeToEvaluate.replace(/%/g, "%25"); + gCodeToEvaluate = ""; + return; + } + + var resultRange = gEvaluator.contentDocument.createRange(); + resultRange.selectNode(gEvaluator.contentDocument.documentElement); + var result = resultRange.toString(); + if (result) + Services.console.logStringMessage(result); + // or could use appendMessage which doesn't persist +} diff --git a/toolkit/components/console/content/console.xul b/toolkit/components/console/content/console.xul new file mode 100644 index 000000000..0abd0a981 --- /dev/null +++ b/toolkit/components/console/content/console.xul @@ -0,0 +1,101 @@ + + + + + + + + + + %console; +]> + + + + + -- cgit v1.2.3