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