internal-ambient.d.ts 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. declare var internalBinding: any;
  2. declare const BUILDFLAG: (flag: boolean) => boolean;
  3. declare const ENABLE_DESKTOP_CAPTURER: boolean;
  4. declare const ENABLE_REMOTE_MODULE: boolean;
  5. declare const ENABLE_VIEWS_API: boolean;
  6. declare namespace NodeJS {
  7. interface FeaturesBinding {
  8. isBuiltinSpellCheckerEnabled(): boolean;
  9. isDesktopCapturerEnabled(): boolean;
  10. isOffscreenRenderingEnabled(): boolean;
  11. isRemoteModuleEnabled(): boolean;
  12. isPDFViewerEnabled(): boolean;
  13. isRunAsNodeEnabled(): boolean;
  14. isFakeLocationProviderEnabled(): boolean;
  15. isViewApiEnabled(): boolean;
  16. isTtsEnabled(): boolean;
  17. isPrintingEnabled(): boolean;
  18. isPictureInPictureEnabled(): boolean;
  19. isExtensionsEnabled(): boolean;
  20. isComponentBuild(): boolean;
  21. isWinDarkModeWindowUiEnabled(): boolean;
  22. }
  23. interface IpcRendererBinding {
  24. send(internal: boolean, channel: string, args: any[]): void;
  25. sendSync(internal: boolean, channel: string, args: any[]): any;
  26. sendToHost(channel: string, args: any[]): void;
  27. sendTo(internal: boolean, sendToAll: boolean, webContentsId: number, channel: string, args: any[]): void;
  28. invoke<T>(internal: boolean, channel: string, args: any[]): Promise<{ error: string, result: T }>;
  29. postMessage(channel: string, message: any, transferables: MessagePort[]): void;
  30. }
  31. interface V8UtilBinding {
  32. getHiddenValue<T>(obj: any, key: string): T;
  33. setHiddenValue<T>(obj: any, key: string, value: T): void;
  34. deleteHiddenValue(obj: any, key: string): void;
  35. requestGarbageCollectionForTesting(): void;
  36. createIDWeakMap<V>(): ElectronInternal.KeyWeakMap<number, V>;
  37. createDoubleIDWeakMap<V>(): ElectronInternal.KeyWeakMap<[string, number], V>;
  38. setRemoteCallbackFreer(fn: Function, processId: number, frameId: number, contextId: String, id: number, sender: any): void
  39. weaklyTrackValue(value: any): void;
  40. clearWeaklyTrackedValues(): void;
  41. getWeaklyTrackedValues(): any[];
  42. triggerFatalErrorForTesting(): void;
  43. }
  44. type DataPipe = {
  45. write: (buf: Uint8Array) => Promise<void>;
  46. done: () => void;
  47. };
  48. type BodyFunc = (pipe: DataPipe) => void;
  49. type CreateURLLoaderOptions = {
  50. method: string;
  51. url: string;
  52. extraHeaders?: Record<string, string>;
  53. useSessionCookies?: boolean;
  54. body: Uint8Array | BodyFunc;
  55. session?: Electron.Session;
  56. partition?: string;
  57. referrer?: string;
  58. }
  59. type ResponseHead = {
  60. statusCode: number;
  61. statusMessage: string;
  62. httpVersion: { major: number, minor: number };
  63. rawHeaders: { key: string, value: string }[];
  64. };
  65. type RedirectInfo = {
  66. statusCode: number;
  67. newMethod: string;
  68. newUrl: string;
  69. newSiteForCookies: string;
  70. newReferrer: string;
  71. insecureSchemeWasUpgraded: boolean;
  72. isSignedExchangeFallbackRedirect: boolean;
  73. }
  74. interface URLLoader extends EventEmitter {
  75. cancel(): void;
  76. on(eventName: 'data', listener: (event: any, data: ArrayBuffer) => void): this;
  77. on(eventName: 'response-started', listener: (event: any, finalUrl: string, responseHead: ResponseHead) => void): this;
  78. on(eventName: 'complete', listener: (event: any) => void): this;
  79. on(eventName: 'error', listener: (event: any, netErrorString: string) => void): this;
  80. on(eventName: 'login', listener: (event: any, authInfo: Electron.AuthInfo, callback: (username?: string, password?: string) => void) => void): this;
  81. on(eventName: 'redirect', listener: (event: any, redirectInfo: RedirectInfo, headers: Record<string, string>) => void): this;
  82. on(eventName: 'upload-progress', listener: (event: any, position: number, total: number) => void): this;
  83. on(eventName: 'download-progress', listener: (event: any, current: number) => void): this;
  84. }
  85. interface Process {
  86. /**
  87. * DO NOT USE DIRECTLY, USE process.electronBinding
  88. */
  89. _linkedBinding(name: string): any;
  90. electronBinding(name: string): any;
  91. electronBinding(name: 'features'): FeaturesBinding;
  92. electronBinding(name: 'ipc'): { ipc: IpcRendererBinding };
  93. electronBinding(name: 'v8_util'): V8UtilBinding;
  94. electronBinding(name: 'app'): { app: Electron.App, App: Function };
  95. electronBinding(name: 'command_line'): Electron.CommandLine;
  96. electronBinding(name: 'desktop_capturer'): { createDesktopCapturer(): ElectronInternal.DesktopCapturer };
  97. electronBinding(name: 'net'): {
  98. isValidHeaderName: (headerName: string) => boolean;
  99. isValidHeaderValue: (headerValue: string) => boolean;
  100. Net: any;
  101. net: any;
  102. createURLLoader(options: CreateURLLoaderOptions): URLLoader;
  103. };
  104. log: NodeJS.WriteStream['write'];
  105. activateUvLoop(): void;
  106. // Additional events
  107. once(event: 'document-start', listener: () => any): this;
  108. once(event: 'document-end', listener: () => any): this;
  109. // Additional properties
  110. _firstFileName?: string;
  111. helperExecPath: string;
  112. isRemoteModuleEnabled: boolean;
  113. }
  114. }
  115. declare module NodeJS {
  116. interface Global {
  117. require: NodeRequire;
  118. module: NodeModule;
  119. __filename: string;
  120. __dirname: string;
  121. }
  122. }
  123. interface ContextMenuItem {
  124. id: number;
  125. label: string;
  126. type: 'normal' | 'separator' | 'subMenu' | 'checkbox';
  127. checked: boolean;
  128. enabled: boolean;
  129. subItems: ContextMenuItem[];
  130. }
  131. declare interface Window {
  132. ELECTRON_DISABLE_SECURITY_WARNINGS?: boolean;
  133. ELECTRON_ENABLE_SECURITY_WARNINGS?: boolean;
  134. InspectorFrontendHost?: {
  135. showContextMenuAtPoint: (x: number, y: number, items: ContextMenuItem[]) => void
  136. };
  137. DevToolsAPI?: {
  138. contextMenuItemSelected: (id: number) => void;
  139. contextMenuCleared: () => void
  140. };
  141. UI?: {
  142. createFileSelectorElement: (callback: () => void) => HTMLSpanElement
  143. };
  144. Persistence?: {
  145. FileSystemWorkspaceBinding: {
  146. completeURL: (project: string, path: string) => string;
  147. }
  148. };
  149. ResizeObserver: ResizeObserver;
  150. trustedTypes: TrustedTypePolicyFactory;
  151. }
  152. /**
  153. * The ResizeObserver interface is used to observe changes to Element's content
  154. * rect.
  155. *
  156. * It is modeled after MutationObserver and IntersectionObserver.
  157. */
  158. declare class ResizeObserver {
  159. constructor (callback: ResizeObserverCallback);
  160. /**
  161. * Adds target to the list of observed elements.
  162. */
  163. observe: (target: Element) => void;
  164. /**
  165. * Removes target from the list of observed elements.
  166. */
  167. unobserve: (target: Element) => void;
  168. /**
  169. * Clears both the observationTargets and activeTargets lists.
  170. */
  171. disconnect: () => void;
  172. }
  173. /**
  174. * This callback delivers ResizeObserver's notifications. It is invoked by a
  175. * broadcast active observations algorithm.
  176. */
  177. interface ResizeObserverCallback {
  178. (entries: ResizeObserverEntry[], observer: ResizeObserver): void;
  179. }
  180. interface ResizeObserverEntry {
  181. /**
  182. * @param target The Element whose size has changed.
  183. */
  184. new (target: Element): ResizeObserverEntry;
  185. /**
  186. * The Element whose size has changed.
  187. */
  188. readonly target: Element;
  189. /**
  190. * Element's content rect when ResizeObserverCallback is invoked.
  191. */
  192. readonly contentRect: DOMRectReadOnly;
  193. }
  194. // https://w3c.github.io/webappsec-trusted-types/dist/spec/#trusted-types
  195. type TrustedHTML = string;
  196. type TrustedScript = string;
  197. type TrustedScriptURL = string;
  198. type TrustedType = TrustedHTML | TrustedScript | TrustedScriptURL;
  199. type StringContext = 'TrustedHTML' | 'TrustedScript' | 'TrustedScriptURL';
  200. // https://w3c.github.io/webappsec-trusted-types/dist/spec/#typedef-trustedtypepolicy
  201. interface TrustedTypePolicy {
  202. createHTML(input: string, ...arguments: any[]): TrustedHTML;
  203. createScript(input: string, ...arguments: any[]): TrustedScript;
  204. createScriptURL(input: string, ...arguments: any[]): TrustedScriptURL;
  205. }
  206. // https://w3c.github.io/webappsec-trusted-types/dist/spec/#typedef-trustedtypepolicyoptions
  207. interface TrustedTypePolicyOptions {
  208. createHTML?: (input: string, ...arguments: any[]) => TrustedHTML;
  209. createScript?: (input: string, ...arguments: any[]) => TrustedScript;
  210. createScriptURL?: (input: string, ...arguments: any[]) => TrustedScriptURL;
  211. }
  212. // https://w3c.github.io/webappsec-trusted-types/dist/spec/#typedef-trustedtypepolicyfactory
  213. interface TrustedTypePolicyFactory {
  214. createPolicy(policyName: string, policyOptions: TrustedTypePolicyOptions): TrustedTypePolicy
  215. isHTML(value: any): boolean;
  216. isScript(value: any): boolean;
  217. isScriptURL(value: any): boolean;
  218. readonly emptyHTML: TrustedHTML;
  219. readonly emptyScript: TrustedScript;
  220. getAttributeType(tagName: string, attribute: string, elementNs?: string, attrNs?: string): StringContext | null;
  221. getPropertyType(tagName: string, property: string, elementNs?: string): StringContext | null;
  222. readonly defaultPolicy: TrustedTypePolicy | null;
  223. }