summaryrefslogtreecommitdiffstats
path: root/toolkit/components/extensions/types/gecko.ts
blob: f6b5190f8d29c8efbb57598b088a08e5aabb0b41 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
/**
 * Global Gecko type declarations.
 */

// @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;
  }

  // XPIDL additions/overrides.

  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?

  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;
  }

  // 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> {}

  namespace Components {
    type Exception = Error;
  }
  namespace UrlbarUtils {
    type RESULT_TYPE = any;
    type RESULT_SOURCE = any;
  }

  // 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;
  }

  var Ci: nsIXPCComponents_Interfaces;
  var Cu: nsIXPCComponents_Utils;
  var Services: nsIServices;
}