Chromium Code Reviews| Index: remoting/webapp/app_remoting/js/app_remoting.js |
| diff --git a/remoting/webapp/app_remoting/js/app_remoting.js b/remoting/webapp/app_remoting/js/app_remoting.js |
| index b3fd07c25fc24c3383d03422c35dd490761d97e7..487d7ac716c9122585ab36831427c6b5bc50d64a 100644 |
| --- a/remoting/webapp/app_remoting/js/app_remoting.js |
| +++ b/remoting/webapp/app_remoting/js/app_remoting.js |
| @@ -14,13 +14,14 @@ |
| 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} |
| * @implements {remoting.ProtocolExtension} |
| + * @extends {remoting.Application} |
| */ |
| -remoting.AppRemoting = function(app) { |
| - app.setDelegate(this); |
| +remoting.AppRemoting = function(appCapabilities) { |
| + base.inherits(this, remoting.Application, appCapabilities); |
| /** @private {remoting.ApplicationContextMenu} */ |
| this.contextMenu_ = null; |
| @@ -59,12 +60,39 @@ remoting.AppRemoting.AppHostResponse = function() { |
| hostId: ''}; |
| }; |
| +/** @return {string} */ |
| +remoting.AppRemoting.prototype.runApplicationUrl = function() { |
|
Jamie
2015/03/25 20:00:39
This shouldn't be a public member, I don't think.
garykac
2015/03/26 01:41:57
Done.
|
| + return remoting.settings.APP_REMOTING_API_BASE_URL + '/applications/' + |
| + remoting.settings.getAppRemotingApplicationId() + '/run'; |
| +}; |
| + |
| +/** |
| + * Required for remoting.ApplicationInterface interface. |
| + * |
| + * @return {string} Application product name to be used in UI. |
| + * @override |
| + */ |
| +remoting.AppRemoting.prototype.getApplicationName = function() { |
| + var manifest = chrome.runtime.getManifest(); |
| + return manifest.name; |
| +}; |
| + |
| +/** |
| + * Required for remoting.ApplicationInterface interface. |
| + * |
| + * @param {!remoting.Error} error The failure reason. |
| + * @override |
| + */ |
| +remoting.AppRemoting.prototype.signInFailed = function(error) { |
| + this.onError(error); |
| +}; |
| + |
| /** |
| - * Initialize the application. This is called before an OAuth token is requested |
| - * and should be used for tasks such as initializing the DOM, registering event |
| - * handlers, etc. |
| + * Required for remoting.ApplicationInterface interface. |
| + * |
| + * @override |
| */ |
| -remoting.AppRemoting.prototype.init = function() { |
| +remoting.AppRemoting.prototype.initApplication = function() { |
| // TODO(jamiewalch): Remove ClientSession's dependency on remoting.fullscreen |
| // so that this is no longer required. |
| remoting.fullscreen = new remoting.FullscreenAppsV2(); |
| @@ -93,15 +121,12 @@ remoting.AppRemoting.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.AppRemoting.prototype.start = function(connector, token) { |
| +remoting.AppRemoting.prototype.startApplication = function(token) { |
| /** @type {remoting.AppRemoting} */ |
| var that = this; |
| @@ -147,9 +172,9 @@ remoting.AppRemoting.prototype.start = function(connector, token) { |
| host['sharedSecret']); |
| }; |
| - connector.connectMe2App(host, fetchThirdPartyToken); |
| + that.sessionConnector_.connectMe2App(host, fetchThirdPartyToken); |
| } else if (response && response.status == 'pending') { |
| - that.handleError(new remoting.Error( |
| + that.onError(new remoting.Error( |
| remoting.Error.Tag.SERVICE_UNAVAILABLE)); |
| } |
| } else { |
| @@ -158,19 +183,19 @@ remoting.AppRemoting.prototype.start = function(connector, token) { |
| // been updated to properly report 'unknown' errors (rather than |
| // reporting them as AUTHENTICATION_FAILED). |
| if (xhrResponse.status == 0) { |
| - that.handleError(new remoting.Error( |
| + that.onError(new remoting.Error( |
| remoting.Error.Tag.NETWORK_FAILURE)); |
| } else if (xhrResponse.status == 401) { |
| - that.handleError(new remoting.Error( |
| + that.onError(new remoting.Error( |
| remoting.Error.Tag.AUTHENTICATION_FAILED)); |
| } else if (xhrResponse.status == 403) { |
| - that.handleError(new remoting.Error( |
| + that.onError(new remoting.Error( |
| remoting.Error.Tag.APP_NOT_AUTHORIZED)); |
| } else if (xhrResponse.status == 502 || xhrResponse.status == 503) { |
| - that.handleError(new remoting.Error( |
| + that.onError(new remoting.Error( |
| remoting.Error.Tag.SERVICE_UNAVAILABLE)); |
| } else { |
| - that.handleError(remoting.Error.unexpected()); |
| + that.onError(remoting.Error.unexpected()); |
| } |
| } |
| }; |
| @@ -183,27 +208,13 @@ remoting.AppRemoting.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.AppRemoting.prototype.signInFailed = function(error) { |
| - this.handleError(error); |
| -}; |
| - |
| -/** |
| - * @return {string} Application product name to be used in UI. |
| + * Close the loading window before exiting. |
| */ |
| -remoting.AppRemoting.prototype.getApplicationName = function() { |
| - var manifest = chrome.runtime.getManifest(); |
| - return manifest.name; |
| -}; |
| +remoting.AppRemoting.prototype.exit = function() { |
| + remoting.LoadingWindow.close(); |
| -/** @return {string} */ |
| -remoting.AppRemoting.prototype.runApplicationUrl = function() { |
| - return remoting.settings.APP_REMOTING_API_BASE_URL + '/applications/' + |
| - remoting.settings.getAppRemotingApplicationId() + '/run'; |
| + // Call superclass exit() after we've closed all our windows. |
| + remoting.Application.prototype.exit.call(this); |
| }; |
| /** |
| @@ -212,7 +223,9 @@ remoting.AppRemoting.prototype.runApplicationUrl = function() { |
| * @param {remoting.ConnectionInfo} connectionInfo |
| * @return {void} Nothing. |
| */ |
| -remoting.AppRemoting.prototype.handleConnected = function(connectionInfo) { |
| +remoting.AppRemoting.prototype.onConnected = function(connectionInfo) { |
| + remoting.Application.prototype.onConnected.call(this, connectionInfo); |
| + |
| remoting.identity.getUserInfo().then( |
| function(userInfo) { |
| remoting.clientSession.sendClientMessage( |
| @@ -220,7 +233,7 @@ remoting.AppRemoting.prototype.handleConnected = function(connectionInfo) { |
| JSON.stringify({fullName: userInfo.name})); |
| }); |
| - remoting.app.getSessionConnector().registerProtocolExtension(this); |
| + this.sessionConnector_.registerProtocolExtension(this); |
| this.connectedView_ = new remoting.AppConnectedView( |
| document.getElementById('client-container'), connectionInfo); |
| @@ -237,7 +250,9 @@ remoting.AppRemoting.prototype.handleConnected = function(connectionInfo) { |
| * |
| * @return {void} Nothing. |
| */ |
| -remoting.AppRemoting.prototype.handleDisconnected = function() { |
| +remoting.AppRemoting.prototype.onDisconnected = function() { |
| + remoting.Application.prototype.onDisconnected.call(this); |
| + |
| base.dispose(this.connectedView_); |
| this.connectedView_ = null; |
| @@ -247,22 +262,45 @@ remoting.AppRemoting.prototype.handleDisconnected = function() { |
| /** |
| * Called when the current session's connection has failed. |
| * |
| - * @param {remoting.SessionConnector} connector |
| * @param {!remoting.Error} error |
| * @return {void} Nothing. |
| */ |
| -remoting.AppRemoting.prototype.handleConnectionFailed = function( |
| - connector, error) { |
| - this.handleError(error); |
| +remoting.AppRemoting.prototype.onConnectionFailed = function(error) { |
| + remoting.Application.prototype.onConnectionFailed.call(this, error); |
| + |
| + this.onError(error); |
| }; |
| -/** @return {Array<string>} */ |
| +/** |
| + * Called when an error needs to be displayed to the user. |
| + * |
| + * @param {!remoting.Error} error The error to be localized and displayed. |
| + * @return {void} Nothing. |
| + */ |
| +remoting.AppRemoting.prototype.onError = function(error) { |
| + remoting.Application.prototype.onError.call(this, error); |
| + |
| + console.error('Connection failed: ' + error.toString()); |
| + remoting.LoadingWindow.close(); |
| + remoting.MessageWindow.showErrorMessage( |
| + chrome.i18n.getMessage(/*i18n-content*/'CONNECTION_FAILED'), |
| + chrome.i18n.getMessage(error.getTag())); |
| +}; |
| + |
| + |
| +/** |
| + * Required for remoting.ProtocolExtension interface. |
| + * |
| + * @return {Array<string>} |
| + */ |
| remoting.AppRemoting.prototype.getExtensionTypes = function() { |
| return ['openURL', 'onWindowRemoved', 'onWindowAdded', |
| 'onAllWindowsMinimized', 'setKeyboardLayouts', 'pingResponse']; |
| }; |
| /** |
| + * Required for remoting.ProtocolExtension interface. |
| + * |
| * @param {function(string,string)} sendMessageToHost Callback to send a message |
| * to the host. |
| */ |
| @@ -270,6 +308,8 @@ remoting.AppRemoting.prototype.startExtension = function(sendMessageToHost) { |
| }; |
| /** |
| + * Required for remoting.ProtocolExtension interface. |
| + * |
| * @param {string} type The message type. |
| * @param {Object} message The parsed extension message data. |
| */ |
| @@ -319,24 +359,3 @@ remoting.AppRemoting.prototype.onExtensionMessage = function(type, message) { |
| return false; |
| }; |
| - |
| -/** |
| - * Called when an error needs to be displayed to the user. |
| - * |
| - * @param {!remoting.Error} error The error to be localized and displayed. |
| - * @return {void} Nothing. |
| - */ |
| -remoting.AppRemoting.prototype.handleError = function(error) { |
| - console.error('Connection failed: ' + error.toString()); |
| - remoting.LoadingWindow.close(); |
| - remoting.MessageWindow.showErrorMessage( |
| - chrome.i18n.getMessage(/*i18n-content*/'CONNECTION_FAILED'), |
| - chrome.i18n.getMessage(error.getTag())); |
| -}; |
| - |
| -/** |
| - * Close the loading window before exiting. |
| - */ |
| -remoting.AppRemoting.prototype.handleExit = function() { |
| - remoting.LoadingWindow.close(); |
| -}; |