From 9ed4730cba8fcaa2a0439868a8fb8b98a665c983 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Sat, 28 May 2016 21:45:23 +0900 Subject: [PATCH] Pass sender for chrome.runtime.onMessage --- lib/browser/chrome-extension.js | 2 +- lib/renderer/chrome-api.js | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/browser/chrome-extension.js b/lib/browser/chrome-extension.js index ad78e18d998b..9cdebdba7d6c 100644 --- a/lib/browser/chrome-extension.js +++ b/lib/browser/chrome-extension.js @@ -93,7 +93,7 @@ ipcMain.on('CHROME_RUNTIME_SENDMESSAGE', function (event, extensionId, message) return } - page.webContents.sendToAll(`CHROME_RUNTIME_ONMESSAGE_${extensionId}`, message) + page.webContents.sendToAll(`CHROME_RUNTIME_ONMESSAGE_${extensionId}`, event.sender.id, message) }) ipcMain.on('CHROME_TABS_EXECUTESCRIPT', function (event, requestId, webContentsId, extensionId, details) { diff --git a/lib/renderer/chrome-api.js b/lib/renderer/chrome-api.js index fc3ea3072f8d..19bf69f9a0df 100644 --- a/lib/renderer/chrome-api.js +++ b/lib/renderer/chrome-api.js @@ -86,8 +86,8 @@ exports.injectTo = function (extensionId, context) { chrome.runtime.onConnect.emit(new Port(webContentsId, portId, extensionId, connectInfo.name)) }) - ipcRenderer.on(`CHROME_RUNTIME_ONMESSAGE_${extensionId}`, (event, message) => { - chrome.runtime.onMessage.emit(message) + ipcRenderer.on(`CHROME_RUNTIME_ONMESSAGE_${extensionId}`, (event, tabId, message) => { + chrome.runtime.onMessage.emit(message, new MessageSender(tabId, extensionId)) }) chrome.runtime = { @@ -148,8 +148,10 @@ exports.injectTo = function (extensionId, context) { if (responseCallback) { console.error('responseCallback is not supported') } - ipcRenderer.sendToAll(tabId, `CHROME_RUNTIME_ONMESSAGE_${extensionId}`, message) - } + ipcRenderer.send('CHROME_RUNTIME_SENDMESSAGE', extensionId, message) + }, + + onUpdated: new Event() } chrome.extension = {