diff --git a/lib/browser/guest-view-manager.js b/lib/browser/guest-view-manager.js index 4183e178daa7..a1ed7b940886 100644 --- a/lib/browser/guest-view-manager.js +++ b/lib/browser/guest-view-manager.js @@ -108,14 +108,17 @@ const createGuest = function (embedder, params) { guest.allowPopups = params.allowpopups }) + const sendToEmbedder = (channel, ...args) => { + const embedder = getEmbedder(guestInstanceId) + if (embedder) { + embedder.send(`${channel}-${guest.viewInstanceId}`, ...args) + } + } + // Dispatch events to embedder. const fn = function (event) { guest.on(event, function (_, ...args) { - const embedder = getEmbedder(guestInstanceId) - if (!embedder) { - return - } - embedder.send.apply(embedder, ['ELECTRON_GUEST_VIEW_INTERNAL_DISPATCH_EVENT-' + guest.viewInstanceId, event].concat(args)) + sendToEmbedder('ELECTRON_GUEST_VIEW_INTERNAL_DISPATCH_EVENT', event, ...args) }) } for (const event of supportedWebViewEvents) { @@ -124,20 +127,12 @@ const createGuest = function (embedder, params) { // Dispatch guest's IPC messages to embedder. guest.on('ipc-message-host', function (_, [channel, ...args]) { - const embedder = getEmbedder(guestInstanceId) - if (!embedder) { - return - } - embedder.send.apply(embedder, ['ELECTRON_GUEST_VIEW_INTERNAL_IPC_MESSAGE-' + guest.viewInstanceId, channel].concat(args)) + sendToEmbedder('ELECTRON_GUEST_VIEW_INTERNAL_IPC_MESSAGE', channel, ...args) }) // Autosize. guest.on('size-changed', function (_, ...args) { - const embedder = getEmbedder(guestInstanceId) - if (!embedder) { - return - } - embedder.send.apply(embedder, ['ELECTRON_GUEST_VIEW_INTERNAL_SIZE_CHANGED-' + guest.viewInstanceId].concat(args)) + sendToEmbedder('ELECTRON_GUEST_VIEW_INTERNAL_SIZE_CHANGED', ...args) }) return guestInstanceId @@ -146,7 +141,7 @@ const createGuest = function (embedder, params) { // Attach the guest to an element of embedder. const attachGuest = function (embedder, elementInstanceId, guestInstanceId, params) { // Destroy the old guest when attaching. - const key = (embedder.getId()) + '-' + elementInstanceId + const key = `${embedder.getId()}-${elementInstanceId}` const oldGuestInstanceId = embedderElementsMap[key] if (oldGuestInstanceId != null) { // Reattachment to the same guest is just a no-op. @@ -166,10 +161,10 @@ const attachGuest = function (embedder, elementInstanceId, guestInstanceId, para // If this guest is already attached to an element then remove it if (guestInstance.elementInstanceId) { - const oldKey = (guestInstance.embedder.getId()) + '-' + guestInstance.elementInstanceId + const oldKey = `${guestInstance.embedder.getId()}-${guestInstance.elementInstanceId}` delete embedderElementsMap[oldKey] webViewManager.removeGuest(guestInstance.embedder, guestInstanceId) - guestInstance.embedder.send('ELECTRON_GUEST_VIEW_INTERNAL_DESTROY_GUEST-' + guest.viewInstanceId) + guestInstance.embedder.send(`ELECTRON_GUEST_VIEW_INTERNAL_DESTROY_GUEST-${guest.viewInstanceId}`) } const webPreferences = { @@ -223,7 +218,7 @@ const destroyGuest = function (embedder, guestInstanceId) { guestInstance.guest.destroy() delete guestInstances[guestInstanceId] - const key = embedder.getId() + '-' + guestInstance.elementInstanceId + const key = `${embedder.getId()}-${guestInstance.elementInstanceId}` delete embedderElementsMap[key] } @@ -265,7 +260,7 @@ const watchEmbedder = function (embedder) { } ipcMain.on('ELECTRON_GUEST_VIEW_MANAGER_CREATE_GUEST', function (event, params, requestId) { - event.sender.send('ELECTRON_RESPONSE_' + requestId, createGuest(event.sender, params)) + event.sender.send(`ELECTRON_RESPONSE_${requestId}`, createGuest(event.sender, params)) }) ipcMain.on('ELECTRON_GUEST_VIEW_MANAGER_ATTACH_GUEST', function (event, elementInstanceId, guestInstanceId, params) { diff --git a/lib/renderer/web-view/guest-view-internal.js b/lib/renderer/web-view/guest-view-internal.js index 1f3ba1b193a9..2d2b269e1989 100644 --- a/lib/renderer/web-view/guest-view-internal.js +++ b/lib/renderer/web-view/guest-view-internal.js @@ -62,7 +62,7 @@ const dispatchEvent = function (webView, eventName, eventKey, ...args) { module.exports = { registerEvents: function (webView, viewInstanceId) { - ipcRenderer.on('ELECTRON_GUEST_VIEW_INTERNAL_DESTROY_GUEST-' + viewInstanceId, function () { + ipcRenderer.on(`ELECTRON_GUEST_VIEW_INTERNAL_DESTROY_GUEST-${viewInstanceId}`, function () { webFrame.detachGuest(webView.internalInstanceId) webView.guestInstanceId = undefined webView.reset() @@ -70,18 +70,18 @@ module.exports = { webView.dispatchEvent(domEvent) }) - ipcRenderer.on('ELECTRON_GUEST_VIEW_INTERNAL_DISPATCH_EVENT-' + viewInstanceId, function (event, eventName, ...args) { + ipcRenderer.on(`ELECTRON_GUEST_VIEW_INTERNAL_DISPATCH_EVENT-${viewInstanceId}`, function (event, eventName, ...args) { dispatchEvent.apply(null, [webView, eventName, eventName].concat(args)) }) - ipcRenderer.on('ELECTRON_GUEST_VIEW_INTERNAL_IPC_MESSAGE-' + viewInstanceId, function (event, channel, ...args) { + ipcRenderer.on(`ELECTRON_GUEST_VIEW_INTERNAL_IPC_MESSAGE-${viewInstanceId}`, function (event, channel, ...args) { const domEvent = new Event('ipc-message') domEvent.channel = channel domEvent.args = args webView.dispatchEvent(domEvent) }) - ipcRenderer.on('ELECTRON_GUEST_VIEW_INTERNAL_SIZE_CHANGED-' + viewInstanceId, function (event, ...args) { + ipcRenderer.on(`ELECTRON_GUEST_VIEW_INTERNAL_SIZE_CHANGED-${viewInstanceId}`, function (event, ...args) { let f, i, j, len const domEvent = new Event('size-changed') const props = ['oldWidth', 'oldHeight', 'newWidth', 'newHeight'] @@ -93,15 +93,15 @@ module.exports = { }) }, deregisterEvents: function (viewInstanceId) { - ipcRenderer.removeAllListeners('ELECTRON_GUEST_VIEW_INTERNAL_DESTROY_GUEST-' + viewInstanceId) - ipcRenderer.removeAllListeners('ELECTRON_GUEST_VIEW_INTERNAL_DISPATCH_EVENT-' + viewInstanceId) - ipcRenderer.removeAllListeners('ELECTRON_GUEST_VIEW_INTERNAL_IPC_MESSAGE-' + viewInstanceId) - ipcRenderer.removeAllListeners('ELECTRON_GUEST_VIEW_INTERNAL_SIZE_CHANGED-' + viewInstanceId) + ipcRenderer.removeAllListeners(`ELECTRON_GUEST_VIEW_INTERNAL_DESTROY_GUEST-${viewInstanceId}`) + ipcRenderer.removeAllListeners(`ELECTRON_GUEST_VIEW_INTERNAL_DISPATCH_EVENT-${viewInstanceId}`) + ipcRenderer.removeAllListeners(`ELECTRON_GUEST_VIEW_INTERNAL_IPC_MESSAGE-${viewInstanceId}`) + ipcRenderer.removeAllListeners(`ELECTRON_GUEST_VIEW_INTERNAL_SIZE_CHANGED-${viewInstanceId}`) }, createGuest: function (params, callback) { requestId++ ipcRenderer.send('ELECTRON_GUEST_VIEW_MANAGER_CREATE_GUEST', params, requestId) - ipcRenderer.once('ELECTRON_RESPONSE_' + requestId, callback) + ipcRenderer.once(`ELECTRON_RESPONSE_${requestId}`, callback) }, attachGuest: function (elementInstanceId, guestInstanceId, params) { ipcRenderer.send('ELECTRON_GUEST_VIEW_MANAGER_ATTACH_GUEST', elementInstanceId, guestInstanceId, params) diff --git a/lib/renderer/web-view/web-view.js b/lib/renderer/web-view/web-view.js index b6818e344aad..03b44e12e49d 100644 --- a/lib/renderer/web-view/web-view.js +++ b/lib/renderer/web-view/web-view.js @@ -148,8 +148,8 @@ const WebViewImpl = (function () { minWidth = Math.min(minWidth, maxWidth) minHeight = Math.min(minHeight, maxHeight) if (!this.attributes[webViewConstants.ATTRIBUTE_AUTOSIZE].getValue() || (newWidth >= minWidth && newWidth <= maxWidth && newHeight >= minHeight && newHeight <= maxHeight)) { - node.style.width = newWidth + 'px' - node.style.height = newHeight + 'px' + node.style.width = `${newWidth}px` + node.style.height = `${newHeight}px` // Only fire the DOM event if the size of the has actually // changed. @@ -191,7 +191,7 @@ const WebViewImpl = (function () { // Adds an 'on' property on the webview, which can be used to set/unset // an event handler. WebViewImpl.prototype.setupEventProperty = function (eventName) { - const propertyName = 'on' + eventName.toLowerCase() + const propertyName = `on${eventName.toLowerCase()}` return Object.defineProperty(this.webviewNode, propertyName, { get: () => { return this.on[propertyName] @@ -267,7 +267,7 @@ const registerBrowserPluginElement = function () { const proto = Object.create(HTMLObjectElement.prototype) proto.createdCallback = function () { this.setAttribute('type', 'application/browser-plugin') - this.setAttribute('id', 'browser-plugin-' + getNextId()) + this.setAttribute('id', `browser-plugin-${getNextId()}`) // The node fills in the container. this.style.flex = '1 1 auto'