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
3 // found in the LICENSE file.
7 * Class representing the application's context menu.
12 /** @suppress {duplicate} */
13 var remoting
= remoting
|| {};
16 * @param {remoting.ContextMenuAdapter} adapter
19 remoting
.ApplicationContextMenu = function(adapter
) {
21 * @type {remoting.ContextMenuAdapter}
24 this.adapter_
= adapter
;
27 remoting
.ApplicationContextMenu
.kSendFeedbackId
,
28 l10n
.getTranslationOrError(/*i18n-content*/'SEND_FEEDBACK'),
31 remoting
.ApplicationContextMenu
.kShowStatsId
,
32 l10n
.getTranslationOrError(/*i18n-content*/'SHOW_STATS'),
34 this.adapter_
.addListener(this.onClicked_
.bind(this));
44 * @param {string} hostId
46 remoting
.ApplicationContextMenu
.prototype.setHostId = function(hostId
) {
47 this.hostId_
= hostId
;
51 * Add an indication of the connection RTT to the 'Show statistics' menu item.
53 * @param {number} rttMs The RTT of the connection, in ms.
55 remoting
.ApplicationContextMenu
.prototype.updateConnectionRTT
=
58 rttMs
< 50 ? /*i18n-content*/'CONNECTION_QUALITY_GOOD' :
59 rttMs
< 100 ? /*i18n-content*/'CONNECTION_QUALITY_FAIR' :
60 /*i18n-content*/'CONNECTION_QUALITY_POOR';
61 rttText
= l10n
.getTranslationOrError(rttText
);
62 this.adapter_
.updateTitle(
63 remoting
.ApplicationContextMenu
.kShowStatsId
,
64 l10n
.getTranslationOrError(/*i18n-content*/'SHOW_STATS_WITH_RTT',
68 /** @param {OnClickData=} info */
69 remoting
.ApplicationContextMenu
.prototype.onClicked_ = function(info
) {
70 switch (info
.menuItemId
) {
72 case remoting
.ApplicationContextMenu
.kSendFeedbackId
:
73 var windowAttributes
= {
81 /** @type {remoting.ApplicationContextMenu} */
84 /** @param {AppWindow} consentWindow */
85 var onCreate = function(consentWindow
) {
86 var onLoad = function() {
90 connectionStats
: JSON
.stringify(remoting
.stats
.mostRecent())
92 consentWindow
.contentWindow
.postMessage(message
, '*');
94 consentWindow
.contentWindow
.addEventListener('load', onLoad
, false);
96 chrome
.app
.window
.create(
97 'feedback_consent.html', windowAttributes
, onCreate
);
100 case remoting
.ApplicationContextMenu
.kShowStatsId
:
101 if (remoting
.stats
) {
102 remoting
.stats
.show(info
.checked
);
109 /** @type {string} */
110 remoting
.ApplicationContextMenu
.kSendFeedbackId
= 'send-feedback';
112 /** @type {string} */
113 remoting
.ApplicationContextMenu
.kShowStatsId
= 'show-stats';