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
21 * @implements {base.Disposable}
23 remoting.ApplicationContextMenu = function(adapter, plugin, clientSession) {
25 this.adapter_ = adapter;
28 this.clientSession_ = clientSession;
31 remoting.ApplicationContextMenu.kSendFeedbackId,
32 l10n.getTranslationOrError(/*i18n-content*/'SEND_FEEDBACK'),
35 remoting.ApplicationContextMenu.kShowStatsId,
36 l10n.getTranslationOrError(/*i18n-content*/'SHOW_STATS'),
39 // TODO(kelvinp):Unhook this event on shutdown.
40 this.adapter_.addListener(this.onClicked_.bind(this));
42 /** @private {string} */
46 this.stats_ = new remoting.ConnectionStats(
47 document.getElementById('statistics'), plugin);
50 remoting.ApplicationContextMenu.prototype.dispose = function() {
51 base.dispose(this.stats_);
56 * @param {string} hostId
58 remoting.ApplicationContextMenu.prototype.setHostId = function(hostId) {
59 this.hostId_ = hostId;
63 * Add an indication of the connection RTT to the 'Show statistics' menu item.
65 * @param {number} rttMs The RTT of the connection, in ms.
67 remoting.ApplicationContextMenu.prototype.updateConnectionRTT =
70 rttMs < 50 ? /*i18n-content*/'CONNECTION_QUALITY_GOOD' :
71 rttMs < 100 ? /*i18n-content*/'CONNECTION_QUALITY_FAIR' :
72 /*i18n-content*/'CONNECTION_QUALITY_POOR';
73 rttText = l10n.getTranslationOrError(rttText);
74 this.adapter_.updateTitle(
75 remoting.ApplicationContextMenu.kShowStatsId,
76 l10n.getTranslationOrError(/*i18n-content*/'SHOW_STATS_WITH_RTT',
80 /** @param {OnClickData=} info */
81 remoting.ApplicationContextMenu.prototype.onClicked_ = function(info) {
82 var menuId = /** @type {string} */ (info.menuItemId.toString());
85 case remoting.ApplicationContextMenu.kSendFeedbackId:
86 var windowAttributes = {
96 /** @type {remoting.ApplicationContextMenu} */
99 /** @param {chrome.app.window.AppWindow} consentWindow */
100 var onCreate = function(consentWindow) {
101 var onLoad = function() {
104 hostId: that.hostId_,
105 connectionStats: JSON.stringify(that.stats_.mostRecent()),
106 sessionId: that.clientSession_.getLogger().getSessionId()
108 consentWindow.contentWindow.postMessage(message, '*');
110 consentWindow.contentWindow.addEventListener('load', onLoad, false);
112 chrome.app.window.create(
113 'feedback_consent.html', windowAttributes, onCreate);
116 case remoting.ApplicationContextMenu.kShowStatsId:
117 this.stats_.show(info.checked);
123 /** @type {string} */
124 remoting.ApplicationContextMenu.kSendFeedbackId = 'send-feedback';
126 /** @type {string} */
127 remoting.ApplicationContextMenu.kShowStatsId = 'show-stats';