Supervised user whitelists: Cleanup
[chromium-blink-merge.git] / remoting / webapp / crd / js / client_plugin_host_desktop_impl.js
blob94ed9d27885b95822591a4630108840a4f8a1f65
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.
5 /**
6 * @fileoverview
7 * Provides an interface to manage the Host Desktop of a remoting session.
8 */
10 var remoting = remoting || {};
11 remoting.ClientPlugin = remoting.ClientPlugin || {};
13 (function() {
15 'use strict';
17 /**
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}
24 * @constructor
26 remoting.ClientPlugin.HostDesktopImpl = function(plugin, postMessageCallback) {
27 base.inherits(this, base.EventSourceImpl);
28 /** @private */
29 this.plugin_ = plugin;
30 /** @private */
31 this.width_ = 0;
32 /** @private */
33 this.height_ = 0;
34 /** @private */
35 this.xDpi_ = 96;
36 /** @private */
37 this.yDpi_ = 96;
38 /** @private */
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() {
52 return {
53 width: this.width_,
54 height: this.height_,
55 xDpi: this.xDpi_,
56 yDpi: this.yDpi_
60 /**
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',
71 data: {
72 width: Math.floor(width * deviceScale),
73 height: Math.floor(height * deviceScale),
74 x_dpi: dpi,
75 y_dpi: dpi
77 });
81 /**
82 * This function is called by |this.plugin_| when the size of the host
83 * desktop is changed.
85 * @param {remoting.ClientPluginMessage} message
87 remoting.ClientPlugin.HostDesktopImpl.prototype.onSizeUpdated = function(
88 message) {
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());
97 /**
98 * This function is called by |this.plugin_| when the shape of the host
99 * desktop is changed.
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 =
106 function(message) {
107 var shapes = base.getArrayAttr(message.data, 'rects');
108 var rects = shapes.map(
109 /** @param {Array.<number>} shape */
110 function(shape) {
111 if (!Array.isArray(shape) || shape.length != 4) {
112 throw 'Received invalid onDesktopShape message';
114 var rect = {};
115 rect.left = shape[0];
116 rect.top = shape[1];
117 rect.width = shape[2];
118 rect.height = shape[3];
119 return rect;
122 this.raiseEvent(remoting.HostDesktop.Events.shapeChanged, rects);
123 return rects;
126 }());