| 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 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 remoting.initGlobalObjects(); | 87 remoting.initGlobalObjects(); |
| 88 remoting.initIdentity(); | 88 remoting.initIdentity(); |
| 89 | 89 |
| 90 this.delegate_.init(); | 90 this.delegate_.init(); |
| 91 | 91 |
| 92 var that = this; | 92 var that = this; |
| 93 remoting.identity.getToken().then( | 93 remoting.identity.getToken().then( |
| 94 this.delegate_.start.bind(this.delegate_, this.getSessionConnector()) | 94 this.delegate_.start.bind(this.delegate_, this.getSessionConnector()) |
| 95 ).catch(remoting.Error.handler( | 95 ).catch(remoting.Error.handler( |
| 96 function(/** !remoting.Error */ error) { | 96 function(/** !remoting.Error */ error) { |
| 97 if (error == remoting.Error.CANCELLED) { | 97 if (error.tag == remoting.Error.Tag.CANCELLED) { |
| 98 that.exit(); | 98 that.exit(); |
| 99 } else { | 99 } else { |
| 100 that.delegate_.signInFailed(error); | 100 that.delegate_.signInFailed(error); |
| 101 } | 101 } |
| 102 } | 102 } |
| 103 ) | 103 ) |
| 104 ); | 104 ); |
| 105 }; | 105 }; |
| 106 | 106 |
| 107 /** | 107 /** |
| 108 * Quit the application. | 108 * Quit the application. |
| 109 */ | 109 */ |
| 110 remoting.Application.prototype.exit = function() { | 110 remoting.Application.prototype.exit = function() { |
| 111 this.delegate_.handleExit(); | 111 this.delegate_.handleExit(); |
| 112 chrome.app.window.current().close(); | 112 chrome.app.window.current().close(); |
| 113 }; | 113 }; |
| 114 | 114 |
| 115 /** Disconnect the remoting client. */ | 115 /** Disconnect the remoting client. */ |
| 116 remoting.Application.prototype.disconnect = function() { | 116 remoting.Application.prototype.disconnect = function() { |
| 117 if (remoting.clientSession) { | 117 if (remoting.clientSession) { |
| 118 remoting.clientSession.disconnect(remoting.Error.NONE); | 118 remoting.clientSession.disconnect(remoting.Error.none()); |
| 119 console.log('Disconnected.'); | 119 console.log('Disconnected.'); |
| 120 } | 120 } |
| 121 }; | 121 }; |
| 122 | 122 |
| 123 /** | 123 /** |
| 124 * Called when a new session has been connected. | 124 * Called when a new session has been connected. |
| 125 * | 125 * |
| 126 * @param {remoting.ClientSession} clientSession | 126 * @param {remoting.ClientSession} clientSession |
| 127 * @return {void} Nothing. | 127 * @return {void} Nothing. |
| 128 */ | 128 */ |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 229 remoting.Application.prototype.onClientStateChange_ = function(state) { | 229 remoting.Application.prototype.onClientStateChange_ = function(state) { |
| 230 switch (state.current) { | 230 switch (state.current) { |
| 231 case remoting.ClientSession.State.CLOSED: | 231 case remoting.ClientSession.State.CLOSED: |
| 232 console.log('Connection closed by host'); | 232 console.log('Connection closed by host'); |
| 233 this.onDisconnected(); | 233 this.onDisconnected(); |
| 234 break; | 234 break; |
| 235 case remoting.ClientSession.State.FAILED: | 235 case remoting.ClientSession.State.FAILED: |
| 236 var error = remoting.clientSession.getError(); | 236 var error = remoting.clientSession.getError(); |
| 237 console.error('Client plugin reported connection failed: ' + error); | 237 console.error('Client plugin reported connection failed: ' + error); |
| 238 if (error === null) { | 238 if (error === null) { |
| 239 error = remoting.Error.UNEXPECTED; | 239 error = remoting.Error.unexpected(); |
| 240 } | 240 } |
| 241 this.onError(error); | 241 this.onError(error); |
| 242 break; | 242 break; |
| 243 | 243 |
| 244 default: | 244 default: |
| 245 console.error('Unexpected client plugin state: ' + state.current); | 245 console.error('Unexpected client plugin state: ' + state.current); |
| 246 // This should only happen if the web-app and client plugin get out of | 246 // This should only happen if the web-app and client plugin get out of |
| 247 // sync, so MISSING_PLUGIN is a suitable error. | 247 // sync, so MISSING_PLUGIN is a suitable error. |
| 248 this.onError(remoting.Error.MISSING_PLUGIN); | 248 this.onError(new remoting.Error(remoting.Error.Tag.MISSING_PLUGIN)); |
| 249 break; | 249 break; |
| 250 } | 250 } |
| 251 | 251 |
| 252 base.dispose(this.sessionConnectedHooks_); | 252 base.dispose(this.sessionConnectedHooks_); |
| 253 this.sessionConnectedHooks_= null; | 253 this.sessionConnectedHooks_= null; |
| 254 remoting.clientSession.dispose(); | 254 remoting.clientSession.dispose(); |
| 255 remoting.clientSession = null; | 255 remoting.clientSession = null; |
| 256 }; | 256 }; |
| 257 | 257 |
| 258 /** @private */ | 258 /** @private */ |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 360 * Perform any application-specific cleanup before exiting. This is called in | 360 * Perform any application-specific cleanup before exiting. This is called in |
| 361 * lieu of start() if the user declines the app permissions, and will usually | 361 * lieu of start() if the user declines the app permissions, and will usually |
| 362 * be called immediately prior to exiting, although delegates should not rely | 362 * be called immediately prior to exiting, although delegates should not rely |
| 363 * on this. | 363 * on this. |
| 364 */ | 364 */ |
| 365 remoting.Application.Delegate.prototype.handleExit = function() {}; | 365 remoting.Application.Delegate.prototype.handleExit = function() {}; |
| 366 | 366 |
| 367 | 367 |
| 368 /** @type {remoting.Application} */ | 368 /** @type {remoting.Application} */ |
| 369 remoting.app = null; | 369 remoting.app = null; |
| OLD | NEW |