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

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: 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 /** @private {?function(string):void} */ 25 /** @private {?function(string):void} */
26 this.onConnected_ = null; 26 this.onConnected_ = null;
27 /** @private {function(remoting.Error):void} */ 27 /** @private {function(!remoting.Error):void} */
28 this.onError_ = function(error) {}; 28 this.onError_ = function(error) {};
29 /** @private {?function(string):void} */ 29 /** @private {?function(string):void} */
30 this.onIq_ = null; 30 this.onIq_ = null;
31 /** @private {Object<number, XMLHttpRequest>} */ 31 /** @private {Object<number, XMLHttpRequest>} */
32 this.pendingXhrs_ = {}; 32 this.pendingXhrs_ = {};
33 /** @private */ 33 /** @private */
34 this.localJid_ = ''; 34 this.localJid_ = '';
35 35
36 /** @private */ 36 /** @private */
37 this.accessTokenRefreshTimerStarted_ = false; 37 this.accessTokenRefreshTimerStarted_ = false;
38 38
39 window.addEventListener('message', this.onMessage_.bind(this), false); 39 window.addEventListener('message', this.onMessage_.bind(this), false);
40 40
41 if (base.isAppsV2()) { 41 if (base.isAppsV2()) {
42 var message = { 42 var message = {
43 'command': 'proxyXhrs' 43 'command': 'proxyXhrs'
44 }; 44 };
45 this.sandbox_.postMessage(message, '*'); 45 this.sandbox_.postMessage(message, '*');
46 } 46 }
47 }; 47 };
48 48
49 /** 49 /**
50 * @param {function(string):void} onConnected Callback to be called when WCS is 50 * @param {function(string):void} onConnected Callback to be called when WCS is
51 * connected. May be called synchronously if WCS is already connected. 51 * connected. May be called synchronously if WCS is already connected.
52 * @param {function(remoting.Error):void} onError called in case of an error. 52 * @param {function(!remoting.Error):void} onError called in case of an error.
53 * @return {void} Nothing. 53 * @return {void} Nothing.
54 */ 54 */
55 remoting.WcsSandboxContainer.prototype.connect = function( 55 remoting.WcsSandboxContainer.prototype.connect = function(
56 onConnected, onError) { 56 onConnected, onError) {
57 this.onError_ = onError; 57 this.onError_ = onError;
58 this.ensureAccessTokenRefreshTimer_(); 58 this.ensureAccessTokenRefreshTimer_();
59 if (this.localJid_) { 59 if (this.localJid_) {
60 onConnected(this.localJid_); 60 onConnected(this.localJid_);
61 } else { 61 } else {
62 this.onConnected_ = onConnected; 62 this.onConnected_ = onConnected;
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 } 140 }
141 this.localJid_ = localJid; 141 this.localJid_ = localJid;
142 if (this.onConnected_) { 142 if (this.onConnected_) {
143 var callback = this.onConnected_; 143 var callback = this.onConnected_;
144 this.onConnected_ = null; 144 this.onConnected_ = null;
145 callback(localJid); 145 callback(localJid);
146 } 146 }
147 break; 147 break;
148 148
149 case 'onError': 149 case 'onError':
150 /** @type {remoting.Error} */ 150 /** @type {!remoting.Error} */
151 var error = event.data['error']; 151 var error = event.data['error'];
152 if (error === undefined) { 152 if (error === undefined) {
153 console.error('onError: missing error code'); 153 console.error('onError: missing error code');
154 break; 154 break;
155 } 155 }
156 this.onError_(error); 156 this.onError_(error);
157 break; 157 break;
158 158
159 case 'onIq': 159 case 'onIq':
160 /** @type {string} */ 160 /** @type {string} */
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 'xhr': sanitizeXhr_(xhr) 277 'xhr': sanitizeXhr_(xhr)
278 }; 278 };
279 this.sandbox_.postMessage(message, '*'); 279 this.sandbox_.postMessage(message, '*');
280 if (xhr.readyState == 4) { 280 if (xhr.readyState == 4) {
281 delete this.pendingXhrs_[id]; 281 delete this.pendingXhrs_[id];
282 } 282 }
283 } 283 }
284 284
285 /** @type {remoting.WcsSandboxContainer} */ 285 /** @type {remoting.WcsSandboxContainer} */
286 remoting.wcsSandbox = null; 286 remoting.wcsSandbox = null;
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698