diff --git a/lib/browser/guest-window-manager.js b/lib/browser/guest-window-manager.js index 3d920ab54e..aee98fc41f 100644 --- a/lib/browser/guest-window-manager.js +++ b/lib/browser/guest-window-manager.js @@ -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.`) } }) + +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 + } +}) diff --git a/lib/renderer/override.js b/lib/renderer/override.js index 6b5e0e1615..69ef3a5e6f 100644 --- a/lib/renderer/override.js +++ b/lib/renderer/override.js @@ -22,7 +22,7 @@ var BrowserWindowProxy = (function () { } BrowserWindowProxy.remove = function (guestId) { - return delete this.proxies[guestId] + delete this.proxies[guestId] } function BrowserWindowProxy (guestId1) { @@ -41,28 +41,28 @@ var BrowserWindowProxy = (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 () { - 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 () { - 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 () { - 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', { 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) { 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) } }) @@ -70,11 +70,11 @@ var BrowserWindowProxy = (function () { if (targetOrigin == null) { targetOrigin = '*' } - return ipcRenderer.send('ELECTRON_GUEST_WINDOW_MANAGER_WINDOW_POSTMESSAGE', this.guestId, message, targetOrigin, window.location.origin) + ipcRenderer.send('ELECTRON_GUEST_WINDOW_MANAGER_WINDOW_POSTMESSAGE', this.guestId, message, targetOrigin, window.location.origin) } BrowserWindowProxy.prototype['eval'] = function (...args) { - return ipcRenderer.send.apply(ipcRenderer, ['ELECTRON_GUEST_WINDOW_MANAGER_WEB_CONTENTS_METHOD', this.guestId, 'executeJavaScript'].concat(args)) + ipcRenderer.send.apply(ipcRenderer, ['ELECTRON_GUEST_WINDOW_MANAGER_WEB_CONTENTS_METHOD', this.guestId, 'executeJavaScript'].concat(args)) } return BrowserWindowProxy @@ -207,7 +207,7 @@ ipcRenderer.on('ELECTRON_GUEST_WINDOW_POSTMESSAGE', function (event, sourceId, m // Forward history operations to browser. var sendHistoryOperation = function (...args) { - return ipcRenderer.send.apply(ipcRenderer, ['ELECTRON_NAVIGATION_CONTROLLER'].concat(args)) + ipcRenderer.send.apply(ipcRenderer, ['ELECTRON_NAVIGATION_CONTROLLER'].concat(args)) } var getHistoryOperation = function (...args) { @@ -215,15 +215,15 @@ var getHistoryOperation = function (...args) { } window.history.back = function () { - return sendHistoryOperation('goBack') + sendHistoryOperation('goBack') } window.history.forward = function () { - return sendHistoryOperation('goForward') + sendHistoryOperation('goForward') } window.history.go = function (offset) { - return sendHistoryOperation('goToOffset', offset) + sendHistoryOperation('goToOffset', offset) } Object.defineProperty(window.history, 'length', { diff --git a/spec/chromium-spec.js b/spec/chromium-spec.js index 7d58bee374..1a39edd296 100644 --- a/spec/chromium-spec.js +++ b/spec/chromium-spec.js @@ -345,6 +345,15 @@ describe('chromium feature', function () { w = window.open(url, '', 'show=no') }) + it('works when origin matches', function (done) { + listener = function (event) { + assert.equal(event.data, location.href) + done() + } + window.addEventListener('message', listener) + w = window.open(`file://${fixtures}/pages/window-opener-location.html`, '', 'show=no') + }) + it('works when origin does not match opener but has node integration', function (done) { listener = function (event) { assert.equal(event.data, location.href) @@ -397,11 +406,29 @@ describe('chromium feature', function () { document.body.appendChild(webview) }) + it('works when origin matches', function (done) { + webview = new WebView() + webview.addEventListener('console-message', function (e) { + assert.equal(e.message, webview.src) + done() + }) + webview.setAttribute('allowpopups', 'on') + webview.src = url.format({ + pathname: srcPath, + protocol: 'file', + query: { + p: pageURL + }, + slashes: true + }) + document.body.appendChild(webview) + }) + it('works when origin does not match opener but has node integration', function (done) { webview = new WebView() webview.addEventListener('console-message', function (e) { webview.remove() - assert.equal(e.message, location.href) + assert.equal(e.message, webview.src) done() }) webview.setAttribute('allowpopups', 'on')