Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / remoting / webapp / app_remoting / js / application_context_menu.js
bloba7934c07df9106063b850a3e2dfcf7945d7339a0
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 * @param {remoting.WindowShape} windowShape
21 * @constructor
22 * @implements {base.Disposable}
24 remoting.ApplicationContextMenu = function(adapter, plugin, clientSession,
25 windowShape) {
26 /** @private */
27 this.adapter_ = adapter;
29 /** @private */
30 this.clientSession_ = clientSession;
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);
45 // TODO(kelvinp):Unhook this event on shutdown.
46 this.adapter_.addListener(this.onClicked_.bind(this));
48 /** @private {string} */
49 this.hostId_ = '';
51 /** @private */
52 this.stats_ = new remoting.ConnectionStats(
53 document.getElementById('statistics'), plugin, windowShape);
56 remoting.ApplicationContextMenu.prototype.dispose = function() {
57 base.dispose(this.stats_);
58 this.stats_ = null;
61 /**
62 * @param {string} hostId
64 remoting.ApplicationContextMenu.prototype.setHostId = function(hostId) {
65 this.hostId_ = hostId;
68 /**
69 * Add an indication of the connection RTT to the 'Show statistics' menu item.
71 * @param {number} rttMs The RTT of the connection, in ms.
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));
86 /** @param {OnClickData=} info */
87 remoting.ApplicationContextMenu.prototype.onClicked_ = function(info) {
88 var menuId = /** @type {string} */ (info.menuItemId.toString());
89 switch (menuId) {
91 case remoting.ApplicationContextMenu.kSendFeedbackId:
92 var windowAttributes = {
93 bounds: {
94 width: 400,
95 height: 100,
96 left: undefined,
97 top: undefined
99 resizable: false
102 /** @type {remoting.ApplicationContextMenu} */
103 var that = this;
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())
117 consentWindow.contentWindow.postMessage(message, '*');
119 consentWindow.contentWindow.addEventListener('load', onLoad, false);
121 chrome.app.window.create(
122 '_modules/koejkfhmphamcgafjmkellhnekdkopod/feedback_consent.html',
123 windowAttributes, onCreate);
124 break;
126 case remoting.ApplicationContextMenu.kShowStatsId:
127 this.stats_.show(info.checked);
128 break;
130 case remoting.ApplicationContextMenu.kShowCreditsId:
131 chrome.app.window.create(
132 '_modules/koejkfhmphamcgafjmkellhnekdkopod/credits.html',
134 'width': 800,
135 'height': 600,
136 'id' : 'remoting-credits'
138 break;
143 /** @type {string} */
144 remoting.ApplicationContextMenu.kSendFeedbackId = 'send-feedback';
146 /** @type {string} */
147 remoting.ApplicationContextMenu.kShowStatsId = 'show-stats';
149 /** @type {string} */
150 remoting.ApplicationContextMenu.kShowCreditsId = 'show-credits';