Commit cc2abca5 authored by Pier Angelo Vendrame's avatar Pier Angelo Vendrame 🎃 Committed by brizental
Browse files

dropme! TB 42891: Set the bundled search engine for Tor Browser.

BB 43525: Skip Remote Settings for search engine customization.

Undo some changes to this commit, as they need to be moved to Base
Browser.
parent 00ce04b7
Loading
Loading
Loading
Loading
+38 −14
Original line number Diff line number Diff line
@@ -112,8 +112,6 @@ class IconHandler {
      await this.#buildIconMap();
    }

    return this.#iconMap.get(engineIdentifier);
    // eslint-disable-next-line no-unreachable
    let iconList = this.#iconMap.get(this.getKey(engineIdentifier)) || [];
    return iconList.filter(r =>
      this.#identifierMatches(engineIdentifier, r.engineIdentifiers)
@@ -130,7 +128,29 @@ class IconHandler {
   *   source object or null of there is no icon with the supplied width.
   */
  async createIconURL(iconRecord) {
    return iconRecord.url;
    let iconData;
    try {
      iconData = await this.#iconCollection.attachments.get(iconRecord);
    } catch (ex) {
      console.error(ex);
    }
    if (!iconData) {
      console.warn("Unable to find the attachment for", iconRecord.id);
      // Queue an update in case we haven't downloaded it yet.
      this.#pendingUpdatesMap.set(iconRecord.id, iconRecord);
      this.#maybeQueueIdle();
      return null;
    }

    if (iconData.record.last_modified != iconRecord.last_modified) {
      // The icon we have stored is out of date, queue an update so that we'll
      // download the new icon.
      this.#pendingUpdatesMap.set(iconRecord.id, iconRecord);
      this.#maybeQueueIdle();
    }
    return URL.createObjectURL(
      new Blob([iconData.buffer], { type: iconRecord.attachment.mimetype })
    );
  }

  QueryInterface = ChromeUtils.generateQI(["nsIObserver"]);
@@ -214,23 +234,27 @@ class IconHandler {
   * Obtains the icon list from the remote settings collection.
   */
  async #buildIconMap() {
    let iconList = [];
    try {
      this.#iconMap = new Map(
        Object.entries(
          await (
            await fetch(
              "chrome://global/content/search/torBrowserSearchEngineIcons.json"
            )
          ).json()
        )
      );
      iconList = await this.#iconCollection.get();
    } catch (ex) {
      console.error(ex);
      this.#iconMap = null;
    }
    if (!this.#iconMap) {
    if (!iconList.length) {
      console.error("Failed to obtain search engine icon list records");
    }

    this.#iconMap = new Map();
    for (let record of iconList) {
      let keys = new Set(record.engineIdentifiers.map(this.getKey));
      for (let key of keys) {
        if (this.#iconMap.has(key)) {
          this.#iconMap.get(key).push(record);
        } else {
          this.#iconMap.set(key, [record]);
        }
      }
    }
  }

  /**
+29 −20
Original line number Diff line number Diff line
@@ -9,7 +9,6 @@
 * } from "../uniffi-bindgen-gecko-js/components/generated/RustSearch.sys.mjs";
 */

import { AppConstants } from "resource://gre/modules/AppConstants.sys.mjs";
import { XPCOMUtils } from "resource://gre/modules/XPCOMUtils.sys.mjs";

const lazy = XPCOMUtils.declareLazy({
@@ -92,13 +91,35 @@ export class SearchEngineSelector {
      return this.#getConfigurationPromise;
    }

    let { promise, resolve } = Promise.withResolvers();
    this.#getConfigurationPromise = promise;
    this.#getConfigurationPromise = await (
      await fetch("chrome://global/content/search/torBrowserSearchEngines.json")
    ).json();
    this.#configurationOverrides = [];
    resolve(this.#configuration);
    this.#getConfigurationPromise = Promise.all([
      this.#getConfiguration(),
      this.#getConfigurationOverrides(),
    ]);
    let remoteSettingsData = await this.#getConfigurationPromise;
    this.#configuration = remoteSettingsData[0];
    this.#getConfigurationPromise = null;

    if (!this.#configuration?.length) {
      throw Components.Exception(
        "Failed to get engine data from Remote Settings",
        Cr.NS_ERROR_UNEXPECTED
      );
    }

    /**
     * Records whether the listeners have been added or not.
     */
    if (!this.#listenerAdded) {
      this.#remoteConfig.on("sync", this.#boundOnConfigurationUpdated);
      this.#remoteConfigOverrides.on(
        "sync",
        this.#boundOnConfigurationOverridesUpdated
      );
      /**
       * Records whether the listeners have been added or not.
       */
      this.#listenerAdded = true;
    }

    this.#selector.setSearchConfig(
      JSON.stringify({ data: this.#configuration })
@@ -348,12 +369,6 @@ export class SearchEngineSelector {
   *   The new configuration object
   */
  _onConfigurationUpdated({ data: { current } }) {
    // tor-browser#43525: Even though RemoteSettings are a no-op for us, we do
    // not want them to interfere in any way.
    if (AppConstants.BASE_BROWSER_VERSION) {
      return;
    }

    this.#configuration = current;

    this.#selector.setSearchConfig(
@@ -381,12 +396,6 @@ export class SearchEngineSelector {
   *   The new configuration object
   */
  _onConfigurationOverridesUpdated({ data: { current } }) {
    // tor-browser#43525: Even though RemoteSettings are a no-op for us, we do
    // not want them to interfere in any way.
    if (AppConstants.BASE_BROWSER_VERSION) {
      return;
    }

    this.#selector.setConfigOverrides(JSON.stringify({ data: current }));

    lazy.logConsole.debug("Search configuration overrides updated remotely");
−2.73 KiB
Loading image diff...
−550 B
Loading image diff...
−1.17 KiB
Loading image diff...
Loading