Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2014 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. | |
| 4 | |
| 5 /** | |
| 6 * @fileoverview | |
| 7 * Provides an interface to manage the Host Desktop of a remoting session. | |
| 8 */ | |
| 9 | |
| 10 /** @suppress {duplicate} */ | |
| 11 var remoting = remoting || {}; | |
| 12 remoting.ClientPlugin = remoting.ClientPlugin || {}; | |
| 13 | |
| 14 (function() { | |
| 15 | |
| 16 'use strict'; | |
| 17 | |
| 18 var HostDesktopEvents = remoting.ClientPlugin.HostDesktop.Events; | |
| 19 | |
| 20 /** | |
| 21 * @param {remoting.ClientPluginImpl} plugin | |
| 22 * @param {function(Object):void} postMessageCallback Callback to post a message | |
| 23 * to the Client Plugin. | |
| 24 * | |
| 25 * @implements {remoting.ClientPlugin.HostDesktop} | |
| 26 * @extends {base.EventSourceImpl} | |
| 27 * @constructor | |
| 28 */ | |
| 29 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
| |
| 30 /** @private */ | |
| 31 this.plugin_ = plugin; | |
| 32 /** @private */ | |
| 33 this.width_ = 0; | |
| 34 /** @private */ | |
| 35 this.height_ = 0; | |
| 36 /** @private */ | |
| 37 this.xDpi_ = 96; | |
| 38 /** @private */ | |
| 39 this.yDpi_ = 96; | |
| 40 /** @private */ | |
| 41 this.hasResizeRateLimit_ = false; | |
| 42 /** @private */ | |
| 43 this.postMessageCallback_ = postMessageCallback; | |
| 44 | |
| 45 this.defineEvents(Object.keys(HostDesktopEvents)); | |
| 46 }; | |
| 47 base.extend(remoting.ClientPlugin.HostDesktopImpl, base.EventSourceImpl); | |
| 48 | |
| 49 /** @return {boolean} */ | |
| 50 remoting.ClientPlugin.HostDesktopImpl.prototype.hasResizeRateLimit = | |
| 51 function() { | |
| 52 return this.hasResizeRateLimit_; | |
| 53 }; | |
| 54 | |
| 55 /** @return {boolean} Whether the host supports desktop resizing. */ | |
| 56 remoting.ClientPlugin.HostDesktopImpl.prototype.isResizable = function() { | |
| 57 return this.plugin_.hasFeature( | |
| 58 remoting.ClientPlugin.Feature.NOTIFY_CLIENT_RESOLUTION); | |
| 59 }; | |
| 60 | |
| 61 /** @return {{width:number, height:number, xDpi:number, yDpi:number}} */ | |
| 62 remoting.ClientPlugin.HostDesktopImpl.prototype.getDimensions = function() { | |
| 63 return { | |
| 64 width: this.width_, | |
| 65 height: this.height_, | |
| 66 xDpi: this.xDpi_, | |
| 67 yDpi: this.yDpi_ | |
| 68 }; | |
| 69 }; | |
| 70 | |
| 71 /** | |
| 72 * @param {number} width | |
| 73 * @param {number} height | |
| 74 * @param {number} device_scale | |
| 75 */ | |
| 76 remoting.ClientPlugin.HostDesktopImpl.prototype.resize = function( | |
| 77 width, height, device_scale) { | |
| 78 if (this.isResizable()) { | |
| 79 var dpi = Math.floor(device_scale * 96); | |
| 80 this.postMessageCallback_({ | |
| 81 method: 'notifyClientResolution', | |
| 82 data: { | |
| 83 width: Math.floor(width * device_scale), | |
| 84 height: Math.floor(height * device_scale), | |
| 85 x_dpi: dpi, | |
| 86 y_dpi: dpi | |
| 87 } | |
| 88 }); | |
| 89 } | |
| 90 }; | |
| 91 | |
| 92 /** | |
| 93 * @param {Array.<string>} capabilities | |
| 94 */ | |
| 95 remoting.ClientPlugin.HostDesktopImpl.prototype.onSetCapabilities = function( | |
| 96 capabilities) { | |
| 97 this.hasResizeRateLimit_ = | |
| 98 capabilities.indexOf( | |
| 99 remoting.ClientSession.Capability.RATE_LIMIT_RESIZE_REQUESTS) !== -1; | |
| 100 }; | |
| 101 | |
| 102 /** | |
| 103 * This function is called by |this.plugin_| when the size of the host | |
| 104 * desktop is changed. | |
| 105 * | |
| 106 * @param {remoting.ClientPluginMessage} message | |
| 107 */ | |
| 108 remoting.ClientPlugin.HostDesktopImpl.prototype.onSizeUpdated = function( | |
| 109 message) { | |
| 110 this.width_ = getNumberAttr(message.data, 'width'); | |
| 111 this.height_ = getNumberAttr(message.data, 'height'); | |
| 112 this.xDpi_ = getNumberAttr(message.data, 'x_dpi', 96); | |
| 113 this.yDpi_ = getNumberAttr(message.data, 'y_dpi', 96); | |
| 114 this.raiseEvent(HostDesktopEvents.sizeChanged); | |
| 115 }; | |
| 116 | |
| 117 /** | |
| 118 * This function is called by |this.plugin_| when the shape of the host | |
| 119 * desktop is changed. | |
| 120 * | |
| 121 * @param {remoting.ClientPluginMessage} message | |
| 122 * @return {Array.<Array.<number>>} rectangles of the desktop shape. | |
| 123 */ | |
| 124 remoting.ClientPlugin.HostDesktopImpl.prototype.onShapeUpdated = | |
| 125 function(message) { | |
| 126 var rects = getArrayAttr(message.data, 'rects'); | |
| 127 for (var i = 0; i < rects.length; ++i) { | |
| 128 /** @type {Array.<number>} */ | |
| 129 var rect = rects[i]; | |
| 130 if (typeof rect != 'object' || rect.length != 4) { | |
| 131 throw 'Received invalid onDesktopShape message'; | |
| 132 } | |
| 133 } | |
| 134 this.raiseEvent(HostDesktopEvents.shapeChanged, rects); | |
| 135 return rects; | |
| 136 }; | |
| 137 | |
| 138 }()); | |
| OLD | NEW |