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
17 * @param {remoting.ClientPlugin} plugin
18 * @param {remoting.ClientSession} clientSession
19 * @param {remoting.WindowShape} windowShape
22 * @implements {base.Disposable}
24 remoting
.ApplicationContextMenu = function(adapter
, plugin
, clientSession
,
27 this.adapter_
= adapter
;
30 this.clientSession_
= clientSession
;
33 remoting
.ApplicationContextMenu
.kSendFeedbackId
,
34 l10n
.getTranslationOrError(/*i18n-content*/'SEND_FEEDBACK'),
37 remoting
.ApplicationContextMenu
.kShowStatsId
,
38 l10n
.getTranslationOrError(/*i18n-content*/'SHOW_STATS'),
41 remoting
.ApplicationContextMenu
.kShowCreditsId
,
42 l10n
.getTranslationOrError(/*i18n-content*/'CREDITS'),
45 // TODO(kelvinp):Unhook this event on shutdown.
46 this.adapter_
.addListener(this.onClicked_
.bind(this));
48 /** @private {string} */
52 this.stats_
= new remoting
.ConnectionStats(
53 document
.getElementById('statistics'), plugin
, windowShape
);
56 remoting
.ApplicationContextMenu
.prototype.dispose = function() {
57 base
.dispose(this.stats_
);
62 * @param {string} hostId
64 remoting
.ApplicationContextMenu
.prototype.setHostId = function(hostId
) {
65 this.hostId_
= hostId
;
69 * Add an indication of the connection RTT to the 'Show statistics' menu item.
71 * @param {number} rttMs The RTT of the connection, in ms.
73 remoting
.ApplicationContextMenu
.prototype.updateConnectionRTT
=
76 rttMs
< 50 ? /*i18n-content*/'CONNECTION_QUALITY_GOOD' :
77 rttMs
< 100 ? /*i18n-content*/'CONNECTION_QUALITY_FAIR' :
78 /*i18n-content*/'CONNECTION_QUALITY_POOR';
79 rttText
= l10n
.getTranslationOrError(rttText
);
80 this.adapter_
.updateTitle(
81 remoting
.ApplicationContextMenu
.kShowStatsId
,
82 l10n
.getTranslationOrError(/*i18n-content*/'SHOW_STATS_WITH_RTT',
86 /** @param {OnClickData=} info */
87 remoting
.ApplicationContextMenu
.prototype.onClicked_ = function(info
) {
88 var menuId
= /** @type {string} */ (info
.menuItemId
.toString());
91 case remoting
.ApplicationContextMenu
.kSendFeedbackId
:
92 var windowAttributes
= {
102 /** @type {remoting.ApplicationContextMenu} */
105 /** @param {chrome.app.window.AppWindow} consentWindow */
106 var onCreate = function(consentWindow
) {
107 var onLoad = function() {
110 appId
: remoting
.app
.getApplicationId(),
111 hostId
: that
.hostId_
,
112 connectionStats
: JSON
.stringify(that
.stats_
.mostRecent()),
113 sessionId
: that
.clientSession_
.getLogger().getSessionId(),
114 consoleErrors
: JSON
.stringify(
115 remoting
.ConsoleWrapper
.getInstance().getHistory())
117 consentWindow
.contentWindow
.postMessage(message
, '*');
119 consentWindow
.contentWindow
.addEventListener('load', onLoad
, false);
121 chrome
.app
.window
.create(
122 '_modules/koejkfhmphamcgafjmkellhnekdkopod/feedback_consent.html',
123 windowAttributes
, onCreate
);
126 case remoting
.ApplicationContextMenu
.kShowStatsId
:
127 this.stats_
.show(info
.checked
);
130 case remoting
.ApplicationContextMenu
.kShowCreditsId
:
131 chrome
.app
.window
.create(
132 '_modules/koejkfhmphamcgafjmkellhnekdkopod/credits.html',
136 'id' : 'remoting-credits'
143 /** @type {string} */
144 remoting
.ApplicationContextMenu
.kSendFeedbackId
= 'send-feedback';
146 /** @type {string} */
147 remoting
.ApplicationContextMenu
.kShowStatsId
= 'show-stats';
149 /** @type {string} */
150 remoting
.ApplicationContextMenu
.kShowCreditsId
= 'show-credits';