Implement FakeWindow.postMessage, window.opener.postMessage and window.closed flag for popup windows.

This commit is contained in:
Bundyo 2015-02-13 18:45:12 +02:00
parent f1ad8836d1
commit 7fa1296a17
2 changed files with 27 additions and 0 deletions

View file

@ -17,9 +17,11 @@ createGuest = (embedder, url, frameName, options) ->
# guest is closed by user then we should prevent |embedder| from double
# closing guest.
closedByEmbedder = ->
embedder.send 'ATOM_SHELL_GUEST_WINDOW_MANAGER_WINDOW_CLOSED', guest.id
guest.removeListener 'closed', closedByUser
guest.destroy() unless guest.isClosed()
closedByUser = ->
embedder.send 'ATOM_SHELL_GUEST_WINDOW_MANAGER_WINDOW_CLOSED', guest.id
embedder.removeListener 'render-view-deleted', closedByEmbedder
embedder.once 'render-view-deleted', closedByEmbedder
guest.once 'closed', closedByUser
@ -30,6 +32,10 @@ createGuest = (embedder, url, frameName, options) ->
guest.once 'closed', ->
delete frameToGuest[frameName]
ipc.on 'ATOM_SHELL_GUEST_WINDOW_MANAGER_WINDOW_OPENER_POSTMESSAGE', (event, method, args...) ->
if embedder.getUrl().indexOf(args[1]) is 0 or args[1] is '*'
embedder.send 'ATOM_SHELL_GUEST_WINDOW_MANAGER_WINDOW_POSTMESSAGE', args[0], args[1];
guest.id
# Routed window.open messages.
@ -49,6 +55,12 @@ ipc.on 'ATOM_SHELL_GUEST_WINDOW_MANAGER_WINDOW_METHOD', (event, guestId, method,
return unless BrowserWindow.windows.has guestId
BrowserWindow.windows.get(guestId)[method] args...
ipc.on 'ATOM_SHELL_GUEST_WINDOW_MANAGER_WINDOW_POSTMESSAGE', (event, guestId, method, args...) ->
return unless BrowserWindow.windows.has guestId
window = BrowserWindow.windows.get(guestId)
if window.getUrl().indexOf(args[1]) is 0 or args[1] is '*'
window.send 'ATOM_SHELL_GUEST_WINDOW_MANAGER_WINDOW_POSTMESSAGE', args[0], args[1]
ipc.on 'ATOM_SHELL_GUEST_WINDOW_MANAGER_WEB_CONTENTS_METHOD', (event, guestId, method, args...) ->
return unless BrowserWindow.windows.has guestId
BrowserWindow.windows.get(guestId).webContents?[method] args...

View file

@ -5,6 +5,11 @@ remote = require 'remote'
# Window object returned by "window.open".
class FakeWindow
constructor: (@guestId) ->
that = this
ipc.on 'ATOM_SHELL_GUEST_WINDOW_MANAGER_WINDOW_CLOSED', (guestId) ->
if guestId is that.guestId
that.closed = true
close: ->
ipc.send 'ATOM_SHELL_GUEST_WINDOW_MANAGER_WINDOW_CLOSE', @guestId
@ -15,6 +20,9 @@ class FakeWindow
blur: ->
ipc.send 'ATOM_SHELL_GUEST_WINDOW_MANAGER_WINDOW_METHOD', @guestId, 'blur'
postMessage: (args...) ->
ipc.send 'ATOM_SHELL_GUEST_WINDOW_MANAGER_WINDOW_POSTMESSAGE', @guestId, 'postMessage', args[0], args[1];
eval: (args...) ->
ipc.send 'ATOM_SHELL_GUEST_WINDOW_MANAGER_WEB_CONTENTS_METHOD', @guestId, 'executeJavaScript', args...
@ -63,3 +71,10 @@ window.confirm = (message, title='') ->
# But we do not support prompt().
window.prompt = ->
throw new Error('prompt() is and will not be supported in atom-shell.')
window.opener =
postMessage: (args...) ->
ipc.send 'ATOM_SHELL_GUEST_WINDOW_MANAGER_WINDOW_OPENER_POSTMESSAGE', 'postMessage', args[0], args[1]
ipc.on 'ATOM_SHELL_GUEST_WINDOW_MANAGER_WINDOW_POSTMESSAGE', (data, origin) ->
window.postMessage(data, origin)