internal-ambient.d.ts 13 KB

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