1 // Copyright 2013 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.
7 * ButterBar class that is used to show the butter bar with various
13 /** @suppress {duplicate} */
14 var remoting = remoting || {};
19 remoting.ButterBar = function() {
20 this.storageKey_ = '';
22 /** @type{remoting.ButterBar} */
25 /** @param {Object} syncValues */
26 var onSyncDataLoaded = function(syncValues) {
27 chrome.storage.local.get(
28 remoting.kIT2MeVisitedStorageKey,
29 that.onStateLoaded_.bind(that, syncValues));
32 chrome.storage.sync.get(
33 [remoting.ButterBar.kSurveyStorageKey_,
34 remoting.ButterBar.kHangoutsStorageKey_],
39 * Shows butter bar with the specified |message| and updates |storageKey| after
40 * the bar is dismissed.
42 * @param {string} messageId
43 * @param {string|Array} substitutions
44 * @param {string} storageKey
47 remoting.ButterBar.prototype.show_ =
48 function(messageId, substitutions, storageKey) {
49 this.storageKey_ = storageKey;
51 var messageElement = document.getElementById(remoting.ButterBar.kMessageId_);
52 l10n.localizeElementFromTag(messageElement, messageId, substitutions, true);
54 /** @type{Element} */ messageElement.getElementsByTagName('a')[0];
55 acceptLink.addEventListener(
56 'click', this.dismiss.bind(this, true), false);
58 document.getElementById(remoting.ButterBar.kDismissId_).addEventListener(
59 'click', this.dismiss.bind(this, false), false);
61 document.getElementById(remoting.ButterBar.kId_).hidden = false;
65 * @param {Object} syncValues
66 * @param {Object} localValues
69 remoting.ButterBar.prototype.onStateLoaded_ =
70 function(syncValues, localValues) {
71 /** @type {boolean} */
72 var surveyDismissed = !!syncValues[remoting.ButterBar.kSurveyStorageKey_];
73 /** @type {boolean} */
74 var hangoutsDismissed =
75 !!syncValues[remoting.ButterBar.kHangoutsStorageKey_];
76 /** @type {boolean} */
77 var it2meExpanded = !!localValues[remoting.kIT2MeVisitedStorageKey];
79 var showSurvey = !surveyDismissed;
80 var showHangouts = it2meExpanded && !hangoutsDismissed;
82 // If both messages can be shown choose only one randomly.
83 if (showSurvey && showHangouts) {
84 if (Math.random() > 0.5) {
92 this.show_(/*i18n-content*/'SURVEY_INVITATION',
93 ['<a href="http://goo.gl/njH2q" target="_blank">', '</a>'],
94 remoting.ButterBar.kSurveyStorageKey_);
95 } else if (showHangouts) {
96 this.show_(/*i18n-content*/'HANGOUTS_INVITATION',
97 ['<a id="hangouts-accept" ' +
98 'href="https://plus.google.com/hangouts/_?gid=818572447316">',
100 remoting.ButterBar.kHangoutsStorageKey_);
104 /** @const @private */
105 remoting.ButterBar.kId_ = 'butter-bar';
107 /** @const @private */
108 remoting.ButterBar.kMessageId_ = 'butter-bar-message';
109 /** @const @private */
110 remoting.ButterBar.kDismissId_ = 'butter-bar-dismiss';
112 /** @const @private */
113 remoting.ButterBar.kSurveyStorageKey_ = 'feedback-survey-dismissed';
114 /** @const @private */
115 remoting.ButterBar.kHangoutsStorageKey_ = 'hangouts-notice-dismissed';
118 * Hide the butter bar request and record some basic information about the
119 * current state of the world in synced storage. This may be useful in the
120 * future if we want to show the request again. At the moment, the data itself
121 * is ignored; only its presence or absence is important.
123 * @param {boolean} accepted True if the user clicked the "accept" link;
124 * false if they clicked the close icon.
126 remoting.ButterBar.prototype.dismiss = function(accepted) {
128 value[this.storageKey_] = {
131 version: chrome.runtime.getManifest().version
133 chrome.storage.sync.set(value);
135 document.getElementById(remoting.ButterBar.kId_).hidden = true;