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 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
378 | 378 |
379 listeners.forEach( | 379 listeners.forEach( |
380 /** @param {function(*=):void} listener */ | 380 /** @param {function(*=):void} listener */ |
381 function(listener){ | 381 function(listener){ |
382 if (listener) { | 382 if (listener) { |
383 listener(opt_details); | 383 listener(opt_details); |
384 } | 384 } |
385 }); | 385 }); |
386 } | 386 } |
387 }; | 387 }; |
| 388 |
| 389 /** |
| 390 * Converts UTF-8 string to ArrayBuffer. |
| 391 * |
| 392 * @param {string} string |
| 393 * @return {ArrayBuffer} |
| 394 */ |
| 395 base.encodeUtf8 = function(string) { |
| 396 var utf8String = unescape(encodeURIComponent(string)); |
| 397 var result = new Uint8Array(utf8String.length); |
| 398 for (var i = 0; i < utf8String.length; i++) |
| 399 result[i] = utf8String.charCodeAt(i); |
| 400 return result.buffer; |
| 401 } |
| 402 |
| 403 /** |
| 404 * Decodes UTF-8 string from ArrayBuffer. |
| 405 * |
| 406 * @param {ArrayBuffer} buffer |
| 407 * @return {string} |
| 408 */ |
| 409 base.decodeUtf8 = function(buffer) { |
| 410 return decodeURIComponent( |
| 411 escape(String.fromCharCode.apply(null, new Uint8Array(buffer)))); |
| 412 } |
OLD | NEW |