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

Side by Side Diff: extensions/renderer/resources/messaging.js

Issue 709933002: Add frameId to MessageSender (extension messaging API) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add test that tests for a non-negative frameId Created 6 years, 1 month 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // chrome.runtime.messaging API implementation. 5 // chrome.runtime.messaging API implementation.
6 6
7 // TODO(kalman): factor requiring chrome out of here. 7 // TODO(kalman): factor requiring chrome out of here.
8 var chrome = requireNative('chrome').GetChrome(); 8 var chrome = requireNative('chrome').GetChrome();
9 var Event = require('event_bindings').Event; 9 var Event = require('event_bindings').Event;
10 var lastError = require('lastError'); 10 var lastError = require('lastError');
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 logActivity.LogEvent(targetExtensionId, 209 logActivity.LogEvent(targetExtensionId,
210 eventName, 210 eventName,
211 [sourceExtensionId, sourceUrl]); 211 [sourceExtensionId, sourceUrl]);
212 return true; 212 return true;
213 } 213 }
214 214
215 // Called by native code when a channel has been opened to this context. 215 // Called by native code when a channel has been opened to this context.
216 function dispatchOnConnect(portId, 216 function dispatchOnConnect(portId,
217 channelName, 217 channelName,
218 sourceTab, 218 sourceTab,
219 sourceFrameId,
219 sourceExtensionId, 220 sourceExtensionId,
220 targetExtensionId, 221 targetExtensionId,
221 sourceUrl, 222 sourceUrl,
222 tlsChannelId) { 223 tlsChannelId) {
223 // Only create a new Port if someone is actually listening for a connection. 224 // Only create a new Port if someone is actually listening for a connection.
224 // In addition to being an optimization, this also fixes a bug where if 2 225 // In addition to being an optimization, this also fixes a bug where if 2
225 // channels were opened to and from the same process, closing one would 226 // channels were opened to and from the same process, closing one would
226 // close both. 227 // close both.
227 var extensionId = processNatives.GetExtensionId(); 228 var extensionId = processNatives.GetExtensionId();
228 229
229 // messaging_bindings.cc should ensure that this method only gets called for 230 // messaging_bindings.cc should ensure that this method only gets called for
230 // the right extension. 231 // the right extension.
231 logging.CHECK(targetExtensionId == extensionId); 232 logging.CHECK(targetExtensionId == extensionId);
232 233
233 if (ports[getOppositePortId(portId)]) 234 if (ports[getOppositePortId(portId)])
234 return false; // this channel was opened by us, so ignore it 235 return false; // this channel was opened by us, so ignore it
235 236
236 // Determine whether this is coming from another extension, so we can use 237 // Determine whether this is coming from another extension, so we can use
237 // the right event. 238 // the right event.
238 var isExternal = sourceExtensionId != extensionId; 239 var isExternal = sourceExtensionId != extensionId;
239 240
240 var sender = {}; 241 var sender = {};
241 if (sourceExtensionId != '') 242 if (sourceExtensionId != '')
242 sender.id = sourceExtensionId; 243 sender.id = sourceExtensionId;
243 if (sourceUrl) 244 if (sourceUrl)
244 sender.url = sourceUrl; 245 sender.url = sourceUrl;
245 if (sourceTab) 246 if (sourceTab) {
246 sender.tab = sourceTab; 247 sender.tab = sourceTab;
248 sender.frameId = sourceFrameId;
249 }
not at google - send to devlin 2014/11/10 18:36:42 Minimise the amount of logic scattered about the p
robwu 2014/11/10 21:43:07 I've done this to make sure that frameId is only s
247 if (tlsChannelId !== undefined) 250 if (tlsChannelId !== undefined)
248 sender.tlsChannelId = tlsChannelId; 251 sender.tlsChannelId = tlsChannelId;
249 252
250 // Special case for sendRequest/onRequest and sendMessage/onMessage. 253 // Special case for sendRequest/onRequest and sendMessage/onMessage.
251 if (channelName == kRequestChannel || channelName == kMessageChannel) { 254 if (channelName == kRequestChannel || channelName == kMessageChannel) {
252 return dispatchOnRequest(portId, channelName, sender, 255 return dispatchOnRequest(portId, channelName, sender,
253 sourceExtensionId, targetExtensionId, sourceUrl, 256 sourceExtensionId, targetExtensionId, sourceUrl,
254 isExternal); 257 isExternal);
255 } 258 }
256 259
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
377 exports.Port = Port; 380 exports.Port = Port;
378 exports.createPort = createPort; 381 exports.createPort = createPort;
379 exports.sendMessageImpl = sendMessageImpl; 382 exports.sendMessageImpl = sendMessageImpl;
380 exports.sendMessageUpdateArguments = sendMessageUpdateArguments; 383 exports.sendMessageUpdateArguments = sendMessageUpdateArguments;
381 384
382 // For C++ code to call. 385 // For C++ code to call.
383 exports.hasPort = hasPort; 386 exports.hasPort = hasPort;
384 exports.dispatchOnConnect = dispatchOnConnect; 387 exports.dispatchOnConnect = dispatchOnConnect;
385 exports.dispatchOnDisconnect = dispatchOnDisconnect; 388 exports.dispatchOnDisconnect = dispatchOnDisconnect;
386 exports.dispatchOnMessage = dispatchOnMessage; 389 exports.dispatchOnMessage = dispatchOnMessage;
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698