From 97c04735a27bf58b5bbe962eddf8babb0842cf25 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Fri, 27 May 2016 09:55:59 +0900 Subject: [PATCH] Handle unloading devtools correctly --- lib/browser/chrome-extension.js | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/lib/browser/chrome-extension.js b/lib/browser/chrome-extension.js index 1ccc130ebb..f02a1113cc 100644 --- a/lib/browser/chrome-extension.js +++ b/lib/browser/chrome-extension.js @@ -60,7 +60,7 @@ const startBackgroundPages = function (manifest) { const html = new Buffer(`${scripts}`) const contents = webContents.create({}) - backgroundPages[manifest.hostname] = { html: html, contents: contents } + backgroundPages[manifest.hostname] = { html: html, webContents: contents } contents.loadURL(url.format({ protocol: 'chrome-extension', slashes: true, @@ -69,6 +69,13 @@ const startBackgroundPages = function (manifest) { })) } +const removeBackgroundPages = function (manifest) { + if (!backgroundPages[manifest.hostname]) return + + backgroundPages[manifest.hostname].webContents.destroy() + delete backgroundPages[manifest.hostname] +} + // Transfer the content scripts to renderer. const contentScripts = {} @@ -97,6 +104,13 @@ const injectContentScripts = function (manifest) { } } +const removeContentScripts = function (manifest) { + if (!contentScripts[manifest.name]) return + + renderProcessPreferences.removeEntry(contentScripts[manifest.name]) + delete contentScripts[manifest.name] +} + // Transfer the |manifest| to a format that can be recognized by the // |DevToolsAPI.addExtensions|. const manifestToExtensionInfo = function (manifest) { @@ -200,6 +214,11 @@ app.once('ready', function () { } } BrowserWindow.removeDevToolsExtension = function (name) { + const manifest = manifestMap[name] + if (!manifest) return + + removeBackgroundPages(manifest) + removeContentScripts(manifest) delete manifestMap[name] }