Merge pull request #6298 from jhen0409/patch-5
Support background.page in extension manifest
This commit is contained in:
commit
5dcc354432
1 changed files with 17 additions and 9 deletions
|
@ -72,21 +72,29 @@ const backgroundPages = {}
|
||||||
const startBackgroundPages = function (manifest) {
|
const startBackgroundPages = function (manifest) {
|
||||||
if (backgroundPages[manifest.extensionId] || !manifest.background) return
|
if (backgroundPages[manifest.extensionId] || !manifest.background) return
|
||||||
|
|
||||||
const scripts = manifest.background.scripts.map((name) => {
|
let html
|
||||||
return `<script src="${name}"></script>`
|
let name
|
||||||
}).join('')
|
if (manifest.background.page) {
|
||||||
const html = new Buffer(`<html><body>${scripts}</body></html>`)
|
name = manifest.background.page
|
||||||
|
html = fs.readFileSync(path.join(manifest.srcDirectory, manifest.background.page))
|
||||||
|
} else {
|
||||||
|
name = '_generated_background_page.html'
|
||||||
|
const scripts = manifest.background.scripts.map((name) => {
|
||||||
|
return `<script src="${name}"></script>`
|
||||||
|
}).join('')
|
||||||
|
html = new Buffer(`<html><body>${scripts}</body></html>`)
|
||||||
|
}
|
||||||
|
|
||||||
const contents = webContents.create({
|
const contents = webContents.create({
|
||||||
isBackgroundPage: true,
|
isBackgroundPage: true,
|
||||||
commandLineSwitches: ['--background-page']
|
commandLineSwitches: ['--background-page']
|
||||||
})
|
})
|
||||||
backgroundPages[manifest.extensionId] = { html: html, webContents: contents }
|
backgroundPages[manifest.extensionId] = { html: html, webContents: contents, name: name }
|
||||||
contents.loadURL(url.format({
|
contents.loadURL(url.format({
|
||||||
protocol: 'chrome-extension',
|
protocol: 'chrome-extension',
|
||||||
slashes: true,
|
slashes: true,
|
||||||
hostname: manifest.extensionId,
|
hostname: manifest.extensionId,
|
||||||
pathname: '_generated_background_page.html'
|
pathname: name
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -309,11 +317,11 @@ app.once('ready', function () {
|
||||||
const manifest = manifestMap[parsed.hostname]
|
const manifest = manifestMap[parsed.hostname]
|
||||||
if (!manifest) return callback()
|
if (!manifest) return callback()
|
||||||
|
|
||||||
if (parsed.path === '/_generated_background_page.html' &&
|
const page = backgroundPages[parsed.hostname]
|
||||||
backgroundPages[parsed.hostname]) {
|
if (page && parsed.path === `/${page.name}`) {
|
||||||
return callback({
|
return callback({
|
||||||
mimeType: 'text/html',
|
mimeType: 'text/html',
|
||||||
data: backgroundPages[parsed.hostname].html
|
data: page.html
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue