OLD | NEW |
| (Empty) |
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. | |
4 | |
5 /** | |
6 * @fileoverview | |
7 * Class representing the application's context menu. | |
8 */ | |
9 | |
10 'use strict'; | |
11 | |
12 /** @suppress {duplicate} */ | |
13 var remoting = remoting || {}; | |
14 | |
15 /** | |
16 * @param {remoting.ContextMenuAdapter} adapter | |
17 * @param {remoting.ClientPlugin} plugin | |
18 * @param {remoting.ClientSession} clientSession | |
19 * @param {remoting.WindowShape} windowShape | |
20 * | |
21 * @constructor | |
22 * @implements {base.Disposable} | |
23 */ | |
24 remoting.ApplicationContextMenu = function(adapter, plugin, clientSession, | |
25 windowShape) { | |
26 /** @private */ | |
27 this.adapter_ = adapter; | |
28 | |
29 /** @private */ | |
30 this.clientSession_ = clientSession; | |
31 | |
32 this.adapter_.create( | |
33 remoting.ApplicationContextMenu.kSendFeedbackId, | |
34 l10n.getTranslationOrError(/*i18n-content*/'SEND_FEEDBACK'), | |
35 false); | |
36 this.adapter_.create( | |
37 remoting.ApplicationContextMenu.kShowStatsId, | |
38 l10n.getTranslationOrError(/*i18n-content*/'SHOW_STATS'), | |
39 true); | |
40 this.adapter_.create( | |
41 remoting.ApplicationContextMenu.kShowCreditsId, | |
42 l10n.getTranslationOrError(/*i18n-content*/'CREDITS'), | |
43 true); | |
44 | |
45 // TODO(kelvinp):Unhook this event on shutdown. | |
46 this.adapter_.addListener(this.onClicked_.bind(this)); | |
47 | |
48 /** @private {string} */ | |
49 this.hostId_ = ''; | |
50 | |
51 /** @private */ | |
52 this.stats_ = new remoting.ConnectionStats( | |
53 document.getElementById('statistics'), plugin, windowShape); | |
54 }; | |
55 | |
56 remoting.ApplicationContextMenu.prototype.dispose = function() { | |
57 base.dispose(this.stats_); | |
58 this.stats_ = null; | |
59 }; | |
60 | |
61 /** | |
62 * @param {string} hostId | |
63 */ | |
64 remoting.ApplicationContextMenu.prototype.setHostId = function(hostId) { | |
65 this.hostId_ = hostId; | |
66 }; | |
67 | |
68 /** | |
69 * Add an indication of the connection RTT to the 'Show statistics' menu item. | |
70 * | |
71 * @param {number} rttMs The RTT of the connection, in ms. | |
72 */ | |
73 remoting.ApplicationContextMenu.prototype.updateConnectionRTT = | |
74 function(rttMs) { | |
75 var rttText = | |
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', | |
83 rttText)); | |
84 }; | |
85 | |
86 /** @param {OnClickData=} info */ | |
87 remoting.ApplicationContextMenu.prototype.onClicked_ = function(info) { | |
88 var menuId = /** @type {string} */ (info.menuItemId.toString()); | |
89 switch (menuId) { | |
90 | |
91 case remoting.ApplicationContextMenu.kSendFeedbackId: | |
92 var windowAttributes = { | |
93 bounds: { | |
94 width: 400, | |
95 height: 100, | |
96 left: undefined, | |
97 top: undefined | |
98 }, | |
99 resizable: false | |
100 }; | |
101 | |
102 /** @type {remoting.ApplicationContextMenu} */ | |
103 var that = this; | |
104 | |
105 /** @param {chrome.app.window.AppWindow} consentWindow */ | |
106 var onCreate = function(consentWindow) { | |
107 var onLoad = function() { | |
108 var message = { | |
109 method: 'init', | |
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()) | |
116 }; | |
117 consentWindow.contentWindow.postMessage(message, '*'); | |
118 }; | |
119 consentWindow.contentWindow.addEventListener('load', onLoad, false); | |
120 }; | |
121 chrome.app.window.create( | |
122 '_modules/koejkfhmphamcgafjmkellhnekdkopod/feedback_consent.html', | |
123 windowAttributes, onCreate); | |
124 break; | |
125 | |
126 case remoting.ApplicationContextMenu.kShowStatsId: | |
127 this.stats_.show(info.checked); | |
128 break; | |
129 | |
130 case remoting.ApplicationContextMenu.kShowCreditsId: | |
131 chrome.app.window.create( | |
132 '_modules/koejkfhmphamcgafjmkellhnekdkopod/credits.html', | |
133 { | |
134 'width': 800, | |
135 'height': 600, | |
136 'id' : 'remoting-credits' | |
137 }); | |
138 break; | |
139 } | |
140 }; | |
141 | |
142 | |
143 /** @type {string} */ | |
144 remoting.ApplicationContextMenu.kSendFeedbackId = 'send-feedback'; | |
145 | |
146 /** @type {string} */ | |
147 remoting.ApplicationContextMenu.kShowStatsId = 'show-stats'; | |
148 | |
149 /** @type {string} */ | |
150 remoting.ApplicationContextMenu.kShowCreditsId = 'show-credits'; | |
OLD | NEW |