commit 1961e713f2117ce4123e0e9199a9e656b029b5b8
parent 9fd8c6518f1e04c95308a0688e510240ac4a8704
Author: Mark Banner <standard8@mozilla.com>
Date: Fri, 17 Oct 2025 11:14:01 +0000
Bug 1957641 - Change TypeScript definitions to use MozBrowser from browser-custom-element.mjs rather than a hand-crafted type. r=zombie,tgiles
Differential Revision: https://phabricator.services.mozilla.com/D247544
Diffstat:
16 files changed, 71 insertions(+), 55 deletions(-)
diff --git a/browser/components/ipprotection/IPProtectionPanel.sys.mjs b/browser/components/ipprotection/IPProtectionPanel.sys.mjs
@@ -223,7 +223,7 @@ export class IPProtectionPanel {
/**
* Creates a panel component in a panelView.
*
- * @param {XULBrowserElement} panelView
+ * @param {MozBrowser} panelView
*/
#createPanel(panelView) {
let { ownerDocument } = panelView;
diff --git a/browser/components/search/BrowserSearchTelemetry.sys.mjs b/browser/components/search/BrowserSearchTelemetry.sys.mjs
@@ -54,7 +54,7 @@ class BrowserSearchTelemetryHandler {
* Determines if we should record a search for this browser instance.
* Private Browsing mode is normally skipped.
*
- * @param {XULBrowserElement} browser
+ * @param {MozBrowser} browser
* The browser where the search was loaded.
* @returns {boolean}
* True if the search should be recorded, false otherwise.
@@ -126,7 +126,7 @@ class BrowserSearchTelemetryHandler {
* Telemetry records only search counts per engine and action origin, but
* nothing pertaining to the search contents themselves.
*
- * @param {XULBrowserElement} browser
+ * @param {MozBrowser} browser
* The browser where the search originated.
* @param {nsISearchEngine} engine
* The engine handling the search.
@@ -275,7 +275,7 @@ class BrowserSearchTelemetryHandler {
/**
* Records an impression of a search access point.
*
- * @param {XULBrowserElement} browser
+ * @param {MozBrowser} browser
* The browser associated with the SAP.
* @param {nsISearchEngine|null} engine
* The engine handling the search, or null if this doesn't apply to the SAP
@@ -304,7 +304,7 @@ class BrowserSearchTelemetryHandler {
* This function handles the "urlbar", "urlbar-oneoff", "searchbar" and
* "searchbar-oneoff" sources.
*
- * @param {XULBrowserElement} browser
+ * @param {MozBrowser} browser
* The browser where the search originated.
* @param {nsISearchEngine} engine
* The engine handling the search.
diff --git a/browser/components/search/OpenSearchManager.sys.mjs b/browser/components/search/OpenSearchManager.sys.mjs
@@ -23,12 +23,12 @@ class _OpenSearchManager {
*/
/**
- * @type {WeakMap<XULBrowserElement, OpenSearchData[]>}
+ * @type {WeakMap<MozBrowser, OpenSearchData[]>}
*/
#offeredEngines = new WeakMap();
/**
- * @type {WeakMap<XULBrowserElement, OpenSearchData[]>}
+ * @type {WeakMap<MozBrowser, OpenSearchData[]>}
*/
#hiddenEngines = new WeakMap();
@@ -72,7 +72,7 @@ class _OpenSearchManager {
* If an engine with that name is already installed, adds it to the list
* of hidden engines instead.
*
- * @param {XULBrowserElement} browser
+ * @param {MozBrowser} browser
* The browser offering the engine.
* @param {{title: string, href: string}} engine
* The title of the engine and the url to the opensearch XML.
@@ -103,7 +103,6 @@ class _OpenSearchManager {
uri: engine.href,
title: engine.title,
get icon() {
- // @ts-expect-error - Bug 1957641
return browser.mIconURL;
},
});
@@ -197,7 +196,7 @@ class _OpenSearchManager {
/**
* Get the open search engines offered by a certain browser.
*
- * @param {XULBrowserElement} browser
+ * @param {MozBrowser} browser
* The browser for which to get the engines.
* @returns {OpenSearchData[]}
* The open search engines.
diff --git a/browser/components/search/SearchSERPTelemetry.sys.mjs b/browser/components/search/SearchSERPTelemetry.sys.mjs
@@ -278,7 +278,7 @@ class TelemetryHandler {
* Sets the source of a SERP visit from something that occured in content
* rather than from the browser.
*
- * @param {browser} browser
+ * @param {MozBrowser} browser
* The browser object associated with the page that should be a SERP.
* @param {string} source
* The source that started the load. One of
@@ -394,7 +394,7 @@ class TelemetryHandler {
* Records the search source for particular browsers, in case it needs
* to be associated with a SERP.
*
- * @param {browser} browser
+ * @param {MozBrowser} browser
* The browser where the search originated.
* @param {string} source
* Where the search originated from.
@@ -407,7 +407,7 @@ class TelemetryHandler {
* Records the newtab source for particular browsers, in case it needs
* to be associated with a SERP.
*
- * @param {browser} browser
+ * @param {MozBrowser} browser
* The browser where the search originated.
* @param {string} newtabSessionId
* The sessionId of the newtab session the search originated from.
@@ -669,7 +669,7 @@ class TelemetryHandler {
* 3. Untrack the browser if we're tracking it and switching pages.
* 4. Track the browser if we're now on a default search page.
*
- * @param {BrowserElement} browser
+ * @param {MozBrowser} browser
* The browser element related to the request.
* @param {string} url
* The url of the request.
@@ -1321,7 +1321,7 @@ class TelemetryHandler {
* caches information that shouldn't be changed during the lifetime of the
* impression.
*
- * @param {browser} browser
+ * @param {MozBrowser} browser
* The browser associated with the SERP.
* @param {string} url
* The URL of the SERP.
@@ -1630,11 +1630,10 @@ class ContentHandler {
(wrappedChannel.channel.loadInfo.isTopLevelLoad ||
info.nonAdsLinkRegexps.some(r => r.test(url)))
) {
- let browser = wrappedChannel.browserElement;
+ let browser = /** @type {MozBrowser} */ (wrappedChannel.browserElement);
// If the load is from history, don't record an event.
if (
- // @ts-expect-error - Bug 1957632
browser?.browsingContext.webProgress?.loadType &
Ci.nsIDocShell.LOAD_CMD_HISTORY
) {
@@ -1669,7 +1668,6 @@ class ContentHandler {
// If the count is more than 1, then multiple open SERPs contain the
// same search term, so try to find the specific browser that opened
// the request.
- // @ts-expect-error - Bug 1957632
let tabBrowser = browser.getTabBrowser();
let tab = tabBrowser.getTabForBrowser(browser).openerTab;
// A tab will not always have an openerTab, as first tabs in new
@@ -1828,10 +1826,8 @@ class ContentHandler {
// The sponsored link could be opened in a new tab, in which case the
// browser URI may not match a SERP. Thus, try to find a tab that contains
// a URI matching a SERP.
- let browser = wrappedChannel.browserElement;
- // @ts-expect-error - Bug 1957632
+ let browser = /** @type {MozBrowser} */ (wrappedChannel.browserElement);
if (browser?.currentURI.spec == "about:blank") {
- // @ts-expect-error - Bug 1957632
let tabBrowser = browser.getTabBrowser();
let tab = tabBrowser.getTabForBrowser(browser).openerTab;
if (tab) {
@@ -1853,7 +1849,6 @@ class ContentHandler {
return null;
}
- // @ts-expect-error - Bug 1957632
return browser?.currentURI.spec;
}
diff --git a/browser/components/search/types/mozTabbrowserTab.d.ts b/browser/components/search/types/mozTabbrowserTab.d.ts
@@ -1,6 +1,5 @@
// Just for the purpose of accessing the browser object, we define the tab.
// This should be removed once the tab is defined globally.
declare class MozTabbrowserTab {
- // Bug 1957641
- linkedBrowser: XULBrowserElement;
+ linkedBrowser: MozBrowser;
}
diff --git a/browser/components/search/types/searchbar.d.ts b/browser/components/search/types/searchbar.d.ts
@@ -1,10 +1,5 @@
-// There's a number of properties added by MozXULElement but for our purposes we
-// don't need them. We do this merely to accurately describe what MozSearchbar
-// extends.
-declare class MozXULElement extends XULElement {}
-
// Largely just here to fix SearchUIUtils errors. This should be removed once
// searchbar becomes a exportable module.
-declare class MozSearchbar extends MozXULElement {
+interface MozSearchbar extends MozXULElement {
select(): void;
}
diff --git a/browser/components/urlbar/UrlbarInput.sys.mjs b/browser/components/urlbar/UrlbarInput.sys.mjs
@@ -3176,7 +3176,7 @@ export class UrlbarInput {
* True if this query was initiated from a form history result.
* @param {string} [searchActionDetails.url]
* The url this query was triggered with.
- * @param {XULBrowserElement} [browser]
+ * @param {MozBrowser} [browser]
* The browser where the search is being opened.
* Defaults to the window's selected browser.
*/
diff --git a/toolkit/components/extensions/ExtensionParent.sys.mjs b/toolkit/components/extensions/ExtensionParent.sys.mjs
@@ -469,7 +469,7 @@ GlobalManager = {
extensionMap: new Map(),
initialized: false,
- /** @type {WeakMap<XULBrowserElement, object>} Extension Context init data. */
+ /** @type {WeakMap<MozBrowser, object>} Extension Context init data. */
frameData: new WeakMap(),
init(extension) {
@@ -1460,7 +1460,7 @@ class HiddenXULWindow {
* An object that contains the xul attributes to set of the newly
* created browser XUL element.
*
- * @returns {Promise<XULBrowserElement>}
+ * @returns {Promise<MozBrowser>}
* A Promise which resolves to the newly created browser XUL element.
*/
async createBrowserElement(xulAttributes) {
@@ -1633,9 +1633,9 @@ const DebugUtils = {
// which are used to connect the webextension patent actor to the extension process.
hiddenXULWindow: null,
- /** @type {Map<string, Promise<XULBrowserElement> & { browser: XULBrowserElement }>} */
+ /** @type {Map<string, Promise<MozBrowser> & { browser: MozBrowser }>} */
debugBrowserPromises: new Map(),
- /** @type {WeakMap<Promise<XULBrowserElement>, Set<WebExtensionDescriptorActor>>} */
+ /** @type {WeakMap<Promise<MozBrowser>, Set<WebExtensionDescriptorActor>>} */
debugActors: new DefaultWeakMap(() => new Set()),
_extensionUpdatedWatcher: null,
@@ -1787,7 +1787,7 @@ const DebugUtils = {
* @param {WebExtensionDescriptorActor} webExtensionParentActor
* The devtools actor that is retrieving the browser element.
*
- * @returns {Promise<XULBrowserElement>}
+ * @returns {Promise<MozBrowser>}
* A promise which resolves to the configured browser XUL element.
*/
async getExtensionProcessBrowser(webExtensionParentActor) {
@@ -1914,7 +1914,7 @@ function promiseMessageFromChild(messageManager, messageName, abortSignal) {
* Returns a Promise which rejects if the load in the browser is aborted.
* Accepts an AbortSignal to allow early unregistration of the listeners.
*
- * @param {XULBrowserElement} browser
+ * @param {MozBrowser} browser
* @param {AbortSignal} abortSignal
* @returns {Promise<void>} A promise that never resolves, but only rejects.
*/
diff --git a/toolkit/components/extensions/ExtensionPermissions.sys.mjs b/toolkit/components/extensions/ExtensionPermissions.sys.mjs
@@ -606,7 +606,7 @@ export var ExtensionPermissions = {
export var OriginControls = {
/**
* @typedef {object} NativeTab
- * @property {XULBrowserElement} linkedBrowser
+ * @property {MozBrowser} linkedBrowser
*/
/**
diff --git a/toolkit/components/extensions/WebNavigation.sys.mjs b/toolkit/components/extensions/WebNavigation.sys.mjs
@@ -26,7 +26,7 @@ export var WebNavigationManager = {
/** @type {Map<string, Set<callback>>} */
listeners: new Map(),
- /** @type {WeakMap<XULBrowserElement, object>} */
+ /** @type {WeakMap<MozBrowser, object>} */
recentTabTransitionData: new WeakMap(),
init() {
@@ -231,7 +231,7 @@ export var WebNavigationManager = {
* collected when one of the `onCommitted`, `onHistoryStateUpdated`
* or `onReferenceFragmentUpdated` events has been received.
*
- * @param {XULBrowserElement} browser
+ * @param {MozBrowser} browser
* @returns {object}
*/
getAndForgetRecentTabTransitionData(browser) {
diff --git a/toolkit/components/extensions/types/ext-tabs-base.d.ts b/toolkit/components/extensions/types/ext-tabs-base.d.ts
@@ -193,7 +193,7 @@ declare class TabBase {
* @readonly
* @abstract
*/
- readonly get browser(): XULBrowserElement;
+ readonly get browser(): MozBrowser;
/**
* @property {BrowsingContext} browsingContext
* Returns the BrowsingContext for the given tab.
diff --git a/toolkit/content/widgets/browser-custom-element.mjs b/toolkit/content/widgets/browser-custom-element.mjs
@@ -2,6 +2,10 @@
* 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/. */
+// TODO: Bug 1994968 - Fix most TypeScript issues in this file. Currently there
+// are lots of errors that may show up in an editor due to our TypeScript
+// configuration. Skip this for now, until these are resolved.
+
const { AppConstants } = ChromeUtils.importESModule(
"resource://gre/modules/AppConstants.sys.mjs"
);
@@ -86,7 +90,7 @@ window.addEventListener(
/**
* @implements {nsIBrowser}
*/
-class MozBrowser extends MozElements.MozElementMixin(XULFrameElement) {
+export class MozBrowser extends MozElements.MozElementMixin(XULFrameElement) {
static get observedAttributes() {
return ["remote"];
}
@@ -264,6 +268,14 @@ class MozBrowser extends MozElements.MozElementMixin(XULFrameElement) {
});
}
+ /**
+ * The browser's permanent key. This was added temporarily for Session Store,
+ * and will be removed in bug 1716788.
+ *
+ * @type {any}
+ */
+ permanentKey;
+
resetFields() {
if (this.observer) {
try {
diff --git a/toolkit/modules/HiddenFrame.sys.mjs b/toolkit/modules/HiddenFrame.sys.mjs
@@ -184,7 +184,7 @@ export const HiddenBrowserManager = new (class HiddenBrowserManager {
/**
* Releases the given hidden browser.
*
- * @param {XULBrowserElement} browser
+ * @param {MozBrowser} browser
* The hidden browser element.
*/
#releaseBrowser(browser) {
@@ -202,7 +202,7 @@ export const HiddenBrowserManager = new (class HiddenBrowserManager {
* This function will return whatever the callback function returns.
*
* @template T
- * @param {(XULBrowserElement) => T | Promise<T>} callback
+ * @param {(MozBrowser) => T | Promise<T>} callback
* The callback function will be called with the browser element and may
* be asynchronous.
* @returns {Promise<T>}
diff --git a/tools/@types/index.d.ts b/tools/@types/index.d.ts
@@ -21,6 +21,8 @@
/// Order of references matters here, for overriding type signatures.
/// <reference types="./lib.gecko.tweaks.d.ts" />
+import type {} from "./lib.gecko.augmentations.d.ts";
+
declare global {
const Cc: nsXPCComponents_Classes;
const Ci: nsIXPCComponents_Interfaces;
diff --git a/tools/@types/lib.gecko.augmentations.d.ts b/tools/@types/lib.gecko.augmentations.d.ts
@@ -0,0 +1,23 @@
+/**
+ * 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/.
+ */
+export {};
+
+interface MozElementBase {
+ new (...any): any;
+ implementCustomInterface(MozBrowser, interfaces: nsIID[]);
+}
+
+declare global {
+ const MozElements: Readonly<{
+ MozElementMixin<T extends MozElementBase>(base: T): T;
+ }>;
+
+ interface MozXULElement extends MozElementBase, XULElement {}
+ interface MozHTMLElement extends MozElementBase, HTMLElement {}
+
+ type MozBrowser =
+ import("../../toolkit/content/widgets/browser-custom-element.mjs").MozBrowser;
+}
diff --git a/tools/@types/lib.gecko.tweaks.d.ts b/tools/@types/lib.gecko.tweaks.d.ts
@@ -4,7 +4,7 @@
// More specific types for parent process browsing contexts.
interface CanonicalBrowsingContext extends LoadContextMixin {
- embedderElement: XULBrowserElement;
+ embedderElement: MozBrowser;
currentWindowContext: WindowGlobalParent;
parent: CanonicalBrowsingContext;
parentWindowContext: WindowGlobalParent;
@@ -26,7 +26,7 @@ interface ChromeWindow extends Window {
}
interface Document {
- createXULElement(name: "browser"): XULBrowserElement;
+ createXULElement(name: "browser"): MozBrowser;
}
type nsIGleanPingNoReason = {
@@ -128,15 +128,6 @@ interface WindowGlobalParent extends WindowContext {
readonly browsingContext: CanonicalBrowsingContext;
}
-// Hand-crafted artisanal types.
-interface XULBrowserElement extends XULFrameElement, FrameLoader {
- currentURI: nsIURI;
- documentURI: nsIURI | null;
- docShellIsActive: boolean;
- isRemoteBrowser: boolean;
- remoteType: string;
-}
-
// https://github.com/microsoft/TypeScript-DOM-lib-generator/issues/1736
interface Localization {
formatValuesSync(aKeys: L10nKey[]): (string | null)[];