 Chromium Code Reviews
 Chromium Code Reviews Issue 1015523005:
  [Webapp Refactor] Implements AppConnectedView.  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master
    
  
    Issue 1015523005:
  [Webapp Refactor] Implements AppConnectedView.  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master| OLD | NEW | 
|---|---|
| (Empty) | |
| 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. | |
| 4 | |
| 5 /** | |
| 6 * @fileoverview | |
| 7 * Implements a basic UX control for a connected app remoting session. | |
| 8 */ | |
| 9 | |
| 10 /** @suppress {duplicate} */ | |
| 11 var remoting = remoting || {}; | |
| 12 | |
| 13 (function() { | |
| 14 | |
| 15 'use strict'; | |
| 16 | |
| 17 // A 10-second interval to test the connection speed. | |
| 18 var CONNECTION_SPEED_PING_INTERVAL = 10 * 1000; | |
| 19 | |
| 20 /** | |
| 21 * @param {HTMLElement} containerElement | |
| 22 * @param {remoting.ConnectionInfo} connectionInfo | |
| 23 * | |
| 24 * @constructor | |
| 25 * @implements {base.Disposable} | |
| 26 */ | |
| 27 remoting.AppConnectedView = function(containerElement, connectionInfo) { | |
| 28 | |
| 29 /** @private */ | |
| 30 this.plugin_ = connectionInfo.plugin(); | |
| 31 | |
| 32 /** @private */ | |
| 33 this.host_ = connectionInfo.host(); | |
| 34 | |
| 35 var pingTimer = new base.RepeatingTimer(function () { | |
| 
kelvinp
2015/03/19 21:19:21
Moved from app_remoting.js.
 | |
| 36 var message = { timestamp: new Date().getTime() }; | |
| 37 var clientSession = connectionInfo.session(); | |
| 38 clientSession.sendClientMessage('pingRequest', JSON.stringify(message)); | |
| 39 }, CONNECTION_SPEED_PING_INTERVAL); | |
| 40 | |
| 41 var baseView = new remoting.ConnectedView( | |
| 42 this.plugin_, containerElement, | |
| 43 containerElement.querySelector('.mouse-cursor-overlay'));; | |
| 44 | |
| 45 var eventHook = new base.EventHook( | |
| 46 this.plugin_.hostDesktop(), | |
| 47 remoting.HostDesktop.Events.shapeChanged, | |
| 48 remoting.windowShape.setDesktopRects.bind(remoting.windowShape)); | |
| 49 | |
| 50 /** @private */ | |
| 51 this.disposables_ = new base.Disposables(pingTimer, baseView, eventHook); | |
| 52 | |
| 53 this.resizeHostToClientArea_().then( | |
| 54 this.setPluginSize_.bind(this) | |
| 55 ); | |
| 56 }; | |
| 57 | |
| 58 /** | |
| 59 * @return {void} Nothing. | |
| 60 */ | |
| 61 remoting.AppConnectedView.prototype.dispose = function() { | |
| 62 base.dispose(this.disposables_); | |
| 63 }; | |
| 64 | |
| 65 /** | |
| 66 * Resize the host to the dimensions of the current window. | |
| 67 * | |
| 68 * @return {Promise} A promise that resolves when the host finishes responding | |
| 69 * to the resize request. | |
| 70 * @private | |
| 71 */ | |
| 72 remoting.AppConnectedView.prototype.resizeHostToClientArea_ = function() { | |
| 73 var hostDesktop = this.plugin_.hostDesktop(); | |
| 74 var desktopScale = this.host_.options.desktopScale; | |
| 75 | |
| 76 return new Promise(function(/** Function */ resolve) { | |
| 77 var eventHook = new base.EventHook( | |
| 78 hostDesktop, remoting.HostDesktop.Events.sizeChanged, resolve); | |
| 79 hostDesktop.resize(window.innerWidth * desktopScale, | |
| 80 window.innerHeight * desktopScale, | |
| 81 window.devicePixelRatio); | |
| 82 }); | |
| 83 }; | |
| 84 | |
| 85 | |
| 86 /** | |
| 87 * Adjust the size of the plugin according to the dimensions of the hostDesktop. | |
| 88 * | |
| 89 * @param {{width:number, height:number, xDpi:number, yDpi:number}} hostDesktop | |
| 90 * @private | |
| 91 */ | |
| 92 remoting.AppConnectedView.prototype.setPluginSize_ = function(hostDesktop) { | |
| 93 remoting.LoadingWindow.close(); | |
| 94 var hostSize = { width: hostDesktop.width, height: hostDesktop.height }; | |
| 95 var hostDpi = { x: hostDesktop.xDpi, y: hostDesktop.yDpi }; | |
| 96 var clientArea = { width: window.innerWidth, height: window.innerHeight }; | |
| 97 var newSize = remoting.DesktopViewport.choosePluginSize( | |
| 98 clientArea, window.devicePixelRatio, | |
| 99 hostSize, hostDpi, this.host_.options.desktopScale, | |
| 100 true /* fullscreen */ , false /* shrinkToFit */ ); | |
| 101 | |
| 102 this.plugin_.element().style.width = newSize.width + 'px'; | |
| 103 this.plugin_.element().style.height = newSize.height + 'px'; | |
| 104 } | |
| 105 | |
| 106 })(); | |
| OLD | NEW |