Files
electron/shell/browser/ui/devtools_ui_theme_data_source.cc
electron-roller[bot] b93642678c chore: bump chromium to 149.0.7798.0 (main) (#50814)
* chore: bump chromium in DEPS to 149.0.7779.0

* chore: bump chromium in DEPS to 149.0.7781.0

* 7726883: Add secondary label support to SimpleMenuModel and update views_examples

Ref: https://chromium-review.googlesource.com/c/chromium/src/+/7726883

Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>

* chore: update patches (trivial only)

Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>

* fix: IWYU for base/logging.h

Upstream is removing transitive includes of base/logging.h as part of
crbug.com/499476145. Several CLs landed in this roll that required
adding explicit includes across Electron source and patches.

Ref: https://chromium-review.googlesource.com/c/chromium/src/+/7732103
Ref: https://chromium-review.googlesource.com/c/chromium/src/+/7735571

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* 7732482: [bedrock] Create BrowserProcess setters for system tray icons

Ref: https://chromium-review.googlesource.com/c/chromium/src/+/7732482

Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>

* chore: update patches (trivial only)

Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>

* 7739543: Add RenderWidgetHostView::HasSavedFrame

Ref: https://chromium-review.googlesource.com/c/chromium/src/+/7739543

Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>

* chore: bump chromium in DEPS to 149.0.7783.0

* chore: bump chromium in DEPS to 149.0.7789.0

* chore: update patches (trivial only)

* 7703728: DedicatedWorker: Enforce same-origin check for main script fetch.

Ref: https://chromium-review.googlesource.com/c/chromium/src/+/7703728

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* 7720140: Remove GetPrefServiceForContext from ExtensionsBrowserClient

Ref: https://chromium-review.googlesource.com/c/chromium/src/+/7720140

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* chore: update patches (trivial only)

* 7728375: Disable reentrancy by default except for Android and iOS

Upstream changed the default ObserverList reentrancy policy from
kAllowReentrancy to kDisallowReentrancy. Electron's observer lists
are re-entered when macOS AppKit delivers synchronous window
notifications (e.g. windowDidResignMain: during windowDidChangeOcclusionState:)
because JS event handlers can trigger window state changes mid-iteration.

Explicitly opt into kAllowReentrancy for now. A follow-up should
convert synchronous Emit calls in window observer callbacks to
EmitEventSoon to eliminate the reentrancy.

Ref: https://chromium-review.googlesource.com/c/chromium/src/+/7728375

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* chore: bump chromium in DEPS to 149.0.7791.1

* chore: update patches (trivial only)

* 7696481: [pdf] Rename PdfViewerStreamManager to MimeHandlerStreamManager

Ref: https://chromium-review.googlesource.com/c/chromium/src/+/7696481

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* 7745796: Printing: Remove parameter from ShowScriptedPrintPreview() interface

Ref: https://chromium-review.googlesource.com/c/chromium/src/+/7745796

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* 7688714: [Lens / Cookies] Grant secure cookie exemptions for Lens side panel

Ref: https://chromium-review.googlesource.com/c/chromium/src/+/7688714

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* 7752609: don't show glic button for non-normal BWIs.

Ref: https://chromium-review.googlesource.com/c/chromium/src/+/7752609

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* 7749860: [media] Remove VideoFrame::WrapSharedImage with coded_size

Ref: https://chromium-review.googlesource.com/c/chromium/src/+/7749860

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* chore: bump chromium in DEPS to 149.0.7793.0

* chore: bump chromium in DEPS to 149.0.7795.0

* chore: bump chromium in DEPS to 149.0.7797.0

* chore: update patches

* chore: remove upstreamed patches

- fix_pass_trigger_for_global_shortcuts_on_wayland.patch: https://chromium-review.googlesource.com/c/chromium/src/+/7620219
- gin_mark_argumentholder_as_cppgc_stack_allocated.patch: https://chromium-review.googlesource.com/c/chromium/src/+/7728865

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* chore: bump chromium in DEPS to 149.0.7798.0

* chore: update filenames.libcxx.gni

* 7760061: Reland Reland Add a client-side decorated frame view for non-browser widgets on Linux

Ref: https://chromium-review.googlesource.com/c/chromium/src/+/7760061

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* 7760945: Rename WebString::UTF8ConversionMode to Utf8ConversionMode

Ref: https://chromium-review.googlesource.com/c/chromium/src/+/7760945

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* chore: update patches

* chore: remove upstreamed patches

- patches/devtools_frontend/fix_context_selector_not_showing_execution_contexts.patch: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/7761316

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* 7719004: [extensions] Gate dict-format mime_types_handler parsing

Ref: https://chromium-review.googlesource.com/c/chromium/src/+/7719004

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* 7716681: [pdf] Introduce MimeHandlerStreamDelegate and plumb ownership

Ref: https://chromium-review.googlesource.com/c/chromium/src/+/7716681

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* 7725342: Rename WebString::FromUTF8 to FromUtf8 in Blink

Ref: https://chromium-review.googlesource.com/c/chromium/src/+/7725342

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* 7615475: Add a native frame view for non-browser widgets on Linux

Ref: https://chromium-review.googlesource.com/c/chromium/src/+/7615475

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* 7735248: Move ManifestV2ExperimentManager to //extensions

Ref: https://chromium-review.googlesource.com/c/chromium/src/+/7735248

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* 7725187: linux: set env FC_FONTATIONS and EGL_PLATFORM early

Move Ozone pre-init from ElectronBrowserMainParts::PreEarlyInitialization()
to ElectronMainDelegate::PreSandboxStartup() to match upstream's rename
and relocation. The call has to run before threads are created.

Ref: https://chromium-review.googlesource.com/c/chromium/src/+/7725187

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* 7743280: Introduce client ID for network throttling conditions.

Ref: https://chromium-review.googlesource.com/c/chromium/src/+/7743280

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* chore: disable ml-kem node test incompatible with BoringSSL

test-crypto-pqc-key-objects-ml-kem: BoringSSL's ML-KEM support is
inconsistent with the test's OpenSSL-version-based assumptions.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* test: update V8 serialization wire format version to 16

V8 14.9 (Chromium 149) bumped the serialization wire format from
version 15 to 16. Update the hardcoded expected bytes in the
test-v8-serdes.js test.

Remove this patch once upstream Node.js catches up via its next
V8 roll.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com>
Co-authored-by: Samuel Maddock <samuelmaddock@electronjs.org>
Co-authored-by: Claude <svc-devxp-claude@slack-corp.com>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-authored-by: clavin <clavin@electronjs.org>
2026-04-23 16:32:10 -05:00

222 lines
8.7 KiB
C++

// Copyright (c) 2024 The Chromium Authors. All rights reserved.
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#include "shell/browser/ui/devtools_ui_theme_data_source.h"
#include <string>
#include <string_view>
#include <utility>
#include "base/logging.h"
#include "base/memory/ref_counted_memory.h"
#include "base/metrics/histogram_functions.h"
#include "base/strings/strcat.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_split.h"
#include "base/strings/string_util.h"
#include "chrome/browser/ui/color/chrome_color_id.h"
#include "chrome/browser/ui/color/chrome_color_provider_utils.h"
#include "chrome/common/webui_url_constants.h"
#include "content/public/browser/devtools_frontend_host.h"
#include "content/public/browser/url_data_source.h"
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_ui.h"
#include "net/base/url_util.h"
#include "third_party/abseil-cpp/absl/strings/str_format.h"
#include "ui/base/webui/web_ui_util.h"
#include "ui/color/color_provider.h"
#include "ui/color/color_provider_utils.h"
namespace electron {
namespace {
GURL GetThemeUrl(const std::string& path) {
return GURL(std::string(content::kChromeDevToolsScheme) +
url::kStandardSchemeSeparator +
std::string(chrome::kChromeUIThemeHost) + "/" + path);
}
scoped_refptr<base::RefCountedMemory> CreateNotFoundResponse() {
const char kHttpNotFound[] = "HTTP/1.1 404 Not Found\n\n";
return base::MakeRefCounted<base::RefCountedStaticMemory>(
base::byte_span_from_cstring(kHttpNotFound));
}
std::string GetMimeTypeForUrl(const GURL& url) {
std::string filename = url.ExtractFileName();
if (base::EndsWith(filename, ".html", base::CompareCase::INSENSITIVE_ASCII)) {
return "text/html";
} else if (base::EndsWith(filename, ".css",
base::CompareCase::INSENSITIVE_ASCII)) {
return "text/css";
} else if (base::EndsWith(filename, ".js",
base::CompareCase::INSENSITIVE_ASCII) ||
base::EndsWith(filename, ".mjs",
base::CompareCase::INSENSITIVE_ASCII)) {
return "application/javascript";
} else if (base::EndsWith(filename, ".png",
base::CompareCase::INSENSITIVE_ASCII)) {
return "image/png";
} else if (base::EndsWith(filename, ".map",
base::CompareCase::INSENSITIVE_ASCII)) {
return "application/json";
} else if (base::EndsWith(filename, ".ts",
base::CompareCase::INSENSITIVE_ASCII)) {
return "application/x-typescript";
} else if (base::EndsWith(filename, ".gif",
base::CompareCase::INSENSITIVE_ASCII)) {
return "image/gif";
} else if (base::EndsWith(filename, ".svg",
base::CompareCase::INSENSITIVE_ASCII)) {
return "image/svg+xml";
} else if (base::EndsWith(filename, ".manifest",
base::CompareCase::INSENSITIVE_ASCII)) {
return "text/cache-manifest";
}
return "text/html";
}
} // namespace
std::string ThemeDataSource::GetSource() {
// kChromeUIThemeHost
return chrome::kChromeUIThemeHost;
}
void ThemeDataSource::StartDataRequest(
const GURL& url,
const content::WebContents::Getter& wc_getter,
GotDataCallback callback) {
// TODO(crbug.com/40050262): Simplify usages of |path| since |url| is
// available.
const std::string path = content::URLDataSource::URLToRequestPath(url);
// Default scale factor if not specified.
float scale = 1.0f;
// All frames by default if not specified.
int frame = -1;
std::string parsed_path;
webui::ParsePathAndImageSpec(GetThemeUrl(path), &parsed_path, &scale, &frame);
// kColorsCssPath should stay consistent with COLORS_CSS_SELECTOR in
// colors_css_updater.js.
constexpr std::string_view kColorsCssPath = "colors.css";
if (parsed_path == kColorsCssPath) {
SendColorsCss(url, wc_getter, std::move(callback));
return;
}
std::move(callback).Run(CreateNotFoundResponse());
}
std::string ThemeDataSource::GetMimeType(const GURL& url) {
return GetMimeTypeForUrl(url);
}
void ThemeDataSource::SendColorsCss(
const GURL& url,
const content::WebContents::Getter& wc_getter,
content::URLDataSource::GotDataCallback callback) {
const ui::ColorProvider& color_provider = wc_getter.Run()->GetColorProvider();
std::string sets_param;
std::vector<std::string_view> color_id_sets;
bool generate_rgb_vars = false;
std::string generate_rgb_vars_query_value;
if (net::GetValueForKeyInQuery(url, "generate_rgb_vars",
&generate_rgb_vars_query_value)) {
generate_rgb_vars =
base::ToLowerASCII(generate_rgb_vars_query_value) == "true";
}
bool shadow_host = false;
std::string shadow_host_query_value;
if (net::GetValueForKeyInQuery(url, "shadow_host",
&shadow_host_query_value)) {
shadow_host = base::ToLowerASCII(shadow_host_query_value) == "true";
}
if (!net::GetValueForKeyInQuery(url, "sets", &sets_param)) {
LOG(ERROR)
<< "colors.css requires a 'sets' query parameter to specify the "
"color "
"id sets returned e.g chrome://theme/colors.css?sets=ui,chrome";
std::move(callback).Run(nullptr);
return;
}
color_id_sets = base::SplitStringPiece(sets_param, ",", base::TRIM_WHITESPACE,
base::SPLIT_WANT_ALL);
using ColorIdCSSCallback = base::RepeatingCallback<std::string(ui::ColorId)>;
auto generate_color_mapping =
[&color_id_sets, &color_provider, &generate_rgb_vars](
std::string set_name, ui::ColorId start, ui::ColorId end,
ColorIdCSSCallback color_css_name) {
// Only return these mappings if specified in the query parameter.
auto it = std::ranges::find(color_id_sets, set_name);
if (it == color_id_sets.end()) {
return std::string();
}
color_id_sets.erase(it);
std::string css_string;
for (ui::ColorId id = start; id < end; ++id) {
const SkColor color = color_provider.GetColor(id);
std::string css_id_to_color_mapping =
absl::StrFormat("%s:%s;", color_css_name.Run(id),
ui::ConvertSkColorToCSSColor(color));
base::StrAppend(&css_string, {css_id_to_color_mapping});
if (generate_rgb_vars) {
// Also generate a r,g,b string for each color so apps can construct
// colors with their own opacities in css.
const std::string css_rgb_color_str =
color_utils::SkColorToRgbString(color);
const std::string css_id_to_rgb_color_mapping = absl::StrFormat(
"%s-rgb:%s;", color_css_name.Run(id), css_rgb_color_str);
base::StrAppend(&css_string, {css_id_to_rgb_color_mapping});
}
}
return css_string;
};
// Convenience lambda for wrapping
// |ConvertColorProviderColorIdToCSSColorId|.
auto generate_color_provider_mapping = [&generate_color_mapping](
std::string set_name,
ui::ColorId start, ui::ColorId end,
std::string (*color_id_name)(
ui::ColorId)) {
auto color_id_to_css_name = base::BindRepeating(
[](std::string (*color_id_name)(ui::ColorId), ui::ColorId id) {
return ui::ConvertColorProviderColorIdToCSSColorId(color_id_name(id));
},
color_id_name);
return generate_color_mapping(set_name, start, end, color_id_to_css_name);
};
std::string css_selector;
if (shadow_host) {
css_selector = ":host";
} else {
// This selector requires more specificity than other existing CSS
// selectors that define variables. We increase the specificity by adding
// a pseudoselector.
css_selector = "html:not(#z)";
}
std::string css_string = base::StrCat(
{css_selector, "{", "--user-color-source: baseline-default;",
generate_color_provider_mapping("ui", ui::kUiColorsStart,
ui::kUiColorsEnd, ui::ColorIdName),
generate_color_provider_mapping("chrome", kChromeColorsStart,
kChromeColorsEnd, &ChromeColorIdName),
"}"});
if (!color_id_sets.empty()) {
LOG(ERROR) << "Unrecognized color set(s) specified for "
"chrome://theme/colors.css: "
<< base::JoinString(color_id_sets, ",");
std::move(callback).Run(nullptr);
return;
}
std::move(callback).Run(
base::MakeRefCounted<base::RefCountedString>(std::move(css_string)));
}
} // namespace electron