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 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
268 this.connectToHost_.bind(this, email), | 268 this.connectToHost_.bind(this, email), |
269 this.sendErrorResponse_.bind(this, message) | 269 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 when the user clicks accept on the | 278 * @return {Promise} A promise that resolves to a boolean value, indicating |
279 * dialog. | 279 * whether the user accepts the remote assistance or not. |
280 * @private | 280 * @private |
281 */ | 281 */ |
282 remoting.It2MeHelpeeChannel.prototype.showConfirmDialog_ = function() { | 282 remoting.It2MeHelpeeChannel.prototype.showConfirmDialog_ = function() { |
| 283 if (base.isAppsV2()) { |
| 284 return this.showConfirmDialogV2_(); |
| 285 } else { |
| 286 return this.showConfirmDialogV1_(); |
| 287 } |
| 288 }; |
| 289 |
| 290 /** |
| 291 * @return {Promise} A promise that resolves to a boolean value, indicating |
| 292 * whether the user accepts the remote assistance or not. |
| 293 * @private |
| 294 */ |
| 295 remoting.It2MeHelpeeChannel.prototype.showConfirmDialogV1_ = function() { |
| 296 var messageHeader = l10n.getTranslationOrError( |
| 297 /*i18n-content*/'HANGOUTS_CONFIRM_DIALOG_MESSAGE_1'); |
| 298 var message1 = l10n.getTranslationOrError( |
| 299 /*i18n-content*/'HANGOUTS_CONFIRM_DIALOG_MESSAGE_2'); |
| 300 var message2 = l10n.getTranslationOrError( |
| 301 /*i18n-content*/'HANGOUTS_CONFIRM_DIALOG_MESSAGE_3'); |
| 302 var message = base.escapeHTML(messageHeader) + '\n' + |
| 303 '- ' + base.escapeHTML(message1) + '\n' + |
| 304 '- ' + base.escapeHTML(message2) + '\n'; |
| 305 |
| 306 if(window.confirm(message)) { |
| 307 return Promise.resolve(); |
| 308 } else { |
| 309 return Promise.reject(new Error(remoting.Error.CANCELLED)); |
| 310 } |
| 311 }; |
| 312 |
| 313 /** |
| 314 * @return {Promise} A promise that resolves to a boolean value, indicating |
| 315 * whether the user accepts the remote assistance or not. |
| 316 * @private |
| 317 */ |
| 318 remoting.It2MeHelpeeChannel.prototype.showConfirmDialogV2_ = function() { |
| 319 var messageHeader = l10n.getTranslationOrError( |
| 320 /*i18n-content*/'HANGOUTS_CONFIRM_DIALOG_MESSAGE_1'); |
| 321 var message1 = l10n.getTranslationOrError( |
| 322 /*i18n-content*/'HANGOUTS_CONFIRM_DIALOG_MESSAGE_2'); |
| 323 var message2 = l10n.getTranslationOrError( |
| 324 /*i18n-content*/'HANGOUTS_CONFIRM_DIALOG_MESSAGE_3'); |
| 325 var message = '<div>' + base.escapeHTML(messageHeader) + '</div>' + |
| 326 '<ul class="insetList">' + |
| 327 '<li>' + base.escapeHTML(message1) + '</li>' + |
| 328 '<li>' + base.escapeHTML(message2) + '</li>' + |
| 329 '</ul>'; |
283 /** | 330 /** |
284 * @param {function(*=):void} resolve | 331 * @param {function(*=):void} resolve |
285 * @param {function(*=):void} reject | 332 * @param {function(*=):void} reject |
286 */ | 333 */ |
287 return new Promise(function(resolve, reject) { | 334 return new Promise(function(resolve, reject) { |
288 // TODO(kelvinp): The existing implementation doesn't work in the v2 app as | 335 /** @param {number} result */ |
289 // window.confirm is blacklisted. Implement the dialog using | 336 function confirmDialogCallback(result) { |
290 // chrome.app.window instead (crbug.com/405139). | 337 if (result === 1) { |
291 if (base.isAppsV2()) { | 338 resolve(); |
292 resolve(); | 339 } else { |
293 // The unlocalized string will be replaced in (crbug.com/405139). | 340 reject(new Error(remoting.Error.CANCELLED)); |
294 } else if (window.confirm('Accept help?')) { | 341 } |
295 resolve(); | |
296 } else { | |
297 reject(new Error(remoting.Error.CANCELLED)); | |
298 } | 342 } |
| 343 remoting.MessageWindow.showConfirmWindow( |
| 344 '', // Empty string to use the package name as the dialog title. |
| 345 message, |
| 346 l10n.getTranslationOrError( |
| 347 /*i18n-content*/'HANGOUTS_CONFIRM_DIALOG_ACCEPT'), |
| 348 l10n.getTranslationOrError( |
| 349 /*i18n-content*/'HANGOUTS_CONFIRM_DIALOG_DECLINE'), |
| 350 confirmDialogCallback |
| 351 ); |
299 }); | 352 }); |
300 }; | 353 }; |
301 | 354 |
302 /** | 355 /** |
303 * @return {Promise} A promise that resolves when the host is initialized. | 356 * @return {Promise} A promise that resolves when the host is initialized. |
304 * @private | 357 * @private |
305 */ | 358 */ |
306 remoting.It2MeHelpeeChannel.prototype.initializeHost_ = function() { | 359 remoting.It2MeHelpeeChannel.prototype.initializeHost_ = function() { |
307 /** @type {remoting.It2MeHostFacade} */ | 360 /** @type {remoting.It2MeHostFacade} */ |
308 var host = this.host_; | 361 var host = this.host_; |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
419 | 472 |
420 console.error('Error responding to message method:' + | 473 console.error('Error responding to message method:' + |
421 (incomingMessage ? incomingMessage.method : 'null') + | 474 (incomingMessage ? incomingMessage.method : 'null') + |
422 ' error:' + error); | 475 ' error:' + error); |
423 this.hangoutPort_.postMessage({ | 476 this.hangoutPort_.postMessage({ |
424 method: remoting.It2MeHelpeeChannel.HangoutMessageTypes.ERROR, | 477 method: remoting.It2MeHelpeeChannel.HangoutMessageTypes.ERROR, |
425 message: error, | 478 message: error, |
426 request: incomingMessage | 479 request: incomingMessage |
427 }); | 480 }); |
428 }; | 481 }; |
OLD | NEW |