Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/themes/theme_service.h" | 5 #include "chrome/browser/themes/theme_service.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 | 10 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 48 | 48 |
| 49 #if defined(ENABLE_EXTENSIONS) | 49 #if defined(ENABLE_EXTENSIONS) |
| 50 #include "extensions/browser/extension_registry_observer.h" | 50 #include "extensions/browser/extension_registry_observer.h" |
| 51 #endif | 51 #endif |
| 52 | 52 |
| 53 #if defined(ENABLE_SUPERVISED_USERS) | 53 #if defined(ENABLE_SUPERVISED_USERS) |
| 54 #include "chrome/browser/supervised_user/supervised_user_theme.h" | 54 #include "chrome/browser/supervised_user/supervised_user_theme.h" |
| 55 #endif | 55 #endif |
| 56 | 56 |
| 57 #if defined(OS_WIN) | 57 #if defined(OS_WIN) |
| 58 #include "base/win/windows_version.h" | |
| 59 #include "skia/ext/skia_utils_win.h" | |
| 58 #include "ui/base/win/shell.h" | 60 #include "ui/base/win/shell.h" |
| 59 #endif | 61 #endif |
| 60 | 62 |
| 61 using base::UserMetricsAction; | 63 using base::UserMetricsAction; |
| 62 using content::BrowserThread; | 64 using content::BrowserThread; |
| 63 using extensions::Extension; | 65 using extensions::Extension; |
| 64 using extensions::UnloadedExtensionInfo; | 66 using extensions::UnloadedExtensionInfo; |
| 65 using ui::ResourceBundle; | 67 using ui::ResourceBundle; |
| 66 | 68 |
| 67 // The default theme if we haven't installed a theme yet or if we've clicked | 69 // The default theme if we haven't installed a theme yet or if we've clicked |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 161 #endif // defined(ENABLE_EXTENSIONS) | 163 #endif // defined(ENABLE_EXTENSIONS) |
| 162 | 164 |
| 163 ThemeService::ThemeService() | 165 ThemeService::ThemeService() |
| 164 : ready_(false), | 166 : ready_(false), |
| 165 rb_(ResourceBundle::GetSharedInstance()), | 167 rb_(ResourceBundle::GetSharedInstance()), |
| 166 profile_(nullptr), | 168 profile_(nullptr), |
| 167 installed_pending_load_id_(kDefaultThemeID), | 169 installed_pending_load_id_(kDefaultThemeID), |
| 168 number_of_infobars_(0), | 170 number_of_infobars_(0), |
| 169 original_theme_provider_(*this, false), | 171 original_theme_provider_(*this, false), |
| 170 incognito_theme_provider_(*this, true), | 172 incognito_theme_provider_(*this, true), |
| 171 weak_ptr_factory_(this) {} | 173 weak_ptr_factory_(this) { |
| 174 #if defined(OS_WIN) | |
| 175 // This just checks for Windows 10 instead of calling ShouldUseDwmFrameColor() | |
| 176 // because we want to monitor the frame color even when a custom frame is in | |
| 177 // use, so that it will be correct if at any time the user switches to the | |
| 178 // native frame. | |
| 179 if (base::win::GetVersion() >= base::win::VERSION_WIN10) { | |
| 180 dwm_key_.reset(new base::win::RegKey( | |
| 181 HKEY_CURRENT_USER, L"SOFTWARE\\Microsoft\\Windows\\DWM", KEY_READ)); | |
|
Bret
2016/02/29 18:29:03
Are you sure this is actually the frame color? Whe
Peter Kasting
2016/02/29 19:57:06
On my system, the swatch color and the frame color
| |
| 182 OnDwmKeyUpdated(); | |
| 183 } | |
| 184 #endif | |
| 185 } | |
| 172 | 186 |
| 173 ThemeService::~ThemeService() { | 187 ThemeService::~ThemeService() { |
| 174 FreePlatformCaches(); | 188 FreePlatformCaches(); |
| 175 } | 189 } |
| 176 | 190 |
| 177 void ThemeService::Init(Profile* profile) { | 191 void ThemeService::Init(Profile* profile) { |
| 178 DCHECK(CalledOnValidThread()); | 192 DCHECK(CalledOnValidThread()); |
| 179 profile_ = profile; | 193 profile_ = profile; |
| 180 | 194 |
| 181 LoadThemePrefs(); | 195 LoadThemePrefs(); |
| (...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 468 SkColor color; | 482 SkColor color; |
| 469 if (theme_supplier_ && theme_supplier_->GetColor(theme_supplier_id, &color)) | 483 if (theme_supplier_ && theme_supplier_->GetColor(theme_supplier_id, &color)) |
| 470 return color; | 484 return color; |
| 471 | 485 |
| 472 // For backward compat with older themes, some newer colors are generated from | 486 // For backward compat with older themes, some newer colors are generated from |
| 473 // older ones if they are missing. | 487 // older ones if they are missing. |
| 474 const int kNtpText = ThemeProperties::COLOR_NTP_TEXT; | 488 const int kNtpText = ThemeProperties::COLOR_NTP_TEXT; |
| 475 const int kLabelBackground = | 489 const int kLabelBackground = |
| 476 ThemeProperties::COLOR_SUPERVISED_USER_LABEL_BACKGROUND; | 490 ThemeProperties::COLOR_SUPERVISED_USER_LABEL_BACKGROUND; |
| 477 switch (id) { | 491 switch (id) { |
| 492 #if defined(OS_WIN) | |
| 493 case ThemeProperties::COLOR_FRAME: | |
| 494 case ThemeProperties::COLOR_FRAME_INCOGNITO: | |
| 495 // Active native windows on Windows 10 may have a custom frame color. | |
| 496 if (ShouldUseDwmFrameColor()) | |
| 497 return dwm_frame_color_; | |
| 498 break; | |
| 499 case ThemeProperties::COLOR_FRAME_INACTIVE: | |
| 500 case ThemeProperties::COLOR_FRAME_INCOGNITO_INACTIVE: | |
| 501 // Inactive native windows on Windows 10 always have a white frame. | |
| 502 if (ShouldUseDwmFrameColor()) | |
| 503 return SK_ColorWHITE; | |
| 504 break; | |
| 505 #endif | |
| 478 case ThemeProperties::COLOR_TOOLBAR_BUTTON_ICON: | 506 case ThemeProperties::COLOR_TOOLBAR_BUTTON_ICON: |
| 479 return color_utils::HSLShift( | 507 return color_utils::HSLShift( |
| 480 gfx::kChromeIconGrey, | 508 gfx::kChromeIconGrey, |
| 481 GetTint(ThemeProperties::TINT_BUTTONS, incognito)); | 509 GetTint(ThemeProperties::TINT_BUTTONS, incognito)); |
| 482 case ThemeProperties::COLOR_TOOLBAR_BUTTON_ICON_INACTIVE: | 510 case ThemeProperties::COLOR_TOOLBAR_BUTTON_ICON_INACTIVE: |
| 483 // The active color is overridden in Gtk2UI. | 511 // The active color is overridden in Gtk2UI. |
| 484 return SkColorSetA( | 512 return SkColorSetA( |
| 485 GetColor(ThemeProperties::COLOR_TOOLBAR_BUTTON_ICON, incognito), | 513 GetColor(ThemeProperties::COLOR_TOOLBAR_BUTTON_ICON, incognito), |
| 486 0x33); | 514 0x33); |
| 487 case ThemeProperties::COLOR_BACKGROUND_TAB: { | 515 case ThemeProperties::COLOR_BACKGROUND_TAB: { |
| (...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 731 #if defined(ENABLE_SUPERVISED_USERS) | 759 #if defined(ENABLE_SUPERVISED_USERS) |
| 732 bool ThemeService::IsSupervisedUser() const { | 760 bool ThemeService::IsSupervisedUser() const { |
| 733 return profile_->IsSupervised(); | 761 return profile_->IsSupervised(); |
| 734 } | 762 } |
| 735 | 763 |
| 736 void ThemeService::SetSupervisedUserTheme() { | 764 void ThemeService::SetSupervisedUserTheme() { |
| 737 SetCustomDefaultTheme(new SupervisedUserTheme); | 765 SetCustomDefaultTheme(new SupervisedUserTheme); |
| 738 } | 766 } |
| 739 #endif | 767 #endif |
| 740 | 768 |
| 769 #if defined(OS_WIN) | |
| 770 bool ThemeService::ShouldUseDwmFrameColor() const { | |
| 771 return ShouldUseNativeFrame() && | |
| 772 (base::win::GetVersion() >= base::win::VERSION_WIN10); | |
| 773 } | |
| 774 | |
| 775 void ThemeService::OnDwmKeyUpdated() { | |
| 776 // Attempt to read the accent color. | |
| 777 DWORD accent_color, color_prevalence; | |
| 778 dwm_frame_color_ = | |
| 779 ((dwm_key_->ReadValueDW(L"ColorPrevalence", &color_prevalence) == | |
| 780 ERROR_SUCCESS) && | |
| 781 (color_prevalence == 1) && | |
| 782 (dwm_key_->ReadValueDW(L"AccentColor", &accent_color) == ERROR_SUCCESS)) | |
| 783 ? skia::COLORREFToSkColor(accent_color) | |
| 784 : SK_ColorWHITE; | |
| 785 | |
| 786 // Watch for future changes. | |
| 787 if (!dwm_key_->StartWatching( | |
| 788 base::Bind(&ThemeService::OnDwmKeyUpdated, base::Unretained(this)))) | |
| 789 dwm_key_.reset(); | |
| 790 } | |
| 791 #endif | |
| 792 | |
| 741 void ThemeService::OnInfobarDisplayed() { | 793 void ThemeService::OnInfobarDisplayed() { |
| 742 number_of_infobars_++; | 794 number_of_infobars_++; |
| 743 } | 795 } |
| 744 | 796 |
| 745 void ThemeService::OnInfobarDestroyed() { | 797 void ThemeService::OnInfobarDestroyed() { |
| 746 number_of_infobars_--; | 798 number_of_infobars_--; |
| 747 | 799 |
| 748 if (number_of_infobars_ == 0) | 800 if (number_of_infobars_ == 0) |
| 749 RemoveUnusedThemes(false); | 801 RemoveUnusedThemes(false); |
| 750 } | 802 } |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 796 | 848 |
| 797 bool ThemeService::BrowserThemeProvider::HasCustomImage(int id) const { | 849 bool ThemeService::BrowserThemeProvider::HasCustomImage(int id) const { |
| 798 return theme_service_.HasCustomImage(id); | 850 return theme_service_.HasCustomImage(id); |
| 799 } | 851 } |
| 800 | 852 |
| 801 base::RefCountedMemory* ThemeService::BrowserThemeProvider::GetRawData( | 853 base::RefCountedMemory* ThemeService::BrowserThemeProvider::GetRawData( |
| 802 int id, | 854 int id, |
| 803 ui::ScaleFactor scale_factor) const { | 855 ui::ScaleFactor scale_factor) const { |
| 804 return theme_service_.GetRawData(id, scale_factor); | 856 return theme_service_.GetRawData(id, scale_factor); |
| 805 } | 857 } |
| OLD | NEW |