Add webContents.getFocusedWebContents()

This commit is contained in:
Kevin Sawicki 2016-07-13 12:15:30 -07:00
parent 7877fa7c0a
commit 06e595e7cc

View file

@ -2,6 +2,7 @@
const {EventEmitter} = require('events')
const {app, ipcMain, session, Menu, NavigationController} = require('electron')
const {getAllWebContents} = process.atomBinding('web_contents')
// session is not used here, the purpose is to make sure session is initalized
// before the webContents module.
@ -245,7 +246,18 @@ module.exports = {
fromId (id) {
return binding.fromId(id)
},
getAllWebContents () {
return binding.getAllWebContents()
getFocusedWebContents () {
let focused = null
for (let contents of getAllWebContents()) {
if (!contents.isFocused()) continue
// Return webview web contents which may be embedded inside another
// web contents that is also reporting as focused
if (contents.getType() === 'webview') return contents
if (focused == null) focused = contents
}
return focused
}
}