Browse Source

Add back BrowserWindowProxy location property

Kevin Sawicki 8 years ago
parent
commit
fbcbfbda6a
2 changed files with 18 additions and 12 deletions
  1. 10 0
      lib/renderer/window-setup.js
  2. 8 12
      spec/chromium-spec.js

+ 10 - 0
lib/renderer/window-setup.js

@@ -31,6 +31,16 @@ const removeProxy = (guestId) => {
 function BrowserWindowProxy (ipcRenderer, guestId) {
   this.closed = false
 
+  defineProperty(this, 'location', {
+    get: function () {
+      return ipcRenderer.sendSync('ELECTRON_GUEST_WINDOW_MANAGER_WEB_CONTENTS_METHOD_SYNC', guestId, 'getURL')
+    },
+    set: function (url) {
+      url = resolveURL(url)
+      return ipcRenderer.sendSync('ELECTRON_GUEST_WINDOW_MANAGER_WEB_CONTENTS_METHOD_SYNC', guestId, 'loadURL', url)
+    }
+  })
+
   ipcRenderer.once(`ELECTRON_GUEST_WINDOW_MANAGER_WINDOW_CLOSED_${guestId}`, () => {
     removeProxy(guestId)
     this.closed = true

+ 8 - 12
spec/chromium-spec.js

@@ -6,7 +6,7 @@ const url = require('url')
 const {ipcRenderer, remote} = require('electron')
 const {closeWindow} = require('./window-helpers')
 
-const {BrowserWindow, ipcMain, protocol, session, webContents} = remote
+const {app, BrowserWindow, ipcMain, protocol, session, webContents} = remote
 
 const isCI = remote.getGlobal('isCi')
 
@@ -197,12 +197,6 @@ describe('chromium feature', function () {
       var b = window.open('about:blank', '', 'show=no')
       assert.equal(b.closed, false)
       assert.equal(b.constructor.name, 'BrowserWindowProxy')
-
-      // Check that guestId is not writeable
-      assert(b.guestId)
-      b.guestId = 'anotherValue'
-      assert.notEqual(b.guestId, 'anoterValue')
-
       b.close()
     })
 
@@ -295,12 +289,14 @@ describe('chromium feature', function () {
       } else {
         targetURL = 'file://' + fixtures + '/pages/base-page.html'
       }
-      b = window.open(targetURL)
-      webContents.fromId(b.guestId).once('did-finish-load', function () {
-        assert.equal(b.location, targetURL)
-        b.close()
-        done()
+      app.once('browser-window-created', (event, window) => {
+        window.webContents.once('did-finish-load', () => {
+          assert.equal(b.location, targetURL)
+          b.close()
+          done()
+        })
       })
+      b = window.open(targetURL)
     })
 
     it('defines a window.location setter', function (done) {