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 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 return url; | 172 return url; |
173 } | 173 } |
174 var queryParameters = []; | 174 var queryParameters = []; |
175 for (var key in opt_params) { | 175 for (var key in opt_params) { |
176 queryParameters.push(encodeURIComponent(key) + "=" + | 176 queryParameters.push(encodeURIComponent(key) + "=" + |
177 encodeURIComponent(opt_params[key])); | 177 encodeURIComponent(opt_params[key])); |
178 } | 178 } |
179 return url + '?' + queryParameters.join('&'); | 179 return url + '?' + queryParameters.join('&'); |
180 }; | 180 }; |
181 | 181 |
| 182 |
| 183 /** |
| 184 * @return {Object.<string, string>} The URL parameters. |
| 185 */ |
| 186 base.getUrlParameters = function() { |
| 187 var result = {}; |
| 188 var parts = window.location.search.substring(1).split('&'); |
| 189 for (var i = 0; i < parts.length; i++) { |
| 190 var pair = parts[i].split('='); |
| 191 result[pair[0]] = decodeURIComponent(pair[1]); |
| 192 } |
| 193 return result; |
| 194 }; |
| 195 |
182 /** | 196 /** |
183 * Convert special characters (e.g. &, < and >) to HTML entities. | 197 * Convert special characters (e.g. &, < and >) to HTML entities. |
184 * | 198 * |
185 * @param {string} str | 199 * @param {string} str |
186 * @return {string} | 200 * @return {string} |
187 */ | 201 */ |
188 base.escapeHTML = function(str) { | 202 base.escapeHTML = function(str) { |
189 var div = document.createElement('div'); | 203 var div = document.createElement('div'); |
190 div.appendChild(document.createTextNode(str)); | 204 div.appendChild(document.createTextNode(str)); |
191 return div.innerHTML; | 205 return div.innerHTML; |
(...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
575 * @return {Object|undefined} The decoded object, or undefined if the string | 589 * @return {Object|undefined} The decoded object, or undefined if the string |
576 * cannot be parsed. | 590 * cannot be parsed. |
577 */ | 591 */ |
578 base.jsonParseSafe = function(jsonString) { | 592 base.jsonParseSafe = function(jsonString) { |
579 try { | 593 try { |
580 return /** @type {Object} */ (JSON.parse(jsonString)); | 594 return /** @type {Object} */ (JSON.parse(jsonString)); |
581 } catch (err) { | 595 } catch (err) { |
582 return undefined; | 596 return undefined; |
583 } | 597 } |
584 }; | 598 }; |
| 599 |
| 600 /** |
| 601 * Size the current window to fit its content vertically. |
| 602 */ |
| 603 base.resizeWindowToContent = function() { |
| 604 var appWindow = chrome.app.window.current(); |
| 605 var outerBounds = appWindow.outerBounds; |
| 606 var borderY = outerBounds.height - appWindow.innerBounds.height; |
| 607 appWindow.resizeTo(outerBounds.width, document.body.clientHeight + borderY); |
| 608 // Sometimes, resizing the window causes its position to be reset to (0, 0), |
| 609 // so restore it explicitly. |
| 610 appWindow.moveTo(outerBounds.left, outerBounds.top); |
| 611 }; |
OLD | NEW |