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

Side by Side Diff: remoting/webapp/crd/js/wcs_sandbox_container.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 2013 The Chromium Authors. All rights reserved. 1 /* Copyright 2013 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 * The application side of the application/sandbox WCS interface, used by the 8 * The application side of the application/sandbox WCS interface, used by the
9 * application to exchange messages with the sandbox. 9 * application to exchange messages with the sandbox.
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 /** 17 /**
18 * @param {Window} sandbox The Javascript Window object representing the 18 * @param {Window} sandbox The Javascript Window object representing the
19 * sandboxed WCS driver. 19 * sandboxed WCS driver.
20 * @constructor 20 * @constructor
21 */ 21 */
22 remoting.WcsSandboxContainer = function(sandbox) { 22 remoting.WcsSandboxContainer = function(sandbox) {
23 /** @private */ 23 /** @private */
24 this.sandbox_ = sandbox; 24 this.sandbox_ = sandbox;
25 /** @type {?function(string):void} 25 /** @type {?function(string):void}
26 * @private */ 26 * @private */
27 this.onConnected_ = null; 27 this.onConnected_ = null;
28 /** @type {function(remoting.Error):void} 28 /** @type {function(!remoting.Error):void}
29 * @private */ 29 * @private */
30 this.onError_ = function(error) {}; 30 this.onError_ = function(error) {};
31 /** @type {?function(string):void} 31 /** @type {?function(string):void}
32 * @private */ 32 * @private */
33 this.onIq_ = null; 33 this.onIq_ = null;
34 /** @type {Object<number, XMLHttpRequest>} 34 /** @type {Object<number, XMLHttpRequest>}
35 * @private */ 35 * @private */
36 this.pendingXhrs_ = {}; 36 this.pendingXhrs_ = {};
37 /** @private */ 37 /** @private */
38 this.localJid_ = ''; 38 this.localJid_ = '';
39 39
40 /** @private */ 40 /** @private */
41 this.accessTokenRefreshTimerStarted_ = false; 41 this.accessTokenRefreshTimerStarted_ = false;
42 42
43 window.addEventListener('message', this.onMessage_.bind(this), false); 43 window.addEventListener('message', this.onMessage_.bind(this), false);
44 44
45 if (base.isAppsV2()) { 45 if (base.isAppsV2()) {
46 var message = { 46 var message = {
47 'command': 'proxyXhrs' 47 'command': 'proxyXhrs'
48 }; 48 };
49 this.sandbox_.postMessage(message, '*'); 49 this.sandbox_.postMessage(message, '*');
50 } 50 }
51 }; 51 };
52 52
53 /** 53 /**
54 * @param {function(string):void} onConnected Callback to be called when WCS is 54 * @param {function(string):void} onConnected Callback to be called when WCS is
55 * connected. May be called synchronously if WCS is already connected. 55 * connected. May be called synchronously if WCS is already connected.
56 * @param {function(remoting.Error):void} onError called in case of an error. 56 * @param {function(!remoting.Error):void} onError called in case of an error.
57 * @return {void} Nothing. 57 * @return {void} Nothing.
58 */ 58 */
59 remoting.WcsSandboxContainer.prototype.connect = function( 59 remoting.WcsSandboxContainer.prototype.connect = function(
60 onConnected, onError) { 60 onConnected, onError) {
61 this.onError_ = onError; 61 this.onError_ = onError;
62 this.ensureAccessTokenRefreshTimer_(); 62 this.ensureAccessTokenRefreshTimer_();
63 if (this.localJid_) { 63 if (this.localJid_) {
64 onConnected(this.localJid_); 64 onConnected(this.localJid_);
65 } else { 65 } else {
66 this.onConnected_ = onConnected; 66 this.onConnected_ = onConnected;
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 } 144 }
145 this.localJid_ = localJid; 145 this.localJid_ = localJid;
146 if (this.onConnected_) { 146 if (this.onConnected_) {
147 var callback = this.onConnected_; 147 var callback = this.onConnected_;
148 this.onConnected_ = null; 148 this.onConnected_ = null;
149 callback(localJid); 149 callback(localJid);
150 } 150 }
151 break; 151 break;
152 152
153 case 'onError': 153 case 'onError':
154 /** @type {remoting.Error} */ 154 /** @type {!remoting.Error} */
155 var error = event.data['error']; 155 var error = event.data['error'];
156 if (error === undefined) { 156 if (error === undefined) {
157 console.error('onError: missing error code'); 157 console.error('onError: missing error code');
158 break; 158 break;
159 } 159 }
160 this.onError_(error); 160 this.onError_(error);
161 break; 161 break;
162 162
163 case 'onIq': 163 case 'onIq':
164 /** @type {string} */ 164 /** @type {string} */
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 'xhr': sanitizeXhr_(xhr) 281 'xhr': sanitizeXhr_(xhr)
282 }; 282 };
283 this.sandbox_.postMessage(message, '*'); 283 this.sandbox_.postMessage(message, '*');
284 if (xhr.readyState == 4) { 284 if (xhr.readyState == 4) {
285 delete this.pendingXhrs_[id]; 285 delete this.pendingXhrs_[id];
286 } 286 }
287 } 287 }
288 288
289 /** @type {remoting.WcsSandboxContainer} */ 289 /** @type {remoting.WcsSandboxContainer} */
290 remoting.wcsSandbox = null; 290 remoting.wcsSandbox = null;
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698