OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 var authToken = ''; | 7 var authToken = ''; |
8 | 8 |
9 function getAuthToken(interactive) { | 9 function getAuthToken(interactive) { |
10 chrome.identity.getAuthToken( | 10 chrome.identity.getAuthToken( |
11 {'interactive': interactive}, onGetAuthToken); | 11 {'interactive': interactive}, onGetAuthToken); |
12 } | 12 } |
13 | 13 |
14 function onGetAuthToken(authToken) { | 14 function onGetAuthToken(authToken) { |
15 var signInEl = document.getElementById('signIn'); | 15 var signInEl = document.getElementById('signIn'); |
16 var getFileEl = document.getElementById('getFile'); | 16 var getFileEl = document.getElementById('getFile'); |
17 if (authToken) { | 17 if (authToken) { |
18 signInEl.setAttribute('hidden'); | 18 signInEl.setAttribute('hidden', ''); |
19 getFileEl.removeAttribute('hidden'); | 19 getFileEl.removeAttribute('hidden'); |
20 window.authToken = authToken; | 20 window.authToken = authToken; |
21 | 21 |
22 // Send the auth token to the NaCl module. | 22 // Send the auth token to the NaCl module. |
23 common.naclModule.postMessage('token:'+authToken); | 23 common.naclModule.postMessage('token:'+authToken); |
24 } else { | 24 } else { |
25 // There is no auth token; this means that the user has yet to authorize | 25 // There is no auth token; this means that the user has yet to authorize |
26 // this app. Display a button to let the user sign in and authorize this | 26 // this app. Display a button to let the user sign in and authorize this |
27 // application. | 27 // application. |
28 signInEl.removeAttribute('hidden'); | 28 signInEl.removeAttribute('hidden'); |
29 getFileEl.setAttribute('hidden'); | 29 getFileEl.setAttribute('hidden', ''); |
30 } | 30 } |
31 }; | 31 }; |
32 | 32 |
33 // Called by the common.js module. | 33 // Called by the common.js module. |
34 function moduleDidLoad() { | 34 function moduleDidLoad() { |
35 // The module is not hidden by default so we can easily see if the plugin | 35 // The module is not hidden by default so we can easily see if the plugin |
36 // failed to load. | 36 // failed to load. |
37 common.hideModule(); | 37 common.hideModule(); |
38 | 38 |
39 // Make sure this example is running as a packaged app. If not, display a | 39 // Make sure this example is running as a packaged app. If not, display a |
(...skipping 21 matching lines...) Expand all Loading... |
61 getAuthToken(true); | 61 getAuthToken(true); |
62 }); | 62 }); |
63 | 63 |
64 document.getElementById('getFile').addEventListener('click', function () { | 64 document.getElementById('getFile').addEventListener('click', function () { |
65 // Clear the file contents dialog box. | 65 // Clear the file contents dialog box. |
66 document.getElementById('contents').textContent = ''; | 66 document.getElementById('contents').textContent = ''; |
67 | 67 |
68 common.naclModule.postMessage('getFile'); | 68 common.naclModule.postMessage('getFile'); |
69 }); | 69 }); |
70 } | 70 } |
OLD | NEW |