
Pier Angelo Vendrame pushed to branch base-browser-140.2.0esr-15.0-1 at The Tor Project / Applications / Tor Browser Commits: a1886d8c by Pier Angelo Vendrame at 2025-09-08T11:57:50+02:00 BB 43525: Skip Remote Settings for search engine customization. Also, add some bundled search engines. - - - - - 9 changed files: - toolkit/components/search/AppProvidedSearchEngine.sys.mjs - toolkit/components/search/SearchEngineSelector.sys.mjs - + toolkit/components/search/content/base-browser-search-engine-icons.json - + toolkit/components/search/content/base-browser-search-engines.json - + toolkit/components/search/content/duckduckgo.ico - + toolkit/components/search/content/startpage-16.png - + toolkit/components/search/content/startpage-32.png - + toolkit/components/search/jar.mn - toolkit/components/search/moz.build Changes: ===================================== toolkit/components/search/AppProvidedSearchEngine.sys.mjs ===================================== @@ -116,6 +116,10 @@ class IconHandler { await this.#buildIconMap(); } + if (AppConstants.BASE_BROWSER_VERSION) { + return this.#iconMap.get(engineIdentifier); + } + let iconList = this.#iconMap.get(this.getKey(engineIdentifier)) || []; return iconList.filter(r => this.#identifierMatches(engineIdentifier, r.engineIdentifiers) @@ -132,29 +136,7 @@ class IconHandler { * source object or null of there is no icon with the supplied width. */ async createIconURL(iconRecord) { - 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 }) - ); + return iconRecord.url; } QueryInterface = ChromeUtils.generateQI(["nsIObserver"]); @@ -238,27 +220,23 @@ class IconHandler { * Obtains the icon list from the remote settings collection. */ async #buildIconMap() { - let iconList = []; try { - iconList = await this.#iconCollection.get(); + this.#iconMap = new Map( + Object.entries( + await ( + await fetch( + "chrome://global/content/search/base-browser-search-engine-icons.json" + ) + ).json() + ) + ); } catch (ex) { console.error(ex); + this.#iconMap = null; } - if (!iconList.length) { + if (!this.#iconMap) { 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]); - } - } - } } /** ===================================== toolkit/components/search/SearchEngineSelector.sys.mjs ===================================== @@ -2,6 +2,8 @@ * 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 { AppConstants } from "resource://gre/modules/AppConstants.sys.mjs"; + /** * @typedef {import("../uniffi-bindgen-gecko-js/components/generated/RustSearch.sys.mjs").SearchEngineSelector} RustSearchEngineSelector * We use "Rust" above to avoid conflict with the class name for the JavaScript wrapper. @@ -92,30 +94,15 @@ export class SearchEngineSelector { return this._getConfigurationPromise; } - this._getConfigurationPromise = Promise.all([ - this._getConfiguration(), - this._getConfigurationOverrides(), - ]); - let remoteSettingsData = await this._getConfigurationPromise; - this._configuration = remoteSettingsData[0]; - this._configurationOverrides = remoteSettingsData[1]; - delete this._getConfigurationPromise; - - if (!this._configuration?.length) { - throw Components.Exception( - "Failed to get engine data from Remote Settings", - Cr.NS_ERROR_UNEXPECTED - ); - } - - if (!this._listenerAdded) { - this._remoteConfig.on("sync", this._onConfigurationUpdated); - this._remoteConfigOverrides.on( - "sync", - this._onConfigurationOverridesUpdated - ); - this._listenerAdded = true; - } + let { promise, resolve } = Promise.withResolvers(); + this._getConfigurationPromise = promise; + this._configuration = await ( + await fetch( + "chrome://global/content/search/base-browser-search-engines.json" + ) + ).json(); + this._configurationOverrides = []; + resolve(this._configuration); if (lazy.SearchUtils.rustSelectorFeatureGate) { this.#selector.setSearchConfig( @@ -242,6 +229,12 @@ 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; if (lazy.SearchUtils.rustSelectorFeatureGate) { @@ -268,6 +261,12 @@ 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._configurationOverrides = current; if (lazy.SearchUtils.rustSelectorFeatureGate) { ===================================== toolkit/components/search/content/base-browser-search-engine-icons.json ===================================== @@ -0,0 +1,15 @@ +{ + "ddg": [ + { "url": "chrome://global/content/search/duckduckgo.ico", "imageSize": 32 } + ], + "startpage": [ + { + "url": "chrome://global/content/search/startpage-16.png", + "imageSize": 16 + }, + { + "url": "chrome://global/content/search/startpage-32.png", + "imageSize": 32 + } + ] +} ===================================== toolkit/components/search/content/base-browser-search-engines.json ===================================== @@ -0,0 +1,43 @@ +[ + { + "base": { + "aliases": ["duckduckgo", "ddg"], + "classification": "general", + "name": "DuckDuckGo", + "urls": { + "search": { + "base": "https://duckduckgo.com/", + "params": [], + "searchTermParamName": "q" + } + } + }, + "id": "04e99a38-13ee-47d8-8aa4-64482b3dea99", + "identifier": "ddg", + "recordType": "engine", + "variants": [{ "environment": { "allRegionsAndLocales": true } }] + }, + { + "base": { + "aliases": ["startpage", "sp"], + "classification": "general", + "name": "Startpage", + "urls": { + "search": { + "base": "https://www.startpage.com/sp/search", + "params": [], + "searchTermParamName": "q" + } + } + }, + "id": "927bbd9f-b2f3-48b4-8974-1c1148028f4d", + "identifier": "startpage", + "recordType": "engine", + "variants": [{ "environment": { "allRegionsAndLocales": true } }] + }, + { + "recordType": "defaultEngines", + "globalDefault": "ddg", + "globalDefaultPrivate": "ddg" + } +] ===================================== toolkit/components/search/content/duckduckgo.ico ===================================== Binary files /dev/null and b/toolkit/components/search/content/duckduckgo.ico differ ===================================== toolkit/components/search/content/startpage-16.png ===================================== Binary files /dev/null and b/toolkit/components/search/content/startpage-16.png differ ===================================== toolkit/components/search/content/startpage-32.png ===================================== Binary files /dev/null and b/toolkit/components/search/content/startpage-32.png differ ===================================== toolkit/components/search/jar.mn ===================================== @@ -0,0 +1,6 @@ +# 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/. + +toolkit.jar: + content/global/search/ (content/*) ===================================== toolkit/components/search/moz.build ===================================== @@ -46,5 +46,7 @@ TESTING_JS_MODULES += [ "tests/SearchTestUtils.sys.mjs", ] +JAR_MANIFESTS += ["jar.mn"] + with Files("**"): BUG_COMPONENT = ("Firefox", "Search") View it on GitLab: https://gitlab.torproject.org/tpo/applications/tor-browser/-/commit/a1886d8c... -- View it on GitLab: https://gitlab.torproject.org/tpo/applications/tor-browser/-/commit/a1886d8c... You're receiving this email because of your account on gitlab.torproject.org.
participants (1)
-
Pier Angelo Vendrame (@pierov)