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 /** | 5 /** |
6 * The global object. | 6 * The global object. |
7 * @type {!Object} | 7 * @type {!Object} |
8 * @const | 8 * @const |
9 */ | 9 */ |
10 var global = this; | 10 var global = this; |
11 | 11 |
| 12 /** @typedef {{eventName: string, uid: number}} */ |
| 13 var WebUIListener; |
| 14 |
12 /** Platform, package, object property, and Event support. **/ | 15 /** Platform, package, object property, and Event support. **/ |
13 var cr = function() { | 16 var cr = function() { |
14 'use strict'; | 17 'use strict'; |
15 | 18 |
16 /** | 19 /** |
17 * Builds an object structure for the provided namespace path, | 20 * Builds an object structure for the provided namespace path, |
18 * ensuring that names that already exist are not overwritten. For | 21 * ensuring that names that already exist are not overwritten. For |
19 * example: | 22 * example: |
20 * "a.b.c" -> a = {};a.b={};a.b.c={}; | 23 * "a.b.c" -> a = {};a.b={};a.b.c={}; |
21 * @param {string} name Name of the object that this file defines. | 24 * @param {string} name Name of the object that this file defines. |
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
381 return; | 384 return; |
382 } | 385 } |
383 | 386 |
384 var args = Array.prototype.slice.call(arguments, 1); | 387 var args = Array.prototype.slice.call(arguments, 1); |
385 for (var listenerId in eventListenersMap) { | 388 for (var listenerId in eventListenersMap) { |
386 eventListenersMap[listenerId].apply(null, args); | 389 eventListenersMap[listenerId].apply(null, args); |
387 } | 390 } |
388 } | 391 } |
389 | 392 |
390 /** | 393 /** |
391 * @typedef {{ | |
392 * eventName: string, | |
393 * uid: number, | |
394 * }} | |
395 */ | |
396 var WebUIListener; | |
397 | |
398 /** | |
399 * Registers a listener for an event fired from WebUI handlers. Any number of | 394 * Registers a listener for an event fired from WebUI handlers. Any number of |
400 * listeners may register for a single event. | 395 * listeners may register for a single event. |
401 * @param {string} eventName The event to listen to. | 396 * @param {string} eventName The event to listen to. |
402 * @param {!Function} callback The callback run when the event is fired. | 397 * @param {!Function} callback The callback run when the event is fired. |
403 * @return {!WebUIListener} An object to be used for removing a listener via | 398 * @return {!WebUIListener} An object to be used for removing a listener via |
404 * cr.removeWebUIListener. Should be treated as read-only. | 399 * cr.removeWebUIListener. Should be treated as read-only. |
405 */ | 400 */ |
406 function addWebUIListener(eventName, callback) { | 401 function addWebUIListener(eventName, callback) { |
407 webUIListenerMap[eventName] = webUIListenerMap[eventName] || {}; | 402 webUIListenerMap[eventName] = webUIListenerMap[eventName] || {}; |
408 var uid = createUid(); | 403 var uid = createUid(); |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
469 get isLinux() { | 464 get isLinux() { |
470 return /Linux/.test(navigator.userAgent); | 465 return /Linux/.test(navigator.userAgent); |
471 }, | 466 }, |
472 | 467 |
473 /** Whether this is on Android. */ | 468 /** Whether this is on Android. */ |
474 get isAndroid() { | 469 get isAndroid() { |
475 return /Android/.test(navigator.userAgent); | 470 return /Android/.test(navigator.userAgent); |
476 } | 471 } |
477 }; | 472 }; |
478 }(); | 473 }(); |
OLD | NEW |