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

Side by Side Diff: chrome/browser/resources/ntp4/other_sessions.js

Issue 9838064: Add a sign-in promo message to the Other Devices menu. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments, and only enable menu when tab sync is enabled. Created 8 years, 9 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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 /** 5 /**
6 * @fileoverview The menu that shows tabs from sessions on other devices. 6 * @fileoverview The menu that shows tabs from sessions on other devices.
7 */ 7 */
8 8
9 cr.define('ntp', function() { 9 cr.define('ntp', function() {
10 'use strict'; 10 'use strict';
11 11
12 var localStrings = new LocalStrings(); 12 var localStrings = new LocalStrings();
13 var Menu = cr.ui.Menu; 13 var Menu = cr.ui.Menu;
14 var MenuItem = cr.ui.MenuItem; 14 var MenuItem = cr.ui.MenuItem;
15 var MenuButton = cr.ui.MenuButton; 15 var MenuButton = cr.ui.MenuButton;
16 var OtherSessionsMenuButton = cr.ui.define('button'); 16 var OtherSessionsMenuButton = cr.ui.define('button');
17 17
18 // Histogram buckets for UMA tracking of menu usage. 18 // Histogram buckets for UMA tracking of menu usage.
19 var HISTOGRAM_EVENT = { 19 var HISTOGRAM_EVENT = {
20 INITIALIZED: 0, 20 INITIALIZED: 0,
21 SHOW_MENU: 1, 21 SHOW_MENU: 1,
22 LINK_CLICKED: 2, 22 LINK_CLICKED: 2,
23 LINK_RIGHT_CLICKED: 3 23 LINK_RIGHT_CLICKED: 3
24 }; 24 };
25 var HISTOGRAM_EVENT_LIMIT = HISTOGRAM_EVENT.LINK_RIGHT_CLICKED + 1; 25 var HISTOGRAM_EVENT_LIMIT = HISTOGRAM_EVENT.LINK_RIGHT_CLICKED + 1;
26 26
27 // Indicates whether or not the current user is signed in. This is
28 // initially set in initialize(), and is updated when the user's login state
29 // changes.
30 var isUserSignedIn = false;
Dan Beam 2012/03/26 23:18:54 nit: this is probably meant to go on the class pro
Patrick Dubroy 2012/03/27 00:36:51 Actually, it's not even used anymore.
31
27 OtherSessionsMenuButton.prototype = { 32 OtherSessionsMenuButton.prototype = {
28 __proto__: MenuButton.prototype, 33 __proto__: MenuButton.prototype,
29 34
30 decorate: function() { 35 decorate: function() {
31 MenuButton.prototype.decorate.call(this); 36 MenuButton.prototype.decorate.call(this);
32 this.menu = new Menu; 37 this.menu = new Menu;
33 cr.ui.decorate(this.menu, Menu); 38 cr.ui.decorate(this.menu, Menu);
34 this.menu.classList.add('footer-menu'); 39 this.menu.classList.add('footer-menu');
35 this.menu.addEventListener('contextmenu', 40 this.menu.addEventListener('contextmenu',
36 this.onContextMenu_.bind(this), true); 41 this.onContextMenu_.bind(this), true);
37 document.body.appendChild(this.menu); 42 document.body.appendChild(this.menu);
38 43
44 this.resetMenu_();
45
39 this.sessions_ = []; 46 this.sessions_ = [];
40 this.anchorType = cr.ui.AnchorType.ABOVE; 47 this.anchorType = cr.ui.AnchorType.ABOVE;
41 this.invertLeftRight = true; 48 this.invertLeftRight = true;
42 49
43 chrome.send('getForeignSessions');
44 this.recordUmaEvent_(HISTOGRAM_EVENT.INITIALIZED); 50 this.recordUmaEvent_(HISTOGRAM_EVENT.INITIALIZED);
45 }, 51 },
46 52
47 /** 53 /**
54 * Initialize this element.
55 * @param {boolean} signedIn Is the current user signed in?
56 */
57 initialize: function(signedIn) {
58 this.updateSignInState(signedIn);
59 },
60
61 /**
48 * Record an event in the UMA histogram. 62 * Record an event in the UMA histogram.
49 * @param {Number} eventId The id of the event to be recorded. 63 * @param {Number} eventId The id of the event to be recorded.
50 */ 64 */
51 recordUmaEvent_: function(eventId) { 65 recordUmaEvent_: function(eventId) {
52 chrome.send('metricsHandler:recordInHistogram', 66 chrome.send('metricsHandler:recordInHistogram',
53 ['NewTabPage.OtherSessionsMenu', eventId, HISTOGRAM_EVENT_LIMIT]); 67 ['NewTabPage.OtherSessionsMenu', eventId, HISTOGRAM_EVENT_LIMIT]);
54 }, 68 },
55 69
56 /** 70 /**
57 * Handle a context menu event for an object in the menu's DOM subtree. 71 * Handle a context menu event for an object in the menu's DOM subtree.
(...skipping 11 matching lines...) Expand all
69 * @override 83 * @override
70 */ 84 */
71 showMenu: function() { 85 showMenu: function() {
72 if (this.sessions_.length == 0) 86 if (this.sessions_.length == 0)
73 chrome.send('getForeignSessions'); 87 chrome.send('getForeignSessions');
74 this.recordUmaEvent_(HISTOGRAM_EVENT.SHOW_MENU); 88 this.recordUmaEvent_(HISTOGRAM_EVENT.SHOW_MENU);
75 MenuButton.prototype.showMenu.call(this); 89 MenuButton.prototype.showMenu.call(this);
76 }, 90 },
77 91
78 /** 92 /**
93 * Reset the menu to the default state.
94 * @private
95 */
96 resetMenu_: function() {
97 var promoContent = $('other-sessions-promo-message');
Dan Beam 2012/03/26 23:18:54 why do you need to do var promoContent = $('oth
Patrick Dubroy 2012/03/26 23:46:07 No, 'this' is the button that you click to show th
Dan Beam 2012/03/27 00:03:42 Then it seems like you should be assigning this to
Patrick Dubroy 2012/03/27 00:36:51 Done.
98 this.menu.innerHTML = '';
99 this.menu.appendChild(promoContent);
100 promoContent.hidden = true;
101 },
102
103 /**
79 * Create a custom click handler for a link, so that clicking on a link 104 * Create a custom click handler for a link, so that clicking on a link
80 * restores the session (including back stack) rather than just opening 105 * restores the session (including back stack) rather than just opening
81 * the URL. 106 * the URL.
82 */ 107 */
83 makeClickHandler_: function(sessionTag, windowId, tabId) { 108 makeClickHandler_: function(sessionTag, windowId, tabId) {
84 var self = this; 109 var self = this;
85 return function(e) { 110 return function(e) {
86 self.recordUmaEvent_(HISTOGRAM_EVENT.LINK_CLICKED); 111 self.recordUmaEvent_(HISTOGRAM_EVENT.LINK_CLICKED);
87 chrome.send('openForeignSession', [sessionTag, windowId, tabId, 112 chrome.send('openForeignSession', [sessionTag, windowId, tabId,
88 e.button, e.altKey, e.ctrlKey, e.metaKey, e.shiftKey]); 113 e.button, e.altKey, e.ctrlKey, e.metaKey, e.shiftKey]);
(...skipping 26 matching lines...) Expand all
115 a.style.backgroundImage = 'url(chrome://favicon/' + tab.url + ')'; 140 a.style.backgroundImage = 'url(chrome://favicon/' + tab.url + ')';
116 var clickHandler = this.makeClickHandler_( 141 var clickHandler = this.makeClickHandler_(
117 session.tag, String(window.sessionId), String(tab.sessionId)); 142 session.tag, String(window.sessionId), String(tab.sessionId));
118 a.addEventListener('click', clickHandler); 143 a.addEventListener('click', clickHandler);
119 section.appendChild(a); 144 section.appendChild(a);
120 } 145 }
121 } 146 }
122 }, 147 },
123 148
124 /** 149 /**
125 * Create the UI for the promo and place it inside the menu. 150 * Show or hide the promo message shown in place of the session list.
126 * The promo is shown instead of foreign session data when tab sync is 151 * The promo is shown when the user is signed in, but there is no foreign
127 * not enabled for a profile. 152 * session data available.
153 * @param {boolean} visible Whether the message should be shown.
154 * @private
128 */ 155 */
129 showPromo_: function() { 156 setPromoVisible_: function(visible) {
130 var message = localStrings.getString('otherSessionsEmpty'); 157 this.resetMenu_();
131 this.menu.appendChild(this.ownerDocument.createTextNode(message)); 158 $('other-sessions-promo-message').hidden = !visible;
132 }, 159 },
133 160
134 /** 161 /**
135 * Sets the menu model data. 162 * Sets the menu model data. An empty list means that either there are no
163 * foreign sessions, or tab sync is disabled for this profile.
164 * |isTabSyncEnabled| makes it possible to distinguish between the cases.
165 *
136 * @param {Array} sessionList Array of objects describing the sessions 166 * @param {Array} sessionList Array of objects describing the sessions
137 * from other devices. 167 * from other devices.
168 * @param {boolean} isTabSyncEnabled Is tab sync enabled for this profile?
138 */ 169 */
139 set sessions(sessionList) { 170 setForeignSessions: function(sessionList, isTabSyncEnabled) {
140 // Clear the current contents of the menu. 171 this.sessions_ = sessionList;
141 this.menu.innerHTML = ''; 172 this.setPromoVisible_(sessionList.length == 0);
173 if (sessionList.length > 0) {
174 // Rebuild the menu with the new data.
175 for (var i = 0; i < sessionList.length; i++) {
176 this.addSession_(sessionList[i]);
177 }
178 }
179 // The menu button is shown iff tab sync is enabled.
180 if (isTabSyncEnabled)
181 this.classList.remove('invisible');
182 else
183 this.classList.add('invisible');
184 },
142 185
143 // Rebuild the menu with the new data. 186 /**
144 for (var i = 0; i < sessionList.length; i++) { 187 * Called from the new tab page when the user's signed in state changes.
145 this.addSession_(sessionList[i]); 188 * @param {boolean} signedIn Is the user currently signed in?
146 } 189 */
190 updateSignInState: function(signedIn) {
191 isUserSignedIn = signedIn;
147 192
148 if (sessionList.length == 0) 193 if (signedIn)
194 chrome.send('getForeignSessions');
195 else
149 this.classList.add('invisible'); 196 this.classList.add('invisible');
150 else
151 this.classList.remove('invisible');
152
153 this.sessions_ = sessionList;
154 }, 197 },
155 }; 198 };
156 199
157 return { 200 return {
158 OtherSessionsMenuButton: OtherSessionsMenuButton, 201 OtherSessionsMenuButton: OtherSessionsMenuButton,
159 }; 202 };
160 }); 203 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698