|
@@ -87,10 +87,7 @@ const createGuest = function (embedder, url, frameName, options) {
|
|
|
return guestId
|
|
|
}
|
|
|
|
|
|
-const getGuestWindow = function (guestId) {
|
|
|
- const guestContents = webContents.fromId(guestId)
|
|
|
- if (guestContents == null) return
|
|
|
-
|
|
|
+const getGuestWindow = function (guestContents) {
|
|
|
let guestWindow = BrowserWindow.fromWebContents(guestContents)
|
|
|
if (guestWindow == null) {
|
|
|
const hostContents = guestContents.hostWebContents
|
|
@@ -129,27 +126,35 @@ ipcMain.on('ELECTRON_GUEST_WINDOW_MANAGER_WINDOW_OPEN', function (event, url, fr
|
|
|
})
|
|
|
|
|
|
ipcMain.on('ELECTRON_GUEST_WINDOW_MANAGER_WINDOW_CLOSE', function (event, guestId) {
|
|
|
- const guestWindow = getGuestWindow(guestId)
|
|
|
- if (guestWindow == null) return
|
|
|
+ const guestContents = webContents.fromId(guestId)
|
|
|
+ if (guestContents == null) return
|
|
|
|
|
|
- if (canAccessWindow(event.sender, guestWindow.webContents)) {
|
|
|
- guestWindow.destroy()
|
|
|
- } else {
|
|
|
+ if (!canAccessWindow(event.sender, guestContents)) {
|
|
|
console.error(`Blocked ${event.sender.getURL()} from closing its opener.`)
|
|
|
+ return
|
|
|
}
|
|
|
+
|
|
|
+ const guestWindow = getGuestWindow(guestContents)
|
|
|
+ if (guestWindow != null) guestWindow.destroy()
|
|
|
})
|
|
|
|
|
|
ipcMain.on('ELECTRON_GUEST_WINDOW_MANAGER_WINDOW_METHOD', function (event, guestId, method, ...args) {
|
|
|
- const guestWindow = getGuestWindow(guestId)
|
|
|
- if (guestWindow == null) {
|
|
|
+ const guestContents = webContents.fromId(guestId)
|
|
|
+ if (guestContents == null) {
|
|
|
+ event.returnValue = null
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!canAccessWindow(event.sender, guestContents)) {
|
|
|
+ console.error(`Blocked ${event.sender.getURL()} from calling ${method} on its opener.`)
|
|
|
event.returnValue = null
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- if (canAccessWindow(event.sender, guestWindow.webContents)) {
|
|
|
+ const guestWindow = getGuestWindow(guestContents)
|
|
|
+ if (guestWindow != null) {
|
|
|
event.returnValue = guestWindow[method].apply(guestWindow, args)
|
|
|
} else {
|
|
|
- console.error(`Blocked ${event.sender.getURL()} from calling ${method} on its opener.`)
|
|
|
event.returnValue = null
|
|
|
}
|
|
|
})
|