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'; |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 // Bump-scroll test variables. Override to use a fake value for the width | 107 // Bump-scroll test variables. Override to use a fake value for the width |
108 // and height of the client plugin so that bump-scrolling can be tested | 108 // and height of the client plugin so that bump-scrolling can be tested |
109 // without relying on the actual size of the host desktop. | 109 // without relying on the actual size of the host desktop. |
110 /** @type {number} @private */ | 110 /** @type {number} @private */ |
111 this.pluginWidthForBumpScrollTesting_ = 0; | 111 this.pluginWidthForBumpScrollTesting_ = 0; |
112 /** @type {number} @private */ | 112 /** @type {number} @private */ |
113 this.pluginHeightForBumpScrollTesting_ = 0; | 113 this.pluginHeightForBumpScrollTesting_ = 0; |
114 | 114 |
115 /** @type {remoting.VideoFrameRecorder} @private */ | 115 /** @type {remoting.VideoFrameRecorder} @private */ |
116 this.videoFrameRecorder_ = null; | 116 this.videoFrameRecorder_ = null; |
| 117 |
| 118 /** @private {base.Disposables} */ |
| 119 this.eventHooks_ = null; |
117 }; | 120 }; |
118 | 121 |
119 base.extend(remoting.DesktopConnectedView, base.EventSourceImpl); | 122 base.extend(remoting.DesktopConnectedView, base.EventSourceImpl); |
120 | 123 |
121 /** @enum {string} */ | 124 /** @enum {string} */ |
122 remoting.DesktopConnectedView.Events = { | 125 remoting.DesktopConnectedView.Events = { |
123 bumpScrollStarted: 'bumpScrollStarted', | 126 bumpScrollStarted: 'bumpScrollStarted', |
124 bumpScrollStopped: 'bumpScrollStopped' | 127 bumpScrollStopped: 'bumpScrollStopped' |
125 }; | 128 }; |
126 | 129 |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 this.pluginHeightForBumpScrollTesting_ = height; | 200 this.pluginHeightForBumpScrollTesting_ = height; |
198 } | 201 } |
199 | 202 |
200 /** | 203 /** |
201 * Notifies the host of the client's current dimensions and DPI. | 204 * Notifies the host of the client's current dimensions and DPI. |
202 * Also takes into account per-host scaling factor, if configured. | 205 * Also takes into account per-host scaling factor, if configured. |
203 * TODO: private | 206 * TODO: private |
204 */ | 207 */ |
205 remoting.DesktopConnectedView.prototype.notifyClientResolution_ = function() { | 208 remoting.DesktopConnectedView.prototype.notifyClientResolution_ = function() { |
206 var clientArea = this.getClientArea_(); | 209 var clientArea = this.getClientArea_(); |
207 this.plugin_.notifyClientResolution(clientArea.width * this.desktopScale_, | 210 this.plugin_.hostDesktop().resize(clientArea.width * this.desktopScale_, |
208 clientArea.height * this.desktopScale_, | 211 clientArea.height * this.desktopScale_, |
209 window.devicePixelRatio); | 212 window.devicePixelRatio); |
210 }; | 213 }; |
211 | 214 |
212 /** | 215 /** |
213 * Adds <embed> element to the UI container and readies the session object. | 216 * Adds <embed> element to the UI container and readies the session object. |
214 * | 217 * |
215 * @param {function(string, string):boolean} onExtensionMessage The handler for | 218 * @param {function(string, string):boolean} onExtensionMessage The handler for |
216 * protocol extension messages. Returns true if a message is recognized; | 219 * protocol extension messages. Returns true if a message is recognized; |
217 * false otherwise. | 220 * false otherwise. |
218 * @param {Array<string>} requiredCapabilities A list of capabilities | 221 * @param {Array<string>} requiredCapabilities A list of capabilities |
219 * required by this application. | 222 * required by this application. |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
296 this.applyRemapKeys_(true); | 299 this.applyRemapKeys_(true); |
297 } | 300 } |
298 | 301 |
299 // TODO(wez): Only allow mouse lock if the app has the pointerLock permission. | 302 // TODO(wez): Only allow mouse lock if the app has the pointerLock permission. |
300 // Enable automatic mouse-lock. | 303 // Enable automatic mouse-lock. |
301 if (remoting.enableMouseLock && | 304 if (remoting.enableMouseLock && |
302 this.plugin_.hasFeature(remoting.ClientPlugin.Feature.ALLOW_MOUSE_LOCK)) { | 305 this.plugin_.hasFeature(remoting.ClientPlugin.Feature.ALLOW_MOUSE_LOCK)) { |
303 this.plugin_.allowMouseLock(); | 306 this.plugin_.allowMouseLock(); |
304 } | 307 } |
305 | 308 |
306 this.plugin_.setDesktopShapeUpdateHandler( | 309 base.dispose(this.eventHooks_); |
307 this.onDesktopShapeChanged_.bind(this)); | 310 var hostDesktop = this.plugin_.hostDesktop(); |
308 this.plugin_.setDesktopSizeUpdateHandler( | 311 this.eventHooks_ = new base.Disposables( |
309 this.onDesktopSizeChanged_.bind(this)); | 312 new base.EventHook( |
| 313 hostDesktop, remoting.HostDesktop.Events.sizeChanged, |
| 314 this.onDesktopSizeChanged_.bind(this)), |
| 315 new base.EventHook( |
| 316 hostDesktop, remoting.HostDesktop.Events.shapeChanged, |
| 317 this.onDesktopShapeChanged_.bind(this))); |
| 318 |
310 this.plugin_.setMouseCursorHandler(this.updateMouseCursorImage_.bind(this)); | 319 this.plugin_.setMouseCursorHandler(this.updateMouseCursorImage_.bind(this)); |
311 | 320 |
312 this.onInitialized_(remoting.Error.NONE, this.plugin_); | 321 this.onInitialized_(remoting.Error.NONE, this.plugin_); |
313 }; | 322 }; |
314 | 323 |
315 /** | 324 /** |
316 * This is a callback that gets called when the plugin notifies us of a change | 325 * This is a callback that gets called when the plugin notifies us of a change |
317 * in the size of the remote desktop. | 326 * in the size of the remote desktop. |
318 * | 327 * |
319 * @return {void} Nothing. | 328 * @return {void} Nothing. |
320 * @private | 329 * @private |
321 */ | 330 */ |
322 remoting.DesktopConnectedView.prototype.onDesktopSizeChanged_ = function() { | 331 remoting.DesktopConnectedView.prototype.onDesktopSizeChanged_ = function() { |
| 332 var desktop = this.plugin_.hostDesktop().getDimensions(); |
323 console.log('desktop size changed: ' + | 333 console.log('desktop size changed: ' + |
324 this.plugin_.getDesktopWidth() + 'x' + | 334 desktop.width + 'x' + |
325 this.plugin_.getDesktopHeight() +' @ ' + | 335 desktop.height +' @ ' + |
326 this.plugin_.getDesktopXDpi() + 'x' + | 336 desktop.xDpi + 'x' + |
327 this.plugin_.getDesktopYDpi() + ' DPI'); | 337 desktop.yDpi + ' DPI'); |
328 this.updateDimensions(); | 338 this.updateDimensions(); |
329 this.updateScrollbarVisibility(); | 339 this.updateScrollbarVisibility(); |
330 }; | 340 }; |
331 | 341 |
332 /** | 342 /** |
333 * Sets the non-click-through area of the client in response to notifications | 343 * Sets the non-click-through area of the client in response to notifications |
334 * from the plugin of desktop shape changes. | 344 * from the plugin of desktop shape changes. |
335 * | 345 * |
336 * @param {Array<Array<number>>} rects List of rectangles comprising the | 346 * @param {Array<Array<number>>} rects List of rectangles comprising the |
337 * desktop shape. | 347 * desktop shape. |
(...skipping 25 matching lines...) Expand all Loading... |
363 this.updateDimensions(); | 373 this.updateDimensions(); |
364 | 374 |
365 if (this.notifyClientResolutionTimer_) { | 375 if (this.notifyClientResolutionTimer_) { |
366 window.clearTimeout(this.notifyClientResolutionTimer_); | 376 window.clearTimeout(this.notifyClientResolutionTimer_); |
367 this.notifyClientResolutionTimer_ = null; | 377 this.notifyClientResolutionTimer_ = null; |
368 } | 378 } |
369 | 379 |
370 // Defer notifying the host of the change until the window stops resizing, to | 380 // Defer notifying the host of the change until the window stops resizing, to |
371 // avoid overloading the control channel with notifications. | 381 // avoid overloading the control channel with notifications. |
372 if (this.resizeToClient_) { | 382 if (this.resizeToClient_) { |
373 var kResizeRateLimitMs = 1000; | 383 var kResizeRateLimitMs = 250; |
374 if (this.session_.hasCapability( | |
375 remoting.ClientSession.Capability.RATE_LIMIT_RESIZE_REQUESTS)) { | |
376 kResizeRateLimitMs = 250; | |
377 } | |
378 var clientArea = this.getClientArea_(); | 384 var clientArea = this.getClientArea_(); |
379 this.notifyClientResolutionTimer_ = window.setTimeout( | 385 this.notifyClientResolutionTimer_ = window.setTimeout( |
380 this.notifyClientResolution_.bind(this), | 386 this.notifyClientResolution_.bind(this), |
381 kResizeRateLimitMs); | 387 kResizeRateLimitMs); |
382 } | 388 } |
383 | 389 |
384 // If bump-scrolling is enabled, adjust the plugin margins to fully utilize | 390 // If bump-scrolling is enabled, adjust the plugin margins to fully utilize |
385 // the new window area. | 391 // the new window area. |
386 this.resetScroll_(); | 392 this.resetScroll_(); |
387 | 393 |
(...skipping 16 matching lines...) Expand all Loading... |
404 | 410 |
405 /** | 411 /** |
406 * Deletes the <embed> element from the container, without sending a | 412 * Deletes the <embed> element from the container, without sending a |
407 * session_terminate request. This is to be called when the session was | 413 * session_terminate request. This is to be called when the session was |
408 * disconnected by the Host. | 414 * disconnected by the Host. |
409 * | 415 * |
410 * @return {void} Nothing. | 416 * @return {void} Nothing. |
411 */ | 417 */ |
412 remoting.DesktopConnectedView.prototype.removePlugin = function() { | 418 remoting.DesktopConnectedView.prototype.removePlugin = function() { |
413 if (this.plugin_) { | 419 if (this.plugin_) { |
| 420 base.dispose(this.eventHooks_); |
| 421 this.eventHooks_ = null; |
414 this.plugin_.element().removeEventListener( | 422 this.plugin_.element().removeEventListener( |
415 'focus', this.callPluginGotFocus_, false); | 423 'focus', this.callPluginGotFocus_, false); |
416 this.plugin_.element().removeEventListener( | 424 this.plugin_.element().removeEventListener( |
417 'blur', this.callPluginLostFocus_, false); | 425 'blur', this.callPluginLostFocus_, false); |
418 this.plugin_.dispose(); | 426 this.plugin_.dispose(); |
419 this.plugin_ = null; | 427 this.plugin_ = null; |
420 } | 428 } |
421 | 429 |
422 this.updateClientSessionUi_(null); | 430 this.updateClientSessionUi_(null); |
423 }; | 431 }; |
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
737 return stopX.stop && stopY.stop; | 745 return stopX.stop && stopY.stop; |
738 }; | 746 }; |
739 | 747 |
740 /** | 748 /** |
741 * Refreshes the plugin's dimensions, taking into account the sizes of the | 749 * Refreshes the plugin's dimensions, taking into account the sizes of the |
742 * remote desktop and client window, and the current scale-to-fit setting. | 750 * remote desktop and client window, and the current scale-to-fit setting. |
743 * | 751 * |
744 * @return {void} Nothing. | 752 * @return {void} Nothing. |
745 */ | 753 */ |
746 remoting.DesktopConnectedView.prototype.updateDimensions = function() { | 754 remoting.DesktopConnectedView.prototype.updateDimensions = function() { |
747 if (this.plugin_.getDesktopWidth() == 0 || | 755 var desktopSize = this.plugin_.hostDesktop().getDimensions(); |
748 this.plugin_.getDesktopHeight() == 0) { | 756 |
| 757 if (desktopSize.width === 0 || |
| 758 desktopSize.height === 0) { |
749 return; | 759 return; |
750 } | 760 } |
751 | 761 |
752 var desktopSize = { width: this.plugin_.getDesktopWidth(), | 762 var desktopDpi = { x: desktopSize.xDpi, |
753 height: this.plugin_.getDesktopHeight() }; | 763 y: desktopSize.yDpi }; |
754 var desktopDpi = { x: this.plugin_.getDesktopXDpi(), | |
755 y: this.plugin_.getDesktopYDpi() }; | |
756 var newSize = remoting.DesktopConnectedView.choosePluginSize( | 764 var newSize = remoting.DesktopConnectedView.choosePluginSize( |
757 this.getClientArea_(), window.devicePixelRatio, | 765 this.getClientArea_(), window.devicePixelRatio, |
758 desktopSize, desktopDpi, this.desktopScale_, | 766 desktopSize, desktopDpi, this.desktopScale_, |
759 remoting.fullscreen.isActive(), this.shrinkToFit_); | 767 remoting.fullscreen.isActive(), this.shrinkToFit_); |
760 | 768 |
761 // Resize the plugin if necessary. | 769 // Resize the plugin if necessary. |
762 console.log('plugin dimensions:' + newSize.width + 'x' + newSize.height); | 770 console.log('plugin dimensions:' + newSize.width + 'x' + newSize.height); |
763 this.plugin_.element().style.width = newSize.width + 'px'; | 771 this.plugin_.element().style.width = newSize.width + 'px'; |
764 this.plugin_.element().style.height = newSize.height + 'px'; | 772 this.plugin_.element().style.height = newSize.height + 'px'; |
765 | 773 |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
913 if (!scroller) { | 921 if (!scroller) { |
914 return; | 922 return; |
915 } | 923 } |
916 | 924 |
917 var needsVerticalScroll = false; | 925 var needsVerticalScroll = false; |
918 var needsHorizontalScroll = false; | 926 var needsHorizontalScroll = false; |
919 if (!this.shrinkToFit_) { | 927 if (!this.shrinkToFit_) { |
920 // Determine whether or not horizontal or vertical scrollbars are | 928 // Determine whether or not horizontal or vertical scrollbars are |
921 // required, taking into account their width. | 929 // required, taking into account their width. |
922 var clientArea = this.getClientArea_(); | 930 var clientArea = this.getClientArea_(); |
923 needsVerticalScroll = clientArea.height < this.plugin_.getDesktopHeight(); | 931 var desktopSize = this.plugin_.hostDesktop().getDimensions(); |
924 needsHorizontalScroll = clientArea.width < this.plugin_.getDesktopWidth(); | 932 needsVerticalScroll = clientArea.height < desktopSize.height; |
| 933 needsHorizontalScroll = clientArea.width < desktopSize.width; |
925 var kScrollBarWidth = 16; | 934 var kScrollBarWidth = 16; |
926 if (needsHorizontalScroll && !needsVerticalScroll) { | 935 if (needsHorizontalScroll && !needsVerticalScroll) { |
927 needsVerticalScroll = | 936 needsVerticalScroll = |
928 clientArea.height - kScrollBarWidth < this.plugin_.getDesktopHeight(); | 937 clientArea.height - kScrollBarWidth < desktopSize.height; |
929 } else if (!needsHorizontalScroll && needsVerticalScroll) { | 938 } else if (!needsHorizontalScroll && needsVerticalScroll) { |
930 needsHorizontalScroll = | 939 needsHorizontalScroll = |
931 clientArea.width - kScrollBarWidth < this.plugin_.getDesktopWidth(); | 940 clientArea.width - kScrollBarWidth < desktopSize.width; |
932 } | 941 } |
933 } | 942 } |
934 | 943 |
935 if (needsHorizontalScroll) { | 944 if (needsHorizontalScroll) { |
936 scroller.classList.remove('no-horizontal-scroll'); | 945 scroller.classList.remove('no-horizontal-scroll'); |
937 } else { | 946 } else { |
938 scroller.classList.add('no-horizontal-scroll'); | 947 scroller.classList.add('no-horizontal-scroll'); |
939 } | 948 } |
940 if (needsVerticalScroll) { | 949 if (needsVerticalScroll) { |
941 scroller.classList.remove('no-vertical-scroll'); | 950 scroller.classList.remove('no-vertical-scroll'); |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1098 * @param {Object} message The parsed extension message data. | 1107 * @param {Object} message The parsed extension message data. |
1099 * @return {boolean} True if the message was recognized, false otherwise. | 1108 * @return {boolean} True if the message was recognized, false otherwise. |
1100 */ | 1109 */ |
1101 remoting.DesktopConnectedView.prototype.handleExtensionMessage = | 1110 remoting.DesktopConnectedView.prototype.handleExtensionMessage = |
1102 function(type, message) { | 1111 function(type, message) { |
1103 if (this.videoFrameRecorder_) { | 1112 if (this.videoFrameRecorder_) { |
1104 return this.videoFrameRecorder_.handleMessage(type, message); | 1113 return this.videoFrameRecorder_.handleMessage(type, message); |
1105 } | 1114 } |
1106 return false; | 1115 return false; |
1107 }; | 1116 }; |
OLD | NEW |