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..cd9ffc1fb7aa21dc7174e38fa70c74afc00c7fb4 100644 |
--- a/chrome/browser/resources/ntp4/other_sessions.js |
+++ b/chrome/browser/resources/ntp4/other_sessions.js |
@@ -24,6 +24,8 @@ cr.define('ntp', function() { |
}; |
var HISTOGRAM_EVENT_LIMIT = HISTOGRAM_EVENT.LINK_RIGHT_CLICKED + 1; |
Dan Beam
2012/03/26 20:42:39
can you document when/where this will be changed
Patrick Dubroy
2012/03/26 21:41:47
Done.
|
+ var isUserSignedIn = false; |
+ |
OtherSessionsMenuButton.prototype = { |
__proto__: MenuButton.prototype, |
@@ -36,15 +38,26 @@ cr.define('ntp', function() { |
this.onContextMenu_.bind(this), true); |
document.body.appendChild(this.menu); |
+ // Put the promo content (hidden by default) into the menu. |
+ var messageContent = $('other-sessions-promo-message'); |
+ this.menu.appendChild(messageContent); |
Dan Beam
2012/03/26 20:42:39
nit: inline this
this.menu.appendChild($('other
Patrick Dubroy
2012/03/26 21:41:47
Done.
|
+ |
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 +89,16 @@ cr.define('ntp', function() { |
}, |
/** |
+ * Reset the menu to the default state. |
Dan Beam
2012/03/26 20:42:39
@private
Patrick Dubroy
2012/03/26 21:41:47
Done.
|
+ */ |
+ resetMenu_: function() { |
+ var promoContent = $('other-sessions-promo-message'); |
+ this.menu.innerHTML = ''; |
+ this.menu.appendChild(promoContent); |
+ promoContent.hidden = true; |
+ }, |
+ |
+ /** |
* 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 +145,45 @@ 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. |
Dan Beam
2012/03/26 20:42:39
@private
Patrick Dubroy
2012/03/26 21:41:47
Done.
|
*/ |
- showPromo_: function() { |
- var message = localStrings.getString('otherSessionsEmpty'); |
- this.menu.appendChild(this.ownerDocument.createTextNode(message)); |
+ setPromoVisible_: function(visible) { |
+ this.resetMenu_(); |
+ $('other-sessions-promo-message').hidden = !visible; |
}, |
/** |
* Sets the menu model data. |
* @param {Array} sessionList Array of objects describing the sessions |
- * from other devices. |
+ * from other devices. |
*/ |
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]); |
+ this.sessions_ = sessionList; |
+ this.setPromoVisible_(sessionList.length == 0); |
+ if (sessionList.length > 0) { |
+ // Rebuild the menu with the new data. |
+ for (var i = 0; i < sessionList.length; i++) { |
+ this.addSession_(sessionList[i]); |
+ } |
} |
+ // Make the menu button visible. |
+ this.classList.remove('invisible'); |
+ }, |
- if (sessionList.length == 0) |
- this.classList.add('invisible'); |
- else |
- this.classList.remove('invisible'); |
+ /** |
+ * Called 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) { |
Dan Beam
2012/03/26 20:42:39
if this is called nowhere else outside of this fun
Patrick Dubroy
2012/03/26 21:41:47
It's called from the ntp.js when the sign-in state
|
+ isUserSignedIn = signedIn; |
- this.sessions_ = sessionList; |
+ if (signedIn) |
+ chrome.send('getForeignSessions'); |
+ else |
+ this.classList.add('invisible'); |
}, |
}; |