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

Unified 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: Fix copyright header. 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/resources/ntp4/new_tab.js ('k') | chrome/browser/ui/webui/ntp/foreign_session_handler.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..9abd87550e3db175d6179bbfb693aa7a6e1c39ca 100644
--- a/chrome/browser/resources/ntp4/other_sessions.js
+++ b/chrome/browser/resources/ntp4/other_sessions.js
@@ -36,15 +36,25 @@ cr.define('ntp', function() {
this.onContextMenu_.bind(this), true);
document.body.appendChild(this.menu);
+ this.promoMessage_ = $('other-sessions-promo-template').cloneNode(true);
+ this.promoMessage_.removeAttribute('id'); // Prevent a duplicate id.
+
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 +86,15 @@ cr.define('ntp', function() {
},
/**
+ * Reset the menu contents to the default state.
+ * @private
+ */
+ resetMenuContents_: function() {
+ this.menu.innerHTML = '';
+ this.menu.appendChild(this.promoMessage_);
+ },
+
+ /**
* 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 +141,41 @@ 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.
- */
- showPromo_: function() {
- var message = localStrings.getString('otherSessionsEmpty');
- this.menu.appendChild(this.ownerDocument.createTextNode(message));
- },
-
- /**
- * 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.resetMenuContents_();
+ 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');
},
};
« no previous file with comments | « chrome/browser/resources/ntp4/new_tab.js ('k') | chrome/browser/ui/webui/ntp/foreign_session_handler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698