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 {boolean} Whether the host supports desktop resizing. */
45 remoting.ClientPlugin.HostDesktopImpl.prototype.isResizable = function() {
46 return this.plugin_.hasFeature(
47 remoting.ClientPlugin.Feature.NOTIFY_CLIENT_RESOLUTION);
50 /** @return {{width:number, height:number, xDpi:number, yDpi:number}} */
51 remoting.ClientPlugin.HostDesktopImpl.prototype.getDimensions = function() {
61 * @param {number} width
62 * @param {number} height
63 * @param {number} deviceScale
65 remoting.ClientPlugin.HostDesktopImpl.prototype.resize = function(
66 width, height, deviceScale) {
67 if (this.isResizable()) {
68 var dpi = Math.floor(deviceScale * 96);
69 this.postMessageCallback_({
70 method: 'notifyClientResolution',
72 width: Math.floor(width * deviceScale),
73 height: Math.floor(height * deviceScale),
82 * This function is called by |this.plugin_| when the size of the host
85 * @param {remoting.ClientPluginMessage} message
87 remoting.ClientPlugin.HostDesktopImpl.prototype.onSizeUpdated = function(
89 this.width_ = base.getNumberAttr(message.data, 'width');
90 this.height_ = base.getNumberAttr(message.data, 'height');
91 this.xDpi_ = base.getNumberAttr(message.data, 'x_dpi', 96);
92 this.yDpi_ = base.getNumberAttr(message.data, 'y_dpi', 96);
93 this.raiseEvent(remoting.HostDesktop.Events.sizeChanged,
94 this.getDimensions());
98 * This function is called by |this.plugin_| when the shape of the host
101 * @param {remoting.ClientPluginMessage} message
102 * @return {Array<{left:number, top:number, width:number, height:number}>}
103 * rectangles of the desktop shape.
105 remoting.ClientPlugin.HostDesktopImpl.prototype.onShapeUpdated =
107 var shapes = base.getArrayAttr(message.data, 'rects');
108 var rects = shapes.map(
109 /** @param {Array<number>} shape */
111 if (!Array.isArray(shape) || shape.length != 4) {
112 throw 'Received invalid onDesktopShape message';
115 rect.left = shape[0];
117 rect.width = shape[2];
118 rect.height = shape[3];
122 this.raiseEvent(remoting.HostDesktop.Events.shapeChanged, rects);