-
Notifications
You must be signed in to change notification settings - Fork 8
/
client_plugin_host_desktop_impl.js
126 lines (113 loc) · 3.5 KB
/
client_plugin_host_desktop_impl.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
/**
* @fileoverview
* Provides an interface to manage the Host Desktop of a remoting session.
*/
var remoting = remoting || {};
remoting.ClientPlugin = remoting.ClientPlugin || {};
(function() {
'use strict';
/**
* @param {remoting.ClientPluginImpl} plugin
* @param {function(Object):void} postMessageCallback Callback to post a message
* to the Client Plugin.
*
* @implements {remoting.HostDesktop}
* @extends {base.EventSourceImpl}
* @constructor
*/
remoting.ClientPlugin.HostDesktopImpl = function(plugin, postMessageCallback) {
/** @private */
this.plugin_ = plugin;
/** @private */
this.width_ = 0;
/** @private */
this.height_ = 0;
/** @private */
this.xDpi_ = 96;
/** @private */
this.yDpi_ = 96;
/** @private */
this.postMessageCallback_ = postMessageCallback;
this.defineEvents(base.values(remoting.HostDesktop.Events));
};
base.extend(remoting.ClientPlugin.HostDesktopImpl, base.EventSourceImpl);
/** @return {boolean} Whether the host supports desktop resizing. */
remoting.ClientPlugin.HostDesktopImpl.prototype.isResizable = function() {
return this.plugin_.hasFeature(
remoting.ClientPlugin.Feature.NOTIFY_CLIENT_RESOLUTION);
};
/** @return {{width:number, height:number, xDpi:number, yDpi:number}} */
remoting.ClientPlugin.HostDesktopImpl.prototype.getDimensions = function() {
return {
width: this.width_,
height: this.height_,
xDpi: this.xDpi_,
yDpi: this.yDpi_
};
};
/**
* @param {number} width
* @param {number} height
* @param {number} deviceScale
*/
remoting.ClientPlugin.HostDesktopImpl.prototype.resize = function(
width, height, deviceScale) {
if (this.isResizable()) {
var dpi = Math.floor(deviceScale * 96);
this.postMessageCallback_({
method: 'notifyClientResolution',
data: {
width: Math.floor(width * deviceScale),
height: Math.floor(height * deviceScale),
x_dpi: dpi,
y_dpi: dpi
}
});
}
};
/**
* This function is called by |this.plugin_| when the size of the host
* desktop is changed.
*
* @param {remoting.ClientPluginMessage} message
*/
remoting.ClientPlugin.HostDesktopImpl.prototype.onSizeUpdated = function(
message) {
this.width_ = getNumberAttr(message.data, 'width');
this.height_ = getNumberAttr(message.data, 'height');
this.xDpi_ = getNumberAttr(message.data, 'x_dpi', 96);
this.yDpi_ = getNumberAttr(message.data, 'y_dpi', 96);
this.raiseEvent(remoting.HostDesktop.Events.sizeChanged,
this.getDimensions());
};
/**
* This function is called by |this.plugin_| when the shape of the host
* desktop is changed.
*
* @param {remoting.ClientPluginMessage} message
* @return {Array<{left:number, top:number, width:number, height:number}>}
* rectangles of the desktop shape.
*/
remoting.ClientPlugin.HostDesktopImpl.prototype.onShapeUpdated =
function(message) {
var shapes = getArrayAttr(message.data, 'rects');
var rects = shapes.map(
/** @param {Array.<number>} shape */
function(shape) {
if (!Array.isArray(shape) || shape.length != 4) {
throw 'Received invalid onDesktopShape message';
}
var rect = {};
rect.left = shape[0];
rect.top = shape[1];
rect.width = shape[2];
rect.height = shape[3];
return rect;
});
this.raiseEvent(remoting.HostDesktop.Events.shapeChanged, rects);
return rects;
};
}());