Chromium Code Reviews| Index: chrome/browser/dom_ui/shown_sections_handler.cc |
| diff --git a/chrome/browser/dom_ui/shown_sections_handler.cc b/chrome/browser/dom_ui/shown_sections_handler.cc |
| index 381ea326103edbc6c54653340aa8dbeba2ad88f3..189c1c3d39b0d4a6c6a995e0d8772a238f0fbf92 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. |
|
Erik does not do reviews
2010/11/04 23:40:39
Shouldn't this be "minimize" rather than "hide"?
Aaron Boodman
2010/11/05 00:08:34
The nomenclature in NTP is all messed up. We unfor
|
| + mode &= ~ALL_SECTIONS_MASK; |
| + |
| + // Show the apps section. |
| + mode |= APPS; |
| + |
| + pref_service_->SetInteger(prefs::kNTPShownSections, mode); |
| + } |
| + } else { |
| + NOTREACHED(); |
| + } |
| } |
| void ShownSectionsHandler::HandleGetShownSections(const ListValue* args) { |