summaryrefslogtreecommitdiffstats
path: root/toolkit/components/extensions/types/gecko.ts
diff options
context:
space:
mode:
Diffstat (limited to 'toolkit/components/extensions/types/gecko.ts')
-rw-r--r--toolkit/components/extensions/types/gecko.ts231
1 files changed, 81 insertions, 150 deletions
diff --git a/toolkit/components/extensions/types/gecko.ts b/toolkit/components/extensions/types/gecko.ts
index f6b5190f8d..720919d794 100644
--- a/toolkit/components/extensions/types/gecko.ts
+++ b/toolkit/components/extensions/types/gecko.ts
@@ -1,163 +1,94 @@
/**
- * Global Gecko type declarations.
+ * Gecko generic/specialized adjustments for xpcom and webidl types.
*/
-// @ts-ignore
-import type { CiClass } from "lib.gecko.xpidl"
-
-declare global {
- // Other misc types.
- type Browser = InstanceType<typeof XULBrowserElement>;
- type bytestring = string;
- type callback = (...args: any[]) => any;
- type ColorArray = number[];
- type integer = number;
- type JSONValue = null | boolean | number | string | JSONValue[] | { [key: string]: JSONValue };
-
- interface Document {
- createXULElement(name: string): Element;
- documentReadyForIdle: Promise<void>;
- }
- interface EventTarget {
- ownerGlobal: Window;
- }
- interface Error {
- code;
- }
- interface ErrorConstructor {
- new (message?: string, options?: ErrorOptions, lineNo?: number): Error;
- }
- interface Window {
- gBrowser;
- }
- // HACK to get the static isInstance for DOMException and Window?
- interface Object {
- isInstance(object: any): boolean;
- }
+// More specific types for parent process browsing contexts.
+interface CanonicalBrowsingContext extends LoadContextMixin {
+ embedderElement: XULBrowserElement;
+ currentWindowContext: WindowGlobalParent;
+ parent: CanonicalBrowsingContext;
+ parentWindowContext: WindowGlobalParent;
+ top: CanonicalBrowsingContext;
+ topWindowContext: WindowGlobalParent;
+}
- // XPIDL additions/overrides.
+interface ChromeWindow extends Window {
+ isChromeWindow: true;
+}
- interface nsISupports {
- // OMG it works!
- QueryInterface?<T extends CiClass<nsISupports>>(aCiClass: T): T['prototype'];
- wrappedJSObject?: object;
- }
- interface nsIProperties {
- get<T extends CiClass<nsISupports>>(prop: string, aCiClass: T): T['prototype'];
- }
- interface nsIPrefBranch {
- getComplexValue<T extends CiClass<nsISupports>>(aPrefName: string, aCiClass: T): T['prototype'];
- }
- // TODO: incorporate above into lib.xpidl.d.ts generation, somehow?
+interface Document {
+ createXULElement(name: "browser"): XULBrowserElement;
+}
- type Sandbox = typeof globalThis;
- interface nsIXPCComponents_utils_Sandbox {
- (principal: nsIPrincipal | nsIPrincipal[], options: object): Sandbox;
- }
- interface nsIXPCComponents_Utils {
- cloneInto<T>(obj: T, ...args: any[]): T;
- createObjectIn<T>(Sandbox, options?: T): T;
- exportFunction<T extends callback>(f: T, ...args: any[]): T;
- getWeakReference<T extends object>(T): { get(): T };
- readonly Sandbox: nsIXPCComponents_utils_Sandbox;
- waiveXrays<T>(obj: T): T;
- }
- interface nsIDOMWindow extends Window {
- docShell: nsIDocShell;
- }
- interface Document {
- documentURIObject: nsIURI;
- createXULElement(name: string): Element;
- }
+interface MessageListenerManagerMixin {
+ // Overloads that define `data` arg as required, since it's ~always expected.
+ addMessageListener(msg: string, listener: { receiveMessage(_: ReceiveMessageArgument & { data })});
+ removeMessageListener(msg: string, listener: { receiveMessage(_: ReceiveMessageArgument & { data })});
+}
+
+interface MozQueryInterface {
+ <T>(iid: T): nsQIResult<T>;
+}
- // nsDocShell is the only thing implementing nsIDocShell, but it also
- // implements nsIWebNavigation, and a few others, so this is "ok".
- interface nsIDocShell extends nsIWebNavigation {}
- interface nsISimpleEnumerator extends Iterable<any> {}
+interface nsICryptoHash extends nsISupports {
+ // Accepts a TypedArray.
+ update(aData: ArrayLike<number>, aLen: number): void;
+}
- namespace Components {
- type Exception = Error;
- }
- namespace UrlbarUtils {
- type RESULT_TYPE = any;
- type RESULT_SOURCE = any;
+interface nsIDOMWindow extends Window {}
+
+interface nsISimpleEnumerator extends Iterable<any> {}
+
+interface nsISupports {
+ wrappedJSObject?: object;
+}
+
+interface nsIXPCComponents_Constructor {
+ <const T, IIDs = nsIXPCComponents_Interfaces>(cid, id: T, init?): {
+ new (...any): nsQIResult<T extends keyof IIDs ? IIDs[T] : T>;
+ (...any): nsQIResult<T extends keyof IIDs ? IIDs[T] : T>;
}
+}
+
+interface nsIXPCComponents_Exception {
+ (...args: ConstructorParameters<typeof Error>): Error;
+}
+
+interface nsIXPCComponents_utils_Sandbox {
+ (principal: nsIPrincipal | nsIPrincipal[], options: object): typeof globalThis;
+}
- // Various mozilla globals.
- var Cc, Cr, ChromeUtils, Components, dump, uneval;
-
- // [ChromeOnly] WebIDL, to be generated.
- var BrowsingContext, ChannelWrapper, ChromeWindow, ChromeWorker,
- ClonedErrorHolder, Glean, InspectorUtils, IOUtils, JSProcessActorChild,
- JSProcessActorParent, JSWindowActor, JSWindowActorChild,
- JSWindowActorParent, L10nRegistry, L10nFileSource, Localization,
- MatchGlob, MatchPattern, MatchPatternSet, PathUtils, PreloadedScript,
- StructuredCloneHolder, TelemetryStopwatch, WindowGlobalChild,
- WebExtensionContentScript, WebExtensionParentActor, WebExtensionPolicy,
- XULBrowserElement, nsIMessageListenerManager;
-
- interface XULElement extends Element {}
-
- // nsIServices is not a thing.
- interface nsIServices {
- scriptloader: mozIJSSubScriptLoader;
- locale: mozILocaleService;
- intl: mozIMozIntl;
- storage: mozIStorageService;
- appShell: nsIAppShellService;
- startup: nsIAppStartup;
- blocklist: nsIBlocklistService;
- cache2: nsICacheStorageService;
- catMan: nsICategoryManager;
- clearData: nsIClearDataService;
- clipboard: nsIClipboard;
- console: nsIConsoleService;
- cookieBanners: nsICookieBannerService;
- cookies: nsICookieManager & nsICookieService;
- appinfo: nsICrashReporter & nsIXULAppInfo & nsIXULRuntime;
- DAPTelemetry: nsIDAPTelemetry;
- DOMRequest: nsIDOMRequestService;
- dns: nsIDNSService;
- dirsvc: nsIDirectoryService & nsIProperties;
- droppedLinkHandler: nsIDroppedLinkHandler;
- eTLD: nsIEffectiveTLDService;
- policies: nsIEnterprisePolicies;
- env: nsIEnvironment;
- els: nsIEventListenerService;
- fog: nsIFOG;
- focus: nsIFocusManager;
- io: nsIIOService & nsINetUtil & nsISpeculativeConnect;
- loadContextInfo: nsILoadContextInfoFactory;
- domStorageManager: nsIDOMStorageManager & nsILocalStorageManager;
- logins: nsILoginManager;
- obs: nsIObserverService;
- perms: nsIPermissionManager;
- prefs: nsIPrefBranch & nsIPrefService;
- profiler: nsIProfiler;
- prompt: nsIPromptService;
- sysinfo: nsISystemInfo & nsIPropertyBag2;
- qms: nsIQuotaManagerService;
- rfp: nsIRFPService;
- scriptSecurityManager: nsIScriptSecurityManager;
- search: nsISearchService;
- sessionStorage: nsISessionStorageService;
- strings: nsIStringBundleService;
- telemetry: nsITelemetry;
- textToSubURI: nsITextToSubURI;
- tm: nsIThreadManager;
- uriFixup: nsIURIFixup;
- urlFormatter: nsIURLFormatter;
- uuid: nsIUUIDGenerator;
- vc: nsIVersionComparator;
- wm: nsIWindowMediator;
- ww: nsIWindowWatcher;
- xulStore: nsIXULStore;
- ppmm: any;
- cpmm: any;
- mm: any;
+interface nsXPCComponents_Classes {
+ [cid: string]: {
+ createInstance<T>(aID: T): nsQIResult<T>;
+ getService<T>(aID?: T): unknown extends T ? nsISupports : nsQIResult<T>;
}
+}
- var Ci: nsIXPCComponents_Interfaces;
- var Cu: nsIXPCComponents_Utils;
- var Services: nsIServices;
+// Generic overloads.
+interface nsXPCComponents_Utils {
+ cloneInto<T>(value: T, ...any): T;
+ createObjectIn<T = object>(_, object?: T): T;
+ exportFunction<T>(func: T, ...any): T;
+ getWeakReference<T>(value: T): { get(): T };
+ waiveXrays<T>(object: T): T;
}
+
+// TODO: remove after next TS update.
+interface PromiseConstructor {
+ withResolvers<T>(): {
+ promise: Promise<T>;
+ resolve: (value: T | PromiseLike<T>) => void;
+ reject: (reason?: any) => void;
+ };
+}
+
+// Hand-crafted artisanal types.
+interface XULBrowserElement extends XULFrameElement, FrameLoader {
+ currentURI: nsIURI;
+ docShellIsActive: boolean;
+ isRemoteBrowser: boolean;
+ remoteType: string;
+}
+
+type nsQIResult<iid> = import("gecko/lib.gecko.xpcom").nsQIResult<iid>;