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

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

Issue 8336004: Improve web-app type safety. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 9 years, 2 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 | Annotate | Revision Log
« no previous file with comments | « remoting/webapp/me2mom/wcs_iq_client_proto.js ('k') | remoting/webapp/me2mom/xhr.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 /* Copyright (c) 2011 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 */
11 11
12 'use strict'; 12 'use strict';
13 13
14 /** @suppress {duplicate} */ 14 /** @suppress {duplicate} */
15 var remoting = remoting || {}; 15 var remoting = remoting || {};
16 16
17 (function() { 17 /** @type {remoting.WcsLoader} */
18 remoting.wcsLoader = null;
19
18 /** 20 /**
19 * @constructor 21 * @constructor
20 */ 22 */
21 remoting.WcsLoader = function() { 23 remoting.WcsLoader = function() {
22 /** 24 /**
23 * An OAuth2 access token. 25 * An OAuth2 access token.
24 * @type {string} 26 * @type {string}
25 * @private 27 * @private
26 */ 28 */
27 this.token_ = ''; 29 this.token_ = '';
28 30
29 /** 31 /**
30 * A callback that gets an updated access token asynchronously. 32 * A callback that gets an updated access token asynchronously.
31 * @type {function(function(string): void): void} 33 * @param {function(string): void} setToken The function to call when the
34 * token is available.
32 * @private 35 * @private
33 */ 36 */
34 this.refreshToken_ = function(setToken) {}; 37 this.refreshToken_ = function(setToken) {};
35 38
36 /** 39 /**
37 * The function called when WCS is ready. 40 * The function called when WCS is ready.
38 * @type {function(): void}
39 * @private 41 * @private
40 */ 42 */
41 this.onReady_ = function() {}; 43 this.onReady_ = function() {};
42 44
43 /** 45 /**
44 * @enum {string} 46 * @enum {string}
45 * @private 47 * @private
46 */ 48 */
47 this.LoadState_ = { 49 this.LoadState_ = {
48 NOT_STARTED: 'NOT_STARTED', 50 NOT_STARTED: 'NOT_STARTED',
49 STARTED: 'STARTED', 51 STARTED: 'STARTED',
50 READY: 'READY' 52 READY: 'READY'
51 }; 53 };
52 54
53 /** 55 /**
54 * The state of WCS loading. 56 * The state of WCS loading.
55 * @type {string} 57 * @type {string}
56 * @private 58 * @private
57 */ 59 */
58 this.loadState_ = this.LoadState_.NOT_STARTED; 60 this.loadState_ = this.LoadState_.NOT_STARTED;
59 61
60 /** 62 /**
61 * The WCS client that will be downloaded. 63 * The WCS client that will be downloaded.
62 * @type {Object} 64 * @type {remoting.WcsIqClient}
63 */ 65 */
64 this.wcsIqClient = null; 66 this.wcsIqClient = null;
65 }; 67 };
66 68
67 /** 69 /**
68 * The URL of the GTalk gadget. 70 * The URL of the GTalk gadget.
69 * @type {string} 71 * @type {string}
70 * @private 72 * @private
71 */ 73 */
72 remoting.WcsLoader.prototype.TALK_GADGET_URL_ = 74 remoting.WcsLoader.prototype.TALK_GADGET_URL_ =
(...skipping 23 matching lines...) Expand all
96 this.onReady_(); 98 this.onReady_();
97 return; 99 return;
98 } 100 }
99 if (this.loadState_ == this.LoadState_.STARTED) { 101 if (this.loadState_ == this.LoadState_.STARTED) {
100 return; 102 return;
101 } 103 }
102 this.loadState_ = this.LoadState_.STARTED; 104 this.loadState_ = this.LoadState_.STARTED;
103 var node = document.createElement('script'); 105 var node = document.createElement('script');
104 node.src = this.TALK_GADGET_URL_ + 'iq?access_token=' + this.token_; 106 node.src = this.TALK_GADGET_URL_ + 'iq?access_token=' + this.token_;
105 node.type = 'text/javascript'; 107 node.type = 'text/javascript';
108 /** @type {remoting.WcsLoader} */
106 var that = this; 109 var that = this;
107 node.onload = function() { that.constructWcs_(); }; 110 node.onload = function() { that.constructWcs_(); };
108 document.body.insertBefore(node, document.body.firstChild); 111 document.body.insertBefore(node, document.body.firstChild);
109 return; 112 return;
110 }; 113 };
111 114
112 /** 115 /**
113 * Constructs the remoting.wcs object. 116 * Constructs the remoting.wcs object.
114 * 117 *
115 * @return {void} Nothing. 118 * @return {void} Nothing.
116 * @private 119 * @private
117 */ 120 */
118 remoting.WcsLoader.prototype.constructWcs_ = function() { 121 remoting.WcsLoader.prototype.constructWcs_ = function() {
122 /** @type {remoting.WcsLoader} */
119 var that = this; 123 var that = this;
124 /** @param {function(string): void} setToken The function to call when the
125 token is available. */
126 var refreshToken = function(setToken) { that.refreshToken_(setToken); };
120 remoting.wcs = new remoting.Wcs( 127 remoting.wcs = new remoting.Wcs(
121 remoting.wcsLoader.wcsIqClient, 128 remoting.wcsLoader.wcsIqClient,
122 this.token_, 129 this.token_,
123 function() { that.onWcsReady_(); }, 130 function() { that.onWcsReady_(); },
124 function(setToken) { that.refreshToken_(setToken); }); 131 refreshToken);
125 }; 132 };
126 133
127 /** 134 /**
128 * Notifies this object that WCS is ready. 135 * Notifies this object that WCS is ready.
129 * 136 *
130 * @return {void} Nothing. 137 * @return {void} Nothing.
131 * @private 138 * @private
132 */ 139 */
133 remoting.WcsLoader.prototype.onWcsReady_ = function() { 140 remoting.WcsLoader.prototype.onWcsReady_ = function() {
134 this.loadState_ = this.LoadState_.READY; 141 this.loadState_ = this.LoadState_.READY;
135 this.onReady_(); 142 this.onReady_();
136 this.onReady_ = function() {}; 143 this.onReady_ = function() {};
137 }; 144 };
138
139 }());
OLDNEW
« no previous file with comments | « remoting/webapp/me2mom/wcs_iq_client_proto.js ('k') | remoting/webapp/me2mom/xhr.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698