From 8c5aad8b173dfadef42d487e3628c6de025b0915 Mon Sep 17 00:00:00 2001 From: Felix Rieseberg Date: Wed, 22 Nov 2017 14:36:54 -0800 Subject: [PATCH 1/5] :wrench: Add BrowserWindow.fromBrowserView() --- lib/browser/api/browser-window.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/browser/api/browser-window.js b/lib/browser/api/browser-window.js index 96cadbd33de6..2d119770dab3 100644 --- a/lib/browser/api/browser-window.js +++ b/lib/browser/api/browser-window.js @@ -144,6 +144,12 @@ BrowserWindow.fromWebContents = (webContents) => { } } +BrowserWindow.fromBrowserView = (browserView) => { + for (const window of BrowserWindow.getAllWindows()) { + if (window.getBrowserView() === browserView) return window + } +} + BrowserWindow.fromDevToolsWebContents = (webContents) => { for (const window of BrowserWindow.getAllWindows()) { const {devToolsWebContents} = window From 14db20431592f23174052fd04f16a5f39b9ce97d Mon Sep 17 00:00:00 2001 From: Felix Rieseberg Date: Wed, 22 Nov 2017 14:37:46 -0800 Subject: [PATCH 2/5] :construction_worker: Add a spec --- spec/api-browser-window-spec.js | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/spec/api-browser-window-spec.js b/spec/api-browser-window-spec.js index bb5996e68335..61561401c8b9 100644 --- a/spec/api-browser-window-spec.js +++ b/spec/api-browser-window-spec.js @@ -9,7 +9,7 @@ const http = require('http') const {closeWindow} = require('./window-helpers') const {ipcRenderer, remote, screen} = require('electron') -const {app, ipcMain, BrowserWindow, protocol, webContents} = remote +const {app, ipcMain, BrowserWindow, BrowserView, protocol, webContents} = remote const isCI = remote.getGlobal('isCi') const nativeModulesEnabled = remote.getGlobal('nativeModulesEnabled') @@ -802,6 +802,25 @@ describe('BrowserWindow module', () => { }) }) + describe('BrowserWindow.fromBrowserView(browserView)', () => { + let bv = null + + beforeEach(() => { + bv = new BrowserView() + w.setBrowserView(bv) + }) + + afterEach(() => { + w.setBrowserView(null) + bv.destroy() + }) + + it('returns the window with the browserView', () => { + assert.equal(BrowserWindow.fromBrowserView(bv).id, w.id) + }) + }) + }) + describe('BrowserWindow.setOpacity(opacity)', () => { it('make window with initial opacity', () => { w.destroy() From b7bc4eb5864e26c3f1124addc35222bafefc0973 Mon Sep 17 00:00:00 2001 From: Felix Rieseberg Date: Wed, 22 Nov 2017 14:38:08 -0800 Subject: [PATCH 3/5] =?UTF-8?q?:construction=5Fworker:=20Let=E2=80=99s=20t?= =?UTF-8?q?est=20the=20undefined=20case,=20too?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- spec/api-browser-window-spec.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/spec/api-browser-window-spec.js b/spec/api-browser-window-spec.js index 61561401c8b9..2adc82df05d0 100644 --- a/spec/api-browser-window-spec.js +++ b/spec/api-browser-window-spec.js @@ -818,6 +818,10 @@ describe('BrowserWindow module', () => { it('returns the window with the browserView', () => { assert.equal(BrowserWindow.fromBrowserView(bv).id, w.id) }) + + it('returns undefined if not attached', () => { + w.setBrowserView(null) + assert.equal(BrowserWindow.fromBrowserView(bv), undefined) }) }) From 8f20ce6dcf5a70ffde5e4e13359950e251e6fb0f Mon Sep 17 00:00:00 2001 From: Felix Rieseberg Date: Wed, 22 Nov 2017 14:38:22 -0800 Subject: [PATCH 4/5] :memo: Docs! --- docs/api/browser-window.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/docs/api/browser-window.md b/docs/api/browser-window.md index 4b4a677af925..2cddafa25e76 100644 --- a/docs/api/browser-window.md +++ b/docs/api/browser-window.md @@ -580,6 +580,12 @@ Returns `BrowserWindow` - The window that is focused in this application, otherw Returns `BrowserWindow` - The window that owns the given `webContents`. +#### `BrowserWindow.fromBrowserView(browserView)` + +* `browserView` [BrowserView](browser-view.md) + +Returns `BrowserWindow | null` - The window that owns the given `browserView`. If the given view is not attached to any window, returns `null`. + #### `BrowserWindow.fromId(id)` * `id` Integer From 7630ac6e90a2186266acb619c240cfa31441981e Mon Sep 17 00:00:00 2001 From: Felix Rieseberg Date: Wed, 22 Nov 2017 15:48:11 -0800 Subject: [PATCH 5/5] :wrench: Return null if not found --- lib/browser/api/browser-window.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/browser/api/browser-window.js b/lib/browser/api/browser-window.js index 2d119770dab3..b977e8766f9d 100644 --- a/lib/browser/api/browser-window.js +++ b/lib/browser/api/browser-window.js @@ -148,6 +148,8 @@ BrowserWindow.fromBrowserView = (browserView) => { for (const window of BrowserWindow.getAllWindows()) { if (window.getBrowserView() === browserView) return window } + + return null } BrowserWindow.fromDevToolsWebContents = (webContents) => {