tor-browser

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

commit fea06a7a7b54addf064310ef129216f276125dd7
parent f5faa7d7a9ac30501553160115a25c381d916f24
Author: Dão Gottwald <dao@mozilla.com>
Date:   Thu,  6 Nov 2025 00:15:03 +0000

Bug 1998111 - Replace isAddressbar with sapName checks. r=mbeier

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

Diffstat:
Mbrowser/base/content/browser.js | 1-
Mbrowser/components/urlbar/ActionsProviderQuickActions.sys.mjs | 4++--
Mbrowser/components/urlbar/ActionsProviderTabGroups.sys.mjs | 4++--
Mbrowser/components/urlbar/SearchModeSwitcher.sys.mjs | 2+-
Mbrowser/components/urlbar/UrlbarInput.sys.mjs | 42++++++++++++++++++++----------------------
Mbrowser/components/urlbar/UrlbarProviderGlobalActions.sys.mjs | 15+++++----------
Mbrowser/components/urlbar/UrlbarProviderInterventions.sys.mjs | 5++---
Mbrowser/components/urlbar/UrlbarProviderSearchSuggestions.sys.mjs | 10++++------
Mbrowser/components/urlbar/UrlbarProviderTabToSearch.sys.mjs | 7+++----
Mbrowser/components/urlbar/UrlbarView.sys.mjs | 2+-
Mbrowser/components/urlbar/tests/UrlbarTestUtils.sys.mjs | 1-
Mbrowser/components/urlbar/tests/unit/head.js | 1-
Mbrowser/components/urlbar/tests/unit/test_quickactions.js | 9++-------
13 files changed, 42 insertions(+), 61 deletions(-)

diff --git a/browser/base/content/browser.js b/browser/base/content/browser.js @@ -370,7 +370,6 @@ ChromeUtils.defineLazyGetter(this, "gNavToolbox", () => { ChromeUtils.defineLazyGetter(this, "gURLBar", () => { let urlbar = new UrlbarInput({ textbox: document.getElementById("urlbar"), - isAddressbar: true, sapName: "urlbar", }); diff --git a/browser/components/urlbar/ActionsProviderQuickActions.sys.mjs b/browser/components/urlbar/ActionsProviderQuickActions.sys.mjs @@ -43,9 +43,9 @@ class ProviderQuickActions extends ActionsProvider { return "ActionsProviderQuickActions"; } - isActive(queryContext, controller) { + isActive(queryContext) { return ( - controller?.input.isAddressbar && + queryContext.sapName == "urlbar" && lazy.UrlbarPrefs.get(ENABLED_PREF) && !queryContext.searchMode && queryContext.trimmedSearchString.length < 50 && diff --git a/browser/components/urlbar/ActionsProviderTabGroups.sys.mjs b/browser/components/urlbar/ActionsProviderTabGroups.sys.mjs @@ -26,9 +26,9 @@ class ProviderTabGroups extends ActionsProvider { return "ActionsProviderTabGroups"; } - isActive(queryContext, controller) { + isActive(queryContext) { return ( - controller?.input.isAddressbar && + queryContext.sapName == "urlbar" && Services.prefs.getBoolPref("browser.tabs.groups.enabled") && (!queryContext.restrictSource || queryContext.restrictSource == lazy.UrlbarUtils.RESULT_SOURCE.TABS) && diff --git a/browser/components/urlbar/SearchModeSwitcher.sys.mjs b/browser/components/urlbar/SearchModeSwitcher.sys.mjs @@ -427,7 +427,7 @@ export class SearchModeSwitcher { * @param {Element} separator */ async #buildLocalSearchModeList(separator) { - if (!this.#input.isAddressbar) { + if (this.#input.sapName != "urlbar") { return; } diff --git a/browser/components/urlbar/UrlbarInput.sys.mjs b/browser/components/urlbar/UrlbarInput.sys.mjs @@ -82,6 +82,7 @@ let px = number => number.toFixed(2) + "px"; export class UrlbarInput { #allowBreakout = false; #breakoutBlockerCount = 0; + #isAddressbar; #sapName; #userTypedValue; @@ -93,20 +94,17 @@ export class UrlbarInput { * @param {string} options.sapName * The search access point name of the UrlbarInput for use with telemetry or * logging, e.g. `urlbar`, `searchbar`. - * @param {boolean} [options.isAddressbar] - * Whether this instance is meant to display the browser's current address, - * as opposed to being just a search input. */ - constructor({ textbox, sapName, isAddressbar = false }) { + constructor({ textbox, sapName }) { this.textbox = textbox; - this.isAddressbar = !!isAddressbar; + this.#isAddressbar = sapName == "urlbar"; this.window = this.textbox.ownerGlobal; this.document = this.window.document; this.isPrivate = lazy.PrivateBrowsingUtils.isWindowPrivate(this.window); this.panel = this.textbox.querySelector(".urlbarView"); this.controller = new lazy.UrlbarController({ input: this, - manager: isAddressbar ? null : lazy.SearchbarProvidersManager, + manager: this.#isAddressbar ? null : lazy.SearchbarProvidersManager, }); this.view = new lazy.UrlbarView(this); this.valueIsTyped = false; @@ -301,7 +299,7 @@ export class UrlbarInput { this.editor.newlineHandling = Ci.nsIEditor.eNewlinesStripSurroundingWhitespace; - if (isAddressbar) { + if (this.#isAddressbar) { let searchContainersPref = lazy.UrlbarPrefs.get( "switchTabs.searchAllContainers" ); @@ -416,7 +414,7 @@ export class UrlbarInput { */ formatValue() { // The editor may not exist if the toolbar is not visible. - if (this.isAddressbar && this.editor) { + if (this.#isAddressbar && this.editor) { this.#lazy.valueFormatter.update(); } } @@ -523,7 +521,7 @@ export class UrlbarInput { hideSearchTerms = false, isSameDocument = false ) { - if (!this.isAddressbar) { + if (!this.#isAddressbar) { throw new Error( "Cannot set URI for UrlbarInput that is not an address bar" ); @@ -1059,7 +1057,7 @@ export class UrlbarInput { this.userTypedValue = null; // Nullify search mode before setURI so it won't try to restore it. this.searchMode = null; - if (this.isAddressbar) { + if (this.#isAddressbar) { this.setURI(null, true, false, true); } else { this.value = ""; @@ -1995,7 +1993,7 @@ export class UrlbarInput { } let mode = - this.isAddressbar && + 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. @@ -2282,13 +2280,13 @@ export class UrlbarInput { } get userTypedValue() { - return this.isAddressbar + return this.#isAddressbar ? this.window.gBrowser.userTypedValue : this.#userTypedValue; } set userTypedValue(val) { - if (this.isAddressbar) { + if (this.#isAddressbar) { this.window.gBrowser.userTypedValue = val; } else { this.#userTypedValue = val; @@ -2521,7 +2519,7 @@ export class UrlbarInput { * The source name. */ getSearchSource(event) { - if (this.isAddressbar) { + if (this.#isAddressbar) { if (this._isHandoffSession) { return "urlbar-handoff"; } @@ -3236,7 +3234,7 @@ export class UrlbarInput { * The trimmed string */ _trimValue(val) { - if (!this.isAddressbar) { + if (!this.#isAddressbar) { return val; } let trimmedValue = lazy.UrlbarPrefs.get("trimURLs") @@ -3446,7 +3444,7 @@ export class UrlbarInput { resultDetails = null, browser ) { - if (!this.isAddressbar) { + if (!this.#isAddressbar) { throw new Error( "Can't prepare addressbar load when this isn't an addressbar input" ); @@ -3546,7 +3544,7 @@ export class UrlbarInput { resultDetails = null, browser = this.window.gBrowser.selectedBrowser ) { - if (this.isAddressbar) { + if (this.#isAddressbar) { this.#prepareAddressbarLoad( url, openUILinkWhere, @@ -3944,7 +3942,7 @@ export class UrlbarInput { * Details of the result that was selected, if any. */ #notifyStartNavigation(result) { - if (this.isAddressbar) { + if (this.#isAddressbar) { Services.obs.notifyObservers({ result }, "urlbar-user-start-navigation"); } } @@ -4193,7 +4191,7 @@ export class UrlbarInput { * without an engine name ("Search or enter address"). */ initPlaceHolder(force = false) { - if (!this.isAddressbar) { + if (!this.#isAddressbar) { return; } @@ -4305,7 +4303,7 @@ export class UrlbarInput { throw new Error("Expected an engineName to be specified"); } - if (this.searchMode || !this.isAddressbar) { + if (this.searchMode || !this.#isAddressbar) { return; } @@ -4327,7 +4325,7 @@ export class UrlbarInput { * The name of the engine or an empty string to use the default placeholder. */ _setPlaceholder(name) { - if (!this.isAddressbar) { + if (!this.#isAddressbar) { return; } @@ -5231,7 +5229,7 @@ export class UrlbarInput { this.controller.setLastQueryContextCache(queryContext); this.controller.engagementEvent.start(event, queryContext); this.handleNavigation({ triggeringPrincipal: principal }); - if (this.isAddressbar) { + if (this.#isAddressbar) { // For safety reasons, in the drop case we don't want to immediately show // the dropped value, instead we want to keep showing the current page // url until an onLocationChange happens. diff --git a/browser/components/urlbar/UrlbarProviderGlobalActions.sys.mjs b/browser/components/urlbar/UrlbarProviderGlobalActions.sys.mjs @@ -57,16 +57,12 @@ export class UrlbarProviderGlobalActions extends UrlbarProvider { return UrlbarUtils.PROVIDER_TYPE.PROFILE; } - #controller; - async isActive(_queryContext, controller) { - let isActive = + async isActive(_queryContext) { + return ( (lazy.UrlbarPrefs.get(SCOTCH_BONNET_PREF) || lazy.UrlbarPrefs.get(ACTIONS_PREF)) && - lazy.UrlbarPrefs.get(QUICK_ACTIONS_PREF); - if (isActive && controller) { - this.#controller = controller; - } - return isActive; + lazy.UrlbarPrefs.get(QUICK_ACTIONS_PREF) + ); } /** @@ -81,7 +77,7 @@ export class UrlbarProviderGlobalActions extends UrlbarProvider { let searchModeEngine = ""; for (let provider of globalActionsProviders) { - if (provider.isActive(queryContext, this.#controller)) { + if (provider.isActive(queryContext)) { for (let action of (await provider.queryActions(queryContext)) || []) { if (action.engine && !searchModeEngine) { searchModeEngine = action.engine; @@ -94,7 +90,6 @@ export class UrlbarProviderGlobalActions extends UrlbarProvider { } } } - this.#controller = null; if (!actionsResults.length) { return; diff --git a/browser/components/urlbar/UrlbarProviderInterventions.sys.mjs b/browser/components/urlbar/UrlbarProviderInterventions.sys.mjs @@ -480,9 +480,8 @@ export class UrlbarProviderInterventions extends UrlbarProvider { * with this provider, to save on resources. * * @param {UrlbarQueryContext} queryContext The query context object - * @param {UrlbarController} controller The current controller. */ - async isActive(queryContext, controller) { + async isActive(queryContext) { if ( !queryContext.searchString || queryContext.searchString.length > UrlbarUtils.MAX_TEXT_LENGTH || @@ -491,7 +490,7 @@ export class UrlbarProviderInterventions extends UrlbarProvider { !Services.policies.isAllowed("urlbarinterventions") || (await this.queryInstance .getProvider(lazy.UrlbarProviderGlobalActions.name) - ?.isActive(queryContext, controller)) + ?.isActive(queryContext)) ) { return false; } diff --git a/browser/components/urlbar/UrlbarProviderSearchSuggestions.sys.mjs b/browser/components/urlbar/UrlbarProviderSearchSuggestions.sys.mjs @@ -84,9 +84,8 @@ export class UrlbarProviderSearchSuggestions extends UrlbarProvider { * with this provider, to save on resources. * * @param {UrlbarQueryContext} queryContext The query context object. - * @param {UrlbarController} controller The current controller. */ - async isActive(queryContext, controller) { + async isActive(queryContext) { // If the sources don't include search or the user used a restriction // character other than search, don't allow any suggestions. if ( @@ -107,7 +106,7 @@ export class UrlbarProviderSearchSuggestions extends UrlbarProvider { return false; } - if (!this._allowSuggestions(queryContext, controller)) { + if (!this._allowSuggestions(queryContext)) { return false; } @@ -148,15 +147,14 @@ export class UrlbarProviderSearchSuggestions extends UrlbarProvider { * history or remote suggestions. * * @param {UrlbarQueryContext} queryContext The query context object. - * @param {UrlbarController} controller The current controller. * @returns {boolean} True if suggestions in general are allowed and false if * not. */ - _allowSuggestions(queryContext, controller) { + _allowSuggestions(queryContext) { if ( // If the user typed a restriction token or token alias, we ignore the // pref to disable suggestions in the Urlbar. - (controller.input.isAddressbar && + (queryContext.sapName == "urlbar" && !lazy.UrlbarPrefs.get("suggest.searches") && !this._isTokenOrRestrictionPresent(queryContext)) || !lazy.UrlbarPrefs.get("browser.search.suggest.enabled") || diff --git a/browser/components/urlbar/UrlbarProviderTabToSearch.sys.mjs b/browser/components/urlbar/UrlbarProviderTabToSearch.sys.mjs @@ -122,9 +122,8 @@ export class UrlbarProviderTabToSearch extends UrlbarProvider { * with this provider, to save on resources. * * @param {UrlbarQueryContext} queryContext The query context object - * @param {UrlbarController} controller The current controller. */ - async isActive(queryContext, controller) { + async isActive(queryContext) { return ( queryContext.searchString && queryContext.tokens.length == 1 && @@ -133,8 +132,8 @@ export class UrlbarProviderTabToSearch extends UrlbarProvider { !( (await this.queryInstance .getProvider(lazy.UrlbarProviderGlobalActions.name) - ?.isActive(queryContext, controller)) && - lazy.ActionsProviderContextualSearch.isActive(queryContext, controller) + ?.isActive(queryContext)) && + lazy.ActionsProviderContextualSearch.isActive(queryContext) ) ); } diff --git a/browser/components/urlbar/UrlbarView.sys.mjs b/browser/components/urlbar/UrlbarView.sys.mjs @@ -113,7 +113,7 @@ export class UrlbarView { } get oneOffSearchButtons() { - if (!this.input.isAddressbar) { + if (this.input.sapName != "urlbar") { return null; } if (!this.#oneOffSearchButtons) { diff --git a/browser/components/urlbar/tests/UrlbarTestUtils.sys.mjs b/browser/components/urlbar/tests/UrlbarTestUtils.sys.mjs @@ -1235,7 +1235,6 @@ export var UrlbarTestUtils = { Object.assign( { input: { - isAddressbar: true, isPrivate: false, onFirstResult() { return false; diff --git a/browser/components/urlbar/tests/unit/head.js b/browser/components/urlbar/tests/unit/head.js @@ -1015,7 +1015,6 @@ async function check_results({ const controller = UrlbarTestUtils.newMockController({ input: { - isAddressbar: true, isPrivate: context.isPrivate, onFirstResult() { return false; diff --git a/browser/components/urlbar/tests/unit/test_quickactions.js b/browser/components/urlbar/tests/unit/test_quickactions.js @@ -90,12 +90,8 @@ add_task(async function minimum_search_string() { UrlbarPrefs.set("quickactions.minimumSearchString", minimumSearchString); for (let i = 1; i < 4; i++) { let context = createContext(searchString.substring(0, i), {}); - let controller = UrlbarTestUtils.newMockController(); let result = await ActionsProviderQuickActions.queryActions(context); - let isActive = await ActionsProviderQuickActions.isActive( - context, - controller - ); + let isActive = await ActionsProviderQuickActions.isActive(context); if (i >= minimumSearchString) { Assert.equal(result[0].key, "newaction", "Matched the new action"); @@ -117,10 +113,9 @@ add_task(async function interventions_disabled() { getProvider: name => UrlbarProvidersManager.getProvider(name), }; let context = createContext("test", { isPrivate: false }); - let controller = UrlbarTestUtils.newMockController(); Assert.ok( - !(await interventionsProvider.isActive(context, controller)), + !(await interventionsProvider.isActive(context)), "Urlbar interventions are disabled when actions are enabled" ); interventionsProvider.queryInstance = null;