зеркало из https://github.com/electron/electron.git
Move chromeExtensionHandler out of ready handler
This code were in ready handler because we could not require "protocol" before ready before. It is now safe to move the code out.
This commit is contained in:
Родитель
6db75a3458
Коммит
e653c67153
|
@ -284,6 +284,39 @@ app.on('web-contents-created', function (event, webContents) {
|
|||
})
|
||||
})
|
||||
|
||||
// The chrome-extension: can map a extension URL request to real file path.
|
||||
const chromeExtensionHandler = function (request, callback) {
|
||||
const parsed = url.parse(request.url)
|
||||
if (!parsed.hostname || !parsed.path) return callback()
|
||||
|
||||
const manifest = manifestMap[parsed.hostname]
|
||||
if (!manifest) return callback()
|
||||
|
||||
const page = backgroundPages[parsed.hostname]
|
||||
if (page && parsed.path === `/${page.name}`) {
|
||||
return callback({
|
||||
mimeType: 'text/html',
|
||||
data: page.html
|
||||
})
|
||||
}
|
||||
|
||||
fs.readFile(path.join(manifest.srcDirectory, parsed.path), function (err, content) {
|
||||
if (err) {
|
||||
return callback(-6) // FILE_NOT_FOUND
|
||||
} else {
|
||||
return callback(content)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
app.on('session-created', function (ses) {
|
||||
ses.protocol.registerBufferProtocol('chrome-extension', chromeExtensionHandler, function (error) {
|
||||
if (error) {
|
||||
console.error(`Unable to register chrome-extension protocol: ${error}`)
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
// The persistent path of "DevTools Extensions" preference file.
|
||||
let loadedExtensionsPath = null
|
||||
|
||||
|
@ -309,38 +342,6 @@ app.on('will-quit', function () {
|
|||
|
||||
// We can not use protocol or BrowserWindow until app is ready.
|
||||
app.once('ready', function () {
|
||||
// The chrome-extension: can map a extension URL request to real file path.
|
||||
const chromeExtensionHandler = function (request, callback) {
|
||||
const parsed = url.parse(request.url)
|
||||
if (!parsed.hostname || !parsed.path) return callback()
|
||||
|
||||
const manifest = manifestMap[parsed.hostname]
|
||||
if (!manifest) return callback()
|
||||
|
||||
const page = backgroundPages[parsed.hostname]
|
||||
if (page && parsed.path === `/${page.name}`) {
|
||||
return callback({
|
||||
mimeType: 'text/html',
|
||||
data: page.html
|
||||
})
|
||||
}
|
||||
|
||||
fs.readFile(path.join(manifest.srcDirectory, parsed.path), function (err, content) {
|
||||
if (err) {
|
||||
return callback(-6) // FILE_NOT_FOUND
|
||||
} else {
|
||||
return callback(content)
|
||||
}
|
||||
})
|
||||
}
|
||||
app.on('session-created', function (ses) {
|
||||
ses.protocol.registerBufferProtocol('chrome-extension', chromeExtensionHandler, function (error) {
|
||||
if (error) {
|
||||
console.error(`Unable to register chrome-extension protocol: ${error}`)
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
// Load persisted extensions.
|
||||
loadedExtensionsPath = path.join(app.getPath('userData'), 'DevTools Extensions')
|
||||
try {
|
||||
|
|
Загрузка…
Ссылка в новой задаче