| 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 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 208 * (e.g. undefined, NaN). | 208 * (e.g. undefined, NaN). |
| 209 */ | 209 */ |
| 210 base.deepCopy = function(value) { | 210 base.deepCopy = function(value) { |
| 211 try { | 211 try { |
| 212 return JSON.parse(JSON.stringify(value)); | 212 return JSON.parse(JSON.stringify(value)); |
| 213 } catch (e) {} | 213 } catch (e) {} |
| 214 return null; | 214 return null; |
| 215 }; | 215 }; |
| 216 | 216 |
| 217 /** | 217 /** |
| 218 * Returns a copy of the input object with all null/undefined fields |
| 219 * removed. Returns an empty object for a null/undefined input. |
| 220 * |
| 221 * @param {Object<string,?T>|undefined} input |
| 222 * @return {!Object<string,T>} |
| 223 * @template T |
| 224 */ |
| 225 base.copyWithoutNullFields = function(input) { |
| 226 /** @const {!Object} */ |
| 227 var result = {}; |
| 228 if (input) { |
| 229 for (var field in input) { |
| 230 var value = /** @type {*} */ (input[field]); |
| 231 if (value != null) { |
| 232 result[field] = value; |
| 233 } |
| 234 } |
| 235 } |
| 236 return result; |
| 237 }; |
| 238 |
| 239 /** |
| 218 * @type {boolean|undefined} | 240 * @type {boolean|undefined} |
| 219 * @private | 241 * @private |
| 220 */ | 242 */ |
| 221 base.isAppsV2_ = undefined; | 243 base.isAppsV2_ = undefined; |
| 222 | 244 |
| 223 /** | 245 /** |
| 224 * @return {boolean} True if this is a v2 app; false if it is a legacy app. | 246 * @return {boolean} True if this is a v2 app; false if it is a legacy app. |
| 225 */ | 247 */ |
| 226 base.isAppsV2 = function() { | 248 base.isAppsV2 = function() { |
| 227 if (base.isAppsV2_ === undefined) { | 249 if (base.isAppsV2_ === undefined) { |
| (...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 705 */ | 727 */ |
| 706 base.resizeWindowToContent = function() { | 728 base.resizeWindowToContent = function() { |
| 707 var appWindow = chrome.app.window.current(); | 729 var appWindow = chrome.app.window.current(); |
| 708 var outerBounds = appWindow.outerBounds; | 730 var outerBounds = appWindow.outerBounds; |
| 709 var borderY = outerBounds.height - appWindow.innerBounds.height; | 731 var borderY = outerBounds.height - appWindow.innerBounds.height; |
| 710 appWindow.resizeTo(outerBounds.width, document.body.clientHeight + borderY); | 732 appWindow.resizeTo(outerBounds.width, document.body.clientHeight + borderY); |
| 711 // Sometimes, resizing the window causes its position to be reset to (0, 0), | 733 // Sometimes, resizing the window causes its position to be reset to (0, 0), |
| 712 // so restore it explicitly. | 734 // so restore it explicitly. |
| 713 appWindow.moveTo(outerBounds.left, outerBounds.top); | 735 appWindow.moveTo(outerBounds.left, outerBounds.top); |
| 714 }; | 736 }; |
| OLD | NEW |