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

fix: default to system accent color on invalid user color"

Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com>
Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>
This commit is contained in:
trop[bot]
2025-07-08 15:21:44 +02:00
committed by GitHub
parent 130f00dfcd
commit 0b77096f2a
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;
}