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

Side by Side Diff: remoting/webapp/crd/js/wcs_loader.js

Issue 955283002: Converted remoting.Error from an enum to a class (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Requested changes. Created 5 years, 9 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) 2012 The Chromium Authors. All rights reserved.
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 5
6 /** 6 /**
7 * @fileoverview 7 * @fileoverview
8 * A class that loads a WCS IQ client and constructs remoting.wcs as a 8 * A class that loads a WCS IQ client and constructs remoting.wcs as a
9 * wrapper for it. 9 * wrapper for it.
10 */ 10 */
(...skipping 28 matching lines...) Expand all
39 /** 39 /**
40 * Starts loading the WCS IQ client. 40 * Starts loading the WCS IQ client.
41 * 41 *
42 * When it's loaded, construct remoting.wcs as a wrapper for it. 42 * When it's loaded, construct remoting.wcs as a wrapper for it.
43 * When the WCS connection is ready, or on error, call |onReady| or |onError|, 43 * When the WCS connection is ready, or on error, call |onReady| or |onError|,
44 * respectively. 44 * respectively.
45 * 45 *
46 * @param {string} token An OAuth2 access token. 46 * @param {string} token An OAuth2 access token.
47 * @param {function(string): void} onReady The callback function, called with 47 * @param {function(string): void} onReady The callback function, called with
48 * a client JID when WCS has been loaded. 48 * a client JID when WCS has been loaded.
49 * @param {function(remoting.Error):void} onError Function to invoke with an 49 * @param {function(!remoting.Error):void} onError Function to invoke with an
50 * error code on failure. 50 * error code on failure.
51 * @return {void} Nothing. 51 * @return {void} Nothing.
52 */ 52 */
53 remoting.WcsLoader.prototype.start = function(token, onReady, onError) { 53 remoting.WcsLoader.prototype.start = function(token, onReady, onError) {
54 var node = document.getElementById(this.SCRIPT_NODE_ID_); 54 var node = document.getElementById(this.SCRIPT_NODE_ID_);
55 if (node) { 55 if (node) {
56 console.error('Multiple calls to WcsLoader.start are not allowed.'); 56 console.error('Multiple calls to WcsLoader.start are not allowed.');
57 onError(remoting.Error.UNEXPECTED); 57 onError(remoting.Error.UNEXPECTED);
58 return; 58 return;
59 } 59 }
60 60
61 // Create a script node to load the WCS driver. 61 // Create a script node to load the WCS driver.
62 node = document.createElement('script'); 62 node = document.createElement('script');
63 node.id = this.SCRIPT_NODE_ID_; 63 node.id = this.SCRIPT_NODE_ID_;
64 node.src = remoting.settings.TALK_GADGET_URL + 'iq?access_token=' + token; 64 node.src = remoting.settings.TALK_GADGET_URL + 'iq?access_token=' + token;
65 node.type = 'text/javascript'; 65 node.type = 'text/javascript';
66 document.body.insertBefore(node, document.body.firstChild); 66 document.body.insertBefore(node, document.body.firstChild);
67 67
68 /** @type {remoting.WcsLoader} */ 68 /** @type {remoting.WcsLoader} */
69 var that = this; 69 var that = this;
70 var onLoad = function() { 70 var onLoad = function() {
71 that.constructWcs_(token, onReady); 71 that.constructWcs_(token, onReady);
72 }; 72 };
73 var onLoadError = function(event) { 73 var onLoadError = function(event) {
74 // The DOM Event object has no detail on the nature of the error, so try to 74 // The DOM Event object has no detail on the nature of the error, so try to
75 // validate the token to get a better idea. 75 // validate the token to get a better idea.
76 /** @param {remoting.Error} error Error code. */ 76 /** @param {!remoting.Error} error Error code. */
77 var onValidateError = function(error) { 77 var onValidateError = function(error) {
78 var typedNode = /** @type {Element} */ (node); 78 var typedNode = /** @type {Element} */ (node);
79 typedNode.parentNode.removeChild(node); 79 typedNode.parentNode.removeChild(node);
80 onError(error); 80 onError(error);
81 }; 81 };
82 var onValidateOk = function() { 82 var onValidateOk = function() {
83 // We can reach the authentication server and validate the token. Either 83 // We can reach the authentication server and validate the token. Either
84 // there's something wrong with the talkgadget service, or there is a 84 // there's something wrong with the talkgadget service, or there is a
85 // cookie problem. Only the cookie problem can be fixed by the user, so 85 // cookie problem. Only the cookie problem can be fixed by the user, so
86 // suggest that fix. 86 // suggest that fix.
(...skipping 17 matching lines...) Expand all
104 remoting.WcsLoader.prototype.constructWcs_ = function(token, onReady) { 104 remoting.WcsLoader.prototype.constructWcs_ = function(token, onReady) {
105 remoting.wcs = new remoting.Wcs( 105 remoting.wcs = new remoting.Wcs(
106 remoting.wcsLoader.wcsIqClient, token, onReady); 106 remoting.wcsLoader.wcsIqClient, token, onReady);
107 }; 107 };
108 108
109 /** 109 /**
110 * Validates an OAuth2 access token. 110 * Validates an OAuth2 access token.
111 * 111 *
112 * @param {string} token The access token. 112 * @param {string} token The access token.
113 * @param {function():void} onOk Callback to invoke if the token is valid. 113 * @param {function():void} onOk Callback to invoke if the token is valid.
114 * @param {function(remoting.Error):void} onError Function to invoke with an 114 * @param {function(!remoting.Error):void} onError Function to invoke with an
115 * error code on failure. 115 * error code on failure.
116 * @return {void} Nothing. 116 * @return {void} Nothing.
117 */ 117 */
118 remoting.WcsLoader.prototype.validateToken = function(token, onOk, onError) { 118 remoting.WcsLoader.prototype.validateToken = function(token, onOk, onError) {
119 /** @type {XMLHttpRequest} */ 119 /** @type {XMLHttpRequest} */
120 var xhr = new XMLHttpRequest(); 120 var xhr = new XMLHttpRequest();
121 xhr.onreadystatechange = function() { 121 xhr.onreadystatechange = function() {
122 if (xhr.readyState != 4) { 122 if (xhr.readyState != 4) {
123 return; 123 return;
124 } 124 }
(...skipping 12 matching lines...) Expand all
137 } 137 }
138 onError(error); 138 onError(error);
139 } 139 }
140 }; 140 };
141 var parameters = '?access_token=' + encodeURIComponent(token); 141 var parameters = '?access_token=' + encodeURIComponent(token);
142 xhr.open('GET', 142 xhr.open('GET',
143 remoting.settings.OAUTH2_API_BASE_URL + '/v1/tokeninfo' + parameters, 143 remoting.settings.OAUTH2_API_BASE_URL + '/v1/tokeninfo' + parameters,
144 true); 144 true);
145 xhr.send(null); 145 xhr.send(null);
146 }; 146 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698