| Index: chrome/browser/themes/theme_service.cc
|
| diff --git a/chrome/browser/themes/theme_service.cc b/chrome/browser/themes/theme_service.cc
|
| index 02d80af857d45095e090c00b3e1ce0e199d09a2e..6cd110208a2e13fee758862d5f00b787e2579779 100644
|
| --- a/chrome/browser/themes/theme_service.cc
|
| +++ b/chrome/browser/themes/theme_service.cc
|
| @@ -54,6 +54,10 @@
|
| #include "chrome/browser/supervised_user/supervised_user_theme.h"
|
| #endif
|
|
|
| +#if defined(OS_WIN)
|
| +#include "ui/base/win/shell.h"
|
| +#endif
|
| +
|
| using base::UserMetricsAction;
|
| using content::BrowserThread;
|
| using extensions::Extension;
|
| @@ -409,7 +413,132 @@
|
| return false;
|
| }
|
|
|
| -SkColor ThemeService::GetDefaultColor(int id, bool incognito) const {
|
| +color_utils::HSL ThemeService::GetTint(int id, bool incognito) const {
|
| + DCHECK(CalledOnValidThread());
|
| +
|
| + color_utils::HSL hsl;
|
| + if (theme_supplier_ && theme_supplier_->GetTint(id, &hsl))
|
| + return hsl;
|
| +
|
| + return ThemeProperties::GetDefaultTint(id, incognito);
|
| +}
|
| +
|
| +void ThemeService::ClearAllThemeData() {
|
| + if (!ready_)
|
| + return;
|
| +
|
| + SwapThemeSupplier(nullptr);
|
| +
|
| + // Clear our image cache.
|
| + FreePlatformCaches();
|
| +
|
| + profile_->GetPrefs()->ClearPref(prefs::kCurrentThemePackFilename);
|
| + SaveThemeID(kDefaultThemeID);
|
| +
|
| + // There should be no more infobars. This may not be the case because of
|
| + // http://crbug.com/62154
|
| + // RemoveUnusedThemes is called on a task because ClearAllThemeData() may
|
| + // be called as a result of NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED.
|
| + base::ThreadTaskRunnerHandle::Get()->PostTask(
|
| + FROM_HERE, base::Bind(&ThemeService::RemoveUnusedThemes,
|
| + weak_ptr_factory_.GetWeakPtr(), true));
|
| +}
|
| +
|
| +void ThemeService::LoadThemePrefs() {
|
| + PrefService* prefs = profile_->GetPrefs();
|
| +
|
| + std::string current_id = GetThemeID();
|
| + if (current_id == kDefaultThemeID) {
|
| +#if defined(ENABLE_SUPERVISED_USERS)
|
| + // Supervised users have a different default theme.
|
| + if (IsSupervisedUser()) {
|
| + SetSupervisedUserTheme();
|
| + set_ready();
|
| + return;
|
| + }
|
| +#endif
|
| + if (ShouldInitWithSystemTheme())
|
| + UseSystemTheme();
|
| + else
|
| + UseDefaultTheme();
|
| + set_ready();
|
| + return;
|
| + }
|
| +
|
| + bool loaded_pack = false;
|
| +
|
| + // If we don't have a file pack, we're updating from an old version, or the
|
| + // pack was created for an alternative MaterialDesignController::Mode.
|
| + base::FilePath path = prefs->GetFilePath(prefs::kCurrentThemePackFilename);
|
| + if (path != base::FilePath()) {
|
| + path = path.Append(ui::MaterialDesignController::IsModeMaterial()
|
| + ? chrome::kThemePackMaterialDesignFilename
|
| + : chrome::kThemePackFilename);
|
| + SwapThemeSupplier(BrowserThemePack::BuildFromDataPack(path, current_id));
|
| + loaded_pack = theme_supplier_ != nullptr;
|
| + }
|
| +
|
| + if (loaded_pack) {
|
| + content::RecordAction(UserMetricsAction("Themes.Loaded"));
|
| + set_ready();
|
| + }
|
| + // Else: wait for the extension service to be ready so that the theme pack
|
| + // can be recreated from the extension.
|
| +}
|
| +
|
| +void ThemeService::NotifyThemeChanged() {
|
| + if (!ready_)
|
| + return;
|
| +
|
| + DVLOG(1) << "Sending BROWSER_THEME_CHANGED";
|
| + // Redraw!
|
| + content::NotificationService* service =
|
| + content::NotificationService::current();
|
| + service->Notify(chrome::NOTIFICATION_BROWSER_THEME_CHANGED,
|
| + content::Source<ThemeService>(this),
|
| + content::NotificationService::NoDetails());
|
| +#if defined(OS_MACOSX)
|
| + NotifyPlatformThemeChanged();
|
| +#endif // OS_MACOSX
|
| +
|
| + // Notify sync that theme has changed.
|
| + if (theme_syncable_service_.get()) {
|
| + theme_syncable_service_->OnThemeChange();
|
| + }
|
| +}
|
| +
|
| +#if defined(USE_AURA)
|
| +void ThemeService::FreePlatformCaches() {
|
| + // Views (Skia) has no platform image cache to clear.
|
| +}
|
| +#endif
|
| +
|
| +gfx::ImageSkia* ThemeService::GetImageSkiaNamed(int id, bool incognito) const {
|
| + gfx::Image image = GetImageNamed(id, incognito);
|
| + if (image.IsEmpty())
|
| + return nullptr;
|
| + // TODO(pkotwicz): Remove this const cast. The gfx::Image interface returns
|
| + // its images const. GetImageSkiaNamed() also should but has many callsites.
|
| + return const_cast<gfx::ImageSkia*>(image.ToImageSkia());
|
| +}
|
| +
|
| +SkColor ThemeService::GetColor(int id, bool incognito) const {
|
| + DCHECK(CalledOnValidThread());
|
| +
|
| + // For legacy reasons, |theme_supplier_| requires the incognito variants
|
| + // of color IDs.
|
| + int theme_supplier_id = id;
|
| + if (incognito) {
|
| + if (id == ThemeProperties::COLOR_FRAME)
|
| + theme_supplier_id = ThemeProperties::COLOR_FRAME_INCOGNITO;
|
| + else if (id == ThemeProperties::COLOR_FRAME_INACTIVE)
|
| + theme_supplier_id = ThemeProperties::COLOR_FRAME_INCOGNITO_INACTIVE;
|
| + }
|
| +
|
| + SkColor color;
|
| + if (theme_supplier_ && theme_supplier_->GetColor(theme_supplier_id, &color))
|
| + return color;
|
| +
|
| // For backward compat with older themes, some newer colors are generated from
|
| // older ones if they are missing.
|
| const int kNtpText = ThemeProperties::COLOR_NTP_TEXT;
|
| @@ -497,144 +626,6 @@
|
| return ThemeProperties::GetDefaultColor(id, incognito);
|
| }
|
|
|
| -color_utils::HSL ThemeService::GetTint(int id, bool incognito) const {
|
| - DCHECK(CalledOnValidThread());
|
| -
|
| - color_utils::HSL hsl;
|
| - if (theme_supplier_ && theme_supplier_->GetTint(id, &hsl))
|
| - return hsl;
|
| -
|
| - return ThemeProperties::GetDefaultTint(id, incognito);
|
| -}
|
| -
|
| -void ThemeService::ClearAllThemeData() {
|
| - if (!ready_)
|
| - return;
|
| -
|
| - SwapThemeSupplier(nullptr);
|
| -
|
| - // Clear our image cache.
|
| - FreePlatformCaches();
|
| -
|
| - profile_->GetPrefs()->ClearPref(prefs::kCurrentThemePackFilename);
|
| - SaveThemeID(kDefaultThemeID);
|
| -
|
| - // There should be no more infobars. This may not be the case because of
|
| - // http://crbug.com/62154
|
| - // RemoveUnusedThemes is called on a task because ClearAllThemeData() may
|
| - // be called as a result of NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED.
|
| - base::ThreadTaskRunnerHandle::Get()->PostTask(
|
| - FROM_HERE, base::Bind(&ThemeService::RemoveUnusedThemes,
|
| - weak_ptr_factory_.GetWeakPtr(), true));
|
| -}
|
| -
|
| -void ThemeService::LoadThemePrefs() {
|
| - PrefService* prefs = profile_->GetPrefs();
|
| -
|
| - std::string current_id = GetThemeID();
|
| - if (current_id == kDefaultThemeID) {
|
| -#if defined(ENABLE_SUPERVISED_USERS)
|
| - // Supervised users have a different default theme.
|
| - if (IsSupervisedUser()) {
|
| - SetSupervisedUserTheme();
|
| - set_ready();
|
| - return;
|
| - }
|
| -#endif
|
| - if (ShouldInitWithSystemTheme())
|
| - UseSystemTheme();
|
| - else
|
| - UseDefaultTheme();
|
| - set_ready();
|
| - return;
|
| - }
|
| -
|
| - bool loaded_pack = false;
|
| -
|
| - // If we don't have a file pack, we're updating from an old version, or the
|
| - // pack was created for an alternative MaterialDesignController::Mode.
|
| - base::FilePath path = prefs->GetFilePath(prefs::kCurrentThemePackFilename);
|
| - if (path != base::FilePath()) {
|
| - path = path.Append(ui::MaterialDesignController::IsModeMaterial()
|
| - ? chrome::kThemePackMaterialDesignFilename
|
| - : chrome::kThemePackFilename);
|
| - SwapThemeSupplier(BrowserThemePack::BuildFromDataPack(path, current_id));
|
| - loaded_pack = theme_supplier_ != nullptr;
|
| - }
|
| -
|
| - if (loaded_pack) {
|
| - content::RecordAction(UserMetricsAction("Themes.Loaded"));
|
| - set_ready();
|
| - }
|
| - // Else: wait for the extension service to be ready so that the theme pack
|
| - // can be recreated from the extension.
|
| -}
|
| -
|
| -void ThemeService::NotifyThemeChanged() {
|
| - if (!ready_)
|
| - return;
|
| -
|
| - DVLOG(1) << "Sending BROWSER_THEME_CHANGED";
|
| - // Redraw!
|
| - content::NotificationService* service =
|
| - content::NotificationService::current();
|
| - service->Notify(chrome::NOTIFICATION_BROWSER_THEME_CHANGED,
|
| - content::Source<ThemeService>(this),
|
| - content::NotificationService::NoDetails());
|
| -#if defined(OS_MACOSX)
|
| - NotifyPlatformThemeChanged();
|
| -#endif // OS_MACOSX
|
| -
|
| - // Notify sync that theme has changed.
|
| - if (theme_syncable_service_.get()) {
|
| - theme_syncable_service_->OnThemeChange();
|
| - }
|
| -}
|
| -
|
| -#if defined(USE_AURA)
|
| -void ThemeService::FreePlatformCaches() {
|
| - // Views (Skia) has no platform image cache to clear.
|
| -}
|
| -#endif
|
| -
|
| -bool ThemeService::ShouldUseNativeFrame() const {
|
| - return false;
|
| -}
|
| -
|
| -bool ThemeService::HasCustomImage(int id) const {
|
| - return BrowserThemePack::IsPersistentImageID(id) && theme_supplier_ &&
|
| - theme_supplier_->HasCustomImage(id);
|
| -}
|
| -
|
| -gfx::ImageSkia* ThemeService::GetImageSkiaNamed(int id, bool incognito) const {
|
| - gfx::Image image = GetImageNamed(id, incognito);
|
| - if (image.IsEmpty())
|
| - return nullptr;
|
| - // TODO(pkotwicz): Remove this const cast. The gfx::Image interface returns
|
| - // its images const. GetImageSkiaNamed() also should but has many callsites.
|
| - return const_cast<gfx::ImageSkia*>(image.ToImageSkia());
|
| -}
|
| -
|
| -SkColor ThemeService::GetColor(int id, bool incognito) const {
|
| - DCHECK(CalledOnValidThread());
|
| -
|
| - // For legacy reasons, |theme_supplier_| requires the incognito variants
|
| - // of color IDs.
|
| - int theme_supplier_id = id;
|
| - if (incognito) {
|
| - if (id == ThemeProperties::COLOR_FRAME)
|
| - theme_supplier_id = ThemeProperties::COLOR_FRAME_INCOGNITO;
|
| - else if (id == ThemeProperties::COLOR_FRAME_INACTIVE)
|
| - theme_supplier_id = ThemeProperties::COLOR_FRAME_INCOGNITO_INACTIVE;
|
| - }
|
| -
|
| - SkColor color;
|
| - if (theme_supplier_ && theme_supplier_->GetColor(theme_supplier_id, &color))
|
| - return color;
|
| -
|
| - return GetDefaultColor(id, incognito);
|
| -}
|
| -
|
| int ThemeService::GetDisplayProperty(int id) const {
|
| int result = 0;
|
| if (theme_supplier_ && theme_supplier_->GetDisplayProperty(id, &result)) {
|
| @@ -660,6 +651,21 @@
|
| default:
|
| return -1;
|
| }
|
| +}
|
| +
|
| +bool ThemeService::ShouldUseNativeFrame() const {
|
| + if (HasCustomImage(IDR_THEME_FRAME))
|
| + return false;
|
| +#if defined(OS_WIN)
|
| + return ui::win::IsAeroGlassEnabled();
|
| +#else
|
| + return false;
|
| +#endif
|
| +}
|
| +
|
| +bool ThemeService::HasCustomImage(int id) const {
|
| + return BrowserThemePack::IsPersistentImageID(id) && theme_supplier_ &&
|
| + theme_supplier_->HasCustomImage(id);
|
| }
|
|
|
| base::RefCountedMemory* ThemeService::GetRawData(
|
|
|