Don't show supervised user as "already on this device" while they're being imported.
[chromium-blink-merge.git] / remoting / webapp / app_remoting / js / application_context_menu.js
blob4dbb0adb7e1895f347dcfbc9dd4fabdd7454b6f4
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  * @param {remoting.ClientPlugin} plugin
18  * @param {remoting.ClientSession} clientSession
19  *
20  * @constructor
21  * @implements {base.Disposable}
22  */
23 remoting.ApplicationContextMenu = function(adapter, plugin, clientSession) {
24   /** @private */
25   this.adapter_ = adapter;
27   /** @private */
28   this.clientSession_ = clientSession;
30   this.adapter_.create(
31       remoting.ApplicationContextMenu.kSendFeedbackId,
32       l10n.getTranslationOrError(/*i18n-content*/'SEND_FEEDBACK'),
33       false);
34   this.adapter_.create(
35       remoting.ApplicationContextMenu.kShowStatsId,
36       l10n.getTranslationOrError(/*i18n-content*/'SHOW_STATS'),
37       true);
39   // TODO(kelvinp):Unhook this event on shutdown.
40   this.adapter_.addListener(this.onClicked_.bind(this));
42   /** @private {string} */
43   this.hostId_ = '';
45   /** @private */
46   this.stats_ = new remoting.ConnectionStats(
47       document.getElementById('statistics'), plugin);
50 remoting.ApplicationContextMenu.prototype.dispose = function() {
51   base.dispose(this.stats_);
52   this.stats_ = null;
55 /**
56  * @param {string} hostId
57  */
58 remoting.ApplicationContextMenu.prototype.setHostId = function(hostId) {
59   this.hostId_ = hostId;
62 /**
63  * Add an indication of the connection RTT to the 'Show statistics' menu item.
64  *
65  * @param {number} rttMs The RTT of the connection, in ms.
66  */
67 remoting.ApplicationContextMenu.prototype.updateConnectionRTT =
68     function(rttMs) {
69   var rttText =
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',
77                                  rttText));
80 /** @param {OnClickData=} info */
81 remoting.ApplicationContextMenu.prototype.onClicked_ = function(info) {
82   var menuId = /** @type {string} */ (info.menuItemId.toString());
83   switch (menuId) {
85     case remoting.ApplicationContextMenu.kSendFeedbackId:
86       var windowAttributes = {
87         bounds: {
88           width: 400,
89           height: 100,
90           left: undefined,
91           top: undefined
92         },
93         resizable: false
94       };
96       /** @type {remoting.ApplicationContextMenu} */
97       var that = this;
99       /** @param {chrome.app.window.AppWindow} consentWindow */
100       var onCreate = function(consentWindow) {
101         var onLoad = function() {
102           var message = {
103             method: 'init',
104             hostId: that.hostId_,
105             connectionStats: JSON.stringify(that.stats_.mostRecent()),
106             sessionId: that.clientSession_.getLogger().getSessionId()
107           };
108           consentWindow.contentWindow.postMessage(message, '*');
109         };
110         consentWindow.contentWindow.addEventListener('load', onLoad, false);
111       };
112       chrome.app.window.create(
113           'feedback_consent.html', windowAttributes, onCreate);
114       break;
116     case remoting.ApplicationContextMenu.kShowStatsId:
117       this.stats_.show(info.checked);
118       break;
119   }
123 /** @type {string} */
124 remoting.ApplicationContextMenu.kSendFeedbackId = 'send-feedback';
126 /** @type {string} */
127 remoting.ApplicationContextMenu.kShowStatsId = 'show-stats';