| 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 <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/location.h" | 10 #include "base/location.h" |
| 11 #include "base/memory/ref_counted_memory.h" | 11 #include "base/memory/ref_counted_memory.h" |
| 12 #include "base/prefs/pref_service.h" | 12 #include "base/prefs/pref_service.h" |
| 13 #include "base/sequenced_task_runner.h" | 13 #include "base/sequenced_task_runner.h" |
| 14 #include "base/single_thread_task_runner.h" | 14 #include "base/single_thread_task_runner.h" |
| 15 #include "base/strings/string_util.h" | 15 #include "base/strings/string_util.h" |
| 16 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
| 17 #include "base/thread_task_runner_handle.h" | 17 #include "base/thread_task_runner_handle.h" |
| 18 #include "chrome/browser/chrome_notification_types.h" | 18 #include "chrome/browser/chrome_notification_types.h" |
| 19 #include "chrome/browser/extensions/extension_service.h" | 19 #include "chrome/browser/extensions/extension_service.h" |
| 20 #include "chrome/browser/profiles/profile.h" | 20 #include "chrome/browser/profiles/profile.h" |
| 21 #include "chrome/browser/themes/browser_theme_pack.h" | 21 #include "chrome/browser/themes/browser_theme_pack.h" |
| 22 #include "chrome/browser/themes/custom_theme_supplier.h" | 22 #include "chrome/browser/themes/custom_theme_supplier.h" |
| 23 #include "chrome/browser/themes/theme_properties.h" | 23 #include "chrome/browser/themes/theme_properties.h" |
| 24 #include "chrome/browser/themes/theme_service_factory.h" |
| 24 #include "chrome/browser/themes/theme_syncable_service.h" | 25 #include "chrome/browser/themes/theme_syncable_service.h" |
| 25 #include "chrome/common/chrome_constants.h" | 26 #include "chrome/common/chrome_constants.h" |
| 26 #include "chrome/common/pref_names.h" | 27 #include "chrome/common/pref_names.h" |
| 27 #include "content/public/browser/notification_service.h" | 28 #include "content/public/browser/notification_service.h" |
| 28 #include "content/public/browser/user_metrics.h" | 29 #include "content/public/browser/user_metrics.h" |
| 29 #include "extensions/browser/extension_prefs.h" | 30 #include "extensions/browser/extension_prefs.h" |
| 30 #include "extensions/browser/extension_registry.h" | 31 #include "extensions/browser/extension_registry.h" |
| 31 #include "extensions/browser/extension_system.h" | 32 #include "extensions/browser/extension_system.h" |
| 32 #include "extensions/browser/uninstall_reason.h" | 33 #include "extensions/browser/uninstall_reason.h" |
| 33 #include "extensions/common/extension.h" | 34 #include "extensions/common/extension.h" |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 ThemeService* theme_service_; | 158 ThemeService* theme_service_; |
| 158 }; | 159 }; |
| 159 #endif // defined(ENABLE_EXTENSIONS) | 160 #endif // defined(ENABLE_EXTENSIONS) |
| 160 | 161 |
| 161 ThemeService::ThemeService() | 162 ThemeService::ThemeService() |
| 162 : ready_(false), | 163 : ready_(false), |
| 163 rb_(ResourceBundle::GetSharedInstance()), | 164 rb_(ResourceBundle::GetSharedInstance()), |
| 164 profile_(nullptr), | 165 profile_(nullptr), |
| 165 installed_pending_load_id_(kDefaultThemeID), | 166 installed_pending_load_id_(kDefaultThemeID), |
| 166 number_of_infobars_(0), | 167 number_of_infobars_(0), |
| 167 weak_ptr_factory_(this) { | 168 original_theme_provider_(*this, false), |
| 168 } | 169 otr_theme_provider_(*this, true), |
| 170 weak_ptr_factory_(this) {} |
| 169 | 171 |
| 170 ThemeService::~ThemeService() { | 172 ThemeService::~ThemeService() { |
| 171 FreePlatformCaches(); | 173 FreePlatformCaches(); |
| 172 } | 174 } |
| 173 | 175 |
| 174 void ThemeService::Init(Profile* profile) { | 176 void ThemeService::Init(Profile* profile) { |
| 175 DCHECK(CalledOnValidThread()); | 177 DCHECK(CalledOnValidThread()); |
| 176 profile_ = profile; | 178 profile_ = profile; |
| 177 | 179 |
| 178 LoadThemePrefs(); | 180 LoadThemePrefs(); |
| 179 | 181 |
| 180 registrar_.Add(this, | 182 registrar_.Add(this, |
| 181 extensions::NOTIFICATION_EXTENSIONS_READY_DEPRECATED, | 183 extensions::NOTIFICATION_EXTENSIONS_READY_DEPRECATED, |
| 182 content::Source<Profile>(profile_)); | 184 content::Source<Profile>(profile_)); |
| 183 | 185 |
| 184 theme_syncable_service_.reset(new ThemeSyncableService(profile_, this)); | 186 theme_syncable_service_.reset(new ThemeSyncableService(profile_, this)); |
| 185 } | 187 } |
| 186 | 188 |
| 187 gfx::Image ThemeService::GetImageNamed(int id) const { | |
| 188 DCHECK(CalledOnValidThread()); | |
| 189 | |
| 190 gfx::Image image; | |
| 191 if (theme_supplier_.get()) | |
| 192 image = theme_supplier_->GetImageNamed(id); | |
| 193 | |
| 194 if (image.IsEmpty()) | |
| 195 image = rb_.GetNativeImageNamed(id); | |
| 196 | |
| 197 return image; | |
| 198 } | |
| 199 | |
| 200 bool ThemeService::IsSystemThemeDistinctFromDefaultTheme() const { | 189 bool ThemeService::IsSystemThemeDistinctFromDefaultTheme() const { |
| 201 return false; | 190 return false; |
| 202 } | 191 } |
| 203 | 192 |
| 204 bool ThemeService::UsingSystemTheme() const { | |
| 205 return UsingDefaultTheme(); | |
| 206 } | |
| 207 | |
| 208 gfx::ImageSkia* ThemeService::GetImageSkiaNamed(int id) const { | |
| 209 gfx::Image image = GetImageNamed(id); | |
| 210 if (image.IsEmpty()) | |
| 211 return nullptr; | |
| 212 // TODO(pkotwicz): Remove this const cast. The gfx::Image interface returns | |
| 213 // its images const. GetImageSkiaNamed() also should but has many callsites. | |
| 214 return const_cast<gfx::ImageSkia*>(image.ToImageSkia()); | |
| 215 } | |
| 216 | |
| 217 SkColor ThemeService::GetColor(int id) const { | |
| 218 DCHECK(CalledOnValidThread()); | |
| 219 SkColor color; | |
| 220 if (theme_supplier_.get() && theme_supplier_->GetColor(id, &color)) | |
| 221 return color; | |
| 222 | |
| 223 // For backward compat with older themes, some newer colors are generated from | |
| 224 // older ones if they are missing. | |
| 225 switch (id) { | |
| 226 case Properties::COLOR_TOOLBAR_BUTTON_ICON: | |
| 227 return color_utils::HSLShift(gfx::kChromeIconGrey, | |
| 228 GetTint(Properties::TINT_BUTTONS)); | |
| 229 case Properties::COLOR_TOOLBAR_BUTTON_ICON_INACTIVE: | |
| 230 // The active color is overridden in Gtk2UI. | |
| 231 return SkColorSetA(GetColor(Properties::COLOR_TOOLBAR_BUTTON_ICON), 0x33); | |
| 232 case Properties::COLOR_NTP_SECTION_HEADER_TEXT: | |
| 233 return IncreaseLightness(GetColor(Properties::COLOR_NTP_TEXT), 0.30); | |
| 234 case Properties::COLOR_NTP_SECTION_HEADER_TEXT_HOVER: | |
| 235 return GetColor(Properties::COLOR_NTP_TEXT); | |
| 236 case Properties::COLOR_NTP_SECTION_HEADER_RULE: | |
| 237 return IncreaseLightness(GetColor(Properties::COLOR_NTP_TEXT), 0.70); | |
| 238 case Properties::COLOR_NTP_SECTION_HEADER_RULE_LIGHT: | |
| 239 return IncreaseLightness(GetColor(Properties::COLOR_NTP_TEXT), 0.86); | |
| 240 case Properties::COLOR_NTP_TEXT_LIGHT: | |
| 241 return IncreaseLightness(GetColor(Properties::COLOR_NTP_TEXT), 0.40); | |
| 242 case Properties::COLOR_TAB_THROBBER_SPINNING: | |
| 243 case Properties::COLOR_TAB_THROBBER_WAITING: { | |
| 244 SkColor base_color = | |
| 245 ui::GetAuraColor(id == Properties::COLOR_TAB_THROBBER_SPINNING | |
| 246 ? ui::NativeTheme::kColorId_ThrobberSpinningColor | |
| 247 : ui::NativeTheme::kColorId_ThrobberWaitingColor, | |
| 248 nullptr); | |
| 249 color_utils::HSL hsl = GetTint(Properties::TINT_BUTTONS); | |
| 250 return color_utils::HSLShift(base_color, hsl); | |
| 251 } | |
| 252 #if defined(ENABLE_SUPERVISED_USERS) | |
| 253 case Properties::COLOR_SUPERVISED_USER_LABEL: | |
| 254 return color_utils::GetReadableColor( | |
| 255 SK_ColorWHITE, | |
| 256 GetColor(Properties::COLOR_SUPERVISED_USER_LABEL_BACKGROUND)); | |
| 257 case Properties::COLOR_SUPERVISED_USER_LABEL_BACKGROUND: | |
| 258 return color_utils::BlendTowardOppositeLuminance( | |
| 259 GetColor(Properties::COLOR_FRAME), 0x80); | |
| 260 case Properties::COLOR_SUPERVISED_USER_LABEL_BORDER: | |
| 261 return color_utils::AlphaBlend( | |
| 262 GetColor(Properties::COLOR_SUPERVISED_USER_LABEL_BACKGROUND), | |
| 263 SK_ColorBLACK, | |
| 264 230); | |
| 265 #endif | |
| 266 case Properties::COLOR_STATUS_BAR_TEXT: { | |
| 267 // A long time ago, we blended the toolbar and the tab text together to | |
| 268 // get the status bar text because, at the time, our text rendering in | |
| 269 // views couldn't do alpha blending. Even though this is no longer the | |
| 270 // case, this blending decision is built into the majority of themes that | |
| 271 // exist, and we must keep doing it. | |
| 272 SkColor toolbar_color = GetColor(Properties::COLOR_TOOLBAR); | |
| 273 SkColor text_color = GetColor(Properties::COLOR_TAB_TEXT); | |
| 274 return SkColorSetARGB( | |
| 275 SkColorGetA(text_color), | |
| 276 (SkColorGetR(text_color) + SkColorGetR(toolbar_color)) / 2, | |
| 277 (SkColorGetG(text_color) + SkColorGetR(toolbar_color)) / 2, | |
| 278 (SkColorGetB(text_color) + SkColorGetR(toolbar_color)) / 2); | |
| 279 } | |
| 280 } | |
| 281 | |
| 282 return Properties::GetDefaultColor(id); | |
| 283 } | |
| 284 | |
| 285 int ThemeService::GetDisplayProperty(int id) const { | |
| 286 int result = 0; | |
| 287 if (theme_supplier_.get() && | |
| 288 theme_supplier_->GetDisplayProperty(id, &result)) { | |
| 289 return result; | |
| 290 } | |
| 291 | |
| 292 switch (id) { | |
| 293 case Properties::NTP_BACKGROUND_ALIGNMENT: | |
| 294 return Properties::ALIGN_CENTER; | |
| 295 | |
| 296 case Properties::NTP_BACKGROUND_TILING: | |
| 297 return Properties::NO_REPEAT; | |
| 298 | |
| 299 case Properties::NTP_LOGO_ALTERNATE: | |
| 300 return UsingDefaultTheme() || UsingSystemTheme() || | |
| 301 (!HasCustomImage(IDR_THEME_NTP_BACKGROUND) && | |
| 302 IsColorGrayscale(GetColor(Properties::COLOR_NTP_BACKGROUND))) ? | |
| 303 0 : 1; | |
| 304 | |
| 305 default: | |
| 306 return -1; | |
| 307 } | |
| 308 } | |
| 309 | |
| 310 bool ThemeService::ShouldUseNativeFrame() const { | |
| 311 if (HasCustomImage(IDR_THEME_FRAME)) | |
| 312 return false; | |
| 313 #if defined(OS_WIN) | |
| 314 return ui::win::IsAeroGlassEnabled(); | |
| 315 #else | |
| 316 return false; | |
| 317 #endif | |
| 318 } | |
| 319 | |
| 320 bool ThemeService::HasCustomImage(int id) const { | |
| 321 return BrowserThemePack::IsPersistentImageID(id) && | |
| 322 theme_supplier_ && theme_supplier_->HasCustomImage(id); | |
| 323 } | |
| 324 | |
| 325 base::RefCountedMemory* ThemeService::GetRawData( | |
| 326 int id, | |
| 327 ui::ScaleFactor scale_factor) const { | |
| 328 // Check to see whether we should substitute some images. | |
| 329 int ntp_alternate = GetDisplayProperty(Properties::NTP_LOGO_ALTERNATE); | |
| 330 if (id == IDR_PRODUCT_LOGO && ntp_alternate != 0) | |
| 331 id = IDR_PRODUCT_LOGO_WHITE; | |
| 332 | |
| 333 base::RefCountedMemory* data = nullptr; | |
| 334 if (theme_supplier_.get()) | |
| 335 data = theme_supplier_->GetRawData(id, scale_factor); | |
| 336 if (!data) | |
| 337 data = rb_.LoadDataResourceBytesForScale(id, ui::SCALE_FACTOR_100P); | |
| 338 | |
| 339 return data; | |
| 340 } | |
| 341 | |
| 342 void ThemeService::Shutdown() { | 193 void ThemeService::Shutdown() { |
| 343 #if defined(ENABLE_EXTENSIONS) | 194 #if defined(ENABLE_EXTENSIONS) |
| 344 theme_observer_.reset(); | 195 theme_observer_.reset(); |
| 345 #endif | 196 #endif |
| 346 } | 197 } |
| 347 | 198 |
| 348 void ThemeService::Observe(int type, | 199 void ThemeService::Observe(int type, |
| 349 const content::NotificationSource& source, | 200 const content::NotificationSource& source, |
| 350 const content::NotificationDetails& details) { | 201 const content::NotificationDetails& details) { |
| 351 using content::Details; | 202 using content::Details; |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 484 } | 335 } |
| 485 | 336 |
| 486 std::string ThemeService::GetThemeID() const { | 337 std::string ThemeService::GetThemeID() const { |
| 487 return profile_->GetPrefs()->GetString(prefs::kCurrentThemeID); | 338 return profile_->GetPrefs()->GetString(prefs::kCurrentThemeID); |
| 488 } | 339 } |
| 489 | 340 |
| 490 color_utils::HSL ThemeService::GetTint(int id) const { | 341 color_utils::HSL ThemeService::GetTint(int id) const { |
| 491 DCHECK(CalledOnValidThread()); | 342 DCHECK(CalledOnValidThread()); |
| 492 | 343 |
| 493 color_utils::HSL hsl; | 344 color_utils::HSL hsl; |
| 494 if (theme_supplier_.get() && theme_supplier_->GetTint(id, &hsl)) | 345 if (theme_supplier_ && theme_supplier_->GetTint(id, &hsl)) |
| 495 return hsl; | 346 return hsl; |
| 496 | 347 |
| 497 return ThemeProperties::GetDefaultTint(id); | 348 return ThemeProperties::GetDefaultTint(id); |
| 498 } | 349 } |
| 499 | 350 |
| 500 void ThemeService::ClearAllThemeData() { | 351 void ThemeService::ClearAllThemeData() { |
| 501 if (!ready_) | 352 if (!ready_) |
| 502 return; | 353 return; |
| 503 | 354 |
| 504 SwapThemeSupplier(nullptr); | 355 SwapThemeSupplier(nullptr); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 542 bool loaded_pack = false; | 393 bool loaded_pack = false; |
| 543 | 394 |
| 544 // If we don't have a file pack, we're updating from an old version, or the | 395 // If we don't have a file pack, we're updating from an old version, or the |
| 545 // pack was created for an alternative MaterialDesignController::Mode. | 396 // pack was created for an alternative MaterialDesignController::Mode. |
| 546 base::FilePath path = prefs->GetFilePath(prefs::kCurrentThemePackFilename); | 397 base::FilePath path = prefs->GetFilePath(prefs::kCurrentThemePackFilename); |
| 547 if (path != base::FilePath()) { | 398 if (path != base::FilePath()) { |
| 548 path = path.Append(ui::MaterialDesignController::IsModeMaterial() | 399 path = path.Append(ui::MaterialDesignController::IsModeMaterial() |
| 549 ? chrome::kThemePackMaterialDesignFilename | 400 ? chrome::kThemePackMaterialDesignFilename |
| 550 : chrome::kThemePackFilename); | 401 : chrome::kThemePackFilename); |
| 551 SwapThemeSupplier(BrowserThemePack::BuildFromDataPack(path, current_id)); | 402 SwapThemeSupplier(BrowserThemePack::BuildFromDataPack(path, current_id)); |
| 552 loaded_pack = theme_supplier_.get() != nullptr; | 403 loaded_pack = theme_supplier_ != nullptr; |
| 553 } | 404 } |
| 554 | 405 |
| 555 if (loaded_pack) { | 406 if (loaded_pack) { |
| 556 content::RecordAction(UserMetricsAction("Themes.Loaded")); | 407 content::RecordAction(UserMetricsAction("Themes.Loaded")); |
| 557 set_ready(); | 408 set_ready(); |
| 558 } | 409 } |
| 559 // Else: wait for the extension service to be ready so that the theme pack | 410 // Else: wait for the extension service to be ready so that the theme pack |
| 560 // can be recreated from the extension. | 411 // can be recreated from the extension. |
| 561 } | 412 } |
| 562 | 413 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 580 theme_syncable_service_->OnThemeChange(); | 431 theme_syncable_service_->OnThemeChange(); |
| 581 } | 432 } |
| 582 } | 433 } |
| 583 | 434 |
| 584 #if defined(USE_AURA) | 435 #if defined(USE_AURA) |
| 585 void ThemeService::FreePlatformCaches() { | 436 void ThemeService::FreePlatformCaches() { |
| 586 // Views (Skia) has no platform image cache to clear. | 437 // Views (Skia) has no platform image cache to clear. |
| 587 } | 438 } |
| 588 #endif | 439 #endif |
| 589 | 440 |
| 441 bool ThemeService::UsingSystemTheme() const { |
| 442 return UsingDefaultTheme(); |
| 443 } |
| 444 |
| 445 gfx::ImageSkia* ThemeService::GetImageSkiaNamed(int id) const { |
| 446 gfx::Image image = GetImageNamed(id); |
| 447 if (image.IsEmpty()) |
| 448 return nullptr; |
| 449 // TODO(pkotwicz): Remove this const cast. The gfx::Image interface returns |
| 450 // its images const. GetImageSkiaNamed() also should but has many callsites. |
| 451 return const_cast<gfx::ImageSkia*>(image.ToImageSkia()); |
| 452 } |
| 453 |
| 454 SkColor ThemeService::GetColor(int id, bool otr) const { |
| 455 DCHECK(CalledOnValidThread()); |
| 456 // Custom themes always use the original (non-incognito) color. |
| 457 SkColor color; |
| 458 if (theme_supplier_ && theme_supplier_->GetColor(id, &color)) |
| 459 return color; |
| 460 |
| 461 // For backward compat with older themes, some newer colors are generated from |
| 462 // older ones if they are missing. |
| 463 switch (id) { |
| 464 case Properties::COLOR_TOOLBAR_BUTTON_ICON: |
| 465 return color_utils::HSLShift(gfx::kChromeIconGrey, |
| 466 GetTint(Properties::TINT_BUTTONS)); |
| 467 case Properties::COLOR_TOOLBAR_BUTTON_ICON_INACTIVE: |
| 468 // The active color is overridden in Gtk2UI. |
| 469 return SkColorSetA(GetColor(Properties::COLOR_TOOLBAR_BUTTON_ICON, otr), |
| 470 0x33); |
| 471 case Properties::COLOR_NTP_SECTION_HEADER_TEXT: |
| 472 return IncreaseLightness(GetColor(Properties::COLOR_NTP_TEXT, otr), 0.30); |
| 473 case Properties::COLOR_NTP_SECTION_HEADER_TEXT_HOVER: |
| 474 return GetColor(Properties::COLOR_NTP_TEXT, otr); |
| 475 case Properties::COLOR_NTP_SECTION_HEADER_RULE: |
| 476 return IncreaseLightness(GetColor(Properties::COLOR_NTP_TEXT, otr), 0.70); |
| 477 case Properties::COLOR_NTP_SECTION_HEADER_RULE_LIGHT: |
| 478 return IncreaseLightness(GetColor(Properties::COLOR_NTP_TEXT, otr), 0.86); |
| 479 case Properties::COLOR_NTP_TEXT_LIGHT: |
| 480 return IncreaseLightness(GetColor(Properties::COLOR_NTP_TEXT, otr), 0.40); |
| 481 case Properties::COLOR_TAB_THROBBER_SPINNING: |
| 482 case Properties::COLOR_TAB_THROBBER_WAITING: { |
| 483 SkColor base_color = |
| 484 ui::GetAuraColor(id == Properties::COLOR_TAB_THROBBER_SPINNING |
| 485 ? ui::NativeTheme::kColorId_ThrobberSpinningColor |
| 486 : ui::NativeTheme::kColorId_ThrobberWaitingColor, |
| 487 nullptr); |
| 488 color_utils::HSL hsl = GetTint(Properties::TINT_BUTTONS); |
| 489 return color_utils::HSLShift(base_color, hsl); |
| 490 } |
| 491 #if defined(ENABLE_SUPERVISED_USERS) |
| 492 case Properties::COLOR_SUPERVISED_USER_LABEL: |
| 493 return color_utils::GetReadableColor( |
| 494 SK_ColorWHITE, |
| 495 GetColor(Properties::COLOR_SUPERVISED_USER_LABEL_BACKGROUND, otr)); |
| 496 case Properties::COLOR_SUPERVISED_USER_LABEL_BACKGROUND: |
| 497 return color_utils::BlendTowardOppositeLuminance( |
| 498 GetColor(Properties::COLOR_FRAME, otr), 0x80); |
| 499 case Properties::COLOR_SUPERVISED_USER_LABEL_BORDER: |
| 500 return color_utils::AlphaBlend( |
| 501 GetColor(Properties::COLOR_SUPERVISED_USER_LABEL_BACKGROUND, otr), |
| 502 SK_ColorBLACK, 230); |
| 503 #endif |
| 504 case Properties::COLOR_STATUS_BAR_TEXT: { |
| 505 // A long time ago, we blended the toolbar and the tab text together to |
| 506 // get the status bar text because, at the time, our text rendering in |
| 507 // views couldn't do alpha blending. Even though this is no longer the |
| 508 // case, this blending decision is built into the majority of themes that |
| 509 // exist, and we must keep doing it. |
| 510 SkColor toolbar_color = GetColor(Properties::COLOR_TOOLBAR, otr); |
| 511 SkColor text_color = GetColor(Properties::COLOR_TAB_TEXT, otr); |
| 512 return SkColorSetARGB( |
| 513 SkColorGetA(text_color), |
| 514 (SkColorGetR(text_color) + SkColorGetR(toolbar_color)) / 2, |
| 515 (SkColorGetG(text_color) + SkColorGetR(toolbar_color)) / 2, |
| 516 (SkColorGetB(text_color) + SkColorGetR(toolbar_color)) / 2); |
| 517 } |
| 518 } |
| 519 |
| 520 return Properties::GetDefaultColor(id, otr); |
| 521 } |
| 522 |
| 523 int ThemeService::GetDisplayProperty(int id) const { |
| 524 int result = 0; |
| 525 if (theme_supplier_ && theme_supplier_->GetDisplayProperty(id, &result)) { |
| 526 return result; |
| 527 } |
| 528 |
| 529 switch (id) { |
| 530 case Properties::NTP_BACKGROUND_ALIGNMENT: |
| 531 return Properties::ALIGN_CENTER; |
| 532 |
| 533 case Properties::NTP_BACKGROUND_TILING: |
| 534 return Properties::NO_REPEAT; |
| 535 |
| 536 case Properties::NTP_LOGO_ALTERNATE: |
| 537 return UsingDefaultTheme() || UsingSystemTheme() || |
| 538 (!HasCustomImage(IDR_THEME_NTP_BACKGROUND) && |
| 539 IsColorGrayscale( |
| 540 GetColor(Properties::COLOR_NTP_BACKGROUND, false))) |
| 541 ? 0 |
| 542 : 1; |
| 543 |
| 544 default: |
| 545 return -1; |
| 546 } |
| 547 } |
| 548 |
| 549 bool ThemeService::ShouldUseNativeFrame() const { |
| 550 if (HasCustomImage(IDR_THEME_FRAME)) |
| 551 return false; |
| 552 #if defined(OS_WIN) |
| 553 return ui::win::IsAeroGlassEnabled(); |
| 554 #else |
| 555 return false; |
| 556 #endif |
| 557 } |
| 558 |
| 559 bool ThemeService::HasCustomImage(int id) const { |
| 560 return BrowserThemePack::IsPersistentImageID(id) && theme_supplier_ && |
| 561 theme_supplier_->HasCustomImage(id); |
| 562 } |
| 563 |
| 564 base::RefCountedMemory* ThemeService::GetRawData( |
| 565 int id, |
| 566 ui::ScaleFactor scale_factor) const { |
| 567 // Check to see whether we should substitute some images. |
| 568 int ntp_alternate = GetDisplayProperty(Properties::NTP_LOGO_ALTERNATE); |
| 569 if (id == IDR_PRODUCT_LOGO && ntp_alternate != 0) |
| 570 id = IDR_PRODUCT_LOGO_WHITE; |
| 571 |
| 572 base::RefCountedMemory* data = nullptr; |
| 573 if (theme_supplier_) |
| 574 data = theme_supplier_->GetRawData(id, scale_factor); |
| 575 if (!data) |
| 576 data = rb_.LoadDataResourceBytesForScale(id, ui::SCALE_FACTOR_100P); |
| 577 |
| 578 return data; |
| 579 } |
| 580 |
| 581 gfx::Image ThemeService::GetImageNamed(int id) const { |
| 582 DCHECK(CalledOnValidThread()); |
| 583 |
| 584 gfx::Image image; |
| 585 if (theme_supplier_) |
| 586 image = theme_supplier_->GetImageNamed(id); |
| 587 |
| 588 if (image.IsEmpty()) |
| 589 image = rb_.GetNativeImageNamed(id); |
| 590 |
| 591 return image; |
| 592 } |
| 593 |
| 590 void ThemeService::OnExtensionServiceReady() { | 594 void ThemeService::OnExtensionServiceReady() { |
| 591 if (!ready_) { | 595 if (!ready_) { |
| 592 // If the ThemeService is not ready yet, the custom theme data pack needs to | 596 // If the ThemeService is not ready yet, the custom theme data pack needs to |
| 593 // be recreated from the extension. | 597 // be recreated from the extension. |
| 594 MigrateTheme(); | 598 MigrateTheme(); |
| 595 set_ready(); | 599 set_ready(); |
| 596 | 600 |
| 597 // Send notification in case anyone requested data and cached it when the | 601 // Send notification in case anyone requested data and cached it when the |
| 598 // theme service was not ready yet. | 602 // theme service was not ready yet. |
| 599 NotifyThemeChanged(); | 603 NotifyThemeChanged(); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 626 content::RecordAction(UserMetricsAction("Themes.Migrated")); | 630 content::RecordAction(UserMetricsAction("Themes.Migrated")); |
| 627 } else { | 631 } else { |
| 628 DLOG(ERROR) << "Theme is mysteriously gone."; | 632 DLOG(ERROR) << "Theme is mysteriously gone."; |
| 629 ClearAllThemeData(); | 633 ClearAllThemeData(); |
| 630 content::RecordAction(UserMetricsAction("Themes.Gone")); | 634 content::RecordAction(UserMetricsAction("Themes.Gone")); |
| 631 } | 635 } |
| 632 } | 636 } |
| 633 | 637 |
| 634 void ThemeService::SwapThemeSupplier( | 638 void ThemeService::SwapThemeSupplier( |
| 635 scoped_refptr<CustomThemeSupplier> theme_supplier) { | 639 scoped_refptr<CustomThemeSupplier> theme_supplier) { |
| 636 if (theme_supplier_.get()) | 640 if (theme_supplier_) |
| 637 theme_supplier_->StopUsingTheme(); | 641 theme_supplier_->StopUsingTheme(); |
| 638 theme_supplier_ = theme_supplier; | 642 theme_supplier_ = theme_supplier; |
| 639 if (theme_supplier_.get()) | 643 if (theme_supplier_) |
| 640 theme_supplier_->StartUsingTheme(); | 644 theme_supplier_->StartUsingTheme(); |
| 641 } | 645 } |
| 642 | 646 |
| 643 void ThemeService::SavePackName(const base::FilePath& pack_path) { | 647 void ThemeService::SavePackName(const base::FilePath& pack_path) { |
| 644 profile_->GetPrefs()->SetFilePath( | 648 profile_->GetPrefs()->SetFilePath( |
| 645 prefs::kCurrentThemePackFilename, pack_path); | 649 prefs::kCurrentThemePackFilename, pack_path); |
| 646 } | 650 } |
| 647 | 651 |
| 648 void ThemeService::SaveThemeID(const std::string& id) { | 652 void ThemeService::SaveThemeID(const std::string& id) { |
| 649 profile_->GetPrefs()->SetString(prefs::kCurrentThemeID, id); | 653 profile_->GetPrefs()->SetString(prefs::kCurrentThemeID, id); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 696 void ThemeService::OnInfobarDestroyed() { | 700 void ThemeService::OnInfobarDestroyed() { |
| 697 number_of_infobars_--; | 701 number_of_infobars_--; |
| 698 | 702 |
| 699 if (number_of_infobars_ == 0) | 703 if (number_of_infobars_ == 0) |
| 700 RemoveUnusedThemes(false); | 704 RemoveUnusedThemes(false); |
| 701 } | 705 } |
| 702 | 706 |
| 703 ThemeSyncableService* ThemeService::GetThemeSyncableService() const { | 707 ThemeSyncableService* ThemeService::GetThemeSyncableService() const { |
| 704 return theme_syncable_service_.get(); | 708 return theme_syncable_service_.get(); |
| 705 } | 709 } |
| 710 |
| 711 // static |
| 712 const ui::ThemeProvider& ThemeService::GetThemeProviderForProfile( |
| 713 Profile* profile) { |
| 714 ThemeService* service = ThemeServiceFactory::GetForProfile(profile); |
| 715 #if defined(OS_MACOSX) |
| 716 // TODO(estade): this doesn't work for OSX yet; fall back to normal theming |
| 717 // in incognito. Since the OSX version of ThemeService caches colors, and |
| 718 // both ThemeProviders use the same ThemeService some code needs to be |
| 719 // rearranged. |
| 720 bool off_the_record = false; |
| 721 #else |
| 722 bool off_the_record = profile->IsOffTheRecord(); |
| 723 #endif |
| 724 return off_the_record ? service->otr_theme_provider_ |
| 725 : service->original_theme_provider_; |
| 726 } |
| 727 |
| 728 ThemeService::BrowserThemeProvider::BrowserThemeProvider( |
| 729 const ThemeService& theme_service, |
| 730 bool off_the_record) |
| 731 : theme_service_(theme_service), off_the_record_(off_the_record) {} |
| 732 |
| 733 ThemeService::BrowserThemeProvider::~BrowserThemeProvider() {} |
| 734 |
| 735 gfx::ImageSkia* ThemeService::BrowserThemeProvider::GetImageSkiaNamed( |
| 736 int id) const { |
| 737 return theme_service_.GetImageSkiaNamed(id); |
| 738 } |
| 739 |
| 740 SkColor ThemeService::BrowserThemeProvider::GetColor(int id) const { |
| 741 return theme_service_.GetColor(id, off_the_record_); |
| 742 } |
| 743 |
| 744 int ThemeService::BrowserThemeProvider::GetDisplayProperty(int id) const { |
| 745 return theme_service_.GetDisplayProperty(id); |
| 746 } |
| 747 |
| 748 bool ThemeService::BrowserThemeProvider::ShouldUseNativeFrame() const { |
| 749 return theme_service_.ShouldUseNativeFrame(); |
| 750 } |
| 751 |
| 752 bool ThemeService::BrowserThemeProvider::HasCustomImage(int id) const { |
| 753 return theme_service_.HasCustomImage(id); |
| 754 } |
| 755 |
| 756 base::RefCountedMemory* ThemeService::BrowserThemeProvider::GetRawData( |
| 757 int id, |
| 758 ui::ScaleFactor scale_factor) const { |
| 759 return theme_service_.GetRawData(id, scale_factor); |
| 760 } |
| OLD | NEW |