| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 * Class handling user-facing aspects of the client session. | 7 * Class handling user-facing aspects of the client session. |
| 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 {HTMLElement} container | 16 * @param {HTMLElement} container |
| 17 * @param {remoting.ConnectionInfo} connectionInfo | 17 * @param {remoting.ConnectionInfo} connectionInfo |
| 18 * @param {string} defaultRemapKeys The default set of remap keys, to use | |
| 19 * when the client doesn't define any. | |
| 20 * @constructor | 18 * @constructor |
| 21 * @extends {base.EventSourceImpl} | 19 * @extends {base.EventSourceImpl} |
| 22 * @implements {base.Disposable} | 20 * @implements {base.Disposable} |
| 23 */ | 21 */ |
| 24 remoting.DesktopConnectedView = function(container, connectionInfo, | 22 remoting.DesktopConnectedView = function(container, connectionInfo) { |
| 25 defaultRemapKeys) { | |
| 26 | 23 |
| 27 /** @private {HTMLElement} */ | 24 /** @private {HTMLElement} */ |
| 28 this.container_ = container; | 25 this.container_ = container; |
| 29 | 26 |
| 30 /** @private {remoting.ClientPlugin} */ | 27 /** @private {remoting.ClientPlugin} */ |
| 31 this.plugin_ = connectionInfo.plugin(); | 28 this.plugin_ = connectionInfo.plugin(); |
| 32 | 29 |
| 33 /** @private {remoting.ClientSession} */ | 30 /** @private {remoting.ClientSession} */ |
| 34 this.session_ = connectionInfo.session(); | 31 this.session_ = connectionInfo.session(); |
| 35 | 32 |
| 36 /** @private */ | 33 /** @private */ |
| 37 this.host_ = connectionInfo.host(); | 34 this.host_ = connectionInfo.host(); |
| 38 | 35 |
| 39 /** @private */ | 36 /** @private */ |
| 40 this.mode_ = connectionInfo.mode(); | 37 this.mode_ = connectionInfo.mode(); |
| 41 | 38 |
| 42 /** @private {string} */ | |
| 43 this.defaultRemapKeys_ = defaultRemapKeys; | |
| 44 | |
| 45 /** @private {remoting.DesktopViewport} */ | 39 /** @private {remoting.DesktopViewport} */ |
| 46 this.viewport_ = null; | 40 this.viewport_ = null; |
| 47 | 41 |
| 48 /** private {remoting.ConnectedView} */ | 42 /** private {remoting.ConnectedView} */ |
| 49 this.view_ = null; | 43 this.view_ = null; |
| 50 | 44 |
| 51 /** @private {remoting.VideoFrameRecorder} */ | 45 /** @private {remoting.VideoFrameRecorder} */ |
| 52 this.videoFrameRecorder_ = null; | 46 this.videoFrameRecorder_ = null; |
| 53 | 47 |
| 54 /** private {base.Disposable} */ | 48 /** private {base.Disposable} */ |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 if (!this.plugin_.hasFeature( | 143 if (!this.plugin_.hasFeature( |
| 150 remoting.ClientPlugin.Feature.INJECT_KEY_EVENT)) { | 144 remoting.ClientPlugin.Feature.INJECT_KEY_EVENT)) { |
| 151 var sendKeysElement = document.getElementById('send-keys-menu'); | 145 var sendKeysElement = document.getElementById('send-keys-menu'); |
| 152 sendKeysElement.hidden = true; | 146 sendKeysElement.hidden = true; |
| 153 } else if (this.mode_ != remoting.DesktopConnectedView.Mode.ME2ME && | 147 } else if (this.mode_ != remoting.DesktopConnectedView.Mode.ME2ME && |
| 154 this.mode_ != remoting.DesktopConnectedView.Mode.APP_REMOTING) { | 148 this.mode_ != remoting.DesktopConnectedView.Mode.APP_REMOTING) { |
| 155 var sendCadElement = document.getElementById('send-ctrl-alt-del'); | 149 var sendCadElement = document.getElementById('send-ctrl-alt-del'); |
| 156 sendCadElement.hidden = true; | 150 sendCadElement.hidden = true; |
| 157 } | 151 } |
| 158 | 152 |
| 159 // Apply customized key remappings if the plugin supports remapKeys. | |
| 160 if (this.plugin_.hasFeature(remoting.ClientPlugin.Feature.REMAP_KEY)) { | |
| 161 this.applyRemapKeys_(true); | |
| 162 } | |
| 163 | |
| 164 if (this.session_.hasCapability( | 153 if (this.session_.hasCapability( |
| 165 remoting.ClientSession.Capability.VIDEO_RECORDER)) { | 154 remoting.ClientSession.Capability.VIDEO_RECORDER)) { |
| 166 this.videoFrameRecorder_ = new remoting.VideoFrameRecorder(this.plugin_); | 155 this.videoFrameRecorder_ = new remoting.VideoFrameRecorder(this.plugin_); |
| 167 } | 156 } |
| 168 }; | 157 }; |
| 169 | 158 |
| 170 /** | 159 /** |
| 171 * This is a callback that gets called when the window is resized. | 160 * This is a callback that gets called when the window is resized. |
| 172 * | 161 * |
| 173 * @return {void} Nothing. | 162 * @return {void} Nothing. |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 247 // Fullscreen.isActive call is not guaranteed to return true until the | 236 // Fullscreen.isActive call is not guaranteed to return true until the |
| 248 // full-screen event is triggered. In apps v2, the size of the window's | 237 // full-screen event is triggered. In apps v2, the size of the window's |
| 249 // client area is calculated differently in full-screen mode, so register | 238 // client area is calculated differently in full-screen mode, so register |
| 250 // for both events. | 239 // for both events. |
| 251 this.viewport_.onResize(); | 240 this.viewport_.onResize(); |
| 252 this.viewport_.enableBumpScroll(Boolean(fullscreen)); | 241 this.viewport_.enableBumpScroll(Boolean(fullscreen)); |
| 253 } | 242 } |
| 254 }; | 243 }; |
| 255 | 244 |
| 256 /** | 245 /** |
| 257 * Sets and stores the key remapping setting for the current host. | |
| 258 * | |
| 259 * @param {string} remappings Comma separated list of key remappings. | |
| 260 */ | |
| 261 remoting.DesktopConnectedView.prototype.setRemapKeys = function(remappings) { | |
| 262 // Cancel any existing remappings and apply the new ones. | |
| 263 this.applyRemapKeys_(false); | |
| 264 this.host_.options.remapKeys = remappings; | |
| 265 this.applyRemapKeys_(true); | |
| 266 | |
| 267 // Save the new remapping setting. | |
| 268 this.host_.options.save(); | |
| 269 }; | |
| 270 | |
| 271 /** | |
| 272 * Applies the configured key remappings to the session, or resets them. | |
| 273 * | |
| 274 * @param {boolean} apply True to apply remappings, false to cancel them. | |
| 275 */ | |
| 276 remoting.DesktopConnectedView.prototype.applyRemapKeys_ = function(apply) { | |
| 277 var remapKeys = this.host_.options.remapKeys; | |
| 278 if (remapKeys == '') { | |
| 279 remapKeys = this.defaultRemapKeys_; | |
| 280 if (remapKeys == '') { | |
| 281 return; | |
| 282 } | |
| 283 } | |
| 284 | |
| 285 var remappings = remapKeys.split(','); | |
| 286 for (var i = 0; i < remappings.length; ++i) { | |
| 287 var keyCodes = remappings[i].split('>'); | |
| 288 if (keyCodes.length != 2) { | |
| 289 console.log('bad remapKey: ' + remappings[i]); | |
| 290 continue; | |
| 291 } | |
| 292 var fromKey = parseInt(keyCodes[0], 0); | |
| 293 var toKey = parseInt(keyCodes[1], 0); | |
| 294 if (!fromKey || !toKey) { | |
| 295 console.log('bad remapKey code: ' + remappings[i]); | |
| 296 continue; | |
| 297 } | |
| 298 if (apply) { | |
| 299 console.log('remapKey 0x' + fromKey.toString(16) + | |
| 300 '>0x' + toKey.toString(16)); | |
| 301 this.plugin_.remapKey(fromKey, toKey); | |
| 302 } else { | |
| 303 console.log('cancel remapKey 0x' + fromKey.toString(16)); | |
| 304 this.plugin_.remapKey(fromKey, fromKey); | |
| 305 } | |
| 306 } | |
| 307 }; | |
| 308 | |
| 309 /** | |
| 310 * Sends a key combination to the remoting client, by sending down events for | |
| 311 * the given keys, followed by up events in reverse order. | |
| 312 * | |
| 313 * @param {Array<number>} keys Key codes to be sent. | |
| 314 * @return {void} Nothing. | |
| 315 * @private | |
| 316 */ | |
| 317 remoting.DesktopConnectedView.prototype.sendKeyCombination_ = function(keys) { | |
| 318 for (var i = 0; i < keys.length; i++) { | |
| 319 this.plugin_.injectKeyEvent(keys[i], true); | |
| 320 } | |
| 321 for (var i = 0; i < keys.length; i++) { | |
| 322 this.plugin_.injectKeyEvent(keys[i], false); | |
| 323 } | |
| 324 }; | |
| 325 | |
| 326 /** | |
| 327 * Sends a Ctrl-Alt-Del sequence to the remoting client. | 246 * Sends a Ctrl-Alt-Del sequence to the remoting client. |
| 328 * | 247 * |
| 329 * @return {void} Nothing. | 248 * @return {void} Nothing. |
| 330 */ | 249 */ |
| 331 remoting.DesktopConnectedView.prototype.sendCtrlAltDel = function() { | 250 remoting.DesktopConnectedView.prototype.sendCtrlAltDel = function() { |
| 332 console.log('Sending Ctrl-Alt-Del.'); | 251 console.log('Sending Ctrl-Alt-Del.'); |
| 333 this.sendKeyCombination_([0x0700e0, 0x0700e2, 0x07004c]); | 252 this.plugin_.injectKeyCombination([0x0700e0, 0x0700e2, 0x07004c]); |
| 334 }; | 253 }; |
| 335 | 254 |
| 336 /** | 255 /** |
| 337 * Sends a Print Screen keypress to the remoting client. | 256 * Sends a Print Screen keypress to the remoting client. |
| 338 * | 257 * |
| 339 * @return {void} Nothing. | 258 * @return {void} Nothing. |
| 340 */ | 259 */ |
| 341 remoting.DesktopConnectedView.prototype.sendPrintScreen = function() { | 260 remoting.DesktopConnectedView.prototype.sendPrintScreen = function() { |
| 342 console.log('Sending Print Screen.'); | 261 console.log('Sending Print Screen.'); |
| 343 this.sendKeyCombination_([0x070046]); | 262 this.plugin_.injectKeyCombination([0x070046]); |
| 344 }; | 263 }; |
| 345 | 264 |
| 346 /** | 265 /** |
| 347 * Returns true if the ClientSession can record video frames to a file. | 266 * Returns true if the ClientSession can record video frames to a file. |
| 348 * @return {boolean} | 267 * @return {boolean} |
| 349 */ | 268 */ |
| 350 remoting.DesktopConnectedView.prototype.canRecordVideo = function() { | 269 remoting.DesktopConnectedView.prototype.canRecordVideo = function() { |
| 351 return !!this.videoFrameRecorder_; | 270 return !!this.videoFrameRecorder_; |
| 352 }; | 271 }; |
| 353 | 272 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 377 * @param {Object} message The parsed extension message data. | 296 * @param {Object} message The parsed extension message data. |
| 378 * @return {boolean} True if the message was recognized, false otherwise. | 297 * @return {boolean} True if the message was recognized, false otherwise. |
| 379 */ | 298 */ |
| 380 remoting.DesktopConnectedView.prototype.handleExtensionMessage = | 299 remoting.DesktopConnectedView.prototype.handleExtensionMessage = |
| 381 function(type, message) { | 300 function(type, message) { |
| 382 if (this.videoFrameRecorder_) { | 301 if (this.videoFrameRecorder_) { |
| 383 return this.videoFrameRecorder_.handleMessage(type, message); | 302 return this.videoFrameRecorder_.handleMessage(type, message); |
| 384 } | 303 } |
| 385 return false; | 304 return false; |
| 386 }; | 305 }; |
| OLD | NEW |