| 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 * This class implements the functionality that is specific to desktop | 7 * This class implements the functionality that is specific to desktop |
| 8 * remoting ("Chromoting" or CRD). | 8 * remoting ("Chromoting" or CRD). |
| 9 */ | 9 */ |
| 10 | 10 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 this.app_ = app; | 29 this.app_ = app; |
| 30 app.setDelegate(this); | 30 app.setDelegate(this); |
| 31 | 31 |
| 32 /** | 32 /** |
| 33 * Whether to refresh the JID and retry the connection if the current JID | 33 * Whether to refresh the JID and retry the connection if the current JID |
| 34 * is offline. | 34 * is offline. |
| 35 * | 35 * |
| 36 * @private {boolean} | 36 * @private {boolean} |
| 37 */ | 37 */ |
| 38 this.refreshHostJidIfOffline_ = true; | 38 this.refreshHostJidIfOffline_ = true; |
| 39 |
| 40 /** @private {remoting.DesktopConnectedView} */ |
| 41 this.connectedView_ = null; |
| 42 |
| 43 remoting.desktopDelegateForTesting = this; |
| 39 }; | 44 }; |
| 40 | 45 |
| 41 /** | 46 /** |
| 42 * Initialize the application and register all event handlers. After this | 47 * Initialize the application and register all event handlers. After this |
| 43 * is called, the app is running and waiting for user events. | 48 * is called, the app is running and waiting for user events. |
| 44 * | 49 * |
| 45 * @return {void} Nothing. | 50 * @return {void} Nothing. |
| 46 */ | 51 */ |
| 47 remoting.DesktopRemoting.prototype.init = function() { | 52 remoting.DesktopRemoting.prototype.init = function() { |
| 48 remoting.initElementEventHandlers(); | 53 remoting.initElementEventHandlers(); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 var onIsWindowed = function(isWindowed) { | 111 var onIsWindowed = function(isWindowed) { |
| 107 if (!isWindowed) { | 112 if (!isWindowed) { |
| 108 document.getElementById('startup-mode-box-me2me').hidden = false; | 113 document.getElementById('startup-mode-box-me2me').hidden = false; |
| 109 document.getElementById('startup-mode-box-it2me').hidden = false; | 114 document.getElementById('startup-mode-box-it2me').hidden = false; |
| 110 } | 115 } |
| 111 }; | 116 }; |
| 112 isWindowed_(onIsWindowed); | 117 isWindowed_(onIsWindowed); |
| 113 } | 118 } |
| 114 | 119 |
| 115 remoting.ClientPlugin.factory.preloadPlugin(); | 120 remoting.ClientPlugin.factory.preloadPlugin(); |
| 116 } | 121 }; |
| 117 | 122 |
| 118 /** | 123 /** |
| 119 * Start the application. Once start() is called, the delegate can assume that | 124 * Start the application. Once start() is called, the delegate can assume that |
| 120 * the user has consented to all permissions specified in the manifest. | 125 * the user has consented to all permissions specified in the manifest. |
| 121 * | 126 * |
| 122 * @param {remoting.SessionConnector} connector | 127 * @param {remoting.SessionConnector} connector |
| 123 * @param {string} token An OAuth access token. The delegate should not cache | 128 * @param {string} token An OAuth access token. The delegate should not cache |
| 124 * this token, but can assume that it will remain valid during application | 129 * this token, but can assume that it will remain valid during application |
| 125 * start-up. | 130 * start-up. |
| 126 */ | 131 */ |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 // Reset the refresh flag so that the next connection will retry if needed. | 190 // Reset the refresh flag so that the next connection will retry if needed. |
| 186 this.refreshHostJidIfOffline_ = true; | 191 this.refreshHostJidIfOffline_ = true; |
| 187 | 192 |
| 188 document.getElementById('access-code-entry').value = ''; | 193 document.getElementById('access-code-entry').value = ''; |
| 189 remoting.setMode(remoting.AppMode.IN_SESSION); | 194 remoting.setMode(remoting.AppMode.IN_SESSION); |
| 190 if (!base.isAppsV2()) { | 195 if (!base.isAppsV2()) { |
| 191 remoting.toolbar.center(); | 196 remoting.toolbar.center(); |
| 192 remoting.toolbar.preview(); | 197 remoting.toolbar.preview(); |
| 193 } | 198 } |
| 194 | 199 |
| 195 if (remoting.desktopConnectedView.getMode() == | 200 this.connectedView_ = new remoting.DesktopConnectedView( |
| 196 remoting.DesktopConnectedView.Mode.ME2ME) { | 201 document.getElementById('client-container'), connectionInfo, |
| 202 this.getDefaultRemapKeys()); |
| 203 |
| 204 if (connectionInfo.mode() === remoting.DesktopConnectedView.Mode.ME2ME) { |
| 197 var sessionConnector = remoting.app.getSessionConnector(); | 205 var sessionConnector = remoting.app.getSessionConnector(); |
| 198 if (remoting.app.hasCapability(remoting.ClientSession.Capability.CAST)) { | 206 if (remoting.app.hasCapability(remoting.ClientSession.Capability.CAST)) { |
| 199 sessionConnector.registerProtocolExtension( | 207 sessionConnector.registerProtocolExtension( |
| 200 new remoting.CastExtensionHandler()); | 208 new remoting.CastExtensionHandler()); |
| 201 } | 209 } |
| 202 sessionConnector.registerProtocolExtension( | 210 sessionConnector.registerProtocolExtension( |
| 203 new remoting.GnubbyAuthHandler()); | 211 new remoting.GnubbyAuthHandler()); |
| 204 } | 212 } |
| 205 | 213 |
| 206 if (remoting.pairingRequested) { | 214 if (remoting.pairingRequested) { |
| (...skipping 28 matching lines...) Expand all Loading... |
| 235 connectionInfo.session().requestPairing(clientName, onPairingComplete); | 243 connectionInfo.session().requestPairing(clientName, onPairingComplete); |
| 236 } | 244 } |
| 237 }; | 245 }; |
| 238 | 246 |
| 239 /** | 247 /** |
| 240 * Called when the current session has been disconnected. | 248 * Called when the current session has been disconnected. |
| 241 * | 249 * |
| 242 * @return {void} Nothing. | 250 * @return {void} Nothing. |
| 243 */ | 251 */ |
| 244 remoting.DesktopRemoting.prototype.handleDisconnected = function() { | 252 remoting.DesktopRemoting.prototype.handleDisconnected = function() { |
| 245 if (remoting.desktopConnectedView.getMode() == | 253 var mode = this.connectedView_.getMode(); |
| 246 remoting.DesktopConnectedView.Mode.IT2ME) { | 254 if (mode === remoting.DesktopConnectedView.Mode.IT2ME) { |
| 247 remoting.setMode(remoting.AppMode.CLIENT_SESSION_FINISHED_IT2ME); | 255 remoting.setMode(remoting.AppMode.CLIENT_SESSION_FINISHED_IT2ME); |
| 248 } else { | 256 } else { |
| 249 remoting.setMode(remoting.AppMode.CLIENT_SESSION_FINISHED_ME2ME); | 257 remoting.setMode(remoting.AppMode.CLIENT_SESSION_FINISHED_ME2ME); |
| 250 } | 258 } |
| 259 base.dispose(this.connectedView_); |
| 260 this.connectedView_ = null; |
| 251 }; | 261 }; |
| 252 | 262 |
| 253 /** | 263 /** |
| 254 * Called when the current session's connection has failed. | 264 * Called when the current session's connection has failed. |
| 255 * | 265 * |
| 256 * @param {remoting.SessionConnector} connector | 266 * @param {remoting.SessionConnector} connector |
| 257 * @param {!remoting.Error} error | 267 * @param {!remoting.Error} error |
| 258 * @return {void} Nothing. | 268 * @return {void} Nothing. |
| 259 */ | 269 */ |
| 260 remoting.DesktopRemoting.prototype.handleConnectionFailed = function( | 270 remoting.DesktopRemoting.prototype.handleConnectionFailed = function( |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 294 }; | 304 }; |
| 295 | 305 |
| 296 /** | 306 /** |
| 297 * Called when an error needs to be displayed to the user. | 307 * Called when an error needs to be displayed to the user. |
| 298 * | 308 * |
| 299 * @param {!remoting.Error} error The error to be localized and displayed. | 309 * @param {!remoting.Error} error The error to be localized and displayed. |
| 300 * @return {void} Nothing. | 310 * @return {void} Nothing. |
| 301 */ | 311 */ |
| 302 remoting.DesktopRemoting.prototype.handleError = function(error) { | 312 remoting.DesktopRemoting.prototype.handleError = function(error) { |
| 303 console.error('Connection failed: ' + error.toString()); | 313 console.error('Connection failed: ' + error.toString()); |
| 304 remoting.accessCode = ''; | 314 var mode = this.connectedView_ ? this.connectedView_.getMode() |
| 315 : this.app_.getSessionConnector().getConnectionMode(); |
| 316 base.dispose(this.connectedView_); |
| 317 this.connectedView_ = null; |
| 305 | 318 |
| 306 if (error.hasTag(remoting.Error.Tag.AUTHENTICATION_FAILED)) { | 319 if (error.hasTag(remoting.Error.Tag.AUTHENTICATION_FAILED)) { |
| 307 remoting.setMode(remoting.AppMode.HOME); | 320 remoting.setMode(remoting.AppMode.HOME); |
| 308 remoting.handleAuthFailureAndRelaunch(); | 321 remoting.handleAuthFailureAndRelaunch(); |
| 309 return; | 322 return; |
| 310 } | 323 } |
| 311 | 324 |
| 312 // Reset the refresh flag so that the next connection will retry if needed. | 325 // Reset the refresh flag so that the next connection will retry if needed. |
| 313 this.refreshHostJidIfOffline_ = true; | 326 this.refreshHostJidIfOffline_ = true; |
| 314 | 327 |
| 315 var errorDiv = document.getElementById('connect-error-message'); | 328 var errorDiv = document.getElementById('connect-error-message'); |
| 316 l10n.localizeElementFromTag(errorDiv, error.getTag()); | 329 l10n.localizeElementFromTag(errorDiv, error.getTag()); |
| 317 | 330 |
| 318 var mode = remoting.clientSession ? remoting.desktopConnectedView.getMode() | |
| 319 : this.app_.getSessionConnector().getConnectionMode(); | |
| 320 if (mode == remoting.DesktopConnectedView.Mode.IT2ME) { | 331 if (mode == remoting.DesktopConnectedView.Mode.IT2ME) { |
| 321 remoting.setMode(remoting.AppMode.CLIENT_CONNECT_FAILED_IT2ME); | 332 remoting.setMode(remoting.AppMode.CLIENT_CONNECT_FAILED_IT2ME); |
| 322 } else { | 333 } else { |
| 323 remoting.setMode(remoting.AppMode.CLIENT_CONNECT_FAILED_ME2ME); | 334 remoting.setMode(remoting.AppMode.CLIENT_CONNECT_FAILED_ME2ME); |
| 324 } | 335 } |
| 325 }; | 336 }; |
| 326 | 337 |
| 327 /** | 338 /** |
| 328 * No cleanup required for desktop remoting. | 339 * No cleanup required for desktop remoting. |
| 329 */ | 340 */ |
| 330 remoting.DesktopRemoting.prototype.handleExit = function() { | 341 remoting.DesktopRemoting.prototype.handleExit = function() { |
| 331 }; | 342 }; |
| 343 |
| 344 /** @returns {remoting.DesktopConnectedView} */ |
| 345 remoting.DesktopRemoting.prototype.getConnectedViewForTesting = function() { |
| 346 return this.connectedView_; |
| 347 }; |
| 348 |
| 349 /** |
| 350 * Global instance of remoting.DesktopRemoting used for testing. |
| 351 * @type {remoting.DesktopRemoting} |
| 352 */ |
| 353 remoting.desktopDelegateForTesting = null; |
| OLD | NEW |