Pass sender for chrome.runtime.onMessage
authorCheng Zhao <zcbenz@gmail.com>
Sat, 28 May 2016 12:45:23 +0000 (21:45 +0900)
committerCheng Zhao <zcbenz@gmail.com>
Sat, 28 May 2016 12:45:23 +0000 (21:45 +0900)
lib/browser/chrome-extension.js
lib/renderer/chrome-api.js

index ad78e18..9cdebdb 100644 (file)
@@ -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) {
index fc3ea30..19bf69f 100644 (file)
@@ -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 = {