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 'use strict'; | 5 'use strict'; |
6 | 6 |
7 /** @suppress {duplicate} */ | 7 /** @suppress {duplicate} */ |
8 var remoting = remoting || {}; | 8 var remoting = remoting || {}; |
9 | 9 |
10 (function() { | 10 (function() { |
(...skipping 20 matching lines...) Expand all Loading... |
31 | 31 |
32 /** @private {?function(remoting.SignalStrategy.State):void} */ | 32 /** @private {?function(remoting.SignalStrategy.State):void} */ |
33 this.onStateChangedCallback_ = null; | 33 this.onStateChangedCallback_ = null; |
34 | 34 |
35 /** @private */ | 35 /** @private */ |
36 this.state_ = remoting.SignalStrategy.State.NOT_CONNECTED; | 36 this.state_ = remoting.SignalStrategy.State.NOT_CONNECTED; |
37 | 37 |
38 /** @private */ | 38 /** @private */ |
39 this.blackholeState_ = BlackholeState.PENDING; | 39 this.blackholeState_ = BlackholeState.PENDING; |
40 | 40 |
41 /** @private {?XMLHttpRequest} */ | 41 /** @private {?remoting.Xhr} */ |
42 this.xhr_ = null; | 42 this.xhr_ = null; |
43 }; | 43 }; |
44 | 44 |
45 /** | 45 /** |
46 * @const | 46 * @const |
47 * @private | 47 * @private |
48 */ | 48 */ |
49 remoting.DnsBlackholeChecker.URL_TO_REQUEST_ = | 49 remoting.DnsBlackholeChecker.URL_TO_REQUEST_ = |
50 "https://chromoting-client.talkgadget.google.com/talkgadget/oauth/" + | 50 "https://chromoting-client.talkgadget.google.com/talkgadget/oauth/" + |
51 "chrome-remote-desktop-client"; | 51 "chrome-remote-desktop-client"; |
(...skipping 26 matching lines...) Expand all Loading... |
78 * @param {string} username | 78 * @param {string} username |
79 * @param {string} authToken | 79 * @param {string} authToken |
80 */ | 80 */ |
81 remoting.DnsBlackholeChecker.prototype.connect = function(server, | 81 remoting.DnsBlackholeChecker.prototype.connect = function(server, |
82 username, | 82 username, |
83 authToken) { | 83 authToken) { |
84 base.debug.assert(this.onStateChangedCallback_ != null); | 84 base.debug.assert(this.onStateChangedCallback_ != null); |
85 | 85 |
86 this.signalStrategy_.connect(server, username, authToken); | 86 this.signalStrategy_.connect(server, username, authToken); |
87 | 87 |
88 this.xhr_ = remoting.xhr.start({ | 88 this.xhr_ = new remoting.Xhr({ |
89 method: 'GET', | 89 method: 'GET', |
90 url: remoting.DnsBlackholeChecker.URL_TO_REQUEST_, | 90 url: remoting.DnsBlackholeChecker.URL_TO_REQUEST_ |
91 onDone: this.onHttpRequestDone_.bind(this) | |
92 }); | 91 }); |
| 92 this.xhr_.then(this.onHttpRequestDone_.bind(this)); |
93 }; | 93 }; |
94 | 94 |
95 remoting.DnsBlackholeChecker.prototype.getState = function() { | 95 remoting.DnsBlackholeChecker.prototype.getState = function() { |
96 return this.state_; | 96 return this.state_; |
97 }; | 97 }; |
98 | 98 |
99 remoting.DnsBlackholeChecker.prototype.getError = function() { | 99 remoting.DnsBlackholeChecker.prototype.getError = function() { |
100 if (this.blackholeState_ == BlackholeState.BLOCKED) { | 100 if (this.blackholeState_ == BlackholeState.BLOCKED) { |
101 return remoting.Error.NOT_AUTHORIZED; | 101 return remoting.Error.NOT_AUTHORIZED; |
102 } | 102 } |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 case BlackholeState.OPEN: | 146 case BlackholeState.OPEN: |
147 this.setState_(state); | 147 this.setState_(state); |
148 break; | 148 break; |
149 case BlackholeState.BLOCKED: | 149 case BlackholeState.BLOCKED: |
150 // In case DNS blackhole is active the external state stays FAILED. | 150 // In case DNS blackhole is active the external state stays FAILED. |
151 break; | 151 break; |
152 } | 152 } |
153 }; | 153 }; |
154 | 154 |
155 /** | 155 /** |
156 * @param {XMLHttpRequest} xhr | 156 * @param {remoting.Xhr.Response} xhrr |
157 * @private | 157 * @private |
158 */ | 158 */ |
159 remoting.DnsBlackholeChecker.prototype.onHttpRequestDone_ = function(xhr) { | 159 remoting.DnsBlackholeChecker.prototype.onHttpRequestDone_ = function(xhrr) { |
160 this.xhr_ = null; | 160 this.xhr_ = null; |
161 if (xhr.status >= 200 && xhr.status <= 299) { | 161 if (xhrr.status >= 200 && xhrr.status <= 299) { |
162 console.log("DNS blackhole check succeeded."); | 162 console.log("DNS blackhole check succeeded."); |
163 this.blackholeState_ = BlackholeState.OPEN; | 163 this.blackholeState_ = BlackholeState.OPEN; |
164 if (this.signalStrategy_.getState() == | 164 if (this.signalStrategy_.getState() == |
165 remoting.SignalStrategy.State.CONNECTED) { | 165 remoting.SignalStrategy.State.CONNECTED) { |
166 this.setState_(remoting.SignalStrategy.State.CONNECTED); | 166 this.setState_(remoting.SignalStrategy.State.CONNECTED); |
167 } | 167 } |
168 } else { | 168 } else { |
169 console.error("DNS blackhole check failed: " + xhr.status + " " + | 169 console.error("DNS blackhole check failed: " + xhrr.status + " " + |
170 xhr.statusText + ". Response URL: " + xhr.responseURL + | 170 xhrr.statusText + ". Response URL: " + xhrr.responseUrl + |
171 ". Response Text: " + xhr.responseText); | 171 ". Response Text: " + xhrr.responseText); |
172 this.blackholeState_ = BlackholeState.BLOCKED; | 172 this.blackholeState_ = BlackholeState.BLOCKED; |
173 base.dispose(this.signalStrategy_); | 173 base.dispose(this.signalStrategy_); |
174 this.setState_(remoting.SignalStrategy.State.FAILED); | 174 this.setState_(remoting.SignalStrategy.State.FAILED); |
175 } | 175 } |
176 } | 176 }; |
177 | 177 |
178 /** | 178 /** |
179 * @param {remoting.SignalStrategy.State} newState | 179 * @param {remoting.SignalStrategy.State} newState |
180 * @private | 180 * @private |
181 */ | 181 */ |
182 remoting.DnsBlackholeChecker.prototype.setState_ = function(newState) { | 182 remoting.DnsBlackholeChecker.prototype.setState_ = function(newState) { |
183 if (this.state_ != newState) { | 183 if (this.state_ != newState) { |
184 this.state_ = newState; | 184 this.state_ = newState; |
185 this.onStateChangedCallback_(this.state_); | 185 this.onStateChangedCallback_(this.state_); |
186 } | 186 } |
187 }; | 187 }; |
188 | 188 |
189 }()); | 189 }()); |
OLD | NEW |