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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // 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.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 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
6 var CLIENT_SECRET = "TO FILL";
7
8 var REDIRECT_URI = "http://localhost:5103/index.html";
9
10 var currentURL = window.location.href;
11 var tokenValue = "Set at domContentLoaded()";
12
13 function buttonOnClick() {
14 var array = new Uint32Array(3);
15 window.crypto.getRandomValues(array);
16 var stateValue = array[0].toString() +
17 array[1].toString() +
18 array[2].toString();
19
20 var url = "http://accounts.google.com/o/oauth2/v2/auth?" +
21 "scope=https://www.googleapis.com/auth/drive"
22 + "+" + "https://www.googleapis.com/auth/drive.metadata" + "&" +
23 "state=" + stateValue + "&" +
24 "redirect_uri=http://localhost:5103/index.html" + "&" +
25 "response_type=code" + "&" +
26 "client_id=" + CLIENT_ID;
27
28 window.open(url, "_self");
29 }
30
31 function executeAfterGettingCode() {
32 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.
33 if (-1 == codeKeyIndex) {
34 return -1;
35 }
36 var codeValue = currentURL.substring(codeKeyIndex + 5);
37
38 var xHTTP = new XMLHttpRequest();
39 xHTTP.onreadystatechange = function() {
40 if (xHTTP.readyState == 4 && xHTTP.status == 200) {
41 var obj = JSON.parse(xHTTP.responseText);
42 var url = REDIRECT_URI + "?token=" + obj.access_token;
43
44 window.open(url, "_self");
45 }
46 };
47
48 xHTTP.timeout = 4000; // Set timeout to 4 seconds (4000 milliseconds)
49 xHTTP.ontimeout = function () { alert("Timed out"); }
50
51 var params = "code=" + codeValue + "&" +
52 "client_id=" + CLIENT_ID + "&" +
53 "client_secret=" + CLIENT_SECRET + "&" +
54 "redirect_uri=" + REDIRECT_URI + "&" +
55 "grant_type=authorization_code";
56
57 xHTTP.open("POST", "https://www.googleapis.com/oauth2/v4/token", true);
58 xHTTP.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
59 xHTTP.send(params);
60 }
61
5 function moduleDidLoad() { 62 function moduleDidLoad() {
6 common.hideModule(); 63 common.hideModule();
7 } 64 }
8 65
9 function $(id) { 66 function $(id) {
10 return document.getElementById(id); 67 return document.getElementById(id);
11 } 68 }
12 69
13 // Called by the common.js module. 70 // Called by the common.js module.
14 function domContentLoaded(name, tc, config, width, height) { 71 function domContentLoaded(name, tc, config, width, height) {
15 navigator.webkitPersistentStorage.requestQuota(5 * 1024 * 1024, 72 navigator.webkitPersistentStorage.requestQuota(5 * 1024 * 1024,
16 function(bytes) { 73 function(bytes) {
17 common.updateStatus( 74 common.updateStatus(
18 'Allocated ' + bytes + ' bytes of persistant storage.'); 75 'Allocated ' + bytes + ' bytes of persistant storage.');
19 common.attachDefaultListeners(); 76 common.attachDefaultListeners();
20 common.createNaClModule(name, tc, config, width, height); 77
78 var tokenKeyIndex = currentURL.search("token=");
79 if (-1 == tokenKeyIndex) {
80 common.createNaClModule(name, tc, config, width, height);
81 } else {
82 tokenValue = currentURL.substring(tokenKeyIndex + 6);
83 var tokenMap = { 'token' : tokenValue };
84
85 common.createNaClModule(name, tc, config, width, height, tokenMap);
86
87 document.getElementById("buttonid").disabled = true;
88 }
21 }, 89 },
22 function(e) { alert('Failed to allocate space') }); 90 function(e) { alert('Failed to allocate space') });
23 } 91 }
24 92
25 // Called by the common.js module. 93 // Called by the common.js module.
26 function attachListeners() { 94 function attachListeners() {
27 var radioEls = document.querySelectorAll('input[type="radio"]'); 95 var radioEls = document.querySelectorAll('input[type="radio"]');
28 for (var i = 0; i < radioEls.length; ++i) { 96 for (var i = 0; i < radioEls.length; ++i) {
29 radioEls[i].addEventListener('click', onRadioClicked); 97 radioEls[i].addEventListener('click', onRadioClicked);
30 } 98 }
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 if (!callback) { 404 if (!callback) {
337 common.logMessage('Error: Bad message ' + funcName + 405 common.logMessage('Error: Bad message ' + funcName +
338 ' received from NaCl module.'); 406 ' received from NaCl module.');
339 return; 407 return;
340 } 408 }
341 409
342 delete funcToCallback[funcName]; 410 delete funcToCallback[funcName];
343 callback.apply(null, params); 411 callback.apply(null, params);
344 } 412 }
345 } else { 413 } else {
346 common.logMessage('Error: Unknow message `' + data + 414 common.logMessage('Error: Unknown message `' + data +
347 '` received from NaCl module.'); 415 '` received from NaCl module.');
348 } 416 }
349 } 417 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698