Merge pull request #3769 from atom/reuse-browser-window-proxies
Reuse BrowserWindowProxy objects across events
This commit is contained in:
commit
6351e28f00
2 changed files with 14 additions and 5 deletions
|
@ -8,9 +8,18 @@ resolveURL = (url) ->
|
||||||
|
|
||||||
# Window object returned by "window.open".
|
# Window object returned by "window.open".
|
||||||
class BrowserWindowProxy
|
class BrowserWindowProxy
|
||||||
|
@proxies: {}
|
||||||
|
|
||||||
|
@getOrCreate: (guestId) ->
|
||||||
|
@proxies[guestId] ?= new BrowserWindowProxy(guestId)
|
||||||
|
|
||||||
|
@remove: (guestId) ->
|
||||||
|
delete @proxies[guestId]
|
||||||
|
|
||||||
constructor: (@guestId) ->
|
constructor: (@guestId) ->
|
||||||
@closed = false
|
@closed = false
|
||||||
ipcRenderer.once "ATOM_SHELL_GUEST_WINDOW_MANAGER_WINDOW_CLOSED_#{@guestId}", =>
|
ipcRenderer.once "ATOM_SHELL_GUEST_WINDOW_MANAGER_WINDOW_CLOSED_#{@guestId}", =>
|
||||||
|
BrowserWindowProxy.remove(@guestId)
|
||||||
@closed = true
|
@closed = true
|
||||||
|
|
||||||
close: ->
|
close: ->
|
||||||
|
@ -60,7 +69,7 @@ window.open = (url, frameName='', features='') ->
|
||||||
|
|
||||||
guestId = ipcRenderer.sendSync 'ATOM_SHELL_GUEST_WINDOW_MANAGER_WINDOW_OPEN', url, frameName, options
|
guestId = ipcRenderer.sendSync 'ATOM_SHELL_GUEST_WINDOW_MANAGER_WINDOW_OPEN', url, frameName, options
|
||||||
if guestId
|
if guestId
|
||||||
new BrowserWindowProxy(guestId)
|
BrowserWindowProxy.getOrCreate(guestId)
|
||||||
else
|
else
|
||||||
null
|
null
|
||||||
|
|
||||||
|
@ -96,7 +105,7 @@ ipcRenderer.on 'ATOM_SHELL_GUEST_WINDOW_POSTMESSAGE', (event, guestId, message,
|
||||||
event.initEvent 'message', false, false
|
event.initEvent 'message', false, false
|
||||||
event.data = message
|
event.data = message
|
||||||
event.origin = sourceOrigin
|
event.origin = sourceOrigin
|
||||||
event.source = new BrowserWindowProxy(guestId)
|
event.source = BrowserWindowProxy.getOrCreate(guestId)
|
||||||
window.dispatchEvent event
|
window.dispatchEvent event
|
||||||
|
|
||||||
# Forward history operations to browser.
|
# Forward history operations to browser.
|
||||||
|
|
|
@ -120,7 +120,7 @@ describe 'chromium feature', ->
|
||||||
listener = (event) ->
|
listener = (event) ->
|
||||||
window.removeEventListener 'message', listener
|
window.removeEventListener 'message', listener
|
||||||
b.close()
|
b.close()
|
||||||
assert.equal event.source.guestId, b.guestId
|
assert.equal event.source, b
|
||||||
assert.equal event.origin, 'file://'
|
assert.equal event.origin, 'file://'
|
||||||
done()
|
done()
|
||||||
window.addEventListener 'message', listener
|
window.addEventListener 'message', listener
|
||||||
|
@ -210,7 +210,7 @@ describe 'chromium feature', ->
|
||||||
setImmediate ->
|
setImmediate ->
|
||||||
called = false
|
called = false
|
||||||
Promise.resolve().then ->
|
Promise.resolve().then ->
|
||||||
done(if called then undefined else new Error('wrong sequnce'))
|
done(if called then undefined else new Error('wrong sequence'))
|
||||||
document.createElement 'x-element'
|
document.createElement 'x-element'
|
||||||
called = true
|
called = true
|
||||||
|
|
||||||
|
@ -224,6 +224,6 @@ describe 'chromium feature', ->
|
||||||
remote.getGlobal('setImmediate') ->
|
remote.getGlobal('setImmediate') ->
|
||||||
called = false
|
called = false
|
||||||
Promise.resolve().then ->
|
Promise.resolve().then ->
|
||||||
done(if called then undefined else new Error('wrong sequnce'))
|
done(if called then undefined else new Error('wrong sequence'))
|
||||||
document.createElement 'y-element'
|
document.createElement 'y-element'
|
||||||
called = true
|
called = true
|
||||||
|
|
Loading…
Reference in a new issue