Add new certificateProvider extension API.
[chromium-blink-merge.git] / chrome / browser / themes / theme_service_aurax11.cc
blob7f25e50053d4e7bc1cba4ba21c31072ef831928e
1 // Copyright 2013 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/themes/theme_service_aurax11.h"
7 #include "base/bind.h"
8 #include "base/prefs/pref_service.h"
9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/themes/custom_theme_supplier.h"
11 #include "chrome/common/pref_names.h"
12 #include "ui/gfx/image/image.h"
13 #include "ui/native_theme/native_theme_aura.h"
14 #include "ui/views/linux_ui/linux_ui.h"
16 namespace {
18 class SystemThemeX11 : public CustomThemeSupplier {
19 public:
20 explicit SystemThemeX11(PrefService* pref_service);
22 // Overridden from CustomThemeSupplier:
23 void StartUsingTheme() override;
24 void StopUsingTheme() override;
25 bool GetColor(int id, SkColor* color) const override;
26 gfx::Image GetImageNamed(int id) override;
27 bool HasCustomImage(int id) const override;
29 private:
30 ~SystemThemeX11() override;
32 // These pointers are not owned by us.
33 views::LinuxUI* const linux_ui_;
34 PrefService* const pref_service_;
36 DISALLOW_COPY_AND_ASSIGN(SystemThemeX11);
39 SystemThemeX11::SystemThemeX11(PrefService* pref_service)
40 : CustomThemeSupplier(NATIVE_X11),
41 linux_ui_(views::LinuxUI::instance()),
42 pref_service_(pref_service) {}
44 void SystemThemeX11::StartUsingTheme() {
45 pref_service_->SetBoolean(prefs::kUsesSystemTheme, true);
46 // Have the former theme notify its observers of change.
47 ui::NativeThemeAura::instance()->NotifyObservers();
50 void SystemThemeX11::StopUsingTheme() {
51 pref_service_->SetBoolean(prefs::kUsesSystemTheme, false);
52 // Have the former theme notify its observers of change.
53 if (linux_ui_)
54 linux_ui_->GetNativeTheme(NULL)->NotifyObservers();
57 bool SystemThemeX11::GetColor(int id, SkColor* color) const {
58 return linux_ui_ && linux_ui_->GetColor(id, color);
61 gfx::Image SystemThemeX11::GetImageNamed(int id) {
62 return linux_ui_ ? linux_ui_->GetThemeImageNamed(id) : gfx::Image();
65 bool SystemThemeX11::HasCustomImage(int id) const {
66 return linux_ui_ && linux_ui_->HasCustomImage(id);
69 SystemThemeX11::~SystemThemeX11() {}
71 } // namespace
73 ThemeServiceAuraX11::ThemeServiceAuraX11() {}
75 ThemeServiceAuraX11::~ThemeServiceAuraX11() {}
77 bool ThemeServiceAuraX11::ShouldInitWithSystemTheme() const {
78 return profile()->GetPrefs()->GetBoolean(prefs::kUsesSystemTheme);
81 void ThemeServiceAuraX11::UseSystemTheme() {
82 SetCustomDefaultTheme(new SystemThemeX11(profile()->GetPrefs()));
85 bool ThemeServiceAuraX11::IsSystemThemeDistinctFromDefaultTheme() const {
86 return true;
89 bool ThemeServiceAuraX11::UsingDefaultTheme() const {
90 return ThemeService::UsingDefaultTheme() && !UsingSystemTheme();
93 bool ThemeServiceAuraX11::UsingSystemTheme() const {
94 const CustomThemeSupplier* theme_supplier = get_theme_supplier();
95 return theme_supplier &&
96 theme_supplier->get_theme_type() == CustomThemeSupplier::NATIVE_X11;