OLD | NEW |
1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. | 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 | 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/ui/webui/settings/appearance_handler.h" | 5 #include "chrome/browser/ui/webui/settings/appearance_handler.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/values.h" | 9 #include "base/values.h" |
10 #include "chrome/browser/chrome_notification_types.h" | 10 #include "chrome/browser/chrome_notification_types.h" |
11 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
12 #include "chrome/browser/themes/theme_service.h" | 12 #include "chrome/browser/themes/theme_service.h" |
13 #include "chrome/browser/themes/theme_service_factory.h" | 13 #include "chrome/browser/themes/theme_service_factory.h" |
14 #include "content/public/browser/notification_source.h" | 14 #include "content/public/browser/notification_source.h" |
15 #include "content/public/browser/web_ui.h" | 15 #include "content/public/browser/web_ui.h" |
16 | 16 |
| 17 #if defined(OS_CHROMEOS) |
| 18 #include "ash/desktop_background/user_wallpaper_delegate.h" |
| 19 #include "ash/shell.h" |
| 20 #endif |
| 21 |
17 namespace settings { | 22 namespace settings { |
18 | 23 |
19 AppearanceHandler::AppearanceHandler(content::WebUI* webui) | 24 AppearanceHandler::AppearanceHandler(content::WebUI* webui) |
20 : profile_(Profile::FromWebUI(webui)) { | 25 : profile_(Profile::FromWebUI(webui)) { |
21 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED, | 26 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED, |
22 content::Source<ThemeService>( | 27 content::Source<ThemeService>( |
23 ThemeServiceFactory::GetForProfile(profile_))); | 28 ThemeServiceFactory::GetForProfile(profile_))); |
24 } | 29 } |
25 | 30 |
26 AppearanceHandler::~AppearanceHandler() { | 31 AppearanceHandler::~AppearanceHandler() { |
27 registrar_.RemoveAll(); | 32 registrar_.RemoveAll(); |
28 } | 33 } |
29 | 34 |
30 void AppearanceHandler::RegisterMessages() { | 35 void AppearanceHandler::RegisterMessages() { |
31 web_ui()->RegisterMessageCallback( | 36 web_ui()->RegisterMessageCallback( |
32 "resetTheme", | 37 "resetTheme", |
33 base::Bind(&AppearanceHandler::ResetTheme, base::Unretained(this))); | 38 base::Bind(&AppearanceHandler::HandleResetTheme, base::Unretained(this))); |
34 web_ui()->RegisterMessageCallback( | 39 web_ui()->RegisterMessageCallback( |
35 "getResetThemeEnabled", | 40 "getResetThemeEnabled", |
36 base::Bind(&AppearanceHandler::GetResetThemeEnabled, | 41 base::Bind(&AppearanceHandler::HandleGetResetThemeEnabled, |
37 base::Unretained(this))); | 42 base::Unretained(this))); |
| 43 #if defined(OS_CHROMEOS) |
| 44 web_ui()->RegisterMessageCallback( |
| 45 "openWallpaperManager", |
| 46 base::Bind(&AppearanceHandler::HandleOpenWallpaperManager, |
| 47 base::Unretained(this))); |
| 48 #endif |
38 } | 49 } |
39 | 50 |
40 void AppearanceHandler::Observe( | 51 void AppearanceHandler::Observe( |
41 int type, | 52 int type, |
42 const content::NotificationSource& source, | 53 const content::NotificationSource& source, |
43 const content::NotificationDetails& details) { | 54 const content::NotificationDetails& details) { |
44 switch (type) { | 55 switch (type) { |
45 case chrome::NOTIFICATION_BROWSER_THEME_CHANGED: { | 56 case chrome::NOTIFICATION_BROWSER_THEME_CHANGED: { |
46 web_ui()->CallJavascriptFunction( | 57 web_ui()->CallJavascriptFunction( |
47 "cr.webUIListenerCallback", | 58 "cr.webUIListenerCallback", |
48 base::StringValue("reset-theme-enabled-changed"), | 59 base::StringValue("reset-theme-enabled-changed"), |
49 base::FundamentalValue(ResetThemeEnabled())); | 60 base::FundamentalValue(ResetThemeEnabled())); |
50 break; | 61 break; |
51 } | 62 } |
52 default: | 63 default: |
53 NOTREACHED(); | 64 NOTREACHED(); |
54 } | 65 } |
55 } | 66 } |
56 | 67 |
57 void AppearanceHandler::ResetTheme(const base::ListValue* /* args */) { | 68 void AppearanceHandler::HandleResetTheme(const base::ListValue* /*args*/) { |
58 ThemeServiceFactory::GetForProfile(profile_)->UseDefaultTheme(); | 69 ThemeServiceFactory::GetForProfile(profile_)->UseDefaultTheme(); |
59 } | 70 } |
60 | 71 |
61 bool AppearanceHandler::ResetThemeEnabled() const { | 72 bool AppearanceHandler::ResetThemeEnabled() const { |
62 // TODO(jhawkins): Handle native/system theme button. | 73 // TODO(jhawkins): Handle native/system theme button. |
63 return !ThemeServiceFactory::GetForProfile(profile_)->UsingDefaultTheme(); | 74 return !ThemeServiceFactory::GetForProfile(profile_)->UsingDefaultTheme(); |
64 } | 75 } |
65 | 76 |
66 void AppearanceHandler::GetResetThemeEnabled(const base::ListValue* args) { | 77 void AppearanceHandler::HandleGetResetThemeEnabled( |
| 78 const base::ListValue* args) { |
67 CHECK_EQ(1U, args->GetSize()); | 79 CHECK_EQ(1U, args->GetSize()); |
68 const base::Value* callback_id; | 80 const base::Value* callback_id; |
69 CHECK(args->Get(0, &callback_id)); | 81 CHECK(args->Get(0, &callback_id)); |
70 | |
71 ResolveJavascriptCallback(*callback_id, | 82 ResolveJavascriptCallback(*callback_id, |
72 base::FundamentalValue(ResetThemeEnabled())); | 83 base::FundamentalValue(ResetThemeEnabled())); |
73 } | 84 } |
74 | 85 |
| 86 #if defined(OS_CHROMEOS) |
| 87 void AppearanceHandler::HandleOpenWallpaperManager( |
| 88 const base::ListValue* /*args*/) { |
| 89 ash::Shell::GetInstance()->user_wallpaper_delegate()->OpenSetWallpaperPage(); |
| 90 } |
| 91 #endif |
| 92 |
75 } // namespace settings | 93 } // namespace settings |
OLD | NEW |