From ebf977326992eafad08f1af7ddb18d44aaba7237 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 9 Jun 2016 10:35:48 -0700 Subject: [PATCH] Use const/let and removes CoffeeScript ref vars --- lib/browser/guest-window-manager.js | 56 ++++++++++++++++++++++--------------- 1 file changed, 33 insertions(+), 23 deletions(-) diff --git a/lib/browser/guest-window-manager.js b/lib/browser/guest-window-manager.js index a3d60be..c3767ad 100644 --- a/lib/browser/guest-window-manager.js +++ b/lib/browser/guest-window-manager.js @@ -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) + } + } }) -- 2.7.4