| 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" |
| 11 #include "base/sequenced_task_runner.h" | 11 #include "base/sequenced_task_runner.h" |
| 12 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
| 13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 14 #include "chrome/browser/chrome_notification_types.h" | 14 #include "chrome/browser/chrome_notification_types.h" |
| 15 #include "chrome/browser/extensions/extension_service.h" | 15 #include "chrome/browser/extensions/extension_service.h" |
| 16 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
| 17 #include "chrome/browser/supervised_user/supervised_user_theme.h" | |
| 18 #include "chrome/browser/themes/browser_theme_pack.h" | 17 #include "chrome/browser/themes/browser_theme_pack.h" |
| 19 #include "chrome/browser/themes/custom_theme_supplier.h" | 18 #include "chrome/browser/themes/custom_theme_supplier.h" |
| 20 #include "chrome/browser/themes/theme_properties.h" | 19 #include "chrome/browser/themes/theme_properties.h" |
| 21 #include "chrome/browser/themes/theme_syncable_service.h" | 20 #include "chrome/browser/themes/theme_syncable_service.h" |
| 22 #include "chrome/common/chrome_constants.h" | 21 #include "chrome/common/chrome_constants.h" |
| 23 #include "chrome/common/pref_names.h" | 22 #include "chrome/common/pref_names.h" |
| 24 #include "content/public/browser/notification_service.h" | 23 #include "content/public/browser/notification_service.h" |
| 25 #include "content/public/browser/user_metrics.h" | 24 #include "content/public/browser/user_metrics.h" |
| 26 #include "extensions/browser/extension_prefs.h" | 25 #include "extensions/browser/extension_prefs.h" |
| 27 #include "extensions/browser/extension_registry.h" | 26 #include "extensions/browser/extension_registry.h" |
| 28 #include "extensions/browser/extension_system.h" | 27 #include "extensions/browser/extension_system.h" |
| 29 #include "extensions/common/extension.h" | 28 #include "extensions/common/extension.h" |
| 30 #include "extensions/common/extension_set.h" | 29 #include "extensions/common/extension_set.h" |
| 31 #include "grit/theme_resources.h" | 30 #include "grit/theme_resources.h" |
| 32 #include "grit/ui_resources.h" | 31 #include "grit/ui_resources.h" |
| 33 #include "ui/base/layout.h" | 32 #include "ui/base/layout.h" |
| 34 #include "ui/base/resource/resource_bundle.h" | 33 #include "ui/base/resource/resource_bundle.h" |
| 35 #include "ui/gfx/image/image_skia.h" | 34 #include "ui/gfx/image/image_skia.h" |
| 36 | 35 |
| 36 #if defined(ENABLE_MANAGED_USERS) |
| 37 #include "chrome/browser/supervised_user/supervised_user_theme.h" |
| 38 #endif |
| 39 |
| 37 #if defined(OS_WIN) | 40 #if defined(OS_WIN) |
| 38 #include "ui/base/win/shell.h" | 41 #include "ui/base/win/shell.h" |
| 39 #endif | 42 #endif |
| 40 | 43 |
| 41 using base::UserMetricsAction; | 44 using base::UserMetricsAction; |
| 42 using content::BrowserThread; | 45 using content::BrowserThread; |
| 43 using extensions::Extension; | 46 using extensions::Extension; |
| 44 using extensions::UnloadedExtensionInfo; | 47 using extensions::UnloadedExtensionInfo; |
| 45 using ui::ResourceBundle; | 48 using ui::ResourceBundle; |
| 46 | 49 |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 case Properties::COLOR_NTP_SECTION_HEADER_TEXT: | 147 case Properties::COLOR_NTP_SECTION_HEADER_TEXT: |
| 145 return IncreaseLightness(GetColor(Properties::COLOR_NTP_TEXT), 0.30); | 148 return IncreaseLightness(GetColor(Properties::COLOR_NTP_TEXT), 0.30); |
| 146 case Properties::COLOR_NTP_SECTION_HEADER_TEXT_HOVER: | 149 case Properties::COLOR_NTP_SECTION_HEADER_TEXT_HOVER: |
| 147 return GetColor(Properties::COLOR_NTP_TEXT); | 150 return GetColor(Properties::COLOR_NTP_TEXT); |
| 148 case Properties::COLOR_NTP_SECTION_HEADER_RULE: | 151 case Properties::COLOR_NTP_SECTION_HEADER_RULE: |
| 149 return IncreaseLightness(GetColor(Properties::COLOR_NTP_TEXT), 0.70); | 152 return IncreaseLightness(GetColor(Properties::COLOR_NTP_TEXT), 0.70); |
| 150 case Properties::COLOR_NTP_SECTION_HEADER_RULE_LIGHT: | 153 case Properties::COLOR_NTP_SECTION_HEADER_RULE_LIGHT: |
| 151 return IncreaseLightness(GetColor(Properties::COLOR_NTP_TEXT), 0.86); | 154 return IncreaseLightness(GetColor(Properties::COLOR_NTP_TEXT), 0.86); |
| 152 case Properties::COLOR_NTP_TEXT_LIGHT: | 155 case Properties::COLOR_NTP_TEXT_LIGHT: |
| 153 return IncreaseLightness(GetColor(Properties::COLOR_NTP_TEXT), 0.40); | 156 return IncreaseLightness(GetColor(Properties::COLOR_NTP_TEXT), 0.40); |
| 157 #if defined(ENABLE_MANAGED_USERS) |
| 154 case Properties::COLOR_SUPERVISED_USER_LABEL: | 158 case Properties::COLOR_SUPERVISED_USER_LABEL: |
| 155 return color_utils::GetReadableColor( | 159 return color_utils::GetReadableColor( |
| 156 SK_ColorWHITE, | 160 SK_ColorWHITE, |
| 157 GetColor(Properties::COLOR_SUPERVISED_USER_LABEL_BACKGROUND)); | 161 GetColor(Properties::COLOR_SUPERVISED_USER_LABEL_BACKGROUND)); |
| 158 case Properties::COLOR_SUPERVISED_USER_LABEL_BACKGROUND: | 162 case Properties::COLOR_SUPERVISED_USER_LABEL_BACKGROUND: |
| 159 return color_utils::BlendTowardOppositeLuminance( | 163 return color_utils::BlendTowardOppositeLuminance( |
| 160 GetColor(Properties::COLOR_FRAME), 0x80); | 164 GetColor(Properties::COLOR_FRAME), 0x80); |
| 161 case Properties::COLOR_SUPERVISED_USER_LABEL_BORDER: | 165 case Properties::COLOR_SUPERVISED_USER_LABEL_BORDER: |
| 162 return color_utils::AlphaBlend( | 166 return color_utils::AlphaBlend( |
| 163 GetColor(Properties::COLOR_SUPERVISED_USER_LABEL_BACKGROUND), | 167 GetColor(Properties::COLOR_SUPERVISED_USER_LABEL_BACKGROUND), |
| 164 SK_ColorBLACK, | 168 SK_ColorBLACK, |
| 165 230); | 169 230); |
| 170 #endif |
| 166 case Properties::COLOR_STATUS_BAR_TEXT: { | 171 case Properties::COLOR_STATUS_BAR_TEXT: { |
| 167 // A long time ago, we blended the toolbar and the tab text together to | 172 // A long time ago, we blended the toolbar and the tab text together to |
| 168 // get the status bar text because, at the time, our text rendering in | 173 // get the status bar text because, at the time, our text rendering in |
| 169 // views couldn't do alpha blending. Even though this is no longer the | 174 // views couldn't do alpha blending. Even though this is no longer the |
| 170 // case, this blending decision is built into the majority of themes that | 175 // case, this blending decision is built into the majority of themes that |
| 171 // exist, and we must keep doing it. | 176 // exist, and we must keep doing it. |
| 172 SkColor toolbar_color = GetColor(Properties::COLOR_TOOLBAR); | 177 SkColor toolbar_color = GetColor(Properties::COLOR_TOOLBAR); |
| 173 SkColor text_color = GetColor(Properties::COLOR_TAB_TEXT); | 178 SkColor text_color = GetColor(Properties::COLOR_TAB_TEXT); |
| 174 return SkColorSetARGB( | 179 return SkColorSetARGB( |
| 175 SkColorGetA(text_color), | 180 SkColorGetA(text_color), |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 370 service->UninstallExtension( | 375 service->UninstallExtension( |
| 371 remove_list[i], | 376 remove_list[i], |
| 372 ExtensionService::UNINSTALL_REASON_ORPHANED_THEME, | 377 ExtensionService::UNINSTALL_REASON_ORPHANED_THEME, |
| 373 NULL); | 378 NULL); |
| 374 } | 379 } |
| 375 } | 380 } |
| 376 | 381 |
| 377 void ThemeService::UseDefaultTheme() { | 382 void ThemeService::UseDefaultTheme() { |
| 378 if (ready_) | 383 if (ready_) |
| 379 content::RecordAction(UserMetricsAction("Themes_Reset")); | 384 content::RecordAction(UserMetricsAction("Themes_Reset")); |
| 385 #if defined(ENABLE_MANAGED_USERS) |
| 380 if (IsSupervisedUser()) { | 386 if (IsSupervisedUser()) { |
| 381 SetSupervisedUserTheme(); | 387 SetSupervisedUserTheme(); |
| 382 return; | 388 return; |
| 383 } | 389 } |
| 390 #endif |
| 384 ClearAllThemeData(); | 391 ClearAllThemeData(); |
| 385 NotifyThemeChanged(); | 392 NotifyThemeChanged(); |
| 386 } | 393 } |
| 387 | 394 |
| 388 void ThemeService::UseSystemTheme() { | 395 void ThemeService::UseSystemTheme() { |
| 389 UseDefaultTheme(); | 396 UseDefaultTheme(); |
| 390 } | 397 } |
| 391 | 398 |
| 392 bool ThemeService::UsingDefaultTheme() const { | 399 bool ThemeService::UsingDefaultTheme() const { |
| 393 std::string id = GetThemeID(); | 400 std::string id = GetThemeID(); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 429 base::Bind(&ThemeService::RemoveUnusedThemes, | 436 base::Bind(&ThemeService::RemoveUnusedThemes, |
| 430 weak_ptr_factory_.GetWeakPtr(), | 437 weak_ptr_factory_.GetWeakPtr(), |
| 431 true)); | 438 true)); |
| 432 } | 439 } |
| 433 | 440 |
| 434 void ThemeService::LoadThemePrefs() { | 441 void ThemeService::LoadThemePrefs() { |
| 435 PrefService* prefs = profile_->GetPrefs(); | 442 PrefService* prefs = profile_->GetPrefs(); |
| 436 | 443 |
| 437 std::string current_id = GetThemeID(); | 444 std::string current_id = GetThemeID(); |
| 438 if (current_id == kDefaultThemeID) { | 445 if (current_id == kDefaultThemeID) { |
| 446 #if defined(ENABLE_MANAGED_USERS) |
| 439 // Supervised users have a different default theme. | 447 // Supervised users have a different default theme. |
| 440 if (IsSupervisedUser()) | 448 if (IsSupervisedUser()) { |
| 441 SetSupervisedUserTheme(); | 449 SetSupervisedUserTheme(); |
| 442 else if (ShouldInitWithSystemTheme()) | 450 set_ready(); |
| 451 return; |
| 452 } |
| 453 #endif |
| 454 if (ShouldInitWithSystemTheme()) |
| 443 UseSystemTheme(); | 455 UseSystemTheme(); |
| 444 else | 456 else |
| 445 UseDefaultTheme(); | 457 UseDefaultTheme(); |
| 446 set_ready(); | 458 set_ready(); |
| 447 return; | 459 return; |
| 448 } | 460 } |
| 449 | 461 |
| 450 bool loaded_pack = false; | 462 bool loaded_pack = false; |
| 451 | 463 |
| 452 // If we don't have a file pack, we're updating from an old version. | 464 // If we don't have a file pack, we're updating from an old version. |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 578 base::FilePath pack_path = | 590 base::FilePath pack_path = |
| 579 extension->path().Append(chrome::kThemePackFilename); | 591 extension->path().Append(chrome::kThemePackFilename); |
| 580 service->GetFileTaskRunner()->PostTask( | 592 service->GetFileTaskRunner()->PostTask( |
| 581 FROM_HERE, | 593 FROM_HERE, |
| 582 base::Bind(&WritePackToDiskCallback, pack, pack_path)); | 594 base::Bind(&WritePackToDiskCallback, pack, pack_path)); |
| 583 | 595 |
| 584 SavePackName(pack_path); | 596 SavePackName(pack_path); |
| 585 SwapThemeSupplier(pack); | 597 SwapThemeSupplier(pack); |
| 586 } | 598 } |
| 587 | 599 |
| 600 #if defined(ENABLE_MANAGED_USERS) |
| 588 bool ThemeService::IsSupervisedUser() const { | 601 bool ThemeService::IsSupervisedUser() const { |
| 589 return profile_->IsSupervised(); | 602 return profile_->IsSupervised(); |
| 590 } | 603 } |
| 591 | 604 |
| 592 void ThemeService::SetSupervisedUserTheme() { | 605 void ThemeService::SetSupervisedUserTheme() { |
| 593 SetCustomDefaultTheme(new SupervisedUserTheme); | 606 SetCustomDefaultTheme(new SupervisedUserTheme); |
| 594 } | 607 } |
| 608 #endif |
| 595 | 609 |
| 596 void ThemeService::OnInfobarDisplayed() { | 610 void ThemeService::OnInfobarDisplayed() { |
| 597 number_of_infobars_++; | 611 number_of_infobars_++; |
| 598 } | 612 } |
| 599 | 613 |
| 600 void ThemeService::OnInfobarDestroyed() { | 614 void ThemeService::OnInfobarDestroyed() { |
| 601 number_of_infobars_--; | 615 number_of_infobars_--; |
| 602 | 616 |
| 603 if (number_of_infobars_ == 0) | 617 if (number_of_infobars_ == 0) |
| 604 RemoveUnusedThemes(false); | 618 RemoveUnusedThemes(false); |
| 605 } | 619 } |
| 606 | 620 |
| 607 ThemeSyncableService* ThemeService::GetThemeSyncableService() const { | 621 ThemeSyncableService* ThemeService::GetThemeSyncableService() const { |
| 608 return theme_syncable_service_.get(); | 622 return theme_syncable_service_.get(); |
| 609 } | 623 } |
| OLD | NEW |