tor-browser

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

commit 74f71b94d23f901d3cd9afd9ce753c408aa817ed
parent 7a0997b419789d73c38ebac7cc681ea9e6e6237c
Author: Mark Banner <standard8@mozilla.com>
Date:   Mon, 20 Oct 2025 13:36:27 +0000

Bug 1993085 - Add initial TypeScript setup for browser/components/places. r=places-reviewers,daisuke

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

Diffstat:
Mbrowser/components/places/InteractionsBlocklist.sys.mjs | 4++--
Mbrowser/components/places/InteractionsChild.sys.mjs | 9+++++++--
Mbrowser/components/places/PlacesBrowserStartup.sys.mjs | 2+-
Mbrowser/components/places/PlacesUIUtils.sys.mjs | 68+++++++++++++++++++++++++++++++++++++-------------------------------
Abrowser/components/places/tsconfig.json | 16++++++++++++++++
5 files changed, 63 insertions(+), 36 deletions(-)

diff --git a/browser/components/places/InteractionsBlocklist.sys.mjs b/browser/components/places/InteractionsBlocklist.sys.mjs @@ -229,7 +229,7 @@ class _InteractionsBlocklist { try { regex = new RegExp(regexToAdd, "i"); } catch (ex) { - this.logConsole.warn("Invalid regex passed to addRegexToBlocklist."); + lazy.logConsole.warn("Invalid regex passed to addRegexToBlocklist."); return; } @@ -256,7 +256,7 @@ class _InteractionsBlocklist { try { regex = new RegExp(regexToRemove, "i"); } catch (ex) { - this.logConsole.warn("Invalid regex passed to addRegexToBlocklist."); + lazy.logConsole.warn("Invalid regex passed to addRegexToBlocklist."); return; } diff --git a/browser/components/places/InteractionsChild.sys.mjs b/browser/components/places/InteractionsChild.sys.mjs @@ -113,11 +113,16 @@ export class InteractionsChild extends JSWindowActorChild { break; } case "pagehide": { - if (!this.docShell.currentDocumentChannel) { + // We generally expect this to be an nsIHttpChannel, if it isn't + // then the if statement below will return early anyway. + let currentDocumentChannel = /** @type {nsIHttpChannel} */ ( + this.docShell.currentDocumentChannel + ); + if (!currentDocumentChannel) { return; } - if (!this.docShell.currentDocumentChannel.requestSucceeded) { + if (!currentDocumentChannel.requestSucceeded) { return; } diff --git a/browser/components/places/PlacesBrowserStartup.sys.mjs b/browser/components/places/PlacesBrowserStartup.sys.mjs @@ -297,7 +297,7 @@ export let PlacesBrowserStartup = { // interval between backups elapsed. if ( !lastBackupFile || - new Date() - lazy.PlacesBackups.getDateForFile(lastBackupFile) > + Date.now() - lazy.PlacesBackups.getDateForFile(lastBackupFile).getTime() > BOOKMARKS_BACKUP_MIN_INTERVAL_DAYS * 86400000 ) { let maxBackups = Services.prefs.getIntPref( diff --git a/browser/components/places/PlacesUIUtils.sys.mjs b/browser/components/places/PlacesUIUtils.sys.mjs @@ -157,7 +157,7 @@ class BookmarkState { /** * Create a new bookmark. * - * @returns {string} The bookmark's GUID. + * @returns {Promise<string>} The bookmark's GUID. */ async _createBookmark() { let transactions = [ @@ -189,7 +189,7 @@ class BookmarkState { /** * Create a new folder. * - * @returns {string} The folder's GUID. + * @returns {Promise<string>} The folder's GUID. */ async _createFolder() { let transactions = [ @@ -226,7 +226,7 @@ class BookmarkState { /** * Save() API function for bookmark. * - * @returns {string} bookmark.guid + * @returns {Promise<string>} bookmark.guid */ async save() { if (this._guid === lazy.PlacesUtils.bookmarks.unsavedGuid) { @@ -366,7 +366,7 @@ export var PlacesUIUtils = { * Obfuscates a place: URL to use it in xulstore without the risk of leaking browsing information. Uses md5 to hash the query string. * - * @param {URL} url + * @param {string} url * the URL for xulstore with place: key pairs. * @returns {string} "place:[md5_hash]" hashed url */ @@ -387,11 +387,11 @@ export var PlacesUIUtils = { * @param {object} aInfo * Describes the item to be edited/added in the dialog. * See documentation at the top of bookmarkProperties.js - * @param {DOMWindow} [aParentWindow] + * @param {Window} [aParentWindow] * Owner window for the new dialog. * * @see documentation at the top of bookmarkProperties.js - * @returns {string} The guid of the item that was created or edited, + * @returns {Promise<string>} The guid of the item that was created or edited, * undefined otherwise. */ async showBookmarkDialog(aInfo, aParentWindow = null) { @@ -425,11 +425,11 @@ export var PlacesUIUtils = { * Bookmarks one or more pages. If there is more than one, this will create * the bookmarks in a new folder. * - * @param {Array.<nsIURI>} URIList + * @param {{uri: nsIURI, title: string}[]} URIList * The list of URIs to bookmark. - * @param {Array.<string>} [hiddenRows] + * @param {string[]} [hiddenRows] * An array of rows to be hidden. - * @param {DOMWindow} [win] + * @param {Window} [win] * The window to use as the parent to display the bookmark dialog. */ async showBookmarkPagesDialog(URIList, hiddenRows = [], win = null) { @@ -498,7 +498,7 @@ export var PlacesUIUtils = { /** * Returns the active PlacesController for a given command. * - * @param {DOMWindow} win The window containing the affected view + * @param {Window} win The window containing the affected view * @param {string} command The command * @returns {PlacesController} a places controller */ @@ -527,7 +527,7 @@ export var PlacesUIUtils = { /** * Update all the Places commands for the given window. * - * @param {DOMWindow} win The window to update. + * @param {Window} win The window to update. */ updateCommands(win) { // Get the controller for one of the places commands. @@ -559,7 +559,7 @@ export var PlacesUIUtils = { /** * Executes the given command on the currently active controller. * - * @param {DOMWindow} win The window containing the affected view + * @param {Window} win The window containing the affected view * @param {string} command The command to execute */ doCommand(win, command) { @@ -624,7 +624,7 @@ export var PlacesUIUtils = { * * @param {string|URL|nsIURI} url The URL of the page to set the charset on. * @param {string} charset character-set value. - * @param {DOMWindow} window The window that the charset is being set from. + * @param {Window} window The window that the charset is being set from. * @returns {Promise} */ async setCharsetForPage(url, charset, window) { @@ -650,11 +650,11 @@ export var PlacesUIUtils = { * * @param {object} aURINode * a URI node - * @param {DOMWindow} aWindow + * @param {Window} aWindow * a window on which a potential error alert is shown on. * @returns {boolean} true if it's safe to open the node in the browser, false otherwise. */ - checkURLSecurity: function PUIU_checkURLSecurity(aURINode, aWindow) { + checkURLSecurity(aURINode, aWindow) { if (lazy.PlacesUtils.nodeIsBookmark(aURINode)) { return true; } @@ -749,7 +749,7 @@ export var PlacesUIUtils = { * {uri: string, isBookmark: boolean} * @param {object} aEvent * The associated event triggering the open. - * @param {DOMWindow} aWindow + * @param {Window} aWindow * The window associated with the event. */ openTabset(aItemsToOpen, aEvent, aWindow) { @@ -1014,7 +1014,8 @@ export var PlacesUIUtils = { * * @param {object} aFetchInfo * a bookmark object returned by Bookmarks.fetch. - * @returns {object} a node-like object suitable for initialising editBookmarkOverlay. + * @returns {Promise<{bookmarkGuid: string, title: string, uri: string, type: nsINavHistoryResultNode.ResultType}>} + * A node-like object suitable for initialising editBookmarkOverlay. * @throws if aFetchInfo is representing a separator. */ async promiseNodeLikeFromFetchInfo(aFetchInfo) { @@ -1060,12 +1061,13 @@ export var PlacesUIUtils = { * to batch mode. If resultNode is not supplied, the function will * pass-through to functionToWrap. * + * @template T * @param {nsINavHistoryResult} resultNode The result node to turn on batching. * @param {number} itemsBeingChanged The count of items being changed. If the * count is lower than a threshold, then * batching won't be set. - * @param {Function} functionToWrap The function to - * @returns {object} forwards the functionToWrap return value. + * @param {() => T} functionToWrap The function to + * @returns {Promise<T>} forwards the functionToWrap return value. */ async batchUpdatesForNode(resultNode, itemsBeingChanged, functionToWrap) { if (!resultNode) { @@ -1089,13 +1091,17 @@ export var PlacesUIUtils = { * Processes a set of transfer items that have been dropped or pasted. * Batching will be applied where necessary. * - * @param {Array} items A list of unwrapped nodes to process. - * @param {object} insertionPoint The requested point for insertion. - * @param {boolean} doCopy Set to true to copy the items, false will move them - * if possible. - * @param {object} view The view that should be used for batching. - * @returns {Array} Returns an empty array when the insertion point is a tag, else - * returns an array of copied or moved guids. + * @param {object[]} items + * A list of unwrapped nodes to process. + * @param {object} insertionPoint + * The requested point for insertion. + * @param {boolean} doCopy + * Set to true to copy the items, false will move them if possible. + * @param {object} view + * The view that should be used for batching. + * @returns {Promise<string[]>} + * Returns an empty array when the insertion point is a tag, else returns + * an array of copied or moved guids. */ async handleTransferItems(items, insertionPoint, doCopy, view) { let transactions; @@ -1371,7 +1377,7 @@ export var PlacesUIUtils = { }, placesContextShowing(event) { - let menupopup = event.target; + let menupopup = /** @type {XULPopupElement} */ (event.target); if ( !["placesContext", "sidebar-history-context-menu"].includes(menupopup.id) ) { @@ -1605,9 +1611,9 @@ export var PlacesUIUtils = { * infallible, if a speculative connection cannot be initialized, it will be a * no-op. * - * @param {nsIURI|URL|string} url entity to initiate + * @param {string} url entity to initiate * a speculative connection for. - * @param {window} window the window from where the connection is initialized. + * @param {Window} window the window from where the connection is initialized. */ setupSpeculativeConnection(url, window) { if ( @@ -1622,7 +1628,7 @@ export var PlacesUIUtils = { return; } try { - let uri = url instanceof Ci.nsIURI ? url : Services.io.newURI(url); + let uri = Services.io.newURI(url); Services.io.speculativeConnect( uri, window.gBrowser.contentPrincipal, @@ -1638,7 +1644,7 @@ export var PlacesUIUtils = { * Sets up a speculative connection to the target of a * clicked places DOM node on left and middle click. * - * @param {event} event the mousedown event. + * @param {MouseEvent} event the mousedown event. */ maybeSpeculativeConnectOnMouseDown(event) { if ( diff --git a/browser/components/places/tsconfig.json b/browser/components/places/tsconfig.json @@ -0,0 +1,16 @@ +{ + "include": ["*.sys.mjs", "types/*.ts"], + "exclude": ["Interactions.sys.mjs", "PlacesUIUtils.sys.mjs"], + "extends": "../../../tools/@types/tsconfig.json", + + "compilerOptions": { + "checkJs": true, + + "plugins": [ + { + "transform": "../../../tools/ts/plugins/checkRootOnly.js", + "transformProgram": true + } + ] + } +}