tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

platform-messages.js (1785B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 
      5 "use strict";
      6 
      7 const nsIConsoleListenerWatcher = require("resource://devtools/server/actors/resources/utils/nsi-console-listener-watcher.js");
      8 
      9 const {
     10  createStringGrip,
     11 } = require("resource://devtools/server/actors/object/utils.js");
     12 
     13 class PlatformMessageWatcher extends nsIConsoleListenerWatcher {
     14  shouldHandleTarget(targetActor) {
     15    return this.isProcessTarget(targetActor);
     16  }
     17 
     18  /**
     19   * Returns true if the message is considered a platform message, and as a result, should
     20   * be sent to the client.
     21   *
     22   * @param {TargetActor} targetActor
     23   * @param {nsIConsoleMessage} message
     24   */
     25  shouldHandleMessage(targetActor, message) {
     26    // The listener we use can be called either with a nsIConsoleMessage or as nsIScriptError.
     27    // In this file, we want to ignore nsIScriptError, which are handled by the
     28    // error-messages resource handler (See Bug 1644186).
     29    if (message instanceof Ci.nsIScriptError) {
     30      return false;
     31    }
     32 
     33    // Ignore message that were forwarded from the content process to the parent process,
     34    // since we're getting those directly from the content process.
     35    if (message.isForwardedFromContentProcess) {
     36      return false;
     37    }
     38 
     39    return true;
     40  }
     41 
     42  /**
     43   * Returns an object from the nsIConsoleMessage.
     44   *
     45   * @param {Actor} targetActor
     46   * @param {nsIConsoleMessage} message
     47   */
     48  buildResource(targetActor, message) {
     49    return {
     50      message: createStringGrip(targetActor, message.message),
     51      timeStamp: message.microSecondTimeStamp / 1000,
     52    };
     53  }
     54 }
     55 module.exports = PlatformMessageWatcher;