refactor: use ipcMainUtils.invokeInWebContents / ipcRendererUtils.handle helpers for Chrome APIs (#17417)

This commit is contained in:
Milan Burda 2019-03-26 03:38:35 +01:00 committed by Cheng Zhao
parent 546466b209
commit 336db33d18
9 changed files with 82 additions and 99 deletions

View file

@ -1,6 +1,7 @@
import { ipcRendererInternal } from '@electron/internal/renderer/ipc-renderer-internal'
import { webFrame } from 'electron'
import * as ipcRendererUtils from '@electron/internal/renderer/ipc-renderer-internal-utils'
const v8Util = process.electronBinding('v8_util')
const IsolatedWorldIDs = {
@ -94,17 +95,13 @@ const injectContentScript = function (extensionId: string, script: Electron.Cont
}
// Handle the request of chrome.tabs.executeJavaScript.
ipcRendererInternal.on('CHROME_TABS_EXECUTESCRIPT', function (
ipcRendererUtils.handle('CHROME_TABS_EXECUTE_SCRIPT', function (
event: Electron.Event,
senderWebContentsId: number,
requestId: number,
extensionId: string,
url: string,
code: string
) {
runContentScript.call(window, extensionId, url, code).then(result => {
ipcRendererInternal.sendToAll(senderWebContentsId, `CHROME_TABS_EXECUTESCRIPT_RESULT_${requestId}`, result)
})
return runContentScript.call(window, extensionId, url, code)
})
module.exports = (getRenderProcessPreferences: typeof process.getRenderProcessPreferences) => {