summaryrefslogtreecommitdiffstats
path: root/chrome/browser/dom_ui/shown_sections_handler.cc
diff options
context:
space:
mode:
authorBen Murdoch <benm@google.com>2010-11-18 18:32:45 +0000
committerBen Murdoch <benm@google.com>2010-11-18 18:38:07 +0000
commit513209b27ff55e2841eac0e4120199c23acce758 (patch)
treeaeba30bb08c5f47c57003544e378a377c297eee6 /chrome/browser/dom_ui/shown_sections_handler.cc
parent164f7496de0fbee436b385a79ead9e3cb81a50c1 (diff)
downloadexternal_chromium-513209b27ff55e2841eac0e4120199c23acce758.zip
external_chromium-513209b27ff55e2841eac0e4120199c23acce758.tar.gz
external_chromium-513209b27ff55e2841eac0e4120199c23acce758.tar.bz2
Merge Chromium at r65505: Initial merge by git.
Change-Id: I31d8f1d8cd33caaf7f47ffa7350aef42d5fbdb45
Diffstat (limited to 'chrome/browser/dom_ui/shown_sections_handler.cc')
-rw-r--r--chrome/browser/dom_ui/shown_sections_handler.cc39
1 files changed, 30 insertions, 9 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) {