Merge pull request #11224 from electron/browser-view-window
feature: Add `BrowserWindow.fromBrowserView()`
This commit is contained in:
commit
9c217fc6c7
3 changed files with 38 additions and 1 deletions
|
@ -580,6 +580,12 @@ Returns `BrowserWindow` - The window that is focused in this application, otherw
|
||||||
|
|
||||||
Returns `BrowserWindow` - The window that owns the given `webContents`.
|
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)`
|
#### `BrowserWindow.fromId(id)`
|
||||||
|
|
||||||
* `id` Integer
|
* `id` Integer
|
||||||
|
|
|
@ -144,6 +144,14 @@ BrowserWindow.fromWebContents = (webContents) => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BrowserWindow.fromBrowserView = (browserView) => {
|
||||||
|
for (const window of BrowserWindow.getAllWindows()) {
|
||||||
|
if (window.getBrowserView() === browserView) return window
|
||||||
|
}
|
||||||
|
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
BrowserWindow.fromDevToolsWebContents = (webContents) => {
|
BrowserWindow.fromDevToolsWebContents = (webContents) => {
|
||||||
for (const window of BrowserWindow.getAllWindows()) {
|
for (const window of BrowserWindow.getAllWindows()) {
|
||||||
const {devToolsWebContents} = window
|
const {devToolsWebContents} = window
|
||||||
|
|
|
@ -9,7 +9,7 @@ const http = require('http')
|
||||||
const {closeWindow} = require('./window-helpers')
|
const {closeWindow} = require('./window-helpers')
|
||||||
|
|
||||||
const {ipcRenderer, remote, screen} = require('electron')
|
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 isCI = remote.getGlobal('isCi')
|
||||||
const nativeModulesEnabled = remote.getGlobal('nativeModulesEnabled')
|
const nativeModulesEnabled = remote.getGlobal('nativeModulesEnabled')
|
||||||
|
@ -802,6 +802,29 @@ 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)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('returns undefined if not attached', () => {
|
||||||
|
w.setBrowserView(null)
|
||||||
|
assert.equal(BrowserWindow.fromBrowserView(bv), undefined)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
describe('BrowserWindow.setOpacity(opacity)', () => {
|
describe('BrowserWindow.setOpacity(opacity)', () => {
|
||||||
it('make window with initial opacity', () => {
|
it('make window with initial opacity', () => {
|
||||||
w.destroy()
|
w.destroy()
|
||||||
|
|
Loading…
Reference in a new issue