diff options
author | aa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-05 17:05:22 +0000 |
---|---|---|
committer | aa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-05 17:05:22 +0000 |
commit | 26a70a153a51257706e27485e1382e1e25fbf4fe (patch) | |
tree | 83bd75b7a60fba9f878b5a678d5094f7754bcfca | |
parent | a01e0063c4e06678007daf9a6fd8cc0bff23c560 (diff) | |
download | chromium_src-26a70a153a51257706e27485e1382e1e25fbf4fe.zip chromium_src-26a70a153a51257706e27485e1382e1e25fbf4fe.tar.gz chromium_src-26a70a153a51257706e27485e1382e1e25fbf4fe.tar.bz2 |
Make sure the app section opens whenever a new apps is
installed, even if the installation is through default
installation.
BUG=61973
TEST=Have an app installed, then close apps section, then install a new app. Apps section should re-open.
Review URL: http://codereview.chromium.org/4506002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@65213 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/dom_ui/shown_sections_handler.cc | 39 | ||||
-rw-r--r-- | chrome/browser/dom_ui/shown_sections_handler.h | 7 | ||||
-rw-r--r-- | chrome/browser/resources/ntp/apps.js | 7 |
3 files changed, 36 insertions, 17 deletions
diff --git a/chrome/browser/dom_ui/shown_sections_handler.cc b/chrome/browser/dom_ui/shown_sections_handler.cc index 381ea32..189c1c3 100644 --- a/chrome/browser/dom_ui/shown_sections_handler.cc +++ b/chrome/browser/dom_ui/shown_sections_handler.cc @@ -14,6 +14,7 @@ #include "chrome/common/chrome_switches.h" #include "chrome/common/extensions/extension.h" #include "chrome/common/notification_details.h" +#include "chrome/common/notification_source.h" #include "chrome/common/notification_type.h" #include "chrome/common/pref_names.h" @@ -49,11 +50,14 @@ int ShownSectionsHandler::GetShownSections(PrefService* prefs) { ShownSectionsHandler::ShownSectionsHandler(PrefService* pref_service) : pref_service_(pref_service) { - registrar_.Init(pref_service); - registrar_.Add(prefs::kNTPShownSections, this); + pref_registrar_.Init(pref_service); + pref_registrar_.Add(prefs::kNTPShownSections, this); } void ShownSectionsHandler::RegisterMessages() { + notification_registrar_.Add(this, NotificationType::EXTENSION_INSTALLED, + Source<Profile>(dom_ui_->GetProfile())); + dom_ui_->RegisterMessageCallback("getShownSections", NewCallback(this, &ShownSectionsHandler::HandleGetShownSections)); dom_ui_->RegisterMessageCallback("setShownSections", @@ -63,13 +67,30 @@ void ShownSectionsHandler::RegisterMessages() { void ShownSectionsHandler::Observe(NotificationType type, const NotificationSource& source, const NotificationDetails& details) { - DCHECK(NotificationType::PREF_CHANGED == type); - std::string* pref_name = Details<std::string>(details).ptr(); - DCHECK(*pref_name == prefs::kNTPShownSections); - - int sections = pref_service_->GetInteger(prefs::kNTPShownSections); - FundamentalValue sections_value(sections); - dom_ui_->CallJavascriptFunction(L"setShownSections", sections_value); + if (type == NotificationType::PREF_CHANGED) { + std::string* pref_name = Details<std::string>(details).ptr(); + DCHECK(*pref_name == prefs::kNTPShownSections); + int sections = pref_service_->GetInteger(prefs::kNTPShownSections); + FundamentalValue sections_value(sections); + dom_ui_->CallJavascriptFunction(L"setShownSections", sections_value); + } else if (type == NotificationType::EXTENSION_INSTALLED) { + if (Details<const Extension>(details).ptr()->is_app()) { + int mode = pref_service_->GetInteger(prefs::kNTPShownSections); + + // De-minimize the apps section. + mode &= ~MINIMIZED_APPS; + + // Hide any open sections. + mode &= ~ALL_SECTIONS_MASK; + + // Show the apps section. + mode |= APPS; + + pref_service_->SetInteger(prefs::kNTPShownSections, mode); + } + } else { + NOTREACHED(); + } } void ShownSectionsHandler::HandleGetShownSections(const ListValue* args) { diff --git a/chrome/browser/dom_ui/shown_sections_handler.h b/chrome/browser/dom_ui/shown_sections_handler.h index be07735..e82c3fb 100644 --- a/chrome/browser/dom_ui/shown_sections_handler.h +++ b/chrome/browser/dom_ui/shown_sections_handler.h @@ -8,6 +8,7 @@ #include "chrome/browser/dom_ui/dom_ui.h" #include "chrome/common/notification_observer.h" +#include "chrome/common/notification_registrar.h" #include "chrome/browser/prefs/pref_change_registrar.h" class DOMUI; @@ -23,6 +24,9 @@ enum Section { THUMB = 1 << 0, APPS = 1 << 6, + // We use the low 16 bits for sections, the high 16 bits for minimized state. + ALL_SECTIONS_MASK = 0x0000FFFF, + // If one of these is set, then the corresponding section is shown minimized // at the bottom of the NTP and no data is directly visible on the NTP. MINIMIZED_THUMB = 1 << (0 + 16), @@ -61,7 +65,8 @@ class ShownSectionsHandler : public DOMMessageHandler, private: PrefService* pref_service_; - PrefChangeRegistrar registrar_; + PrefChangeRegistrar pref_registrar_; + NotificationRegistrar notification_registrar_; DISALLOW_COPY_AND_ASSIGN(ShownSectionsHandler); }; diff --git a/chrome/browser/resources/ntp/apps.js b/chrome/browser/resources/ntp/apps.js index 52cafff..81d7eb0 100644 --- a/chrome/browser/resources/ntp/apps.js +++ b/chrome/browser/resources/ntp/apps.js @@ -252,13 +252,6 @@ var apps = (function() { document.documentElement.setAttribute("install-animation-enabled", "false"); }); - - // Make sure apps is de-minimized... - setSectionVisible('apps', Section.APPS, true, MINIMIZED_APPS); - - // ...and expanded. - if ($('apps').classList.contains('hidden')) - toggleSectionVisibilityAndAnimate('APPS'); } var settingsButton = div.appendChild(new cr.ui.ContextMenuButton); |