diff --git a/atom/browser/lib/guest-window-manager.coffee b/atom/browser/lib/guest-window-manager.coffee index 7ed42ecff27a..14b0cafe8f53 100644 --- a/atom/browser/lib/guest-window-manager.coffee +++ b/atom/browser/lib/guest-window-manager.coffee @@ -1,4 +1,5 @@ ipc = require 'ipc' +v8Util = process.atomBinding 'v8_util' BrowserWindow = require 'browser-window' frameToGuest = {} @@ -13,6 +14,9 @@ createGuest = (embedder, url, frameName, options) -> guest = new BrowserWindow(options) 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 # guest is closed by user then we should prevent |embedder| from double # closing guest. @@ -32,10 +36,6 @@ createGuest = (embedder, url, frameName, options) -> guest.once 'closed', -> 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 # 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) -> return unless BrowserWindow.windows.has guestId - window = BrowserWindow.windows.get(guestId) - if window.getUrl().indexOf(targetOrigin) is 0 or targetOrigin is '*' - window.send 'ATOM_SHELL_GUEST_WINDOW_MANAGER_WINDOW_POSTMESSAGE', message, targetOrigin + guestContents = BrowserWindow.windows.get(guestId).webContents + if guestContents.getUrl().indexOf(targetOrigin) is 0 or targetOrigin is '*' + 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...) -> return unless BrowserWindow.windows.has guestId diff --git a/atom/renderer/lib/override.coffee b/atom/renderer/lib/override.coffee index e6a53399b9ca..61d476568e98 100644 --- a/atom/renderer/lib/override.coffee +++ b/atom/renderer/lib/override.coffee @@ -18,7 +18,7 @@ class FakeWindow 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 eval: (args...) -> @@ -75,8 +75,8 @@ window.prompt = -> throw new Error('prompt() is and will not be supported in atom-shell.') window.opener = - postMessage: (message, targetOrigin) -> + 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) -> - window.postMessage(message, targetOrigin) +ipc.on 'ATOM_SHELL_GUEST_WINDOW_POSTMESSAGE', (message, targetOrigin) -> + window.postMessage message, targetOrigin