Use id from source window when building proxy for event source

This commit is contained in:
Kevin Sawicki 2015-12-14 16:47:33 -08:00
parent 0ef0ce7345
commit 184b11be4c
2 changed files with 19 additions and 17 deletions

View file

@ -91,22 +91,20 @@ window.confirm = (message, title='') ->
window.prompt = ->
throw new Error('prompt() is and will not be supported.')
guestId = ipcRenderer.sendSync 'ATOM_SHELL_GUEST_WINDOW_MANAGER_GET_GUEST_ID'
if guestId?
window.opener = BrowserWindowProxy.getOrCreate(guestId)
# Remove BrowserWindowProxy API and give it a custom postMessage method
Object.setPrototypeOf(window.opener, null)
openerId = ipcRenderer.sendSync 'ATOM_SHELL_GUEST_WINDOW_MANAGER_GET_OPENER_ID'
if openerId?
window.opener = BrowserWindowProxy.getOrCreate(openerId)
window.opener.postMessage = (message, targetOrigin='*') ->
ipcRenderer.send 'ATOM_SHELL_GUEST_WINDOW_MANAGER_WINDOW_OPENER_POSTMESSAGE', guestId, message, targetOrigin, location.origin
ipcRenderer.send 'ATOM_SHELL_GUEST_WINDOW_MANAGER_WINDOW_OPENER_POSTMESSAGE', message, targetOrigin, location.origin
ipcRenderer.on 'ATOM_SHELL_GUEST_WINDOW_POSTMESSAGE', (event, guestId, message, sourceOrigin) ->
ipcRenderer.on 'ATOM_SHELL_GUEST_WINDOW_POSTMESSAGE', (event, sourceId, message, sourceOrigin) ->
# Manually dispatch event instead of using postMessage because we also need to
# set event.source.
event = document.createEvent 'Event'
event.initEvent 'message', false, false
event.data = message
event.origin = sourceOrigin
event.source = BrowserWindowProxy.getOrCreate(guestId)
event.source = BrowserWindowProxy.getOrCreate(sourceId)
window.dispatchEvent event
# Forward history operations to browser.