Use const/let and removes CoffeeScript ref vars
This commit is contained in:
parent
a3899f17f9
commit
ebf9773269
1 changed files with 33 additions and 23 deletions
|
@ -3,12 +3,12 @@
|
|||
const ipcMain = require('electron').ipcMain
|
||||
const BrowserWindow = require('electron').BrowserWindow
|
||||
|
||||
var hasProp = {}.hasOwnProperty
|
||||
var frameToGuest = {}
|
||||
const hasProp = {}.hasOwnProperty
|
||||
const frameToGuest = {}
|
||||
|
||||
// Copy attribute of |parent| to |child| if it is not defined in |child|.
|
||||
var mergeOptions = function (child, parent) {
|
||||
var key, value
|
||||
const mergeOptions = function (child, parent) {
|
||||
let key, value
|
||||
for (key in parent) {
|
||||
if (!hasProp.call(parent, key)) continue
|
||||
value = parent[key]
|
||||
|
@ -24,7 +24,7 @@ var mergeOptions = function (child, parent) {
|
|||
}
|
||||
|
||||
// Merge |options| with the |embedder|'s window's options.
|
||||
var mergeBrowserWindowOptions = function (embedder, options) {
|
||||
const mergeBrowserWindowOptions = function (embedder, options) {
|
||||
if (embedder.browserWindowOptions != null) {
|
||||
// Inherit the original options if it is a BrowserWindow.
|
||||
mergeOptions(options, embedder.browserWindowOptions)
|
||||
|
@ -45,9 +45,8 @@ var mergeBrowserWindowOptions = function (embedder, options) {
|
|||
}
|
||||
|
||||
// Create a new guest created by |embedder| with |options|.
|
||||
var createGuest = function (embedder, url, frameName, options) {
|
||||
var closedByEmbedder, closedByUser, guest, guestId, ref1
|
||||
guest = frameToGuest[frameName]
|
||||
const createGuest = function (embedder, url, frameName, options) {
|
||||
let guest = frameToGuest[frameName]
|
||||
if (frameName && (guest != null)) {
|
||||
guest.loadURL(url)
|
||||
return guest.id
|
||||
|
@ -57,24 +56,27 @@ var createGuest = function (embedder, url, frameName, options) {
|
|||
if (options.webPreferences == null) {
|
||||
options.webPreferences = {}
|
||||
}
|
||||
options.webPreferences.openerId = (ref1 = BrowserWindow.fromWebContents(embedder)) != null ? ref1.id : void 0
|
||||
const embedderWindow = BrowserWindow.fromWebContents(embedder)
|
||||
options.webPreferences.openerId = embedderWindow != null ? embedderWindow.id : void 0
|
||||
guest = new BrowserWindow(options)
|
||||
guest.loadURL(url)
|
||||
|
||||
// When |embedder| is destroyed we should also destroy attached guest, and if
|
||||
// guest is closed by user then we should prevent |embedder| from double
|
||||
// closing guest.
|
||||
guestId = guest.id
|
||||
closedByEmbedder = function () {
|
||||
const guestId = guest.id
|
||||
|
||||
const closedByEmbedder = function () {
|
||||
guest.removeListener('closed', closedByUser)
|
||||
return guest.destroy()
|
||||
guest.destroy()
|
||||
}
|
||||
closedByUser = function () {
|
||||
const closedByUser = function () {
|
||||
embedder.send('ELECTRON_GUEST_WINDOW_MANAGER_WINDOW_CLOSED_' + guestId)
|
||||
return embedder.removeListener('render-view-deleted', closedByEmbedder)
|
||||
embedder.removeListener('render-view-deleted', closedByEmbedder)
|
||||
}
|
||||
embedder.once('render-view-deleted', closedByEmbedder)
|
||||
guest.once('closed', closedByUser)
|
||||
|
||||
if (frameName) {
|
||||
frameToGuest[frameName] = guest
|
||||
guest.frameName = frameName
|
||||
|
@ -82,6 +84,7 @@ var createGuest = function (embedder, url, frameName, options) {
|
|||
delete frameToGuest[frameName]
|
||||
})
|
||||
}
|
||||
|
||||
return guest.id
|
||||
}
|
||||
|
||||
|
@ -97,28 +100,35 @@ ipcMain.on('ELECTRON_GUEST_WINDOW_MANAGER_WINDOW_OPEN', function (event, url, fr
|
|||
})
|
||||
|
||||
ipcMain.on('ELECTRON_GUEST_WINDOW_MANAGER_WINDOW_CLOSE', function (event, guestId) {
|
||||
var ref1
|
||||
(ref1 = BrowserWindow.fromId(guestId)) != null ? ref1.destroy() : void 0
|
||||
const guestWindow = BrowserWindow.fromId(guestId)
|
||||
if (guestWindow != null) guestWindow.destroy()
|
||||
})
|
||||
|
||||
ipcMain.on('ELECTRON_GUEST_WINDOW_MANAGER_WINDOW_METHOD', function (event, guestId, method, ...args) {
|
||||
var ref1
|
||||
event.returnValue = (ref1 = BrowserWindow.fromId(guestId)) != null ? ref1[method].apply(ref1, args) : void 0
|
||||
const guestWindow = BrowserWindow.fromId(guestId)
|
||||
event.returnValue = guestWindow != null ? guestWindow[method].apply(guestWindow, args) : void 0
|
||||
})
|
||||
|
||||
ipcMain.on('ELECTRON_GUEST_WINDOW_MANAGER_WINDOW_POSTMESSAGE', function (event, guestId, message, targetOrigin, sourceOrigin) {
|
||||
var guestContents, ref1, ref2, sourceId
|
||||
sourceId = (ref1 = BrowserWindow.fromWebContents(event.sender)) != null ? ref1.id : void 0
|
||||
const sourceContents = BrowserWindow.fromWebContents(event.sender)
|
||||
const sourceId = sourceContents != null ? sourceContents.id : void 0
|
||||
if (sourceId == null) {
|
||||
return
|
||||
}
|
||||
guestContents = (ref2 = BrowserWindow.fromId(guestId)) != null ? ref2.webContents : void 0
|
||||
|
||||
const guestWindow = BrowserWindow.fromId(guestId)
|
||||
const guestContents = guestWindow != null ? guestWindow.webContents : void 0
|
||||
if ((guestContents != null ? guestContents.getURL().indexOf(targetOrigin) : void 0) === 0 || targetOrigin === '*') {
|
||||
guestContents != null ? guestContents.send('ELECTRON_GUEST_WINDOW_POSTMESSAGE', sourceId, message, sourceOrigin) : void 0
|
||||
}
|
||||
})
|
||||
|
||||
ipcMain.on('ELECTRON_GUEST_WINDOW_MANAGER_WEB_CONTENTS_METHOD', function (event, guestId, method, ...args) {
|
||||
var ref1, ref2
|
||||
(ref1 = BrowserWindow.fromId(guestId)) != null ? (ref2 = ref1.webContents) != null ? ref2[method].apply(ref2, args) : void 0 : void 0
|
||||
const guestWindow = BrowserWindow.fromId(guestId)
|
||||
if (guestWindow != null) {
|
||||
const guestContents = guestWindow.webContents
|
||||
if (guestContents != null) {
|
||||
guestContents[method].apply(guestContents, args)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue