#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "chrome/browser/themes/browser_theme_pack.h"
#include <limits.h>
#include <stddef.h>
#include <limits>
#include <memory>
#include <optional>
#include <string_view>
#include <utility>
#include "base/containers/contains.h"
#include "base/containers/fixed_flat_set.h"
#include "base/containers/heap_array.h"
#include "base/containers/span.h"
#include "base/files/file.h"
#include "base/memory/ref_counted_memory.h"
#include "base/metrics/histogram_macros.h"
#include "base/no_destructor.h"
#include "base/numerics/safe_conversions.h"
#include "base/ranges/algorithm.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "base/task/thread_pool.h"
#include "base/threading/thread_restrictions.h"
#include "build/build_config.h"
#include "chrome/browser/themes/theme_properties.h"
#include "chrome/browser/ui/color/chrome_color_id.h"
#include "chrome/browser/ui/frame/window_frame_util.h"
#include "chrome/common/extensions/manifest_handlers/theme_handler.h"
#include "chrome/common/themes/autogenerated_theme_util.h"
#include "chrome/grit/theme_resources.h"
#include "components/crx_file/id_util.h"
#include "content/public/browser/browser_thread.h"
#include "third_party/skia/include/core/SkCanvas.h"
#include "third_party/skia/include/core/SkColor.h"
#include "ui/base/resource/data_pack.h"
#include "ui/color/color_mixer.h"
#include "ui/color/color_provider.h"
#include "ui/color/color_recipe.h"
#include "ui/color/color_transform.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/codec/png_codec.h"
#include "ui/gfx/color_analysis.h"
#include "ui/gfx/color_palette.h"
#include "ui/gfx/color_utils.h"
#include "ui/gfx/geometry/size_conversions.h"
#include "ui/gfx/geometry/skia_conversions.h"
#include "ui/gfx/image/canvas_image_source.h"
#include "ui/gfx/image/image.h"
#include "ui/gfx/image/image_skia.h"
#include "ui/gfx/image/image_skia_operations.h"
#include "ui/gfx/image/image_skia_rep.h"
BrowserThread;
Extension;
TP;
enum BrowserThemePack::PersistentID : int { … };
namespace {
PRS;
constexpr int kTallestTabHeight = …;
constexpr int kTallestFrameHeight = …;
const int kThemePackVersion = …;
const int kMaxID = …;
const int kHeaderID = …;
const int kTintsID = …;
const int kColorsID = …;
const int kDisplayPropertiesID = …;
const int kSourceImagesID = …;
const int kScaleFactorsID = …;
struct PersistingImagesTable { … };
constexpr PersistingImagesTable kPersistingImages[] = …;
BrowserThemePack::PersistentID GetPersistentIDByName(const std::string& key) { … }
BrowserThemePack::PersistentID GetPersistentIDByIDR(int idr) { … }
bool InputScalesValid(std::string_view input,
base::span<ui::ResourceScaleFactor> expected) { … }
std::string GetResourceScaleFactorsAsString(
base::span<const ui::ResourceScaleFactor> scale_factors) { … }
struct StringToIntTable { … };
const StringToIntTable kTintTable[] = …;
const size_t kTintTableLength = …;
constexpr StringToIntTable kOverwritableColorTable[] = …;
constexpr size_t kOverwritableColorTableLength = …;
constexpr int kNonOverwritableColorTable[] = …;
constexpr size_t kNonOverwritableColorTableLength = …;
constexpr size_t kColorsArrayLength = …;
const StringToIntTable kDisplayProperties[] = …;
const size_t kDisplayPropertiesSize = …;
int GetIntForString(const std::string& key,
const StringToIntTable* table,
size_t table_length) { … }
struct CropEntry { … };
const struct CropEntry kImagesToCrop[] = …;
const BrowserThemePack::PersistentID kPreloadIDs[] = …;
scoped_refptr<base::RefCountedMemory> ReadFileData(const base::FilePath& path) { … }
SkBitmap CreateLowQualityResizedBitmap(
const SkBitmap& source_bitmap,
ui::ResourceScaleFactor source_scale_factor,
ui::ResourceScaleFactor desired_scale_factor) { … }
class ThemeImageSource : public gfx::ImageSkiaSource { … };
class ThemeImagePngSource : public gfx::ImageSkiaSource { … };
class TabBackgroundImageSource : public gfx::CanvasImageSource { … };
class ControlButtonBackgroundImageSource : public gfx::CanvasImageSource { … };
bool IsColorGrayscale(SkColor color) { … }
constexpr float kMinOmniboxToolbarContrast = …;
ui::ColorTransform ChooseOmniboxBgBlendTarget() { … }
}
BrowserThemePack::~BrowserThemePack() { … }
void BrowserThemePack::SetColor(int id, SkColor color) { … }
void BrowserThemePack::SetColorIfUnspecified(int id, SkColor color) { … }
void BrowserThemePack::SetTint(int id, color_utils::HSL tint) { … }
void BrowserThemePack::SetDisplayProperty(int id, int value) { … }
SkColor BrowserThemePack::ComputeImageColor(const gfx::Image& image,
int height) { … }
void BrowserThemePack::BuildFromExtension(
const extensions::Extension* extension,
BrowserThemePack* pack) { … }
scoped_refptr<BrowserThemePack> BrowserThemePack::BuildFromDataPack(
const base::FilePath& path, const std::string& expected_id) { … }
bool BrowserThemePack::IsPersistentImageID(int id) { … }
void BrowserThemePack::BuildFromColor(SkColor color, BrowserThemePack* pack) { … }
void BrowserThemePack::BuildFromColors(AutogeneratedThemeColors colors,
BrowserThemePack* pack) { … }
void BrowserThemePack::BuildFromWebAppColors(SkColor theme_color,
SkColor background_color,
BrowserThemePack* pack) { … }
BrowserThemePack::BrowserThemePack(ThemeType theme_type)
: … { … }
bool BrowserThemePack::WriteToDisk(const base::FilePath& path) const { … }
bool BrowserThemePack::GetTint(int id, color_utils::HSL* hsl) const { … }
bool BrowserThemePack::GetColor(int id, SkColor* color) const { … }
bool BrowserThemePack::GetDisplayProperty(int id, int* result) const { … }
gfx::Image BrowserThemePack::GetImageNamed(int idr_id) const { … }
base::RefCountedMemory* BrowserThemePack::GetRawData(
int idr_id,
ui::ResourceScaleFactor scale_factor) const { … }
bool BrowserThemePack::HasCustomImage(int idr_id) const { … }
void BrowserThemePack::AddColorMixers(ui::ColorProvider* provider,
const ui::ColorProviderKey& key) const { … }
void BrowserThemePack::AdjustThemePack() { … }
void BrowserThemePack::InitEmptyPack() { … }
void BrowserThemePack::InitEmptyPackFromColors() { … }
void BrowserThemePack::InitHeader() { … }
void BrowserThemePack::InitTints() { … }
void BrowserThemePack::InitColors() { … }
void BrowserThemePack::InitDisplayProperties() { … }
void BrowserThemePack::InitSourceImages() { … }
void BrowserThemePack::FinalizePackFromColors() { … }
void BrowserThemePack::SetHeaderId(const Extension* extension) { … }
void BrowserThemePack::SetTintsFromJSON(const base::Value::Dict* tints_value) { … }
void BrowserThemePack::SetColorsFromJSON(
const base::Value::Dict* colors_value) { … }
void BrowserThemePack::ReadColorsFromJSON(const base::Value::Dict& colors_value,
std::map<int, SkColor>* temp_colors) { … }
void BrowserThemePack::SetDisplayPropertiesFromJSON(
const base::Value::Dict* display_properties_value) { … }
void BrowserThemePack::ParseImageNamesFromJSON(
const base::Value::Dict* images_value,
const base::FilePath& images_path,
FilePathMap* file_paths) const { … }
void BrowserThemePack::AddFileAtScaleToMap(const std::string& image_name,
ui::ResourceScaleFactor scale_factor,
const base::FilePath& image_path,
FilePathMap* file_paths) const { … }
void BrowserThemePack::BuildSourceImagesArray(const FilePathMap& file_paths) { … }
bool BrowserThemePack::LoadRawBitmapsTo(
const FilePathMap& file_paths,
ImageCache* image_cache) { … }
void BrowserThemePack::CropImages(ImageCache* images) const { … }
void BrowserThemePack::SetFrameAndToolbarRelatedColors() { … }
void BrowserThemePack::CreateToolbarImageAndColors(ImageCache* images) { … }
void BrowserThemePack::CreateFrameImagesAndColors(ImageCache* images) { … }
void BrowserThemePack::GenerateFrameColorsFromTints() { … }
void BrowserThemePack::GenerateWindowControlButtonColor(ImageCache* images) { … }
void BrowserThemePack::CreateTabBackgroundImagesAndColors(ImageCache* images) { … }
void BrowserThemePack::GenerateMissingNtpColors() { … }
void BrowserThemePack::RepackImages(const ImageCache& images,
RawImages* reencoded_images) const { … }
void BrowserThemePack::MergeImageCaches(
const ImageCache& source, ImageCache* destination) const { … }
void BrowserThemePack::AddRawImagesTo(const RawImages& images,
RawDataForWriting* out) const { … }
color_utils::HSL BrowserThemePack::GetTintInternal(int id) const { … }
int BrowserThemePack::GetRawIDByPersistentID(
PersistentID prs_id,
ui::ResourceScaleFactor scale_factor) const { … }
bool BrowserThemePack::GetScaleFactorFromManifestKey(
const std::string& key,
ui::ResourceScaleFactor* scale_factor) const { … }
void BrowserThemePack::GenerateRawImageForAllSupportedScales(
PersistentID prs_id) { … }