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.
7 * Provides an interface to manage the Host Desktop of a remoting session.
10 var remoting
= remoting
|| {};
11 remoting
.ClientPlugin
= remoting
.ClientPlugin
|| {};
18 * @param {remoting.ClientPlugin} plugin
19 * @param {function(Object):void} postMessageCallback Callback to post a message
20 * to the Client Plugin.
22 * @implements {remoting.HostDesktop}
23 * @extends {base.EventSourceImpl}
26 remoting
.ClientPlugin
.HostDesktopImpl = function(plugin
, postMessageCallback
) {
27 base
.inherits(this, base
.EventSourceImpl
);
29 this.plugin_
= plugin
;
39 this.postMessageCallback_
= postMessageCallback
;
41 this.defineEvents(base
.values(remoting
.HostDesktop
.Events
));
44 /** @return {{width:number, height:number, xDpi:number, yDpi:number}} */
45 remoting
.ClientPlugin
.HostDesktopImpl
.prototype.getDimensions = function() {
55 * @param {number} width
56 * @param {number} height
57 * @param {number} deviceScale
59 remoting
.ClientPlugin
.HostDesktopImpl
.prototype.resize = function(
60 width
, height
, deviceScale
) {
61 var dpi
= Math
.floor(deviceScale
* 96);
62 this.postMessageCallback_({
63 method
: 'notifyClientResolution',
65 width
: Math
.floor(width
* deviceScale
),
66 height
: Math
.floor(height
* deviceScale
),
74 * This function is called by |this.plugin_| when the size of the host
77 * @param {remoting.ClientPluginMessage} message
79 remoting
.ClientPlugin
.HostDesktopImpl
.prototype.onSizeUpdated = function(
81 this.width_
= base
.getNumberAttr(message
.data
, 'width');
82 this.height_
= base
.getNumberAttr(message
.data
, 'height');
83 this.xDpi_
= base
.getNumberAttr(message
.data
, 'x_dpi', 96);
84 this.yDpi_
= base
.getNumberAttr(message
.data
, 'y_dpi', 96);
85 this.raiseEvent(remoting
.HostDesktop
.Events
.sizeChanged
,
86 this.getDimensions());
90 * This function is called by |this.plugin_| when the shape of the host
93 * @param {remoting.ClientPluginMessage} message
94 * @return {Array<{left:number, top:number, width:number, height:number}>}
95 * rectangles of the desktop shape.
97 remoting
.ClientPlugin
.HostDesktopImpl
.prototype.onShapeUpdated
=
99 var shapes
= base
.getArrayAttr(message
.data
, 'rects');
100 var rects
= shapes
.map(
101 /** @param {Array<number>} shape */
103 if (!Array
.isArray(shape
) || shape
.length
!= 4) {
104 throw 'Received invalid onDesktopShape message';
107 rect
.left
= shape
[0];
109 rect
.width
= shape
[2];
110 rect
.height
= shape
[3];
114 this.raiseEvent(remoting
.HostDesktop
.Events
.shapeChanged
, rects
);