henry pushed to branch tor-browser-147.0a1-16.0-2 at The Tor Project / Applications / Tor Browser

Commits:

1 changed file:

Changes:

  • toolkit/components/search/SearchEngineSelector.sys.mjs
    ... ... @@ -92,19 +92,44 @@ export class SearchEngineSelector {
    92 92
           return this.#getConfigurationPromise;
    
    93 93
         }
    
    94 94
     
    
    95
    -    let { promise, resolve } = Promise.withResolvers();
    
    96
    -    this.#getConfigurationPromise = promise;
    
    97
    -    this.#configuration = await (
    
    98
    -      await fetch(
    
    99
    -        "chrome://global/content/search/base-browser-search-engines.json"
    
    100
    -      )
    
    101
    -    ).json();
    
    102
    -    resolve(this.#configuration);
    
    95
    +    this.#getConfigurationPromise = Promise.all([
    
    96
    +      this.#getConfiguration(),
    
    97
    +      this.#getConfigurationOverrides(),
    
    98
    +    ]);
    
    99
    +    let remoteSettingsData = await this.#getConfigurationPromise;
    
    100
    +    this.#configuration = remoteSettingsData[0];
    
    101
    +    // For Base Browser, we don't expect the configuration to ever change in a
    
    102
    +    // session, so we keep the #getConfigurationPromise as-is for later calls.
    
    103
    +
    
    104
    +    if (!this.#configuration?.length) {
    
    105
    +      throw Components.Exception(
    
    106
    +        "Failed to get engine data from Remote Settings",
    
    107
    +        Cr.NS_ERROR_UNEXPECTED
    
    108
    +      );
    
    109
    +    }
    
    110
    +
    
    111
    +    /**
    
    112
    +     * Records whether the listeners have been added or not.
    
    113
    +     */
    
    114
    +    // For Base Browser, we don't use remoteConfig. tor-browser#43525.
    
    115
    +    if (!AppConstants.BASE_BROWSER_VERSION && !this.#listenerAdded) {
    
    116
    +      this.#remoteConfig.on("sync", this.#boundOnConfigurationUpdated);
    
    117
    +      this.#remoteConfigOverrides.on(
    
    118
    +        "sync",
    
    119
    +        this.#boundOnConfigurationOverridesUpdated
    
    120
    +      );
    
    121
    +      /**
    
    122
    +       * Records whether the listeners have been added or not.
    
    123
    +       */
    
    124
    +      this.#listenerAdded = true;
    
    125
    +    }
    
    103 126
     
    
    104 127
         this.#selector.setSearchConfig(
    
    105 128
           JSON.stringify({ data: this.#configuration })
    
    106 129
         );
    
    107
    -    this.#selector.setConfigOverrides(JSON.stringify({ data: [] }));
    
    130
    +    this.#selector.setConfigOverrides(
    
    131
    +      JSON.stringify({ data: remoteSettingsData[1] })
    
    132
    +    );
    
    108 133
     
    
    109 134
         return this.#configuration;
    
    110 135
       }
    
    ... ... @@ -324,6 +349,15 @@ export class SearchEngineSelector {
    324 349
        *   could be obtained.
    
    325 350
        */
    
    326 351
       async #getConfiguration(firstTime = true) {
    
    352
    +    if (AppConstants.BASE_BROWSER_VERSION) {
    
    353
    +      // For Base Browser, load the config from a local file, rather than
    
    354
    +      // #remoteConfig. tor-browser#43525.
    
    355
    +      return (
    
    356
    +        await fetch(
    
    357
    +          "chrome://global/content/search/base-browser-search-engines.json"
    
    358
    +        )
    
    359
    +      ).json();
    
    360
    +    }
    
    327 361
         let result = [];
    
    328 362
         let failed = false;
    
    329 363
         try {
    
    ... ... @@ -409,6 +443,27 @@ export class SearchEngineSelector {
    409 443
         }
    
    410 444
       }
    
    411 445
     
    
    446
    +  /**
    
    447
    +   * Obtains the configuration overrides from remote settings.
    
    448
    +   *
    
    449
    +   * @returns {Promise<object[]>}
    
    450
    +   *   An array of objects in the database, or an empty array if none
    
    451
    +   *   could be obtained.
    
    452
    +   */
    
    453
    +  async #getConfigurationOverrides() {
    
    454
    +    if (AppConstants.BASE_BROWSER_VERSION) {
    
    455
    +      // For Base Browser, we don't want overrides. tor-browser#43525.
    
    456
    +      return [];
    
    457
    +    }
    
    458
    +    let result = [];
    
    459
    +    try {
    
    460
    +      result = await this.#remoteConfigOverrides.get();
    
    461
    +    } catch (ex) {
    
    462
    +      // This data is remote only, so we just return an empty array if it fails.
    
    463
    +    }
    
    464
    +    return result;
    
    465
    +  }
    
    466
    +
    
    412 467
       /**
    
    413 468
        * @type {InstanceType<typeof lazy.SearchEngineSelector>?}
    
    414 469
        */