Add devtools from web-contents-created event

This commit is contained in:
Kevin Sawicki 2016-06-08 11:15:41 -07:00
parent d8fe5da3ea
commit c8c60dd313
3 changed files with 18 additions and 27 deletions

View file

@ -10,6 +10,14 @@ session
const binding = process.atomBinding('web_contents')
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
const getNextId = function () {
return ++nextId
@ -223,6 +231,8 @@ const wrapWebContents = function (webContents) {
this._printToPDF(printingSetting, callback)
}
WebContents.emit('web-contents-created', webContents)
}
binding._setWrapWebContents(wrapWebContents)
@ -235,12 +245,4 @@ const wrapDebugger = function (webContentsDebugger) {
debuggerBinding._setWrapDebugger(wrapDebugger)
module.exports = {
create (options = {}) {
return binding.create(options)
},
fromId (id) {
return binding.fromId(id)
}
}
module.exports = WebContents

View file

@ -222,6 +222,13 @@ const loadDevToolsExtensions = function (win, manifests) {
win.devToolsWebContents.executeJavaScript(`DevToolsAPI.addExtensions(${JSON.stringify(extensionInfoArray)})`)
}
webContents.on('web-contents-created', function (webContents) {
hookWindowForTabEvents(webContents)
webContents.on('devtools-opened', function () {
loadDevToolsExtensions(webContents, objectValues(manifestMap))
})
})
// The persistent path of "DevTools Extensions" preference file.
let loadedExtensionsPath = null
@ -312,18 +319,4 @@ app.once('ready', function () {
delete manifestMap[manifest.extensionId]
delete manifestNameMap[name]
}
// Load extensions automatically when devtools is opened.
const init = BrowserWindow.prototype._init
BrowserWindow.prototype._init = function () {
init.call(this)
exports.loadDevToolsExtensions(this.webContents)
}
})
exports.loadDevToolsExtensions = function (webContents) {
hookWindowForTabEvents(webContents)
webContents.on('devtools-opened', function () {
loadDevToolsExtensions(webContents, objectValues(manifestMap))
})
}

View file

@ -1,6 +1,5 @@
'use strict'
const ChromeExtension = require('./chrome-extension')
const ipcMain = require('electron').ipcMain
const webContents = require('electron').webContents
@ -151,9 +150,6 @@ const createGuest = function (embedder, params) {
embedder.send.apply(embedder, ['ELECTRON_GUEST_VIEW_INTERNAL_SIZE_CHANGED-' + guest.viewInstanceId].concat(args))
})
// Enable DevTools extensions in guest view
ChromeExtension.loadDevToolsExtensions(guest)
return id
}