Handle unloading devtools correctly

This commit is contained in:
Cheng Zhao 2016-05-27 09:55:59 +09:00
parent a63ff714f8
commit 97c04735a2

View file

@ -60,7 +60,7 @@ const startBackgroundPages = function (manifest) {
const html = new Buffer(`<html><body>${scripts}</body></html>`)
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]
}