| 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 /** | 5 /** |
| 6 * @fileoverview | 6 * @fileoverview |
| 7 * A module that contains basic utility components and methods for the | 7 * A module that contains basic utility components and methods for the |
| 8 * chromoting project | 8 * chromoting project |
| 9 * | 9 * |
| 10 */ | 10 */ |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 base.Disposable = function() {}; | 61 base.Disposable = function() {}; |
| 62 base.Disposable.prototype.dispose = function() {}; | 62 base.Disposable.prototype.dispose = function() {}; |
| 63 | 63 |
| 64 /** | 64 /** |
| 65 * @constructor | 65 * @constructor |
| 66 * @param {...base.Disposable} var_args | 66 * @param {...base.Disposable} var_args |
| 67 * @implements {base.Disposable} | 67 * @implements {base.Disposable} |
| 68 */ | 68 */ |
| 69 base.Disposables = function(var_args) { | 69 base.Disposables = function(var_args) { |
| 70 /** | 70 /** |
| 71 * @type {Array.<base.Disposable>} | 71 * @type {Array<base.Disposable>} |
| 72 * @private | 72 * @private |
| 73 */ | 73 */ |
| 74 this.disposables_ = Array.prototype.slice.call(arguments, 0); | 74 this.disposables_ = Array.prototype.slice.call(arguments, 0); |
| 75 }; | 75 }; |
| 76 | 76 |
| 77 base.Disposables.prototype.dispose = function() { | 77 base.Disposables.prototype.dispose = function() { |
| 78 for (var i = 0; i < this.disposables_.length; i++) { | 78 for (var i = 0; i < this.disposables_.length; i++) { |
| 79 this.disposables_[i].dispose(); | 79 this.disposables_[i].dispose(); |
| 80 } | 80 } |
| 81 this.disposables_ = null; | 81 this.disposables_ = null; |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 base.isAppsV2_ = | 158 base.isAppsV2_ = |
| 159 Boolean(manifest && manifest.app && manifest.app.background); | 159 Boolean(manifest && manifest.app && manifest.app.background); |
| 160 } | 160 } |
| 161 return base.isAppsV2_; | 161 return base.isAppsV2_; |
| 162 }; | 162 }; |
| 163 | 163 |
| 164 /** | 164 /** |
| 165 * Joins the |url| with optional query parameters defined in |opt_params| | 165 * Joins the |url| with optional query parameters defined in |opt_params| |
| 166 * See unit test for usage. | 166 * See unit test for usage. |
| 167 * @param {string} url | 167 * @param {string} url |
| 168 * @param {Object.<string>=} opt_params | 168 * @param {Object<string>=} opt_params |
| 169 * @return {string} | 169 * @return {string} |
| 170 */ | 170 */ |
| 171 base.urlJoin = function(url, opt_params) { | 171 base.urlJoin = function(url, opt_params) { |
| 172 if (!opt_params) { | 172 if (!opt_params) { |
| 173 return url; | 173 return url; |
| 174 } | 174 } |
| 175 var queryParameters = []; | 175 var queryParameters = []; |
| 176 for (var key in opt_params) { | 176 for (var key in opt_params) { |
| 177 queryParameters.push(encodeURIComponent(key) + "=" + | 177 queryParameters.push(encodeURIComponent(key) + "=" + |
| 178 encodeURIComponent(opt_params[key])); | 178 encodeURIComponent(opt_params[key])); |
| 179 } | 179 } |
| 180 return url + '?' + queryParameters.join('&'); | 180 return url + '?' + queryParameters.join('&'); |
| 181 }; | 181 }; |
| 182 | 182 |
| 183 | 183 |
| 184 /** | 184 /** |
| 185 * @return {Object.<string, string>} The URL parameters. | 185 * @return {Object<string, string>} The URL parameters. |
| 186 */ | 186 */ |
| 187 base.getUrlParameters = function() { | 187 base.getUrlParameters = function() { |
| 188 var result = {}; | 188 var result = {}; |
| 189 var parts = window.location.search.substring(1).split('&'); | 189 var parts = window.location.search.substring(1).split('&'); |
| 190 for (var i = 0; i < parts.length; i++) { | 190 for (var i = 0; i < parts.length; i++) { |
| 191 var pair = parts[i].split('='); | 191 var pair = parts[i].split('='); |
| 192 result[pair[0]] = decodeURIComponent(pair[1]); | 192 result[pair[0]] = decodeURIComponent(pair[1]); |
| 193 } | 193 } |
| 194 return result; | 194 return result; |
| 195 }; | 195 }; |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 357 * var smokeDetector = new SmokeDetector(); | 357 * var smokeDetector = new SmokeDetector(); |
| 358 * smokeDetector.addEventListener('alarm', listenerObj.someCallback) | 358 * smokeDetector.addEventListener('alarm', listenerObj.someCallback) |
| 359 * | 359 * |
| 360 */ | 360 */ |
| 361 | 361 |
| 362 /** | 362 /** |
| 363 * Helper interface for the EventSource. | 363 * Helper interface for the EventSource. |
| 364 * @constructor | 364 * @constructor |
| 365 */ | 365 */ |
| 366 base.EventEntry = function() { | 366 base.EventEntry = function() { |
| 367 /** @type {Array.<function():void>} */ | 367 /** @type {Array<function():void>} */ |
| 368 this.listeners = []; | 368 this.listeners = []; |
| 369 }; | 369 }; |
| 370 | 370 |
| 371 | 371 |
| 372 /** @interface */ | 372 /** @interface */ |
| 373 base.EventSource = function() {}; | 373 base.EventSource = function() {}; |
| 374 | 374 |
| 375 /** | 375 /** |
| 376 * Add a listener |fn| to listen to |type| event. | 376 * Add a listener |fn| to listen to |type| event. |
| 377 * @param {string} type | 377 * @param {string} type |
| 378 * @param {function(?=):void} fn | 378 * @param {function(?=):void} fn |
| 379 */ | 379 */ |
| 380 base.EventSource.prototype.addEventListener = function(type, fn) {}; | 380 base.EventSource.prototype.addEventListener = function(type, fn) {}; |
| 381 | 381 |
| 382 /** | 382 /** |
| 383 * Remove a listener |fn| to listen to |type| event. | 383 * Remove a listener |fn| to listen to |type| event. |
| 384 * @param {string} type | 384 * @param {string} type |
| 385 * @param {function(?=):void} fn | 385 * @param {function(?=):void} fn |
| 386 */ | 386 */ |
| 387 base.EventSource.prototype.removeEventListener = function(type, fn) {}; | 387 base.EventSource.prototype.removeEventListener = function(type, fn) {}; |
| 388 | 388 |
| 389 | 389 |
| 390 /** | 390 /** |
| 391 * @constructor | 391 * @constructor |
| 392 * Since this class is implemented as a mixin, the constructor may not be | 392 * Since this class is implemented as a mixin, the constructor may not be |
| 393 * called. All initializations should be done in defineEvents. | 393 * called. All initializations should be done in defineEvents. |
| 394 * @implements {base.EventSource} | 394 * @implements {base.EventSource} |
| 395 */ | 395 */ |
| 396 base.EventSourceImpl = function() { | 396 base.EventSourceImpl = function() { |
| 397 /** @type {Object.<string, base.EventEntry>} */ | 397 /** @type {Object<string, base.EventEntry>} */ |
| 398 this.eventMap_; | 398 this.eventMap_; |
| 399 }; | 399 }; |
| 400 | 400 |
| 401 /** | 401 /** |
| 402 * @param {base.EventSourceImpl} obj | 402 * @param {base.EventSourceImpl} obj |
| 403 * @param {string} type | 403 * @param {string} type |
| 404 */ | 404 */ |
| 405 base.EventSourceImpl.isDefined = function(obj, type) { | 405 base.EventSourceImpl.isDefined = function(obj, type) { |
| 406 base.debug.assert(Boolean(obj.eventMap_), | 406 base.debug.assert(Boolean(obj.eventMap_), |
| 407 "The object doesn't support events"); | 407 "The object doesn't support events"); |
| 408 base.debug.assert(Boolean(obj.eventMap_[type]), 'Event <' + type + | 408 base.debug.assert(Boolean(obj.eventMap_[type]), 'Event <' + type + |
| 409 '> is undefined for the current object'); | 409 '> is undefined for the current object'); |
| 410 }; | 410 }; |
| 411 | 411 |
| 412 base.EventSourceImpl.prototype = { | 412 base.EventSourceImpl.prototype = { |
| 413 /** | 413 /** |
| 414 * Define |events| for this event source. | 414 * Define |events| for this event source. |
| 415 * @param {Array.<string>} events | 415 * @param {Array<string>} events |
| 416 */ | 416 */ |
| 417 defineEvents: function(events) { | 417 defineEvents: function(events) { |
| 418 base.debug.assert(!Boolean(this.eventMap_), | 418 base.debug.assert(!Boolean(this.eventMap_), |
| 419 'defineEvents can only be called once.'); | 419 'defineEvents can only be called once.'); |
| 420 this.eventMap_ = {}; | 420 this.eventMap_ = {}; |
| 421 events.forEach( | 421 events.forEach( |
| 422 /** | 422 /** |
| 423 * @this {base.EventSourceImpl} | 423 * @this {base.EventSourceImpl} |
| 424 * @param {string} type | 424 * @param {string} type |
| 425 */ | 425 */ |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 621 */ | 621 */ |
| 622 base.resizeWindowToContent = function() { | 622 base.resizeWindowToContent = function() { |
| 623 var appWindow = chrome.app.window.current(); | 623 var appWindow = chrome.app.window.current(); |
| 624 var outerBounds = appWindow.outerBounds; | 624 var outerBounds = appWindow.outerBounds; |
| 625 var borderY = outerBounds.height - appWindow.innerBounds.height; | 625 var borderY = outerBounds.height - appWindow.innerBounds.height; |
| 626 appWindow.resizeTo(outerBounds.width, document.body.clientHeight + borderY); | 626 appWindow.resizeTo(outerBounds.width, document.body.clientHeight + borderY); |
| 627 // Sometimes, resizing the window causes its position to be reset to (0, 0), | 627 // Sometimes, resizing the window causes its position to be reset to (0, 0), |
| 628 // so restore it explicitly. | 628 // so restore it explicitly. |
| 629 appWindow.moveTo(outerBounds.left, outerBounds.top); | 629 appWindow.moveTo(outerBounds.left, outerBounds.top); |
| 630 }; | 630 }; |
| OLD | NEW |