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

Unified Diff: chrome/browser/themes/theme_service.cc

Issue 19471005: Add custom default theme support and create a managed user default theme. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix bugs. Created 7 years, 5 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/themes/theme_service.cc
diff --git a/chrome/browser/themes/theme_service.cc b/chrome/browser/themes/theme_service.cc
index d7fe33bd290520c6da71f222a288f2fe1bd3adbf..0379b062f7ca93530d2536397df51028dff6c670 100644
--- a/chrome/browser/themes/theme_service.cc
+++ b/chrome/browser/themes/theme_service.cc
@@ -15,6 +15,7 @@
#include "chrome/browser/extensions/extension_system.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/themes/browser_theme_pack.h"
+#include "chrome/browser/themes/custom_theme_provider.h"
#include "chrome/browser/themes/theme_properties.h"
#include "chrome/browser/themes/theme_syncable_service.h"
#include "chrome/common/chrome_constants.h"
@@ -34,6 +35,7 @@
#if defined(ENABLE_MANAGED_USERS)
#include "chrome/browser/managed_mode/managed_user_service.h"
+#include "chrome/browser/managed_mode/managed_user_theme.h"
#endif
using content::BrowserThread;
@@ -104,20 +106,9 @@ void ThemeService::Init(Profile* profile) {
gfx::Image ThemeService::GetImageNamed(int id) const {
DCHECK(CalledOnValidThread());
- // For a managed user, use the special frame instead of the default one.
- // TODO(akuegel): Remove this once we have the default managed user theme.
- if (IsManagedUser()) {
- if (id == IDR_THEME_FRAME)
- id = IDR_MANAGED_USER_THEME_FRAME;
- else if (id == IDR_THEME_FRAME_INACTIVE)
- id = IDR_MANAGED_USER_THEME_FRAME_INACTIVE;
- else if (id == IDR_THEME_TAB_BACKGROUND || id == IDR_THEME_TAB_BACKGROUND_V)
- id = IDR_MANAGED_USER_THEME_TAB_BACKGROUND;
- }
-
gfx::Image image;
- if (theme_pack_.get())
- image = theme_pack_->GetImageNamed(id);
+ if (theme_provider_.get())
+ image = theme_provider_->GetImageNamed(id);
if (image.IsEmpty())
image = rb_.GetNativeImageNamed(id);
@@ -136,17 +127,8 @@ gfx::ImageSkia* ThemeService::GetImageSkiaNamed(int id) const {
SkColor ThemeService::GetColor(int id) const {
DCHECK(CalledOnValidThread());
-
- // TODO(akuegel): Remove this once we have the default managed user theme.
- if (IsManagedUser()) {
- if (id == Properties::COLOR_FRAME)
- id = Properties::COLOR_FRAME_MANAGED_USER;
- else if (id == Properties::COLOR_FRAME_INACTIVE)
- id = Properties::COLOR_FRAME_MANAGED_USER_INACTIVE;
- }
-
SkColor color;
- if (theme_pack_.get() && theme_pack_->GetColor(id, &color))
+ if (theme_provider_.get() && theme_provider_->GetColor(id, &color))
return color;
// For backward compat with older themes, some newer colors are generated from
@@ -163,22 +145,20 @@ SkColor ThemeService::GetColor(int id) const {
case Properties::COLOR_NTP_TEXT_LIGHT:
return IncreaseLightness(GetColor(Properties::COLOR_NTP_TEXT), 0.40);
case Properties::COLOR_MANAGED_USER_LABEL:
- // TODO(akuegel): Use GetReadableColor() once we want to support other
- // themes as well.
- return SkColorSetRGB(231, 245, 255);
+ return color_utils::GetReadableColor(
+ SK_ColorWHITE,
+ GetColor(Properties::COLOR_MANAGED_USER_LABEL_BACKGROUND));
case Properties::COLOR_MANAGED_USER_LABEL_BACKGROUND:
- // TODO(akuegel): Replace this constant by a color calculated from the
- // frame color once the default managed user theme is finished and we
- // allow managed users to install other themes.
- return SkColorSetRGB(108, 167, 210);
+ return color_utils::BlendTowardOppositeLuminance(
+ GetColor(Properties::COLOR_FRAME), 0x80);
}
return Properties::GetDefaultColor(id);
}
bool ThemeService::GetDisplayProperty(int id, int* result) const {
- if (theme_pack_.get())
- return theme_pack_->GetDisplayProperty(id, result);
+ if (theme_provider_.get())
+ return theme_provider_->GetDisplayProperty(id, result);
return Properties::GetDefaultDisplayProperty(id, result);
}
@@ -197,13 +177,8 @@ bool ThemeService::HasCustomImage(int id) const {
if (!Properties::IsThemeableImage(id))
return false;
- if (theme_pack_.get())
- return theme_pack_->HasCustomImage(id);
-
- if (IsManagedUser() &&
- (id == IDR_THEME_FRAME || id == IDR_THEME_FRAME_INACTIVE ||
- id == IDR_THEME_TAB_BACKGROUND || id == IDR_THEME_TAB_BACKGROUND_V))
- return true;
+ if (theme_provider_.get())
+ return theme_provider_->HasCustomImage(id);
return false;
}
@@ -218,8 +193,8 @@ base::RefCountedMemory* ThemeService::GetRawData(
id = IDR_PRODUCT_LOGO_WHITE;
base::RefCountedMemory* data = NULL;
- if (theme_pack_.get())
- data = theme_pack_->GetRawData(id, scale_factor);
+ if (theme_provider_.get())
+ data = theme_provider_->GetRawData(id, scale_factor);
if (!data)
data = rb_.LoadDataResourceBytesForScale(id, ui::SCALE_FACTOR_100P);
@@ -261,6 +236,18 @@ void ThemeService::SetTheme(const Extension* extension) {
content::RecordAction(UserMetricsAction("Themes_Installed"));
}
+void ThemeService::SetCustomDefaultTheme(
+ scoped_refptr<CustomThemeProvider> theme_provider) {
+ SaveThemeID(kDefaultThemeID);
pkotwicz 2013/07/19 05:54:13 The call to SaveThemeID(kDefaultThemeID) is done f
Adrian Kuegel 2013/07/19 13:54:39 Right. I removed those lines.
+ ClearAllThemeData();
+ if (theme_provider_.get())
+ theme_provider_->StopUsingTheme();
+ theme_provider_ = theme_provider;
+ if (theme_provider_.get())
+ theme_provider_->StartUsingTheme();
+ NotifyThemeChanged();
+}
+
void ThemeService::RemoveUnusedThemes() {
if (!profile_)
return;
@@ -281,9 +268,13 @@ void ThemeService::RemoveUnusedThemes() {
}
void ThemeService::UseDefaultTheme() {
+ content::RecordAction(UserMetricsAction("Themes_Reset"));
+ if (IsManagedUser()) {
+ SetCustomDefaultTheme(new ManagedUserTheme());
+ return;
+ }
ClearAllThemeData();
NotifyThemeChanged();
- content::RecordAction(UserMetricsAction("Themes_Reset"));
}
void ThemeService::SetNativeTheme() {
@@ -308,16 +299,18 @@ color_utils::HSL ThemeService::GetTint(int id) const {
DCHECK(CalledOnValidThread());
color_utils::HSL hsl;
- if (theme_pack_.get() && theme_pack_->GetTint(id, &hsl))
+ if (theme_provider_.get() && theme_provider_->GetTint(id, &hsl))
return hsl;
return ThemeProperties::GetDefaultTint(id);
}
void ThemeService::ClearAllThemeData() {
+ if (theme_provider_.get())
+ theme_provider_->StopUsingTheme();
// Clear our image cache.
FreePlatformCaches();
- theme_pack_ = NULL;
+ theme_provider_ = NULL;
profile_->GetPrefs()->ClearPref(prefs::kCurrentThemePackFilename);
SaveThemeID(kDefaultThemeID);
@@ -339,8 +332,13 @@ void ThemeService::LoadThemePrefs() {
// If we don't have a file pack, we're updating from an old version.
base::FilePath path = prefs->GetFilePath(prefs::kCurrentThemePackFilename);
if (path != base::FilePath()) {
- theme_pack_ = BrowserThemePack::BuildFromDataPack(path, current_id);
- loaded_pack = theme_pack_.get() != NULL;
+ if (theme_provider_.get())
+ theme_provider_->StopUsingTheme();
+ theme_provider_ = BrowserThemePack::BuildFromDataPack(path, current_id);
+ if (theme_provider_.get()) {
+ theme_provider_->StartUsingTheme();
+ loaded_pack = true;
+ }
}
if (loaded_pack) {
@@ -430,7 +428,10 @@ void ThemeService::BuildFromExtension(const Extension* extension) {
base::Bind(&WritePackToDiskCallback, pack, pack_path));
SavePackName(pack_path);
- theme_pack_ = pack;
+ if (theme_provider_.get())
pkotwicz 2013/07/19 05:54:13 Optional: It may be worth putting this code in its
Adrian Kuegel 2013/07/19 13:54:39 Done.
+ theme_provider_->StopUsingTheme();
+ theme_provider_ = pack;
+ theme_provider_->StartUsingTheme();
}
bool ThemeService::IsManagedUser() const {

Powered by Google App Engine
This is Rietveld 408576698