From c8c60dd3131aed463cb65472b4d81d7dc2ff5ee8 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Wed, 8 Jun 2016 11:15:41 -0700 Subject: [PATCH] Add devtools from web-contents-created event --- lib/browser/api/web-contents.js | 20 +++++++++++--------- lib/browser/chrome-extension.js | 21 +++++++-------------- lib/browser/guest-view-manager.js | 4 ---- 3 files changed, 18 insertions(+), 27 deletions(-) diff --git a/lib/browser/api/web-contents.js b/lib/browser/api/web-contents.js index ed7bfe0b8bdf..a3b4009aae77 100644 --- a/lib/browser/api/web-contents.js +++ b/lib/browser/api/web-contents.js @@ -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 diff --git a/lib/browser/chrome-extension.js b/lib/browser/chrome-extension.js index f14f56cb1866..bb89c22e2551 100644 --- a/lib/browser/chrome-extension.js +++ b/lib/browser/chrome-extension.js @@ -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)) - }) -} diff --git a/lib/browser/guest-view-manager.js b/lib/browser/guest-view-manager.js index e810aa549483..fdd426c229f6 100644 --- a/lib/browser/guest-view-manager.js +++ b/lib/browser/guest-view-manager.js @@ -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 }