diff --git a/lib/browser/guest-view-manager.js b/lib/browser/guest-view-manager.js index 500ed37bbbf0..95e4e0d47f8d 100644 --- a/lib/browser/guest-view-manager.js +++ b/lib/browser/guest-view-manager.js @@ -147,7 +147,8 @@ const createGuest = function (embedder, params) { } // 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. const key = `${embedder.getId()}-${elementInstanceId}` const oldGuestInstanceId = embedderElementsMap[key] @@ -204,6 +205,14 @@ const attachGuest = function (embedder, elementInstanceId, guestInstanceId, para if (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) guest.attachParams = params 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) { - attachGuest(event.sender, elementInstanceId, guestInstanceId, params) + attachGuest(event, elementInstanceId, guestInstanceId, params) }) ipcMain.on('ELECTRON_GUEST_VIEW_MANAGER_DESTROY_GUEST', function (event, guestInstanceId) {