Access URL through webContents directly
This commit is contained in:
parent
145e40c2f6
commit
3a29555772
2 changed files with 21 additions and 6 deletions
|
@ -240,3 +240,18 @@ ipcMain.on('ELECTRON_GUEST_WINDOW_MANAGER_WEB_CONTENTS_METHOD', function (event,
|
||||||
console.error(`Blocked ${event.sender.getURL()} from calling ${method} on its opener.`)
|
console.error(`Blocked ${event.sender.getURL()} from calling ${method} on its opener.`)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
ipcMain.on('ELECTRON_GUEST_WINDOW_MANAGER_WEB_CONTENTS_METHOD_SYNC', function (event, guestId, method, ...args) {
|
||||||
|
const guestContents = webContents.fromId(guestId)
|
||||||
|
if (guestContents == null) {
|
||||||
|
event.returnValue = null
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (canAccessWindow(event.sender, guestContents)) {
|
||||||
|
event.returnValue = guestContents[method].apply(guestContents, args)
|
||||||
|
} else {
|
||||||
|
console.error(`Blocked ${event.sender.getURL()} from calling ${method} on its opener.`)
|
||||||
|
event.returnValue = null
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
|
@ -41,28 +41,28 @@ var BrowserWindowProxy = (function () {
|
||||||
}
|
}
|
||||||
|
|
||||||
BrowserWindowProxy.prototype.close = function () {
|
BrowserWindowProxy.prototype.close = function () {
|
||||||
return ipcRenderer.send('ELECTRON_GUEST_WINDOW_MANAGER_WINDOW_CLOSE', this.guestId)
|
ipcRenderer.send('ELECTRON_GUEST_WINDOW_MANAGER_WINDOW_CLOSE', this.guestId)
|
||||||
}
|
}
|
||||||
|
|
||||||
BrowserWindowProxy.prototype.focus = function () {
|
BrowserWindowProxy.prototype.focus = function () {
|
||||||
return ipcRenderer.send('ELECTRON_GUEST_WINDOW_MANAGER_WINDOW_METHOD', this.guestId, 'focus')
|
ipcRenderer.send('ELECTRON_GUEST_WINDOW_MANAGER_WINDOW_METHOD', this.guestId, 'focus')
|
||||||
}
|
}
|
||||||
|
|
||||||
BrowserWindowProxy.prototype.blur = function () {
|
BrowserWindowProxy.prototype.blur = function () {
|
||||||
return ipcRenderer.send('ELECTRON_GUEST_WINDOW_MANAGER_WINDOW_METHOD', this.guestId, 'blur')
|
ipcRenderer.send('ELECTRON_GUEST_WINDOW_MANAGER_WINDOW_METHOD', this.guestId, 'blur')
|
||||||
}
|
}
|
||||||
|
|
||||||
BrowserWindowProxy.prototype.print = function () {
|
BrowserWindowProxy.prototype.print = function () {
|
||||||
return ipcRenderer.send('ELECTRON_GUEST_WINDOW_MANAGER_WEB_CONTENTS_METHOD', this.guestId, 'print')
|
ipcRenderer.send('ELECTRON_GUEST_WINDOW_MANAGER_WEB_CONTENTS_METHOD', this.guestId, 'print')
|
||||||
}
|
}
|
||||||
|
|
||||||
Object.defineProperty(BrowserWindowProxy.prototype, 'location', {
|
Object.defineProperty(BrowserWindowProxy.prototype, 'location', {
|
||||||
get: function () {
|
get: function () {
|
||||||
return ipcRenderer.sendSync('ELECTRON_GUEST_WINDOW_MANAGER_WINDOW_METHOD', this.guestId, 'getURL')
|
return ipcRenderer.sendSync('ELECTRON_GUEST_WINDOW_MANAGER_WEB_CONTENTS_METHOD_SYNC', this.guestId, 'getURL')
|
||||||
},
|
},
|
||||||
set: function (url) {
|
set: function (url) {
|
||||||
url = resolveURL(url)
|
url = resolveURL(url)
|
||||||
return ipcRenderer.sendSync('ELECTRON_GUEST_WINDOW_MANAGER_WINDOW_METHOD', this.guestId, 'loadURL', url)
|
return ipcRenderer.sendSync('ELECTRON_GUEST_WINDOW_MANAGER_WEB_CONTENTS_METHOD_SYNC', this.guestId, 'loadURL', url)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue