internal-ambient.d.ts 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. declare const BUILDFLAG: (flag: boolean) => boolean;
  2. declare const ENABLE_VIEWS_API: boolean;
  3. declare namespace NodeJS {
  4. interface FeaturesBinding {
  5. isBuiltinSpellCheckerEnabled(): boolean;
  6. isPDFViewerEnabled(): boolean;
  7. isFakeLocationProviderEnabled(): boolean;
  8. isViewApiEnabled(): boolean;
  9. isPrintingEnabled(): boolean;
  10. isExtensionsEnabled(): boolean;
  11. isComponentBuild(): boolean;
  12. }
  13. interface IpcRendererBinding {
  14. send(internal: boolean, channel: string, args: any[]): void;
  15. sendSync(internal: boolean, channel: string, args: any[]): any;
  16. sendToHost(channel: string, args: any[]): void;
  17. invoke<T>(internal: boolean, channel: string, args: any[]): Promise<{ error: string, result: T }>;
  18. postMessage(channel: string, message: any, transferables: MessagePort[]): void;
  19. }
  20. interface V8UtilBinding {
  21. getHiddenValue<T>(obj: any, key: string): T;
  22. setHiddenValue<T>(obj: any, key: string, value: T): void;
  23. deleteHiddenValue(obj: any, key: string): void;
  24. requestGarbageCollectionForTesting(): void;
  25. runUntilIdle(): void;
  26. triggerFatalErrorForTesting(): void;
  27. }
  28. type CrashReporterBinding = Omit<Electron.CrashReporter, 'start'> & {
  29. start(submitUrl: string,
  30. uploadToServer: boolean,
  31. ignoreSystemCrashHandler: boolean,
  32. rateLimit: boolean,
  33. compress: boolean,
  34. globalExtra: Record<string, string>,
  35. extra: Record<string, string>,
  36. isNodeProcess: boolean): void;
  37. }
  38. interface EnvironmentBinding {
  39. getVar(name: string): string | null;
  40. hasVar(name: string): boolean;
  41. setVar(name: string, value: string): boolean;
  42. unSetVar(name: string): boolean;
  43. }
  44. type AsarFileInfo = {
  45. size: number;
  46. unpacked: boolean;
  47. offset: number;
  48. integrity?: {
  49. algorithm: 'SHA256';
  50. hash: string;
  51. }
  52. };
  53. type AsarFileStat = {
  54. size: number;
  55. offset: number;
  56. isFile: boolean;
  57. isDirectory: boolean;
  58. isLink: boolean;
  59. }
  60. interface AsarArchive {
  61. getFileInfo(path: string): AsarFileInfo | false;
  62. stat(path: string): AsarFileStat | false;
  63. readdir(path: string): string[] | false;
  64. realpath(path: string): string | false;
  65. copyFileOut(path: string): string | false;
  66. getFdAndValidateIntegrityLater(): number | -1;
  67. }
  68. interface AsarBinding {
  69. Archive: { new(path: string): AsarArchive };
  70. splitPath(path: string): {
  71. isAsar: false;
  72. } | {
  73. isAsar: true;
  74. asarPath: string;
  75. filePath: string;
  76. };
  77. initAsarSupport(require: NodeJS.Require): void;
  78. }
  79. interface NetBinding {
  80. isOnline(): boolean;
  81. isValidHeaderName: (headerName: string) => boolean;
  82. isValidHeaderValue: (headerValue: string) => boolean;
  83. fileURLToFilePath: (url: string) => string;
  84. Net: any;
  85. net: any;
  86. createURLLoader(options: CreateURLLoaderOptions): URLLoader;
  87. }
  88. interface NotificationBinding {
  89. isSupported(): boolean;
  90. Notification: typeof Electron.Notification;
  91. }
  92. interface PowerMonitorBinding extends Electron.PowerMonitor {
  93. createPowerMonitor(): PowerMonitorBinding;
  94. setListeningForShutdown(listening: boolean): void;
  95. }
  96. interface SessionBinding {
  97. fromPartition: typeof Electron.Session.fromPartition,
  98. fromPath: typeof Electron.Session.fromPath,
  99. Session: typeof Electron.Session
  100. }
  101. interface WebViewManagerBinding {
  102. addGuest(guestInstanceId: number, embedder: Electron.WebContents, guest: Electron.WebContents, webPreferences: Electron.WebPreferences): void;
  103. removeGuest(embedder: Electron.WebContents, guestInstanceId: number): void;
  104. }
  105. interface WebFrameMainBinding {
  106. WebFrameMain: typeof Electron.WebFrameMain;
  107. fromId(processId: number, routingId: number): Electron.WebFrameMain;
  108. fromIdOrNull(processId: number, routingId: number): Electron.WebFrameMain | null;
  109. }
  110. interface InternalWebPreferences {
  111. isWebView: boolean;
  112. hiddenPage: boolean;
  113. nodeIntegration: boolean;
  114. webviewTag: boolean;
  115. }
  116. interface InternalWebFrame extends Electron.WebFrame {
  117. getWebPreference<K extends keyof InternalWebPreferences>(name: K): InternalWebPreferences[K];
  118. getWebFrameId(window: Window): number;
  119. allowGuestViewElementDefinition(context: object, callback: Function): void;
  120. }
  121. interface WebFrameBinding {
  122. mainFrame: InternalWebFrame;
  123. }
  124. type DataPipe = {
  125. write: (buf: Uint8Array) => Promise<void>;
  126. done: () => void;
  127. };
  128. type BodyFunc = (pipe: DataPipe) => void;
  129. type CreateURLLoaderOptions = {
  130. method: string;
  131. url: string;
  132. extraHeaders?: Record<string, string>;
  133. useSessionCookies?: boolean;
  134. credentials?: 'include' | 'omit' | 'same-origin';
  135. body: Uint8Array | BodyFunc;
  136. session?: Electron.Session;
  137. partition?: string;
  138. referrer?: string;
  139. referrerPolicy?: string;
  140. cache?: string;
  141. origin?: string;
  142. hasUserActivation?: boolean;
  143. mode?: string;
  144. destination?: string;
  145. bypassCustomProtocolHandlers?: boolean;
  146. };
  147. type ResponseHead = {
  148. statusCode: number;
  149. statusMessage: string;
  150. httpVersion: { major: number, minor: number };
  151. rawHeaders: { key: string, value: string }[];
  152. headers: Record<string, string[]>;
  153. };
  154. type RedirectInfo = {
  155. statusCode: number;
  156. newMethod: string;
  157. newUrl: string;
  158. newSiteForCookies: string;
  159. newReferrer: string;
  160. insecureSchemeWasUpgraded: boolean;
  161. isSignedExchangeFallbackRedirect: boolean;
  162. }
  163. interface URLLoader extends EventEmitter {
  164. cancel(): void;
  165. on(eventName: 'data', listener: (event: any, data: ArrayBuffer, resume: () => void) => void): this;
  166. on(eventName: 'response-started', listener: (event: any, finalUrl: string, responseHead: ResponseHead) => void): this;
  167. on(eventName: 'complete', listener: (event: any) => void): this;
  168. on(eventName: 'error', listener: (event: any, netErrorString: string) => void): this;
  169. on(eventName: 'login', listener: (event: any, authInfo: Electron.AuthInfo, callback: (username?: string, password?: string) => void) => void): this;
  170. on(eventName: 'redirect', listener: (event: any, redirectInfo: RedirectInfo, headers: Record<string, string>) => void): this;
  171. on(eventName: 'upload-progress', listener: (event: any, position: number, total: number) => void): this;
  172. on(eventName: 'download-progress', listener: (event: any, current: number) => void): this;
  173. }
  174. interface Process {
  175. internalBinding?(name: string): any;
  176. _linkedBinding(name: string): any;
  177. _linkedBinding(name: 'electron_common_asar'): AsarBinding;
  178. _linkedBinding(name: 'electron_common_clipboard'): Electron.Clipboard;
  179. _linkedBinding(name: 'electron_common_command_line'): Electron.CommandLine;
  180. _linkedBinding(name: 'electron_common_environment'): EnvironmentBinding;
  181. _linkedBinding(name: 'electron_common_features'): FeaturesBinding;
  182. _linkedBinding(name: 'electron_common_native_image'): { nativeImage: typeof Electron.NativeImage };
  183. _linkedBinding(name: 'electron_common_shell'): Electron.Shell;
  184. _linkedBinding(name: 'electron_common_v8_util'): V8UtilBinding;
  185. _linkedBinding(name: 'electron_browser_app'): { app: Electron.App, App: Function };
  186. _linkedBinding(name: 'electron_browser_auto_updater'): { autoUpdater: Electron.AutoUpdater };
  187. _linkedBinding(name: 'electron_browser_browser_view'): { BrowserView: typeof Electron.BrowserView };
  188. _linkedBinding(name: 'electron_browser_crash_reporter'): CrashReporterBinding;
  189. _linkedBinding(name: 'electron_browser_desktop_capturer'): { createDesktopCapturer(): ElectronInternal.DesktopCapturer; };
  190. _linkedBinding(name: 'electron_browser_event_emitter'): { setEventEmitterPrototype(prototype: Object): void; };
  191. _linkedBinding(name: 'electron_browser_global_shortcut'): { globalShortcut: Electron.GlobalShortcut };
  192. _linkedBinding(name: 'electron_browser_image_view'): { ImageView: any };
  193. _linkedBinding(name: 'electron_browser_in_app_purchase'): { inAppPurchase: Electron.InAppPurchase };
  194. _linkedBinding(name: 'electron_browser_message_port'): { createPair(): { port1: Electron.MessagePortMain, port2: Electron.MessagePortMain }; };
  195. _linkedBinding(name: 'electron_browser_native_theme'): { nativeTheme: Electron.NativeTheme };
  196. _linkedBinding(name: 'electron_browser_net'): NetBinding;
  197. _linkedBinding(name: 'electron_browser_notification'): NotificationBinding;
  198. _linkedBinding(name: 'electron_browser_power_monitor'): PowerMonitorBinding;
  199. _linkedBinding(name: 'electron_browser_power_save_blocker'): { powerSaveBlocker: Electron.PowerSaveBlocker };
  200. _linkedBinding(name: 'electron_browser_push_notifications'): { pushNotifications: Electron.PushNotifications };
  201. _linkedBinding(name: 'electron_browser_safe_storage'): { safeStorage: Electron.SafeStorage };
  202. _linkedBinding(name: 'electron_browser_session'): SessionBinding;
  203. _linkedBinding(name: 'electron_browser_screen'): { createScreen(): Electron.Screen };
  204. _linkedBinding(name: 'electron_browser_system_preferences'): { systemPreferences: Electron.SystemPreferences };
  205. _linkedBinding(name: 'electron_browser_tray'): { Tray: Electron.Tray };
  206. _linkedBinding(name: 'electron_browser_view'): { View: Electron.View };
  207. _linkedBinding(name: 'electron_browser_web_contents_view'): { WebContentsView: typeof Electron.WebContentsView };
  208. _linkedBinding(name: 'electron_browser_web_view_manager'): WebViewManagerBinding;
  209. _linkedBinding(name: 'electron_browser_web_frame_main'): WebFrameMainBinding;
  210. _linkedBinding(name: 'electron_renderer_crash_reporter'): Electron.CrashReporter;
  211. _linkedBinding(name: 'electron_renderer_ipc'): { ipc: IpcRendererBinding };
  212. _linkedBinding(name: 'electron_renderer_web_frame'): WebFrameBinding;
  213. log: NodeJS.WriteStream['write'];
  214. activateUvLoop(): void;
  215. // Additional events
  216. once(event: 'document-start', listener: () => any): this;
  217. once(event: 'document-end', listener: () => any): this;
  218. // Additional properties
  219. _firstFileName?: string;
  220. _serviceStartupScript: string;
  221. helperExecPath: string;
  222. mainModule?: NodeJS.Module | undefined;
  223. appCodeLoaded?: () => void;
  224. }
  225. }
  226. declare module NodeJS {
  227. interface Global {
  228. require: NodeRequire;
  229. module: NodeModule;
  230. __filename: string;
  231. __dirname: string;
  232. }
  233. }
  234. interface ContextMenuItem {
  235. id: number;
  236. label: string;
  237. type: 'normal' | 'separator' | 'subMenu' | 'checkbox';
  238. checked: boolean;
  239. enabled: boolean;
  240. subItems: ContextMenuItem[];
  241. }
  242. declare interface Window {
  243. ELECTRON_DISABLE_SECURITY_WARNINGS?: boolean;
  244. ELECTRON_ENABLE_SECURITY_WARNINGS?: boolean;
  245. InspectorFrontendHost?: {
  246. showContextMenuAtPoint: (x: number, y: number, items: ContextMenuItem[]) => void
  247. };
  248. DevToolsAPI?: {
  249. contextMenuItemSelected: (id: number) => void;
  250. contextMenuCleared: () => void
  251. };
  252. UI?: {
  253. createFileSelectorElement: (callback: () => void) => HTMLSpanElement
  254. };
  255. Persistence?: {
  256. FileSystemWorkspaceBinding: {
  257. completeURL: (project: string, path: string) => string;
  258. }
  259. };
  260. WebView: typeof ElectronInternal.WebViewElement;
  261. trustedTypes: TrustedTypePolicyFactory;
  262. }
  263. // https://w3c.github.io/webappsec-trusted-types/dist/spec/#trusted-types
  264. type TrustedHTML = string;
  265. type TrustedScript = string;
  266. type TrustedScriptURL = string;
  267. type TrustedType = TrustedHTML | TrustedScript | TrustedScriptURL;
  268. type StringContext = 'TrustedHTML' | 'TrustedScript' | 'TrustedScriptURL';
  269. // https://w3c.github.io/webappsec-trusted-types/dist/spec/#typedef-trustedtypepolicy
  270. interface TrustedTypePolicy {
  271. createHTML(input: string, ...arguments: any[]): TrustedHTML;
  272. createScript(input: string, ...arguments: any[]): TrustedScript;
  273. createScriptURL(input: string, ...arguments: any[]): TrustedScriptURL;
  274. }
  275. // https://w3c.github.io/webappsec-trusted-types/dist/spec/#typedef-trustedtypepolicyoptions
  276. interface TrustedTypePolicyOptions {
  277. createHTML?: (input: string, ...arguments: any[]) => TrustedHTML;
  278. createScript?: (input: string, ...arguments: any[]) => TrustedScript;
  279. createScriptURL?: (input: string, ...arguments: any[]) => TrustedScriptURL;
  280. }
  281. // https://w3c.github.io/webappsec-trusted-types/dist/spec/#typedef-trustedtypepolicyfactory
  282. interface TrustedTypePolicyFactory {
  283. createPolicy(policyName: string, policyOptions: TrustedTypePolicyOptions): TrustedTypePolicy
  284. isHTML(value: any): boolean;
  285. isScript(value: any): boolean;
  286. isScriptURL(value: any): boolean;
  287. readonly emptyHTML: TrustedHTML;
  288. readonly emptyScript: TrustedScript;
  289. getAttributeType(tagName: string, attribute: string, elementNs?: string, attrNs?: string): StringContext | null;
  290. getPropertyType(tagName: string, property: string, elementNs?: string): StringContext | null;
  291. readonly defaultPolicy: TrustedTypePolicy | null;
  292. }