Chromium Code Reviews| Index: chrome/browser/resources/ntp4/other_sessions.js |
| diff --git a/chrome/browser/resources/ntp4/other_sessions.js b/chrome/browser/resources/ntp4/other_sessions.js |
| index ccd693d67b8f1385a813ace1e3733ac51e0199bf..0a62a0af946b5572b6c2051ddefcaad09f9a2117 100644 |
| --- a/chrome/browser/resources/ntp4/other_sessions.js |
| +++ b/chrome/browser/resources/ntp4/other_sessions.js |
| @@ -36,15 +36,26 @@ cr.define('ntp', function() { |
| this.onContextMenu_.bind(this), true); |
| document.body.appendChild(this.menu); |
| + this.promoMessage_ = $('other-sessions-promo-message'); |
|
Dan Beam
2012/03/27 01:21:06
this would be much more loosely coupled if you pas
Patrick Dubroy
2012/03/27 13:44:21
What is the advantage of that? Currently new_tab.j
|
| + |
| + this.resetMenu_(); |
|
Dan Beam
2012/03/27 01:21:06
you're probably better off doing all this in initi
Patrick Dubroy
2012/03/27 13:44:21
It's not clear what you're talking about here. Wha
|
| + |
| this.sessions_ = []; |
| this.anchorType = cr.ui.AnchorType.ABOVE; |
| this.invertLeftRight = true; |
| - chrome.send('getForeignSessions'); |
| this.recordUmaEvent_(HISTOGRAM_EVENT.INITIALIZED); |
| }, |
| /** |
| + * Initialize this element. |
| + * @param {boolean} signedIn Is the current user signed in? |
| + */ |
| + initialize: function(signedIn) { |
| + this.updateSignInState(signedIn); |
| + }, |
| + |
| + /** |
| * Record an event in the UMA histogram. |
| * @param {Number} eventId The id of the event to be recorded. |
| */ |
| @@ -76,6 +87,16 @@ cr.define('ntp', function() { |
| }, |
| /** |
| + * Reset the menu to the default state. |
| + * @private |
| + */ |
| + resetMenu_: function() { |
| + this.menu.innerHTML = ''; |
| + this.menu.appendChild(this.promoMessage_); |
|
Dan Beam
2012/03/27 01:21:06
also, if you never need more than 1 and/or you mov
Patrick Dubroy
2012/03/27 13:44:21
What is the purpose of "also" in this sentence? Is
|
| + this.promoMessage_.hidden = true; |
|
Dan Beam
2012/03/27 01:21:06
this should probably be using setPromoVisible_() i
Patrick Dubroy
2012/03/27 13:44:21
I've removed this line altogether. It's not really
|
| + }, |
| + |
| + /** |
| * Create a custom click handler for a link, so that clicking on a link |
| * restores the session (including back stack) rather than just opening |
| * the URL. |
| @@ -122,35 +143,52 @@ cr.define('ntp', function() { |
| }, |
| /** |
| - * Create the UI for the promo and place it inside the menu. |
| - * The promo is shown instead of foreign session data when tab sync is |
| - * not enabled for a profile. |
| + * Show or hide the promo message shown in place of the session list. |
| + * The promo is shown when the user is signed in, but there is no foreign |
| + * session data available. |
| + * @param {boolean} visible Whether the message should be shown. |
| + * @private |
| */ |
| - showPromo_: function() { |
| - var message = localStrings.getString('otherSessionsEmpty'); |
| - this.menu.appendChild(this.ownerDocument.createTextNode(message)); |
| + setPromoVisible_: function(visible) { |
| + this.resetMenu_(); |
|
Dan Beam
2012/03/27 01:21:06
should setting it |visible| remove the contents?
Patrick Dubroy
2012/03/27 13:44:21
No, probably not. Fixed.
|
| + this.promoMessage_.hidden = !visible; |
| }, |
| /** |
| - * Sets the menu model data. |
| + * Sets the menu model data. An empty list means that either there are no |
| + * foreign sessions, or tab sync is disabled for this profile. |
| + * |isTabSyncEnabled| makes it possible to distinguish between the cases. |
| + * |
| * @param {Array} sessionList Array of objects describing the sessions |
| - * from other devices. |
| + * from other devices. |
| + * @param {boolean} isTabSyncEnabled Is tab sync enabled for this profile? |
| */ |
| - set sessions(sessionList) { |
| - // Clear the current contents of the menu. |
| - this.menu.innerHTML = ''; |
| - |
| - // Rebuild the menu with the new data. |
| - for (var i = 0; i < sessionList.length; i++) { |
| - this.addSession_(sessionList[i]); |
| + setForeignSessions: function(sessionList, isTabSyncEnabled) { |
| + this.sessions_ = sessionList; |
| + this.setPromoVisible_(sessionList.length == 0); |
|
Dan Beam
2012/03/27 01:21:06
shouldn't this be done after you rebuild the sessi
Patrick Dubroy
2012/03/27 13:44:21
In this version of the code, it needed to be done
|
| + if (sessionList.length > 0) { |
| + // Rebuild the menu with the new data. |
| + for (var i = 0; i < sessionList.length; i++) { |
| + this.addSession_(sessionList[i]); |
| + } |
| } |
| - |
| - if (sessionList.length == 0) |
| - this.classList.add('invisible'); |
| - else |
| + // The menu button is shown iff tab sync is enabled. |
| + if (isTabSyncEnabled) |
| this.classList.remove('invisible'); |
| + else |
| + this.classList.add('invisible'); |
| + }, |
| - this.sessions_ = sessionList; |
| + /** |
| + * Called when this element is initialized, and from the new tab page when |
| + * the user's signed in state changes, |
| + * @param {boolean} signedIn Is the user currently signed in? |
| + */ |
| + updateSignInState: function(signedIn) { |
| + if (signedIn) |
| + chrome.send('getForeignSessions'); |
| + else |
| + this.classList.add('invisible'); |
| }, |
| }; |