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 /** | 8 /** |
9 * Type definition for the RunApplicationResponse returned by the API. | 9 * Type definition for the RunApplicationResponse returned by the API. |
10 * @typedef {{ | 10 * @typedef {{ |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 {fetchThirdPartyToken: fetchThirdPartyToken}); | 133 {fetchThirdPartyToken: fetchThirdPartyToken}); |
134 var that = this; | 134 var that = this; |
135 | 135 |
136 this.sessionFactory_.createSession(this).then( | 136 this.sessionFactory_.createSession(this).then( |
137 function(/** remoting.ClientSession */ session) { | 137 function(/** remoting.ClientSession */ session) { |
138 that.session_ = session; | 138 that.session_ = session; |
139 session.logHostOfflineErrors(true); | 139 session.logHostOfflineErrors(true); |
140 session.connect(host, credentialsProvider); | 140 session.connect(host, credentialsProvider); |
141 }); | 141 }); |
142 } else if (response && response.status == 'pending') { | 142 } else if (response && response.status == 'pending') { |
143 this.onError(new remoting.Error( | 143 this.onConnectionFailed(new remoting.Error( |
144 remoting.Error.Tag.SERVICE_UNAVAILABLE)); | 144 remoting.Error.Tag.SERVICE_UNAVAILABLE)); |
145 } | 145 } |
146 } else { | 146 } else { |
147 console.error('Invalid "runApplication" response from server.'); | 147 console.error('Invalid "runApplication" response from server.'); |
148 this.onError(remoting.Error.fromHttpStatus(xhrResponse.status)); | 148 // The orchestrator returns 403 if the user is not whitelisted to run the |
| 149 // app, which gets translated to a generic error message, so pick something |
| 150 // a bit more user-friendly. |
| 151 var error = xhrResponse.status == 403 ? |
| 152 new remoting.Error(remoting.Error.Tag.APP_NOT_AUTHORIZED) : |
| 153 remoting.Error.fromHttpStatus(xhrResponse.status); |
| 154 this.onConnectionFailed(error); |
149 } | 155 } |
150 }; | 156 }; |
151 | 157 |
152 /** | 158 /** |
153 * @param {remoting.ConnectionInfo} connectionInfo | 159 * @param {remoting.ConnectionInfo} connectionInfo |
154 */ | 160 */ |
155 remoting.AppRemotingActivity.prototype.onConnected = function(connectionInfo) { | 161 remoting.AppRemotingActivity.prototype.onConnected = function(connectionInfo) { |
156 this.connectedView_ = new remoting.AppConnectedView( | 162 this.connectedView_ = new remoting.AppConnectedView( |
157 document.getElementById('client-container'), connectionInfo); | 163 document.getElementById('client-container'), connectionInfo); |
158 | 164 |
159 var idleDetector = new remoting.IdleDetector( | 165 var idleDetector = new remoting.IdleDetector( |
160 document.getElementById('idle-dialog'), this.stop.bind(this)); | 166 document.getElementById('idle-dialog'), this.stop.bind(this)); |
161 | 167 |
162 // Map Cmd to Ctrl on Mac since hosts typically use Ctrl for keyboard | 168 // Map Cmd to Ctrl on Mac since hosts typically use Ctrl for keyboard |
163 // shortcuts, but we want them to act as natively as possible. | 169 // shortcuts, but we want them to act as natively as possible. |
164 if (remoting.platformIsMac()) { | 170 if (remoting.platformIsMac()) { |
165 connectionInfo.plugin().setRemapKeys('0x0700e3>0x0700e0,0x0700e7>0x0700e4'); | 171 connectionInfo.plugin().setRemapKeys('0x0700e3>0x0700e0,0x0700e7>0x0700e4'); |
166 } | 172 } |
167 }; | 173 }; |
168 | 174 |
169 remoting.AppRemotingActivity.prototype.onDisconnected = function() { | 175 /** |
| 176 * @param {remoting.Error} error |
| 177 */ |
| 178 remoting.AppRemotingActivity.prototype.onDisconnected = function(error) { |
| 179 if (error.isNone()) { |
| 180 chrome.app.window.current().close(); |
| 181 } else { |
| 182 this.showErrorMessage_(error); |
| 183 } |
170 this.cleanup_(); | 184 this.cleanup_(); |
171 chrome.app.window.current().close(); | |
172 }; | 185 }; |
173 | 186 |
174 /** | 187 /** |
175 * @param {!remoting.Error} error | 188 * @param {!remoting.Error} error |
176 */ | 189 */ |
177 remoting.AppRemotingActivity.prototype.onConnectionFailed = function(error) { | 190 remoting.AppRemotingActivity.prototype.onConnectionFailed = function(error) { |
178 this.onError(error); | 191 remoting.LoadingWindow.close(); |
| 192 this.showErrorMessage_(error); |
| 193 this.cleanup_(); |
179 }; | 194 }; |
180 | 195 |
181 /** | 196 /** |
182 * @param {!remoting.Error} error The error to be localized and displayed. | 197 * @param {!remoting.Error} error The error to be localized and displayed. |
| 198 * @private |
183 */ | 199 */ |
184 remoting.AppRemotingActivity.prototype.onError = function(error) { | 200 remoting.AppRemotingActivity.prototype.showErrorMessage_ = function(error) { |
185 console.error('Connection failed: ' + error.toString()); | 201 console.error('Connection failed: ' + error.toString()); |
186 remoting.LoadingWindow.close(); | |
187 remoting.MessageWindow.showErrorMessage( | 202 remoting.MessageWindow.showErrorMessage( |
188 chrome.i18n.getMessage(/*i18n-content*/'CONNECTION_FAILED'), | 203 remoting.app.getApplicationName(), |
189 chrome.i18n.getMessage(error.getTag())); | 204 chrome.i18n.getMessage(error.getTag())); |
190 this.cleanup_(); | |
191 }; | 205 }; |
192 | 206 |
193 })(); | 207 })(); |
OLD | NEW |