From 574eec3e748e153b15adceb262871b17d4f4ff25 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Mon, 14 Dec 2015 14:55:48 -0800 Subject: [PATCH] Make window.opener a BrowserWindowProxy --- atom/renderer/lib/override.coffee | 7 ++++--- spec/chromium-spec.coffee | 5 ++++- spec/fixtures/pages/window-open-postMessage.html | 7 ++++++- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/atom/renderer/lib/override.coffee b/atom/renderer/lib/override.coffee index 333acc82739..3b741e004d3 100644 --- a/atom/renderer/lib/override.coffee +++ b/atom/renderer/lib/override.coffee @@ -94,9 +94,10 @@ window.prompt = -> # Implement window.postMessage if current window is a guest window. guestId = ipcRenderer.sendSync 'ATOM_SHELL_GUEST_WINDOW_MANAGER_GET_GUEST_ID' if guestId? - window.opener = - postMessage: (message, targetOrigin='*') -> - ipcRenderer.send 'ATOM_SHELL_GUEST_WINDOW_MANAGER_WINDOW_OPENER_POSTMESSAGE', guestId, message, targetOrigin, location.origin + window.opener = BrowserWindowProxy.getOrCreate(guestId) + Object.setPrototypeOf(window.opener, null) + window.opener.postMessage = (message, targetOrigin='*') -> + ipcRenderer.send 'ATOM_SHELL_GUEST_WINDOW_MANAGER_WINDOW_OPENER_POSTMESSAGE', guestId, message, targetOrigin, location.origin ipcRenderer.on 'ATOM_SHELL_GUEST_WINDOW_POSTMESSAGE', (event, guestId, message, sourceOrigin) -> # Manually dispatch event instead of using postMessage because we also need to diff --git a/spec/chromium-spec.coffee b/spec/chromium-spec.coffee index 2cc2237385b..e6ae8a732f9 100644 --- a/spec/chromium-spec.coffee +++ b/spec/chromium-spec.coffee @@ -120,7 +120,10 @@ describe 'chromium feature', -> listener = (event) -> window.removeEventListener 'message', listener b.close() - assert.equal event.data, 'file://testing' + message = JSON.parse(event.data) + assert.equal message.data, 'testing' + assert.equal message.origin, 'file://' + assert.equal message.sourceEqualsOpener, true assert.equal event.origin, 'file://' done() window.addEventListener 'message', listener diff --git a/spec/fixtures/pages/window-open-postMessage.html b/spec/fixtures/pages/window-open-postMessage.html index e547fa2a609..550b61b2759 100644 --- a/spec/fixtures/pages/window-open-postMessage.html +++ b/spec/fixtures/pages/window-open-postMessage.html @@ -2,7 +2,12 @@