This commit is contained in:
Cheng Zhao 2015-03-04 07:58:06 -08:00
parent fac9ea3356
commit 99f6bf045f
2 changed files with 16 additions and 11 deletions

View file

@ -1,4 +1,5 @@
ipc = require 'ipc' ipc = require 'ipc'
v8Util = process.atomBinding 'v8_util'
BrowserWindow = require 'browser-window' BrowserWindow = require 'browser-window'
frameToGuest = {} frameToGuest = {}
@ -13,6 +14,9 @@ createGuest = (embedder, url, frameName, options) ->
guest = new BrowserWindow(options) guest = new BrowserWindow(options)
guest.loadUrl url guest.loadUrl url
# Remember the embedder, will be used by window.opener methods.
v8Util.setHiddenValue guest.webContents, 'embedder', embedder
# When |embedder| is destroyed we should also destroy attached guest, and if # When |embedder| is destroyed we should also destroy attached guest, and if
# guest is closed by user then we should prevent |embedder| from double # guest is closed by user then we should prevent |embedder| from double
# closing guest. # closing guest.
@ -32,10 +36,6 @@ createGuest = (embedder, url, frameName, options) ->
guest.once 'closed', -> guest.once 'closed', ->
delete frameToGuest[frameName] delete frameToGuest[frameName]
ipc.on 'ATOM_SHELL_GUEST_WINDOW_MANAGER_WINDOW_OPENER_POSTMESSAGE', (event, message, targetOrigin) ->
if embedder.getUrl().indexOf(targetOrigin) is 0 or targetOrigin is '*'
embedder.send 'ATOM_SHELL_GUEST_WINDOW_MANAGER_WINDOW_POSTMESSAGE', message, targetOrigin
guest.id guest.id
# Routed window.open messages. # Routed window.open messages.
@ -57,9 +57,14 @@ ipc.on 'ATOM_SHELL_GUEST_WINDOW_MANAGER_WINDOW_METHOD', (event, guestId, method,
ipc.on 'ATOM_SHELL_GUEST_WINDOW_MANAGER_WINDOW_POSTMESSAGE', (event, guestId, message, targetOrigin) -> ipc.on 'ATOM_SHELL_GUEST_WINDOW_MANAGER_WINDOW_POSTMESSAGE', (event, guestId, message, targetOrigin) ->
return unless BrowserWindow.windows.has guestId return unless BrowserWindow.windows.has guestId
window = BrowserWindow.windows.get(guestId) guestContents = BrowserWindow.windows.get(guestId).webContents
if window.getUrl().indexOf(targetOrigin) is 0 or targetOrigin is '*' if guestContents.getUrl().indexOf(targetOrigin) is 0 or targetOrigin is '*'
window.send 'ATOM_SHELL_GUEST_WINDOW_MANAGER_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) ->
embedder = v8Util.getHiddenValue event.sender, 'embedder'
if embedder?.getUrl().indexOf(targetOrigin) is 0 or targetOrigin is '*'
embedder.send 'ATOM_SHELL_GUEST_WINDOW_POSTMESSAGE', message, targetOrigin
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...) ->
return unless BrowserWindow.windows.has guestId return unless BrowserWindow.windows.has guestId

View file

@ -18,7 +18,7 @@ class FakeWindow
blur: -> blur: ->
ipc.send 'ATOM_SHELL_GUEST_WINDOW_MANAGER_WINDOW_METHOD', @guestId, 'blur' ipc.send 'ATOM_SHELL_GUEST_WINDOW_MANAGER_WINDOW_METHOD', @guestId, 'blur'
postMessage: (message, targetOrigin) -> postMessage: (message, targetOrigin='*') ->
ipc.send 'ATOM_SHELL_GUEST_WINDOW_MANAGER_WINDOW_POSTMESSAGE', @guestId, message, targetOrigin ipc.send 'ATOM_SHELL_GUEST_WINDOW_MANAGER_WINDOW_POSTMESSAGE', @guestId, message, targetOrigin
eval: (args...) -> eval: (args...) ->
@ -75,8 +75,8 @@ window.prompt = ->
throw new Error('prompt() is and will not be supported in atom-shell.') throw new Error('prompt() is and will not be supported in atom-shell.')
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', message, targetOrigin
ipc.on 'ATOM_SHELL_GUEST_WINDOW_MANAGER_WINDOW_POSTMESSAGE', (message, targetOrigin) -> ipc.on 'ATOM_SHELL_GUEST_WINDOW_POSTMESSAGE', (message, targetOrigin) ->
window.postMessage(message, targetOrigin) window.postMessage message, targetOrigin