1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
/**
* @fileoverview
* Class representing the application's context menu.
*/
'use strict';
/** @suppress {duplicate} */
var remoting = remoting || {};
/**
* @param {remoting.ContextMenuAdapter} adapter
* @param {remoting.ClientPlugin} plugin
* @constructor
* @implements {base.Disposable}
*/
remoting.ApplicationContextMenu = function(adapter, plugin) {
/** @private {remoting.ContextMenuAdapter} */
this.adapter_ = adapter;
this.adapter_.create(
remoting.ApplicationContextMenu.kSendFeedbackId,
l10n.getTranslationOrError(/*i18n-content*/'SEND_FEEDBACK'),
false);
this.adapter_.create(
remoting.ApplicationContextMenu.kShowStatsId,
l10n.getTranslationOrError(/*i18n-content*/'SHOW_STATS'),
true);
// TODO(kelvinp):Unhook this event on shutdown.
this.adapter_.addListener(this.onClicked_.bind(this));
/** @private {string} */
this.hostId_ = '';
/** @private */
this.stats_ = new remoting.ConnectionStats(
document.getElementById('statistics'), plugin);
};
remoting.ApplicationContextMenu.prototype.dispose = function() {
base.dispose(this.stats_);
this.stats_ = null;
};
/**
* @param {string} hostId
*/
remoting.ApplicationContextMenu.prototype.setHostId = function(hostId) {
this.hostId_ = hostId;
};
/**
* Add an indication of the connection RTT to the 'Show statistics' menu item.
*
* @param {number} rttMs The RTT of the connection, in ms.
*/
remoting.ApplicationContextMenu.prototype.updateConnectionRTT =
function(rttMs) {
var rttText =
rttMs < 50 ? /*i18n-content*/'CONNECTION_QUALITY_GOOD' :
rttMs < 100 ? /*i18n-content*/'CONNECTION_QUALITY_FAIR' :
/*i18n-content*/'CONNECTION_QUALITY_POOR';
rttText = l10n.getTranslationOrError(rttText);
this.adapter_.updateTitle(
remoting.ApplicationContextMenu.kShowStatsId,
l10n.getTranslationOrError(/*i18n-content*/'SHOW_STATS_WITH_RTT',
rttText));
};
/** @param {OnClickData=} info */
remoting.ApplicationContextMenu.prototype.onClicked_ = function(info) {
switch (info.menuItemId) {
case remoting.ApplicationContextMenu.kSendFeedbackId:
var windowAttributes = {
bounds: {
width: 400,
height: 100
},
resizable: false
};
/** @type {remoting.ApplicationContextMenu} */
var that = this;
/** @param {AppWindow} consentWindow */
var onCreate = function(consentWindow) {
var onLoad = function() {
var message = {
method: 'init',
hostId: that.hostId_,
connectionStats: JSON.stringify(that.stats_.mostRecent())
};
consentWindow.contentWindow.postMessage(message, '*');
};
consentWindow.contentWindow.addEventListener('load', onLoad, false);
};
chrome.app.window.create(
'feedback_consent.html', windowAttributes, onCreate);
break;
case remoting.ApplicationContextMenu.kShowStatsId:
this.stats_.show(info.checked);
break;
}
};
/** @type {string} */
remoting.ApplicationContextMenu.kSendFeedbackId = 'send-feedback';
/** @type {string} */
remoting.ApplicationContextMenu.kShowStatsId = 'show-stats';
|