electron/atom/browser/lib/guest-window-manager.coffee

54 lines
1.8 KiB
CoffeeScript
Raw Normal View History

ipc = require 'ipc'
BrowserWindow = require 'browser-window'
2014-10-28 05:23:25 +00:00
frameToGuest = {}
# Create a new guest created by |embedder| with |options|.
2014-10-28 05:23:25 +00:00
createGuest = (embedder, url, frameName, options) ->
guest = frameToGuest[frameName]
if frameName and guest?
guest.loadUrl url
return guest.id
guest = new BrowserWindow(options)
guest.loadUrl url
# 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 = ->
guest.removeListener 'closed', closedByUser
guest.destroy() unless guest.isClosed()
closedByUser = ->
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-28 05:23:25 +00:00
guest.id
# Routed window.open messages.
ipc.on 'ATOM_SHELL_GUEST_WINDOW_MANAGER_WINDOW_OPEN', (event, args...) ->
event.sender.emit 'new-window', event, args...
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-28 05:23:25 +00:00
ipc.on 'ATOM_SHELL_GUEST_WINDOW_MANAGER_WINDOW_CLOSE', (event, guestId) ->
return unless BrowserWindow.windows.has guestId
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...) ->
return unless BrowserWindow.windows.has guestId
BrowserWindow.windows.get(guestId)[method] args...
2014-10-27 15:07:41 +00:00
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...