commit 20d09a197ad06b9527bea0876cf626f224092c3a
parent d59db0f008c681c0c623a004a8347e94375c8f4c
Author: Henry Wilkes <henry@torproject.org>
Date: Mon, 16 Feb 2026 13:02:33 +0000
fixup! BB 43525: Skip Remote Settings for search engine customization.
TB 44647: Restore upstream's logic for getConfiguration* methods.
Diffstat:
1 file changed, 49 insertions(+), 9 deletions(-)
diff --git a/toolkit/components/search/SearchEngineSelector.sys.mjs b/toolkit/components/search/SearchEngineSelector.sys.mjs
@@ -92,19 +92,42 @@ export class SearchEngineSelector {
return this.#getConfigurationPromise;
}
- let { promise, resolve } = Promise.withResolvers();
- this.#getConfigurationPromise = promise;
- this.#configuration = await (
- await fetch(
- "chrome://global/content/search/base-browser-search-engines.json"
- )
- ).json();
- 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 })
);
- this.#selector.setConfigOverrides(JSON.stringify({ data: [] }));
+ this.#selector.setConfigOverrides(
+ JSON.stringify({ data: remoteSettingsData[1] })
+ );
return this.#configuration;
}
@@ -395,6 +418,23 @@ export class SearchEngineSelector {
}
/**
+ * Obtains the configuration overrides from remote settings.
+ *
+ * @returns {Promise<object[]>}
+ * An array of objects in the database, or an empty array if none
+ * could be obtained.
+ */
+ async #getConfigurationOverrides() {
+ let result = [];
+ try {
+ result = await this.#remoteConfigOverrides.get();
+ } catch (ex) {
+ // This data is remote only, so we just return an empty array if it fails.
+ }
+ return result;
+ }
+
+ /**
* @type {InstanceType<typeof lazy.SearchEngineSelector>?}
*/
#cachedSelector = null;