Use template strings
This commit is contained in:
parent
712b15286c
commit
48bcad87c2
3 changed files with 28 additions and 33 deletions
|
@ -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) {
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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 <webview> has actually
|
||||
// changed.
|
||||
|
@ -191,7 +191,7 @@ const WebViewImpl = (function () {
|
|||
// Adds an 'on<event>' 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 <object> node fills in the <webview> container.
|
||||
this.style.flex = '1 1 auto'
|
||||
|
|
Loading…
Reference in a new issue