tor-browser

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

commit 69c1bd3d1d7dc0d5a6f6b5332236dfce0befb24a
parent daf148ec563a49493127fec14a457b71deb706fc
Author: Mark Banner <standard8@mozilla.com>
Date:   Mon, 13 Oct 2025 13:14:28 +0000

Bug 1992354 - Cleanup some TypeScript issues in UrlbarInput. r=urlbar-reviewers,jteow

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

Diffstat:
Mbrowser/components/urlbar/UrlbarInput.sys.mjs | 123++++++++++++++++++++++++++++++++++++++++++-------------------------------------
Mbrowser/components/urlbar/UrlbarUtils.sys.mjs | 12++----------
Mbrowser/components/urlbar/UrlbarView.sys.mjs | 2+-
3 files changed, 68 insertions(+), 69 deletions(-)

diff --git a/browser/components/urlbar/UrlbarInput.sys.mjs b/browser/components/urlbar/UrlbarInput.sys.mjs @@ -6,9 +6,11 @@ import { XPCOMUtils } from "resource://gre/modules/XPCOMUtils.sys.mjs"; import { AppConstants } from "resource://gre/modules/AppConstants.sys.mjs"; -const lazy = {}; +/** + * @import {UrlbarSearchOneOffs} from "moz-src:///browser/components/urlbar/UrlbarSearchOneOffs.sys.mjs" + */ -ChromeUtils.defineESModuleGetters(lazy, { +const lazy = XPCOMUtils.declareLazy({ ASRouter: "resource:///modules/asrouter/ASRouter.sys.mjs", BrowserSearchTelemetry: "moz-src:///browser/components/search/BrowserSearchTelemetry.sys.mjs", @@ -50,33 +52,21 @@ ChromeUtils.defineESModuleGetters(lazy, { UrlbarView: "moz-src:///browser/components/urlbar/UrlbarView.sys.mjs", UrlbarSearchTermsPersistence: "moz-src:///browser/components/urlbar/UrlbarSearchTermsPersistence.sys.mjs", + ClipboardHelper: { + service: "@mozilla.org/widget/clipboardhelper;1", + iid: Ci.nsIClipboardHelper, + }, + QueryStringStripper: { + service: "@mozilla.org/url-query-string-stripper;1", + iid: Ci.nsIURLQueryStringStripper, + }, + QUERY_STRIPPING_STRIP_ON_SHARE: { + pref: "privacy.query_stripping.strip_on_share.enabled", + default: false, + }, + logger: () => lazy.UrlbarUtils.getLogger({ prefix: "Input" }), }); -XPCOMUtils.defineLazyServiceGetter( - lazy, - "ClipboardHelper", - "@mozilla.org/widget/clipboardhelper;1", - "nsIClipboardHelper" -); - -XPCOMUtils.defineLazyServiceGetter( - lazy, - "QueryStringStripper", - "@mozilla.org/url-query-string-stripper;1", - "nsIURLQueryStringStripper" -); - -XPCOMUtils.defineLazyPreferenceGetter( - lazy, - "QUERY_STRIPPING_STRIP_ON_SHARE", - "privacy.query_stripping.strip_on_share.enabled", - false -); - -ChromeUtils.defineLazyGetter(lazy, "logger", () => - lazy.UrlbarUtils.getLogger({ prefix: "Input" }) -); - const DEFAULT_FORM_HISTORY_NAME = "searchbar-history"; const UNLIMITED_MAX_RESULTS = 99; @@ -783,7 +773,7 @@ export class UrlbarInput { * @param {Event} [event] The event triggering the open. */ handleCommand(event = null) { - let isMouseEvent = this.window.MouseEvent.isInstance(event); + let isMouseEvent = MouseEvent.isInstance(event); if (isMouseEvent && event.button == 2) { // Do nothing for right clicks. return; @@ -1092,7 +1082,7 @@ export class UrlbarInput { * @param {nsISearchEngine} [searchEngine] * Optional. If included and the right prefs are set, we will enter search * mode when handing `searchString` from the fake input to the Urlbar. - * @param {string} newtabSessionId + * @param {string} [newtabSessionId] * Optional. The id of the newtab session that handed off this search. */ handoff(searchString, searchEngine, newtabSessionId) { @@ -2442,8 +2432,9 @@ export class UrlbarInput { * * @param {object} options * Options object. - * @param {string} options.entry - * The search mode entry point. See setSearchMode documentation for details. + * @param {string} [options.entry] + * If provided, this will be recorded as the entry point into search mode. + * See setSearchMode documentation for details. * @param {UrlbarResult} [options.result] * The result to confirm. Defaults to the currently selected result. * @param {boolean} [options.checkValue] @@ -2802,7 +2793,7 @@ export class UrlbarInput { * @param {string} [options.urlOverride] * For results normally returning a url string, this allows to override * it. A blank string may passed-in to clear the input. - * @param {Element} [options.element] + * @param {HTMLElement} [options.element] * The element that was selected or picked, if available. For results that * have multiple selectable children, the value may be taken from a child * element rather than the result. @@ -2848,13 +2839,13 @@ export class UrlbarInput { return url ? losslessDecodeURI(url.URI) : ""; } - let url = URL.parse(result.payload.url); + let parsedUrl = URL.parse(result.payload.url); // If the url is not parsable, just return an empty string; - if (!url) { + if (!parsedUrl) { return ""; } - url = losslessDecodeURI(url.URI); + let url = losslessDecodeURI(parsedUrl.URI); // If the user didn't originally type a protocol, and we generated one, // trim the http protocol from the input value, as https-first may upgrade // it to https, breaking user expectations. @@ -3256,8 +3247,10 @@ export class UrlbarInput { /** * Returns whether the passed-in event may represents a canonization request. * - * @param {DOMEvent} event a KeyboardEvent to examine. - * @returns {boolean} Whether the event is a canonization one. + * @param {Event} event + * An Event to examine. + * @returns {boolean} + * Whether the event is a KeyboardEvent that triggers canonization. */ #isCanonizeKeyboardEvent(event) { return ( @@ -3341,7 +3334,7 @@ export class UrlbarInput { * @param {string} options.adaptiveHistoryInput * If the autofill type is "adaptive", this is the matching `input` value * from adaptive history. - * @param {string} options.untrimmedValue + * @param {string} [options.untrimmedValue] * Untrimmed value including a protocol. */ _autofillValue({ @@ -3431,7 +3424,7 @@ export class UrlbarInput { * @param {object} params * The parameters related to how and where the result will be opened. * Further supported paramters are listed in _loadURL. - * @param {object} params.triggeringPrincipal + * @param {object} [params.triggeringPrincipal] * The principal that the action was triggered from. * @param {object} [resultDetails] * Details of the selected result, if any. @@ -3520,22 +3513,22 @@ export class UrlbarInput { * Where we expect the result to be opened. * @param {object} params * The parameters related to how and where the result will be opened. - * Further supported paramters are listed in utilityOverlay.js#openUILinkIn. - * @param {object} params.triggeringPrincipal + * Further supported parameters are listed in utilityOverlay.js#openUILinkIn. + * @param {object} [params.triggeringPrincipal] * The principal that the action was triggered from. * @param {nsIInputStream} [params.postData] * The POST data associated with a search submission. * @param {boolean} [params.allowInheritPrincipal] * Whether the principal can be inherited. - * @param {SchemelessInputType} [params.schemelessInput] + * @param {nsILoadInfo.SchemelessInputType} [params.schemelessInput] * Whether the search/URL term was without an explicit scheme. * @param {object} [resultDetails] * Details of the selected result, if any. - * @param {UrlbarUtils.RESULT_TYPE} [resultDetails.type] + * @param {Values<typeof lazy.UrlbarUtils.RESULT_TYPE>} [resultDetails.type] * Details of the result type, if any. * @param {string} [resultDetails.searchTerm] * Search term of the result source, if any. - * @param {UrlbarUtils.RESULT_SOURCE} [resultDetails.source] + * @param {Values<typeof lazy.UrlbarUtils.RESULT_SOURCE>} [resultDetails.source] * Details of the result source, if any. * @param {object} browser [optional] the browser to use for the load. */ @@ -3674,7 +3667,7 @@ export class UrlbarInput { * * @param {string} menuItemCommand * The command to search for. - * @returns {string} + * @returns {HTMLElement} * Html element that matches the command or * the last element if we could not find the command. */ @@ -4913,10 +4906,14 @@ export class UrlbarInput { /** * Generate a UrlbarQueryContext from the current context. * - * @param {object} [options] Optional params - * @param {boolean} options.allowAutofill Whether autofill is enabled. - * @param {string} options.searchString The string being searched. - * @param {object} options.event The event triggering the query. + * @param {object} [options] + * Optional params + * @param {boolean} [options.allowAutofill] + * Whether autofill is enabled. + * @param {string} [options.searchString] + * The string being searched. + * @param {object} [options.event] + * The event triggering the query. * @returns {UrlbarQueryContext} * The queryContext object. */ @@ -5194,12 +5191,22 @@ export class UrlbarInput { event.stopPropagation(); } + /** + * Handles dragover events for the input. + * + * @param {DragEvent} event + */ _on_dragover(event) { if (!getDroppableData(event)) { event.dataTransfer.dropEffect = "none"; } } + /** + * Handles dropping of data on the input. + * + * @param {DragEvent} event + */ _on_drop(event) { let droppedItem = getDroppableData(event); let droppedURL = URL.isInstance(droppedItem) @@ -5288,13 +5295,13 @@ export class UrlbarInput { } /** - * @param {string} value A untrimmed address bar input. - * @returns {SchemelessInputType} - * Returns `Ci.nsILoadInfo.SchemelessInputTypeSchemeless` if the - * input doesn't start with a scheme relevant for - * schemeless HTTPS-First (http://, https:// and file://). - * Returns `Ci.nsILoadInfo.SchemelessInputTypeSchemeful` if it does - * have a scheme. + * @param {string} value + * A untrimmed address bar input. + * @returns {nsILoadInfo.SchemelessInputType} + * Returns `Ci.nsILoadInfo.SchemelessInputTypeSchemeless` if the input + * doesn't start with a scheme relevant for schemeless HTTPS-First + * (http://, https:// and file://). + * Returns `Ci.nsILoadInfo.SchemelessInputTypeSchemeful` if it does have a scheme. */ #getSchemelessInput(value) { return ["http://", "https://", "file://"].every( @@ -5345,7 +5352,7 @@ export class UrlbarInput { /** * Check whether a key event has a similar effect as the Home key. * - * @param {nsIEvent} event A Keyboard event + * @param {KeyboardEvent} event A Keyboard event * @returns {boolean} Whether the even will act like the Home key. */ #isHomeKeyUpEvent(event) { @@ -5378,7 +5385,7 @@ export class UrlbarInput { /** * Tries to extract droppable data from a DND event. * - * @param {Event} event The DND event to examine. + * @param {DragEvent} event The DND event to examine. * @returns {URL|string|null} * null if there's a security reason for which we should do nothing. * A URL object if it's a value we can load. diff --git a/browser/components/urlbar/UrlbarUtils.sys.mjs b/browser/components/urlbar/UrlbarUtils.sys.mjs @@ -96,7 +96,7 @@ export var UrlbarUtils = { }), // Defines UrlbarResult types. - RESULT_TYPE: { + RESULT_TYPE: Object.freeze({ // An open tab. TAB_SWITCH: 1, // A search suggestion or engine. @@ -119,7 +119,7 @@ export var UrlbarUtils = { // When you add a new type, also add its schema to // UrlbarUtils.RESULT_PAYLOAD_SCHEMA below. Also consider checking if // consumers of "urlbar-user-start-navigation" need updating. - }, + }), // This defines the source of results returned by a provider. Each provider // can return results from more than one source. This is used by the @@ -701,14 +701,6 @@ export var UrlbarUtils = { } switch (result.type) { - case this.RESULT_TYPE.URL: - case this.RESULT_TYPE.BOOKMARKS: - case this.RESULT_TYPE.REMOTE_TAB: - case this.RESULT_TYPE.TAB_SWITCH: - case this.RESULT_TYPE.KEYWORD: - case this.RESULT_TYPE.SEARCH: - case this.RESULT_TYPE.OMNIBOX: - return 1; case this.RESULT_TYPE.TIP: return 3; } diff --git a/browser/components/urlbar/UrlbarView.sys.mjs b/browser/components/urlbar/UrlbarView.sys.mjs @@ -205,7 +205,7 @@ export class UrlbarView { } /** - * @returns {Element} + * @returns {HTMLElement} * The currently selected element. */ get selectedElement() {