OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 /** @suppress {duplicate} */ | 5 /** @suppress {duplicate} */ |
6 var remoting = remoting || {}; | 6 var remoting = remoting || {}; |
7 | 7 |
8 (function() { | 8 (function() { |
9 | 9 |
10 'use strict'; | 10 'use strict'; |
11 | 11 |
12 /** | 12 /** |
13 * @param {remoting.SessionConnector} sessionConnector | 13 * @param {remoting.SessionConnector} sessionConnector |
14 * @param {remoting.Host} host | 14 * @param {remoting.Host} host |
15 * | 15 * |
16 * @constructor | 16 * @constructor |
17 * @implements {remoting.Activity} | 17 * @implements {remoting.Activity} |
18 */ | 18 */ |
19 remoting.Me2MeActivity = function(sessionConnector, host) { | 19 remoting.Me2MeActivity = function(sessionConnector, host) { |
20 /** @private */ | 20 /** @private */ |
21 this.host_ = host; | 21 this.host_ = host; |
22 /** @private */ | 22 /** @private */ |
23 this.connector_ = sessionConnector; | 23 this.connector_ = sessionConnector; |
24 /** @private */ | 24 /** @private */ |
25 this.pinDialog_ = | 25 this.pinDialog_ = |
26 new remoting.PinDialog(document.getElementById('pin-dialog'), host); | 26 new remoting.PinDialog(document.getElementById('pin-dialog'), host); |
27 /** @private */ | 27 /** @private */ |
28 this.hostUpdateDialog_ = new remoting.HostNeedsUpdateDialog( | 28 this.hostUpdateDialog_ = new remoting.HostNeedsUpdateDialog( |
29 document.getElementById('host-needs-update-dialog'), this.host_); | 29 document.getElementById('host-needs-update-dialog'), this.host_); |
| 30 |
30 /** @private */ | 31 /** @private */ |
31 this.retryOnHostOffline_ = true; | 32 this.retryOnHostOffline_ = true; |
32 }; | 33 }; |
33 | 34 |
34 remoting.Me2MeActivity.prototype.dispose = function() {}; | 35 remoting.Me2MeActivity.prototype.dispose = function() {}; |
35 | 36 |
36 remoting.Me2MeActivity.prototype.start = function() { | 37 remoting.Me2MeActivity.prototype.start = function() { |
37 var webappVersion = chrome.runtime.getManifest().version; | 38 var webappVersion = chrome.runtime.getManifest().version; |
38 var that = this; | 39 var that = this; |
39 | 40 |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 var plugin = connectionInfo.plugin(); | 124 var plugin = connectionInfo.plugin(); |
124 if (remoting.app.hasCapability(remoting.ClientSession.Capability.CAST)) { | 125 if (remoting.app.hasCapability(remoting.ClientSession.Capability.CAST)) { |
125 plugin.extensions().register(new remoting.CastExtensionHandler()); | 126 plugin.extensions().register(new remoting.CastExtensionHandler()); |
126 } | 127 } |
127 plugin.extensions().register(new remoting.GnubbyAuthHandler()); | 128 plugin.extensions().register(new remoting.GnubbyAuthHandler()); |
128 this.pinDialog_.requestPairingIfNecessary(connectionInfo.plugin(), | 129 this.pinDialog_.requestPairingIfNecessary(connectionInfo.plugin(), |
129 this.connector_); | 130 this.connector_); |
130 }; | 131 }; |
131 | 132 |
132 remoting.Me2MeActivity.prototype.onDisconnected = function() { | 133 remoting.Me2MeActivity.prototype.onDisconnected = function() { |
133 remoting.setMode(remoting.AppMode.CLIENT_SESSION_FINISHED_ME2ME); | 134 this.showFinishDialog_(remoting.AppMode.CLIENT_SESSION_FINISHED_ME2ME); |
134 }; | 135 }; |
135 | 136 |
136 /** | 137 /** |
137 * @param {!remoting.Error} error | 138 * @param {!remoting.Error} error |
138 */ | 139 */ |
139 remoting.Me2MeActivity.prototype.onError = function(error) { | 140 remoting.Me2MeActivity.prototype.onError = function(error) { |
140 this.retryOnHostOffline_ = true; | |
141 var errorDiv = document.getElementById('connect-error-message'); | 141 var errorDiv = document.getElementById('connect-error-message'); |
142 l10n.localizeElementFromTag(errorDiv, error.getTag()); | 142 l10n.localizeElementFromTag(errorDiv, error.getTag()); |
143 remoting.setMode(remoting.AppMode.CLIENT_CONNECT_FAILED_ME2ME); | 143 this.showFinishDialog_(remoting.AppMode.CLIENT_CONNECT_FAILED_ME2ME); |
144 }; | 144 }; |
145 | 145 |
146 /** | 146 /** |
| 147 * @param {remoting.AppMode} mode |
| 148 * @private |
| 149 */ |
| 150 remoting.Me2MeActivity.prototype.showFinishDialog_ = function(mode) { |
| 151 var dialog = new remoting.MessageDialog( |
| 152 mode, |
| 153 document.getElementById('client-finished-me2me-button'), |
| 154 document.getElementById('client-reconnect-button')); |
| 155 |
| 156 /** @typedef {remoting.MessageDialog.Result} */ |
| 157 var Result = remoting.MessageDialog.Result; |
| 158 var that = this; |
| 159 |
| 160 dialog.show().then(function(/** Result */result) { |
| 161 if (result === Result.PRIMARY) { |
| 162 remoting.setMode(remoting.AppMode.HOME); |
| 163 } else { |
| 164 that.connector_.reconnect(); |
| 165 remoting.setMode(remoting.AppMode.CLIENT_CONNECTING); |
| 166 } |
| 167 }); |
| 168 }; |
| 169 |
| 170 /** |
147 * @param {HTMLElement} rootElement | 171 * @param {HTMLElement} rootElement |
148 * @param {remoting.Host} host | 172 * @param {remoting.Host} host |
149 * @constructor | 173 * @constructor |
150 */ | 174 */ |
151 remoting.HostNeedsUpdateDialog = function(rootElement, host) { | 175 remoting.HostNeedsUpdateDialog = function(rootElement, host) { |
152 /** @private */ | 176 /** @private */ |
153 this.host_ = host; | 177 this.host_ = host; |
154 /** @private */ | 178 /** @private */ |
155 this.rootElement_ = rootElement; | 179 this.dialog_ = new remoting.MessageDialog( |
156 /** @private {base.Deferred} */ | 180 remoting.AppMode.CLIENT_HOST_NEEDS_UPGRADE, |
157 this.deferred_ = null; | 181 rootElement.querySelector('.connect-button'), |
158 /** @private {base.Disposables} */ | 182 rootElement.querySelector('.cancel-button')); |
159 this.eventHooks_ = null; | |
160 | 183 |
161 l10n.localizeElementFromTag( | 184 l10n.localizeElementFromTag( |
162 rootElement.querySelector('.host-needs-update-message'), | 185 rootElement.querySelector('.host-needs-update-message'), |
163 /*i18n-content*/'HOST_NEEDS_UPDATE_TITLE', host.hostName); | 186 /*i18n-content*/'HOST_NEEDS_UPDATE_TITLE', host.hostName); |
164 }; | 187 }; |
165 | 188 |
166 /** | 189 /** |
167 * Shows the HostNeedsUpdateDialog if the user is trying to connect to a legacy | 190 * Shows the HostNeedsUpdateDialog if the user is trying to connect to a legacy |
168 * host. | 191 * host. |
169 * | 192 * |
170 * @param {string} webappVersion | 193 * @param {string} webappVersion |
171 * @return {Promise} Promise that resolves when no update is required or | 194 * @return {Promise} Promise that resolves when no update is required or |
172 * when the user ignores the update warning. Rejects with | 195 * when the user ignores the update warning. Rejects with |
173 * |remoting.Error.CANCELLED| if the user cancels the connection. | 196 * |remoting.Error.CANCELLED| if the user cancels the connection. |
174 */ | 197 */ |
175 remoting.HostNeedsUpdateDialog.prototype.showIfNecessary = | 198 remoting.HostNeedsUpdateDialog.prototype.showIfNecessary = |
176 function(webappVersion) { | 199 function(webappVersion) { |
177 if (!remoting.Host.needsUpdate(this.host_, webappVersion)) { | 200 if (!remoting.Host.needsUpdate(this.host_, webappVersion)) { |
178 return Promise.resolve(); | 201 return Promise.resolve(); |
179 } | 202 } |
180 | 203 /** @typedef {remoting.MessageDialog.Result} */ |
181 this.eventHooks_ = new base.Disposables( | 204 var Result = remoting.MessageDialog.Result; |
182 new base.DomEventHook(this.rootElement_.querySelector('.connect-button'), | 205 return this.dialog_.show().then(function(/** Result */ result) { |
183 'click', this.onOK_.bind(this), false), | 206 if (result === Result.SECONDARY) { |
184 new base.DomEventHook(this.rootElement_.querySelector('.cancel-button'), | 207 return Promise.reject(new remoting.Error(remoting.Error.Tag.CANCELLED)); |
185 'click', this.onCancel_.bind(this), false)); | 208 } |
186 | 209 }); |
187 base.debug.assert(this.deferred_ === null); | |
188 this.deferred_ = new base.Deferred(); | |
189 | |
190 remoting.setMode(remoting.AppMode.CLIENT_HOST_NEEDS_UPGRADE); | |
191 | |
192 return this.deferred_.promise(); | |
193 }; | |
194 | |
195 /** @private */ | |
196 remoting.HostNeedsUpdateDialog.prototype.cleanup_ = function() { | |
197 base.dispose(this.eventHooks_); | |
198 this.eventHooks_ = null; | |
199 this.deferred_ = null; | |
200 }; | |
201 | |
202 | |
203 /** @private */ | |
204 remoting.HostNeedsUpdateDialog.prototype.onOK_ = function() { | |
205 this.deferred_.resolve(); | |
206 this.cleanup_(); | |
207 }; | |
208 | |
209 /** @private */ | |
210 remoting.HostNeedsUpdateDialog.prototype.onCancel_ = function() { | |
211 this.deferred_.reject(new remoting.Error(remoting.Error.Tag.CANCELLED)); | |
212 this.cleanup_(); | |
213 }; | 210 }; |
214 | 211 |
215 /** | 212 /** |
216 * @param {HTMLElement} rootElement | 213 * @param {HTMLElement} rootElement |
217 * @param {remoting.Host} host | 214 * @param {remoting.Host} host |
218 * @constructor | 215 * @constructor |
219 */ | 216 */ |
220 remoting.PinDialog = function(rootElement, host) { | 217 remoting.PinDialog = function(rootElement, host) { |
221 /** @private */ | 218 /** @private */ |
222 this.rootElement_ = rootElement; | 219 this.rootElement_ = rootElement; |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
283 clientName = 'Linux'; | 280 clientName = 'Linux'; |
284 } else { | 281 } else { |
285 console.log('Unrecognized client platform. Using navigator.platform.'); | 282 console.log('Unrecognized client platform. Using navigator.platform.'); |
286 clientName = navigator.platform; | 283 clientName = navigator.platform; |
287 } | 284 } |
288 plugin.requestPairing(clientName, onPairingComplete); | 285 plugin.requestPairing(clientName, onPairingComplete); |
289 } | 286 } |
290 }; | 287 }; |
291 | 288 |
292 })(); | 289 })(); |
OLD | NEW |