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

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: Fix typo 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.desktopScale_ = 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_SCALE = 'desktopScale';
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_SCALE in options &&
509 typeof(options[remoting.ClientSession.KEY_DESKTOP_SCALE]) ==
510 'number') {
511 this.desktopScale_ = /** @type {number} */
512 options[remoting.ClientSession.KEY_DESKTOP_SCALE];
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 scale factor to apply to host sizing requests.
785 * The desktopScale applies to the dimensions reported to the host, not
786 * to the client DPI reported to it.
787 *
788 * @param {number} desktopScale Scale factor to apply.
789 */
790 remoting.ClientSession.prototype.setDesktopScale =
791 function(desktopScale) {
Jamie 2014/12/15 23:18:55 Nit: Looks like this will fit on the previous line
792 this.desktopScale_ = desktopScale;
793
794 // onResize() will update the plugin size and scrollbars for the new
795 // scaled plugin dimensions, and send a client resolution notification.
796 this.onResize();
797
798 // Save the new desktop scale setting.
799 var options = {};
800 options[remoting.ClientSession.KEY_DESKTOP_SCALE] = this.desktopScale_;
801 remoting.HostSettings.save(this.hostId_, options);
802 }
803
804 /**
775 * Sets and stores the key remapping setting for the current host. 805 * Sets and stores the key remapping setting for the current host.
776 * 806 *
777 * @param {string} remappings Comma separated list of key remappings. 807 * @param {string} remappings Comma separated list of key remappings.
778 */ 808 */
779 remoting.ClientSession.prototype.setRemapKeys = function(remappings) { 809 remoting.ClientSession.prototype.setRemapKeys = function(remappings) {
780 // Cancel any existing remappings and apply the new ones. 810 // Cancel any existing remappings and apply the new ones.
781 this.applyRemapKeys_(false); 811 this.applyRemapKeys_(false);
782 this.remapKeys_ = remappings; 812 this.remapKeys_ = remappings;
783 this.applyRemapKeys_(true); 813 this.applyRemapKeys_(true);
784 814
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
835 * should be added in this case. 865 * should be added in this case.
836 * @param {boolean} resizeToClient True if window resizes should cause the 866 * @param {boolean} resizeToClient True if window resizes should cause the
837 * host to attempt to resize its desktop to match the client window size; 867 * host to attempt to resize its desktop to match the client window size;
838 * false to disable this behaviour for subsequent window resizes--the 868 * false to disable this behaviour for subsequent window resizes--the
839 * current host desktop size is not restored in this case. 869 * current host desktop size is not restored in this case.
840 * @return {void} Nothing. 870 * @return {void} Nothing.
841 */ 871 */
842 remoting.ClientSession.prototype.setScreenMode = 872 remoting.ClientSession.prototype.setScreenMode =
843 function(shrinkToFit, resizeToClient) { 873 function(shrinkToFit, resizeToClient) {
844 if (resizeToClient && !this.resizeToClient_) { 874 if (resizeToClient && !this.resizeToClient_) {
845 var clientArea = this.getClientArea_(); 875 this.notifyClientResolution_();
846 this.plugin_.notifyClientResolution(clientArea.width,
847 clientArea.height,
848 window.devicePixelRatio);
849 } 876 }
850 877
851 // If enabling shrink, reset bump-scroll offsets. 878 // If enabling shrink, reset bump-scroll offsets.
852 var needsScrollReset = shrinkToFit && !this.shrinkToFit_; 879 var needsScrollReset = shrinkToFit && !this.shrinkToFit_;
853 880
854 this.shrinkToFit_ = shrinkToFit; 881 this.shrinkToFit_ = shrinkToFit;
855 this.resizeToClient_ = resizeToClient; 882 this.resizeToClient_ = resizeToClient;
856 this.updateScrollbarVisibility(); 883 this.updateScrollbarVisibility();
857 884
858 if (this.hostId_ != '') { 885 if (this.hostId_ != '') {
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
1001 * @private 1028 * @private
1002 * @param {number} status The plugin's status. 1029 * @param {number} status The plugin's status.
1003 * @param {number} error The plugin's error state, if any. 1030 * @param {number} error The plugin's error state, if any.
1004 */ 1031 */
1005 remoting.ClientSession.prototype.onConnectionStatusUpdate_ = 1032 remoting.ClientSession.prototype.onConnectionStatusUpdate_ =
1006 function(status, error) { 1033 function(status, error) {
1007 if (status == remoting.ClientSession.State.CONNECTED) { 1034 if (status == remoting.ClientSession.State.CONNECTED) {
1008 this.setFocusHandlers_(); 1035 this.setFocusHandlers_();
1009 this.onDesktopSizeChanged_(); 1036 this.onDesktopSizeChanged_();
1010 if (this.resizeToClient_) { 1037 if (this.resizeToClient_) {
1011 var clientArea = this.getClientArea_(); 1038 this.notifyClientResolution_();
1012 this.plugin_.notifyClientResolution(clientArea.width,
1013 clientArea.height,
1014 window.devicePixelRatio);
1015 } 1039 }
1016 // Activate full-screen related UX. 1040 // Activate full-screen related UX.
1017 remoting.fullscreen.addListener(this.callOnFullScreenChanged_); 1041 remoting.fullscreen.addListener(this.callOnFullScreenChanged_);
1018 this.updateClientSessionUi_(this); 1042 this.updateClientSessionUi_(this);
1019 this.container_.addEventListener('mousemove', 1043 this.container_.addEventListener('mousemove',
1020 this.updateMouseCursorPosition_, 1044 this.updateMouseCursorPosition_,
1021 true); 1045 true);
1022 1046
1023 } else if (status == remoting.ClientSession.State.FAILED) { 1047 } else if (status == remoting.ClientSession.State.FAILED) {
1024 switch (error) { 1048 switch (error) {
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
1097 */ 1121 */
1098 remoting.ClientSession.prototype.onSetCapabilities_ = function(capabilities) { 1122 remoting.ClientSession.prototype.onSetCapabilities_ = function(capabilities) {
1099 if (this.capabilities_ != null) { 1123 if (this.capabilities_ != null) {
1100 console.error('onSetCapabilities_() is called more than once'); 1124 console.error('onSetCapabilities_() is called more than once');
1101 return; 1125 return;
1102 } 1126 }
1103 1127
1104 this.capabilities_ = capabilities; 1128 this.capabilities_ = capabilities;
1105 if (this.hasCapability_( 1129 if (this.hasCapability_(
1106 remoting.ClientSession.Capability.SEND_INITIAL_RESOLUTION)) { 1130 remoting.ClientSession.Capability.SEND_INITIAL_RESOLUTION)) {
1107 var clientArea = this.getClientArea_(); 1131 this.notifyClientResolution_();
1108 this.plugin_.notifyClientResolution(clientArea.width,
1109 clientArea.height,
1110 window.devicePixelRatio);
1111 } 1132 }
1112 if (this.hasCapability_(remoting.ClientSession.Capability.GOOGLE_DRIVE)) { 1133 if (this.hasCapability_(remoting.ClientSession.Capability.GOOGLE_DRIVE)) {
1113 this.sendGoogleDriveAccessToken_(); 1134 this.sendGoogleDriveAccessToken_();
1114 } 1135 }
1115 if (this.hasCapability_( 1136 if (this.hasCapability_(
1116 remoting.ClientSession.Capability.VIDEO_RECORDER)) { 1137 remoting.ClientSession.Capability.VIDEO_RECORDER)) {
1117 this.videoFrameRecorder_ = new remoting.VideoFrameRecorder(this.plugin_); 1138 this.videoFrameRecorder_ = new remoting.VideoFrameRecorder(this.plugin_);
1118 } 1139 }
1119 }; 1140 };
1120 1141
(...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 1190 // Defer notifying the host of the change until the window stops resizing, to
1170 // avoid overloading the control channel with notifications. 1191 // avoid overloading the control channel with notifications.
1171 if (this.resizeToClient_) { 1192 if (this.resizeToClient_) {
1172 var kResizeRateLimitMs = 1000; 1193 var kResizeRateLimitMs = 1000;
1173 if (this.hasCapability_( 1194 if (this.hasCapability_(
1174 remoting.ClientSession.Capability.RATE_LIMIT_RESIZE_REQUESTS)) { 1195 remoting.ClientSession.Capability.RATE_LIMIT_RESIZE_REQUESTS)) {
1175 kResizeRateLimitMs = 250; 1196 kResizeRateLimitMs = 250;
1176 } 1197 }
1177 var clientArea = this.getClientArea_(); 1198 var clientArea = this.getClientArea_();
1178 this.notifyClientResolutionTimer_ = window.setTimeout( 1199 this.notifyClientResolutionTimer_ = window.setTimeout(
1179 this.plugin_.notifyClientResolution.bind(this.plugin_, 1200 this.notifyClientResolution_.bind(this),
1180 clientArea.width,
1181 clientArea.height,
1182 window.devicePixelRatio),
1183 kResizeRateLimitMs); 1201 kResizeRateLimitMs);
1184 } 1202 }
1185 1203
1186 // If bump-scrolling is enabled, adjust the plugin margins to fully utilize 1204 // If bump-scrolling is enabled, adjust the plugin margins to fully utilize
1187 // the new window area. 1205 // the new window area.
1188 this.resetScroll_(); 1206 this.resetScroll_();
1189 1207
1190 this.updateScrollbarVisibility(); 1208 this.updateScrollbarVisibility();
1191 }; 1209 };
1192 1210
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
1280 // We specify the plugin dimensions in Density-Independent Pixels, so to 1298 // We specify the plugin dimensions in Density-Independent Pixels, so to
1281 // render pixel-for-pixel we need to down-scale the host dimensions by the 1299 // render pixel-for-pixel we need to down-scale the host dimensions by the
1282 // devicePixelRatio of the client. To match the host pixel density, we choose 1300 // devicePixelRatio of the client. To match the host pixel density, we choose
1283 // an initial scale factor based on the client devicePixelRatio and host DPI. 1301 // an initial scale factor based on the client devicePixelRatio and host DPI.
1284 1302
1285 // Determine the effective device pixel ratio of the host, based on DPI. 1303 // Determine the effective device pixel ratio of the host, based on DPI.
1286 var hostPixelRatioX = Math.ceil(this.plugin_.getDesktopXDpi() / 96); 1304 var hostPixelRatioX = Math.ceil(this.plugin_.getDesktopXDpi() / 96);
1287 var hostPixelRatioY = Math.ceil(this.plugin_.getDesktopYDpi() / 96); 1305 var hostPixelRatioY = Math.ceil(this.plugin_.getDesktopYDpi() / 96);
1288 var hostPixelRatio = Math.min(hostPixelRatioX, hostPixelRatioY); 1306 var hostPixelRatio = Math.min(hostPixelRatioX, hostPixelRatioY);
1289 1307
1308 // Include the desktopScale in the hostPixelRatio before comparing it with
1309 // the client devicePixelRatio to determine the "natural" scale to use.
1310 hostPixelRatio *= this.desktopScale_;
1311
1290 // Down-scale by the smaller of the client and host ratios. 1312 // Down-scale by the smaller of the client and host ratios.
1291 var scale = 1.0 / Math.min(window.devicePixelRatio, hostPixelRatio); 1313 var scale = 1.0 / Math.min(window.devicePixelRatio, hostPixelRatio);
1292 1314
1293 if (this.shrinkToFit_) { 1315 if (this.shrinkToFit_) {
1294 // Reduce the scale, if necessary, to fit the whole desktop in the window. 1316 // Reduce the scale, if necessary, to fit the whole desktop in the window.
1295 var scaleFitWidth = Math.min(scale, 1.0 * clientArea.width / desktopWidth); 1317 var scaleFitWidth = Math.min(scale, 1.0 * clientArea.width / desktopWidth);
1296 var scaleFitHeight = 1318 var scaleFitHeight =
1297 Math.min(scale, 1.0 * clientArea.height / desktopHeight); 1319 Math.min(scale, 1.0 * clientArea.height / desktopHeight);
1298 scale = Math.min(scaleFitHeight, scaleFitWidth); 1320 scale = Math.min(scaleFitHeight, scaleFitWidth);
1299 1321
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after
1626 * borders used by the latter. 1648 * borders used by the latter.
1627 * @private 1649 * @private
1628 */ 1650 */
1629 remoting.ClientSession.prototype.getClientArea_ = function() { 1651 remoting.ClientSession.prototype.getClientArea_ = function() {
1630 return remoting.windowFrame ? 1652 return remoting.windowFrame ?
1631 remoting.windowFrame.getClientArea() : 1653 remoting.windowFrame.getClientArea() :
1632 { 'width': window.innerWidth, 'height': window.innerHeight }; 1654 { 'width': window.innerWidth, 'height': window.innerHeight };
1633 }; 1655 };
1634 1656
1635 /** 1657 /**
1658 * Notifies the host of the client's current dimensions and DPI.
1659 * Also takes into account per-host scaling factor, if configured.
1660 * @private
1661 */
1662 remoting.ClientSession.prototype.notifyClientResolution_ = function() {
1663 var clientArea = this.getClientArea_();
1664 this.plugin_.notifyClientResolution(clientArea.width * this.desktopScale_,
1665 clientArea.height * this.desktopScale_,
1666 window.devicePixelRatio);
1667 }
1668
1669 /**
1636 * @param {string} url 1670 * @param {string} url
1637 * @param {number} hotspotX 1671 * @param {number} hotspotX
1638 * @param {number} hotspotY 1672 * @param {number} hotspotY
1639 */ 1673 */
1640 remoting.ClientSession.prototype.updateMouseCursorImage_ = 1674 remoting.ClientSession.prototype.updateMouseCursorImage_ =
1641 function(url, hotspotX, hotspotY) { 1675 function(url, hotspotX, hotspotY) {
1642 this.mouseCursorOverlay_.hidden = !url; 1676 this.mouseCursorOverlay_.hidden = !url;
1643 if (url) { 1677 if (url) {
1644 this.mouseCursorOverlay_.style.marginLeft = '-' + hotspotX + 'px'; 1678 this.mouseCursorOverlay_.style.marginLeft = '-' + hotspotX + 'px';
1645 this.mouseCursorOverlay_.style.marginTop = '-' + hotspotY + 'px'; 1679 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. 1765 * @param {string} data Contents of the extension message.
1732 * @return {boolean} True if the message was recognized, false otherwise. 1766 * @return {boolean} True if the message was recognized, false otherwise.
1733 */ 1767 */
1734 remoting.ClientSession.prototype.handleExtensionMessage = 1768 remoting.ClientSession.prototype.handleExtensionMessage =
1735 function(type, data) { 1769 function(type, data) {
1736 if (this.videoFrameRecorder_) { 1770 if (this.videoFrameRecorder_) {
1737 return this.videoFrameRecorder_.handleMessage(type, data); 1771 return this.videoFrameRecorder_.handleMessage(type, data);
1738 } 1772 }
1739 return false; 1773 return false;
1740 } 1774 }
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