diff options
Diffstat (limited to 'chrome/browser/dom_ui/shown_sections_handler.cc')
-rw-r--r-- | chrome/browser/dom_ui/shown_sections_handler.cc | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/chrome/browser/dom_ui/shown_sections_handler.cc b/chrome/browser/dom_ui/shown_sections_handler.cc new file mode 100644 index 0000000..d9c3488 --- /dev/null +++ b/chrome/browser/dom_ui/shown_sections_handler.cc @@ -0,0 +1,54 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/dom_ui/shown_sections_handler.h" + +#include "base/string_util.h" +#include "base/values.h" +#include "chrome/browser/profile.h" +#include "chrome/common/pref_names.h" + +ShownSectionsHandler::ShownSectionsHandler(DOMUI* dom_ui) + : DOMMessageHandler(dom_ui), + dom_ui_(dom_ui) { + dom_ui->RegisterMessageCallback("getShownSections", + NewCallback(this, &ShownSectionsHandler::HandleGetShownSections)); + dom_ui->RegisterMessageCallback("setShownSections", + NewCallback(this, &ShownSectionsHandler::HandleSetShownSections)); +} + +void ShownSectionsHandler::HandleGetShownSections(const Value* value) { + const int mode = dom_ui_->GetProfile()->GetPrefs()-> + GetInteger(prefs::kNTPShownSections); + FundamentalValue* mode_value = new FundamentalValue(mode); + dom_ui_->CallJavascriptFunction(L"onShownSections", *mode_value); +} + +void ShownSectionsHandler::HandleSetShownSections(const Value* value) { + if (!value->IsType(Value::TYPE_LIST)) { + NOTREACHED(); + return; + } + + const ListValue* list = static_cast<const ListValue*>(value); + std::string mode_string; + + if (list->GetSize() < 1) { + NOTREACHED() << "setShownSections called with too few arguments"; + return; + } + + bool r = list->GetString(0, &mode_string); + DCHECK(r) << "Missing value in setShownSections from the NTP Most Visited."; + + dom_ui_->GetProfile()->GetPrefs()->SetInteger( + prefs::kNTPShownSections, StringToInt(mode_string)); +} + +// static +void ShownSectionsHandler::RegisterUserPrefs(PrefService* prefs) { + prefs->RegisterIntegerPref(prefs::kNTPShownSections, + THUMB | RECENT | RECOMMENDATIONS); +} + |