Reuse BrowserWindowProxy instances

This commit is contained in:
Kevin Sawicki 2015-12-10 17:20:10 -08:00
Родитель 7dfca3c293
Коммит 49ca7509c7
1 изменённых файлов: 11 добавлений и 2 удалений

Просмотреть файл

@ -8,9 +8,18 @@ resolveURL = (url) ->
# Window object returned by "window.open".
class BrowserWindowProxy
@proxies: {}
@getOrCreate: (guestId) ->
@proxies[guestId] ?= new BrowserWindowProxy(guestId)
@removeWindow: (guestId) ->
delete @proxies[guestId]
constructor: (@guestId) ->
@closed = false
ipcRenderer.once "ATOM_SHELL_GUEST_WINDOW_MANAGER_WINDOW_CLOSED_#{@guestId}", =>
BrowserWindowProxy.removeWindow(@guestId)
@closed = true
close: ->
@ -60,7 +69,7 @@ window.open = (url, frameName='', features='') ->
guestId = ipcRenderer.sendSync 'ATOM_SHELL_GUEST_WINDOW_MANAGER_WINDOW_OPEN', url, frameName, options
if guestId
new BrowserWindowProxy(guestId)
BrowserWindowProxy.getOrCreate(guestId)
else
null
@ -96,7 +105,7 @@ ipcRenderer.on 'ATOM_SHELL_GUEST_WINDOW_POSTMESSAGE', (event, guestId, message,
event.initEvent 'message', false, false
event.data = message
event.origin = sourceOrigin
event.source = new BrowserWindowProxy(guestId)
event.source = BrowserWindowProxy.getOrCreate(guestId)
window.dispatchEvent event
# Forward history operations to browser.