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 * This class implements the functionality that is specific to application | 7 * This class implements the functionality that is specific to application |
| 8 * remoting ("AppRemoting" or AR). | 8 * remoting ("AppRemoting" or AR). |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 'use strict'; | 11 'use strict'; |
| 12 | 12 |
| 13 /** @suppress {duplicate} */ | 13 /** @suppress {duplicate} */ |
| 14 var remoting = remoting || {}; | 14 var remoting = remoting || {}; |
| 15 | 15 |
| 16 /** | 16 /** |
| 17 * @param {remoting.Application} app The main app that owns this delegate. | 17 * @param {remoting.Application} app The main app that owns this delegate. |
| 18 * @constructor | 18 * @constructor |
| 19 * @implements {remoting.Application.Delegate} | 19 * @implements {remoting.Application.Delegate} |
| 20 * @implements {remoting.ProtocolExtension} | |
| 20 */ | 21 */ |
| 21 remoting.AppRemoting = function(app) { | 22 remoting.AppRemoting = function(app) { |
| 22 app.setDelegate(this); | 23 app.setDelegate(this); |
| 23 | 24 |
| 24 /** @private {remoting.ApplicationContextMenu} */ | 25 /** @private {remoting.ApplicationContextMenu} */ |
| 25 this.contextMenu_ = null; | 26 this.contextMenu_ = null; |
| 26 | 27 |
| 27 /** @private {remoting.KeyboardLayoutsMenu} */ | 28 /** @private {remoting.KeyboardLayoutsMenu} */ |
| 28 this.keyboardLayoutsMenu_ = null; | 29 this.keyboardLayoutsMenu_ = null; |
| 29 | 30 |
| 30 /** @private {remoting.WindowActivationMenu} */ | 31 /** @private {remoting.WindowActivationMenu} */ |
| 31 this.windowActivationMenu_ = null; | 32 this.windowActivationMenu_ = null; |
| 32 | 33 |
| 33 /** @private {base.RepeatingTimer} */ | 34 /** @private {base.RepeatingTimer} */ |
| 34 this.pingTimer_ = null; | 35 this.pingTimer_ = null; |
| 36 | |
| 37 /** @private {remoting.DesktopConnectedView} */ | |
| 38 this.connectedView_ = null; | |
| 35 }; | 39 }; |
| 36 | 40 |
| 37 /** | 41 /** |
| 38 * Type definition for the RunApplicationResponse returned by the API. | 42 * Type definition for the RunApplicationResponse returned by the API. |
| 39 * | 43 * |
| 40 * @constructor | 44 * @constructor |
| 41 * @private | 45 * @private |
| 42 */ | 46 */ |
| 43 remoting.AppRemoting.AppHostResponse = function() { | 47 remoting.AppRemoting.AppHostResponse = function() { |
| 44 /** @type {string} */ | 48 /** @type {string} */ |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 225 * @return {void} Nothing. | 229 * @return {void} Nothing. |
| 226 */ | 230 */ |
| 227 remoting.AppRemoting.prototype.handleConnected = function(connectionInfo) { | 231 remoting.AppRemoting.prototype.handleConnected = function(connectionInfo) { |
| 228 remoting.identity.getUserInfo().then( | 232 remoting.identity.getUserInfo().then( |
| 229 function(userInfo) { | 233 function(userInfo) { |
| 230 remoting.clientSession.sendClientMessage( | 234 remoting.clientSession.sendClientMessage( |
| 231 'setUserDisplayInfo', | 235 'setUserDisplayInfo', |
| 232 JSON.stringify({fullName: userInfo.name})); | 236 JSON.stringify({fullName: userInfo.name})); |
| 233 }); | 237 }); |
| 234 | 238 |
| 239 remoting.app.getSessionConnector().registerProtocolExtension(this); | |
| 240 | |
| 235 var clientSession = connectionInfo.session(); | 241 var clientSession = connectionInfo.session(); |
| 236 // Set up a ping at 10-second intervals to test the connection speed. | 242 // Set up a ping at 10-second intervals to test the connection speed. |
| 237 var CONNECTION_SPEED_PING_INTERVAL = 10 * 1000; | 243 var CONNECTION_SPEED_PING_INTERVAL = 10 * 1000; |
| 238 this.pingTimer_ = new base.RepeatingTimer(function () { | 244 this.pingTimer_ = new base.RepeatingTimer(function () { |
| 239 var message = { timestamp: new Date().getTime() }; | 245 var message = { timestamp: new Date().getTime() }; |
| 240 clientSession.sendClientMessage('pingRequest', JSON.stringify(message)); | 246 clientSession.sendClientMessage('pingRequest', JSON.stringify(message)); |
| 241 }, CONNECTION_SPEED_PING_INTERVAL); | 247 }, CONNECTION_SPEED_PING_INTERVAL); |
| 248 | |
| 249 // TODO(kelvinp): Moves all app remoting specific logic into | |
|
Jamie
2015/03/18 01:03:56
s/Moves/Move/
kelvinp
2015/03/18 18:44:22
Done.
| |
| 250 // remoting.AppRemotingView. | |
| 251 this.connectedView_ = new remoting.DesktopConnectedView( | |
| 252 document.getElementById('client-container'), connectionInfo, | |
| 253 this.getDefaultRemapKeys()); | |
| 242 }; | 254 }; |
| 243 | 255 |
| 244 /** | 256 /** |
| 245 * Called when the current session has been disconnected. | 257 * Called when the current session has been disconnected. |
| 246 * | 258 * |
| 247 * @return {void} Nothing. | 259 * @return {void} Nothing. |
| 248 */ | 260 */ |
| 249 remoting.AppRemoting.prototype.handleDisconnected = function() { | 261 remoting.AppRemoting.prototype.handleDisconnected = function() { |
| 250 // Cancel the ping when the connection closes. | 262 // Cancel the ping when the connection closes. |
| 251 base.dispose(this.pingTimer_); | 263 base.dispose(this.pingTimer_); |
| 252 this.pingTimer_ = null; | 264 this.pingTimer_ = null; |
| 253 | 265 |
| 266 base.dispose(this.connectedView_); | |
| 267 this.connectedView_ = null; | |
| 268 | |
| 254 chrome.app.window.current().close(); | 269 chrome.app.window.current().close(); |
| 255 }; | 270 }; |
| 256 | 271 |
| 257 /** | 272 /** |
| 258 * Called when the current session's connection has failed. | 273 * Called when the current session's connection has failed. |
| 259 * | 274 * |
| 260 * @param {remoting.SessionConnector} connector | 275 * @param {remoting.SessionConnector} connector |
| 261 * @param {!remoting.Error} error | 276 * @param {!remoting.Error} error |
| 262 * @return {void} Nothing. | 277 * @return {void} Nothing. |
| 263 */ | 278 */ |
| 264 remoting.AppRemoting.prototype.handleConnectionFailed = function( | 279 remoting.AppRemoting.prototype.handleConnectionFailed = function( |
| 265 connector, error) { | 280 connector, error) { |
| 266 this.handleError(error); | 281 this.handleError(error); |
| 267 }; | 282 }; |
| 268 | 283 |
| 269 /** | 284 /** |
| 270 * Called when the current session has reached the point where the host has | 285 * Called when the current session has reached the point where the host has |
| 271 * started streaming video frames to the client. | 286 * started streaming video frames to the client. |
| 272 * | 287 * |
| 273 * @return {void} Nothing. | 288 * @return {void} Nothing. |
| 274 */ | 289 */ |
| 275 remoting.AppRemoting.prototype.handleVideoStreamingStarted = function() { | 290 remoting.AppRemoting.prototype.handleVideoStreamingStarted = function() { |
| 276 remoting.LoadingWindow.close(); | 291 remoting.LoadingWindow.close(); |
| 277 }; | 292 }; |
| 278 | 293 |
| 294 | |
| 295 /** @return {Array<string>} */ | |
| 296 remoting.AppRemoting.prototype.getExtensionTypes = function() { | |
| 297 return ['openURL', 'onWindowRemoved', 'onWindowAdded', | |
| 298 'onAllWindowsMinimized', 'setKeyboardLayouts', 'pingResponse']; | |
| 299 }; | |
| 300 | |
| 279 /** | 301 /** |
| 280 * Called when an extension message needs to be handled. | 302 * @param {function(string,string)} sendMessageToHost Callback to send a message |
| 281 * | 303 * to the host. |
| 282 * @param {string} type The type of the extension message. | 304 */ |
| 305 remoting.AppRemoting.prototype.startExtension = function(sendMessageToHost) { | |
| 306 }; | |
| 307 | |
| 308 /** | |
| 309 * @param {string} type The message type. | |
| 283 * @param {Object} message The parsed extension message data. | 310 * @param {Object} message The parsed extension message data. |
| 284 * @return {boolean} True if the extension message was recognized. | |
| 285 */ | 311 */ |
| 286 remoting.AppRemoting.prototype.handleExtensionMessage = function( | 312 remoting.AppRemoting.prototype.onExtensionMessage = function(type, message) { |
| 287 type, message) { | |
| 288 switch (type) { | 313 switch (type) { |
| 289 | 314 |
| 290 case 'openURL': | 315 case 'openURL': |
| 291 // URL requests from the hosted app are untrusted, so disallow anything | 316 // URL requests from the hosted app are untrusted, so disallow anything |
| 292 // other than HTTP or HTTPS. | 317 // other than HTTP or HTTPS. |
| 293 var url = getStringAttr(message, 'url'); | 318 var url = getStringAttr(message, 'url'); |
| 294 if (url.indexOf('http:') != 0 && url.indexOf('https:') != 0) { | 319 if (url.indexOf('http:') != 0 && url.indexOf('https:') != 0) { |
| 295 console.error('Bad URL: ' + url); | 320 console.error('Bad URL: ' + url); |
| 296 } else { | 321 } else { |
| 297 window.open(url); | 322 window.open(url); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 344 chrome.i18n.getMessage(/*i18n-content*/'CONNECTION_FAILED'), | 369 chrome.i18n.getMessage(/*i18n-content*/'CONNECTION_FAILED'), |
| 345 chrome.i18n.getMessage(error.getTag())); | 370 chrome.i18n.getMessage(error.getTag())); |
| 346 }; | 371 }; |
| 347 | 372 |
| 348 /** | 373 /** |
| 349 * Close the loading window before exiting. | 374 * Close the loading window before exiting. |
| 350 */ | 375 */ |
| 351 remoting.AppRemoting.prototype.handleExit = function() { | 376 remoting.AppRemoting.prototype.handleExit = function() { |
| 352 remoting.LoadingWindow.close(); | 377 remoting.LoadingWindow.close(); |
| 353 }; | 378 }; |
| OLD | NEW |