| 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 * Class representing the application's context menu. | 7 * Class representing the application's context menu. |
| 8 */ | 8 */ |
| 9 | 9 |
| 10 'use strict'; | 10 'use strict'; |
| 11 | 11 |
| 12 /** @suppress {duplicate} */ | 12 /** @suppress {duplicate} */ |
| 13 var remoting = remoting || {}; | 13 var remoting = remoting || {}; |
| 14 | 14 |
| 15 /** | 15 /** |
| 16 * @param {remoting.ContextMenuAdapter} adapter | 16 * @param {remoting.ContextMenuAdapter} adapter |
| 17 * @param {remoting.ClientPlugin} plugin |
| 17 * @constructor | 18 * @constructor |
| 19 * @implements {base.Disposable} |
| 18 */ | 20 */ |
| 19 remoting.ApplicationContextMenu = function(adapter) { | 21 remoting.ApplicationContextMenu = function(adapter, plugin) { |
| 20 /** @private {remoting.ContextMenuAdapter} */ | 22 /** @private {remoting.ContextMenuAdapter} */ |
| 21 this.adapter_ = adapter; | 23 this.adapter_ = adapter; |
| 22 | 24 |
| 23 this.adapter_.create( | 25 this.adapter_.create( |
| 24 remoting.ApplicationContextMenu.kSendFeedbackId, | 26 remoting.ApplicationContextMenu.kSendFeedbackId, |
| 25 l10n.getTranslationOrError(/*i18n-content*/'SEND_FEEDBACK'), | 27 l10n.getTranslationOrError(/*i18n-content*/'SEND_FEEDBACK'), |
| 26 false); | 28 false); |
| 27 this.adapter_.create( | 29 this.adapter_.create( |
| 28 remoting.ApplicationContextMenu.kShowStatsId, | 30 remoting.ApplicationContextMenu.kShowStatsId, |
| 29 l10n.getTranslationOrError(/*i18n-content*/'SHOW_STATS'), | 31 l10n.getTranslationOrError(/*i18n-content*/'SHOW_STATS'), |
| 30 true); | 32 true); |
| 33 |
| 34 // TODO(kelvinp):Unhook this event on shutdown. |
| 31 this.adapter_.addListener(this.onClicked_.bind(this)); | 35 this.adapter_.addListener(this.onClicked_.bind(this)); |
| 32 | 36 |
| 33 /** @private {string} */ | 37 /** @private {string} */ |
| 34 this.hostId_ = ''; | 38 this.hostId_ = ''; |
| 39 |
| 40 /** @private */ |
| 41 this.stats_ = new remoting.ConnectionStats( |
| 42 document.getElementById('statistics'), plugin); |
| 43 }; |
| 44 |
| 45 remoting.ApplicationContextMenu.prototype.dispose = function() { |
| 46 base.dispose(this.stats_); |
| 47 this.stats_ = null; |
| 35 }; | 48 }; |
| 36 | 49 |
| 37 /** | 50 /** |
| 38 * @param {string} hostId | 51 * @param {string} hostId |
| 39 */ | 52 */ |
| 40 remoting.ApplicationContextMenu.prototype.setHostId = function(hostId) { | 53 remoting.ApplicationContextMenu.prototype.setHostId = function(hostId) { |
| 41 this.hostId_ = hostId; | 54 this.hostId_ = hostId; |
| 42 } | 55 }; |
| 43 | 56 |
| 44 /** | 57 /** |
| 45 * Add an indication of the connection RTT to the 'Show statistics' menu item. | 58 * Add an indication of the connection RTT to the 'Show statistics' menu item. |
| 46 * | 59 * |
| 47 * @param {number} rttMs The RTT of the connection, in ms. | 60 * @param {number} rttMs The RTT of the connection, in ms. |
| 48 */ | 61 */ |
| 49 remoting.ApplicationContextMenu.prototype.updateConnectionRTT = | 62 remoting.ApplicationContextMenu.prototype.updateConnectionRTT = |
| 50 function(rttMs) { | 63 function(rttMs) { |
| 51 var rttText = | 64 var rttText = |
| 52 rttMs < 50 ? /*i18n-content*/'CONNECTION_QUALITY_GOOD' : | 65 rttMs < 50 ? /*i18n-content*/'CONNECTION_QUALITY_GOOD' : |
| (...skipping 21 matching lines...) Expand all Loading... |
| 74 | 87 |
| 75 /** @type {remoting.ApplicationContextMenu} */ | 88 /** @type {remoting.ApplicationContextMenu} */ |
| 76 var that = this; | 89 var that = this; |
| 77 | 90 |
| 78 /** @param {AppWindow} consentWindow */ | 91 /** @param {AppWindow} consentWindow */ |
| 79 var onCreate = function(consentWindow) { | 92 var onCreate = function(consentWindow) { |
| 80 var onLoad = function() { | 93 var onLoad = function() { |
| 81 var message = { | 94 var message = { |
| 82 method: 'init', | 95 method: 'init', |
| 83 hostId: that.hostId_, | 96 hostId: that.hostId_, |
| 84 connectionStats: JSON.stringify(remoting.stats.mostRecent()) | 97 connectionStats: JSON.stringify(that.stats_.mostRecent()) |
| 85 }; | 98 }; |
| 86 consentWindow.contentWindow.postMessage(message, '*'); | 99 consentWindow.contentWindow.postMessage(message, '*'); |
| 87 }; | 100 }; |
| 88 consentWindow.contentWindow.addEventListener('load', onLoad, false); | 101 consentWindow.contentWindow.addEventListener('load', onLoad, false); |
| 89 }; | 102 }; |
| 90 chrome.app.window.create( | 103 chrome.app.window.create( |
| 91 'feedback_consent.html', windowAttributes, onCreate); | 104 'feedback_consent.html', windowAttributes, onCreate); |
| 92 break; | 105 break; |
| 93 | 106 |
| 94 case remoting.ApplicationContextMenu.kShowStatsId: | 107 case remoting.ApplicationContextMenu.kShowStatsId: |
| 95 if (remoting.stats) { | 108 this.stats_.show(info.checked); |
| 96 remoting.stats.show(info.checked); | |
| 97 } | |
| 98 break; | 109 break; |
| 99 } | 110 } |
| 100 }; | 111 }; |
| 101 | 112 |
| 102 | 113 |
| 103 /** @type {string} */ | 114 /** @type {string} */ |
| 104 remoting.ApplicationContextMenu.kSendFeedbackId = 'send-feedback'; | 115 remoting.ApplicationContextMenu.kSendFeedbackId = 'send-feedback'; |
| 105 | 116 |
| 106 /** @type {string} */ | 117 /** @type {string} */ |
| 107 remoting.ApplicationContextMenu.kShowStatsId = 'show-stats'; | 118 remoting.ApplicationContextMenu.kShowStatsId = 'show-stats'; |
| OLD | NEW |