Commit 17ec572f authored by Pier Angelo Vendrame's avatar Pier Angelo Vendrame 🎃
Browse files

fixup! TB 40458: Implement .tor.onion aliases

BB 43770: Follow upstream's BrowserGlue simplifications.
parent 645a01a9
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -57,6 +57,7 @@ category browser-first-window-ready moz-src:///browser/modules/ClipboardPrivacy.
category browser-first-window-ready moz-src:///browser/modules/SecurityLevelNotification.sys.mjs SecurityLevelNotification.ready
category browser-first-window-ready moz-src:///toolkit/modules/DragDropFilter.sys.mjs DragDropFilter.init
category browser-first-window-ready moz-src:///browser/modules/TorSettingsNotification.sys.mjs TorSettingsNotification.ready
category browser-first-window-ready moz-src:///browser/components/onionservices/OnionAliasStore.sys.mjs OnionAliasStore.init

category browser-idle-startup moz-src:///browser/components/places/PlacesUIUtils.sys.mjs PlacesUIUtils.unblockToolbars
category browser-idle-startup resource:///modules/BuiltInThemes.sys.mjs BuiltInThemes.ensureBuiltInThemes
@@ -101,5 +102,6 @@ category browser-quit-application-granted resource://gre/modules/UpdateListener.
#endif
category browser-quit-application-granted resource:///modules/UrlbarSearchTermsPersistence.sys.mjs UrlbarSearchTermsPersistence.uninit
category browser-quit-application-granted resource:///modules/ipprotection/IPProtectionService.sys.mjs IPProtectionService.uninit
category browser-quit-application-granted moz-src:///browser/components/onionservices/OnionAliasStore.sys.mjs OnionAliasStore.uninit

category search-service-notification moz-src:///browser/components/search/SearchUIUtils.sys.mjs SearchUIUtils.showSearchServiceNotification
+0 −28
Original line number Diff line number Diff line
@@ -37,7 +37,6 @@ ChromeUtils.defineESModuleGetters(lazy, {
  LoginHelper: "resource://gre/modules/LoginHelper.sys.mjs",
  MigrationUtils: "resource:///modules/MigrationUtils.sys.mjs",
  NimbusFeatures: "resource://nimbus/ExperimentAPI.sys.mjs",
  OnionAliasStore: "resource:///modules/OnionAliasStore.sys.mjs",
  OnboardingMessageProvider:
    "resource:///modules/asrouter/OnboardingMessageProvider.sys.mjs",
  PageDataService:
@@ -66,8 +65,6 @@ ChromeUtils.defineESModuleGetters(lazy, {
  TelemetryReportingPolicy:
    "resource://gre/modules/TelemetryReportingPolicy.sys.mjs",
  TRRRacer: "resource:///modules/TRRPerformance.sys.mjs",
  TorConnect: "resource://gre/modules/TorConnect.sys.mjs",
  TorConnectTopics: "resource://gre/modules/TorConnect.sys.mjs",
  WebChannel: "resource://gre/modules/WebChannel.sys.mjs",
  WebProtocolHandlerRegistrar:
    "resource:///modules/WebProtocolHandlerRegistrar.sys.mjs",
@@ -869,7 +866,6 @@ BrowserGlue.prototype = {
        // can perform at-shutdown tasks later in shutdown.
        Services.fog;
      },
      () => lazy.OnionAliasStore.uninit(),
    ];

    for (let task of tasks) {
@@ -1140,30 +1136,6 @@ BrowserGlue.prototype = {
        },
      },

      {
        task: () => {
          if (!lazy.TorConnect.shouldShowTorConnect) {
            // we will take this path when the user is using the legacy tor launcher or
            // when Tor Browser didn't launch its own tor.
            lazy.OnionAliasStore.init();
          } else {
            // this path is taken when using about:torconnect, we wait to init
            // after we are bootstrapped and connected to tor
            const topic = lazy.TorConnectTopics.BootstrapComplete;
            let bootstrapObserver = {
              observe(aSubject, aTopic) {
                if (aTopic === topic) {
                  lazy.OnionAliasStore.init();
                  // we only need to init once, so remove ourselves as an obvserver
                  Services.obs.removeObserver(this, topic);
                }
              },
            };
            Services.obs.addObserver(bootstrapObserver, topic);
          }
        },
      },

      // Run TRR performance measurements for DoH.
      {
        name: "doh-rollout.trrRacer.run",
+18 −3
Original line number Diff line number Diff line
// Copyright (c) 2022, The Tor Project, Inc.
/* 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/. */

import { setTimeout, clearTimeout } from "resource://gre/modules/Timer.sys.mjs";

@@ -6,7 +8,10 @@ const lazy = {};

ChromeUtils.defineESModuleGetters(lazy, {
  JSONFile: "resource://gre/modules/JSONFile.sys.mjs",
  TorRequestWatch: "resource:///modules/TorRequestWatch.sys.mjs",
  TorConnect: "resource://gre/modules/TorConnect.sys.mjs",
  TorConnectTopics: "resource://gre/modules/TorConnect.sys.mjs",
  TorRequestWatch:
    "moz-src:///browser/components/onionservices/TorRequestWatch.sys.mjs",
});

/* OnionAliasStore observer topics */
@@ -287,8 +292,10 @@ class _OnionAliasStore {
  async init() {
    lazy.TorRequestWatch.start();
    await this.#loadSettings();
    if (this.enabled) {
    if (this.enabled && !lazy.TorConnect.shouldShowTorConnect) {
      await this.#startUpdates();
    } else {
      Services.obs.addObserver(this, lazy.TorConnectTopics.BootstrapComplete);
    }
    Services.prefs.addObserver(kPrefOnionAliasEnabled, this);
  }
@@ -299,7 +306,10 @@ class _OnionAliasStore {
      clearTimeout(this.#rulesetTimeout);
    }
    this.#rulesetTimeout = null;

    Services.obs.removeObserver(this, lazy.TorConnectTopics.BootstrapComplete);
    Services.prefs.removeObserver(kPrefOnionAliasEnabled, this);

    lazy.TorRequestWatch.stop();
  }

@@ -543,6 +553,11 @@ class _OnionAliasStore {
        clearTimeout(this.#rulesetTimeout);
        this.#rulesetTimeout = null;
      }
    } else if (
      aTopic === lazy.TorConnectTopics.BootstrapComplete &&
      this.enabled
    ) {
      this.#startUpdates();
    }
  }
}
+4 −1
Original line number Diff line number Diff line
JAR_MANIFESTS += ["jar.mn"]

EXTRA_JS_MODULES += [
    "OnionAliasStore.sys.mjs",
    "OnionLocationChild.sys.mjs",
    "OnionLocationParent.sys.mjs",
]

MOZ_SRC_FILES += [
    "OnionAliasStore.sys.mjs",
    "TorRequestWatch.sys.mjs",
]
+6 −3
Original line number Diff line number Diff line
// Copyright (c) 2022, The Tor Project, Inc.
/* 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/. */

import {
  OnionAliasStore,
  OnionAliasStoreTopics,
} from "resource:///modules/OnionAliasStore.sys.mjs";
} from "moz-src:///browser/components/onionservices/OnionAliasStore.sys.mjs";

const kShowWarningPref = "torbrowser.rulesets.show_warning";

@@ -56,9 +58,10 @@ export class RulesetsParent extends JSWindowActorParent {
        return {
          showWarning: Services.prefs.getBoolPref(kShowWarningPref, true),
        };
      case "rulesets:set-channel":
      case "rulesets:set-channel": {
        const ch = await OnionAliasStore.setChannel(message.data);
        return ch;
      }
      case "rulesets:update-channel":
        // We need to catch any error in this way, because in case of an
        // exception, RPMSendQuery does not return on the other side