internal-ambient.d.ts 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. declare var internalBinding: any;
  2. declare const BUILDFLAG: (flag: boolean) => boolean;
  3. declare const ENABLE_DESKTOP_CAPTURER: boolean;
  4. declare const ENABLE_ELECTRON_EXTENSIONS: boolean;
  5. declare const ENABLE_REMOTE_MODULE: boolean;
  6. declare const ENABLE_VIEW_API: boolean;
  7. declare namespace NodeJS {
  8. interface FeaturesBinding {
  9. isBuiltinSpellCheckerEnabled(): boolean;
  10. isDesktopCapturerEnabled(): boolean;
  11. isOffscreenRenderingEnabled(): boolean;
  12. isRemoteModuleEnabled(): boolean;
  13. isPDFViewerEnabled(): boolean;
  14. isRunAsNodeEnabled(): boolean;
  15. isFakeLocationProviderEnabled(): boolean;
  16. isViewApiEnabled(): boolean;
  17. isTtsEnabled(): boolean;
  18. isPrintingEnabled(): boolean;
  19. isPictureInPictureEnabled(): boolean;
  20. isExtensionsEnabled(): boolean;
  21. isComponentBuild(): 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. interface Process {
  45. /**
  46. * DO NOT USE DIRECTLY, USE process.electronBinding
  47. */
  48. _linkedBinding(name: string): any;
  49. electronBinding(name: string): any;
  50. electronBinding(name: 'features'): FeaturesBinding;
  51. electronBinding(name: 'ipc'): { ipc: IpcRendererBinding };
  52. electronBinding(name: 'v8_util'): V8UtilBinding;
  53. electronBinding(name: 'app'): { app: Electron.App, App: Function };
  54. electronBinding(name: 'command_line'): Electron.CommandLine;
  55. electronBinding(name: 'desktop_capturer'): { createDesktopCapturer(): ElectronInternal.DesktopCapturer };
  56. log: NodeJS.WriteStream['write'];
  57. activateUvLoop(): void;
  58. // Additional events
  59. once(event: 'document-start', listener: () => any): this;
  60. once(event: 'document-end', listener: () => any): this;
  61. // Additional properties
  62. _firstFileName?: string;
  63. helperExecPath: string;
  64. isRemoteModuleEnabled: boolean;
  65. }
  66. }
  67. declare module NodeJS {
  68. interface Global {
  69. require: NodeRequire;
  70. module: NodeModule;
  71. __filename: string;
  72. __dirname: string;
  73. }
  74. }
  75. interface ContextMenuItem {
  76. id: number;
  77. label: string;
  78. type: 'normal' | 'separator' | 'subMenu' | 'checkbox';
  79. checked: boolean;
  80. enabled: boolean;
  81. subItems: ContextMenuItem[];
  82. }
  83. declare interface Window {
  84. ELECTRON_DISABLE_SECURITY_WARNINGS?: boolean;
  85. ELECTRON_ENABLE_SECURITY_WARNINGS?: boolean;
  86. InspectorFrontendHost?: {
  87. showContextMenuAtPoint: (x: number, y: number, items: ContextMenuItem[]) => void
  88. };
  89. DevToolsAPI?: {
  90. contextMenuItemSelected: (id: number) => void;
  91. contextMenuCleared: () => void
  92. };
  93. UI?: {
  94. createFileSelectorElement: (callback: () => void) => HTMLSpanElement
  95. };
  96. Persistence?: {
  97. FileSystemWorkspaceBinding: {
  98. completeURL: (project: string, path: string) => string;
  99. }
  100. };
  101. ResizeObserver: ResizeObserver;
  102. trustedTypes: TrustedTypePolicyFactory;
  103. }
  104. /**
  105. * The ResizeObserver interface is used to observe changes to Element's content
  106. * rect.
  107. *
  108. * It is modeled after MutationObserver and IntersectionObserver.
  109. */
  110. declare class ResizeObserver {
  111. constructor (callback: ResizeObserverCallback);
  112. /**
  113. * Adds target to the list of observed elements.
  114. */
  115. observe: (target: Element) => void;
  116. /**
  117. * Removes target from the list of observed elements.
  118. */
  119. unobserve: (target: Element) => void;
  120. /**
  121. * Clears both the observationTargets and activeTargets lists.
  122. */
  123. disconnect: () => void;
  124. }
  125. /**
  126. * This callback delivers ResizeObserver's notifications. It is invoked by a
  127. * broadcast active observations algorithm.
  128. */
  129. interface ResizeObserverCallback {
  130. (entries: ResizeObserverEntry[], observer: ResizeObserver): void;
  131. }
  132. interface ResizeObserverEntry {
  133. /**
  134. * @param target The Element whose size has changed.
  135. */
  136. new (target: Element): ResizeObserverEntry;
  137. /**
  138. * The Element whose size has changed.
  139. */
  140. readonly target: Element;
  141. /**
  142. * Element's content rect when ResizeObserverCallback is invoked.
  143. */
  144. readonly contentRect: DOMRectReadOnly;
  145. }
  146. // https://w3c.github.io/webappsec-trusted-types/dist/spec/#trusted-types
  147. type TrustedHTML = string;
  148. type TrustedScript = string;
  149. type TrustedScriptURL = string;
  150. type TrustedType = TrustedHTML | TrustedScript | TrustedScriptURL;
  151. type StringContext = 'TrustedHTML' | 'TrustedScript' | 'TrustedScriptURL';
  152. // https://w3c.github.io/webappsec-trusted-types/dist/spec/#typedef-trustedtypepolicy
  153. interface TrustedTypePolicy {
  154. createHTML(input: string, ...arguments: any[]): TrustedHTML;
  155. createScript(input: string, ...arguments: any[]): TrustedScript;
  156. createScriptURL(input: string, ...arguments: any[]): TrustedScriptURL;
  157. }
  158. // https://w3c.github.io/webappsec-trusted-types/dist/spec/#typedef-trustedtypepolicyoptions
  159. interface TrustedTypePolicyOptions {
  160. createHTML?: (input: string, ...arguments: any[]) => TrustedHTML;
  161. createScript?: (input: string, ...arguments: any[]) => TrustedScript;
  162. createScriptURL?: (input: string, ...arguments: any[]) => TrustedScriptURL;
  163. }
  164. // https://w3c.github.io/webappsec-trusted-types/dist/spec/#typedef-trustedtypepolicyfactory
  165. interface TrustedTypePolicyFactory {
  166. createPolicy(policyName: string, policyOptions: TrustedTypePolicyOptions): TrustedTypePolicy
  167. isHTML(value: any): boolean;
  168. isScript(value: any): boolean;
  169. isScriptURL(value: any): boolean;
  170. readonly emptyHTML: TrustedHTML;
  171. readonly emptyScript: TrustedScript;
  172. getAttributeType(tagName: string, attribute: string, elementNs?: string, attrNs?: string): StringContext | null;
  173. getPropertyType(tagName: string, property: string, elementNs?: string): StringContext | null;
  174. readonly defaultPolicy: TrustedTypePolicy | null;
  175. }