From ef47656f06fede9f595d2ffac0d02731a7611e2b Mon Sep 17 00:00:00 2001 From: Peter Elmers Date: Thu, 30 Jun 2016 06:59:55 -0700 Subject: [PATCH] Bug 1283465 - New console frontend: Display cached messages. r=linclark MozReview-Commit-ID: ArhGOuUY8ea --- .../new-console-output/utils/messages.js | 20 +++++++++++++++++++ devtools/client/webconsole/webconsole.js | 13 ++++++++---- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/devtools/client/webconsole/new-console-output/utils/messages.js b/devtools/client/webconsole/new-console-output/utils/messages.js index 09f34026155a..44b216cda683 100644 --- a/devtools/client/webconsole/new-console-output/utils/messages.js +++ b/devtools/client/webconsole/new-console-output/utils/messages.js @@ -21,6 +21,22 @@ const WebConsoleUtils = require("devtools/shared/webconsole/utils").Utils; const STRINGS_URI = "chrome://devtools/locale/webconsole.properties"; const l10n = new WebConsoleUtils.L10n(STRINGS_URI); +function convertCachedPacket(packet) { + // The devtools server provides cached message packets in a different shape + // from those of consoleApiCalls, so we prepare them for preparation here. + let convertPacket = {}; + if (packet._type === "ConsoleAPI") { + convertPacket.message = packet; + convertPacket.type = "consoleAPICall"; + } else if (packet._type === "PageError") { + convertPacket.pageError = packet; + convertPacket.type = "pageError"; + } else { + throw new Error("Unexpected packet type"); + } + return convertPacket; +} + function prepareMessage(packet) { // @TODO turn this into an Immutable Record. let allowRepeating; @@ -31,6 +47,10 @@ function prepareMessage(packet) { let repeatId; let severity; + if (packet._type) { + packet = convertCachedPacket(packet); + } + switch (packet.type) { case "consoleAPICall": data = Object.assign({}, packet.message); diff --git a/devtools/client/webconsole/webconsole.js b/devtools/client/webconsole/webconsole.js index 5ebb450450a7..c8406964a2eb 100644 --- a/devtools/client/webconsole/webconsole.js +++ b/devtools/client/webconsole/webconsole.js @@ -3228,10 +3228,15 @@ WebConsoleConnectionProxy.prototype = { response.messages.concat(...this.webConsoleClient.getNetworkEvents()); messages.sort((a, b) => a.timeStamp - b.timeStamp); - this.webConsoleFrame.displayCachedMessages(messages); - - if (!this._hasNativeConsoleAPI) { - this.webConsoleFrame.logWarningAboutReplacedAPI(); + if (this.webConsoleFrame.NEW_CONSOLE_OUTPUT_ENABLED) { + for (let packet of messages) { + this.webConsoleFrame.newConsoleOutput.dispatchMessageAdd(packet); + } + } else { + this.webConsoleFrame.displayCachedMessages(messages); + if (!this._hasNativeConsoleAPI) { + this.webConsoleFrame.logWarningAboutReplacedAPI(); + } } this.connected = true;