Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(532)

Side by Side Diff: remoting/webapp/crd/js/client_session.js

Issue 761673008: Add a per-host desktopScale option, available via the JS console. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add setDesktopZoom helper Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 creation and teardown of a remoting client session. 7 * Class handling creation and teardown of a remoting client session.
8 * 8 *
9 * The ClientSession class controls lifetime of the client plugin 9 * The ClientSession class controls lifetime of the client plugin
10 * object and provides the plugin with the functionality it needs to 10 * object and provides the plugin with the functionality it needs to
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 /** @private */ 122 /** @private */
123 this.sessionId_ = ''; 123 this.sessionId_ = '';
124 /** @type {remoting.ClientPlugin} 124 /** @type {remoting.ClientPlugin}
125 * @private */ 125 * @private */
126 this.plugin_ = null; 126 this.plugin_ = null;
127 /** @private */ 127 /** @private */
128 this.shrinkToFit_ = true; 128 this.shrinkToFit_ = true;
129 /** @private */ 129 /** @private */
130 this.resizeToClient_ = true; 130 this.resizeToClient_ = true;
131 /** @private */ 131 /** @private */
132 this.desktopZoom_ = 1.0;
133 /** @private */
132 this.remapKeys_ = ''; 134 this.remapKeys_ = '';
133 /** @private */ 135 /** @private */
134 this.hasReceivedFrame_ = false; 136 this.hasReceivedFrame_ = false;
135 this.logToServer = new remoting.LogToServer(signalStrategy, mode); 137 this.logToServer = new remoting.LogToServer(signalStrategy, mode);
136 138
137 /** @private */ 139 /** @private */
138 this.signalStrategy_ = signalStrategy; 140 this.signalStrategy_ = signalStrategy;
139 base.debug.assert(this.signalStrategy_.getState() == 141 base.debug.assert(this.signalStrategy_.getState() ==
140 remoting.SignalStrategy.State.CONNECTED); 142 remoting.SignalStrategy.State.CONNECTED);
141 this.signalStrategy_.setIncomingStanzaCallback( 143 this.signalStrategy_.setIncomingStanzaCallback(
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 remoting.ClientSession.STATS_KEY_CAPTURE_LATENCY = 'captureLatency'; 372 remoting.ClientSession.STATS_KEY_CAPTURE_LATENCY = 'captureLatency';
371 remoting.ClientSession.STATS_KEY_ENCODE_LATENCY = 'encodeLatency'; 373 remoting.ClientSession.STATS_KEY_ENCODE_LATENCY = 'encodeLatency';
372 remoting.ClientSession.STATS_KEY_DECODE_LATENCY = 'decodeLatency'; 374 remoting.ClientSession.STATS_KEY_DECODE_LATENCY = 'decodeLatency';
373 remoting.ClientSession.STATS_KEY_RENDER_LATENCY = 'renderLatency'; 375 remoting.ClientSession.STATS_KEY_RENDER_LATENCY = 'renderLatency';
374 remoting.ClientSession.STATS_KEY_ROUNDTRIP_LATENCY = 'roundtripLatency'; 376 remoting.ClientSession.STATS_KEY_ROUNDTRIP_LATENCY = 'roundtripLatency';
375 377
376 // Keys for per-host settings. 378 // Keys for per-host settings.
377 remoting.ClientSession.KEY_REMAP_KEYS = 'remapKeys'; 379 remoting.ClientSession.KEY_REMAP_KEYS = 'remapKeys';
378 remoting.ClientSession.KEY_RESIZE_TO_CLIENT = 'resizeToClient'; 380 remoting.ClientSession.KEY_RESIZE_TO_CLIENT = 'resizeToClient';
379 remoting.ClientSession.KEY_SHRINK_TO_FIT = 'shrinkToFit'; 381 remoting.ClientSession.KEY_SHRINK_TO_FIT = 'shrinkToFit';
382 remoting.ClientSession.KEY_DESKTOP_ZOOM = 'desktopZoom';
380 383
381 /** 384 /**
382 * Set of capabilities for which hasCapability_() can be used to test. 385 * Set of capabilities for which hasCapability_() can be used to test.
383 * 386 *
384 * @enum {string} 387 * @enum {string}
385 */ 388 */
386 remoting.ClientSession.Capability = { 389 remoting.ClientSession.Capability = {
387 // When enabled this capability causes the client to send its screen 390 // When enabled this capability causes the client to send its screen
388 // resolution to the host once connection has been established. See 391 // resolution to the host once connection has been established. See
389 // this.plugin_.notifyClientResolution(). 392 // this.plugin_.notifyClientResolution().
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
495 'boolean') { 498 'boolean') {
496 this.resizeToClient_ = /** @type {boolean} */ 499 this.resizeToClient_ = /** @type {boolean} */
497 options[remoting.ClientSession.KEY_RESIZE_TO_CLIENT]; 500 options[remoting.ClientSession.KEY_RESIZE_TO_CLIENT];
498 } 501 }
499 if (remoting.ClientSession.KEY_SHRINK_TO_FIT in options && 502 if (remoting.ClientSession.KEY_SHRINK_TO_FIT in options &&
500 typeof(options[remoting.ClientSession.KEY_SHRINK_TO_FIT]) == 503 typeof(options[remoting.ClientSession.KEY_SHRINK_TO_FIT]) ==
501 'boolean') { 504 'boolean') {
502 this.shrinkToFit_ = /** @type {boolean} */ 505 this.shrinkToFit_ = /** @type {boolean} */
503 options[remoting.ClientSession.KEY_SHRINK_TO_FIT]; 506 options[remoting.ClientSession.KEY_SHRINK_TO_FIT];
504 } 507 }
508 if (remoting.ClientSession.KEY_DESKTOP_ZOOM in options &&
509 typeof(options[remoting.ClientSession.KEY_DESKTOP_ZOOM]) ==
510 'number') {
511 this.desktopZoom_ = /** @type {number} */
512 options[remoting.ClientSession.KEY_DESKTOP_ZOOM];
513 }
505 514
506 /** @param {boolean} result */ 515 /** @param {boolean} result */
507 this.plugin_.initialize(this.onPluginInitialized_.bind(this)); 516 this.plugin_.initialize(this.onPluginInitialized_.bind(this));
508 }; 517 };
509 518
510 /** 519 /**
511 * Constrains the focus to the plugin element. 520 * Constrains the focus to the plugin element.
512 * @private 521 * @private
513 */ 522 */
514 remoting.ClientSession.prototype.setFocusHandlers_ = function() { 523 remoting.ClientSession.prototype.setFocusHandlers_ = function() {
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
765 * Sends a Print Screen keypress to the remoting client. 774 * Sends a Print Screen keypress to the remoting client.
766 * 775 *
767 * @return {void} Nothing. 776 * @return {void} Nothing.
768 */ 777 */
769 remoting.ClientSession.prototype.sendPrintScreen = function() { 778 remoting.ClientSession.prototype.sendPrintScreen = function() {
770 console.log('Sending Print Screen.'); 779 console.log('Sending Print Screen.');
771 this.sendKeyCombination_([0x070046]); 780 this.sendKeyCombination_([0x070046]);
772 } 781 }
773 782
774 /** 783 /**
784 * Sets and stores the zoom factor to apply to host sizing requests.
785 *
786 * @param {number} desktopZoom Scale factor to apply.
787 */
788 remoting.ClientSession.prototype.setDesktopZoom =
789 function(desktopZoom) {
790 // Apply the new desktop zoom, if resize to client is enabled.
Jamie 2014/12/15 18:39:06 Nit: resize-to-client
Wez 2014/12/15 21:49:42 Done.
791 this.desktopZoom_ = desktopZoom;
792 if (this.resizeToClient_) {
793 this.notifyClientResolution_();
794 }
795
796 // Save the new desktop zoom setting.
797 var options = {};
798 options[remoting.ClientSession.KEY_DESKTOP_ZOOM] = this.desktopZoom_;
799 remoting.HostSettings.save(this.hostId_, options);
800 }
801
802 /**
775 * Sets and stores the key remapping setting for the current host. 803 * Sets and stores the key remapping setting for the current host.
776 * 804 *
777 * @param {string} remappings Comma separated list of key remappings. 805 * @param {string} remappings Comma separated list of key remappings.
778 */ 806 */
779 remoting.ClientSession.prototype.setRemapKeys = function(remappings) { 807 remoting.ClientSession.prototype.setRemapKeys = function(remappings) {
780 // Cancel any existing remappings and apply the new ones. 808 // Cancel any existing remappings and apply the new ones.
781 this.applyRemapKeys_(false); 809 this.applyRemapKeys_(false);
782 this.remapKeys_ = remappings; 810 this.remapKeys_ = remappings;
783 this.applyRemapKeys_(true); 811 this.applyRemapKeys_(true);
784 812
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
835 * should be added in this case. 863 * should be added in this case.
836 * @param {boolean} resizeToClient True if window resizes should cause the 864 * @param {boolean} resizeToClient True if window resizes should cause the
837 * host to attempt to resize its desktop to match the client window size; 865 * host to attempt to resize its desktop to match the client window size;
838 * false to disable this behaviour for subsequent window resizes--the 866 * false to disable this behaviour for subsequent window resizes--the
839 * current host desktop size is not restored in this case. 867 * current host desktop size is not restored in this case.
840 * @return {void} Nothing. 868 * @return {void} Nothing.
841 */ 869 */
842 remoting.ClientSession.prototype.setScreenMode = 870 remoting.ClientSession.prototype.setScreenMode =
843 function(shrinkToFit, resizeToClient) { 871 function(shrinkToFit, resizeToClient) {
844 if (resizeToClient && !this.resizeToClient_) { 872 if (resizeToClient && !this.resizeToClient_) {
845 var clientArea = this.getClientArea_(); 873 this.notifyClientResolution_();
846 this.plugin_.notifyClientResolution(clientArea.width,
847 clientArea.height,
848 window.devicePixelRatio);
849 } 874 }
850 875
851 // If enabling shrink, reset bump-scroll offsets. 876 // If enabling shrink, reset bump-scroll offsets.
852 var needsScrollReset = shrinkToFit && !this.shrinkToFit_; 877 var needsScrollReset = shrinkToFit && !this.shrinkToFit_;
853 878
854 this.shrinkToFit_ = shrinkToFit; 879 this.shrinkToFit_ = shrinkToFit;
855 this.resizeToClient_ = resizeToClient; 880 this.resizeToClient_ = resizeToClient;
856 this.updateScrollbarVisibility(); 881 this.updateScrollbarVisibility();
857 882
858 if (this.hostId_ != '') { 883 if (this.hostId_ != '') {
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
1001 * @private 1026 * @private
1002 * @param {number} status The plugin's status. 1027 * @param {number} status The plugin's status.
1003 * @param {number} error The plugin's error state, if any. 1028 * @param {number} error The plugin's error state, if any.
1004 */ 1029 */
1005 remoting.ClientSession.prototype.onConnectionStatusUpdate_ = 1030 remoting.ClientSession.prototype.onConnectionStatusUpdate_ =
1006 function(status, error) { 1031 function(status, error) {
1007 if (status == remoting.ClientSession.State.CONNECTED) { 1032 if (status == remoting.ClientSession.State.CONNECTED) {
1008 this.setFocusHandlers_(); 1033 this.setFocusHandlers_();
1009 this.onDesktopSizeChanged_(); 1034 this.onDesktopSizeChanged_();
1010 if (this.resizeToClient_) { 1035 if (this.resizeToClient_) {
1011 var clientArea = this.getClientArea_(); 1036 this.notifyClientResolution_();
1012 this.plugin_.notifyClientResolution(clientArea.width,
1013 clientArea.height,
1014 window.devicePixelRatio);
1015 } 1037 }
1016 // Activate full-screen related UX. 1038 // Activate full-screen related UX.
1017 remoting.fullscreen.addListener(this.callOnFullScreenChanged_); 1039 remoting.fullscreen.addListener(this.callOnFullScreenChanged_);
1018 this.updateClientSessionUi_(this); 1040 this.updateClientSessionUi_(this);
1019 this.container_.addEventListener('mousemove', 1041 this.container_.addEventListener('mousemove',
1020 this.updateMouseCursorPosition_, 1042 this.updateMouseCursorPosition_,
1021 true); 1043 true);
1022 1044
1023 } else if (status == remoting.ClientSession.State.FAILED) { 1045 } else if (status == remoting.ClientSession.State.FAILED) {
1024 switch (error) { 1046 switch (error) {
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
1097 */ 1119 */
1098 remoting.ClientSession.prototype.onSetCapabilities_ = function(capabilities) { 1120 remoting.ClientSession.prototype.onSetCapabilities_ = function(capabilities) {
1099 if (this.capabilities_ != null) { 1121 if (this.capabilities_ != null) {
1100 console.error('onSetCapabilities_() is called more than once'); 1122 console.error('onSetCapabilities_() is called more than once');
1101 return; 1123 return;
1102 } 1124 }
1103 1125
1104 this.capabilities_ = capabilities; 1126 this.capabilities_ = capabilities;
1105 if (this.hasCapability_( 1127 if (this.hasCapability_(
1106 remoting.ClientSession.Capability.SEND_INITIAL_RESOLUTION)) { 1128 remoting.ClientSession.Capability.SEND_INITIAL_RESOLUTION)) {
1107 var clientArea = this.getClientArea_(); 1129 this.notifyClientResolution_();
1108 this.plugin_.notifyClientResolution(clientArea.width,
1109 clientArea.height,
1110 window.devicePixelRatio);
1111 } 1130 }
1112 if (this.hasCapability_(remoting.ClientSession.Capability.GOOGLE_DRIVE)) { 1131 if (this.hasCapability_(remoting.ClientSession.Capability.GOOGLE_DRIVE)) {
1113 this.sendGoogleDriveAccessToken_(); 1132 this.sendGoogleDriveAccessToken_();
1114 } 1133 }
1115 if (this.hasCapability_( 1134 if (this.hasCapability_(
1116 remoting.ClientSession.Capability.VIDEO_RECORDER)) { 1135 remoting.ClientSession.Capability.VIDEO_RECORDER)) {
1117 this.videoFrameRecorder_ = new remoting.VideoFrameRecorder(this.plugin_); 1136 this.videoFrameRecorder_ = new remoting.VideoFrameRecorder(this.plugin_);
1118 } 1137 }
1119 }; 1138 };
1120 1139
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
1169 // Defer notifying the host of the change until the window stops resizing, to 1188 // Defer notifying the host of the change until the window stops resizing, to
1170 // avoid overloading the control channel with notifications. 1189 // avoid overloading the control channel with notifications.
1171 if (this.resizeToClient_) { 1190 if (this.resizeToClient_) {
1172 var kResizeRateLimitMs = 1000; 1191 var kResizeRateLimitMs = 1000;
1173 if (this.hasCapability_( 1192 if (this.hasCapability_(
1174 remoting.ClientSession.Capability.RATE_LIMIT_RESIZE_REQUESTS)) { 1193 remoting.ClientSession.Capability.RATE_LIMIT_RESIZE_REQUESTS)) {
1175 kResizeRateLimitMs = 250; 1194 kResizeRateLimitMs = 250;
1176 } 1195 }
1177 var clientArea = this.getClientArea_(); 1196 var clientArea = this.getClientArea_();
1178 this.notifyClientResolutionTimer_ = window.setTimeout( 1197 this.notifyClientResolutionTimer_ = window.setTimeout(
1179 this.plugin_.notifyClientResolution.bind(this.plugin_, 1198 this.notifyClientResolution_.bind(this),
1180 clientArea.width,
1181 clientArea.height,
1182 window.devicePixelRatio),
1183 kResizeRateLimitMs); 1199 kResizeRateLimitMs);
1184 } 1200 }
1185 1201
1186 // If bump-scrolling is enabled, adjust the plugin margins to fully utilize 1202 // If bump-scrolling is enabled, adjust the plugin margins to fully utilize
1187 // the new window area. 1203 // the new window area.
1188 this.resetScroll_(); 1204 this.resetScroll_();
1189 1205
1190 this.updateScrollbarVisibility(); 1206 this.updateScrollbarVisibility();
1191 }; 1207 };
1192 1208
(...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after
1626 * borders used by the latter. 1642 * borders used by the latter.
1627 * @private 1643 * @private
1628 */ 1644 */
1629 remoting.ClientSession.prototype.getClientArea_ = function() { 1645 remoting.ClientSession.prototype.getClientArea_ = function() {
1630 return remoting.windowFrame ? 1646 return remoting.windowFrame ?
1631 remoting.windowFrame.getClientArea() : 1647 remoting.windowFrame.getClientArea() :
1632 { 'width': window.innerWidth, 'height': window.innerHeight }; 1648 { 'width': window.innerWidth, 'height': window.innerHeight };
1633 }; 1649 };
1634 1650
1635 /** 1651 /**
1652 * Notifies the host of the client's current dimensions and DPI.
1653 * Also takes into account per-host scaling factor, if configured.
1654 * @private
1655 */
1656 remoting.ClientSession.prototype.notifyClientResolution_ = function() {
1657 var clientArea = this.getClientArea_();
1658 this.plugin_.notifyClientResolution(clientArea.width * this.desktopZoom_,
1659 clientArea.height * this.desktopZoom_,
1660 window.devicePixelRatio);
Jamie 2014/12/15 18:39:06 Don't you also need to apply the inverse scale to
Wez 2014/12/15 21:49:42 That's a good question. I've added code in update
1661 }
1662
1663 /**
1636 * @param {string} url 1664 * @param {string} url
1637 * @param {number} hotspotX 1665 * @param {number} hotspotX
1638 * @param {number} hotspotY 1666 * @param {number} hotspotY
1639 */ 1667 */
1640 remoting.ClientSession.prototype.updateMouseCursorImage_ = 1668 remoting.ClientSession.prototype.updateMouseCursorImage_ =
1641 function(url, hotspotX, hotspotY) { 1669 function(url, hotspotX, hotspotY) {
1642 this.mouseCursorOverlay_.hidden = !url; 1670 this.mouseCursorOverlay_.hidden = !url;
1643 if (url) { 1671 if (url) {
1644 this.mouseCursorOverlay_.style.marginLeft = '-' + hotspotX + 'px'; 1672 this.mouseCursorOverlay_.style.marginLeft = '-' + hotspotX + 'px';
1645 this.mouseCursorOverlay_.style.marginTop = '-' + hotspotY + 'px'; 1673 this.mouseCursorOverlay_.style.marginTop = '-' + hotspotY + 'px';
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
1731 * @param {string} data Contents of the extension message. 1759 * @param {string} data Contents of the extension message.
1732 * @return {boolean} True if the message was recognized, false otherwise. 1760 * @return {boolean} True if the message was recognized, false otherwise.
1733 */ 1761 */
1734 remoting.ClientSession.prototype.handleExtensionMessage = 1762 remoting.ClientSession.prototype.handleExtensionMessage =
1735 function(type, data) { 1763 function(type, data) {
1736 if (this.videoFrameRecorder_) { 1764 if (this.videoFrameRecorder_) {
1737 return this.videoFrameRecorder_.handleMessage(type, data); 1765 return this.videoFrameRecorder_.handleMessage(type, data);
1738 } 1766 }
1739 return false; 1767 return false;
1740 } 1768 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698