Chromium Code Reviews| Index: remoting/webapp/crd/js/client_plugin_host_desktop_impl.js |
| diff --git a/remoting/webapp/crd/js/client_plugin_host_desktop_impl.js b/remoting/webapp/crd/js/client_plugin_host_desktop_impl.js |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..d47a6fb296f5b5eb84375ebe6b7d08e92e8cc01a |
| --- /dev/null |
| +++ b/remoting/webapp/crd/js/client_plugin_host_desktop_impl.js |
| @@ -0,0 +1,138 @@ |
| +// Copyright 2014 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. |
| + */ |
| + |
| +/** @suppress {duplicate} */ |
| +var remoting = remoting || {}; |
| +remoting.ClientPlugin = remoting.ClientPlugin || {}; |
| + |
| +(function() { |
| + |
| +'use strict'; |
| + |
| +var HostDesktopEvents = remoting.ClientPlugin.HostDesktop.Events; |
| + |
| +/** |
| + * @param {remoting.ClientPluginImpl} plugin |
| + * @param {function(Object):void} postMessageCallback Callback to post a message |
| + * to the Client Plugin. |
| + * |
| + * @implements {remoting.ClientPlugin.HostDesktop} |
| + * @extends {base.EventSourceImpl} |
| + * @constructor |
| + */ |
| +remoting.ClientPlugin.HostDesktopImpl = function(plugin, postMessageCallback) { |
|
Jamie
2015/02/12 21:07:29
I think it's confusing to have a nested type decla
kelvinp
2015/02/12 23:26:41
I removed ClientPlugin from the interface. But th
|
| + /** @private */ |
| + this.plugin_ = plugin; |
| + /** @private */ |
| + this.width_ = 0; |
| + /** @private */ |
| + this.height_ = 0; |
| + /** @private */ |
| + this.xDpi_ = 96; |
| + /** @private */ |
| + this.yDpi_ = 96; |
| + /** @private */ |
| + this.hasResizeRateLimit_ = false; |
| + /** @private */ |
| + this.postMessageCallback_ = postMessageCallback; |
| + |
| + this.defineEvents(Object.keys(HostDesktopEvents)); |
| +}; |
| +base.extend(remoting.ClientPlugin.HostDesktopImpl, base.EventSourceImpl); |
| + |
| +/** @return {boolean} */ |
| +remoting.ClientPlugin.HostDesktopImpl.prototype.hasResizeRateLimit = |
| + function() { |
| + return this.hasResizeRateLimit_; |
| +}; |
| + |
| +/** @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} device_scale |
| + */ |
| +remoting.ClientPlugin.HostDesktopImpl.prototype.resize = function( |
| + width, height, device_scale) { |
| + if (this.isResizable()) { |
| + var dpi = Math.floor(device_scale * 96); |
| + this.postMessageCallback_({ |
| + method: 'notifyClientResolution', |
| + data: { |
| + width: Math.floor(width * device_scale), |
| + height: Math.floor(height * device_scale), |
| + x_dpi: dpi, |
| + y_dpi: dpi |
| + } |
| + }); |
| + } |
| +}; |
| + |
| +/** |
| + * @param {Array.<string>} capabilities |
| + */ |
| +remoting.ClientPlugin.HostDesktopImpl.prototype.onSetCapabilities = function( |
| + capabilities) { |
| + this.hasResizeRateLimit_ = |
| + capabilities.indexOf( |
| + remoting.ClientSession.Capability.RATE_LIMIT_RESIZE_REQUESTS) !== -1; |
| +}; |
| + |
| +/** |
| + * 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(HostDesktopEvents.sizeChanged); |
| +}; |
| + |
| +/** |
| + * This function is called by |this.plugin_| when the shape of the host |
| + * desktop is changed. |
| + * |
| + * @param {remoting.ClientPluginMessage} message |
| + * @return {Array.<Array.<number>>} rectangles of the desktop shape. |
| + */ |
| +remoting.ClientPlugin.HostDesktopImpl.prototype.onShapeUpdated = |
| + function(message) { |
| + var rects = getArrayAttr(message.data, 'rects'); |
| + for (var i = 0; i < rects.length; ++i) { |
| + /** @type {Array.<number>} */ |
| + var rect = rects[i]; |
| + if (typeof rect != 'object' || rect.length != 4) { |
| + throw 'Received invalid onDesktopShape message'; |
| + } |
| + } |
| + this.raiseEvent(HostDesktopEvents.shapeChanged, rects); |
| + return rects; |
| +}; |
| + |
| +}()); |