Commit 7ce1599f authored by pkotwicz@chromium.org's avatar pkotwicz@chromium.org

This CL makes managed users use the normal Google logo on the --enable-instant-extended-api NTP.

I also changed the signature of ui::ThemeProvider::GetDisplayProperty() because most of the callers were ignoring the return value. In some cases we were using uninitialized variables because of this.

BUG=279978
TEST=Manual, see bug
R=erg
TBR=sky (For trivial refactor)

Review URL: https://chromiumcodereview.appspot.com/23614007

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@220537 0039d316-1c4b-4281-b951-d872f2087c98
parent a267567f
...@@ -332,21 +332,17 @@ void InstantService::OnThemeChanged(ThemeService* theme_service) { ...@@ -332,21 +332,17 @@ void InstantService::OnThemeChanged(ThemeService* theme_service) {
theme_info_->header_color = SkColorToRGBAColor(header_color); theme_info_->header_color = SkColorToRGBAColor(header_color);
theme_info_->section_border_color = SkColorToRGBAColor(section_border_color); theme_info_->section_border_color = SkColorToRGBAColor(section_border_color);
// Set logo for the theme. By default, use alternate logo. int logo_alternate = theme_service->GetDisplayProperty(
theme_info_->logo_alternate = true; ThemeProperties::NTP_LOGO_ALTERNATE);
int logo_alternate = 0; theme_info_->logo_alternate = logo_alternate == 1;
if (theme_service->GetDisplayProperty(
ThemeProperties::NTP_LOGO_ALTERNATE, &logo_alternate))
theme_info_->logo_alternate = logo_alternate == 1;
if (theme_service->HasCustomImage(IDR_THEME_NTP_BACKGROUND)) { if (theme_service->HasCustomImage(IDR_THEME_NTP_BACKGROUND)) {
// Set theme id for theme background image url. // Set theme id for theme background image url.
theme_info_->theme_id = theme_service->GetThemeID(); theme_info_->theme_id = theme_service->GetThemeID();
// Set theme background image horizontal alignment. // Set theme background image horizontal alignment.
int alignment = 0; int alignment = theme_service->GetDisplayProperty(
theme_service->GetDisplayProperty( ThemeProperties::NTP_BACKGROUND_ALIGNMENT);
ThemeProperties::NTP_BACKGROUND_ALIGNMENT, &alignment);
if (alignment & ThemeProperties::ALIGN_LEFT) if (alignment & ThemeProperties::ALIGN_LEFT)
theme_info_->image_horizontal_alignment = THEME_BKGRND_IMAGE_ALIGN_LEFT; theme_info_->image_horizontal_alignment = THEME_BKGRND_IMAGE_ALIGN_LEFT;
else if (alignment & ThemeProperties::ALIGN_RIGHT) else if (alignment & ThemeProperties::ALIGN_RIGHT)
...@@ -363,9 +359,8 @@ void InstantService::OnThemeChanged(ThemeService* theme_service) { ...@@ -363,9 +359,8 @@ void InstantService::OnThemeChanged(ThemeService* theme_service) {
theme_info_->image_vertical_alignment = THEME_BKGRND_IMAGE_ALIGN_CENTER; theme_info_->image_vertical_alignment = THEME_BKGRND_IMAGE_ALIGN_CENTER;
// Set theme backgorund image tiling. // Set theme backgorund image tiling.
int tiling = 0; int tiling = theme_service->GetDisplayProperty(
theme_service->GetDisplayProperty(ThemeProperties::NTP_BACKGROUND_TILING, ThemeProperties::NTP_BACKGROUND_TILING);
&tiling);
switch (tiling) { switch (tiling) {
case ThemeProperties::NO_REPEAT: case ThemeProperties::NO_REPEAT:
theme_info_->image_tiling = THEME_BKGRND_IMAGE_NO_REPEAT; theme_info_->image_tiling = THEME_BKGRND_IMAGE_NO_REPEAT;
......
...@@ -71,10 +71,11 @@ const color_utils::HSL kDefaultTintBackgroundTab = { -1, 0.5, 0.75 }; ...@@ -71,10 +71,11 @@ const color_utils::HSL kDefaultTintBackgroundTab = { -1, 0.5, 0.75 };
// Default display properties. // Default display properties.
const int kDefaultDisplayPropertyNTPAlignment = const int kDefaultDisplayPropertyNTPAlignment =
ThemeProperties::ALIGN_BOTTOM; ThemeProperties::ALIGN_CENTER;
const int kDefaultDisplayPropertyNTPTiling = const int kDefaultDisplayPropertyNTPTiling =
ThemeProperties::NO_REPEAT; ThemeProperties::NO_REPEAT;
const int kDefaultDisplayPropertyNTPInverseLogo = 0; // By default, we do not use the ntp alternate logo.
const int kDefaultDisplayPropertyNTPAlternateLogo = 0;
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// Defaults for properties which are not stored in the browser theme pack. // Defaults for properties which are not stored in the browser theme pack.
...@@ -302,18 +303,15 @@ SkColor ThemeProperties::GetDefaultColor(int id) { ...@@ -302,18 +303,15 @@ SkColor ThemeProperties::GetDefaultColor(int id) {
} }
// static // static
bool ThemeProperties::GetDefaultDisplayProperty(int id, int* result) { int ThemeProperties::GetDefaultDisplayProperty(int id) {
switch (id) { switch (id) {
case NTP_BACKGROUND_ALIGNMENT: case NTP_BACKGROUND_ALIGNMENT:
*result = kDefaultDisplayPropertyNTPAlignment; return kDefaultDisplayPropertyNTPAlignment;
return true;
case NTP_BACKGROUND_TILING: case NTP_BACKGROUND_TILING:
*result = kDefaultDisplayPropertyNTPTiling; return kDefaultDisplayPropertyNTPTiling;
return true;
case NTP_LOGO_ALTERNATE: case NTP_LOGO_ALTERNATE:
*result = kDefaultDisplayPropertyNTPInverseLogo; return kDefaultDisplayPropertyNTPAlternateLogo;
return true;
} }
return false; return -1;
} }
...@@ -140,9 +140,9 @@ class ThemeProperties { ...@@ -140,9 +140,9 @@ class ThemeProperties {
// Returns SK_ColorRED if |id| is invalid. // Returns SK_ColorRED if |id| is invalid.
static SkColor GetDefaultColor(int id); static SkColor GetDefaultColor(int id);
// Returns true and sets |result| to the requested default property, if |id| // Returns the default value for the given property |id|. Returns -1 if |id|
// is valid. // is invalid.
static bool GetDefaultDisplayProperty(int id, int* result); static int GetDefaultDisplayProperty(int id);
private: private:
DISALLOW_IMPLICIT_CONSTRUCTORS(ThemeProperties); DISALLOW_IMPLICIT_CONSTRUCTORS(ThemeProperties);
......
...@@ -169,11 +169,22 @@ SkColor ThemeService::GetColor(int id) const { ...@@ -169,11 +169,22 @@ SkColor ThemeService::GetColor(int id) const {
return Properties::GetDefaultColor(id); return Properties::GetDefaultColor(id);
} }
bool ThemeService::GetDisplayProperty(int id, int* result) const { int ThemeService::GetDisplayProperty(int id) const {
if (theme_supplier_.get()) int result = 0;
return theme_supplier_->GetDisplayProperty(id, result); if (theme_supplier_.get() &&
theme_supplier_->GetDisplayProperty(id, &result)) {
return result;
}
if (id == Properties::NTP_LOGO_ALTERNATE &&
!UsingDefaultTheme() &&
!UsingNativeTheme()) {
// Use the alternate logo for themes from the web store except for
// |kDefaultThemeGalleryID|.
return 1;
}
return Properties::GetDefaultDisplayProperty(id, result); return Properties::GetDefaultDisplayProperty(id);
} }
bool ThemeService::ShouldUseNativeFrame() const { bool ThemeService::ShouldUseNativeFrame() const {
...@@ -200,8 +211,7 @@ base::RefCountedMemory* ThemeService::GetRawData( ...@@ -200,8 +211,7 @@ base::RefCountedMemory* ThemeService::GetRawData(
int id, int id,
ui::ScaleFactor scale_factor) const { ui::ScaleFactor scale_factor) const {
// Check to see whether we should substitute some images. // Check to see whether we should substitute some images.
int ntp_alternate; int ntp_alternate = GetDisplayProperty(Properties::NTP_LOGO_ALTERNATE);
GetDisplayProperty(Properties::NTP_LOGO_ALTERNATE, &ntp_alternate);
if (id == IDR_PRODUCT_LOGO && ntp_alternate != 0) if (id == IDR_PRODUCT_LOGO && ntp_alternate != 0)
id = IDR_PRODUCT_LOGO_WHITE; id = IDR_PRODUCT_LOGO_WHITE;
...@@ -364,7 +374,7 @@ void ThemeService::SetNativeTheme() { ...@@ -364,7 +374,7 @@ void ThemeService::SetNativeTheme() {
bool ThemeService::UsingDefaultTheme() const { bool ThemeService::UsingDefaultTheme() const {
std::string id = GetThemeID(); std::string id = GetThemeID();
return id == ThemeService::kDefaultThemeID || return id == ThemeService::kDefaultThemeID ||
(id == kDefaultThemeGalleryID && !IsManagedUser()); id == kDefaultThemeGalleryID;
} }
bool ThemeService::UsingNativeTheme() const { bool ThemeService::UsingNativeTheme() const {
......
...@@ -78,7 +78,7 @@ class ThemeService : public base::NonThreadSafe, ...@@ -78,7 +78,7 @@ class ThemeService : public base::NonThreadSafe,
// Overridden from ui::ThemeProvider: // Overridden from ui::ThemeProvider:
virtual gfx::ImageSkia* GetImageSkiaNamed(int id) const OVERRIDE; virtual gfx::ImageSkia* GetImageSkiaNamed(int id) const OVERRIDE;
virtual SkColor GetColor(int id) const OVERRIDE; virtual SkColor GetColor(int id) const OVERRIDE;
virtual bool GetDisplayProperty(int id, int* result) const OVERRIDE; virtual int GetDisplayProperty(int id) const OVERRIDE;
virtual bool ShouldUseNativeFrame() const OVERRIDE; virtual bool ShouldUseNativeFrame() const OVERRIDE;
virtual bool HasCustomImage(int id) const OVERRIDE; virtual bool HasCustomImage(int id) const OVERRIDE;
virtual base::RefCountedMemory* GetRawData( virtual base::RefCountedMemory* GetRawData(
......
...@@ -210,8 +210,8 @@ class FakeTheme : public ui::ThemeProvider { ...@@ -210,8 +210,8 @@ class FakeTheme : public ui::ThemeProvider {
return NULL; return NULL;
} }
virtual SkColor GetColor(int id) const OVERRIDE { return SkColor(); } virtual SkColor GetColor(int id) const OVERRIDE { return SkColor(); }
virtual bool GetDisplayProperty(int id, int* result) const OVERRIDE { virtual int GetDisplayProperty(int id) const OVERRIDE {
return false; return -1;
} }
virtual bool ShouldUseNativeFrame() const OVERRIDE { return false; } virtual bool ShouldUseNativeFrame() const OVERRIDE { return false; }
virtual bool HasCustomImage(int id) const OVERRIDE { return false; } virtual bool HasCustomImage(int id) const OVERRIDE { return false; }
......
...@@ -18,7 +18,7 @@ class BackgroundTheme : public ui::ThemeProvider { ...@@ -18,7 +18,7 @@ class BackgroundTheme : public ui::ThemeProvider {
// Overridden from ui::ThemeProvider: // Overridden from ui::ThemeProvider:
virtual gfx::ImageSkia* GetImageSkiaNamed(int id) const OVERRIDE; virtual gfx::ImageSkia* GetImageSkiaNamed(int id) const OVERRIDE;
virtual SkColor GetColor(int id) const OVERRIDE; virtual SkColor GetColor(int id) const OVERRIDE;
virtual bool GetDisplayProperty(int id, int* result) const OVERRIDE; virtual int GetDisplayProperty(int id) const OVERRIDE;
virtual bool ShouldUseNativeFrame() const OVERRIDE; virtual bool ShouldUseNativeFrame() const OVERRIDE;
virtual bool HasCustomImage(int id) const OVERRIDE; virtual bool HasCustomImage(int id) const OVERRIDE;
virtual base::RefCountedMemory* GetRawData( virtual base::RefCountedMemory* GetRawData(
......
...@@ -35,8 +35,8 @@ SkColor BackgroundTheme::GetColor(int id) const { ...@@ -35,8 +35,8 @@ SkColor BackgroundTheme::GetColor(int id) const {
return SkColor(); return SkColor();
} }
bool BackgroundTheme::GetDisplayProperty(int id, int* result) const { int BackgroundTheme::GetDisplayProperty(int id) const {
return false; return -1;
} }
bool BackgroundTheme::ShouldUseNativeFrame() const { bool BackgroundTheme::ShouldUseNativeFrame() const {
......
...@@ -74,16 +74,13 @@ void NtpBackgroundUtil::PaintBackgroundDetachedMode(ui::ThemeProvider* tp, ...@@ -74,16 +74,13 @@ void NtpBackgroundUtil::PaintBackgroundDetachedMode(ui::ThemeProvider* tp,
canvas->FillRect(area, tp->GetColor(ThemeProperties::COLOR_NTP_BACKGROUND)); canvas->FillRect(area, tp->GetColor(ThemeProperties::COLOR_NTP_BACKGROUND));
if (tp->HasCustomImage(IDR_THEME_NTP_BACKGROUND)) { if (tp->HasCustomImage(IDR_THEME_NTP_BACKGROUND)) {
int tiling = ThemeProperties::NO_REPEAT; int tiling = tp->GetDisplayProperty(ThemeProperties::NTP_BACKGROUND_TILING);
tp->GetDisplayProperty(ThemeProperties::NTP_BACKGROUND_TILING, &tiling); int alignment = tp->GetDisplayProperty(
int alignment; ThemeProperties::NTP_BACKGROUND_ALIGNMENT);
if (tp->GetDisplayProperty(ThemeProperties::NTP_BACKGROUND_ALIGNMENT, gfx::ImageSkia* ntp_background =
&alignment)) { tp->GetImageSkiaNamed(IDR_THEME_NTP_BACKGROUND);
gfx::ImageSkia* ntp_background =
tp->GetImageSkiaNamed(IDR_THEME_NTP_BACKGROUND);
PaintThemeBackground( PaintThemeBackground(
canvas, ntp_background, tiling, alignment, area, tab_contents_height); canvas, ntp_background, tiling, alignment, area, tab_contents_height);
}
} }
} }
...@@ -45,8 +45,8 @@ class DesktopThemeProvider : public ui::ThemeProvider { ...@@ -45,8 +45,8 @@ class DesktopThemeProvider : public ui::ThemeProvider {
virtual SkColor GetColor(int id) const OVERRIDE { virtual SkColor GetColor(int id) const OVERRIDE {
return delegate_->GetColor(id); return delegate_->GetColor(id);
} }
virtual bool GetDisplayProperty(int id, int* result) const OVERRIDE { virtual int GetDisplayProperty(int id) const OVERRIDE {
return delegate_->GetDisplayProperty(id, result); return delegate_->GetDisplayProperty(id);
} }
virtual bool ShouldUseNativeFrame() const OVERRIDE { virtual bool ShouldUseNativeFrame() const OVERRIDE {
return delegate_->ShouldUseNativeFrame(); return delegate_->ShouldUseNativeFrame();
......
...@@ -127,10 +127,6 @@ SkColor GetThemeColor(ui::ThemeProvider* tp, int id) { ...@@ -127,10 +127,6 @@ SkColor GetThemeColor(ui::ThemeProvider* tp, int id) {
// states when the bar is attached or detached. // states when the bar is attached or detached.
std::string GetNewTabBackgroundCSS(const ui::ThemeProvider* theme_provider, std::string GetNewTabBackgroundCSS(const ui::ThemeProvider* theme_provider,
bool bar_attached) { bool bar_attached) {
int alignment;
theme_provider->GetDisplayProperty(
ThemeProperties::NTP_BACKGROUND_ALIGNMENT, &alignment);
// TODO(glen): This is a quick workaround to hide the notused.png image when // TODO(glen): This is a quick workaround to hide the notused.png image when
// no image is provided - we don't have time right now to figure out why // no image is provided - we don't have time right now to figure out why
// this is painting as white. // this is painting as white.
...@@ -139,6 +135,9 @@ std::string GetNewTabBackgroundCSS(const ui::ThemeProvider* theme_provider, ...@@ -139,6 +135,9 @@ std::string GetNewTabBackgroundCSS(const ui::ThemeProvider* theme_provider,
return "-64px"; return "-64px";
} }
int alignment = theme_provider->GetDisplayProperty(
ThemeProperties::NTP_BACKGROUND_ALIGNMENT);
if (bar_attached) if (bar_attached)
return ThemeProperties::AlignmentToString(alignment); return ThemeProperties::AlignmentToString(alignment);
...@@ -161,9 +160,8 @@ std::string GetNewTabBackgroundCSS(const ui::ThemeProvider* theme_provider, ...@@ -161,9 +160,8 @@ std::string GetNewTabBackgroundCSS(const ui::ThemeProvider* theme_provider,
// masks in theme_service.h). // masks in theme_service.h).
std::string GetNewTabBackgroundTilingCSS( std::string GetNewTabBackgroundTilingCSS(
const ui::ThemeProvider* theme_provider) { const ui::ThemeProvider* theme_provider) {
int repeat_mode; int repeat_mode = theme_provider->GetDisplayProperty(
theme_provider->GetDisplayProperty( ThemeProperties::NTP_BACKGROUND_TILING);
ThemeProperties::NTP_BACKGROUND_TILING, &repeat_mode);
return ThemeProperties::TilingToString(repeat_mode); return ThemeProperties::TilingToString(repeat_mode);
} }
...@@ -506,10 +504,9 @@ void NTPResourceCache::CreateNewTabHTML() { ...@@ -506,10 +504,9 @@ void NTPResourceCache::CreateNewTabHTML() {
// Control fade and resize animations. // Control fade and resize animations.
load_time_data.SetBoolean("anim", ui::Animation::ShouldRenderRichAnimation()); load_time_data.SetBoolean("anim", ui::Animation::ShouldRenderRichAnimation());
int alignment;
ui::ThemeProvider* tp = ThemeServiceFactory::GetForProfile(profile_); ui::ThemeProvider* tp = ThemeServiceFactory::GetForProfile(profile_);
tp->GetDisplayProperty(ThemeProperties::NTP_BACKGROUND_ALIGNMENT, int alignment = tp->GetDisplayProperty(
&alignment); ThemeProperties::NTP_BACKGROUND_ALIGNMENT);
load_time_data.SetString("themegravity", load_time_data.SetString("themegravity",
(alignment & ThemeProperties::ALIGN_RIGHT) ? "right" : ""); (alignment & ThemeProperties::ALIGN_RIGHT) ? "right" : "");
......
...@@ -26,8 +26,8 @@ SkColor DefaultThemeProvider::GetColor(int id) const { ...@@ -26,8 +26,8 @@ SkColor DefaultThemeProvider::GetColor(int id) const {
return 0xff0000ff; return 0xff0000ff;
} }
bool DefaultThemeProvider::GetDisplayProperty(int id, int* result) const { int DefaultThemeProvider::GetDisplayProperty(int id) const {
return false; return -1;
} }
bool DefaultThemeProvider::ShouldUseNativeFrame() const { bool DefaultThemeProvider::ShouldUseNativeFrame() const {
......
...@@ -26,7 +26,7 @@ class UI_EXPORT DefaultThemeProvider : public ThemeProvider { ...@@ -26,7 +26,7 @@ class UI_EXPORT DefaultThemeProvider : public ThemeProvider {
// Overridden from ui::ThemeProvider: // Overridden from ui::ThemeProvider:
virtual gfx::ImageSkia* GetImageSkiaNamed(int id) const OVERRIDE; virtual gfx::ImageSkia* GetImageSkiaNamed(int id) const OVERRIDE;
virtual SkColor GetColor(int id) const OVERRIDE; virtual SkColor GetColor(int id) const OVERRIDE;
virtual bool GetDisplayProperty(int id, int* result) const OVERRIDE; virtual int GetDisplayProperty(int id) const OVERRIDE;
virtual bool ShouldUseNativeFrame() const OVERRIDE; virtual bool ShouldUseNativeFrame() const OVERRIDE;
virtual bool HasCustomImage(int id) const OVERRIDE; virtual bool HasCustomImage(int id) const OVERRIDE;
virtual base::RefCountedMemory* GetRawData( virtual base::RefCountedMemory* GetRawData(
......
...@@ -59,7 +59,7 @@ class UI_EXPORT ThemeProvider { ...@@ -59,7 +59,7 @@ class UI_EXPORT ThemeProvider {
// Get the property (e.g. an alignment expressed in an enum, or a width or // Get the property (e.g. an alignment expressed in an enum, or a width or
// height) specified by |id|. // height) specified by |id|.
virtual bool GetDisplayProperty(int id, int* result) const = 0; virtual int GetDisplayProperty(int id) const = 0;
// Whether we should use the native system frame (typically Aero glass) or // Whether we should use the native system frame (typically Aero glass) or
// a custom frame. // a custom frame.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment