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 require('json_schema'); | 10 require('json_schema'); |
11 var json = require('json'); | 11 var json = require('json'); |
12 var lastError = require('lastError'); | 12 var lastError = require('lastError'); |
13 var miscNatives = requireNative('miscellaneous_bindings'); | 13 var miscNatives = requireNative('miscellaneous_bindings'); |
14 var chrome = requireNative('chrome').GetChrome(); | 14 var chrome = requireNative('chrome').GetChrome(); |
15 var CloseChannel = miscNatives.CloseChannel; | 15 var CloseChannel = miscNatives.CloseChannel; |
16 var PortAddRef = miscNatives.PortAddRef; | 16 var PortAddRef = miscNatives.PortAddRef; |
17 var PortRelease = miscNatives.PortRelease; | 17 var PortRelease = miscNatives.PortRelease; |
18 var PostMessage = miscNatives.PostMessage; | 18 var PostMessage = miscNatives.PostMessage; |
19 var BindToGC = miscNatives.BindToGC; | 19 var BindToGC = miscNatives.BindToGC; |
20 | 20 |
21 var chromeHidden = requireNative('chrome_hidden').GetChromeHidden(); | 21 var chromeHidden = requireNative('chrome_hidden').GetChromeHidden(); |
22 | 22 |
23 var processNatives = requireNative('process'); | 23 var processNatives = requireNative('process'); |
24 var manifestVersion = processNatives.GetManifestVersion(); | 24 var manifestVersion = processNatives.GetManifestVersion(); |
25 var extensionId = processNatives.GetExtensionId(); | 25 var extensionId = processNatives.GetExtensionId(); |
26 | 26 |
27 var logActivity = requireNative('activityLogger').LogActivity; | |
28 | |
27 // The reserved channel name for the sendRequest/sendMessage APIs. | 29 // The reserved channel name for the sendRequest/sendMessage APIs. |
28 // Note: sendRequest is deprecated. | 30 // Note: sendRequest is deprecated. |
29 chromeHidden.kRequestChannel = "chrome.extension.sendRequest"; | 31 chromeHidden.kRequestChannel = "chrome.extension.sendRequest"; |
30 chromeHidden.kMessageChannel = "chrome.runtime.sendMessage"; | 32 chromeHidden.kMessageChannel = "chrome.runtime.sendMessage"; |
31 chromeHidden.kNativeMessageChannel = "chrome.runtime.sendNativeMessage"; | 33 chromeHidden.kNativeMessageChannel = "chrome.runtime.sendNativeMessage"; |
32 | 34 |
33 // Map of port IDs to port object. | 35 // Map of port IDs to port object. |
34 var ports = {}; | 36 var ports = {}; |
35 | 37 |
36 // Map of port IDs to chromeHidden.onUnload listeners. Keep track of these | 38 // Map of port IDs to chromeHidden.onUnload listeners. Keep track of these |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
168 responseCallbackPreserved = | 170 responseCallbackPreserved = |
169 rv && rv.results && rv.results.indexOf(true) > -1; | 171 rv && rv.results && rv.results.indexOf(true) > -1; |
170 if (!responseCallbackPreserved && port) { | 172 if (!responseCallbackPreserved && port) { |
171 // If they didn't access the response callback, they're not | 173 // If they didn't access the response callback, they're not |
172 // going to send a response, so clean up the port immediately. | 174 // going to send a response, so clean up the port immediately. |
173 port.destroy_(); | 175 port.destroy_(); |
174 port = null; | 176 port = null; |
175 } | 177 } |
176 } | 178 } |
177 }); | 179 }); |
180 var eventName = (isSendMessage ? | |
Matt Perry
2013/04/09 20:56:59
you can use requestEvent_.eventName_
felt
2013/04/10 00:21:38
Done.
felt
2013/04/10 22:25:04
I reverted this change -- eventName_ is there, but
Matt Perry
2013/04/10 22:48:06
Doh, sorry about that.
| |
181 (isExternal ? | |
182 "runtime.onMessageExternal" : "runtime.onMessage") : | |
183 (isExternal ? | |
184 "extension.onRequestExternal" : "extension.onRequest")); | |
185 logActivity("EVENT", targetExtensionId, eventName, [sourceExtensionId]); | |
178 return true; | 186 return true; |
179 } | 187 } |
180 return false; | 188 return false; |
181 } | 189 } |
182 | 190 |
183 // Called by native code when a channel has been opened to this context. | 191 // Called by native code when a channel has been opened to this context. |
184 chromeHidden.Port.dispatchOnConnect = function(portId, channelName, tab, | 192 chromeHidden.Port.dispatchOnConnect = function(portId, channelName, tab, |
185 sourceExtensionId, | 193 sourceExtensionId, |
186 targetExtensionId) { | 194 targetExtensionId) { |
187 // Only create a new Port if someone is actually listening for a connection. | 195 // Only create a new Port if someone is actually listening for a connection. |
(...skipping 23 matching lines...) Expand all Loading... | |
211 | 219 |
212 var connectEvent = (isExternal ? | 220 var connectEvent = (isExternal ? |
213 chrome.runtime.onConnectExternal : chrome.runtime.onConnect); | 221 chrome.runtime.onConnectExternal : chrome.runtime.onConnect); |
214 if (connectEvent.hasListeners()) { | 222 if (connectEvent.hasListeners()) { |
215 var port = chromeHidden.Port.createPort(portId, channelName); | 223 var port = chromeHidden.Port.createPort(portId, channelName); |
216 port.sender = sender; | 224 port.sender = sender; |
217 if (manifestVersion < 2) | 225 if (manifestVersion < 2) |
218 port.tab = port.sender.tab; | 226 port.tab = port.sender.tab; |
219 | 227 |
220 connectEvent.dispatch(port); | 228 connectEvent.dispatch(port); |
229 var eventName = (isExternal ? | |
230 "runtime.onConnectExternal" : "runtime.onConnect"); | |
Matt Perry
2013/04/09 20:56:59
same here, with connectEvent
felt
2013/04/10 00:21:38
Done.
| |
231 logActivity("EVENT", targetExtensionId, eventName, [sourceExtensionId]); | |
221 return true; | 232 return true; |
222 } | 233 } |
223 return false; | 234 return false; |
224 }; | 235 }; |
225 | 236 |
226 // Called by native code when a channel has been closed. | 237 // Called by native code when a channel has been closed. |
227 chromeHidden.Port.dispatchOnDisconnect = function( | 238 chromeHidden.Port.dispatchOnDisconnect = function( |
228 portId, errorMessage) { | 239 portId, errorMessage) { |
229 var port = ports[portId]; | 240 var port = ports[portId]; |
230 if (port) { | 241 if (port) { |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
312 var targetId = null; | 323 var targetId = null; |
313 if (lastArg >= 0) | 324 if (lastArg >= 0) |
314 targetId = args[lastArg--]; | 325 targetId = args[lastArg--]; |
315 | 326 |
316 if (lastArg != -1) | 327 if (lastArg != -1) |
317 throw new Error('Invalid arguments to ' + functionName + '.'); | 328 throw new Error('Invalid arguments to ' + functionName + '.'); |
318 return [targetId, request, responseCallback]; | 329 return [targetId, request, responseCallback]; |
319 } | 330 } |
320 | 331 |
321 exports.sendMessageUpdateArguments = sendMessageUpdateArguments; | 332 exports.sendMessageUpdateArguments = sendMessageUpdateArguments; |
OLD | NEW |