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.Host} host | 13 * @param {remoting.Host} host |
14 * @param {remoting.HostList} hostList | |
14 * | 15 * |
15 * @constructor | 16 * @constructor |
16 * @implements {remoting.Activity} | 17 * @implements {remoting.Activity} |
17 */ | 18 */ |
18 remoting.Me2MeActivity = function(host) { | 19 remoting.Me2MeActivity = function(host, hostList) { |
19 /** @private */ | 20 /** @private */ |
20 this.host_ = host; | 21 this.host_ = host; |
21 /** @private */ | 22 /** @private */ |
23 this.hostList_ = hostList; | |
24 /** @private */ | |
22 this.pinDialog_ = | 25 this.pinDialog_ = |
23 new remoting.PinDialog(document.getElementById('pin-dialog'), host); | 26 new remoting.PinDialog(document.getElementById('pin-dialog'), host); |
24 /** @private */ | 27 /** @private */ |
25 this.hostUpdateDialog_ = new remoting.HostNeedsUpdateDialog( | 28 this.hostUpdateDialog_ = new remoting.HostNeedsUpdateDialog( |
26 document.getElementById('host-needs-update-dialog'), this.host_); | 29 document.getElementById('host-needs-update-dialog'), this.host_); |
27 | 30 |
28 /** @private */ | 31 /** @private */ |
29 this.retryOnHostOffline_ = true; | 32 this.retryOnHostOffline_ = true; |
30 | 33 |
31 /** @private {remoting.SmartReconnector} */ | 34 /** @private {remoting.SmartReconnector} */ |
32 this.reconnector_ = null; | 35 this.reconnector_ = null; |
33 | 36 |
34 /** @private {remoting.DesktopRemotingActivity} */ | 37 /** @private {remoting.DesktopRemotingActivity} */ |
35 this.desktopActivity_ = null; | 38 this.desktopActivity_ = null; |
36 }; | 39 }; |
37 | 40 |
38 remoting.Me2MeActivity.prototype.dispose = function() { | 41 remoting.Me2MeActivity.prototype.dispose = function() { |
39 base.dispose(this.desktopActivity_); | 42 base.dispose(this.desktopActivity_); |
40 this.desktopActivity_ = null; | 43 this.desktopActivity_ = null; |
41 }; | 44 }; |
42 | 45 |
43 remoting.Me2MeActivity.prototype.start = function() { | 46 remoting.Me2MeActivity.prototype.start = function() { |
44 var webappVersion = chrome.runtime.getManifest().version; | 47 var webappVersion = chrome.runtime.getManifest().version; |
45 var that = this; | 48 var that = this; |
46 | 49 |
47 this.hostUpdateDialog_.showIfNecessary(webappVersion).then(function() { | 50 this.hostUpdateDialog_.showIfNecessary(webappVersion).then(function() { |
48 return that.host_.options.load(); | 51 return that.host_.options.load(); |
49 }).then(function() { | 52 }).then(function() { |
50 that.connect_(true); | 53 that.connect_(true); |
51 }).catch(function(/** remoting.Error */ error) { | 54 }).catch(remoting.Error.handler(function(/** remoting.Error */ error) { |
52 if (error.hasTag(remoting.Error.Tag.CANCELLED)) { | 55 if (error.hasTag(remoting.Error.Tag.CANCELLED)) { |
53 remoting.setMode(remoting.AppMode.HOME); | 56 remoting.setMode(remoting.AppMode.HOME); |
54 } | 57 } |
55 }); | 58 })); |
56 }; | 59 }; |
57 | 60 |
58 remoting.Me2MeActivity.prototype.stop = function() { | 61 remoting.Me2MeActivity.prototype.stop = function() { |
59 this.desktopActivity_.stop(); | 62 this.desktopActivity_.stop(); |
60 }; | 63 }; |
61 | 64 |
62 /** @return {remoting.DesktopRemotingActivity} */ | 65 /** @return {remoting.DesktopRemotingActivity} */ |
63 remoting.Me2MeActivity.prototype.getDesktopActivity = function() { | 66 remoting.Me2MeActivity.prototype.getDesktopActivity = function() { |
64 return this.desktopActivity_; | 67 return this.desktopActivity_; |
65 }; | 68 }; |
66 | 69 |
67 /** | 70 /** |
68 * @param {boolean} suppressHostOfflineError | 71 * @param {boolean} suppressHostOfflineError |
69 * @private | 72 * @private |
70 */ | 73 */ |
71 remoting.Me2MeActivity.prototype.connect_ = function(suppressHostOfflineError) { | 74 remoting.Me2MeActivity.prototype.connect_ = function(suppressHostOfflineError) { |
72 remoting.setMode(remoting.AppMode.CLIENT_CONNECTING); | |
73 base.dispose(this.desktopActivity_); | 75 base.dispose(this.desktopActivity_); |
74 this.desktopActivity_ = new remoting.DesktopRemotingActivity(this); | 76 this.desktopActivity_ = new remoting.DesktopRemotingActivity(this); |
77 this.desktopActivity_.getConnectingDialog().show(); | |
75 remoting.app.setConnectionMode(remoting.Application.Mode.ME2ME); | 78 remoting.app.setConnectionMode(remoting.Application.Mode.ME2ME); |
76 this.desktopActivity_.start(this.host_, this.createCredentialsProvider_(), | 79 this.desktopActivity_.start(this.host_, this.createCredentialsProvider_(), |
77 suppressHostOfflineError); | 80 suppressHostOfflineError); |
78 }; | 81 }; |
79 | 82 |
80 /** | 83 /** |
81 * @return {remoting.CredentialsProvider} | 84 * @return {remoting.CredentialsProvider} |
82 * @private | 85 * @private |
83 */ | 86 */ |
84 remoting.Me2MeActivity.prototype.createCredentialsProvider_ = function() { | 87 remoting.Me2MeActivity.prototype.createCredentialsProvider_ = function() { |
(...skipping 12 matching lines...) Expand all Loading... | |
97 tokenUrl, hostPublicKey, scope, host.tokenUrlPatterns, | 100 tokenUrl, hostPublicKey, scope, host.tokenUrlPatterns, |
98 onThirdPartyTokenFetched); | 101 onThirdPartyTokenFetched); |
99 thirdPartyTokenFetcher.fetchToken(); | 102 thirdPartyTokenFetcher.fetchToken(); |
100 }; | 103 }; |
101 | 104 |
102 /** | 105 /** |
103 * @param {boolean} supportsPairing | 106 * @param {boolean} supportsPairing |
104 * @param {function(string):void} onPinFetched | 107 * @param {function(string):void} onPinFetched |
105 */ | 108 */ |
106 var requestPin = function(supportsPairing, onPinFetched) { | 109 var requestPin = function(supportsPairing, onPinFetched) { |
110 that.desktopActivity_.getConnectingDialog().hide(); | |
107 that.pinDialog_.show(supportsPairing).then(function(/** string */ pin) { | 111 that.pinDialog_.show(supportsPairing).then(function(/** string */ pin) { |
108 remoting.setMode(remoting.AppMode.CLIENT_CONNECTING); | 112 that.desktopActivity_.getConnectingDialog().show(); |
109 onPinFetched(pin); | 113 onPinFetched(pin); |
110 }).catch(function(/** remoting.Error */ error) { | 114 }).catch(remoting.Error.handler(function(/** remoting.Error */ error) { |
111 base.debug.assert(error.hasTag(remoting.Error.Tag.CANCELLED)); | 115 base.debug.assert(error.hasTag(remoting.Error.Tag.CANCELLED)); |
112 remoting.setMode(remoting.AppMode.HOME); | 116 remoting.setMode(remoting.AppMode.HOME); |
113 }); | 117 that.stop(); |
118 })); | |
114 }; | 119 }; |
115 | 120 |
116 return new remoting.CredentialsProvider({ | 121 return new remoting.CredentialsProvider({ |
117 fetchPin: requestPin, | 122 fetchPin: requestPin, |
118 pairingInfo: /** @type{remoting.PairingInfo} */ ( | 123 pairingInfo: /** @type{remoting.PairingInfo} */ ( |
119 base.deepCopy(host.options.pairingInfo)), | 124 base.deepCopy(host.options.pairingInfo)), |
120 fetchThirdPartyToken: fetchThirdPartyToken | 125 fetchThirdPartyToken: fetchThirdPartyToken |
121 }); | 126 }); |
122 }; | 127 }; |
123 | 128 |
124 /** | 129 /** |
125 * @param {!remoting.Error} error | 130 * @param {!remoting.Error} error |
126 */ | 131 */ |
127 remoting.Me2MeActivity.prototype.onConnectionFailed = function(error) { | 132 remoting.Me2MeActivity.prototype.onConnectionFailed = function(error) { |
128 if (error.hasTag(remoting.Error.Tag.HOST_IS_OFFLINE) && | 133 if (error.hasTag(remoting.Error.Tag.HOST_IS_OFFLINE) && |
129 this.retryOnHostOffline_) { | 134 this.retryOnHostOffline_) { |
130 var that = this; | 135 var that = this; |
131 var onHostListRefresh = function(/** boolean */ success) { | 136 var onHostListRefresh = function(/** boolean */ success) { |
132 if (success) { | 137 if (success) { |
133 // Get the host from the hostList for the refreshed JID. | 138 // Get the host from the hostList for the refreshed JID. |
134 that.host_ = remoting.hostList.getHostForId(that.host_.hostId); | 139 that.host_ = that.hostList_.getHostForId(that.host_.hostId); |
135 that.connect_(false); | 140 that.connect_(false); |
136 return; | 141 return; |
137 } | 142 } |
138 that.onError(error); | 143 that.onError(error); |
139 }; | 144 }; |
140 this.retryOnHostOffline_ = false; | 145 this.retryOnHostOffline_ = false; |
141 | 146 |
142 // The plugin will be re-created when the host finished refreshing | 147 // The plugin will be re-created when the host finished refreshing |
143 remoting.hostList.refresh(onHostListRefresh); | 148 remoting.hostList.refresh(onHostListRefresh); |
Jamie
2015/04/24 17:59:18
this.hostList_?
kelvinp
2015/04/24 19:03:52
Done.
| |
144 } else { | 149 } else if (!error.isNone()) { |
145 this.onError(error); | 150 this.onError(error); |
146 } | 151 } |
152 | |
153 base.dispose(this.desktopActivity_); | |
154 this.desktopActivity_ = null; | |
147 }; | 155 }; |
148 | 156 |
149 /** | 157 /** |
150 * @param {!remoting.ConnectionInfo} connectionInfo | 158 * @param {!remoting.ConnectionInfo} connectionInfo |
151 */ | 159 */ |
152 remoting.Me2MeActivity.prototype.onConnected = function(connectionInfo) { | 160 remoting.Me2MeActivity.prototype.onConnected = function(connectionInfo) { |
153 // Reset the refresh flag so that the next connection will retry if needed. | 161 // Reset the refresh flag so that the next connection will retry if needed. |
154 this.retryOnHostOffline_ = true; | 162 this.retryOnHostOffline_ = true; |
155 | 163 |
156 var plugin = connectionInfo.plugin(); | 164 var plugin = connectionInfo.plugin(); |
157 if (plugin.hasCapability(remoting.ClientSession.Capability.CAST)) { | 165 if (plugin.hasCapability(remoting.ClientSession.Capability.CAST)) { |
158 plugin.extensions().register(new remoting.CastExtensionHandler()); | 166 plugin.extensions().register(new remoting.CastExtensionHandler()); |
159 } | 167 } |
160 plugin.extensions().register(new remoting.GnubbyAuthHandler()); | 168 plugin.extensions().register(new remoting.GnubbyAuthHandler()); |
161 this.pinDialog_.requestPairingIfNecessary(connectionInfo.plugin()); | 169 this.pinDialog_.requestPairingIfNecessary(connectionInfo.plugin()); |
162 | 170 |
163 base.dispose(this.reconnector_); | 171 base.dispose(this.reconnector_); |
164 this.reconnector_ = new remoting.SmartReconnector( | 172 this.reconnector_ = new remoting.SmartReconnector( |
173 this.desktopActivity_.getConnectingDialog(), | |
165 this.connect_.bind(this, false), | 174 this.connect_.bind(this, false), |
166 this.stop.bind(this), | 175 this.stop.bind(this), |
167 connectionInfo.session()); | 176 connectionInfo.session()); |
168 }; | 177 }; |
169 | 178 |
170 remoting.Me2MeActivity.prototype.onDisconnected = function() { | 179 remoting.Me2MeActivity.prototype.onDisconnected = function() { |
171 this.showFinishDialog_(remoting.AppMode.CLIENT_SESSION_FINISHED_ME2ME); | 180 this.showFinishDialog_(remoting.AppMode.CLIENT_SESSION_FINISHED_ME2ME); |
172 }; | 181 }; |
173 | 182 |
174 /** | 183 /** |
(...skipping 19 matching lines...) Expand all Loading... | |
194 var Result = remoting.MessageDialog.Result; | 203 var Result = remoting.MessageDialog.Result; |
195 var that = this; | 204 var that = this; |
196 | 205 |
197 dialog.show().then(function(/** Result */result) { | 206 dialog.show().then(function(/** Result */result) { |
198 if (result === Result.PRIMARY) { | 207 if (result === Result.PRIMARY) { |
199 remoting.setMode(remoting.AppMode.HOME); | 208 remoting.setMode(remoting.AppMode.HOME); |
200 } else { | 209 } else { |
201 that.connect_(true); | 210 that.connect_(true); |
202 } | 211 } |
203 }); | 212 }); |
213 | |
214 base.dispose(this.desktopActivity_); | |
215 this.desktopActivity_ = null; | |
204 }; | 216 }; |
205 | 217 |
206 /** | 218 /** |
207 * @param {HTMLElement} rootElement | 219 * @param {HTMLElement} rootElement |
208 * @param {remoting.Host} host | 220 * @param {remoting.Host} host |
209 * @constructor | 221 * @constructor |
210 */ | 222 */ |
211 remoting.HostNeedsUpdateDialog = function(rootElement, host) { | 223 remoting.HostNeedsUpdateDialog = function(rootElement, host) { |
212 /** @private */ | 224 /** @private */ |
213 this.host_ = host; | 225 this.host_ = host; |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
313 clientName = 'Linux'; | 325 clientName = 'Linux'; |
314 } else { | 326 } else { |
315 console.log('Unrecognized client platform. Using navigator.platform.'); | 327 console.log('Unrecognized client platform. Using navigator.platform.'); |
316 clientName = navigator.platform; | 328 clientName = navigator.platform; |
317 } | 329 } |
318 plugin.requestPairing(clientName, onPairingComplete); | 330 plugin.requestPairing(clientName, onPairingComplete); |
319 } | 331 } |
320 }; | 332 }; |
321 | 333 |
322 })(); | 334 })(); |
OLD | NEW |