From 19787544b5f6b5323ade07ac3c155d508b45a24f Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Tue, 7 Jun 2016 09:50:06 -0700 Subject: [PATCH 01/44] Add failing spec for webview devtools extension --- spec/fixtures/pages/webview-devtools.html | 30 +++++++++++++++++++++++ spec/webview-spec.js | 20 +++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 spec/fixtures/pages/webview-devtools.html diff --git a/spec/fixtures/pages/webview-devtools.html b/spec/fixtures/pages/webview-devtools.html new file mode 100644 index 000000000000..c16dbb2f8f14 --- /dev/null +++ b/spec/fixtures/pages/webview-devtools.html @@ -0,0 +1,30 @@ + + + + + + + + + + + diff --git a/spec/webview-spec.js b/spec/webview-spec.js index b1fa4405ada8..a588f389bea9 100644 --- a/spec/webview-spec.js +++ b/spec/webview-spec.js @@ -912,4 +912,24 @@ describe(' tag', function () { w.loadURL('file://' + fixtures + '/pages/webview-visibilitychange.html') }) + + it('loads devtools extension registered on the parent window', function (done) { + this.timeout(10000) + + w = new BrowserWindow({ + show: false + }) + + BrowserWindow.removeDevToolsExtension('foo') + + var extensionPath = path.join(__dirname, 'fixtures', 'devtools-extensions', 'foo') + BrowserWindow.addDevToolsExtension(extensionPath) + + w.loadURL('file://' + fixtures + '/pages/webview-devtools.html') + + ipcMain.once('answer', function (event, message) { + assert.equal(message.runtimeId, 'foo') + done() + }) + }) }) From 4f46f75d8f804fcc001417c710b02ade7541da2c Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Tue, 7 Jun 2016 09:50:36 -0700 Subject: [PATCH 02/44] Load dev tools extensions in webviews --- lib/browser/chrome-extension.js | 15 ++++++++++----- lib/browser/guest-view-manager.js | 5 +++++ 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/lib/browser/chrome-extension.js b/lib/browser/chrome-extension.js index d3c76ce797be..fac80d9177e6 100644 --- a/lib/browser/chrome-extension.js +++ b/lib/browser/chrome-extension.js @@ -81,8 +81,8 @@ const removeBackgroundPages = function (manifest) { } // Dispatch tabs events. -const hookWindowForTabEvents = function (win) { - const tabId = win.webContents.id +const hookWindowForTabEvents = function (win, webContents) { + const tabId = webContents.id for (const page of objectValues(backgroundPages)) { page.webContents.sendToAll('CHROME_TABS_ONCREATED', tabId) } @@ -301,6 +301,7 @@ app.once('ready', function () { return manifest.name } } + BrowserWindow.removeDevToolsExtension = function (name) { const manifest = manifestNameMap[name] if (!manifest) return @@ -315,9 +316,13 @@ app.once('ready', function () { const init = BrowserWindow.prototype._init BrowserWindow.prototype._init = function () { init.call(this) - hookWindowForTabEvents(this) - this.webContents.on('devtools-opened', () => { - loadDevToolsExtensions(this, objectValues(manifestMap)) + this._loadDevToolsExtensions(this.webContents) + } + + BrowserWindow.prototype._loadDevToolsExtensions = function (webContents) { + hookWindowForTabEvents(this, 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 fdd426c229f6..8bccaad84b0e 100644 --- a/lib/browser/guest-view-manager.js +++ b/lib/browser/guest-view-manager.js @@ -1,5 +1,6 @@ 'use strict' +const BrowserWindow = require('electron').BrowserWindow const ipcMain = require('electron').ipcMain const webContents = require('electron').webContents @@ -150,6 +151,10 @@ 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 + const window = BrowserWindow.fromWebContents(embedder) + if (window) window._loadDevToolsExtensions(guest) + return id } From 4c1ede32cfa1358acfe0c6f60b7b3b0b38f2c8a5 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Tue, 7 Jun 2016 10:10:56 -0700 Subject: [PATCH 03/44] Use destroyed event instead of closed event --- lib/browser/chrome-extension.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/browser/chrome-extension.js b/lib/browser/chrome-extension.js index fac80d9177e6..c323819a7877 100644 --- a/lib/browser/chrome-extension.js +++ b/lib/browser/chrome-extension.js @@ -81,13 +81,13 @@ const removeBackgroundPages = function (manifest) { } // Dispatch tabs events. -const hookWindowForTabEvents = function (win, webContents) { +const hookWindowForTabEvents = function (webContents) { const tabId = webContents.id for (const page of objectValues(backgroundPages)) { page.webContents.sendToAll('CHROME_TABS_ONCREATED', tabId) } - win.once('closed', () => { + webContents.once('destroyed', () => { for (const page of objectValues(backgroundPages)) { page.webContents.sendToAll('CHROME_TABS_ONREMOVED', tabId) } @@ -320,7 +320,7 @@ app.once('ready', function () { } BrowserWindow.prototype._loadDevToolsExtensions = function (webContents) { - hookWindowForTabEvents(this, webContents) + hookWindowForTabEvents(webContents) webContents.on('devtools-opened', function () { loadDevToolsExtensions(webContents, objectValues(manifestMap)) }) From 78e3bb066038c76b25a7ba1ff9e2be2e7bf60b27 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Tue, 7 Jun 2016 10:11:47 -0700 Subject: [PATCH 04/44] :art: --- lib/browser/guest-view-manager.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/browser/guest-view-manager.js b/lib/browser/guest-view-manager.js index 8bccaad84b0e..61ab7673fb1c 100644 --- a/lib/browser/guest-view-manager.js +++ b/lib/browser/guest-view-manager.js @@ -1,8 +1,6 @@ 'use strict' -const BrowserWindow = require('electron').BrowserWindow -const ipcMain = require('electron').ipcMain -const webContents = require('electron').webContents +const {BrowserWindow, ipcMain, webContents} = require('electron') // Doesn't exist in early initialization. let webViewManager = null From bf47056561ee613105072f10be2f7079cc9fcc49 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Tue, 7 Jun 2016 10:34:17 -0700 Subject: [PATCH 05/44] Pluralize extension --- spec/webview-spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/webview-spec.js b/spec/webview-spec.js index a588f389bea9..3e22a79a9cf7 100644 --- a/spec/webview-spec.js +++ b/spec/webview-spec.js @@ -913,7 +913,7 @@ describe(' tag', function () { w.loadURL('file://' + fixtures + '/pages/webview-visibilitychange.html') }) - it('loads devtools extension registered on the parent window', function (done) { + it('loads devtools extensions registered on the parent window', function (done) { this.timeout(10000) w = new BrowserWindow({ From 4f7bde38a973cd0e95722bfd270dbddb3f4c592c Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Tue, 7 Jun 2016 10:38:01 -0700 Subject: [PATCH 06/44] Assert on tab id as well --- spec/api-browser-window-spec.js | 2 ++ spec/fixtures/devtools-extensions/foo/index.html | 3 ++- spec/webview-spec.js | 1 + 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/spec/api-browser-window-spec.js b/spec/api-browser-window-spec.js index 11b954d2d07a..6a76ba5ddb6c 100644 --- a/spec/api-browser-window-spec.js +++ b/spec/api-browser-window-spec.js @@ -864,6 +864,7 @@ describe('browser-window module', function () { ipcMain.once('answer', function (event, message) { assert.equal(message.runtimeId, 'foo') + assert.equal(message.tabId, w.webContents.id) done() }) }) @@ -875,6 +876,7 @@ describe('browser-window module', function () { ipcMain.once('answer', function (event, message, extensionId) { assert.equal(message.runtimeId, 'foo') + assert.equal(message.tabId, w.webContents.id) done() }) }) diff --git a/spec/fixtures/devtools-extensions/foo/index.html b/spec/fixtures/devtools-extensions/foo/index.html index 1b9d1b8cb9b4..2e0a29aff3d0 100644 --- a/spec/fixtures/devtools-extensions/foo/index.html +++ b/spec/fixtures/devtools-extensions/foo/index.html @@ -5,7 +5,8 @@