diff options
author | arv@chromium.org <arv@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-11 01:55:44 +0000 |
---|---|---|
committer | arv@chromium.org <arv@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-11 01:55:44 +0000 |
commit | a551ebd84a64c2723cae1b1c48eef602f9c3b44b (patch) | |
tree | d3e2fed57729cbbc06a74258426f65e9809583e0 /chrome/browser/resources | |
parent | 285a0674eadfe577c5f23484ac024b2371b9eac5 (diff) | |
download | chromium_src-a551ebd84a64c2723cae1b1c48eef602f9c3b44b.zip chromium_src-a551ebd84a64c2723cae1b1c48eef602f9c3b44b.tar.gz chromium_src-a551ebd84a64c2723cae1b1c48eef602f9c3b44b.tar.bz2 |
NTP: Sync shown sections across instances
This adds a pref observer for prefs::kNTPShownSections and calls a js function when these changes. This is so that instances of the NTP do not get out of sync with each other.
BUG=None
TEST=Open two or more NTPs. Hide and show different sections and the sections should be hidden and removed on all instances.
Review URL: http://codereview.chromium.org/2792004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@49487 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/resources')
-rw-r--r-- | chrome/browser/resources/new_new_tab.html | 1 | ||||
-rw-r--r-- | chrome/browser/resources/new_new_tab.js | 21 |
2 files changed, 20 insertions, 2 deletions
diff --git a/chrome/browser/resources/new_new_tab.html b/chrome/browser/resources/new_new_tab.html index 3be5df2..b29a3fa 100644 --- a/chrome/browser/resources/new_new_tab.html +++ b/chrome/browser/resources/new_new_tab.html @@ -52,6 +52,7 @@ registerCallback('syncMessageChanged'); registerCallback('tips'); registerCallback('onHomePageSet'); registerCallback('getAppsCallback'); +registerCallback('setShownSections'); </script> <!-- template data placeholder --> diff --git a/chrome/browser/resources/new_new_tab.js b/chrome/browser/resources/new_new_tab.js index 16d47b7..8fc13a7 100644 --- a/chrome/browser/resources/new_new_tab.js +++ b/chrome/browser/resources/new_new_tab.js @@ -239,7 +239,9 @@ function getSectionElement(section) { function showSection(section) { if (!(section & shownSections)) { shownSections |= section; - getSectionElement(section).classList.remove('hidden'); + var el = getSectionElement(section); + if (el) + el.classList.remove('hidden'); switch (section) { case Section.THUMB: @@ -267,7 +269,22 @@ function hideSection(section) { break; } - getSectionElement(section).classList.add('hidden'); + var el = getSectionElement(section); + if (el) + el.classList.add('hidden'); + } +} + +/** + * Callback when the shown sections changes in another NTP. + * @param {number} newShownSections Bitmask of the shown sections. + */ +function setShownSections(newShownSections) { + for (var key in Section) { + if (newShownSections & Section[key]) + showSection(Section[key]); + else + hideSection(Section[key]); } } |