tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit 8168b31afd40ea603285421d51fa4383f43c8422
parent 2df553f33535c48b468dbe8d5c7f39b5ff0c269b
Author: Dão Gottwald <dao@mozilla.com>
Date:   Mon,  3 Nov 2025 19:06:11 +0000

Bug 1990522 - Restrict tokens should not be available in the search bar re-implementation. r=mbeier

Differential Revision: https://phabricator.services.mozilla.com/D266142

Diffstat:
Mbrowser/components/urlbar/UrlbarInput.sys.mjs | 6+++---
Mbrowser/components/urlbar/UrlbarProviderHeuristicFallback.sys.mjs | 5++++-
Mbrowser/components/urlbar/UrlbarProvidersManager.sys.mjs | 36++++++++++++++++++------------------
3 files changed, 25 insertions(+), 22 deletions(-)

diff --git a/browser/components/urlbar/UrlbarInput.sys.mjs b/browser/components/urlbar/UrlbarInput.sys.mjs @@ -1990,9 +1990,9 @@ export class UrlbarInput { }; } - let mode = lazy.UrlbarUtils.LOCAL_SEARCH_MODES.find( - m => m.restrict == token - ); + let mode = + this.isAddressbar && + lazy.UrlbarUtils.LOCAL_SEARCH_MODES.find(m => m.restrict == token); if (mode) { // Return a copy so callers don't modify the object in LOCAL_SEARCH_MODES. return { ...mode }; diff --git a/browser/components/urlbar/UrlbarProviderHeuristicFallback.sys.mjs b/browser/components/urlbar/UrlbarProviderHeuristicFallback.sys.mjs @@ -231,7 +231,10 @@ export class UrlbarProviderHeuristicFallback extends UrlbarProvider { } async _searchModeKeywordResult(queryContext) { - if (!queryContext.tokens.length) { + if ( + !queryContext.tokens.length || + !this.queryInstance.controller.input.isAddressbar + ) { return null; } diff --git a/browser/components/urlbar/UrlbarProvidersManager.sys.mjs b/browser/components/urlbar/UrlbarProvidersManager.sys.mjs @@ -437,7 +437,7 @@ export class ProvidersManager { // can be used for searching. Otherwise sources are extracted from prefs and // restriction tokens, then restriction tokens must be filtered out of the // search string. - let restrictToken = updateSourcesIfEmpty(queryContext); + let restrictToken = updateSourcesIfEmpty(queryContext, controller); if (restrictToken) { queryContext.restrictToken = restrictToken; // If the restriction token has an equivalent source, then set it as @@ -983,27 +983,31 @@ export class Query { * Updates in place the sources for a given UrlbarQueryContext. * * @param {UrlbarQueryContext} context The query context to examine + * @param {?UrlbarController} [controller] A UrlbarController instance * @returns {UrlbarSearchStringTokenData|undefined} The restriction token that * was used to set sources, or undefined if there's no restriction token. */ -function updateSourcesIfEmpty(context) { +function updateSourcesIfEmpty(context, controller) { if (context.sources && context.sources.length) { return undefined; } let acceptedSources = []; // There can be only one restrict token per query. - let restrictToken = context.tokens.find(t => - [ - lazy.UrlbarTokenizer.TYPE.RESTRICT_HISTORY, - lazy.UrlbarTokenizer.TYPE.RESTRICT_BOOKMARK, - lazy.UrlbarTokenizer.TYPE.RESTRICT_TAG, - lazy.UrlbarTokenizer.TYPE.RESTRICT_OPENPAGE, - lazy.UrlbarTokenizer.TYPE.RESTRICT_SEARCH, - lazy.UrlbarTokenizer.TYPE.RESTRICT_TITLE, - lazy.UrlbarTokenizer.TYPE.RESTRICT_URL, - lazy.UrlbarTokenizer.TYPE.RESTRICT_ACTION, - ].includes(t.type) - ); + let restrictToken = + controller && !controller.input.isAddressbar + ? undefined + : context.tokens.find(t => + [ + lazy.UrlbarTokenizer.TYPE.RESTRICT_HISTORY, + lazy.UrlbarTokenizer.TYPE.RESTRICT_BOOKMARK, + lazy.UrlbarTokenizer.TYPE.RESTRICT_TAG, + lazy.UrlbarTokenizer.TYPE.RESTRICT_OPENPAGE, + lazy.UrlbarTokenizer.TYPE.RESTRICT_SEARCH, + lazy.UrlbarTokenizer.TYPE.RESTRICT_TITLE, + lazy.UrlbarTokenizer.TYPE.RESTRICT_URL, + lazy.UrlbarTokenizer.TYPE.RESTRICT_ACTION, + ].includes(t.type) + ); // RESTRICT_TITLE and RESTRICT_URL do not affect query sources. let restrictTokenType = @@ -1014,10 +1018,6 @@ function updateSourcesIfEmpty(context) { : undefined; for (let source of Object.values(lazy.UrlbarUtils.RESULT_SOURCE)) { - // Skip sources that the context doesn't care about. - if (context.sources && !context.sources.includes(source)) { - continue; - } // Check prefs and restriction tokens. switch (source) { case lazy.UrlbarUtils.RESULT_SOURCE.BOOKMARKS: