Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1737)

Unified Diff: chrome/renderer/resources/extensions/messaging.js

Issue 145463002: Extensions: Send the tab id to platform apps. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/renderer/resources/extensions/messaging.js
===================================================================
--- chrome/renderer/resources/extensions/messaging.js (revision 246436)
+++ chrome/renderer/resources/extensions/messaging.js (working copy)
@@ -30,6 +30,9 @@
// unloadEvent listeners when ports are closed.
var portReleasers = {};
+ // A stack of tabs ids for the tabs that are dispatching requests.
+ var dispatchingTabIds = [];
+
// Change even to odd and vice versa, to get the other side of a given
// channel.
function getOppositePortId(portId) { return portId ^ 1; }
@@ -142,7 +145,7 @@
// Helper function for dispatchOnConnect
function dispatchOnRequest(portId, channelName, sender,
sourceExtensionId, targetExtensionId, sourceUrl,
- isExternal) {
+ isExternal, senderTabId) {
var isSendMessage = channelName == kMessageChannel;
var requestEvent = null;
if (isSendMessage) {
@@ -186,7 +189,12 @@
port = null;
}
});
+ if (senderTabId)
+ dispatchingTabIds.push(senderTabId);
var rv = requestEvent.dispatch(request, sender, responseCallback);
+ if (senderTabId)
+ dispatchingTabIds.pop();
+
if (isSendMessage) {
responseCallbackPreserved =
rv && rv.results && $Array.indexOf(rv.results, true) > -1;
@@ -241,16 +249,19 @@
sender.id = sourceExtensionId;
if (sourceUrl)
sender.url = sourceUrl;
- if (sourceTab)
+ if (sourceTab && !('isPlatformApp' in sourceTab))
sender.tab = sourceTab;
if (tlsChannelId !== undefined)
sender.tlsChannelId = tlsChannelId;
// Special case for sendRequest/onRequest and sendMessage/onMessage.
if (channelName == kRequestChannel || channelName == kMessageChannel) {
+ var senderTabId =
+ (sourceTab && ('id' in sourceTab) && ('isPlatformApp' in sourceTab)) ?
+ sourceTab['id'] : null;
return dispatchOnRequest(portId, channelName, sender,
sourceExtensionId, targetExtensionId, sourceUrl,
- isExternal);
+ isExternal, senderTabId);
not at google - send to devlin 2014/01/23 16:41:59 The above comment said... maybe it would be easier
}
var connectEvent = null;
@@ -360,6 +371,10 @@
return alignedArgs;
}
+ function currentTabId() {
+ return dispatchingTabIds[dispatchingTabIds.length - 1];
+ }
+
exports.kRequestChannel = kRequestChannel;
exports.kMessageChannel = kMessageChannel;
exports.kNativeMessageChannel = kNativeMessageChannel;
@@ -367,6 +382,7 @@
exports.createPort = createPort;
exports.sendMessageImpl = sendMessageImpl;
exports.sendMessageUpdateArguments = sendMessageUpdateArguments;
+exports.currentTabId = currentTabId;
// For C++ code to call.
exports.hasPort = hasPort;

Powered by Google App Engine
This is Rietveld 408576698