Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(91)

Side by Side Diff: remoting/webapp/butter_bar.js

Issue 14803010: Add link to Hangouts Remote Desktop in the It2Me section of the remoting app. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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.
4
5 /**
6 * @fileoverview
7 * Functions and event handlers to invite the user to participate in a survey
8 * to help improve the product.
Jamie 2013/05/23 20:31:46 Is this comment still correct?
Sergey Ulanov 2013/05/29 23:36:11 Done.
9 */
10
11 'use strict';
12
13 /** @suppress {duplicate} */
14 var remoting = remoting || {};
15
16 var kButterBarId = 'butter-bar';
17
18 var kSurveyInvitationId = 'survey-invitation';
19 var kSurveyAcceptId = 'survey-accept';
20 var kSurveyDismissId = 'survey-dismiss';
21
22 var kHangoutsInvitationId = 'hangouts-invitation';
23 var kHangoutsAcceptId = 'hangouts-accept';
24 var kHangoutsDismissId = 'hangouts-dismiss';
25
26 var kSurveyStorageKey = 'feedback-survey-dismissed';
27 var kHangoutsStorageKey = 'hangouts-notice-dismissed';
Jamie 2013/05/23 20:31:46 I realize this was my error originally, but by dec
Sergey Ulanov 2013/05/29 23:36:11 Done.
28
29 /** @enum {number} */
30 remoting.ButterBarMode = {
31 NONE: 0,
32 SURVEY: 1,
33 HANGOUTS: 2
34 };
35
36 /**
37 * Hide the survey request and record some basic information about the current
Jamie 2013/05/23 20:31:46 s/survey request/butter-bar/ (and similar elsewher
Sergey Ulanov 2013/05/29 23:36:11 Done.
38 * state of the world in synced storage. This may be useful in the future if we
39 * want to show the request again. At the moment, the data itself is ignored;
40 * only its presence or absence is important.
41 *
42 * @param {string} storageKey Storage key used to store dismissal state.
43 * @param {boolean} optIn True if the user clicked the "Take the survey" link;
44 * false if they clicked the close icon.
Jamie 2013/05/23 20:31:46 |optIn| doesn't really make sense as a parameter n
Sergey Ulanov 2013/05/29 23:36:11 Done. Also changed the key that we use to store th
Jamie 2013/05/30 01:10:16 It will mean that users who have previously dismis
Sergey Ulanov 2013/05/30 22:04:54 No, the value is not actually used in any way. We
Jamie 2013/05/31 00:12:41 Ah yes, good point. Still, if we ever want to make
Sergey Ulanov 2013/06/03 19:11:48 Ok, renamed it back to optIn.
45 */
46 remoting.dismissButterBar = function(storageKey, optIn) {
47 var value = {};
48 value[storageKey] = {
49 optIn: optIn,
50 date: new Date(),
51 version: chrome.runtime.getManifest().version
52 };
53 chrome.storage.sync.set(value);
54
55 remoting.showButterBar(remoting.ButterBarMode.NONE);
56 };
57
58 /**
59 * Show the butter bar if there is a message to show.
60 */
61 remoting.initButterBar = function() {
62 document.getElementById(kHangoutsAcceptId).addEventListener(
63 'click', remoting.dismissButterBar.bind(null, kHangoutsStorageKey, true),
64 false);
65 document.getElementById(kHangoutsDismissId).addEventListener(
66 'click', remoting.dismissButterBar.bind(null, kHangoutsStorageKey, false),
67 false);
68
69 document.getElementById(kSurveyAcceptId).addEventListener(
70 'click', remoting.dismissButterBar.bind(null, kSurveyStorageKey, true),
71 false);
72 document.getElementById(kSurveyDismissId).addEventListener(
73 'click', remoting.dismissButterBar.bind(null, kSurveyStorageKey, false),
74 false);
Jamie 2013/05/23 20:31:46 It's a shame to duplicate the action elements and
Sergey Ulanov 2013/05/29 23:36:11 Done.
75
76 /** @param {boolean} surveyDismissed
77 * @param {boolean} hangoutsDismissed
78 * @param {boolean} it2meExpanded */
79 var onStateLoaded = function(surveyDismissed, hangoutsDismissed,
80 it2meExpanded) {
81 var showSurvey = !surveyDismissed;
82 var showHangouts = it2meExpanded && !hangoutsDismissed;
83 if (showSurvey && !showHangouts) {
84 remoting.showButterBar(remoting.ButterBarMode.SURVEY);
85 } else if (showHangouts && !showSurvey) {
86 remoting.showButterBar(remoting.ButterBarMode.HANGOUTS);
87 } else if (showSurvey && showHangouts) {
88 if (Math.random() > 0.5) {
89 remoting.showButterBar(remoting.ButterBarMode.SURVEY);
90 } else {
91 remoting.showButterBar(remoting.ButterBarMode.HANGOUTS);
92 }
93 }
94 };
95 /** @param {Object} value */
96 var onSyncDataLoaded = function(value) {
97 /** @type {boolean} */
98 var surveyDismissed = !!value[kSurveyStorageKey];
99 /** @type {boolean} */
100 var hangoutsDismissed = !!value[kHangoutsStorageKey];
101 chrome.storage.local.get(remoting.kIT2MeVisitedStorageKey, function(value) {
Jamie 2013/05/23 20:31:46 Optional: I'm not a big fan of anonymous functions
Sergey Ulanov 2013/05/29 23:36:11 Done
102 /** @type {boolean} */
103 var it2meExpanded = !!value[remoting.kIT2MeVisitedStorageKey];
104 onStateLoaded(surveyDismissed, hangoutsDismissed, it2meExpanded);
105 });
106 };
107 chrome.storage.sync.get(
108 [kSurveyStorageKey, kHangoutsStorageKey], onSyncDataLoaded);
109 }
110
111 /**
112 * Shows butter bar in the specified |mode|.
113 *
114 * @param {remoting.ButterBarMode} mode
115 */
116 remoting.showButterBar = function(mode) {
117 if (mode == remoting.ButterBarMode.NONE) {
118 document.getElementById(kButterBarId).hidden = true;
119 return;
120 }
121
122 document.getElementById(kButterBarId).hidden = false;
123 if (mode == remoting.ButterBarMode.SURVEY) {
124 document.getElementById(kSurveyInvitationId).hidden = false;
125 document.getElementById(kHangoutsInvitationId).hidden = true;
126 } else {
127 document.getElementById(kSurveyInvitationId).hidden = true;
128 document.getElementById(kHangoutsInvitationId).hidden = false;
129 }
Jamie 2013/05/23 20:31:46 This can be more simply expressed as three express
Sergey Ulanov 2013/05/29 23:36:11 Removed most of this code.
130 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698