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

Side by Side Diff: chrome/renderer/resources/extensions/miscellaneous_bindings.js

Issue 13726026: Added ActivityLog tests and associated bugfixes/extra logging. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Wrapped line Created 7 years, 8 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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');
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 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 responseCallbackPreserved = 168 responseCallbackPreserved =
167 rv && rv.results && rv.results.indexOf(true) > -1; 169 rv && rv.results && rv.results.indexOf(true) > -1;
168 if (!responseCallbackPreserved && port) { 170 if (!responseCallbackPreserved && port) {
169 // If they didn't access the response callback, they're not 171 // If they didn't access the response callback, they're not
170 // going to send a response, so clean up the port immediately. 172 // going to send a response, so clean up the port immediately.
171 port.destroy_(); 173 port.destroy_();
172 port = null; 174 port = null;
173 } 175 }
174 } 176 }
175 }); 177 });
178 var eventName = (isSendMessage ?
179 (isExternal ?
180 "runtime.onMessageExternal" : "runtime.onMessage") :
181 (isExternal ?
182 "extension.onRequestExternal" : "extension.onRequest"));
183 logActivity.LogEvent(targetExtensionId,
184 eventName,
185 [sourceExtensionId]);
176 return true; 186 return true;
177 } 187 }
178 return false; 188 return false;
179 } 189 }
180 190
181 // 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.
182 chromeHidden.Port.dispatchOnConnect = function(portId, channelName, tab, 192 chromeHidden.Port.dispatchOnConnect = function(portId, channelName, tab,
183 sourceExtensionId, 193 sourceExtensionId,
184 targetExtensionId) { 194 targetExtensionId) {
185 // 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 22 matching lines...) Expand all
208 } 218 }
209 219
210 var connectEvent = (isExternal ? 220 var connectEvent = (isExternal ?
211 chrome.runtime.onConnectExternal : chrome.runtime.onConnect); 221 chrome.runtime.onConnectExternal : chrome.runtime.onConnect);
212 if (connectEvent.hasListeners()) { 222 if (connectEvent.hasListeners()) {
213 var port = chromeHidden.Port.createPort(portId, channelName); 223 var port = chromeHidden.Port.createPort(portId, channelName);
214 port.sender = sender; 224 port.sender = sender;
215 if (manifestVersion < 2) 225 if (manifestVersion < 2)
216 port.tab = port.sender.tab; 226 port.tab = port.sender.tab;
217 227
228 var eventName = (isExternal ?
229 "runtime.onConnectExternal" : "runtime.onConnect");
218 connectEvent.dispatch(port); 230 connectEvent.dispatch(port);
231 logActivity.LogEvent(targetExtensionId,
232 eventName,
233 [sourceExtensionId]);
219 return true; 234 return true;
220 } 235 }
221 return false; 236 return false;
222 }; 237 };
223 238
224 // Called by native code when a channel has been closed. 239 // Called by native code when a channel has been closed.
225 chromeHidden.Port.dispatchOnDisconnect = function( 240 chromeHidden.Port.dispatchOnDisconnect = function(
226 portId, errorMessage) { 241 portId, errorMessage) {
227 var port = ports[portId]; 242 var port = ports[portId];
228 if (port) { 243 if (port) {
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 var targetId = null; 323 var targetId = null;
309 if (lastArg >= 0) 324 if (lastArg >= 0)
310 targetId = args[lastArg--]; 325 targetId = args[lastArg--];
311 326
312 if (lastArg != -1) 327 if (lastArg != -1)
313 throw new Error('Invalid arguments to ' + functionName + '.'); 328 throw new Error('Invalid arguments to ' + functionName + '.');
314 return [targetId, request, responseCallback]; 329 return [targetId, request, responseCallback];
315 } 330 }
316 331
317 exports.sendMessageUpdateArguments = sendMessageUpdateArguments; 332 exports.sendMessageUpdateArguments = sendMessageUpdateArguments;
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698