Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(74)

Side by Side Diff: chrome/browser/ui/webui/settings/appearance_handler.cc

Issue 2413623004: MD Settings: allow changing to GTK+ theme on Linux (Closed)
Patch Set: rejigger tests Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
11 #include "chrome/browser/profiles/profile.h" 10 #include "chrome/browser/profiles/profile.h"
12 #include "chrome/browser/themes/theme_service.h" 11 #include "chrome/browser/themes/theme_service.h"
13 #include "chrome/browser/themes/theme_service_factory.h" 12 #include "chrome/browser/themes/theme_service_factory.h"
14 #include "content/public/browser/notification_source.h"
15 #include "content/public/browser/web_ui.h" 13 #include "content/public/browser/web_ui.h"
16 14
17 #if defined(OS_CHROMEOS) 15 #if defined(OS_CHROMEOS)
18 #include "ash/common/wallpaper/wallpaper_delegate.h" // nogncheck 16 #include "ash/common/wallpaper/wallpaper_delegate.h" // nogncheck
19 #include "ash/common/wm_shell.h" // nogncheck 17 #include "ash/common/wm_shell.h" // nogncheck
20 #endif 18 #endif
21 19
22 namespace settings { 20 namespace settings {
23 21
24 AppearanceHandler::AppearanceHandler(content::WebUI* webui) 22 AppearanceHandler::AppearanceHandler(content::WebUI* webui)
25 : profile_(Profile::FromWebUI(webui)) { 23 : profile_(Profile::FromWebUI(webui)) {
26 } 24 }
27 25
28 AppearanceHandler::~AppearanceHandler() {} 26 AppearanceHandler::~AppearanceHandler() {}
29 27
28 void AppearanceHandler::OnJavascriptAllowed() {}
29 void AppearanceHandler::OnJavascriptDisallowed() {}
30
30 void AppearanceHandler::RegisterMessages() { 31 void AppearanceHandler::RegisterMessages() {
31 web_ui()->RegisterMessageCallback( 32 web_ui()->RegisterMessageCallback(
32 "resetTheme", 33 "useDefaultTheme",
33 base::Bind(&AppearanceHandler::HandleResetTheme, base::Unretained(this))); 34 base::Bind(&AppearanceHandler::HandleUseDefaultTheme,
35 base::Unretained(this)));
36 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
34 web_ui()->RegisterMessageCallback( 37 web_ui()->RegisterMessageCallback(
35 "getResetThemeEnabled", 38 "useSystemTheme",
36 base::Bind(&AppearanceHandler::HandleGetResetThemeEnabled, 39 base::Bind(&AppearanceHandler::HandleUseSystemTheme,
37 base::Unretained(this))); 40 base::Unretained(this)));
41 #endif
38 #if defined(OS_CHROMEOS) 42 #if defined(OS_CHROMEOS)
39 web_ui()->RegisterMessageCallback( 43 web_ui()->RegisterMessageCallback(
40 "openWallpaperManager", 44 "openWallpaperManager",
41 base::Bind(&AppearanceHandler::HandleOpenWallpaperManager, 45 base::Bind(&AppearanceHandler::HandleOpenWallpaperManager,
42 base::Unretained(this))); 46 base::Unretained(this)));
43 #endif 47 #endif
44 } 48 }
45 49
46 void AppearanceHandler::OnJavascriptAllowed() { 50 void AppearanceHandler::HandleUseDefaultTheme(const base::ListValue* args) {
47 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED,
48 content::Source<ThemeService>(
49 ThemeServiceFactory::GetForProfile(profile_)));
50 }
51
52 void AppearanceHandler::OnJavascriptDisallowed() {
53 registrar_.RemoveAll();
54 }
55
56 void AppearanceHandler::Observe(
57 int type,
58 const content::NotificationSource& source,
59 const content::NotificationDetails& details) {
60 DCHECK_EQ(chrome::NOTIFICATION_BROWSER_THEME_CHANGED, type);
61
62 CallJavascriptFunction("cr.webUIListenerCallback",
dpapad 2016/10/13 18:31:20 Why don't we need to listen to this anymore?
Dan Beam 2016/10/13 18:56:53 because observing the prefs is basically the same
63 base::StringValue("reset-theme-enabled-changed"),
64 base::FundamentalValue(ResetThemeEnabled()));
65 }
66
67 void AppearanceHandler::HandleResetTheme(const base::ListValue* /*args*/) {
68 ThemeServiceFactory::GetForProfile(profile_)->UseDefaultTheme(); 51 ThemeServiceFactory::GetForProfile(profile_)->UseDefaultTheme();
69 } 52 }
70 53
71 bool AppearanceHandler::ResetThemeEnabled() const { 54 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
72 // TODO(jhawkins): Handle native/system theme button. 55 void AppearanceHandler::HandleUseSystemTheme(const base::ListValue* args) {
73 return !ThemeServiceFactory::GetForProfile(profile_)->UsingDefaultTheme(); 56 ThemeServiceFactory::GetForProfile(profile_)->UseSystemTheme();
74 } 57 }
75 58 #endif
76 void AppearanceHandler::HandleGetResetThemeEnabled(
77 const base::ListValue* args) {
78 AllowJavascript();
79
80 CHECK_EQ(1U, args->GetSize());
81 const base::Value* callback_id;
82 CHECK(args->Get(0, &callback_id));
83 ResolveJavascriptCallback(*callback_id,
84 base::FundamentalValue(ResetThemeEnabled()));
85 }
86 59
87 #if defined(OS_CHROMEOS) 60 #if defined(OS_CHROMEOS)
88 void AppearanceHandler::HandleOpenWallpaperManager( 61 void AppearanceHandler::HandleOpenWallpaperManager(
89 const base::ListValue* /*args*/) { 62 const base::ListValue* /*args*/) {
90 ash::WmShell::Get()->wallpaper_delegate()->OpenSetWallpaperPage(); 63 ash::WmShell::Get()->wallpaper_delegate()->OpenSetWallpaperPage();
91 } 64 }
92 #endif 65 #endif
93 66
94 } // namespace settings 67 } // namespace settings
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698