Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1716)

Unified Diff: native_client_sdk/src/examples/demo/drive/example.js

Issue 14500010: [NaCl SDK] Google Drive example (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: synchronous on thread Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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');
+ });
+}

Powered by Google App Engine
This is Rietveld 408576698