зеркало из https://github.com/electron/electron.git
Set source and origin correctly for window.opener.postMessage
This commit is contained in:
Родитель
ebedb60684
Коммит
50bfe9e335
|
@ -57,13 +57,19 @@ ipc.on 'ATOM_SHELL_GUEST_WINDOW_MANAGER_WINDOW_POSTMESSAGE', (event, guestId, me
|
||||||
if guestContents?.getUrl().indexOf(targetOrigin) is 0 or targetOrigin is '*'
|
if guestContents?.getUrl().indexOf(targetOrigin) is 0 or targetOrigin is '*'
|
||||||
guestContents.send 'ATOM_SHELL_GUEST_WINDOW_POSTMESSAGE', message, targetOrigin
|
guestContents.send 'ATOM_SHELL_GUEST_WINDOW_POSTMESSAGE', message, targetOrigin
|
||||||
|
|
||||||
ipc.on 'ATOM_SHELL_GUEST_WINDOW_MANAGER_WINDOW_OPENER_POSTMESSAGE', (event, message, targetOrigin) ->
|
ipc.on 'ATOM_SHELL_GUEST_WINDOW_MANAGER_WINDOW_OPENER_POSTMESSAGE', (event, guestId, message, targetOrigin, sourceOrigin) ->
|
||||||
embedder = v8Util.getHiddenValue event.sender, 'embedder'
|
embedder = v8Util.getHiddenValue event.sender, 'embedder'
|
||||||
if embedder?.getUrl().indexOf(targetOrigin) is 0 or targetOrigin is '*'
|
if embedder?.getUrl().indexOf(targetOrigin) is 0 or targetOrigin is '*'
|
||||||
embedder.send 'ATOM_SHELL_GUEST_WINDOW_POSTMESSAGE', message, targetOrigin
|
embedder.send 'ATOM_SHELL_GUEST_WINDOW_POSTMESSAGE', guestId, message, sourceOrigin
|
||||||
|
|
||||||
ipc.on 'ATOM_SHELL_GUEST_WINDOW_MANAGER_WEB_CONTENTS_METHOD', (event, guestId, method, args...) ->
|
ipc.on 'ATOM_SHELL_GUEST_WINDOW_MANAGER_WEB_CONTENTS_METHOD', (event, guestId, method, args...) ->
|
||||||
BrowserWindow.fromId(guestId)?.webContents?[method] args...
|
BrowserWindow.fromId(guestId)?.webContents?[method] args...
|
||||||
|
|
||||||
ipc.on 'ATOM_SHELL_GUEST_WINDOW_MANAGER_IS_GUEST_WINDOW', (event) ->
|
ipc.on 'ATOM_SHELL_GUEST_WINDOW_MANAGER_GET_GUEST_ID', (event) ->
|
||||||
event.returnValue = v8Util.getHiddenValue(event.sender, 'embedder') isnt undefined
|
embedder = v8Util.getHiddenValue event.sender, 'embedder'
|
||||||
|
if embedder?
|
||||||
|
guest = BrowserWindow.fromWebContents event.sender
|
||||||
|
if guest?
|
||||||
|
event.returnValue = guest.id
|
||||||
|
return
|
||||||
|
event.returnValue = null
|
||||||
|
|
|
@ -94,14 +94,22 @@ window.confirm = (message, title='') ->
|
||||||
window.prompt = ->
|
window.prompt = ->
|
||||||
throw new Error('prompt() is and will not be supported.')
|
throw new Error('prompt() is and will not be supported.')
|
||||||
|
|
||||||
# Simple implementation of postMessage.
|
# Implement window.postMessage if current window is a guest window.
|
||||||
if ipc.sendSync 'ATOM_SHELL_GUEST_WINDOW_MANAGER_IS_GUEST_WINDOW'
|
guestId = ipc.sendSync 'ATOM_SHELL_GUEST_WINDOW_MANAGER_GET_GUEST_ID'
|
||||||
|
if guestId?
|
||||||
window.opener =
|
window.opener =
|
||||||
postMessage: (message, targetOrigin='*') ->
|
postMessage: (message, targetOrigin='*') ->
|
||||||
ipc.send 'ATOM_SHELL_GUEST_WINDOW_MANAGER_WINDOW_OPENER_POSTMESSAGE', message, targetOrigin
|
ipc.send 'ATOM_SHELL_GUEST_WINDOW_MANAGER_WINDOW_OPENER_POSTMESSAGE', guestId, message, targetOrigin, location.origin
|
||||||
|
|
||||||
ipc.on 'ATOM_SHELL_GUEST_WINDOW_POSTMESSAGE', (message, targetOrigin) ->
|
ipc.on 'ATOM_SHELL_GUEST_WINDOW_POSTMESSAGE', (guestId, message, sourceOrigin) ->
|
||||||
window.postMessage message, targetOrigin
|
# 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 = new BrowserWindowProxy(guestId)
|
||||||
|
window.dispatchEvent event
|
||||||
|
|
||||||
# Forward history operations to browser.
|
# Forward history operations to browser.
|
||||||
sendHistoryOperation = (args...) ->
|
sendHistoryOperation = (args...) ->
|
||||||
|
|
Загрузка…
Ссылка в новой задаче