Make window.opener a BrowserWindowProxy

This commit is contained in:
Kevin Sawicki 2015-12-14 14:55:48 -08:00
parent 606fb0615f
commit 574eec3e74
3 changed files with 14 additions and 5 deletions

View file

@ -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

View file

@ -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

View file

@ -2,7 +2,12 @@
<body>
<script type="text/javascript" charset="utf-8">
window.addEventListener('message', function (e) {
window.opener.postMessage(e.origin + e.data, '*');
var reply = JSON.stringify({
origin: e.origin,
data: e.data,
sourceEqualsOpener: e.source === window.opener
})
window.opener.postMessage(reply, '*');
});
</script>
</body>