Index: native_client_sdk/src/examples/demo/drive/example.js |
diff --git a/native_client_sdk/src/examples/demo/drive/example.js b/native_client_sdk/src/examples/demo/drive/example.js |
new file mode 100644 |
index 0000000000000000000000000000000000000000..895a8b49c064078264a50681501bae40c7bfac90 |
--- /dev/null |
+++ b/native_client_sdk/src/examples/demo/drive/example.js |
@@ -0,0 +1,61 @@ |
+// Copyright (c) 2013 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+"use strict"; |
+ |
+var authToken = ''; |
+var driveFilesUrl = 'https://www.googleapis.com/drive/v2/files'; |
+var driveFilesUploadUrl = 'https://www.googleapis.com/upload/drive/v2/files'; |
+var multipartBoundary = 'END_OF_PART'; |
+ |
+function $(id) { |
+ return document.getElementById(id); |
+} |
+ |
+function getAuthToken(interactive) { |
+ chrome.experimental.identity.getAuthToken( |
+ {'interactive': interactive}, onGetAuthToken); |
+} |
+ |
+function onGetAuthToken(authToken) { |
+ var signInEl = $('signIn'); |
+ var getFileEl = $('getFile'); |
+ if (authToken) { |
+ signInEl.style.display = 'none'; |
+ getFileEl.style.display = 'block'; |
+ window.authToken = authToken; |
+ |
+ // Send the auth token to the NaCl module. |
+ common.naclModule.postMessage('token:'+authToken); |
+ } else { |
+ signInEl.style.display = 'block'; |
+ getFileEl.style.display = 'none'; |
+ } |
+}; |
+ |
+// Called by the common.js module. |
+function moduleDidLoad() { |
+ // The module is not hidden by default so we can easily see if the plugin |
+ // failed to load. |
+ common.hideModule(); |
noelallen1
2013/04/30 18:46:08
We should probably make this the default behavior.
|
+ |
+ getAuthToken(false); |
+} |
+ |
+function handleMessage(e) { |
+ var msg = e.data; |
+ $('contents').textContent = msg; |
+} |
+ |
+// Called by the common.js module. |
+function attachListeners() { |
+ $('signIn').addEventListener('click', function () { |
+ getAuthToken(true); |
+ }); |
+ |
+ $('getFile').addEventListener('click', function () { |
+ $('contents').textContent = ''; |
+ common.naclModule.postMessage('getFile'); |
+ }); |
+} |