Rewrite AndroidSyncSettings to be significantly simpler.
[chromium-blink-merge.git] / remoting / webapp / app_remoting / js / application_context_menu.js
blob50a429b2b546973b21b63e4b01b4a07e263cb45f
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.
5 /**
6 * @fileoverview
7 * Class representing the application's context menu.
8 */
10 'use strict';
12 /** @suppress {duplicate} */
13 var remoting = remoting || {};
15 /**
16 * @param {remoting.ContextMenuAdapter} adapter
17 * @constructor
19 remoting.ApplicationContextMenu = function(adapter) {
20 /**
21 * @type {remoting.ContextMenuAdapter}
22 * @private
24 this.adapter_ = adapter;
26 this.adapter_.create(
27 remoting.ApplicationContextMenu.kSendFeedbackId,
28 l10n.getTranslationOrError(/*i18n-content*/'SEND_FEEDBACK'),
29 false);
30 this.adapter_.create(
31 remoting.ApplicationContextMenu.kShowStatsId,
32 l10n.getTranslationOrError(/*i18n-content*/'SHOW_STATS'),
33 true);
34 this.adapter_.addListener(this.onClicked_.bind(this));
36 /**
37 * @type {string}
38 * @private
40 this.hostId_ = '';
43 /**
44 * @param {string} hostId
46 remoting.ApplicationContextMenu.prototype.setHostId = function(hostId) {
47 this.hostId_ = hostId;
50 /**
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 =
56 function(rttMs) {
57 var rttText =
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',
65 rttText));
68 /** @param {OnClickData=} info */
69 remoting.ApplicationContextMenu.prototype.onClicked_ = function(info) {
70 switch (info.menuItemId) {
72 case remoting.ApplicationContextMenu.kSendFeedbackId:
73 var windowAttributes = {
74 bounds: {
75 width: 400,
76 height: 100
78 resizable: false
81 /** @type {remoting.ApplicationContextMenu} */
82 var that = this;
84 /** @param {AppWindow} consentWindow */
85 var onCreate = function(consentWindow) {
86 var onLoad = function() {
87 var message = {
88 method: 'init',
89 hostId: that.hostId_,
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);
98 break;
100 case remoting.ApplicationContextMenu.kShowStatsId:
101 if (remoting.stats) {
102 remoting.stats.show(info.checked);
104 break;
109 /** @type {string} */
110 remoting.ApplicationContextMenu.kSendFeedbackId = 'send-feedback';
112 /** @type {string} */
113 remoting.ApplicationContextMenu.kShowStatsId = 'show-stats';