Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 /** | |
| 6 * @fileoverview | |
| 7 * Provides an interface to manage the Host Desktop of a remoting session. | |
| 8 */ | |
| 9 | |
| 10 var remoting = remoting || {}; | |
| 11 remoting.ClientPlugin = remoting.ClientPlugin || {}; | |
| 12 | |
| 13 (function() { | |
| 14 | |
| 15 'use strict'; | |
| 16 | |
| 17 /** | |
| 18 * @param {remoting.ClientPluginImpl} plugin | |
| 19 * @param {function(Object):void} postMessageCallback Callback to post a message | |
| 20 * to the Client Plugin. | |
| 21 * | |
| 22 * @implements {remoting.HostDesktop} | |
| 23 * @extends {base.EventSourceImpl} | |
| 24 * @constructor | |
| 25 */ | |
| 26 remoting.ClientPlugin.HostDesktopImpl = function(plugin, postMessageCallback) { | |
|
Jamie
2015/02/18 23:06:19
The fact that you need an explicit reference to th
kelvinp
2015/02/19 20:58:15
As discussed, the intent of this class is to separ
| |
| 27 /** @private */ | |
| 28 this.plugin_ = plugin; | |
| 29 /** @private */ | |
| 30 this.width_ = 0; | |
| 31 /** @private */ | |
| 32 this.height_ = 0; | |
| 33 /** @private */ | |
| 34 this.xDpi_ = 96; | |
| 35 /** @private */ | |
| 36 this.yDpi_ = 96; | |
| 37 /** @private */ | |
| 38 this.hasResizeRateLimit_ = false; | |
| 39 /** @private */ | |
| 40 this.postMessageCallback_ = postMessageCallback; | |
| 41 | |
| 42 this.defineEvents(Object.keys(remoting.HostDesktop.Events)); | |
|
Jamie
2015/02/18 23:06:19
s/Object.keys/base.values/
kelvinp
2015/02/19 20:58:15
Done.
| |
| 43 }; | |
| 44 base.extend(remoting.ClientPlugin.HostDesktopImpl, base.EventSourceImpl); | |
| 45 | |
| 46 /** @return {boolean} */ | |
| 47 remoting.ClientPlugin.HostDesktopImpl.prototype.hasResizeRateLimit = | |
| 48 function() { | |
| 49 return this.hasResizeRateLimit_; | |
| 50 }; | |
| 51 | |
| 52 /** @return {boolean} Whether the host supports desktop resizing. */ | |
| 53 remoting.ClientPlugin.HostDesktopImpl.prototype.isResizable = function() { | |
| 54 return this.plugin_.hasFeature( | |
| 55 remoting.ClientPlugin.Feature.NOTIFY_CLIENT_RESOLUTION); | |
| 56 }; | |
| 57 | |
| 58 /** @return {{width:number, height:number, xDpi:number, yDpi:number}} */ | |
| 59 remoting.ClientPlugin.HostDesktopImpl.prototype.getDimensions = function() { | |
| 60 return { | |
| 61 width: this.width_, | |
| 62 height: this.height_, | |
| 63 xDpi: this.xDpi_, | |
| 64 yDpi: this.yDpi_ | |
| 65 }; | |
| 66 }; | |
| 67 | |
| 68 /** | |
| 69 * @param {number} width | |
| 70 * @param {number} height | |
| 71 * @param {number} device_scale | |
|
Jamie
2015/02/18 23:06:19
The API declares this parameter as |dpi|, and it r
kelvinp
2015/02/19 20:58:15
Done.
| |
| 72 */ | |
| 73 remoting.ClientPlugin.HostDesktopImpl.prototype.resize = function( | |
| 74 width, height, device_scale) { | |
| 75 if (this.isResizable()) { | |
| 76 var dpi = Math.floor(device_scale * 96); | |
| 77 this.postMessageCallback_({ | |
| 78 method: 'notifyClientResolution', | |
| 79 data: { | |
| 80 width: Math.floor(width * device_scale), | |
| 81 height: Math.floor(height * device_scale), | |
| 82 x_dpi: dpi, | |
| 83 y_dpi: dpi | |
| 84 } | |
| 85 }); | |
| 86 } | |
| 87 }; | |
| 88 | |
| 89 /** | |
| 90 * @param {Array<string>} capabilities | |
| 91 */ | |
| 92 remoting.ClientPlugin.HostDesktopImpl.prototype.onSetCapabilities = function( | |
|
Jamie
2015/02/18 23:06:19
I think this method is only used to set hasResizeR
kelvinp
2015/02/19 20:58:15
Done.
| |
| 93 capabilities) { | |
| 94 this.hasResizeRateLimit_ = this.plugin_.hasCapability( | |
| 95 remoting.ClientSession.Capability.RATE_LIMIT_RESIZE_REQUESTS); | |
| 96 }; | |
| 97 | |
| 98 /** | |
| 99 * This function is called by |this.plugin_| when the size of the host | |
| 100 * desktop is changed. | |
| 101 * | |
| 102 * @param {remoting.ClientPluginMessage} message | |
| 103 */ | |
| 104 remoting.ClientPlugin.HostDesktopImpl.prototype.onSizeUpdated = function( | |
|
Jamie
2015/02/18 23:06:19
This method is not declared on the interface and s
kelvinp
2015/02/19 20:58:15
This class is under the clientPlugin namespace and
| |
| 105 message) { | |
| 106 this.width_ = getNumberAttr(message.data, 'width'); | |
| 107 this.height_ = getNumberAttr(message.data, 'height'); | |
| 108 this.xDpi_ = getNumberAttr(message.data, 'x_dpi', 96); | |
| 109 this.yDpi_ = getNumberAttr(message.data, 'y_dpi', 96); | |
| 110 this.raiseEvent(remoting.HostDesktop.Events.sizeChanged); | |
| 111 }; | |
| 112 | |
| 113 /** | |
| 114 * This function is called by |this.plugin_| when the shape of the host | |
| 115 * desktop is changed. | |
| 116 * | |
| 117 * @param {remoting.ClientPluginMessage} message | |
| 118 * @return {Array<{left:number, top:number, width:number, height:number}>} | |
| 119 * rectangles of the desktop shape. | |
| 120 */ | |
| 121 remoting.ClientPlugin.HostDesktopImpl.prototype.onShapeUpdated = | |
| 122 function(message) { | |
| 123 var shapes = getArrayAttr(message.data, 'rects'); | |
| 124 var rects = shapes.map( | |
| 125 /** @param {Array.<number>} shape */ | |
| 126 function(shape) { | |
| 127 if (!Array.isArray(shape) || shape.length != 4) { | |
| 128 throw 'Received invalid onDesktopShape message'; | |
| 129 } | |
| 130 var rect = {}; | |
|
Jamie
2015/02/18 23:06:19
Optional: Elsewhere, we have code to force left, r
kelvinp
2015/02/19 20:58:15
Done.
| |
| 131 rect.left = shape[0]; | |
| 132 rect.top = shape[1]; | |
| 133 rect.width = shape[2]; | |
| 134 rect.height = shape[3]; | |
| 135 return rect; | |
| 136 }); | |
| 137 | |
| 138 this.raiseEvent(remoting.HostDesktop.Events.shapeChanged, rects); | |
| 139 return rects; | |
| 140 }; | |
| 141 | |
| 142 }()); | |
| OLD | NEW |