fix: default to system accent color on invalid user color (#47800)

fix: default to system accent color on invalid user color"
This commit is contained in:
Shelley Vohr 2025-07-31 11:10:24 +02:00 committed by GitHub
commit e17cbc96e2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 38 additions and 41 deletions

View file

@ -28,7 +28,7 @@ bool IsHexFormatWithAlpha(const std::string& str) {
namespace electron {
SkColor ParseCSSColor(const std::string& color_string) {
std::optional<SkColor> ParseCSSColor(const std::string& color_string) {
// ParseCssColorString expects RGBA and we historically use ARGB
// so we need to convert before passing to ParseCssColorString.
std::string converted_color_str;
@ -42,7 +42,7 @@ SkColor ParseCSSColor(const std::string& color_string) {
SkColor color;
if (!content::ParseCssColorString(converted_color_str, &color))
color = SK_ColorWHITE;
return std::nullopt;
return color;
}

View file

@ -5,6 +5,7 @@
#ifndef ELECTRON_SHELL_COMMON_COLOR_UTIL_H_
#define ELECTRON_SHELL_COMMON_COLOR_UTIL_H_
#include <optional>
#include <string>
#include "third_party/skia/include/core/SkColor.h"
@ -22,7 +23,7 @@ namespace electron {
// Parses a CSS-style color string from hex, rgb(), rgba(),
// hsl(), hsla(), or color name formats.
SkColor ParseCSSColor(const std::string& color_string);
std::optional<SkColor> ParseCSSColor(const std::string& color_string);
// Convert color to RGB hex value like "#RRGGBB".
std::string ToRGBHex(SkColor color);

View file

@ -226,7 +226,7 @@ bool Converter<WrappedSkColor>::FromV8(v8::Isolate* isolate,
std::string str;
if (!gin::ConvertFromV8(isolate, val, &str))
return false;
*out = electron::ParseCSSColor(str);
*out = electron::ParseCSSColor(str).value_or(SK_ColorWHITE);
return true;
}