OLD | NEW |
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 // 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. |
11 var chrome = requireNative('chrome').GetChrome(); | 11 var chrome = requireNative('chrome').GetChrome(); |
12 var Event = require('event_bindings').Event; | 12 var Event = require('event_bindings').Event; |
13 var lastError = require('lastError'); | 13 var lastError = require('lastError'); |
14 var logActivity = requireNative('activityLogger'); | 14 var logActivity = requireNative('activityLogger'); |
| 15 var logging = requireNative('logging'); |
15 var messagingNatives = requireNative('messaging_natives'); | 16 var messagingNatives = requireNative('messaging_natives'); |
16 var processNatives = requireNative('process'); | 17 var processNatives = requireNative('process'); |
17 var unloadEvent = require('unload_event'); | 18 var unloadEvent = require('unload_event'); |
18 var utils = require('utils'); | 19 var utils = require('utils'); |
19 var messagingUtils = require('messaging_utils'); | 20 var messagingUtils = require('messaging_utils'); |
20 | 21 |
21 // The reserved channel name for the sendRequest/send(Native)Message APIs. | 22 // The reserved channel name for the sendRequest/send(Native)Message APIs. |
22 // Note: sendRequest is deprecated. | 23 // Note: sendRequest is deprecated. |
23 var kRequestChannel = "chrome.extension.sendRequest"; | 24 var kRequestChannel = "chrome.extension.sendRequest"; |
24 var kMessageChannel = "chrome.runtime.sendMessage"; | 25 var kMessageChannel = "chrome.runtime.sendMessage"; |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 sourceTab, | 221 sourceTab, |
221 sourceExtensionId, | 222 sourceExtensionId, |
222 targetExtensionId, | 223 targetExtensionId, |
223 sourceUrl, | 224 sourceUrl, |
224 tlsChannelId) { | 225 tlsChannelId) { |
225 // Only create a new Port if someone is actually listening for a connection. | 226 // Only create a new Port if someone is actually listening for a connection. |
226 // In addition to being an optimization, this also fixes a bug where if 2 | 227 // In addition to being an optimization, this also fixes a bug where if 2 |
227 // channels were opened to and from the same process, closing one would | 228 // channels were opened to and from the same process, closing one would |
228 // close both. | 229 // close both. |
229 var extensionId = processNatives.GetExtensionId(); | 230 var extensionId = processNatives.GetExtensionId(); |
230 if (targetExtensionId != extensionId) | 231 |
231 return false; // not for us | 232 // messaging_bindings.cc should ensure that this method only gets called for |
| 233 // the right extension. |
| 234 logging.CHECK(targetExtensionId == extensionId); |
232 | 235 |
233 if (ports[getOppositePortId(portId)]) | 236 if (ports[getOppositePortId(portId)]) |
234 return false; // this channel was opened by us, so ignore it | 237 return false; // this channel was opened by us, so ignore it |
235 | 238 |
236 // Determine whether this is coming from another extension, so we can use | 239 // Determine whether this is coming from another extension, so we can use |
237 // the right event. | 240 // the right event. |
238 var isExternal = sourceExtensionId != extensionId; | 241 var isExternal = sourceExtensionId != extensionId; |
239 | 242 |
240 var sender = {}; | 243 var sender = {}; |
241 if (sourceExtensionId != '') | 244 if (sourceExtensionId != '') |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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; |
OLD | NEW |