Chromium Code Reviews| 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'; |
| 11 | 11 |
| 12 /** @suppress {duplicate} */ | 12 /** @suppress {duplicate} */ |
| 13 var remoting = remoting || {}; | 13 var remoting = remoting || {}; |
| 14 | 14 |
| 15 /** | 15 /** |
| 16 * @param {Array.<string>} app_capabilities Array of application capabilities. | |
| 16 * @constructor | 17 * @constructor |
| 17 */ | 18 */ |
| 18 remoting.Application = function() { | 19 remoting.Application = function(app_capabilities) { |
| 19 /** | 20 /** |
| 20 * @type {remoting.Application.Delegate} | 21 * @type {remoting.Application.Delegate} |
| 21 * @private | 22 * @private |
| 22 */ | 23 */ |
| 23 this.delegate_ = null; | 24 this.delegate_ = null; |
| 24 | 25 |
| 25 /** | 26 /** |
| 27 * @type {Array.<string>} | |
| 28 * @private | |
| 29 */ | |
| 30 this.app_capabilities_ = app_capabilities; | |
| 31 | |
| 32 /** | |
| 26 * @type {remoting.SessionConnector} | 33 * @type {remoting.SessionConnector} |
| 27 * @private | 34 * @private |
| 28 */ | 35 */ |
| 29 this.session_connector_ = null; | 36 this.session_connector_ = null; |
| 30 }; | 37 }; |
| 31 | 38 |
| 32 /** | 39 /** |
| 33 * @param {remoting.Application.Delegate} appDelegate The delegate that | 40 * @param {remoting.Application.Delegate} appDelegate The delegate that |
| 34 * contains the app-specific functionality. | 41 * contains the app-specific functionality. |
| 35 */ | 42 */ |
| 36 remoting.Application.prototype.setDelegate = function(appDelegate) { | 43 remoting.Application.prototype.setDelegate = function(appDelegate) { |
| 37 this.delegate_ = appDelegate; | 44 this.delegate_ = appDelegate; |
| 38 }; | 45 }; |
| 39 | 46 |
| 40 /** | 47 /** |
| 48 * @return {Array.<string>} A list of |ClientSession.Capability|s required | |
| 49 * by this application. | |
| 50 */ | |
| 51 remoting.Application.prototype.getRequiredCapabilities_ = function() { | |
| 52 var capabilities = [ | |
| 53 remoting.ClientSession.Capability.SEND_INITIAL_RESOLUTION, | |
| 54 remoting.ClientSession.Capability.RATE_LIMIT_RESIZE_REQUESTS, | |
| 55 remoting.ClientSession.Capability.VIDEO_RECORDER | |
| 56 ]; | |
| 57 // Append the app-specific capabilities. | |
| 58 capabilities.push.apply(capabilities, this.app_capabilities_); | |
|
Jamie
2015/02/03 18:06:24
I think this would be better done in the ctor, to
| |
| 59 return capabilities; | |
| 60 }; | |
| 61 | |
| 62 /** | |
| 63 * @param {remoting.ClientSession.Capability} capability | |
| 64 * @return {boolean} | |
| 65 */ | |
| 66 remoting.Application.prototype.hasCapability = function(capability) { | |
| 67 var capabilities = remoting.app.getRequiredCapabilities_(); | |
| 68 return capabilities.indexOf(capability) != -1; | |
| 69 }; | |
| 70 | |
| 71 /** | |
| 41 * Initialize the application and register all event handlers. After this | 72 * Initialize the application and register all event handlers. After this |
| 42 * is called, the app is running and waiting for user events. | 73 * is called, the app is running and waiting for user events. |
| 43 * | 74 * |
| 44 * @return {void} Nothing. | 75 * @return {void} Nothing. |
| 45 */ | 76 */ |
| 46 remoting.Application.prototype.start = function() { | 77 remoting.Application.prototype.start = function() { |
| 47 // Create global objects. | 78 // Create global objects. |
| 48 remoting.ClientPlugin.factory = new remoting.DefaultClientPluginFactory(); | 79 remoting.ClientPlugin.factory = new remoting.DefaultClientPluginFactory(); |
| 49 remoting.SessionConnector.factory = | 80 remoting.SessionConnector.factory = |
| 50 new remoting.DefaultSessionConnectorFactory(); | 81 new remoting.DefaultSessionConnectorFactory(); |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 146 */ | 177 */ |
| 147 remoting.Application.prototype.getSessionConnector = function() { | 178 remoting.Application.prototype.getSessionConnector = function() { |
| 148 // TODO(garykac): Check if this can be initialized in the ctor. | 179 // TODO(garykac): Check if this can be initialized in the ctor. |
| 149 if (!this.session_connector_) { | 180 if (!this.session_connector_) { |
| 150 this.session_connector_ = remoting.SessionConnector.factory.createConnector( | 181 this.session_connector_ = remoting.SessionConnector.factory.createConnector( |
| 151 document.getElementById('client-container'), | 182 document.getElementById('client-container'), |
| 152 this.onConnected.bind(this), | 183 this.onConnected.bind(this), |
| 153 this.onError.bind(this), | 184 this.onError.bind(this), |
| 154 this.onExtensionMessage.bind(this), | 185 this.onExtensionMessage.bind(this), |
| 155 this.onConnectionFailed.bind(this), | 186 this.onConnectionFailed.bind(this), |
| 156 this.delegate_.getRequiredCapabilities(), | 187 this.getRequiredCapabilities_(), |
| 157 this.delegate_.getDefaultRemapKeys()); | 188 this.delegate_.getDefaultRemapKeys()); |
| 158 } | 189 } |
| 159 return this.session_connector_; | 190 return this.session_connector_; |
| 160 }; | 191 }; |
| 161 | 192 |
| 162 | 193 |
| 163 /** | 194 /** |
| 164 * @interface | 195 * @interface |
| 165 */ | 196 */ |
| 166 remoting.Application.Delegate = function() {}; | 197 remoting.Application.Delegate = function() {}; |
| 167 | 198 |
| 168 /** | 199 /** |
| 169 * Initialize the application and register all event handlers. After this | 200 * Initialize the application and register all event handlers. After this |
| 170 * is called, the app is running and waiting for user events. | 201 * is called, the app is running and waiting for user events. |
| 171 * | 202 * |
| 172 * @param {remoting.SessionConnector} connector | 203 * @param {remoting.SessionConnector} connector |
| 173 * @return {void} Nothing. | 204 * @return {void} Nothing. |
| 174 */ | 205 */ |
| 175 remoting.Application.Delegate.prototype.init = function(connector) {}; | 206 remoting.Application.Delegate.prototype.init = function(connector) {}; |
| 176 | 207 |
| 177 /** | 208 /** |
| 178 * @return {string} The default remap keys for the current platform. | 209 * @return {string} The default remap keys for the current platform. |
| 179 */ | 210 */ |
| 180 remoting.Application.Delegate.prototype.getDefaultRemapKeys = function() {}; | 211 remoting.Application.Delegate.prototype.getDefaultRemapKeys = function() {}; |
| 181 | 212 |
| 182 /** | 213 /** |
| 183 * @return {Array.<string>} A list of |ClientSession.Capability|s required | |
| 184 * by this application. | |
| 185 */ | |
| 186 remoting.Application.Delegate.prototype.getRequiredCapabilities = function() {}; | |
| 187 | |
| 188 /** | |
| 189 * Called when a new session has been connected. | 214 * Called when a new session has been connected. |
| 190 * | 215 * |
| 191 * @param {remoting.ClientSession} clientSession | 216 * @param {remoting.ClientSession} clientSession |
| 192 * @return {void} Nothing. | 217 * @return {void} Nothing. |
| 193 */ | 218 */ |
| 194 remoting.Application.Delegate.prototype.handleConnected = function( | 219 remoting.Application.Delegate.prototype.handleConnected = function( |
| 195 clientSession) {}; | 220 clientSession) {}; |
| 196 | 221 |
| 197 /** | 222 /** |
| 198 * Called when the current session has been disconnected. | 223 * Called when the current session has been disconnected. |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 234 * Called when an error needs to be displayed to the user. | 259 * Called when an error needs to be displayed to the user. |
| 235 * | 260 * |
| 236 * @param {remoting.Error} errorTag The error to be localized and displayed. | 261 * @param {remoting.Error} errorTag The error to be localized and displayed. |
| 237 * @return {void} Nothing. | 262 * @return {void} Nothing. |
| 238 */ | 263 */ |
| 239 remoting.Application.Delegate.prototype.handleError = function(errorTag) {}; | 264 remoting.Application.Delegate.prototype.handleError = function(errorTag) {}; |
| 240 | 265 |
| 241 | 266 |
| 242 /** @type {remoting.Application} */ | 267 /** @type {remoting.Application} */ |
| 243 remoting.app = null; | 268 remoting.app = null; |
| OLD | NEW |