OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 /** | 5 /** |
6 * @fileoverview | 6 * @fileoverview |
7 * | 7 * |
8 * It2MeHelpeeChannel relays messages between the Hangouts web page (Hangouts) | 8 * It2MeHelpeeChannel relays messages between the Hangouts web page (Hangouts) |
9 * and the It2Me Native Messaging Host (It2MeHost) for the helpee (the Hangouts | 9 * and the It2Me Native Messaging Host (It2MeHost) for the helpee (the Hangouts |
10 * participant who is receiving remoting assistance). | 10 * participant who is receiving remoting assistance). |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 this.handleDownloadHost_(message); | 181 this.handleDownloadHost_(message); |
182 return true; | 182 return true; |
183 case MessageTypes.CONNECT: | 183 case MessageTypes.CONNECT: |
184 this.handleConnect_(message); | 184 this.handleConnect_(message); |
185 return true; | 185 return true; |
186 case MessageTypes.DISCONNECT: | 186 case MessageTypes.DISCONNECT: |
187 this.dispose(); | 187 this.dispose(); |
188 return true; | 188 return true; |
189 } | 189 } |
190 throw new Error('Unsupported message method=' + message.method); | 190 throw new Error('Unsupported message method=' + message.method); |
191 } catch(e) { | 191 } catch(/** @type {*} */ e) { |
192 var error = /** @type {Error} */ e; | 192 var error = /** @type {Error} */ (e); |
193 this.sendErrorResponse_(message, error.message); | 193 this.sendErrorResponse_(message, error.message); |
194 } | 194 } |
195 return false; | 195 return false; |
196 }; | 196 }; |
197 | 197 |
198 /** | 198 /** |
199 * Queries the |hostInstaller| for the installation status. | 199 * Queries the |hostInstaller| for the installation status. |
200 * | 200 * |
201 * @param {{method:string, data:Object.<string,*>}} message | 201 * @param {{method:string, data:Object.<string,*>}} message |
202 * @private | 202 * @private |
203 */ | 203 */ |
204 remoting.It2MeHelpeeChannel.prototype.handleIsHostInstalled_ = | 204 remoting.It2MeHelpeeChannel.prototype.handleIsHostInstalled_ = |
205 function(message) { | 205 function(message) { |
206 /** @type {remoting.It2MeHelpeeChannel} */ | 206 /** @type {remoting.It2MeHelpeeChannel} */ |
207 var that = this; | 207 var that = this; |
208 | 208 |
209 /** @param {boolean} installed */ | 209 /** @param {boolean} installed */ |
210 function sendResponse(installed) { | 210 function sendResponse(installed) { |
211 var MessageTypes = remoting.It2MeHelpeeChannel.HangoutMessageTypes; | 211 var MessageTypes = remoting.It2MeHelpeeChannel.HangoutMessageTypes; |
212 that.hangoutPort_.postMessage({ | 212 that.hangoutPort_.postMessage({ |
213 method: MessageTypes.IS_HOST_INSTALLED_RESPONSE, | 213 method: MessageTypes.IS_HOST_INSTALLED_RESPONSE, |
214 result: installed | 214 result: installed |
215 }); | 215 }); |
216 } | 216 } |
217 | 217 |
218 this.hostInstaller_.isInstalled().then( | 218 this.hostInstaller_.isInstalled().then( |
219 sendResponse, | 219 sendResponse, |
220 this.sendErrorResponse_.bind(this, message) | 220 /** @type {function(*):void} */(this.sendErrorResponse_.bind(this, message)) |
221 ); | 221 ); |
222 }; | 222 }; |
223 | 223 |
224 /** | 224 /** |
225 * @param {{method:string, data:Object.<string,*>}} message | 225 * @param {{method:string, data:Object.<string,*>}} message |
226 * @private | 226 * @private |
227 */ | 227 */ |
228 remoting.It2MeHelpeeChannel.prototype.handleDownloadHost_ = function(message) { | 228 remoting.It2MeHelpeeChannel.prototype.handleDownloadHost_ = function(message) { |
229 try { | 229 try { |
230 this.hostInstaller_.download(); | 230 this.hostInstaller_.download(); |
231 } catch (e) { | 231 } catch (/** @type {*} */ e) { |
232 var error = /** @type {Error} */ e; | 232 var error = /** @type {Error} */ (e); |
233 this.sendErrorResponse_(message, error.message); | 233 this.sendErrorResponse_(message, error.message); |
234 } | 234 } |
235 }; | 235 }; |
236 | 236 |
237 /** | 237 /** |
238 * Disconnect the session if the |hangoutPort| gets disconnected. | 238 * Disconnect the session if the |hangoutPort| gets disconnected. |
239 * @private | 239 * @private |
240 */ | 240 */ |
241 remoting.It2MeHelpeeChannel.prototype.onHangoutDisconnect_ = function() { | 241 remoting.It2MeHelpeeChannel.prototype.onHangoutDisconnect_ = function() { |
242 this.dispose(); | 242 this.dispose(); |
(...skipping 15 matching lines...) Expand all Loading... |
258 | 258 |
259 if (this.hostState_ !== remoting.HostSession.State.UNKNOWN) { | 259 if (this.hostState_ !== remoting.HostSession.State.UNKNOWN) { |
260 throw new Error('An existing connection is in progress.'); | 260 throw new Error('An existing connection is in progress.'); |
261 } | 261 } |
262 | 262 |
263 this.showConfirmDialog_().then( | 263 this.showConfirmDialog_().then( |
264 this.initializeHost_.bind(this) | 264 this.initializeHost_.bind(this) |
265 ).then( | 265 ).then( |
266 this.fetchOAuthToken_.bind(this) | 266 this.fetchOAuthToken_.bind(this) |
267 ).then( | 267 ).then( |
268 this.connectToHost_.bind(this, email), | 268 /** @type {function(*):void} */(this.connectToHost_.bind(this, email)), |
269 this.sendErrorResponse_.bind(this, message) | 269 /** @type {function(*):void} */(this.sendErrorResponse_.bind(this, message)) |
270 ); | 270 ); |
271 }; | 271 }; |
272 | 272 |
273 /** | 273 /** |
274 * Prompts the user before starting the It2Me Native Messaging Host. This | 274 * Prompts the user before starting the It2Me Native Messaging Host. This |
275 * ensures that even if Hangouts is compromised, an attacker cannot start the | 275 * ensures that even if Hangouts is compromised, an attacker cannot start the |
276 * host without explicit user confirmation. | 276 * host without explicit user confirmation. |
277 * | 277 * |
278 * @return {Promise} A promise that resolves to a boolean value, indicating | 278 * @return {Promise} A promise that resolves to a boolean value, indicating |
279 * whether the user accepts the remote assistance or not. | 279 * whether the user accepts the remote assistance or not. |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 '<li>' + base.escapeHTML(message2) + '</li>' + | 328 '<li>' + base.escapeHTML(message2) + '</li>' + |
329 '</ul>'; | 329 '</ul>'; |
330 /** | 330 /** |
331 * @param {function(*=):void} resolve | 331 * @param {function(*=):void} resolve |
332 * @param {function(*=):void} reject | 332 * @param {function(*=):void} reject |
333 */ | 333 */ |
334 return new Promise(function(resolve, reject) { | 334 return new Promise(function(resolve, reject) { |
335 /** @param {number} result */ | 335 /** @param {number} result */ |
336 function confirmDialogCallback(result) { | 336 function confirmDialogCallback(result) { |
337 if (result === 1) { | 337 if (result === 1) { |
338 resolve(); | 338 resolve(true); |
339 } else { | 339 } else { |
340 reject(new Error(remoting.Error.CANCELLED)); | 340 reject(new Error(remoting.Error.CANCELLED)); |
341 } | 341 } |
342 } | 342 } |
343 remoting.MessageWindow.showConfirmWindow( | 343 remoting.MessageWindow.showConfirmWindow( |
344 '', // Empty string to use the package name as the dialog title. | 344 '', // Empty string to use the package name as the dialog title. |
345 message, | 345 message, |
346 l10n.getTranslationOrError( | 346 l10n.getTranslationOrError( |
347 /*i18n-content*/'HANGOUTS_CONFIRM_DIALOG_ACCEPT'), | 347 /*i18n-content*/'HANGOUTS_CONFIRM_DIALOG_ACCEPT'), |
348 l10n.getTranslationOrError( | 348 l10n.getTranslationOrError( |
(...skipping 10 matching lines...) Expand all Loading... |
359 remoting.It2MeHelpeeChannel.prototype.initializeHost_ = function() { | 359 remoting.It2MeHelpeeChannel.prototype.initializeHost_ = function() { |
360 /** @type {remoting.It2MeHostFacade} */ | 360 /** @type {remoting.It2MeHostFacade} */ |
361 var host = this.host_; | 361 var host = this.host_; |
362 | 362 |
363 /** | 363 /** |
364 * @param {function(*=):void} resolve | 364 * @param {function(*=):void} resolve |
365 * @param {function(*=):void} reject | 365 * @param {function(*=):void} reject |
366 */ | 366 */ |
367 return new Promise(function(resolve, reject) { | 367 return new Promise(function(resolve, reject) { |
368 if (host.initialized()) { | 368 if (host.initialized()) { |
369 resolve(); | 369 resolve(true); |
370 } else { | 370 } else { |
371 host.initialize(resolve, reject); | 371 host.initialize(/** @type {function(*=):void} */ (resolve), |
| 372 /** @type {function(*=):void} */ (reject)); |
372 } | 373 } |
373 }); | 374 }); |
374 }; | 375 }; |
375 | 376 |
376 /** | 377 /** |
377 * @return {Promise} Promise that resolves with the OAuth token as the value. | 378 * @return {Promise} Promise that resolves with the OAuth token as the value. |
378 */ | 379 */ |
379 remoting.It2MeHelpeeChannel.prototype.fetchOAuthToken_ = function() { | 380 remoting.It2MeHelpeeChannel.prototype.fetchOAuthToken_ = function() { |
380 if (base.isAppsV2()) { | 381 if (base.isAppsV2()) { |
381 /** | 382 /** |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
488 | 489 |
489 console.error('Error responding to message method:' + | 490 console.error('Error responding to message method:' + |
490 (incomingMessage ? incomingMessage.method : 'null') + | 491 (incomingMessage ? incomingMessage.method : 'null') + |
491 ' error:' + error); | 492 ' error:' + error); |
492 this.hangoutPort_.postMessage({ | 493 this.hangoutPort_.postMessage({ |
493 method: remoting.It2MeHelpeeChannel.HangoutMessageTypes.ERROR, | 494 method: remoting.It2MeHelpeeChannel.HangoutMessageTypes.ERROR, |
494 message: error, | 495 message: error, |
495 request: incomingMessage | 496 request: incomingMessage |
496 }); | 497 }); |
497 }; | 498 }; |
OLD | NEW |