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 "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/memory/ref_counted_memory.h" | 8 #include "base/memory/ref_counted_memory.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 case Properties::COLOR_MANAGED_USER_LABEL_BORDER: | 162 case Properties::COLOR_MANAGED_USER_LABEL_BORDER: |
163 return color_utils::AlphaBlend( | 163 return color_utils::AlphaBlend( |
164 GetColor(Properties::COLOR_MANAGED_USER_LABEL_BACKGROUND), | 164 GetColor(Properties::COLOR_MANAGED_USER_LABEL_BACKGROUND), |
165 SK_ColorBLACK, | 165 SK_ColorBLACK, |
166 230); | 166 230); |
167 } | 167 } |
168 | 168 |
169 return Properties::GetDefaultColor(id); | 169 return Properties::GetDefaultColor(id); |
170 } | 170 } |
171 | 171 |
172 bool ThemeService::GetDisplayProperty(int id, int* result) const { | 172 int ThemeService::GetDisplayProperty(int id) const { |
173 if (theme_supplier_.get()) | 173 int result = 0; |
174 return theme_supplier_->GetDisplayProperty(id, result); | 174 if (theme_supplier_.get() && |
| 175 theme_supplier_->GetDisplayProperty(id, &result)) { |
| 176 return result; |
| 177 } |
175 | 178 |
176 return Properties::GetDefaultDisplayProperty(id, result); | 179 if (id == Properties::NTP_LOGO_ALTERNATE && |
| 180 !UsingDefaultTheme() && |
| 181 !UsingNativeTheme()) { |
| 182 // Use the alternate logo for themes from the web store except for |
| 183 // |kDefaultThemeGalleryID|. |
| 184 return 1; |
| 185 } |
| 186 |
| 187 return Properties::GetDefaultDisplayProperty(id); |
177 } | 188 } |
178 | 189 |
179 bool ThemeService::ShouldUseNativeFrame() const { | 190 bool ThemeService::ShouldUseNativeFrame() const { |
180 if (HasCustomImage(IDR_THEME_FRAME)) | 191 if (HasCustomImage(IDR_THEME_FRAME)) |
181 return false; | 192 return false; |
182 #if defined(OS_WIN) | 193 #if defined(OS_WIN) |
183 return ui::win::IsAeroGlassEnabled(); | 194 return ui::win::IsAeroGlassEnabled(); |
184 #else | 195 #else |
185 return false; | 196 return false; |
186 #endif | 197 #endif |
187 } | 198 } |
188 | 199 |
189 bool ThemeService::HasCustomImage(int id) const { | 200 bool ThemeService::HasCustomImage(int id) const { |
190 if (!Properties::IsThemeableImage(id)) | 201 if (!Properties::IsThemeableImage(id)) |
191 return false; | 202 return false; |
192 | 203 |
193 if (theme_supplier_.get()) | 204 if (theme_supplier_.get()) |
194 return theme_supplier_->HasCustomImage(id); | 205 return theme_supplier_->HasCustomImage(id); |
195 | 206 |
196 return false; | 207 return false; |
197 } | 208 } |
198 | 209 |
199 base::RefCountedMemory* ThemeService::GetRawData( | 210 base::RefCountedMemory* ThemeService::GetRawData( |
200 int id, | 211 int id, |
201 ui::ScaleFactor scale_factor) const { | 212 ui::ScaleFactor scale_factor) const { |
202 // Check to see whether we should substitute some images. | 213 // Check to see whether we should substitute some images. |
203 int ntp_alternate; | 214 int ntp_alternate = GetDisplayProperty(Properties::NTP_LOGO_ALTERNATE); |
204 GetDisplayProperty(Properties::NTP_LOGO_ALTERNATE, &ntp_alternate); | |
205 if (id == IDR_PRODUCT_LOGO && ntp_alternate != 0) | 215 if (id == IDR_PRODUCT_LOGO && ntp_alternate != 0) |
206 id = IDR_PRODUCT_LOGO_WHITE; | 216 id = IDR_PRODUCT_LOGO_WHITE; |
207 | 217 |
208 base::RefCountedMemory* data = NULL; | 218 base::RefCountedMemory* data = NULL; |
209 if (theme_supplier_.get()) | 219 if (theme_supplier_.get()) |
210 data = theme_supplier_->GetRawData(id, scale_factor); | 220 data = theme_supplier_->GetRawData(id, scale_factor); |
211 if (!data) | 221 if (!data) |
212 data = rb_.LoadDataResourceBytesForScale(id, ui::SCALE_FACTOR_100P); | 222 data = rb_.LoadDataResourceBytesForScale(id, ui::SCALE_FACTOR_100P); |
213 | 223 |
214 return data; | 224 return data; |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
357 NotifyThemeChanged(); | 367 NotifyThemeChanged(); |
358 } | 368 } |
359 | 369 |
360 void ThemeService::SetNativeTheme() { | 370 void ThemeService::SetNativeTheme() { |
361 UseDefaultTheme(); | 371 UseDefaultTheme(); |
362 } | 372 } |
363 | 373 |
364 bool ThemeService::UsingDefaultTheme() const { | 374 bool ThemeService::UsingDefaultTheme() const { |
365 std::string id = GetThemeID(); | 375 std::string id = GetThemeID(); |
366 return id == ThemeService::kDefaultThemeID || | 376 return id == ThemeService::kDefaultThemeID || |
367 (id == kDefaultThemeGalleryID && !IsManagedUser()); | 377 id == kDefaultThemeGalleryID; |
368 } | 378 } |
369 | 379 |
370 bool ThemeService::UsingNativeTheme() const { | 380 bool ThemeService::UsingNativeTheme() const { |
371 return UsingDefaultTheme(); | 381 return UsingDefaultTheme(); |
372 } | 382 } |
373 | 383 |
374 std::string ThemeService::GetThemeID() const { | 384 std::string ThemeService::GetThemeID() const { |
375 return profile_->GetPrefs()->GetString(prefs::kCurrentThemeID); | 385 return profile_->GetPrefs()->GetString(prefs::kCurrentThemeID); |
376 } | 386 } |
377 | 387 |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
595 void ThemeService::OnInfobarDestroyed() { | 605 void ThemeService::OnInfobarDestroyed() { |
596 number_of_infobars_--; | 606 number_of_infobars_--; |
597 | 607 |
598 if (number_of_infobars_ == 0) | 608 if (number_of_infobars_ == 0) |
599 RemoveUnusedThemes(false); | 609 RemoveUnusedThemes(false); |
600 } | 610 } |
601 | 611 |
602 ThemeSyncableService* ThemeService::GetThemeSyncableService() const { | 612 ThemeSyncableService* ThemeService::GetThemeSyncableService() const { |
603 return theme_syncable_service_.get(); | 613 return theme_syncable_service_.get(); |
604 } | 614 } |
OLD | NEW |