| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 | 10 |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/files/file_util.h" |
| 12 #include "base/location.h" | 13 #include "base/location.h" |
| 13 #include "base/memory/ref_counted_memory.h" | 14 #include "base/memory/ref_counted_memory.h" |
| 14 #include "base/sequenced_task_runner.h" | 15 #include "base/sequenced_task_runner.h" |
| 15 #include "base/single_thread_task_runner.h" | 16 #include "base/single_thread_task_runner.h" |
| 16 #include "base/strings/string_util.h" | 17 #include "base/strings/string_util.h" |
| 17 #include "base/strings/utf_string_conversions.h" | 18 #include "base/strings/utf_string_conversions.h" |
| 18 #include "base/threading/thread_task_runner_handle.h" | 19 #include "base/threading/thread_task_runner_handle.h" |
| 19 #include "build/build_config.h" | 20 #include "build/build_config.h" |
| 20 #include "chrome/browser/chrome_notification_types.h" | 21 #include "chrome/browser/chrome_notification_types.h" |
| 21 #include "chrome/browser/extensions/extension_service.h" | 22 #include "chrome/browser/extensions/extension_service.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 33 #include "components/prefs/pref_service.h" | 34 #include "components/prefs/pref_service.h" |
| 34 #include "content/public/browser/notification_service.h" | 35 #include "content/public/browser/notification_service.h" |
| 35 #include "content/public/browser/user_metrics.h" | 36 #include "content/public/browser/user_metrics.h" |
| 36 #include "extensions/browser/extension_prefs.h" | 37 #include "extensions/browser/extension_prefs.h" |
| 37 #include "extensions/browser/extension_registry.h" | 38 #include "extensions/browser/extension_registry.h" |
| 38 #include "extensions/browser/extension_system.h" | 39 #include "extensions/browser/extension_system.h" |
| 39 #include "extensions/browser/uninstall_reason.h" | 40 #include "extensions/browser/uninstall_reason.h" |
| 40 #include "extensions/common/extension.h" | 41 #include "extensions/common/extension.h" |
| 41 #include "extensions/common/extension_set.h" | 42 #include "extensions/common/extension_set.h" |
| 42 #include "ui/base/layout.h" | 43 #include "ui/base/layout.h" |
| 43 #include "ui/base/material_design/material_design_controller.h" | |
| 44 #include "ui/base/resource/resource_bundle.h" | 44 #include "ui/base/resource/resource_bundle.h" |
| 45 #include "ui/gfx/color_palette.h" | 45 #include "ui/gfx/color_palette.h" |
| 46 #include "ui/gfx/image/image_skia.h" | 46 #include "ui/gfx/image/image_skia.h" |
| 47 #include "ui/native_theme/common_theme.h" | 47 #include "ui/native_theme/common_theme.h" |
| 48 #include "ui/native_theme/native_theme.h" | 48 #include "ui/native_theme/native_theme.h" |
| 49 | 49 |
| 50 #if defined(ENABLE_EXTENSIONS) | 50 #if defined(ENABLE_EXTENSIONS) |
| 51 #include "extensions/browser/extension_registry_observer.h" | 51 #include "extensions/browser/extension_registry_observer.h" |
| 52 #endif | 52 #endif |
| 53 | 53 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 80 | 80 |
| 81 SkColor IncreaseLightness(SkColor color, double percent) { | 81 SkColor IncreaseLightness(SkColor color, double percent) { |
| 82 color_utils::HSL result; | 82 color_utils::HSL result; |
| 83 color_utils::SkColorToHSL(color, &result); | 83 color_utils::SkColorToHSL(color, &result); |
| 84 result.l += (1 - result.l) * percent; | 84 result.l += (1 - result.l) * percent; |
| 85 return color_utils::HSLToSkColor(result, SkColorGetA(color)); | 85 return color_utils::HSLToSkColor(result, SkColorGetA(color)); |
| 86 } | 86 } |
| 87 | 87 |
| 88 // Writes the theme pack to disk on a separate thread. | 88 // Writes the theme pack to disk on a separate thread. |
| 89 void WritePackToDiskCallback(BrowserThemePack* pack, | 89 void WritePackToDiskCallback(BrowserThemePack* pack, |
| 90 const base::FilePath& path) { | 90 const base::FilePath& directory) { |
| 91 base::FilePath path = directory.Append(chrome::kThemePackFilename); |
| 91 if (!pack->WriteToDisk(path)) | 92 if (!pack->WriteToDisk(path)) |
| 92 NOTREACHED() << "Could not write theme pack to disk"; | 93 NOTREACHED() << "Could not write theme pack to disk"; |
| 94 |
| 95 // Clean up any theme .pak that was generated during the Material Design |
| 96 // transitional period. |
| 97 // TODO(estade): remove this line in Q2 2017. |
| 98 base::DeleteFile(directory.AppendASCII("Cached Theme Material Design.pak"), |
| 99 false); |
| 93 } | 100 } |
| 94 | 101 |
| 95 // Heuristic to determine if color is grayscale. This is used to decide whether | 102 // Heuristic to determine if color is grayscale. This is used to decide whether |
| 96 // to use the colorful or white logo, if a theme fails to specify which. | 103 // to use the colorful or white logo, if a theme fails to specify which. |
| 97 bool IsColorGrayscale(SkColor color) { | 104 bool IsColorGrayscale(SkColor color) { |
| 98 const int kChannelTolerance = 9; | 105 const int kChannelTolerance = 9; |
| 99 int r = SkColorGetR(color); | 106 int r = SkColorGetR(color); |
| 100 int g = SkColorGetG(color); | 107 int g = SkColorGetG(color); |
| 101 int b = SkColorGetB(color); | 108 int b = SkColorGetB(color); |
| 102 int range = std::max(r, std::max(g, b)) - std::min(r, std::min(g, b)); | 109 int range = std::max(r, std::max(g, b)) - std::min(r, std::min(g, b)); |
| (...skipping 464 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 567 if (ShouldInitWithSystemTheme()) | 574 if (ShouldInitWithSystemTheme()) |
| 568 UseSystemTheme(); | 575 UseSystemTheme(); |
| 569 else | 576 else |
| 570 UseDefaultTheme(); | 577 UseDefaultTheme(); |
| 571 set_ready(); | 578 set_ready(); |
| 572 return; | 579 return; |
| 573 } | 580 } |
| 574 | 581 |
| 575 bool loaded_pack = false; | 582 bool loaded_pack = false; |
| 576 | 583 |
| 577 // If we don't have a file pack, we're updating from an old version, or the | 584 // If we don't have a file pack, we're updating from an old version. |
| 578 // pack was created for an alternative MaterialDesignController::Mode. | |
| 579 base::FilePath path = prefs->GetFilePath(prefs::kCurrentThemePackFilename); | 585 base::FilePath path = prefs->GetFilePath(prefs::kCurrentThemePackFilename); |
| 580 if (path != base::FilePath()) { | 586 if (path != base::FilePath()) { |
| 581 path = path.Append(ui::MaterialDesignController::IsModeMaterial() | 587 path = path.Append(chrome::kThemePackFilename); |
| 582 ? chrome::kThemePackMaterialDesignFilename | |
| 583 : chrome::kThemePackFilename); | |
| 584 SwapThemeSupplier(BrowserThemePack::BuildFromDataPack(path, current_id)); | 588 SwapThemeSupplier(BrowserThemePack::BuildFromDataPack(path, current_id)); |
| 585 if (theme_supplier_) | 589 if (theme_supplier_) |
| 586 loaded_pack = true; | 590 loaded_pack = true; |
| 587 } | 591 } |
| 588 | 592 |
| 589 if (loaded_pack) { | 593 if (loaded_pack) { |
| 590 content::RecordAction(UserMetricsAction("Themes.Loaded")); | 594 content::RecordAction(UserMetricsAction("Themes.Loaded")); |
| 591 set_ready(); | 595 set_ready(); |
| 592 } | 596 } |
| 593 // Else: wait for the extension service to be ready so that the theme pack | 597 // Else: wait for the extension service to be ready so that the theme pack |
| (...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 851 LOG(ERROR) << "Could not load theme."; | 855 LOG(ERROR) << "Could not load theme."; |
| 852 return; | 856 return; |
| 853 } | 857 } |
| 854 | 858 |
| 855 ExtensionService* service = | 859 ExtensionService* service = |
| 856 extensions::ExtensionSystem::Get(profile_)->extension_service(); | 860 extensions::ExtensionSystem::Get(profile_)->extension_service(); |
| 857 if (!service) | 861 if (!service) |
| 858 return; | 862 return; |
| 859 | 863 |
| 860 // Write the packed file to disk. | 864 // Write the packed file to disk. |
| 861 base::FilePath pack_path = | |
| 862 extension->path().Append(ui::MaterialDesignController::IsModeMaterial() | |
| 863 ? chrome::kThemePackMaterialDesignFilename | |
| 864 : chrome::kThemePackFilename); | |
| 865 service->GetFileTaskRunner()->PostTask( | 865 service->GetFileTaskRunner()->PostTask( |
| 866 FROM_HERE, | 866 FROM_HERE, base::Bind(&WritePackToDiskCallback, base::RetainedRef(pack), |
| 867 base::Bind(&WritePackToDiskCallback, base::RetainedRef(pack), pack_path)); | 867 extension->path())); |
| 868 | 868 |
| 869 // Save only the extension path. The packed file which matches the | 869 // Save only the extension path. The packed file will be loaded via |
| 870 // MaterialDesignController::Mode will be loaded via LoadThemePrefs(). | 870 // LoadThemePrefs(). |
| 871 SavePackName(extension->path()); | 871 SavePackName(extension->path()); |
| 872 SwapThemeSupplier(pack); | 872 SwapThemeSupplier(pack); |
| 873 } | 873 } |
| 874 | 874 |
| 875 #if BUILDFLAG(ENABLE_SUPERVISED_USERS) | 875 #if BUILDFLAG(ENABLE_SUPERVISED_USERS) |
| 876 bool ThemeService::IsSupervisedUser() const { | 876 bool ThemeService::IsSupervisedUser() const { |
| 877 return profile_->IsSupervised(); | 877 return profile_->IsSupervised(); |
| 878 } | 878 } |
| 879 | 879 |
| 880 void ThemeService::SetSupervisedUserTheme() { | 880 void ThemeService::SetSupervisedUserTheme() { |
| 881 SetCustomDefaultTheme(new SupervisedUserTheme); | 881 SetCustomDefaultTheme(new SupervisedUserTheme); |
| 882 } | 882 } |
| 883 #endif | 883 #endif |
| OLD | NEW |