Chromium Code Reviews| 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 var remoting = remoting || {}; | |
| 6 | |
| 7 (function() { | |
| 8 | |
| 9 'use strict'; | |
| 10 | |
| 11 /** | |
| 12 * @param {HTMLElement} rootElement | |
| 13 * @param {remoting.LocalHostSection.Controller} controller | |
| 14 * | |
| 15 * @constructor | |
| 16 * @implements {base.Disposable} | |
| 17 */ | |
| 18 remoting.LocalHostSection = function(rootElement, controller) { | |
| 19 /** @private */ | |
| 20 this.rootElement_ = rootElement; | |
| 21 /** @private */ | |
| 22 this.controller_ = controller; | |
| 23 /** @private {remoting.Host} */ | |
| 24 this.host_ = null; | |
| 25 /** @private {remoting.HostController.State} */ | |
| 26 this.state_ = remoting.HostController.State.UNKNOWN; | |
| 27 | |
| 28 var hostContainer = rootElement.querySelector('.host-entry'); | |
| 29 /** @private */ | |
| 30 this.hostTableEntry_ = new remoting.HostTableEntry( | |
| 31 parseInt(chrome.runtime.getManifest().version, 10), | |
| 32 remoting.connectMe2Me, | |
| 33 this.rename_.bind(this)); | |
| 34 hostContainer.appendChild(this.hostTableEntry_.element()); | |
| 35 this.hostTableEntry_.element().id = 'local-host-connect-button'; | |
| 36 | |
| 37 var startButton = rootElement.querySelector('.start-daemon'); | |
| 38 var stopButton = rootElement.querySelector('.stop-daemon'); | |
| 39 var changePINButton = rootElement.querySelector('.change-daemon-pin'); | |
| 40 | |
| 41 /** @private */ | |
| 42 this.eventHooks_ = new base.Disposables( | |
| 43 new base.DomEventHook(startButton, 'click', | |
| 44 controller.start.bind(controller), false), | |
| 45 new base.DomEventHook(stopButton, 'click', | |
| 46 controller.stop.bind(controller), false), | |
| 47 new base.DomEventHook(changePINButton, 'click', | |
| 48 controller.changePIN.bind(controller), false)); | |
| 49 /** @private */ | |
| 50 this.hasError_ = false; | |
| 51 }; | |
| 52 | |
| 53 remoting.LocalHostSection.prototype.dispose = function() { | |
| 54 base.dispose(this.eventHooks_); | |
| 55 this.eventHooks_ = null; | |
| 56 }; | |
| 57 | |
| 58 /** | |
| 59 * @param {remoting.Host} host | |
| 60 * @param {remoting.HostController.State} state | |
| 61 * @param {boolean} hasError Whether the host list is in an error state. | |
| 62 */ | |
| 63 remoting.LocalHostSection.prototype.setModel = function(host, state, hasError) { | |
| 64 this.host_ = host; | |
| 65 this.state_ = state; | |
| 66 this.hasError_ = hasError; | |
| 67 this.updateUI_(); | |
| 68 }; | |
| 69 | |
| 70 /** | |
| 71 * @return {?string} | |
| 72 */ | |
| 73 remoting.LocalHostSection.prototype.getHostId = function() { | |
| 74 return this.host_ ? this.host_.hostId : null; | |
| 75 }; | |
| 76 | |
| 77 /** @return {boolean} */ | |
| 78 remoting.LocalHostSection.prototype.isEnabled_ = function() { | |
| 79 return (this.state_ == remoting.HostController.State.STARTING) || | |
| 80 (this.state_ == remoting.HostController.State.STARTED); | |
| 81 }; | |
| 82 | |
| 83 /** @return {boolean} */ | |
| 84 remoting.LocalHostSection.prototype.canChangeState = function() { | |
| 85 // The local host cannot be stopped or started if the host controller is not | |
| 86 // implemented for this platform. Additionally, it cannot be started if there | |
| 87 // is an error (in many error states, the start operation will fail anyway, | |
| 88 // but even if it succeeds, the chance of a related but hard-to-diagnose | |
| 89 // future error is high). | |
| 90 var state = this.state_; | |
| 91 if (state === remoting.HostController.State.NOT_IMPLEMENTED || | |
| 92 state === remoting.HostController.State.UNKNOWN || | |
| 93 this.hasError_) { | |
| 94 return false; | |
| 95 } | |
| 96 var isInstallable = (state != remoting.HostController.State.NOT_INSTALLED || | |
| 97 remoting.isMe2MeInstallable()); | |
|
Jamie
2015/03/04 00:09:25
Shouldn't this be isMe2MeInstallable() && state ==
kelvinp
2015/03/04 02:02:28
Done.
| |
| 98 return (this.isEnabled_() || isInstallable); | |
| 99 }; | |
| 100 | |
| 101 /** @private */ | |
| 102 remoting.LocalHostSection.prototype.updateUI_ = function() { | |
| 103 this.hostTableEntry_.setHost(this.host_); | |
| 104 | |
| 105 // Disable elements. | |
| 106 var enabled = this.isEnabled_(); | |
| 107 var canChangeLocalHostState = this.canChangeState(); | |
| 108 remoting.updateModalUi(enabled ? 'enabled' : 'disabled', 'data-daemon-state'); | |
| 109 this.rootElement_.hidden = !canChangeLocalHostState; | |
| 110 }; | |
| 111 | |
| 112 remoting.LocalHostSection.prototype.rename_ = function() { | |
| 113 return this.controller_.rename(this.hostTableEntry_); | |
| 114 }; | |
| 115 | |
| 116 /** | |
| 117 * @constructor | |
| 118 * @param {remoting.HostList} hostList | |
| 119 * @param {remoting.HostSetupDialog} setupDialog | |
| 120 */ | |
| 121 remoting.LocalHostSection.Controller = function(hostList, setupDialog) { | |
| 122 /** @private */ | |
| 123 this.hostList_ = hostList; | |
| 124 this.setupDialog_ = setupDialog; | |
| 125 }; | |
| 126 | |
| 127 remoting.LocalHostSection.Controller.prototype.start = function() { | |
| 128 this.setupDialog_.showForStart(); | |
| 129 }; | |
| 130 | |
| 131 remoting.LocalHostSection.Controller.prototype.stop = function() { | |
| 132 this.setupDialog_.showForStop(); | |
| 133 }; | |
| 134 | |
| 135 remoting.LocalHostSection.Controller.prototype.changePIN = function() { | |
| 136 this.setupDialog_.showForPin(); | |
| 137 }; | |
| 138 | |
| 139 /** @param {remoting.HostTableEntry} host */ | |
| 140 remoting.LocalHostSection.Controller.prototype.rename = function(host) { | |
| 141 this.hostList_.renameHost(host); | |
| 142 }; | |
| 143 | |
| 144 }()); | |
| 145 | |
| OLD | NEW |