2014-10-27 13:56:04 +00:00
|
|
|
ipc = require 'ipc'
|
|
|
|
BrowserWindow = require 'browser-window'
|
|
|
|
|
2014-10-28 05:23:25 +00:00
|
|
|
frameToGuest = {}
|
2014-10-27 13:56:04 +00:00
|
|
|
|
|
|
|
# Create a new guest created by |embedder| with |options|.
|
2014-10-28 05:23:25 +00:00
|
|
|
createGuest = (embedder, url, frameName, options) ->
|
2014-10-28 10:51:28 +00:00
|
|
|
guest = frameToGuest[frameName]
|
|
|
|
if frameName and guest?
|
|
|
|
guest.loadUrl url
|
|
|
|
return guest.id
|
2014-10-27 13:56:04 +00:00
|
|
|
|
|
|
|
guest = new BrowserWindow(options)
|
|
|
|
guest.loadUrl url
|
|
|
|
|
2014-10-28 10:51:28 +00:00
|
|
|
# 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.
|
|
|
|
closedByEmbedder = ->
|
2015-02-13 16:45:12 +00:00
|
|
|
embedder.send 'ATOM_SHELL_GUEST_WINDOW_MANAGER_WINDOW_CLOSED', guest.id
|
2014-10-28 10:51:28 +00:00
|
|
|
guest.removeListener 'closed', closedByUser
|
|
|
|
guest.destroy() unless guest.isClosed()
|
|
|
|
closedByUser = ->
|
2015-02-13 16:45:12 +00:00
|
|
|
embedder.send 'ATOM_SHELL_GUEST_WINDOW_MANAGER_WINDOW_CLOSED', guest.id
|
2014-10-28 10:51:28 +00:00
|
|
|
embedder.removeListener 'render-view-deleted', closedByEmbedder
|
|
|
|
embedder.once 'render-view-deleted', closedByEmbedder
|
|
|
|
guest.once 'closed', closedByUser
|
|
|
|
|
|
|
|
if frameName
|
|
|
|
frameToGuest[frameName] = guest
|
|
|
|
guest.frameName = frameName
|
|
|
|
guest.once 'closed', ->
|
|
|
|
delete frameToGuest[frameName]
|
2014-10-27 13:56:04 +00:00
|
|
|
|
2015-02-13 16:45:12 +00:00
|
|
|
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];
|
|
|
|
|
2014-10-28 05:23:25 +00:00
|
|
|
guest.id
|
2014-10-27 13:56:04 +00:00
|
|
|
|
|
|
|
# Routed window.open messages.
|
|
|
|
ipc.on 'ATOM_SHELL_GUEST_WINDOW_MANAGER_WINDOW_OPEN', (event, args...) ->
|
2014-11-04 10:31:47 +00:00
|
|
|
[url, frameName, options] = args
|
|
|
|
event.sender.emit '-new-window', event, url, frameName, 7
|
2014-10-27 13:56:04 +00:00
|
|
|
if event.sender.isGuest() or event.defaultPrevented
|
|
|
|
event.returnValue = null
|
|
|
|
else
|
2014-10-28 05:23:25 +00:00
|
|
|
event.returnValue = createGuest event.sender, args...
|
2014-10-27 13:56:04 +00:00
|
|
|
|
2014-10-28 05:23:25 +00:00
|
|
|
ipc.on 'ATOM_SHELL_GUEST_WINDOW_MANAGER_WINDOW_CLOSE', (event, guestId) ->
|
2014-10-27 15:59:11 +00:00
|
|
|
return unless BrowserWindow.windows.has guestId
|
2014-10-28 10:51:28 +00:00
|
|
|
BrowserWindow.windows.get(guestId).destroy()
|
2014-10-27 15:03:05 +00:00
|
|
|
|
|
|
|
ipc.on 'ATOM_SHELL_GUEST_WINDOW_MANAGER_WINDOW_METHOD', (event, guestId, method, args...) ->
|
2014-10-27 15:59:11 +00:00
|
|
|
return unless BrowserWindow.windows.has guestId
|
|
|
|
BrowserWindow.windows.get(guestId)[method] args...
|
2014-10-27 15:07:41 +00:00
|
|
|
|
2015-02-13 16:45:12 +00:00
|
|
|
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]
|
|
|
|
|
2014-10-27 15:07:41 +00:00
|
|
|
ipc.on 'ATOM_SHELL_GUEST_WINDOW_MANAGER_WEB_CONTENTS_METHOD', (event, guestId, method, args...) ->
|
2014-10-27 15:59:11 +00:00
|
|
|
return unless BrowserWindow.windows.has guestId
|
|
|
|
BrowserWindow.windows.get(guestId).webContents?[method] args...
|