| 
									
										
										
										
											2020-03-20 13:28:31 -07:00
										 |  |  | 'use strict'; | 
					
						
							| 
									
										
										
										
											2018-09-23 00:28:50 +12:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-21 07:30:14 -03:00
										 |  |  | /* eslint no-eval: "off" */ | 
					
						
							| 
									
										
										
										
											2018-08-11 00:19:49 +02:00
										 |  |  | /* global binding, Buffer */ | 
					
						
							| 
									
										
										
										
											2020-03-20 13:28:31 -07:00
										 |  |  | const events = require('events'); | 
					
						
							|  |  |  | const { EventEmitter } = events; | 
					
						
							| 
									
										
										
										
											2016-08-21 07:30:14 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-20 13:28:31 -07:00
										 |  |  | process.electronBinding = require('@electron/internal/common/electron-binding-setup').electronBindingSetup(binding.get, 'renderer'); | 
					
						
							| 
									
										
										
										
											2017-02-20 10:59:39 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-20 13:28:31 -07:00
										 |  |  | const v8Util = process.electronBinding('v8_util'); | 
					
						
							| 
									
										
										
										
											2019-06-02 13:03:03 -07:00
										 |  |  | // Expose Buffer shim as a hidden value. This is used by C++ code to
 | 
					
						
							| 
									
										
										
										
											2017-03-16 13:20:09 -03:00
										 |  |  | // deserialize Buffer instances sent from browser process.
 | 
					
						
							| 
									
										
										
										
											2020-03-20 13:28:31 -07:00
										 |  |  | v8Util.setHiddenValue(global, 'Buffer', Buffer); | 
					
						
							| 
									
										
										
										
											2019-08-02 21:35:04 +02:00
										 |  |  | // The `lib/renderer/api/ipc-renderer.ts` module looks for the ipc object in the
 | 
					
						
							| 
									
										
										
										
											2017-02-27 14:14:36 -03:00
										 |  |  | // "ipc" hidden value
 | 
					
						
							| 
									
										
										
										
											2020-03-20 13:28:31 -07:00
										 |  |  | v8Util.setHiddenValue(global, 'ipc', new EventEmitter()); | 
					
						
							| 
									
										
										
										
											2019-08-02 21:35:04 +02:00
										 |  |  | // The `lib/renderer/ipc-renderer-internal.ts` module looks for the ipc object in the
 | 
					
						
							| 
									
										
										
										
											2018-10-06 13:48:00 +02:00
										 |  |  | // "ipc-internal" hidden value
 | 
					
						
							| 
									
										
										
										
											2020-03-20 13:28:31 -07:00
										 |  |  | v8Util.setHiddenValue(global, 'ipc-internal', new EventEmitter()); | 
					
						
							| 
									
										
										
										
											2019-06-02 13:03:03 -07:00
										 |  |  | // The process object created by webpack is not an event emitter, fix it so
 | 
					
						
							| 
									
										
										
										
											2017-02-27 14:14:36 -03:00
										 |  |  | // the API is more compatible with non-sandboxed renderers.
 | 
					
						
							| 
									
										
										
										
											2018-10-02 03:56:31 +02:00
										 |  |  | for (const prop of Object.keys(EventEmitter.prototype)) { | 
					
						
							| 
									
										
										
										
											2020-03-20 08:12:18 -07:00
										 |  |  |   if (Object.prototype.hasOwnProperty.call(process, prop)) { | 
					
						
							| 
									
										
										
										
											2020-03-20 13:28:31 -07:00
										 |  |  |     delete process[prop]; | 
					
						
							| 
									
										
										
										
											2017-02-27 14:14:36 -03:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2016-08-21 07:30:14 -03:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2020-03-20 13:28:31 -07:00
										 |  |  | Object.setPrototypeOf(process, EventEmitter.prototype); | 
					
						
							| 
									
										
										
										
											2016-08-21 07:30:14 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-20 13:28:31 -07:00
										 |  |  | const { ipcRendererInternal } = require('@electron/internal/renderer/ipc-renderer-internal'); | 
					
						
							|  |  |  | const ipcRendererUtils = require('@electron/internal/renderer/ipc-renderer-internal-utils'); | 
					
						
							| 
									
										
										
										
											2018-12-05 19:07:56 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | const { | 
					
						
							| 
									
										
										
										
											2020-01-06 22:23:03 +01:00
										 |  |  |   preloadScripts, | 
					
						
							|  |  |  |   isRemoteModuleEnabled, | 
					
						
							|  |  |  |   isWebViewTagEnabled, | 
					
						
							|  |  |  |   guestInstanceId, | 
					
						
							|  |  |  |   openerId, | 
					
						
							|  |  |  |   process: processProps | 
					
						
							| 
									
										
										
										
											2020-03-20 13:28:31 -07:00
										 |  |  | } = ipcRendererUtils.invokeSync('ELECTRON_BROWSER_SANDBOX_LOAD'); | 
					
						
							| 
									
										
										
										
											2018-12-05 19:07:56 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-20 13:28:31 -07:00
										 |  |  | process.isRemoteModuleEnabled = isRemoteModuleEnabled; | 
					
						
							| 
									
										
										
										
											2018-12-05 19:07:56 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-18 12:37:06 -07:00
										 |  |  | // The electron module depends on process.electronBinding
 | 
					
						
							| 
									
										
										
										
											2020-03-20 13:28:31 -07:00
										 |  |  | const electron = require('electron'); | 
					
						
							| 
									
										
										
										
											2018-12-05 19:07:56 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-21 09:56:05 -03:00
										 |  |  | const loadedModules = new Map([ | 
					
						
							| 
									
										
										
										
											2017-03-21 10:41:23 -03:00
										 |  |  |   ['electron', electron], | 
					
						
							| 
									
										
										
										
											2018-05-04 18:51:32 +02:00
										 |  |  |   ['events', events], | 
					
						
							| 
									
										
										
										
											2018-05-21 09:56:05 -03:00
										 |  |  |   ['timers', require('timers')], | 
					
						
							|  |  |  |   ['url', require('url')] | 
					
						
							| 
									
										
										
										
											2020-03-20 13:28:31 -07:00
										 |  |  | ]); | 
					
						
							| 
									
										
										
										
											2016-08-21 07:30:14 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-02 15:38:16 -07:00
										 |  |  | // ElectronApiServiceImpl will look for the "ipcNative" hidden object when
 | 
					
						
							|  |  |  | // invoking the 'onMessage' callback.
 | 
					
						
							|  |  |  | v8Util.setHiddenValue(global, 'ipcNative', { | 
					
						
							| 
									
										
										
										
											2020-03-11 18:07:54 -07:00
										 |  |  |   onMessage (internal, channel, ports, args, senderId) { | 
					
						
							| 
									
										
										
										
											2020-03-20 13:28:31 -07:00
										 |  |  |     const sender = internal ? ipcRendererInternal : electron.ipcRenderer; | 
					
						
							|  |  |  |     sender.emit(channel, { sender, senderId, ports }, ...args); | 
					
						
							| 
									
										
										
										
											2019-01-23 17:24:57 +01:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2020-03-20 13:28:31 -07:00
										 |  |  | }); | 
					
						
							| 
									
										
										
										
											2019-03-07 19:00:28 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-13 14:32:29 -07:00
										 |  |  | // ElectronSandboxedRendererClient will look for the "lifecycle" hidden object when
 | 
					
						
							| 
									
										
										
										
											2019-04-02 15:38:16 -07:00
										 |  |  | v8Util.setHiddenValue(global, 'lifecycle', { | 
					
						
							| 
									
										
										
										
											2019-04-04 20:35:06 +02:00
										 |  |  |   onLoaded () { | 
					
						
							| 
									
										
										
										
											2020-03-20 13:28:31 -07:00
										 |  |  |     process.emit('loaded'); | 
					
						
							| 
									
										
										
										
											2019-04-04 20:35:06 +02:00
										 |  |  |   }, | 
					
						
							| 
									
										
										
										
											2019-04-02 15:38:16 -07:00
										 |  |  |   onExit () { | 
					
						
							| 
									
										
										
										
											2020-03-20 13:28:31 -07:00
										 |  |  |     process.emit('exit'); | 
					
						
							| 
									
										
										
										
											2019-04-02 15:38:16 -07:00
										 |  |  |   }, | 
					
						
							|  |  |  |   onDocumentStart () { | 
					
						
							| 
									
										
										
										
											2020-03-20 13:28:31 -07:00
										 |  |  |     process.emit('document-start'); | 
					
						
							| 
									
										
										
										
											2019-04-02 15:38:16 -07:00
										 |  |  |   }, | 
					
						
							|  |  |  |   onDocumentEnd () { | 
					
						
							| 
									
										
										
										
											2020-03-20 13:28:31 -07:00
										 |  |  |     process.emit('document-end'); | 
					
						
							| 
									
										
										
										
											2019-04-02 15:38:16 -07:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2020-03-20 13:28:31 -07:00
										 |  |  | }); | 
					
						
							| 
									
										
										
										
											2019-03-07 19:00:28 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-20 13:28:31 -07:00
										 |  |  | const { webFrameInit } = require('@electron/internal/renderer/web-frame-init'); | 
					
						
							|  |  |  | webFrameInit(); | 
					
						
							| 
									
										
										
										
											2018-04-11 18:57:40 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-27 14:14:36 -03:00
										 |  |  | // Pass different process object to the preload script(which should not have
 | 
					
						
							| 
									
										
										
										
											2019-03-18 12:37:06 -07:00
										 |  |  | // access to things like `process.electronBinding`).
 | 
					
						
							| 
									
										
										
										
											2020-03-20 13:28:31 -07:00
										 |  |  | const preloadProcess = new EventEmitter(); | 
					
						
							| 
									
										
										
										
											2018-09-26 07:44:55 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-20 13:28:31 -07:00
										 |  |  | Object.assign(preloadProcess, binding.process); | 
					
						
							|  |  |  | Object.assign(preloadProcess, processProps); | 
					
						
							| 
									
										
										
										
											2018-09-30 23:24:00 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-20 13:28:31 -07:00
										 |  |  | Object.assign(process, binding.process); | 
					
						
							|  |  |  | Object.assign(process, processProps); | 
					
						
							| 
									
										
										
										
											2018-05-21 09:56:05 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-05 10:34:09 +01:00
										 |  |  | Object.defineProperty(preloadProcess, 'noDeprecation', { | 
					
						
							|  |  |  |   get () { | 
					
						
							| 
									
										
										
										
											2020-03-20 13:28:31 -07:00
										 |  |  |     return process.noDeprecation; | 
					
						
							| 
									
										
										
										
											2018-12-05 10:34:09 +01:00
										 |  |  |   }, | 
					
						
							|  |  |  |   set (value) { | 
					
						
							| 
									
										
										
										
											2020-03-20 13:28:31 -07:00
										 |  |  |     process.noDeprecation = value; | 
					
						
							| 
									
										
										
										
											2018-12-05 10:34:09 +01:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2020-03-20 13:28:31 -07:00
										 |  |  | }); | 
					
						
							| 
									
										
										
										
											2018-12-05 10:34:09 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-20 13:28:31 -07:00
										 |  |  | process.on('loaded', () => preloadProcess.emit('loaded')); | 
					
						
							|  |  |  | process.on('exit', () => preloadProcess.emit('exit')); | 
					
						
							|  |  |  | process.on('document-start', () => preloadProcess.emit('document-start')); | 
					
						
							|  |  |  | process.on('document-end', () => preloadProcess.emit('document-end')); | 
					
						
							| 
									
										
										
										
											2017-02-27 14:14:36 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | // This is the `require` function that will be visible to the preload script
 | 
					
						
							| 
									
										
										
										
											2016-08-21 07:30:14 -03:00
										 |  |  | function preloadRequire (module) { | 
					
						
							| 
									
										
										
										
											2018-05-21 09:56:05 -03:00
										 |  |  |   if (loadedModules.has(module)) { | 
					
						
							| 
									
										
										
										
											2020-03-20 13:28:31 -07:00
										 |  |  |     return loadedModules.get(module); | 
					
						
							| 
									
										
										
										
											2018-05-21 09:56:05 -03:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2020-03-20 13:28:31 -07:00
										 |  |  |   throw new Error(`module not found: ${module}`); | 
					
						
							| 
									
										
										
										
											2016-08-21 07:30:14 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-22 02:08:16 +01:00
										 |  |  | // Process command line arguments.
 | 
					
						
							| 
									
										
										
										
											2020-03-20 13:28:31 -07:00
										 |  |  | const { hasSwitch } = process.electronBinding('command_line'); | 
					
						
							| 
									
										
										
										
											2019-01-03 17:22:34 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-15 11:57:40 -07:00
										 |  |  | // Similar to nodes --expose-internals flag, this exposes electronBinding so
 | 
					
						
							|  |  |  | // that tests can call it to get access to some test only bindings
 | 
					
						
							|  |  |  | if (hasSwitch('unsafely-expose-electron-internals-for-testing')) { | 
					
						
							|  |  |  |   preloadProcess.electronBinding = process.electronBinding; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-20 13:28:31 -07:00
										 |  |  | const contextIsolation = hasSwitch('context-isolation'); | 
					
						
							|  |  |  | const isHiddenPage = hasSwitch('hidden-page'); | 
					
						
							|  |  |  | const rendererProcessReuseEnabled = hasSwitch('disable-electron-site-instance-overrides'); | 
					
						
							|  |  |  | const usesNativeWindowOpen = true; | 
					
						
							| 
									
										
										
										
											2020-01-06 22:23:03 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-22 04:56:58 +11:00
										 |  |  | switch (window.location.protocol) { | 
					
						
							| 
									
										
										
										
											2019-05-17 15:37:09 -07:00
										 |  |  |   case 'devtools:': { | 
					
						
							| 
									
										
										
										
											2018-11-22 04:56:58 +11:00
										 |  |  |     // Override some inspector APIs.
 | 
					
						
							| 
									
										
										
										
											2020-03-20 13:28:31 -07:00
										 |  |  |     require('@electron/internal/renderer/inspector'); | 
					
						
							|  |  |  |     break; | 
					
						
							| 
									
										
										
										
											2018-11-22 04:56:58 +11:00
										 |  |  |   } | 
					
						
							|  |  |  |   case 'chrome-extension:': { | 
					
						
							| 
									
										
										
										
											2020-03-20 13:28:31 -07:00
										 |  |  |     break; | 
					
						
							| 
									
										
										
										
											2018-11-22 04:56:58 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-03-07 19:00:28 -05:00
										 |  |  |   case 'chrome': { | 
					
						
							| 
									
										
										
										
											2020-03-20 13:28:31 -07:00
										 |  |  |     break; | 
					
						
							| 
									
										
										
										
											2019-03-07 19:00:28 -05:00
										 |  |  |   } | 
					
						
							|  |  |  |   default: { | 
					
						
							| 
									
										
										
										
											2020-01-06 22:23:03 +01:00
										 |  |  |     // Override default web functions.
 | 
					
						
							| 
									
										
										
										
											2020-03-20 13:28:31 -07:00
										 |  |  |     const { windowSetup } = require('@electron/internal/renderer/window-setup'); | 
					
						
							|  |  |  |     windowSetup(guestInstanceId, openerId, isHiddenPage, usesNativeWindowOpen, rendererProcessReuseEnabled); | 
					
						
							| 
									
										
										
										
											2019-03-07 19:00:28 -05:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2018-03-22 00:15:57 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-22 02:08:16 +01:00
										 |  |  | // Load webview tag implementation.
 | 
					
						
							| 
									
										
										
										
											2019-01-24 19:53:16 +01:00
										 |  |  | if (process.isMainFrame) { | 
					
						
							| 
									
										
										
										
											2020-03-20 13:28:31 -07:00
										 |  |  |   const { webViewInit } = require('@electron/internal/renderer/web-view/web-view-init'); | 
					
						
							|  |  |  |   webViewInit(contextIsolation, isWebViewTagEnabled, guestInstanceId); | 
					
						
							| 
									
										
										
										
											2019-01-24 19:53:16 +01:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2018-07-02 09:06:26 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-27 14:14:36 -03:00
										 |  |  | // Wrap the script into a function executed in global scope. It won't have
 | 
					
						
							|  |  |  | // access to the current scope, so we'll expose a few objects as arguments:
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // - `require`: The `preloadRequire` function
 | 
					
						
							|  |  |  | // - `process`: The `preloadProcess` object
 | 
					
						
							| 
									
										
										
										
											2019-06-02 13:03:03 -07:00
										 |  |  | // - `Buffer`: Shim of `Buffer` implementation
 | 
					
						
							|  |  |  | // - `global`: The window object, which is aliased to `global` by webpack.
 | 
					
						
							| 
									
										
										
										
											2019-01-18 12:03:43 +01:00
										 |  |  | function runPreloadScript (preloadSrc) { | 
					
						
							| 
									
										
										
										
											2019-03-12 00:13:46 +01:00
										 |  |  |   const preloadWrapperSrc = `(function(require, process, Buffer, global, setImmediate, clearImmediate, exports) {
 | 
					
						
							| 
									
										
										
										
											2018-03-22 00:15:57 -07:00
										 |  |  |   ${preloadSrc} | 
					
						
							| 
									
										
										
										
											2020-03-20 13:28:31 -07:00
										 |  |  |   })`;
 | 
					
						
							| 
									
										
										
										
											2016-08-21 07:30:14 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-12 21:17:11 -05:00
										 |  |  |   // eval in window scope
 | 
					
						
							| 
									
										
										
										
											2020-03-20 13:28:31 -07:00
										 |  |  |   const preloadFn = binding.createPreloadScript(preloadWrapperSrc); | 
					
						
							|  |  |  |   const { setImmediate, clearImmediate } = require('timers'); | 
					
						
							| 
									
										
										
										
											2019-01-18 12:03:43 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-20 13:28:31 -07:00
										 |  |  |   preloadFn(preloadRequire, preloadProcess, Buffer, global, setImmediate, clearImmediate, {}); | 
					
						
							| 
									
										
										
										
											2019-01-18 12:03:43 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-29 02:16:46 +01:00
										 |  |  | for (const { preloadPath, preloadSrc, preloadError } of preloadScripts) { | 
					
						
							|  |  |  |   try { | 
					
						
							|  |  |  |     if (preloadSrc) { | 
					
						
							| 
									
										
										
										
											2020-03-20 13:28:31 -07:00
										 |  |  |       runPreloadScript(preloadSrc); | 
					
						
							| 
									
										
										
										
											2019-01-29 02:16:46 +01:00
										 |  |  |     } else if (preloadError) { | 
					
						
							| 
									
										
										
										
											2020-03-20 13:28:31 -07:00
										 |  |  |       throw preloadError; | 
					
						
							| 
									
										
										
										
											2019-01-29 02:16:46 +01:00
										 |  |  |     } | 
					
						
							|  |  |  |   } catch (error) { | 
					
						
							| 
									
										
										
										
											2020-03-20 13:28:31 -07:00
										 |  |  |     console.error(`Unable to load preload script: ${preloadPath}`); | 
					
						
							|  |  |  |     console.error(error); | 
					
						
							| 
									
										
										
										
											2019-01-29 02:16:46 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-20 13:28:31 -07:00
										 |  |  |     ipcRendererInternal.send('ELECTRON_BROWSER_PRELOAD_ERROR', preloadPath, error); | 
					
						
							| 
									
										
										
										
											2019-01-18 12:03:43 +01:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2018-03-22 00:15:57 -07:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2018-10-03 21:36:12 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | // Warn about security issues
 | 
					
						
							| 
									
										
										
										
											2019-01-24 19:53:16 +01:00
										 |  |  | if (process.isMainFrame) { | 
					
						
							| 
									
										
										
										
											2020-03-20 13:28:31 -07:00
										 |  |  |   const { securityWarnings } = require('@electron/internal/renderer/security-warnings'); | 
					
						
							|  |  |  |   securityWarnings(); | 
					
						
							| 
									
										
										
										
											2019-01-24 19:53:16 +01:00
										 |  |  | } |