| 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 'use strict'; | 5 'use strict'; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * Function to convert an array of bytes to a base64 string | 8 * Function to convert an array of bytes to a base64 string |
| 9 * TODO(rkc): Change this to use a Uint8array instead of a string. | 9 * TODO(rkc): Change this to use a Uint8array instead of a string. |
| 10 * @param {string} bytes String containing the bytes we want to convert. | 10 * @param {string} bytes String containing the bytes we want to convert. |
| 11 * @return {string} String containing the base64 representation. | 11 * @return {string} String containing the base64 representation. |
| 12 */ | 12 */ |
| 13 function bytesToBase64(bytes) { | 13 function bytesToBase64(bytes) { |
| 14 var bstr = ''; | 14 var bstr = ''; |
| 15 for (var i = 0; i < bytes.length; ++i) | 15 for (var i = 0; i < bytes.length; ++i) |
| 16 bstr += String.fromCharCode(bytes[i]); | 16 bstr += String.fromCharCode(bytes[i]); |
| 17 return btoa(bstr).replace(/=/g, ''); | 17 return btoa(bstr).replace('=', ''); |
| 18 } | 18 } |
| 19 | 19 |
| 20 /** | 20 /** |
| 21 * Function to convert a string to an array of bytes. | 21 * Function to convert a string to an array of bytes. |
| 22 * @param {string} str String to convert. | 22 * @param {string} str String to convert. |
| 23 * @return {Array} Array containing the string. | 23 * @return {Array} Array containing the string. |
| 24 */ | 24 */ |
| 25 function stringToArray(str) { | 25 function stringToArray(str) { |
| 26 var buffer = []; | 26 var buffer = []; |
| 27 for (var i = 0; i < str.length; ++i) | 27 for (var i = 0; i < str.length; ++i) |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 if (!candidates || candidates.length == 0) | 160 if (!candidates || candidates.length == 0) |
| 161 return; | 161 return; |
| 162 | 162 |
| 163 var returnCandidates = []; | 163 var returnCandidates = []; |
| 164 for (var i = 0; i < candidates.length; ++i) { | 164 for (var i = 0; i < candidates.length; ++i) { |
| 165 returnCandidates[i] = { token: bytesToBase64(candidates[i]), | 165 returnCandidates[i] = { token: bytesToBase64(candidates[i]), |
| 166 audible: audible }; | 166 audible: audible }; |
| 167 } | 167 } |
| 168 chrome.copresencePrivate.sendFound(this.clientId_, returnCandidates); | 168 chrome.copresencePrivate.sendFound(this.clientId_, returnCandidates); |
| 169 }; | 169 }; |
| OLD | NEW |