Verified Commit 404b6d97 authored by Richard Pospesel's avatar Richard Pospesel Committed by Pier Angelo Vendrame
Browse files

Bug 40597: Implement TorSettings module

- migrated in-page settings read/write implementation from about:preferences#tor
  to the TorSettings module
- TorSettings initially loads settings from the tor daemon, and saves them to
  firefox prefs
- TorSettings notifies observers when a setting has changed; currently only
  QuickStart notification is implemented for parity with previous preference
  notify logic in about:torconnect and about:preferences#tor
- about:preferences#tor, and about:torconnect now read and write settings
  thorugh the TorSettings module
- all tor settings live in the torbrowser.settings.* preference branch
- removed unused pref modify permission for about:torconnect content page from
  AsyncPrefs.jsm

Bug 40645: Migrate Moat APIs to Moat.jsm module
parent 6e2d9670
Loading
Loading
Loading
Loading
+65 −0
Original line number Diff line number Diff line
/* 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/. */

const lazy = {};

ChromeUtils.defineESModuleGetters(lazy, {
  MoatRPC: "resource:///modules/Moat.sys.mjs",
});

export var BridgeDB = {
  _moatRPC: null,
  _challenge: null,
  _image: null,
  _bridges: null,

  get currentCaptchaImage() {
    return this._image;
  },

  get currentBridges() {
    return this._bridges;
  },

  async submitCaptchaGuess(solution) {
    if (!this._moatRPC) {
      this._moatRPC = new lazy.MoatRPC();
      await this._moatRPC.init();
    }

    const response = await this._moatRPC.check(
      "obfs4",
      this._challenge,
      solution,
      false
    );
    this._bridges = response?.bridges;
    return this._bridges;
  },

  async requestNewCaptchaImage() {
    try {
      if (!this._moatRPC) {
        this._moatRPC = new lazy.MoatRPC();
        await this._moatRPC.init();
      }

      const response = await this._moatRPC.fetch(["obfs4"]);
      this._challenge = response.challenge;
      this._image =
        "data:image/jpeg;base64," + encodeURIComponent(response.image);
    } catch (err) {
      console.error("Could not request a captcha image", err);
    }
    return this._image;
  },

  close() {
    this._moatRPC?.uninit();
    this._moatRPC = null;
    this._challenge = null;
    this._image = null;
    this._bridges = null;
  },
};
+768 −0

File added.

Preview size limit exceeded, changes collapsed.

+1210 −0

File added.

Preview size limit exceeded, changes collapsed.

+778 −0

File added.

Preview size limit exceeded, changes collapsed.

+4 −0
Original line number Diff line number Diff line
@@ -123,6 +123,7 @@ XPCSHELL_TESTS_MANIFESTS += ["test/unit/xpcshell.ini"]
EXTRA_JS_MODULES += [
    "AboutNewTab.jsm",
    "AsyncTabSwitcher.jsm",
    "BridgeDB.sys.mjs",
    "BrowserUIUtils.jsm",
    "BrowserUsageTelemetry.jsm",
    "BrowserWindowTracker.jsm",
@@ -134,6 +135,7 @@ EXTRA_JS_MODULES += [
    "FeatureCallout.sys.mjs",
    "HomePage.jsm",
    "LaterRun.jsm",
    "Moat.sys.mjs",
    "NewTabPagePreloading.jsm",
    "OpenInTabsUtils.jsm",
    "PageActions.jsm",
@@ -147,6 +149,8 @@ EXTRA_JS_MODULES += [
    "SitePermissions.sys.mjs",
    "TabsList.jsm",
    "TabUnloader.jsm",
    "TorConnect.sys.mjs",
    "TorSettings.sys.mjs",
    "TorStrings.jsm",
    "TransientPrefs.jsm",
    "URILoadingHelper.sys.mjs",
Loading