Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/dom_ui/shown_sections_handler.h" | 5 #include "chrome/browser/dom_ui/shown_sections_handler.h" |
| 6 | 6 |
| 7 #include "base/callback.h" | 7 #include "base/callback.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/string_number_conversions.h" | 9 #include "base/string_number_conversions.h" |
| 10 #include "base/values.h" | 10 #include "base/values.h" |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 48 return prefs->GetInteger(prefs::kNTPShownSections); | 48 return prefs->GetInteger(prefs::kNTPShownSections); |
| 49 } | 49 } |
| 50 | 50 |
| 51 ShownSectionsHandler::ShownSectionsHandler(PrefService* pref_service) | 51 ShownSectionsHandler::ShownSectionsHandler(PrefService* pref_service) |
| 52 : pref_service_(pref_service) { | 52 : pref_service_(pref_service) { |
| 53 pref_registrar_.Init(pref_service); | 53 pref_registrar_.Init(pref_service); |
| 54 pref_registrar_.Add(prefs::kNTPShownSections, this); | 54 pref_registrar_.Add(prefs::kNTPShownSections, this); |
| 55 } | 55 } |
| 56 | 56 |
| 57 void ShownSectionsHandler::RegisterMessages() { | 57 void ShownSectionsHandler::RegisterMessages() { |
| 58 notification_registrar_.Add(this, NotificationType::EXTENSION_INSTALLED, | |
|
Aaron Boodman
2010/11/11 17:59:13
Looks like this member is no longer used. Can you
Dmitry Polukhin
2010/11/11 20:08:20
Done.
| |
| 59 Source<Profile>(dom_ui_->GetProfile())); | |
| 60 | |
| 61 dom_ui_->RegisterMessageCallback("getShownSections", | 58 dom_ui_->RegisterMessageCallback("getShownSections", |
| 62 NewCallback(this, &ShownSectionsHandler::HandleGetShownSections)); | 59 NewCallback(this, &ShownSectionsHandler::HandleGetShownSections)); |
| 63 dom_ui_->RegisterMessageCallback("setShownSections", | 60 dom_ui_->RegisterMessageCallback("setShownSections", |
| 64 NewCallback(this, &ShownSectionsHandler::HandleSetShownSections)); | 61 NewCallback(this, &ShownSectionsHandler::HandleSetShownSections)); |
| 65 } | 62 } |
| 66 | 63 |
| 67 void ShownSectionsHandler::Observe(NotificationType type, | 64 void ShownSectionsHandler::Observe(NotificationType type, |
| 68 const NotificationSource& source, | 65 const NotificationSource& source, |
| 69 const NotificationDetails& details) { | 66 const NotificationDetails& details) { |
| 70 if (type == NotificationType::PREF_CHANGED) { | 67 if (type == NotificationType::PREF_CHANGED) { |
| 71 std::string* pref_name = Details<std::string>(details).ptr(); | 68 std::string* pref_name = Details<std::string>(details).ptr(); |
| 72 DCHECK(*pref_name == prefs::kNTPShownSections); | 69 DCHECK(*pref_name == prefs::kNTPShownSections); |
| 73 int sections = pref_service_->GetInteger(prefs::kNTPShownSections); | 70 int sections = pref_service_->GetInteger(prefs::kNTPShownSections); |
| 74 FundamentalValue sections_value(sections); | 71 FundamentalValue sections_value(sections); |
| 75 dom_ui_->CallJavascriptFunction(L"setShownSections", sections_value); | 72 dom_ui_->CallJavascriptFunction(L"setShownSections", sections_value); |
| 76 } else if (type == NotificationType::EXTENSION_INSTALLED) { | |
| 77 if (Details<const Extension>(details).ptr()->is_app()) { | |
| 78 int mode = pref_service_->GetInteger(prefs::kNTPShownSections); | |
| 79 | |
| 80 // De-minimize the apps section. | |
| 81 mode &= ~MINIMIZED_APPS; | |
| 82 | |
| 83 // Hide any open sections. | |
| 84 mode &= ~ALL_SECTIONS_MASK; | |
| 85 | |
| 86 // Show the apps section. | |
| 87 mode |= APPS; | |
| 88 | |
| 89 pref_service_->SetInteger(prefs::kNTPShownSections, mode); | |
| 90 } | |
| 91 } else { | 73 } else { |
| 92 NOTREACHED(); | 74 NOTREACHED(); |
| 93 } | 75 } |
| 94 } | 76 } |
| 95 | 77 |
| 96 void ShownSectionsHandler::HandleGetShownSections(const ListValue* args) { | 78 void ShownSectionsHandler::HandleGetShownSections(const ListValue* args) { |
| 97 int sections = GetShownSections(pref_service_); | 79 int sections = GetShownSections(pref_service_); |
| 98 FundamentalValue sections_value(sections); | 80 FundamentalValue sections_value(sections); |
| 99 dom_ui_->CallJavascriptFunction(L"onShownSections", sections_value); | 81 dom_ui_->CallJavascriptFunction(L"onShownSections", sections_value); |
| 100 } | 82 } |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 130 shown_sections = APPS; | 112 shown_sections = APPS; |
| 131 else | 113 else |
| 132 shown_sections = THUMB; | 114 shown_sections = THUMB; |
| 133 | 115 |
| 134 changed = true; | 116 changed = true; |
| 135 } | 117 } |
| 136 | 118 |
| 137 if (changed) | 119 if (changed) |
| 138 pref_service->SetInteger(prefs::kNTPShownSections, shown_sections); | 120 pref_service->SetInteger(prefs::kNTPShownSections, shown_sections); |
| 139 } | 121 } |
| 122 | |
| 123 // static | |
| 124 void ShownSectionsHandler::OnExtensionInstalled(PrefService* prefs, | |
| 125 const Extension* extension) { | |
| 126 if (extension->is_app()) { | |
| 127 int mode = prefs->GetInteger(prefs::kNTPShownSections); | |
| 128 | |
| 129 // De-minimize the apps section. | |
| 130 mode &= ~MINIMIZED_APPS; | |
| 131 | |
| 132 // Hide any open sections. | |
| 133 mode &= ~ALL_SECTIONS_MASK; | |
| 134 | |
| 135 // Show the apps section. | |
| 136 mode |= APPS; | |
| 137 | |
| 138 prefs->SetInteger(prefs::kNTPShownSections, mode); | |
| 139 } | |
| 140 } | |
| OLD | NEW |