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 'use strict'; | 5 'use strict'; |
6 | 6 |
7 /** @suppress {duplicate} */ | 7 /** @suppress {duplicate} */ |
8 var remoting = remoting || {}; | 8 var remoting = remoting || {}; |
9 | 9 |
10 /** @type {remoting.HostSession} */ remoting.hostSession = null; | 10 /** @type {remoting.HostSession} */ remoting.hostSession = null; |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 * Log information about the current extension. | 120 * Log information about the current extension. |
121 * The extension manifest is loaded and parsed to extract this info. | 121 * The extension manifest is loaded and parsed to extract this info. |
122 */ | 122 */ |
123 remoting.logExtensionInfoAsync_ = function() { | 123 remoting.logExtensionInfoAsync_ = function() { |
124 /** @type {XMLHttpRequest} */ | 124 /** @type {XMLHttpRequest} */ |
125 var xhr = new XMLHttpRequest(); | 125 var xhr = new XMLHttpRequest(); |
126 xhr.open('GET', 'manifest.json'); | 126 xhr.open('GET', 'manifest.json'); |
127 xhr.onload = function(e) { | 127 xhr.onload = function(e) { |
128 var manifest = | 128 var manifest = |
129 /** @type {{name: string, version: string, default_locale: string}} */ | 129 /** @type {{name: string, version: string, default_locale: string}} */ |
130 JSON.parse(xhr.responseText); | 130 jsonParseSafe(xhr.responseText); |
131 var name = chrome.i18n.getMessage('PRODUCT_NAME'); | 131 if (manifest) { |
132 console.log(name + ' version: ' + manifest.version); | 132 var name = chrome.i18n.getMessage('PRODUCT_NAME'); |
| 133 console.log(name + ' version: ' + manifest.version); |
| 134 } else { |
| 135 console.error('Failed to get product version. Corrupt manifest?'); |
| 136 } |
133 } | 137 } |
134 xhr.send(null); | 138 xhr.send(null); |
135 }; | 139 }; |
136 | 140 |
137 /** | 141 /** |
138 * If the client is connected, or the host is shared, prompt before closing. | 142 * If the client is connected, or the host is shared, prompt before closing. |
139 * | 143 * |
140 * @return {?string} The prompt string if a connection is active. | 144 * @return {?string} The prompt string if a connection is active. |
141 */ | 145 */ |
142 remoting.promptClose = function() { | 146 remoting.promptClose = function() { |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
269 */ | 273 */ |
270 function getUrlParameters_() { | 274 function getUrlParameters_() { |
271 var result = {}; | 275 var result = {}; |
272 var parts = window.location.search.substring(1).split('&'); | 276 var parts = window.location.search.substring(1).split('&'); |
273 for (var i = 0; i < parts.length; i++) { | 277 for (var i = 0; i < parts.length; i++) { |
274 var pair = parts[i].split('='); | 278 var pair = parts[i].split('='); |
275 result[pair[0]] = decodeURIComponent(pair[1]); | 279 result[pair[0]] = decodeURIComponent(pair[1]); |
276 } | 280 } |
277 return result; | 281 return result; |
278 } | 282 } |
| 283 |
| 284 /** |
| 285 * @param {string} jsonString A JSON-encoded string. |
| 286 * @return {*} The decoded object, or undefined if the string cannot be parsed. |
| 287 */ |
| 288 function jsonParseSafe(jsonString) { |
| 289 try { |
| 290 return JSON.parse(jsonString); |
| 291 } catch (err) { |
| 292 return undefined; |
| 293 } |
| 294 } |
OLD | NEW |