Chromium Code Reviews| Index: remoting/webapp/crd/js/desktop_remoting.js |
| diff --git a/remoting/webapp/crd/js/desktop_remoting.js b/remoting/webapp/crd/js/desktop_remoting.js |
| index e9b54c9f3d9181027b3430c49d0a7dfee13f6699..c01193c3d24fd93a516d419c0b2479966fac3600 100644 |
| --- a/remoting/webapp/crd/js/desktop_remoting.js |
| +++ b/remoting/webapp/crd/js/desktop_remoting.js |
| @@ -14,20 +14,13 @@ |
| var remoting = remoting || {}; |
| /** |
| - * @param {remoting.Application} app The main app that owns this delegate. |
| + * @param {Array<string>} appCapabilities Array of application capabilities. |
| * @constructor |
| - * @implements {remoting.Application.Delegate} |
| + * @implements {remoting.ApplicationInterface} |
| + * @extends {remoting.Application} |
| */ |
| -remoting.DesktopRemoting = function(app) { |
| - /** |
| - * TODO(garykac): Remove this reference to the Application. It's only |
| - * needed to get the current mode when reporting errors. So we should be |
| - * able to refactor and remove this reference cycle. |
| - * |
| - * @private {remoting.Application} |
| - */ |
| - this.app_ = app; |
| - app.setDelegate(this); |
| +remoting.DesktopRemoting = function(appCapabilities) { |
| + base.inherits(this, remoting.Application, appCapabilities); |
| /** |
| * Whether to refresh the JID and retry the connection if the current JID |
| @@ -44,12 +37,31 @@ remoting.DesktopRemoting = function(app) { |
| }; |
| /** |
| - * Initialize the application and register all event handlers. After this |
| - * is called, the app is running and waiting for user events. |
| + * Required for remoting.ApplicationInterface interface. |
|
Jamie
2015/03/25 20:00:39
I don't think you need this annotation on every me
garykac
2015/03/26 01:41:57
@override {type} works, but the type isn't validat
|
| * |
| - * @return {void} Nothing. |
| + * @return {string} Application product name to be used in UI. |
| + * @override |
| */ |
| -remoting.DesktopRemoting.prototype.init = function() { |
| +remoting.DesktopRemoting.prototype.getApplicationName = function() { |
| + return chrome.i18n.getMessage(/*i18n-content*/'PRODUCT_NAME'); |
| +}; |
| + |
| +/** |
| + * Required for remoting.ApplicationInterface interface. |
| + * |
| + * @param {!remoting.Error} error The failure reason. |
| + * @override |
| + */ |
| +remoting.DesktopRemoting.prototype.signInFailed = function(error) { |
| + remoting.showErrorMessage(error); |
| +}; |
| + |
| +/** |
| + * Required for remoting.ApplicationInterface interface. |
| + * |
| + * @override |
| + */ |
| +remoting.DesktopRemoting.prototype.initApplication = function() { |
| remoting.initElementEventHandlers(); |
| if (base.isAppsV2()) { |
| @@ -122,15 +134,12 @@ remoting.DesktopRemoting.prototype.init = function() { |
| }; |
| /** |
| - * Start the application. Once start() is called, the delegate can assume that |
| - * the user has consented to all permissions specified in the manifest. |
| + * Required for remoting.ApplicationInterface interface. |
| * |
| - * @param {remoting.SessionConnector} connector |
| - * @param {string} token An OAuth access token. The delegate should not cache |
| - * this token, but can assume that it will remain valid during application |
| - * start-up. |
| + * @param {string} token An OAuth access token. |
| + * @override |
| */ |
| -remoting.DesktopRemoting.prototype.start = function(connector, token) { |
| +remoting.DesktopRemoting.prototype.startApplication = function(token) { |
| remoting.identity.getEmail().then( |
| function(/** string */ email) { |
| document.getElementById('current-email').innerText = email; |
| @@ -140,29 +149,14 @@ remoting.DesktopRemoting.prototype.start = function(connector, token) { |
| }; |
| /** |
| - * Report an authentication error to the user. This is called in lieu of start() |
| - * if the user cannot be authenticated or if they decline the app permissions. |
| - * |
| - * @param {!remoting.Error} error The failure reason. |
| - */ |
| -remoting.DesktopRemoting.prototype.signInFailed = function(error) { |
| - remoting.showErrorMessage(error); |
| -}; |
| - |
| -/** |
| - * @return {string} Application product name to be used in UI. |
| - */ |
| -remoting.DesktopRemoting.prototype.getApplicationName = function() { |
|
garykac
2015/03/23 18:44:22
These were moved earlier in the file so to match t
|
| - return chrome.i18n.getMessage(/*i18n-content*/'PRODUCT_NAME'); |
| -}; |
| - |
| -/** |
| * Called when a new session has been connected. |
| * |
| * @param {remoting.ConnectionInfo} connectionInfo |
| * @return {void} Nothing. |
| */ |
| -remoting.DesktopRemoting.prototype.handleConnected = function(connectionInfo) { |
| +remoting.DesktopRemoting.prototype.onConnected = function(connectionInfo) { |
| + remoting.Application.prototype.onConnected.call(this, connectionInfo); |
| + |
| // Set the text on the buttons shown under the error message so that they are |
| // easy to understand in the case where a successful connection failed, as |
| // opposed to the case where a connection never succeeded. |
| @@ -195,22 +189,22 @@ remoting.DesktopRemoting.prototype.handleConnected = function(connectionInfo) { |
| } |
| if (connectionInfo.mode() === remoting.DesktopConnectedView.Mode.ME2ME) { |
| - var sessionConnector = remoting.app.getSessionConnector(); |
| if (remoting.app.hasCapability(remoting.ClientSession.Capability.CAST)) { |
| - sessionConnector.registerProtocolExtension( |
| + this.sessionConnector_.registerProtocolExtension( |
| new remoting.CastExtensionHandler()); |
| } |
| - sessionConnector.registerProtocolExtension( |
| + this.sessionConnector_.registerProtocolExtension( |
| new remoting.GnubbyAuthHandler()); |
| } |
| if (remoting.pairingRequested) { |
| + var that = this; |
| /** |
| * @param {string} clientId |
| * @param {string} sharedSecret |
| */ |
| var onPairingComplete = function(clientId, sharedSecret) { |
| - var connector = remoting.app.getSessionConnector(); |
| + var connector = that.sessionConnector_; |
| var host = remoting.hostList.getHostForId(connector.getHostId()); |
| host.options.pairingInfo.clientId = clientId; |
| host.options.pairingInfo.sharedSecret = sharedSecret; |
| @@ -242,7 +236,9 @@ remoting.DesktopRemoting.prototype.handleConnected = function(connectionInfo) { |
| * |
| * @return {void} Nothing. |
| */ |
| -remoting.DesktopRemoting.prototype.handleDisconnected = function() { |
| +remoting.DesktopRemoting.prototype.onDisconnected = function() { |
| + remoting.Application.prototype.onDisconnected.call(this); |
| + |
| var mode = this.connectedView_.getMode(); |
| if (mode === remoting.DesktopConnectedView.Mode.IT2ME) { |
| remoting.setMode(remoting.AppMode.CLIENT_SESSION_FINISHED_IT2ME); |
| @@ -256,25 +252,26 @@ remoting.DesktopRemoting.prototype.handleDisconnected = function() { |
| /** |
| * Called when the current session's connection has failed. |
| * |
| - * @param {remoting.SessionConnector} connector |
| * @param {!remoting.Error} error |
| * @return {void} Nothing. |
| */ |
| -remoting.DesktopRemoting.prototype.handleConnectionFailed = function( |
| - connector, error) { |
| +remoting.DesktopRemoting.prototype.onConnectionFailed = function(error) { |
| + remoting.Application.prototype.onConnectionFailed.call(this, error); |
| + |
| var that = this; |
| var onHostListRefresh = function(/** boolean */ success) { |
| if (success) { |
| + var connector = that.sessionConnector_; |
| var host = remoting.hostList.getHostForId(connector.getHostId()); |
| if (host) { |
| connector.retryConnectMe2Me(host); |
| return; |
| } |
| } |
| - that.handleError(error); |
| + that.onError(error); |
| }; |
| - var mode = this.app_.getSessionConnector().getConnectionMode(); |
| + var mode = this.sessionConnector_.getConnectionMode(); |
| if (error.hasTag(remoting.Error.Tag.HOST_IS_OFFLINE) && |
| mode === remoting.DesktopConnectedView.Mode.ME2ME && |
| this.refreshHostJidIfOffline_) { |
| @@ -283,7 +280,7 @@ remoting.DesktopRemoting.prototype.handleConnectionFailed = function( |
| // The plugin will be re-created when the host finished refreshing |
| remoting.hostList.refresh(onHostListRefresh); |
| } else { |
| - this.handleError(error); |
| + this.onError(error); |
| } |
| }; |
| @@ -293,10 +290,12 @@ remoting.DesktopRemoting.prototype.handleConnectionFailed = function( |
| * @param {!remoting.Error} error The error to be localized and displayed. |
| * @return {void} Nothing. |
| */ |
| -remoting.DesktopRemoting.prototype.handleError = function(error) { |
| +remoting.DesktopRemoting.prototype.onError = function(error) { |
| + remoting.Application.prototype.onError.call(this, error); |
| + |
| console.error('Connection failed: ' + error.toString()); |
| var mode = this.connectedView_ ? this.connectedView_.getMode() |
| - : this.app_.getSessionConnector().getConnectionMode(); |
| + : this.sessionConnector_.getConnectionMode(); |
| base.dispose(this.connectedView_); |
| this.connectedView_ = null; |
| @@ -320,12 +319,6 @@ remoting.DesktopRemoting.prototype.handleError = function(error) { |
| }; |
| /** |
| - * No cleanup required for desktop remoting. |
| - */ |
| -remoting.DesktopRemoting.prototype.handleExit = function() { |
| -}; |
| - |
| -/** |
| * Determine whether or not the app is running in a window. |
| * @param {function(boolean):void} callback Callback to receive whether or not |
| * the current tab is running in windowed mode. |
| @@ -358,7 +351,7 @@ remoting.DesktopRemoting.prototype.isWindowed_ = function(callback) { |
| * @private |
| */ |
| remoting.DesktopRemoting.prototype.promptClose_ = function() { |
| - var sessionConnector = remoting.app.getSessionConnector(); |
| + var sessionConnector = this.sessionConnector_; |
| if (sessionConnector && |
| sessionConnector.getConnectionMode() == |
| remoting.DesktopConnectedView.Mode.IT2ME) { |
| @@ -379,9 +372,3 @@ remoting.DesktopRemoting.prototype.promptClose_ = function() { |
| remoting.DesktopRemoting.prototype.getConnectedViewForTesting = function() { |
| return this.connectedView_; |
| }; |
| - |
| -/** |
| - * Global instance of remoting.DesktopRemoting used for testing. |
| - * @type {remoting.DesktopRemoting} |
| - */ |
| -remoting.desktopDelegateForTesting = null; |
|
garykac
2015/03/23 18:44:22
No need for this anymore. We can simply use remoti
|