OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 * @fileoverview | 6 * @fileoverview |
7 * Interface abstracting the Application functionality. | 7 * Interface abstracting the Application functionality. |
8 */ | 8 */ |
9 | 9 |
10 'use strict'; | 10 'use strict'; |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 remoting.initGlobalObjects(); | 79 remoting.initGlobalObjects(); |
80 remoting.initIdentity(); | 80 remoting.initIdentity(); |
81 | 81 |
82 this.delegate_.init(); | 82 this.delegate_.init(); |
83 | 83 |
84 var that = this; | 84 var that = this; |
85 remoting.identity.getToken().then( | 85 remoting.identity.getToken().then( |
86 this.delegate_.start.bind(this.delegate_, this.getSessionConnector()) | 86 this.delegate_.start.bind(this.delegate_, this.getSessionConnector()) |
87 ).catch(remoting.Error.handler( | 87 ).catch(remoting.Error.handler( |
88 function(/** !remoting.Error */ error) { | 88 function(/** !remoting.Error */ error) { |
89 if (error == remoting.Error.CANCELLED) { | 89 if (error.hasTag(remoting.Error.Tag.CANCELLED)) { |
90 that.exit(); | 90 that.exit(); |
91 } else { | 91 } else { |
92 that.delegate_.signInFailed(error); | 92 that.delegate_.signInFailed(error); |
93 } | 93 } |
94 } | 94 } |
95 ) | 95 ) |
96 ); | 96 ); |
97 }; | 97 }; |
98 | 98 |
99 /** | 99 /** |
100 * Quit the application. | 100 * Quit the application. |
101 */ | 101 */ |
102 remoting.Application.prototype.exit = function() { | 102 remoting.Application.prototype.exit = function() { |
103 this.delegate_.handleExit(); | 103 this.delegate_.handleExit(); |
104 chrome.app.window.current().close(); | 104 chrome.app.window.current().close(); |
105 }; | 105 }; |
106 | 106 |
107 /** Disconnect the remoting client. */ | 107 /** Disconnect the remoting client. */ |
108 remoting.Application.prototype.disconnect = function() { | 108 remoting.Application.prototype.disconnect = function() { |
109 if (remoting.clientSession) { | 109 if (remoting.clientSession) { |
110 remoting.clientSession.disconnect(remoting.Error.NONE); | 110 remoting.clientSession.disconnect(remoting.Error.none()); |
111 console.log('Disconnected.'); | 111 console.log('Disconnected.'); |
112 } | 112 } |
113 }; | 113 }; |
114 | 114 |
115 /** | 115 /** |
116 * Called when a new session has been connected. | 116 * Called when a new session has been connected. |
117 * | 117 * |
118 * @param {remoting.ClientSession} clientSession | 118 * @param {remoting.ClientSession} clientSession |
119 * @return {void} Nothing. | 119 * @return {void} Nothing. |
120 */ | 120 */ |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 * @private | 220 * @private |
221 */ | 221 */ |
222 remoting.Application.prototype.onClientStateChange_ = function(state) { | 222 remoting.Application.prototype.onClientStateChange_ = function(state) { |
223 switch (state.current) { | 223 switch (state.current) { |
224 case remoting.ClientSession.State.CLOSED: | 224 case remoting.ClientSession.State.CLOSED: |
225 console.log('Connection closed by host'); | 225 console.log('Connection closed by host'); |
226 this.onDisconnected(); | 226 this.onDisconnected(); |
227 break; | 227 break; |
228 case remoting.ClientSession.State.FAILED: | 228 case remoting.ClientSession.State.FAILED: |
229 var error = remoting.clientSession.getError(); | 229 var error = remoting.clientSession.getError(); |
230 console.error('Client plugin reported connection failed: ' + error); | 230 console.error('Client plugin reported connection failed: ' + |
| 231 error.toString()); |
231 if (error === null) { | 232 if (error === null) { |
232 error = remoting.Error.UNEXPECTED; | 233 error = remoting.Error.unexpected(); |
233 } | 234 } |
234 this.onError(error); | 235 this.onError(error); |
235 break; | 236 break; |
236 | 237 |
237 default: | 238 default: |
238 console.error('Unexpected client plugin state: ' + state.current); | 239 console.error('Unexpected client plugin state: ' + state.current); |
239 // This should only happen if the web-app and client plugin get out of | 240 // This should only happen if the web-app and client plugin get out of |
240 // sync, so MISSING_PLUGIN is a suitable error. | 241 // sync, so MISSING_PLUGIN is a suitable error. |
241 this.onError(remoting.Error.MISSING_PLUGIN); | 242 this.onError(new remoting.Error(remoting.Error.Tag.MISSING_PLUGIN)); |
242 break; | 243 break; |
243 } | 244 } |
244 | 245 |
245 base.dispose(this.sessionConnectedHooks_); | 246 base.dispose(this.sessionConnectedHooks_); |
246 this.sessionConnectedHooks_= null; | 247 this.sessionConnectedHooks_= null; |
247 remoting.clientSession.dispose(); | 248 remoting.clientSession.dispose(); |
248 remoting.clientSession = null; | 249 remoting.clientSession = null; |
249 }; | 250 }; |
250 | 251 |
251 /** @private */ | 252 /** @private */ |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
354 * Perform any application-specific cleanup before exiting. This is called in | 355 * Perform any application-specific cleanup before exiting. This is called in |
355 * lieu of start() if the user declines the app permissions, and will usually | 356 * lieu of start() if the user declines the app permissions, and will usually |
356 * be called immediately prior to exiting, although delegates should not rely | 357 * be called immediately prior to exiting, although delegates should not rely |
357 * on this. | 358 * on this. |
358 */ | 359 */ |
359 remoting.Application.Delegate.prototype.handleExit = function() {}; | 360 remoting.Application.Delegate.prototype.handleExit = function() {}; |
360 | 361 |
361 | 362 |
362 /** @type {remoting.Application} */ | 363 /** @type {remoting.Application} */ |
363 remoting.app = null; | 364 remoting.app = null; |
OLD | NEW |