tor-browser

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

AboutTorMessage.sys.mjs (1757B)


      1 // about:tor should cycle its displayed message on each load, this keeps track
      2 // of which message to show globally.
      3 
      4 /**
      5 * @typedef {object} MessageData
      6 *
      7 * @property {string} [updateVersion] - The update version to show. If this is
      8 *   defined, the update message should be shown.
      9 * @property {string} [updateURL] - The update URL to use when updateVersion is
     10 *   given.
     11 * @property {integer} [number] - The number of the message to show, when
     12 *   updateVersion is not given. This always increases, so the caller should
     13 *   take its remainder to cycle messages.
     14 */
     15 export const AboutTorMessage = {
     16  // NOTE: We always start the count at 0 with every session so that the first
     17  // message is always shown first.
     18  _count: 0,
     19 
     20  /**
     21   * Get details about which message to show on the next about:tor page.
     22   *
     23   * @returns {MessageData} Details about the message to show.
     24   */
     25  getNext() {
     26    const shouldNotifyPref = "torbrowser.post_update.shouldNotify";
     27    if (Services.prefs.getBoolPref(shouldNotifyPref, false)) {
     28      Services.prefs.clearUserPref(shouldNotifyPref);
     29      // Try use the same URL as the about dialog. See tor-browser#43567.
     30      let updateURL = Services.urlFormatter.formatURLPref(
     31        "app.releaseNotesURL.aboutDialog"
     32      );
     33      if (updateURL === "about:blank") {
     34        updateURL = Services.urlFormatter.formatURLPref(
     35          "startup.homepage_override_url"
     36        );
     37      }
     38      return {
     39        updateVersion: Services.prefs.getCharPref(
     40          "browser.startup.homepage_override.torbrowser.version"
     41        ),
     42        updateURL,
     43      };
     44    }
     45    const number = this._count;
     46    // Assume the count will not exceed Number.MAX_SAFE_INTEGER.
     47    this._count++;
     48    return { number };
     49  },
     50 };