Add new-webview event that can be prevented
This commit is contained in:
parent
706b9f6cbf
commit
7eda8fbdfb
1 changed files with 11 additions and 2 deletions
|
@ -147,7 +147,8 @@ const createGuest = function (embedder, params) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Attach the guest to an element of embedder.
|
// Attach the guest to an element of embedder.
|
||||||
const attachGuest = function (embedder, elementInstanceId, guestInstanceId, params) {
|
const attachGuest = function (event, elementInstanceId, guestInstanceId, params) {
|
||||||
|
const embedder = event.sender
|
||||||
// Destroy the old guest when attaching.
|
// Destroy the old guest when attaching.
|
||||||
const key = `${embedder.getId()}-${elementInstanceId}`
|
const key = `${embedder.getId()}-${elementInstanceId}`
|
||||||
const oldGuestInstanceId = embedderElementsMap[key]
|
const oldGuestInstanceId = embedderElementsMap[key]
|
||||||
|
@ -204,6 +205,14 @@ const attachGuest = function (embedder, elementInstanceId, guestInstanceId, para
|
||||||
if (params.preload) {
|
if (params.preload) {
|
||||||
webPreferences.preloadURL = params.preload
|
webPreferences.preloadURL = params.preload
|
||||||
}
|
}
|
||||||
|
|
||||||
|
event.sender.emit('new-webview', event, guest, webPreferences)
|
||||||
|
if (event.defaultPrevented) {
|
||||||
|
if (guest.viewInstanceId == null) guest.viewInstanceId = params.instanceId
|
||||||
|
destroyGuest(embedder, guestInstanceId)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
webViewManager.addGuest(guestInstanceId, elementInstanceId, embedder, guest, webPreferences)
|
webViewManager.addGuest(guestInstanceId, elementInstanceId, embedder, guest, webPreferences)
|
||||||
guest.attachParams = params
|
guest.attachParams = params
|
||||||
embedderElementsMap[key] = guestInstanceId
|
embedderElementsMap[key] = guestInstanceId
|
||||||
|
@ -276,7 +285,7 @@ ipcMain.on('ELECTRON_GUEST_VIEW_MANAGER_CREATE_GUEST', function (event, params,
|
||||||
})
|
})
|
||||||
|
|
||||||
ipcMain.on('ELECTRON_GUEST_VIEW_MANAGER_ATTACH_GUEST', function (event, elementInstanceId, guestInstanceId, params) {
|
ipcMain.on('ELECTRON_GUEST_VIEW_MANAGER_ATTACH_GUEST', function (event, elementInstanceId, guestInstanceId, params) {
|
||||||
attachGuest(event.sender, elementInstanceId, guestInstanceId, params)
|
attachGuest(event, elementInstanceId, guestInstanceId, params)
|
||||||
})
|
})
|
||||||
|
|
||||||
ipcMain.on('ELECTRON_GUEST_VIEW_MANAGER_DESTROY_GUEST', function (event, guestInstanceId) {
|
ipcMain.on('ELECTRON_GUEST_VIEW_MANAGER_DESTROY_GUEST', function (event, guestInstanceId) {
|
||||||
|
|
Loading…
Reference in a new issue