OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // This contains unprivileged javascript APIs for extensions and apps. It | 5 // This contains unprivileged javascript APIs for extensions and apps. It |
6 // can be loaded by any extension-related context, such as content scripts or | 6 // can be loaded by any extension-related context, such as content scripts or |
7 // background pages. See user_script_slave.cc for script that is loaded by | 7 // background pages. See user_script_slave.cc for script that is loaded by |
8 // content scripts only. | 8 // content scripts only. |
9 | 9 |
10 // TODO(kalman): factor requiring chrome out of here. | 10 // TODO(kalman): factor requiring chrome out of here. |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 if (targetExtensionId != extensionId) | 198 if (targetExtensionId != extensionId) |
199 return false; // not for us | 199 return false; // not for us |
200 | 200 |
201 if (ports[getOppositePortId(portId)]) | 201 if (ports[getOppositePortId(portId)]) |
202 return false; // this channel was opened by us, so ignore it | 202 return false; // this channel was opened by us, so ignore it |
203 | 203 |
204 // Determine whether this is coming from another extension, so we can use | 204 // Determine whether this is coming from another extension, so we can use |
205 // the right event. | 205 // the right event. |
206 var isExternal = sourceExtensionId != extensionId; | 206 var isExternal = sourceExtensionId != extensionId; |
207 | 207 |
208 var sender = {id: sourceExtensionId}; | 208 var sender = {}; |
| 209 if (sourceExtensionId != '') |
| 210 sender.id = sourceExtensionId; |
209 if (sourceUrl) | 211 if (sourceUrl) |
210 sender.url = sourceUrl; | 212 sender.url = sourceUrl; |
211 if (sourceTab) | 213 if (sourceTab) |
212 sender.tab = sourceTab; | 214 sender.tab = sourceTab; |
213 | 215 |
214 // Special case for sendRequest/onRequest and sendMessage/onMessage. | 216 // Special case for sendRequest/onRequest and sendMessage/onMessage. |
215 if (channelName == kRequestChannel || channelName == kMessageChannel) { | 217 if (channelName == kRequestChannel || channelName == kMessageChannel) { |
216 return dispatchOnRequest(portId, channelName, sender, | 218 return dispatchOnRequest(portId, channelName, sender, |
217 sourceExtensionId, targetExtensionId, sourceUrl, | 219 sourceExtensionId, targetExtensionId, sourceUrl, |
218 isExternal); | 220 isExternal); |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
335 exports.Port = Port; | 337 exports.Port = Port; |
336 exports.createPort = createPort; | 338 exports.createPort = createPort; |
337 exports.sendMessageImpl = sendMessageImpl; | 339 exports.sendMessageImpl = sendMessageImpl; |
338 exports.sendMessageUpdateArguments = sendMessageUpdateArguments; | 340 exports.sendMessageUpdateArguments = sendMessageUpdateArguments; |
339 | 341 |
340 // For C++ code to call. | 342 // For C++ code to call. |
341 exports.hasPort = hasPort; | 343 exports.hasPort = hasPort; |
342 exports.dispatchOnConnect = dispatchOnConnect; | 344 exports.dispatchOnConnect = dispatchOnConnect; |
343 exports.dispatchOnDisconnect = dispatchOnDisconnect; | 345 exports.dispatchOnDisconnect = dispatchOnDisconnect; |
344 exports.dispatchOnMessage = dispatchOnMessage; | 346 exports.dispatchOnMessage = dispatchOnMessage; |
OLD | NEW |