Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 "use strict"; | |
| 6 | |
| 7 var authToken = ''; | |
| 8 var driveFilesUrl = 'https://www.googleapis.com/drive/v2/files'; | |
| 9 var driveFilesUploadUrl = 'https://www.googleapis.com/upload/drive/v2/files'; | |
| 10 var multipartBoundary = 'END_OF_PART'; | |
| 11 | |
| 12 function $(id) { | |
| 13 return document.getElementById(id); | |
| 14 } | |
| 15 | |
| 16 function getAuthToken(interactive) { | |
| 17 chrome.experimental.identity.getAuthToken( | |
| 18 {'interactive': interactive}, onGetAuthToken); | |
| 19 } | |
| 20 | |
| 21 function onGetAuthToken(authToken) { | |
| 22 var signInEl = $('signIn'); | |
| 23 var getFileEl = $('getFile'); | |
| 24 if (authToken) { | |
| 25 signInEl.style.display = 'none'; | |
| 26 getFileEl.style.display = 'block'; | |
| 27 window.authToken = authToken; | |
| 28 | |
| 29 // Send the auth token to the NaCl module. | |
| 30 common.naclModule.postMessage('token:'+authToken); | |
| 31 } else { | |
| 32 signInEl.style.display = 'block'; | |
| 33 getFileEl.style.display = 'none'; | |
| 34 } | |
| 35 }; | |
| 36 | |
| 37 // Called by the common.js module. | |
| 38 function moduleDidLoad() { | |
| 39 // The module is not hidden by default so we can easily see if the plugin | |
| 40 // failed to load. | |
| 41 common.hideModule(); | |
|
noelallen1
2013/04/30 18:46:08
We should probably make this the default behavior.
| |
| 42 | |
| 43 getAuthToken(false); | |
| 44 } | |
| 45 | |
| 46 function handleMessage(e) { | |
| 47 var msg = e.data; | |
| 48 $('contents').textContent = msg; | |
| 49 } | |
| 50 | |
| 51 // Called by the common.js module. | |
| 52 function attachListeners() { | |
| 53 $('signIn').addEventListener('click', function () { | |
| 54 getAuthToken(true); | |
| 55 }); | |
| 56 | |
| 57 $('getFile').addEventListener('click', function () { | |
| 58 $('contents').textContent = ''; | |
| 59 common.naclModule.postMessage('getFile'); | |
| 60 }); | |
| 61 } | |
| OLD | NEW |