| 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; |
| (...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 287 * instance object. | 287 * instance object. |
| 288 * @param {!Function} ctor The constructor for the class to add the static | 288 * @param {!Function} ctor The constructor for the class to add the static |
| 289 * method to. | 289 * method to. |
| 290 */ | 290 */ |
| 291 function addSingletonGetter(ctor) { | 291 function addSingletonGetter(ctor) { |
| 292 ctor.getInstance = function() { | 292 ctor.getInstance = function() { |
| 293 return ctor.instance_ || (ctor.instance_ = new ctor()); | 293 return ctor.instance_ || (ctor.instance_ = new ctor()); |
| 294 }; | 294 }; |
| 295 } | 295 } |
| 296 | 296 |
| 297 /** |
| 298 * Forwards public APIs to private implementations. |
| 299 * @param {Function} ctor Constructor that have private implementations in its |
| 300 * prototype. |
| 301 * @param {Array.<string>} methods List of public method names that have their |
| 302 * underscored counterparts in constructor's prototype. |
| 303 * @param {string=} opt_target Selector for target node. |
| 304 */ |
| 305 function makePublic(ctor, methods, opt_target) { |
| 306 methods.forEach(function(method) { |
| 307 ctor[method] = function() { |
| 308 var target = opt_target ? document.getElementById(opt_target) : |
| 309 ctor.getInstance(); |
| 310 return target[method + '_'].apply(target, arguments); |
| 311 }; |
| 312 }); |
| 313 } |
| 314 |
| 297 return { | 315 return { |
| 298 addSingletonGetter: addSingletonGetter, | 316 addSingletonGetter: addSingletonGetter, |
| 299 createUid: createUid, | 317 createUid: createUid, |
| 300 define: define, | 318 define: define, |
| 301 defineProperty: defineProperty, | 319 defineProperty: defineProperty, |
| 302 dispatchPropertyChange: dispatchPropertyChange, | 320 dispatchPropertyChange: dispatchPropertyChange, |
| 303 dispatchSimpleEvent: dispatchSimpleEvent, | 321 dispatchSimpleEvent: dispatchSimpleEvent, |
| 304 exportPath: exportPath, | 322 exportPath: exportPath, |
| 305 getUid: getUid, | 323 getUid: getUid, |
| 324 makePublic: makePublic, |
| 306 PropertyKind: PropertyKind, | 325 PropertyKind: PropertyKind, |
| 307 | 326 |
| 308 get doc() { | 327 get doc() { |
| 309 return document; | 328 return document; |
| 310 }, | 329 }, |
| 311 | 330 |
| 312 /** Whether we are using a Mac or not. */ | 331 /** Whether we are using a Mac or not. */ |
| 313 get isMac() { | 332 get isMac() { |
| 314 return /Mac/.test(navigator.platform); | 333 return /Mac/.test(navigator.platform); |
| 315 }, | 334 }, |
| (...skipping 13 matching lines...) Expand all Loading... |
| 329 return /Linux/.test(navigator.userAgent); | 348 return /Linux/.test(navigator.userAgent); |
| 330 }, | 349 }, |
| 331 | 350 |
| 332 /** Whether this uses the views toolkit or not. */ | 351 /** Whether this uses the views toolkit or not. */ |
| 333 get isViews() { | 352 get isViews() { |
| 334 return typeof chrome.getVariableValue == 'function' && | 353 return typeof chrome.getVariableValue == 'function' && |
| 335 /views/.test(chrome.getVariableValue('toolkit')); | 354 /views/.test(chrome.getVariableValue('toolkit')); |
| 336 }, | 355 }, |
| 337 }; | 356 }; |
| 338 }(); | 357 }(); |
| OLD | NEW |