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.
9 function getAuthToken(interactive) {
10 chrome.identity.getAuthToken(
11 {'interactive': interactive}, onGetAuthToken);
14 function onGetAuthToken(authToken) {
15 var signInEl = document.getElementById('signIn');
16 var getFileEl = document.getElementById('getFile');
18 signInEl.setAttribute('hidden', '');
19 getFileEl.removeAttribute('hidden');
20 window.authToken = authToken;
22 // Send the auth token to the NaCl module.
23 common.naclModule.postMessage('token:'+authToken);
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
28 signInEl.removeAttribute('hidden');
29 getFileEl.setAttribute('hidden', '');
33 // Called by the common.js module.
34 function moduleDidLoad() {
35 // The module is not hidden by default so we can easily see if the plugin
39 // Make sure this example is running as a packaged app. If not, display a
41 if (!chrome.identity) {
42 common.updateStatus('Error: must be run as a packged app.');
46 // Try to get the authorization token non-interactively. This will often work
47 // if the user has already authorized the app, and the token is cached.
51 function handleMessage(e) {
53 document.getElementById('contents').textContent = msg;
56 // Called by the common.js module.
57 function attachListeners() {
58 document.getElementById('signIn').addEventListener('click', function () {
59 // Get the authorization token interactively. A dialog box will pop up
60 // asking the user to authorize access to their Drive account.
64 document.getElementById('getFile').addEventListener('click', function () {
65 // Clear the file contents dialog box.
66 document.getElementById('contents').textContent = '';
68 common.naclModule.postMessage('getFile');