diff --git a/atom/renderer/lib/override.coffee b/atom/renderer/lib/override.coffee index cb4fb8fbac2d..c8b0b2a46801 100644 --- a/atom/renderer/lib/override.coffee +++ b/atom/renderer/lib/override.coffee @@ -8,9 +8,18 @@ resolveURL = (url) -> # Window object returned by "window.open". class BrowserWindowProxy + @proxies: {} + + @getOrCreate: (guestId) -> + @proxies[guestId] ?= new BrowserWindowProxy(guestId) + + @remove: (guestId) -> + delete @proxies[guestId] + constructor: (@guestId) -> @closed = false ipcRenderer.once "ATOM_SHELL_GUEST_WINDOW_MANAGER_WINDOW_CLOSED_#{@guestId}", => + BrowserWindowProxy.remove(@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. diff --git a/spec/chromium-spec.coffee b/spec/chromium-spec.coffee index 211de346846b..82eef9e38abd 100644 --- a/spec/chromium-spec.coffee +++ b/spec/chromium-spec.coffee @@ -120,7 +120,7 @@ describe 'chromium feature', -> listener = (event) -> window.removeEventListener 'message', listener b.close() - assert.equal event.source.guestId, b.guestId + assert.equal event.source, b assert.equal event.origin, 'file://' done() window.addEventListener 'message', listener @@ -210,7 +210,7 @@ describe 'chromium feature', -> setImmediate -> called = false 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' called = true @@ -224,6 +224,6 @@ describe 'chromium feature', -> remote.getGlobal('setImmediate') -> called = false 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' called = true