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 | |
| 36 var startButton = rootElement.querySelector('#start-daemon'); | |
| 37 var stopButton = rootElement.querySelector('#stop-daemon'); | |
| 38 var changePINButton = rootElement.querySelector('#change-daemon-pin'); | |
|
Jamie
2015/02/27 18:19:41
Can you query these by class instead of id? Queryi
kelvinp
2015/03/03 21:57:54
Done.
| |
| 39 | |
| 40 /** @private */ | |
| 41 this.eventHooks_ = new base.Disposables( | |
| 42 new base.DomEventHook(startButton, 'click', controller.start, false), | |
| 43 new base.DomEventHook(stopButton, 'click', controller.stop, false), | |
| 44 new base.DomEventHook(changePINButton, 'click', controller.changePIN, false) | |
|
Jamie
2015/02/27 18:19:41
I think these are all missing bind()s.
kelvinp
2015/03/03 21:57:53
Done.
| |
| 45 ); | |
| 46 | |
| 47 /** @private */ | |
| 48 this.hasError_ = false; | |
| 49 }; | |
| 50 | |
| 51 remoting.LocalHostSection.prototype.dispose = function() { | |
| 52 base.dispose(this.eventHooks_); | |
| 53 this.eventHooks_ = null; | |
| 54 }; | |
| 55 | |
| 56 /** | |
| 57 * @param {remoting.Host} host | |
| 58 * @param {remoting.HostController.State} state | |
| 59 * @param {boolean} hasError Whether the host list is in an error state. | |
| 60 */ | |
| 61 remoting.LocalHostSection.prototype.setModel = function(host, state, hasError) { | |
| 62 this.host_ = host; | |
| 63 this.state_ = state; | |
| 64 this.hasError_ = hasError; | |
| 65 this.updateUI_(); | |
| 66 }; | |
| 67 | |
| 68 /** | |
| 69 * @return {?string} | |
| 70 */ | |
| 71 remoting.LocalHostSection.prototype.getHostId = function() { | |
| 72 return this.host_ ? this.host_.hostId : null; | |
| 73 }; | |
| 74 | |
| 75 /** @return {boolean} */ | |
| 76 remoting.LocalHostSection.prototype.isEnabled_ = function() { | |
| 77 return (this.state_ == remoting.HostController.State.STARTING) || | |
| 78 (this.state_ == remoting.HostController.State.STARTED); | |
| 79 }; | |
| 80 | |
| 81 /** @return {boolean} */ | |
| 82 remoting.LocalHostSection.prototype.canChangeState = function() { | |
| 83 // The local host cannot be stopped or started if the host controller is not | |
| 84 // implemented for this platform. Additionally, it cannot be started if there | |
| 85 // is an error (in many error states, the start operation will fail anyway, | |
| 86 // but even if it succeeds, the chance of a related but hard-to-diagnose | |
| 87 // future error is high). | |
| 88 var state = this.state_; | |
| 89 return (state != remoting.HostController.State.NOT_IMPLEMENTED) && | |
| 90 (state != remoting.HostController.State.UNKNOWN) && | |
| 91 (state != remoting.HostController.State.NOT_INSTALLED || | |
| 92 remoting.isMe2MeInstallable()) && | |
| 93 (this.isEnabled_() || !this.hasError_); | |
|
Jamie
2015/02/27 18:19:41
This conditional is hard to parse. Can you break i
kelvinp
2015/03/03 21:57:54
Done.
| |
| 94 }; | |
| 95 | |
| 96 /** @private */ | |
| 97 remoting.LocalHostSection.prototype.updateUI_ = function() { | |
| 98 this.hostTableEntry_.setHost(this.host_); | |
| 99 | |
| 100 // Disable elements. | |
| 101 var enabled = this.isEnabled_(); | |
| 102 var canChangeLocalHostState = this.canChangeState(); | |
| 103 remoting.updateModalUi(enabled ? 'enabled' : 'disabled', 'data-daemon-state'); | |
| 104 this.rootElement_.hidden = !canChangeLocalHostState; | |
| 105 }; | |
| 106 | |
| 107 remoting.LocalHostSection.prototype.rename_ = function() { | |
| 108 return this.controller_.rename(this.hostTableEntry_); | |
| 109 }; | |
| 110 | |
| 111 /** | |
| 112 * @constructor | |
| 113 * @param {remoting.HostList} hostList | |
| 114 */ | |
| 115 remoting.LocalHostSection.Controller = function(hostList) { | |
| 116 /** @private */ | |
| 117 this.hostList_ = hostList; | |
| 118 }; | |
| 119 | |
| 120 remoting.LocalHostSection.Controller.prototype.start = function() { | |
| 121 remoting.hostSetupDialog.showForStart(); | |
|
Jamie
2015/02/27 18:19:41
Maybe pass the HostSetupDialog to the ctor for bet
kelvinp
2015/03/03 21:57:54
Done.
| |
| 122 }; | |
| 123 | |
| 124 remoting.LocalHostSection.Controller.prototype.stop = function() { | |
| 125 remoting.hostSetupDialog.showForStop(); | |
| 126 }; | |
| 127 | |
| 128 remoting.LocalHostSection.Controller.prototype.changePIN = function() { | |
| 129 remoting.hostSetupDialog.showForPin(); | |
| 130 }; | |
| 131 | |
| 132 /** @param {remoting.HostTableEntry} host */ | |
| 133 remoting.LocalHostSection.Controller.prototype.rename = function(host) { | |
| 134 this.hostList_.renameHost(host); | |
| 135 }; | |
| 136 | |
| 137 }()); | |
| 138 | |
| OLD | NEW |