blob: 4cfd6e3dadbdb5c94bf225bdd514e43c8f693360 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
// Copyright (c) 2012 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/ui/webui/ntp/new_tab_page_handler.h"
#include "base/bind.h"
#include "base/bind_helpers.h"
#include "base/memory/scoped_ptr.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/webui/ntp/new_tab_ui.h"
#include "chrome/common/pref_names.h"
#include "components/browser_sync/browser/profile_sync_service.h"
#include "components/pref_registry/pref_registry_syncable.h"
#include "components/prefs/pref_service.h"
#include "content/public/browser/web_ui.h"
NewTabPageHandler::NewTabPageHandler() : page_switch_count_(0) {
}
NewTabPageHandler::~NewTabPageHandler() {}
void NewTabPageHandler::RegisterMessages() {
web_ui()->RegisterMessageCallback("pageSelected",
base::Bind(&NewTabPageHandler::HandlePageSelected,
base::Unretained(this)));
}
void NewTabPageHandler::HandlePageSelected(const base::ListValue* args) {
page_switch_count_++;
double page_id_double;
CHECK(args->GetDouble(0, &page_id_double));
int page_id = static_cast<int>(page_id_double);
double index_double;
CHECK(args->GetDouble(1, &index_double));
int index = static_cast<int>(index_double);
PrefService* prefs = Profile::FromWebUI(web_ui())->GetPrefs();
prefs->SetInteger(prefs::kNtpShownPage, page_id | index);
}
// static
void NewTabPageHandler::RegisterProfilePrefs(
user_prefs::PrefRegistrySyncable* registry) {
// TODO(estade): should be syncable.
registry->RegisterIntegerPref(prefs::kNtpShownPage, APPS_PAGE_ID);
}
// static
void NewTabPageHandler::GetLocalizedValues(Profile* profile,
base::DictionaryValue* values) {
values->SetInteger("apps_page_id", APPS_PAGE_ID);
PrefService* prefs = profile->GetPrefs();
int shown_page = prefs->GetInteger(prefs::kNtpShownPage);
values->SetInteger("shown_page_type", shown_page & ~INDEX_MASK);
values->SetInteger("shown_page_index", shown_page & INDEX_MASK);
}
|