|
@@ -6,6 +6,7 @@ if (process.electronBinding('features').isExtensionsEnabled()) {
|
|
|
|
|
|
const { app, webContents, BrowserWindow } = require('electron')
|
|
|
const { getAllWebContents } = process.electronBinding('web_contents')
|
|
|
+const { ipcMainInternal } = require('@electron/internal/browser/ipc-main-internal')
|
|
|
const ipcMainUtils = require('@electron/internal/browser/ipc-main-internal-utils')
|
|
|
|
|
|
const { Buffer } = require('buffer')
|
|
@@ -160,7 +161,7 @@ const hookWebContentsEvents = function (webContents) {
|
|
|
// Handle the chrome.* API messages.
|
|
|
let nextId = 0
|
|
|
|
|
|
-ipcMainUtils.handle('CHROME_RUNTIME_CONNECT', function (event, extensionId, connectInfo) {
|
|
|
+ipcMainUtils.handleSync('CHROME_RUNTIME_CONNECT', function (event, extensionId, connectInfo) {
|
|
|
if (isBackgroundPage(event.sender)) {
|
|
|
throw new Error('chrome.runtime.connect is not supported in background page')
|
|
|
}
|
|
@@ -182,7 +183,7 @@ ipcMainUtils.handle('CHROME_RUNTIME_CONNECT', function (event, extensionId, conn
|
|
|
return { tabId, portId }
|
|
|
})
|
|
|
|
|
|
-ipcMainUtils.handle('CHROME_EXTENSION_MANIFEST', function (event, extensionId) {
|
|
|
+ipcMainUtils.handleSync('CHROME_EXTENSION_MANIFEST', function (event, extensionId) {
|
|
|
const manifest = manifestMap[extensionId]
|
|
|
if (!manifest) {
|
|
|
throw new Error(`Invalid extensionId: ${extensionId}`)
|
|
@@ -190,7 +191,7 @@ ipcMainUtils.handle('CHROME_EXTENSION_MANIFEST', function (event, extensionId) {
|
|
|
return manifest
|
|
|
})
|
|
|
|
|
|
-ipcMainUtils.handle('CHROME_RUNTIME_SEND_MESSAGE', async function (event, extensionId, message) {
|
|
|
+ipcMainInternal.handle('CHROME_RUNTIME_SEND_MESSAGE', async function (event, extensionId, message) {
|
|
|
if (isBackgroundPage(event.sender)) {
|
|
|
throw new Error('chrome.runtime.sendMessage is not supported in background page')
|
|
|
}
|
|
@@ -203,7 +204,7 @@ ipcMainUtils.handle('CHROME_RUNTIME_SEND_MESSAGE', async function (event, extens
|
|
|
return ipcMainUtils.invokeInWebContents(page.webContents, true, `CHROME_RUNTIME_ONMESSAGE_${extensionId}`, event.sender.id, message)
|
|
|
})
|
|
|
|
|
|
-ipcMainUtils.handle('CHROME_TABS_SEND_MESSAGE', async function (event, tabId, extensionId, message) {
|
|
|
+ipcMainInternal.handle('CHROME_TABS_SEND_MESSAGE', async function (event, tabId, extensionId, message) {
|
|
|
const contents = webContents.fromId(tabId)
|
|
|
if (!contents) {
|
|
|
throw new Error(`Sending message to unknown tab ${tabId}`)
|
|
@@ -237,7 +238,7 @@ const getMessagesPath = (extensionId) => {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-ipcMainUtils.handle('CHROME_GET_MESSAGES', async function (event, extensionId) {
|
|
|
+ipcMainUtils.handleSync('CHROME_GET_MESSAGES', async function (event, extensionId) {
|
|
|
const messagesPath = getMessagesPath(extensionId)
|
|
|
return fs.promises.readFile(messagesPath)
|
|
|
})
|
|
@@ -256,7 +257,7 @@ const getChromeStoragePath = (storageType, extensionId) => {
|
|
|
return path.join(app.getPath('userData'), `/Chrome Storage/${extensionId}-${storageType}.json`)
|
|
|
}
|
|
|
|
|
|
-ipcMainUtils.handle('CHROME_STORAGE_READ', async function (event, storageType, extensionId) {
|
|
|
+ipcMainInternal.handle('CHROME_STORAGE_READ', async function (event, storageType, extensionId) {
|
|
|
const filePath = getChromeStoragePath(storageType, extensionId)
|
|
|
|
|
|
try {
|
|
@@ -270,7 +271,7 @@ ipcMainUtils.handle('CHROME_STORAGE_READ', async function (event, storageType, e
|
|
|
}
|
|
|
})
|
|
|
|
|
|
-ipcMainUtils.handle('CHROME_STORAGE_WRITE', async function (event, storageType, extensionId, data) {
|
|
|
+ipcMainInternal.handle('CHROME_STORAGE_WRITE', async function (event, storageType, extensionId, data) {
|
|
|
const filePath = getChromeStoragePath(storageType, extensionId)
|
|
|
|
|
|
try {
|
|
@@ -295,7 +296,7 @@ const assertChromeExtension = function (contents, api) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-ipcMainUtils.handle('CHROME_TABS_EXECUTE_SCRIPT', async function (event, tabId, extensionId, details) {
|
|
|
+ipcMainInternal.handle('CHROME_TABS_EXECUTE_SCRIPT', async function (event, tabId, extensionId, details) {
|
|
|
assertChromeExtension(event.sender, 'chrome.tabs.executeScript()')
|
|
|
|
|
|
const contents = webContents.fromId(tabId)
|