refactor: simplify content script injection (#18532)

This commit is contained in:
Jeremy Apthorp 2019-06-04 16:07:34 -07:00 committed by GitHub
parent f80601da16
commit ed5fb4a720
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
17 changed files with 63 additions and 407 deletions

View file

@ -108,15 +108,17 @@ ipcRendererUtils.handle('CHROME_TABS_EXECUTE_SCRIPT', function (
return runContentScript.call(window, extensionId, url, code)
})
module.exports = (getRenderProcessPreferences: typeof process.getRenderProcessPreferences) => {
// Read the renderer process preferences.
const preferences = getRenderProcessPreferences()
if (preferences) {
for (const pref of preferences) {
if (pref.contentScripts) {
for (const script of pref.contentScripts) {
injectContentScript(pref.extensionId, script)
}
type ContentScriptEntry = {
extensionId: string;
contentScripts: Electron.ContentScript[];
}
module.exports = () => {
const entries = ipcRendererUtils.invokeSync<ContentScriptEntry[]>('CHROME_GET_CONTENT_SCRIPTS')
for (const entry of entries) {
if (entry.contentScripts) {
for (const script of entry.contentScripts) {
injectContentScript(entry.extensionId, script)
}
}
}