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

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: Un-wrap line 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 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 /** @private */ 131 /** @private */
132 this.sessionId_ = ''; 132 this.sessionId_ = '';
133 /** @type {remoting.ClientPlugin} 133 /** @type {remoting.ClientPlugin}
134 * @private */ 134 * @private */
135 this.plugin_ = null; 135 this.plugin_ = null;
136 /** @private */ 136 /** @private */
137 this.shrinkToFit_ = true; 137 this.shrinkToFit_ = true;
138 /** @private */ 138 /** @private */
139 this.resizeToClient_ = true; 139 this.resizeToClient_ = true;
140 /** @private */ 140 /** @private */
141 this.desktopScale_ = 1.0;
142 /** @private */
141 this.remapKeys_ = ''; 143 this.remapKeys_ = '';
142 /** @private */ 144 /** @private */
143 this.hasReceivedFrame_ = false; 145 this.hasReceivedFrame_ = false;
144 this.logToServer = new remoting.LogToServer(signalStrategy, mode); 146 this.logToServer = new remoting.LogToServer(signalStrategy, mode);
145 147
146 /** @private */ 148 /** @private */
147 this.signalStrategy_ = signalStrategy; 149 this.signalStrategy_ = signalStrategy;
148 base.debug.assert(this.signalStrategy_.getState() == 150 base.debug.assert(this.signalStrategy_.getState() ==
149 remoting.SignalStrategy.State.CONNECTED); 151 remoting.SignalStrategy.State.CONNECTED);
150 this.signalStrategy_.setIncomingStanzaCallback( 152 this.signalStrategy_.setIncomingStanzaCallback(
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
379 remoting.ClientSession.STATS_KEY_CAPTURE_LATENCY = 'captureLatency'; 381 remoting.ClientSession.STATS_KEY_CAPTURE_LATENCY = 'captureLatency';
380 remoting.ClientSession.STATS_KEY_ENCODE_LATENCY = 'encodeLatency'; 382 remoting.ClientSession.STATS_KEY_ENCODE_LATENCY = 'encodeLatency';
381 remoting.ClientSession.STATS_KEY_DECODE_LATENCY = 'decodeLatency'; 383 remoting.ClientSession.STATS_KEY_DECODE_LATENCY = 'decodeLatency';
382 remoting.ClientSession.STATS_KEY_RENDER_LATENCY = 'renderLatency'; 384 remoting.ClientSession.STATS_KEY_RENDER_LATENCY = 'renderLatency';
383 remoting.ClientSession.STATS_KEY_ROUNDTRIP_LATENCY = 'roundtripLatency'; 385 remoting.ClientSession.STATS_KEY_ROUNDTRIP_LATENCY = 'roundtripLatency';
384 386
385 // Keys for per-host settings. 387 // Keys for per-host settings.
386 remoting.ClientSession.KEY_REMAP_KEYS = 'remapKeys'; 388 remoting.ClientSession.KEY_REMAP_KEYS = 'remapKeys';
387 remoting.ClientSession.KEY_RESIZE_TO_CLIENT = 'resizeToClient'; 389 remoting.ClientSession.KEY_RESIZE_TO_CLIENT = 'resizeToClient';
388 remoting.ClientSession.KEY_SHRINK_TO_FIT = 'shrinkToFit'; 390 remoting.ClientSession.KEY_SHRINK_TO_FIT = 'shrinkToFit';
391 remoting.ClientSession.KEY_DESKTOP_SCALE = 'desktopScale';
389 392
390 /** 393 /**
391 * Set of capabilities for which hasCapability_() can be used to test. 394 * Set of capabilities for which hasCapability_() can be used to test.
392 * 395 *
393 * @enum {string} 396 * @enum {string}
394 */ 397 */
395 remoting.ClientSession.Capability = { 398 remoting.ClientSession.Capability = {
396 // When enabled this capability causes the client to send its screen 399 // When enabled this capability causes the client to send its screen
397 // resolution to the host once connection has been established. See 400 // resolution to the host once connection has been established. See
398 // this.plugin_.notifyClientResolution(). 401 // this.plugin_.notifyClientResolution().
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
499 'boolean') { 502 'boolean') {
500 this.resizeToClient_ = /** @type {boolean} */ 503 this.resizeToClient_ = /** @type {boolean} */
501 options[remoting.ClientSession.KEY_RESIZE_TO_CLIENT]; 504 options[remoting.ClientSession.KEY_RESIZE_TO_CLIENT];
502 } 505 }
503 if (remoting.ClientSession.KEY_SHRINK_TO_FIT in options && 506 if (remoting.ClientSession.KEY_SHRINK_TO_FIT in options &&
504 typeof(options[remoting.ClientSession.KEY_SHRINK_TO_FIT]) == 507 typeof(options[remoting.ClientSession.KEY_SHRINK_TO_FIT]) ==
505 'boolean') { 508 'boolean') {
506 this.shrinkToFit_ = /** @type {boolean} */ 509 this.shrinkToFit_ = /** @type {boolean} */
507 options[remoting.ClientSession.KEY_SHRINK_TO_FIT]; 510 options[remoting.ClientSession.KEY_SHRINK_TO_FIT];
508 } 511 }
512 if (remoting.ClientSession.KEY_DESKTOP_SCALE in options &&
513 typeof(options[remoting.ClientSession.KEY_DESKTOP_SCALE]) ==
514 'number') {
515 this.desktopScale_ = /** @type {number} */
516 options[remoting.ClientSession.KEY_DESKTOP_SCALE];
517 }
509 518
510 /** @param {boolean} result */ 519 /** @param {boolean} result */
511 this.plugin_.initialize(this.onPluginInitialized_.bind(this)); 520 this.plugin_.initialize(this.onPluginInitialized_.bind(this));
512 }; 521 };
513 522
514 /** 523 /**
515 * Constrains the focus to the plugin element. 524 * Constrains the focus to the plugin element.
516 * @private 525 * @private
517 */ 526 */
518 remoting.ClientSession.prototype.setFocusHandlers_ = function() { 527 remoting.ClientSession.prototype.setFocusHandlers_ = function() {
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
767 * Sends a Print Screen keypress to the remoting client. 776 * Sends a Print Screen keypress to the remoting client.
768 * 777 *
769 * @return {void} Nothing. 778 * @return {void} Nothing.
770 */ 779 */
771 remoting.ClientSession.prototype.sendPrintScreen = function() { 780 remoting.ClientSession.prototype.sendPrintScreen = function() {
772 console.log('Sending Print Screen.'); 781 console.log('Sending Print Screen.');
773 this.sendKeyCombination_([0x070046]); 782 this.sendKeyCombination_([0x070046]);
774 } 783 }
775 784
776 /** 785 /**
786 * Sets and stores the scale factor to apply to host sizing requests.
787 * The desktopScale applies to the dimensions reported to the host, not
788 * to the client DPI reported to it.
789 *
790 * @param {number} desktopScale Scale factor to apply.
791 */
792 remoting.ClientSession.prototype.setDesktopScale = function(desktopScale) {
793 this.desktopScale_ = desktopScale;
794
795 // onResize() will update the plugin size and scrollbars for the new
796 // scaled plugin dimensions, and send a client resolution notification.
797 this.onResize();
798
799 // Save the new desktop scale setting.
800 var options = {};
801 options[remoting.ClientSession.KEY_DESKTOP_SCALE] = this.desktopScale_;
802 remoting.HostSettings.save(this.hostId_, options);
803 }
804
805 /**
777 * Sets and stores the key remapping setting for the current host. 806 * Sets and stores the key remapping setting for the current host.
778 * 807 *
779 * @param {string} remappings Comma separated list of key remappings. 808 * @param {string} remappings Comma separated list of key remappings.
780 */ 809 */
781 remoting.ClientSession.prototype.setRemapKeys = function(remappings) { 810 remoting.ClientSession.prototype.setRemapKeys = function(remappings) {
782 // Cancel any existing remappings and apply the new ones. 811 // Cancel any existing remappings and apply the new ones.
783 this.applyRemapKeys_(false); 812 this.applyRemapKeys_(false);
784 this.remapKeys_ = remappings; 813 this.remapKeys_ = remappings;
785 this.applyRemapKeys_(true); 814 this.applyRemapKeys_(true);
786 815
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
837 * should be added in this case. 866 * should be added in this case.
838 * @param {boolean} resizeToClient True if window resizes should cause the 867 * @param {boolean} resizeToClient True if window resizes should cause the
839 * host to attempt to resize its desktop to match the client window size; 868 * host to attempt to resize its desktop to match the client window size;
840 * false to disable this behaviour for subsequent window resizes--the 869 * false to disable this behaviour for subsequent window resizes--the
841 * current host desktop size is not restored in this case. 870 * current host desktop size is not restored in this case.
842 * @return {void} Nothing. 871 * @return {void} Nothing.
843 */ 872 */
844 remoting.ClientSession.prototype.setScreenMode = 873 remoting.ClientSession.prototype.setScreenMode =
845 function(shrinkToFit, resizeToClient) { 874 function(shrinkToFit, resizeToClient) {
846 if (resizeToClient && !this.resizeToClient_) { 875 if (resizeToClient && !this.resizeToClient_) {
847 var clientArea = this.getClientArea_(); 876 this.notifyClientResolution_();
848 this.plugin_.notifyClientResolution(clientArea.width,
849 clientArea.height,
850 window.devicePixelRatio);
851 } 877 }
852 878
853 // If enabling shrink, reset bump-scroll offsets. 879 // If enabling shrink, reset bump-scroll offsets.
854 var needsScrollReset = shrinkToFit && !this.shrinkToFit_; 880 var needsScrollReset = shrinkToFit && !this.shrinkToFit_;
855 881
856 this.shrinkToFit_ = shrinkToFit; 882 this.shrinkToFit_ = shrinkToFit;
857 this.resizeToClient_ = resizeToClient; 883 this.resizeToClient_ = resizeToClient;
858 this.updateScrollbarVisibility(); 884 this.updateScrollbarVisibility();
859 885
860 if (this.hostId_ != '') { 886 if (this.hostId_ != '') {
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
1003 * @private 1029 * @private
1004 * @param {number} status The plugin's status. 1030 * @param {number} status The plugin's status.
1005 * @param {number} error The plugin's error state, if any. 1031 * @param {number} error The plugin's error state, if any.
1006 */ 1032 */
1007 remoting.ClientSession.prototype.onConnectionStatusUpdate_ = 1033 remoting.ClientSession.prototype.onConnectionStatusUpdate_ =
1008 function(status, error) { 1034 function(status, error) {
1009 if (status == remoting.ClientSession.State.CONNECTED) { 1035 if (status == remoting.ClientSession.State.CONNECTED) {
1010 this.setFocusHandlers_(); 1036 this.setFocusHandlers_();
1011 this.onDesktopSizeChanged_(); 1037 this.onDesktopSizeChanged_();
1012 if (this.resizeToClient_) { 1038 if (this.resizeToClient_) {
1013 var clientArea = this.getClientArea_(); 1039 this.notifyClientResolution_();
1014 this.plugin_.notifyClientResolution(clientArea.width,
1015 clientArea.height,
1016 window.devicePixelRatio);
1017 } 1040 }
1018 // Activate full-screen related UX. 1041 // Activate full-screen related UX.
1019 remoting.fullscreen.addListener(this.callOnFullScreenChanged_); 1042 remoting.fullscreen.addListener(this.callOnFullScreenChanged_);
1020 this.updateClientSessionUi_(this); 1043 this.updateClientSessionUi_(this);
1021 this.container_.addEventListener('mousemove', 1044 this.container_.addEventListener('mousemove',
1022 this.updateMouseCursorPosition_, 1045 this.updateMouseCursorPosition_,
1023 true); 1046 true);
1024 1047
1025 } else if (status == remoting.ClientSession.State.FAILED) { 1048 } else if (status == remoting.ClientSession.State.FAILED) {
1026 switch (error) { 1049 switch (error) {
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
1099 */ 1122 */
1100 remoting.ClientSession.prototype.onSetCapabilities_ = function(capabilities) { 1123 remoting.ClientSession.prototype.onSetCapabilities_ = function(capabilities) {
1101 if (this.capabilities_ != null) { 1124 if (this.capabilities_ != null) {
1102 console.error('onSetCapabilities_() is called more than once'); 1125 console.error('onSetCapabilities_() is called more than once');
1103 return; 1126 return;
1104 } 1127 }
1105 1128
1106 this.capabilities_ = capabilities; 1129 this.capabilities_ = capabilities;
1107 if (this.hasCapability_( 1130 if (this.hasCapability_(
1108 remoting.ClientSession.Capability.SEND_INITIAL_RESOLUTION)) { 1131 remoting.ClientSession.Capability.SEND_INITIAL_RESOLUTION)) {
1109 var clientArea = this.getClientArea_(); 1132 this.notifyClientResolution_();
1110 this.plugin_.notifyClientResolution(clientArea.width,
1111 clientArea.height,
1112 window.devicePixelRatio);
1113 } 1133 }
1114 if (this.hasCapability_(remoting.ClientSession.Capability.GOOGLE_DRIVE)) { 1134 if (this.hasCapability_(remoting.ClientSession.Capability.GOOGLE_DRIVE)) {
1115 this.sendGoogleDriveAccessToken_(); 1135 this.sendGoogleDriveAccessToken_();
1116 } 1136 }
1117 if (this.hasCapability_( 1137 if (this.hasCapability_(
1118 remoting.ClientSession.Capability.VIDEO_RECORDER)) { 1138 remoting.ClientSession.Capability.VIDEO_RECORDER)) {
1119 this.videoFrameRecorder_ = new remoting.VideoFrameRecorder(this.plugin_); 1139 this.videoFrameRecorder_ = new remoting.VideoFrameRecorder(this.plugin_);
1120 } 1140 }
1121 }; 1141 };
1122 1142
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
1171 // Defer notifying the host of the change until the window stops resizing, to 1191 // Defer notifying the host of the change until the window stops resizing, to
1172 // avoid overloading the control channel with notifications. 1192 // avoid overloading the control channel with notifications.
1173 if (this.resizeToClient_) { 1193 if (this.resizeToClient_) {
1174 var kResizeRateLimitMs = 1000; 1194 var kResizeRateLimitMs = 1000;
1175 if (this.hasCapability_( 1195 if (this.hasCapability_(
1176 remoting.ClientSession.Capability.RATE_LIMIT_RESIZE_REQUESTS)) { 1196 remoting.ClientSession.Capability.RATE_LIMIT_RESIZE_REQUESTS)) {
1177 kResizeRateLimitMs = 250; 1197 kResizeRateLimitMs = 250;
1178 } 1198 }
1179 var clientArea = this.getClientArea_(); 1199 var clientArea = this.getClientArea_();
1180 this.notifyClientResolutionTimer_ = window.setTimeout( 1200 this.notifyClientResolutionTimer_ = window.setTimeout(
1181 this.plugin_.notifyClientResolution.bind(this.plugin_, 1201 this.notifyClientResolution_.bind(this),
1182 clientArea.width,
1183 clientArea.height,
1184 window.devicePixelRatio),
1185 kResizeRateLimitMs); 1202 kResizeRateLimitMs);
1186 } 1203 }
1187 1204
1188 // If bump-scrolling is enabled, adjust the plugin margins to fully utilize 1205 // If bump-scrolling is enabled, adjust the plugin margins to fully utilize
1189 // the new window area. 1206 // the new window area.
1190 this.resetScroll_(); 1207 this.resetScroll_();
1191 1208
1192 this.updateScrollbarVisibility(); 1209 this.updateScrollbarVisibility();
1193 }; 1210 };
1194 1211
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
1282 // We specify the plugin dimensions in Density-Independent Pixels, so to 1299 // We specify the plugin dimensions in Density-Independent Pixels, so to
1283 // render pixel-for-pixel we need to down-scale the host dimensions by the 1300 // render pixel-for-pixel we need to down-scale the host dimensions by the
1284 // devicePixelRatio of the client. To match the host pixel density, we choose 1301 // devicePixelRatio of the client. To match the host pixel density, we choose
1285 // an initial scale factor based on the client devicePixelRatio and host DPI. 1302 // an initial scale factor based on the client devicePixelRatio and host DPI.
1286 1303
1287 // Determine the effective device pixel ratio of the host, based on DPI. 1304 // Determine the effective device pixel ratio of the host, based on DPI.
1288 var hostPixelRatioX = Math.ceil(this.plugin_.getDesktopXDpi() / 96); 1305 var hostPixelRatioX = Math.ceil(this.plugin_.getDesktopXDpi() / 96);
1289 var hostPixelRatioY = Math.ceil(this.plugin_.getDesktopYDpi() / 96); 1306 var hostPixelRatioY = Math.ceil(this.plugin_.getDesktopYDpi() / 96);
1290 var hostPixelRatio = Math.min(hostPixelRatioX, hostPixelRatioY); 1307 var hostPixelRatio = Math.min(hostPixelRatioX, hostPixelRatioY);
1291 1308
1309 // Include the desktopScale in the hostPixelRatio before comparing it with
1310 // the client devicePixelRatio to determine the "natural" scale to use.
1311 hostPixelRatio *= this.desktopScale_;
1312
1292 // Down-scale by the smaller of the client and host ratios. 1313 // Down-scale by the smaller of the client and host ratios.
1293 var scale = 1.0 / Math.min(window.devicePixelRatio, hostPixelRatio); 1314 var scale = 1.0 / Math.min(window.devicePixelRatio, hostPixelRatio);
1294 1315
1295 if (this.shrinkToFit_) { 1316 if (this.shrinkToFit_) {
1296 // Reduce the scale, if necessary, to fit the whole desktop in the window. 1317 // Reduce the scale, if necessary, to fit the whole desktop in the window.
1297 var scaleFitWidth = Math.min(scale, 1.0 * clientArea.width / desktopWidth); 1318 var scaleFitWidth = Math.min(scale, 1.0 * clientArea.width / desktopWidth);
1298 var scaleFitHeight = 1319 var scaleFitHeight =
1299 Math.min(scale, 1.0 * clientArea.height / desktopHeight); 1320 Math.min(scale, 1.0 * clientArea.height / desktopHeight);
1300 scale = Math.min(scaleFitHeight, scaleFitWidth); 1321 scale = Math.min(scaleFitHeight, scaleFitWidth);
1301 1322
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after
1628 * borders used by the latter. 1649 * borders used by the latter.
1629 * @private 1650 * @private
1630 */ 1651 */
1631 remoting.ClientSession.prototype.getClientArea_ = function() { 1652 remoting.ClientSession.prototype.getClientArea_ = function() {
1632 return remoting.windowFrame ? 1653 return remoting.windowFrame ?
1633 remoting.windowFrame.getClientArea() : 1654 remoting.windowFrame.getClientArea() :
1634 { 'width': window.innerWidth, 'height': window.innerHeight }; 1655 { 'width': window.innerWidth, 'height': window.innerHeight };
1635 }; 1656 };
1636 1657
1637 /** 1658 /**
1659 * Notifies the host of the client's current dimensions and DPI.
1660 * Also takes into account per-host scaling factor, if configured.
1661 * @private
1662 */
1663 remoting.ClientSession.prototype.notifyClientResolution_ = function() {
1664 var clientArea = this.getClientArea_();
1665 this.plugin_.notifyClientResolution(clientArea.width * this.desktopScale_,
1666 clientArea.height * this.desktopScale_,
1667 window.devicePixelRatio);
1668 }
1669
1670 /**
1638 * @param {string} url 1671 * @param {string} url
1639 * @param {number} hotspotX 1672 * @param {number} hotspotX
1640 * @param {number} hotspotY 1673 * @param {number} hotspotY
1641 */ 1674 */
1642 remoting.ClientSession.prototype.updateMouseCursorImage_ = 1675 remoting.ClientSession.prototype.updateMouseCursorImage_ =
1643 function(url, hotspotX, hotspotY) { 1676 function(url, hotspotX, hotspotY) {
1644 this.mouseCursorOverlay_.hidden = !url; 1677 this.mouseCursorOverlay_.hidden = !url;
1645 if (url) { 1678 if (url) {
1646 this.mouseCursorOverlay_.style.marginLeft = '-' + hotspotX + 'px'; 1679 this.mouseCursorOverlay_.style.marginLeft = '-' + hotspotX + 'px';
1647 this.mouseCursorOverlay_.style.marginTop = '-' + hotspotY + 'px'; 1680 this.mouseCursorOverlay_.style.marginTop = '-' + hotspotY + 'px';
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
1733 * @param {string} data Contents of the extension message. 1766 * @param {string} data Contents of the extension message.
1734 * @return {boolean} True if the message was recognized, false otherwise. 1767 * @return {boolean} True if the message was recognized, false otherwise.
1735 */ 1768 */
1736 remoting.ClientSession.prototype.handleExtensionMessage = 1769 remoting.ClientSession.prototype.handleExtensionMessage =
1737 function(type, data) { 1770 function(type, data) {
1738 if (this.videoFrameRecorder_) { 1771 if (this.videoFrameRecorder_) {
1739 return this.videoFrameRecorder_.handleMessage(type, data); 1772 return this.videoFrameRecorder_.handleMessage(type, data);
1740 } 1773 }
1741 return false; 1774 return false;
1742 } 1775 }
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