|
@@ -1,23 +1,27 @@
|
|
|
'use strict'
|
|
|
|
|
|
-const ipcRenderer = require('electron').ipcRenderer
|
|
|
-const remote = require('electron').remote
|
|
|
+const {ipcRenderer} = require('electron')
|
|
|
+
|
|
|
+const {defineProperty} = Object
|
|
|
|
|
|
// Helper function to resolve relative url.
|
|
|
-var a = window.top.document.createElement('a')
|
|
|
-var resolveURL = function (url) {
|
|
|
+const a = window.top.document.createElement('a')
|
|
|
+const resolveURL = function (url) {
|
|
|
a.href = url
|
|
|
return a.href
|
|
|
}
|
|
|
|
|
|
// Window object returned by "window.open".
|
|
|
-var BrowserWindowProxy = (function () {
|
|
|
+const BrowserWindowProxy = (function () {
|
|
|
BrowserWindowProxy.proxies = {}
|
|
|
|
|
|
BrowserWindowProxy.getOrCreate = function (guestId) {
|
|
|
- var base = this.proxies
|
|
|
- base[guestId] != null ? base[guestId] : base[guestId] = new BrowserWindowProxy(guestId)
|
|
|
- return base[guestId]
|
|
|
+ let proxy = this.proxies[guestId]
|
|
|
+ if (proxy == null) {
|
|
|
+ proxy = new BrowserWindowProxy(guestId)
|
|
|
+ this.proxies[guestId] = proxy
|
|
|
+ }
|
|
|
+ return proxy
|
|
|
}
|
|
|
|
|
|
BrowserWindowProxy.remove = function (guestId) {
|
|
@@ -25,7 +29,7 @@ var BrowserWindowProxy = (function () {
|
|
|
}
|
|
|
|
|
|
function BrowserWindowProxy (guestId1) {
|
|
|
- Object.defineProperty(this, 'guestId', {
|
|
|
+ defineProperty(this, 'guestId', {
|
|
|
configurable: false,
|
|
|
enumerable: true,
|
|
|
writeable: false,
|
|
@@ -55,7 +59,7 @@ var BrowserWindowProxy = (function () {
|
|
|
ipcRenderer.send('ELECTRON_GUEST_WINDOW_MANAGER_WEB_CONTENTS_METHOD', this.guestId, 'print')
|
|
|
}
|
|
|
|
|
|
- Object.defineProperty(BrowserWindowProxy.prototype, 'location', {
|
|
|
+ defineProperty(BrowserWindowProxy.prototype, 'location', {
|
|
|
get: function () {
|
|
|
return ipcRenderer.sendSync('ELECTRON_GUEST_WINDOW_MANAGER_WEB_CONTENTS_METHOD_SYNC', this.guestId, 'getURL')
|
|
|
},
|
|
@@ -73,7 +77,7 @@ var BrowserWindowProxy = (function () {
|
|
|
}
|
|
|
|
|
|
BrowserWindowProxy.prototype['eval'] = function (...args) {
|
|
|
- ipcRenderer.send.apply(ipcRenderer, ['ELECTRON_GUEST_WINDOW_MANAGER_WEB_CONTENTS_METHOD', this.guestId, 'executeJavaScript'].concat(args))
|
|
|
+ ipcRenderer.send('ELECTRON_GUEST_WINDOW_MANAGER_WEB_CONTENTS_METHOD', this.guestId, 'executeJavaScript', ...args)
|
|
|
}
|
|
|
|
|
|
return BrowserWindowProxy
|
|
@@ -82,7 +86,7 @@ var BrowserWindowProxy = (function () {
|
|
|
if (process.guestInstanceId == null) {
|
|
|
// Override default window.close.
|
|
|
window.close = function () {
|
|
|
- return remote.getCurrentWindow().close()
|
|
|
+ ipcRenderer.sendSync('ELECTRON_BROWSER_WINDOW_CLOSE')
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -158,29 +162,12 @@ window.open = function (url, frameName, features) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-// Use the dialog API to implement alert().
|
|
|
-window.alert = function (message = '', title = '') {
|
|
|
- remote.dialog.showMessageBox(remote.getCurrentWindow(), {
|
|
|
- message: String(message),
|
|
|
- title: String(title),
|
|
|
- buttons: ['OK']
|
|
|
- })
|
|
|
+window.alert = function (message, title) {
|
|
|
+ ipcRenderer.sendSync('ELECTRON_BROWSER_WINDOW_ALERT', message, title)
|
|
|
}
|
|
|
|
|
|
-// And the confirm().
|
|
|
window.confirm = function (message, title) {
|
|
|
- var buttons, cancelId
|
|
|
- if (title == null) {
|
|
|
- title = ''
|
|
|
- }
|
|
|
- buttons = ['OK', 'Cancel']
|
|
|
- cancelId = 1
|
|
|
- return !remote.dialog.showMessageBox(remote.getCurrentWindow(), {
|
|
|
- message: message,
|
|
|
- title: title,
|
|
|
- buttons: buttons,
|
|
|
- cancelId: cancelId
|
|
|
- })
|
|
|
+ return ipcRenderer.sendSync('ELECTRON_BROWSER_WINDOW_CONFIRM', message, title)
|
|
|
}
|
|
|
|
|
|
// But we do not support prompt().
|
|
@@ -205,11 +192,11 @@ ipcRenderer.on('ELECTRON_GUEST_WINDOW_POSTMESSAGE', function (event, sourceId, m
|
|
|
|
|
|
// Forward history operations to browser.
|
|
|
var sendHistoryOperation = function (...args) {
|
|
|
- ipcRenderer.send.apply(ipcRenderer, ['ELECTRON_NAVIGATION_CONTROLLER'].concat(args))
|
|
|
+ ipcRenderer.send('ELECTRON_NAVIGATION_CONTROLLER', ...args)
|
|
|
}
|
|
|
|
|
|
var getHistoryOperation = function (...args) {
|
|
|
- return ipcRenderer.sendSync.apply(ipcRenderer, ['ELECTRON_SYNC_NAVIGATION_CONTROLLER'].concat(args))
|
|
|
+ return ipcRenderer.sendSync('ELECTRON_SYNC_NAVIGATION_CONTROLLER', ...args)
|
|
|
}
|
|
|
|
|
|
window.history.back = function () {
|
|
@@ -224,7 +211,7 @@ window.history.go = function (offset) {
|
|
|
sendHistoryOperation('goToOffset', offset)
|
|
|
}
|
|
|
|
|
|
-Object.defineProperty(window.history, 'length', {
|
|
|
+defineProperty(window.history, 'length', {
|
|
|
get: function () {
|
|
|
return getHistoryOperation('length')
|
|
|
}
|
|
@@ -242,13 +229,13 @@ ipcRenderer.on('ELECTRON_RENDERER_WINDOW_VISIBILITY_CHANGE', function (event, vi
|
|
|
})
|
|
|
|
|
|
// Make document.hidden and document.visibilityState return the correct value.
|
|
|
-Object.defineProperty(document, 'hidden', {
|
|
|
+defineProperty(document, 'hidden', {
|
|
|
get: function () {
|
|
|
return cachedVisibilityState !== 'visible'
|
|
|
}
|
|
|
})
|
|
|
|
|
|
-Object.defineProperty(document, 'visibilityState', {
|
|
|
+defineProperty(document, 'visibilityState', {
|
|
|
get: function () {
|
|
|
return cachedVisibilityState
|
|
|
}
|