Emit web-contents-created on app
This commit is contained in:
parent
2dc453b4be
commit
56001b481e
2 changed files with 12 additions and 12 deletions
|
@ -1,7 +1,7 @@
|
||||||
'use strict'
|
'use strict'
|
||||||
|
|
||||||
const {EventEmitter} = require('events')
|
const {EventEmitter} = require('events')
|
||||||
const {ipcMain, session, Menu, NavigationController} = require('electron')
|
const {app, ipcMain, session, Menu, NavigationController} = require('electron')
|
||||||
|
|
||||||
// session is not used here, the purpose is to make sure session is initalized
|
// session is not used here, the purpose is to make sure session is initalized
|
||||||
// before the webContents module.
|
// before the webContents module.
|
||||||
|
@ -10,14 +10,6 @@ session
|
||||||
const binding = process.atomBinding('web_contents')
|
const binding = process.atomBinding('web_contents')
|
||||||
const debuggerBinding = process.atomBinding('debugger')
|
const debuggerBinding = process.atomBinding('debugger')
|
||||||
|
|
||||||
const WebContents = new EventEmitter()
|
|
||||||
WebContents.create = (options = {}) => {
|
|
||||||
return binding.create(options)
|
|
||||||
}
|
|
||||||
WebContents.fromId = (id) => {
|
|
||||||
return binding.fromId(id)
|
|
||||||
}
|
|
||||||
|
|
||||||
let nextId = 0
|
let nextId = 0
|
||||||
const getNextId = function () {
|
const getNextId = function () {
|
||||||
return ++nextId
|
return ++nextId
|
||||||
|
@ -232,7 +224,7 @@ const wrapWebContents = function (webContents) {
|
||||||
this._printToPDF(printingSetting, callback)
|
this._printToPDF(printingSetting, callback)
|
||||||
}
|
}
|
||||||
|
|
||||||
WebContents.emit('web-contents-created', webContents)
|
app.emit('web-contents-created', {}, webContents)
|
||||||
}
|
}
|
||||||
|
|
||||||
binding._setWrapWebContents(wrapWebContents)
|
binding._setWrapWebContents(wrapWebContents)
|
||||||
|
@ -245,4 +237,12 @@ const wrapDebugger = function (webContentsDebugger) {
|
||||||
|
|
||||||
debuggerBinding._setWrapDebugger(wrapDebugger)
|
debuggerBinding._setWrapDebugger(wrapDebugger)
|
||||||
|
|
||||||
module.exports = WebContents
|
module.exports = {
|
||||||
|
create () {
|
||||||
|
return binding.create(options)
|
||||||
|
},
|
||||||
|
|
||||||
|
fromId (id) {
|
||||||
|
return binding.fromId(id)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -236,7 +236,7 @@ const loadDevToolsExtensions = function (win, manifests) {
|
||||||
win.devToolsWebContents.executeJavaScript(`DevToolsAPI.addExtensions(${JSON.stringify(extensionInfoArray)})`)
|
win.devToolsWebContents.executeJavaScript(`DevToolsAPI.addExtensions(${JSON.stringify(extensionInfoArray)})`)
|
||||||
}
|
}
|
||||||
|
|
||||||
webContents.on('web-contents-created', function (webContents) {
|
app.on('web-contents-created', function (event, webContents) {
|
||||||
if (webContents.getType() === 'remote') return
|
if (webContents.getType() === 'remote') return
|
||||||
|
|
||||||
hookWebContentsForTabEvents(webContents)
|
hookWebContentsForTabEvents(webContents)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue