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

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

Issue 2156503002: [NaCl SDK] Expose Google Drive to nacl_io. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 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/nacl_io_demo/example.js
diff --git a/native_client_sdk/src/examples/demo/nacl_io_demo/example.js b/native_client_sdk/src/examples/demo/nacl_io_demo/example.js
index 7cb83c15b65a1563f16b4c0f8f2b5cca811224ed..c3165b2dee1e69b0062f56b3d263381118f08185 100644
--- a/native_client_sdk/src/examples/demo/nacl_io_demo/example.js
+++ b/native_client_sdk/src/examples/demo/nacl_io_demo/example.js
@@ -1,7 +1,64 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright (c) 2016 The Chromium Authors. All rights reserved.
binji 2016/08/22 19:21:52 It's not necessary to change the copyright year.
chanpatorikku 2016/08/29 17:14:02 Done.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+var CLIENT_ID = "TO FILL";
binji 2016/08/22 19:21:52 Where is this filled in? If it is meant to be fill
chanpatorikku 2016/08/29 17:14:02 This is filled in in example.js. The Drive exampl
+var CLIENT_SECRET = "TO FILL";
+
+var REDIRECT_URI = "http://localhost:5103/index.html";
+
+var currentURL = window.location.href;
+var tokenValue = "Set at domContentLoaded()";
+
+function buttonOnClick() {
+ var array = new Uint32Array(3);
+ window.crypto.getRandomValues(array);
+ var stateValue = array[0].toString() +
+ array[1].toString() +
+ array[2].toString();
+
+ var url = "http://accounts.google.com/o/oauth2/v2/auth?" +
+ "scope=https://www.googleapis.com/auth/drive"
+ + "+" + "https://www.googleapis.com/auth/drive.metadata" + "&" +
+ "state=" + stateValue + "&" +
+ "redirect_uri=http://localhost:5103/index.html" + "&" +
+ "response_type=code" + "&" +
+ "client_id=" + CLIENT_ID;
+
+ window.open(url, "_self");
+}
+
+function executeAfterGettingCode() {
+ var codeKeyIndex = currentURL.search("code=");
binji 2016/08/22 19:21:52 you can just use indexOf instead of search. search
chanpatorikku 2016/08/29 17:14:02 Done.
+ if (-1 == codeKeyIndex) {
+ return -1;
+ }
+ var codeValue = currentURL.substring(codeKeyIndex + 5);
+
+ var xHTTP = new XMLHttpRequest();
+ xHTTP.onreadystatechange = function() {
+ if (xHTTP.readyState == 4 && xHTTP.status == 200) {
+ var obj = JSON.parse(xHTTP.responseText);
+ var url = REDIRECT_URI + "?token=" + obj.access_token;
+
+ window.open(url, "_self");
+ }
+ };
+
+ xHTTP.timeout = 4000; // Set timeout to 4 seconds (4000 milliseconds)
+ xHTTP.ontimeout = function () { alert("Timed out"); }
+
+ var params = "code=" + codeValue + "&" +
+ "client_id=" + CLIENT_ID + "&" +
+ "client_secret=" + CLIENT_SECRET + "&" +
+ "redirect_uri=" + REDIRECT_URI + "&" +
+ "grant_type=authorization_code";
+
+ xHTTP.open("POST", "https://www.googleapis.com/oauth2/v4/token", true);
+ xHTTP.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
+ xHTTP.send(params);
+}
+
function moduleDidLoad() {
common.hideModule();
}
@@ -17,7 +74,18 @@ function domContentLoaded(name, tc, config, width, height) {
common.updateStatus(
'Allocated ' + bytes + ' bytes of persistant storage.');
common.attachDefaultListeners();
- common.createNaClModule(name, tc, config, width, height);
+
+ var tokenKeyIndex = currentURL.search("token=");
+ if (-1 == tokenKeyIndex) {
+ common.createNaClModule(name, tc, config, width, height);
+ } else {
+ tokenValue = currentURL.substring(tokenKeyIndex + 6);
+ var tokenMap = { 'token' : tokenValue };
+
+ common.createNaClModule(name, tc, config, width, height, tokenMap);
+
+ document.getElementById("buttonid").disabled = true;
+ }
},
function(e) { alert('Failed to allocate space') });
}
@@ -343,7 +411,7 @@ function handleMessage(message_event) {
callback.apply(null, params);
}
} else {
- common.logMessage('Error: Unknow message `' + data +
+ common.logMessage('Error: Unknown message `' + data +
'` received from NaCl module.');
}
}

Powered by Google App Engine
This is Rietveld 408576698