Add new certificateProvider extension API.
[chromium-blink-merge.git] / chrome / browser / ui / webui / settings / appearance_handler.cc
blob01ead427b727565e29cd6d59b3d5e53fd5230bdf
1 // Copyright (c) 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/ui/webui/settings/appearance_handler.h"
7 #include "base/bind.h"
8 #include "base/logging.h"
9 #include "base/values.h"
10 #include "chrome/browser/chrome_notification_types.h"
11 #include "chrome/browser/profiles/profile.h"
12 #include "chrome/browser/themes/theme_service.h"
13 #include "chrome/browser/themes/theme_service_factory.h"
14 #include "content/public/browser/notification_source.h"
15 #include "content/public/browser/web_ui.h"
17 namespace settings {
19 AppearanceHandler::AppearanceHandler(content::WebUI* webui)
20 : profile_(Profile::FromWebUI(webui)) {
21 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED,
22 content::Source<ThemeService>(
23 ThemeServiceFactory::GetForProfile(profile_)));
26 AppearanceHandler::~AppearanceHandler() {
27 registrar_.RemoveAll();
30 void AppearanceHandler::RegisterMessages() {
31 web_ui()->RegisterMessageCallback(
32 "resetTheme",
33 base::Bind(&AppearanceHandler::ResetTheme, base::Unretained(this)));
34 web_ui()->RegisterMessageCallback(
35 "getResetThemeEnabled",
36 base::Bind(&AppearanceHandler::GetResetThemeEnabled,
37 base::Unretained(this)));
40 void AppearanceHandler::Observe(
41 int type,
42 const content::NotificationSource& source,
43 const content::NotificationDetails& details) {
44 switch (type) {
45 case chrome::NOTIFICATION_BROWSER_THEME_CHANGED: {
46 base::StringValue event("reset-theme-enabled-changed");
47 base::FundamentalValue enabled(QueryResetThemeEnabledState());
48 web_ui()->CallJavascriptFunction(
49 "cr.webUIListenerCallback", event, enabled);
50 break;
52 default:
53 NOTREACHED();
57 void AppearanceHandler::ResetTheme(const base::ListValue* /* args */) {
58 Profile* profile = Profile::FromWebUI(web_ui());
59 ThemeServiceFactory::GetForProfile(profile)->UseDefaultTheme();
62 base::FundamentalValue AppearanceHandler::QueryResetThemeEnabledState() {
63 ThemeService* theme_service = ThemeServiceFactory::GetForProfile(profile_);
64 bool is_system_theme = false;
66 // TODO(jhawkins): Handle native/system theme button.
68 bool is_classic_theme = !is_system_theme &&
69 theme_service->UsingDefaultTheme();
70 return base::FundamentalValue(!is_classic_theme);
73 void AppearanceHandler::GetResetThemeEnabled(const base::ListValue* args) {
74 CHECK_EQ(2U, args->GetSize());
76 std::string callbackFn;
77 CHECK(args->GetString(0, &callbackFn));
78 const base::Value* callbackId;
79 CHECK(args->Get(1, &callbackId));
81 base::FundamentalValue enabled(QueryResetThemeEnabledState());
82 web_ui()->CallJavascriptFunction(callbackFn, *callbackId, enabled);
85 } // namespace settings