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 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
349 } else { | 349 } else { |
350 chrome.windows.get(tab.windowId, null, windowCallback); | 350 chrome.windows.get(tab.windowId, null, windowCallback); |
351 } | 351 } |
352 }; | 352 }; |
353 if (chrome.tabs) { | 353 if (chrome.tabs) { |
354 chrome.tabs.getCurrent(tabCallback); | 354 chrome.tabs.getCurrent(tabCallback); |
355 } else { | 355 } else { |
356 console.error('chome.tabs is not available.'); | 356 console.error('chome.tabs is not available.'); |
357 } | 357 } |
358 } | 358 } |
| 359 |
| 360 /** |
| 361 * Generate a nonce, to be used as an xsrf protection token. |
| 362 * |
| 363 * @return {string} A URL-Safe Base64-encoded 128-bit random value. */ |
| 364 remoting.generateXsrfToken = function() { |
| 365 var random = new Uint8Array(16); |
| 366 window.crypto.getRandomValues(random); |
| 367 var base64Token = window.btoa(String.fromCharCode.apply(null, random)); |
| 368 return base64Token.replace(/\+/g, '-').replace(/\//g, '_').replace(/=/g, ''); |
| 369 }; |
OLD | NEW |