Compare commits

...

4 Commits

Author SHA1 Message Date
Marshall Greenblatt fae4a6f0bd views: Support themes for Alloy BrowserView in Chrome Window (see #3681)
To test:
- Run `cefclient --enable-chrome-runtime --use-alloy-style
                 --use-chrome-style-window [--background-color=green]`
- OS and Chrome theme changes behave as expected.
2024-05-03 17:27:28 -04:00
Marshall Greenblatt 91ba12468b chrome: Support CefResourceBundleHandler (see #3685) 2024-05-03 13:29:24 -04:00
Marshall Greenblatt 739021e4a8 chrome: Support CefSettings logging config (see #3685)
Also enables logging by default for Release builds (previously
required the `--enable-logging` flag). Logging can still be
disabled by passing the `--disable-logging` flag.
2024-05-03 13:22:19 -04:00
Marshall Greenblatt 853ea8846a chrome: Support CefSettings path config (see #3685) 2024-05-03 13:22:02 -04:00
15 changed files with 622 additions and 109 deletions

View File

@ -118,6 +118,14 @@ void ChromeContentBrowserClientCef::AppendExtraCommandLineSwitches(
// Propagate the following switches to all command lines (along with any
// associated values) if present in the browser command line.
static const char* const kSwitchNames[] = {
#if BUILDFLAG(IS_MAC)
switches::kFrameworkDirPath,
switches::kMainBundlePath,
#endif
switches::kLocalesDirPath,
switches::kLogItems,
switches::kLogSeverity,
switches::kResourcesDirPath,
switches::kUserAgentProductAndVersion,
};
command_line->CopySwitchesFrom(*browser_cmd, kSwitchNames);
@ -125,6 +133,19 @@ void ChromeContentBrowserClientCef::AppendExtraCommandLineSwitches(
const std::string& process_type =
command_line->GetSwitchValueASCII(switches::kProcessType);
#if BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_MAC)
if (process_type == switches::kZygoteProcess &&
browser_cmd->HasSwitch(switches::kBrowserSubprocessPath)) {
// Force use of the sub-process executable path for the zygote process.
const base::FilePath& subprocess_path =
browser_cmd->GetSwitchValuePath(switches::kBrowserSubprocessPath);
if (!subprocess_path.empty()) {
command_line->SetProgram(subprocess_path);
}
}
#endif
if (process_type == switches::kRendererProcess) {
// Propagate the following switches to the renderer command line (along with
// any associated values) if present in the browser command line.

View File

@ -9,6 +9,7 @@
#include "libcef/browser/views/window_view.h"
#include "chrome/browser/themes/theme_service.h"
#include "chrome/browser/themes/theme_service_factory.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/views/frame/browser_view.h"
@ -22,6 +23,10 @@
ChromeBrowserFrame::ChromeBrowserFrame(CefWindowView* window_view)
: window_view_(window_view) {}
ChromeBrowserFrame::~ChromeBrowserFrame() {
DCHECK(associated_profiles_.empty());
}
void ChromeBrowserFrame::Init(BrowserView* browser_view,
std::unique_ptr<Browser> browser) {
DCHECK(browser_view);
@ -64,17 +69,71 @@ void ChromeBrowserFrame::Initialized() {
#endif
}
void ChromeBrowserFrame::AddAssociatedProfile(Profile* /*profile*/) {
// Calls ThemeChanged().
UserChangedTheme(BrowserThemeChangeType::kBrowserTheme);
void ChromeBrowserFrame::AddAssociatedProfile(Profile* profile) {
DCHECK(profile);
// Always call ThemeChanged() when the Chrome style BrowserView is added.
bool call_theme_changed =
browser_view_ && browser_view_->GetProfile() == profile;
ProfileMap::iterator it = associated_profiles_.find(profile);
if (it != associated_profiles_.end()) {
// Another instance of a known Profile.
(it->second)++;
} else {
auto* current_profile = GetThemeProfile();
associated_profiles_.insert(std::make_pair(profile, 1));
if (auto* theme_service = ThemeServiceFactory::GetForProfile(profile)) {
theme_service->AddObserver(this);
}
// Potentially switching to a different theme.
call_theme_changed |= GetThemeProfile() != current_profile;
}
if (call_theme_changed) {
// Calls ThemeChanged().
UserChangedTheme(BrowserThemeChangeType::kBrowserTheme);
}
}
void ChromeBrowserFrame::RemoveAssociatedProfile(Profile* /*profile*/) {}
void ChromeBrowserFrame::RemoveAssociatedProfile(Profile* profile) {
DCHECK(profile);
ProfileMap::iterator it = associated_profiles_.find(profile);
if (it == associated_profiles_.end()) {
DCHECK(false); // Not reached.
return;
}
if (--(it->second) > 0) {
// More instances of the Profile exist.
return;
}
auto* current_profile = GetThemeProfile();
associated_profiles_.erase(it);
if (auto* theme_service = ThemeServiceFactory::GetForProfile(profile)) {
theme_service->RemoveObserver(this);
}
auto* new_profile = GetThemeProfile();
if (new_profile != current_profile) {
// Switching to a different theme.
NotifyThemeColorsChanged(/*chrome_theme=*/!!new_profile);
}
}
Profile* ChromeBrowserFrame::GetThemeProfile() const {
// Always prefer the Browser Profile, if any.
if (browser_view_) {
return browser_view_->GetProfile();
}
if (!associated_profiles_.empty()) {
return associated_profiles_.begin()->first;
}
return nullptr;
}
@ -148,6 +207,31 @@ void ChromeBrowserFrame::OnNativeThemeUpdated(ui::NativeTheme* observed_theme) {
native_theme_change_ = false;
}
ui::ColorProviderKey ChromeBrowserFrame::GetColorProviderKey() const {
if (browser_view_) {
// Use the default Browser implementation.
return BrowserFrame::GetColorProviderKey();
}
const auto& widget_key = Widget::GetColorProviderKey();
if (auto* profile = GetThemeProfile()) {
return CefWidget::GetColorProviderKey(widget_key, profile);
}
return widget_key;
}
void ChromeBrowserFrame::OnThemeChanged() {
if (browser_view_) {
// Ignore these notifications if we have a Browser.
return;
}
// When the Chrome theme changes, the NativeTheme may also change.
SelectNativeTheme();
NotifyThemeColorsChanged(/*chrome_theme=*/true);
}
void ChromeBrowserFrame::OnColorProviderCacheResetMissed() {
// Ignore calls during Widget::Init().
if (!initialized_) {

View File

@ -6,10 +6,13 @@
#define CEF_LIBCEF_BROWSER_CHROME_VIEWS_CHROME_BROWSER_FRAME_H_
#pragma once
#include <map>
#include "libcef/browser/views/color_provider_tracker.h"
#include "libcef/browser/views/widget.h"
#include "base/memory/weak_ptr.h"
#include "chrome/browser/themes/theme_service_observer.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/views/frame/browser_frame.h"
@ -96,9 +99,11 @@ class CefWindowView;
// CefWindowView::CreateWidget() when the Chrome runtime is enabled.
class ChromeBrowserFrame : public BrowserFrame,
public CefWidget,
public CefColorProviderTracker::Observer {
public CefColorProviderTracker::Observer,
public ThemeServiceObserver {
public:
explicit ChromeBrowserFrame(CefWindowView* window_view);
~ChromeBrowserFrame() override;
ChromeBrowserFrame(const ChromeBrowserFrame&) = delete;
ChromeBrowserFrame& operator=(const ChromeBrowserFrame&) = delete;
@ -131,6 +136,10 @@ class ChromeBrowserFrame : public BrowserFrame,
// ui::NativeThemeObserver methods:
void OnNativeThemeUpdated(ui::NativeTheme* observed_theme) override;
ui::ColorProviderKey GetColorProviderKey() const override;
// ThemeServiceObserver methods:
void OnThemeChanged() override;
BrowserView* browser_view() const { return browser_view_; }
@ -146,6 +155,10 @@ class ChromeBrowserFrame : public BrowserFrame,
bool initialized_ = false;
bool native_theme_change_ = false;
// Map of Profile* to count.
using ProfileMap = std::map<Profile*, size_t>;
ProfileMap associated_profiles_;
CefColorProviderTracker color_provider_tracker_{this};
base::WeakPtrFactory<ChromeBrowserFrame> weak_ptr_factory_{this};

View File

@ -9,6 +9,27 @@
#include "libcef/browser/views/widget_impl.h"
#include "libcef/browser/views/window_impl.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/themes/theme_service.h"
#include "chrome/browser/themes/theme_service_factory.h"
namespace {
ui::ColorProviderKey::SchemeVariant GetSchemeVariant(
ui::mojom::BrowserColorVariant color_variant) {
using BCV = ui::mojom::BrowserColorVariant;
using SV = ui::ColorProviderKey::SchemeVariant;
static constexpr auto kSchemeVariantMap = base::MakeFixedFlatMap<BCV, SV>({
{BCV::kTonalSpot, SV::kTonalSpot},
{BCV::kNeutral, SV::kNeutral},
{BCV::kVibrant, SV::kVibrant},
{BCV::kExpressive, SV::kExpressive},
});
return kSchemeVariantMap.at(color_variant);
}
} // namespace
// static
CefWidget* CefWidget::Create(CefWindowView* window_view) {
if (window_view->IsChromeStyle()) {
@ -30,3 +51,60 @@ CefWidget* CefWidget::GetForWidget(views::Widget* widget) {
}
return nullptr;
}
// static
ui::ColorProviderKey CefWidget::GetColorProviderKey(
const ui::ColorProviderKey& widget_key,
Profile* profile) {
// Based on BrowserFrame::GetColorProviderKey.
auto key = widget_key;
const auto* theme_service = ThemeServiceFactory::GetForProfile(profile);
CHECK(theme_service);
// color_mode.
[&key, theme_service]() {
const auto browser_color_scheme = theme_service->GetBrowserColorScheme();
if (browser_color_scheme != ThemeService::BrowserColorScheme::kSystem) {
key.color_mode =
browser_color_scheme == ThemeService::BrowserColorScheme::kLight
? ui::ColorProviderKey::ColorMode::kLight
: ui::ColorProviderKey::ColorMode::kDark;
}
}();
// user_color.
// Device theme retains the user_color from `Widget`.
if (!theme_service->UsingDeviceTheme()) {
if (theme_service->UsingAutogeneratedTheme()) {
key.user_color = theme_service->GetAutogeneratedThemeColor();
} else if (auto user_color = theme_service->GetUserColor()) {
key.user_color = user_color;
}
}
// user_color_source.
if (theme_service->UsingDeviceTheme()) {
key.user_color_source = ui::ColorProviderKey::UserColorSource::kAccent;
} else if (theme_service->GetIsGrayscale()) {
key.user_color_source = ui::ColorProviderKey::UserColorSource::kGrayscale;
} else if (theme_service->GetIsBaseline()) {
key.user_color_source = ui::ColorProviderKey::UserColorSource::kBaseline;
} else {
CHECK(key.user_color.has_value());
key.user_color_source = ui::ColorProviderKey::UserColorSource::kAccent;
}
// scheme_variant.
ui::mojom::BrowserColorVariant color_variant =
theme_service->GetBrowserColorVariant();
if (!theme_service->UsingDeviceTheme() &&
color_variant != ui::mojom::BrowserColorVariant::kSystem) {
key.scheme_variant = GetSchemeVariant(color_variant);
}
// frame_type.
key.frame_type = ui::ColorProviderKey::FrameType::kNative;
return key;
}

View File

@ -6,6 +6,8 @@
#define CEF_LIBCEF_BROWSER_VIEWS_WIDGET_H_
#pragma once
#include "ui/color/color_provider_key.h"
class CefWindowView;
class Profile;
@ -42,7 +44,6 @@ class CefWidget {
// Track all Profiles associated with this Widget. Called from
// CefBrowserViewImpl::AddedToWidget and DisassociateFromWidget.
// |profile| is only used with the Alloy runtime.
virtual void AddAssociatedProfile(Profile* profile) = 0;
virtual void RemoveAssociatedProfile(Profile* profile) = 0;
@ -59,6 +60,10 @@ class CefWidget {
protected:
virtual ~CefWidget() = default;
static ui::ColorProviderKey GetColorProviderKey(
const ui::ColorProviderKey& widget_key,
Profile* profile);
};
#endif // CEF_LIBCEF_BROWSER_VIEWS_WIDGET_H_

View File

@ -16,23 +16,6 @@
#include "ui/linux/linux_ui.h"
#endif
namespace {
ui::ColorProviderKey::SchemeVariant GetSchemeVariant(
ui::mojom::BrowserColorVariant color_variant) {
using BCV = ui::mojom::BrowserColorVariant;
using SV = ui::ColorProviderKey::SchemeVariant;
static constexpr auto kSchemeVariantMap = base::MakeFixedFlatMap<BCV, SV>({
{BCV::kTonalSpot, SV::kTonalSpot},
{BCV::kNeutral, SV::kNeutral},
{BCV::kVibrant, SV::kVibrant},
{BCV::kExpressive, SV::kExpressive},
});
return kSchemeVariantMap.at(color_variant);
}
} // namespace
CefWidgetImpl::CefWidgetImpl(CefWindowView* window_view)
: window_view_(window_view) {}
@ -157,62 +140,11 @@ void CefWidgetImpl::OnNativeThemeUpdated(ui::NativeTheme* observed_theme) {
}
ui::ColorProviderKey CefWidgetImpl::GetColorProviderKey() const {
auto* profile = GetThemeProfile();
if (!profile) {
return Widget::GetColorProviderKey();
const auto& widget_key = Widget::GetColorProviderKey();
if (auto* profile = GetThemeProfile()) {
return CefWidget::GetColorProviderKey(widget_key, profile);
}
// Based on BrowserFrame::GetColorProviderKey.
auto key = Widget::GetColorProviderKey();
const auto* theme_service = ThemeServiceFactory::GetForProfile(profile);
CHECK(theme_service);
// color_mode.
[&key, theme_service]() {
const auto browser_color_scheme = theme_service->GetBrowserColorScheme();
if (browser_color_scheme != ThemeService::BrowserColorScheme::kSystem) {
key.color_mode =
browser_color_scheme == ThemeService::BrowserColorScheme::kLight
? ui::ColorProviderKey::ColorMode::kLight
: ui::ColorProviderKey::ColorMode::kDark;
}
}();
// user_color.
// Device theme retains the user_color from `Widget`.
if (!theme_service->UsingDeviceTheme()) {
if (theme_service->UsingAutogeneratedTheme()) {
key.user_color = theme_service->GetAutogeneratedThemeColor();
} else if (auto user_color = theme_service->GetUserColor()) {
key.user_color = user_color;
}
}
// user_color_source.
if (theme_service->UsingDeviceTheme()) {
key.user_color_source = ui::ColorProviderKey::UserColorSource::kAccent;
} else if (theme_service->GetIsGrayscale()) {
key.user_color_source = ui::ColorProviderKey::UserColorSource::kGrayscale;
} else if (theme_service->GetIsBaseline()) {
key.user_color_source = ui::ColorProviderKey::UserColorSource::kBaseline;
} else {
CHECK(key.user_color.has_value());
key.user_color_source = ui::ColorProviderKey::UserColorSource::kAccent;
}
// scheme_variant.
ui::mojom::BrowserColorVariant color_variant =
theme_service->GetBrowserColorVariant();
if (!theme_service->UsingDeviceTheme() &&
color_variant != ui::mojom::BrowserColorVariant::kSystem) {
key.scheme_variant = GetSchemeVariant(color_variant);
}
// frame_type.
key.frame_type = ui::ColorProviderKey::FrameType::kNative;
return key;
return widget_key;
}
void CefWidgetImpl::OnThemeChanged() {

View File

@ -18,15 +18,18 @@
#include "base/base_switches.h"
#include "base/command_line.h"
#include "base/lazy_instance.h"
#include "base/path_service.h"
#include "base/threading/threading_features.h"
#include "chrome/browser/metrics/chrome_feature_list_creator.h"
#include "chrome/browser/policy/chrome_browser_policy_connector.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.h"
#include "components/embedder_support/switches.h"
#include "content/public/common/content_switches.h"
#include "sandbox/policy/switches.h"
#include "third_party/blink/public/common/switches.h"
#include "ui/base/ui_base_paths.h"
#include "ui/base/ui_base_switches.h"
#if BUILDFLAG(IS_MAC)
@ -40,6 +43,76 @@ namespace {
base::LazyInstance<ChromeContentRendererClientCef>::DestructorAtExit
g_chrome_content_renderer_client = LAZY_INSTANCE_INITIALIZER;
void InitLogging(const base::CommandLine* command_line) {
logging::LogSeverity log_severity = logging::LOGGING_INFO;
std::string log_severity_str =
command_line->GetSwitchValueASCII(switches::kLogSeverity);
if (!log_severity_str.empty()) {
if (base::EqualsCaseInsensitiveASCII(log_severity_str,
switches::kLogSeverity_Verbose)) {
log_severity = logging::LOGGING_VERBOSE;
} else if (base::EqualsCaseInsensitiveASCII(
log_severity_str, switches::kLogSeverity_Warning)) {
log_severity = logging::LOGGING_WARNING;
} else if (base::EqualsCaseInsensitiveASCII(log_severity_str,
switches::kLogSeverity_Error)) {
log_severity = logging::LOGGING_ERROR;
} else if (base::EqualsCaseInsensitiveASCII(log_severity_str,
switches::kLogSeverity_Fatal)) {
log_severity = logging::LOGGING_FATAL;
} else if (base::EqualsCaseInsensitiveASCII(
log_severity_str, switches::kLogSeverity_Disable)) {
log_severity = LOGSEVERITY_DISABLE;
}
}
if (log_severity == LOGSEVERITY_DISABLE) {
// By default, ERROR and FATAL messages will always be output to stderr due
// to the kAlwaysPrintErrorLevel value in base/logging.cc. We change the log
// level here so that only FATAL messages are output.
logging::SetMinLogLevel(logging::LOGGING_FATAL);
} else {
logging::SetMinLogLevel(log_severity);
}
// Customization of items automatically prepended to log lines.
std::string log_items_str =
command_line->GetSwitchValueASCII(switches::kLogItems);
if (!log_items_str.empty()) {
bool enable_log_of_process_id, enable_log_of_thread_id,
enable_log_of_time_stamp, enable_log_of_tick_count;
enable_log_of_process_id = enable_log_of_thread_id =
enable_log_of_time_stamp = enable_log_of_tick_count = false;
for (const auto& cur_item_to_log :
base::SplitStringPiece(log_items_str, ",", base::TRIM_WHITESPACE,
base::SPLIT_WANT_NONEMPTY)) {
// if "none" mode is present, all items are disabled.
if (base::EqualsCaseInsensitiveASCII(cur_item_to_log,
switches::kLogItems_None)) {
enable_log_of_process_id = enable_log_of_thread_id =
enable_log_of_time_stamp = enable_log_of_tick_count = false;
break;
} else if (base::EqualsCaseInsensitiveASCII(cur_item_to_log,
switches::kLogItems_PId)) {
enable_log_of_process_id = true;
} else if (base::EqualsCaseInsensitiveASCII(cur_item_to_log,
switches::kLogItems_TId)) {
enable_log_of_thread_id = true;
} else if (base::EqualsCaseInsensitiveASCII(
cur_item_to_log, switches::kLogItems_TimeStamp)) {
enable_log_of_time_stamp = true;
} else if (base::EqualsCaseInsensitiveASCII(
cur_item_to_log, switches::kLogItems_TickCount)) {
enable_log_of_tick_count = true;
}
}
logging::SetLogItems(enable_log_of_process_id, enable_log_of_thread_id,
enable_log_of_time_stamp, enable_log_of_tick_count);
}
}
} // namespace
ChromeMainDelegateCef::ChromeMainDelegateCef(CefMainRunnerHandler* runner,
@ -87,6 +160,39 @@ std::optional<int> ChromeMainDelegateCef::BasicStartupComplete() {
bool no_sandbox = settings_->no_sandbox ? true : false;
if (settings_->browser_subprocess_path.length > 0) {
base::FilePath file_path =
base::FilePath(CefString(&settings_->browser_subprocess_path));
if (!file_path.empty()) {
command_line->AppendSwitchPath(switches::kBrowserSubprocessPath,
file_path);
#if BUILDFLAG(IS_WIN)
// The sandbox is not supported when using a separate subprocess
// executable on Windows.
no_sandbox = true;
#endif
}
}
#if BUILDFLAG(IS_MAC)
if (settings_->framework_dir_path.length > 0) {
base::FilePath file_path =
base::FilePath(CefString(&settings_->framework_dir_path));
if (!file_path.empty()) {
command_line->AppendSwitchPath(switches::kFrameworkDirPath, file_path);
}
}
if (settings_->main_bundle_path.length > 0) {
base::FilePath file_path =
base::FilePath(CefString(&settings_->main_bundle_path));
if (!file_path.empty()) {
command_line->AppendSwitchPath(switches::kMainBundlePath, file_path);
}
}
#endif
if (no_sandbox) {
command_line->AppendSwitch(sandbox::policy::switches::kNoSandbox);
}
@ -108,12 +214,92 @@ std::optional<int> ChromeMainDelegateCef::BasicStartupComplete() {
command_line->AppendSwitchASCII(switches::kLang, "en-US");
}
if (!command_line->HasSwitch(switches::kLogFile) &&
settings_->log_file.length > 0) {
auto log_file = base::FilePath(CefString(&settings_->log_file));
command_line->AppendSwitchPath(switches::kLogFile, log_file);
}
if (!command_line->HasSwitch(switches::kLogSeverity) &&
settings_->log_severity != LOGSEVERITY_DEFAULT) {
std::string log_severity;
switch (settings_->log_severity) {
case LOGSEVERITY_VERBOSE:
log_severity = switches::kLogSeverity_Verbose;
break;
case LOGSEVERITY_INFO:
log_severity = switches::kLogSeverity_Info;
break;
case LOGSEVERITY_WARNING:
log_severity = switches::kLogSeverity_Warning;
break;
case LOGSEVERITY_ERROR:
log_severity = switches::kLogSeverity_Error;
break;
case LOGSEVERITY_FATAL:
log_severity = switches::kLogSeverity_Fatal;
break;
case LOGSEVERITY_DISABLE:
log_severity = switches::kLogSeverity_Disable;
break;
default:
break;
}
if (!log_severity.empty()) {
command_line->AppendSwitchASCII(switches::kLogSeverity, log_severity);
}
}
if (!command_line->HasSwitch(switches::kLogItems) &&
settings_->log_items != LOG_ITEMS_DEFAULT) {
std::string log_items_str;
if (settings_->log_items == LOG_ITEMS_NONE) {
log_items_str = std::string(switches::kLogItems_None);
} else {
std::vector<std::string_view> added_items;
if (settings_->log_items & LOG_ITEMS_FLAG_PROCESS_ID) {
added_items.emplace_back(switches::kLogItems_PId);
}
if (settings_->log_items & LOG_ITEMS_FLAG_THREAD_ID) {
added_items.emplace_back(switches::kLogItems_TId);
}
if (settings_->log_items & LOG_ITEMS_FLAG_TIME_STAMP) {
added_items.emplace_back(switches::kLogItems_TimeStamp);
}
if (settings_->log_items & LOG_ITEMS_FLAG_TICK_COUNT) {
added_items.emplace_back(switches::kLogItems_TickCount);
}
if (!added_items.empty()) {
log_items_str = base::JoinString(added_items, ",");
}
}
if (!log_items_str.empty()) {
command_line->AppendSwitchASCII(switches::kLogItems, log_items_str);
}
}
if (settings_->javascript_flags.length > 0) {
command_line->AppendSwitchASCII(
blink::switches::kJavaScriptFlags,
CefString(&settings_->javascript_flags).ToString());
}
if (settings_->resources_dir_path.length > 0) {
base::FilePath file_path =
base::FilePath(CefString(&settings_->resources_dir_path));
if (!file_path.empty()) {
command_line->AppendSwitchPath(switches::kResourcesDirPath, file_path);
}
}
if (settings_->locales_dir_path.length > 0) {
base::FilePath file_path =
base::FilePath(CefString(&settings_->locales_dir_path));
if (!file_path.empty()) {
command_line->AppendSwitchPath(switches::kLocalesDirPath, file_path);
}
}
if (settings_->remote_debugging_port >= 1024 &&
settings_->remote_debugging_port <= 65535) {
command_line->AppendSwitchASCII(
@ -161,6 +347,9 @@ std::optional<int> ChromeMainDelegateCef::BasicStartupComplete() {
std::ignore = commandLinePtr->Detach(nullptr);
}
// Call as early as possible.
InitLogging(command_line);
#if BUILDFLAG(IS_MAC)
util_mac::BasicStartupComplete();
#endif
@ -193,6 +382,43 @@ void ChromeMainDelegateCef::PreSandboxStartup() {
// Initialize crash reporting state for this process/module.
// chrome::DIR_CRASH_DUMPS must be configured before calling this function.
crash_reporting::PreSandboxStartup(*command_line, process_type);
base::FilePath resources_dir;
if (command_line->HasSwitch(switches::kResourcesDirPath)) {
resources_dir =
command_line->GetSwitchValuePath(switches::kResourcesDirPath);
}
if (resources_dir.empty()) {
resources_dir = resource_util::GetResourcesDir();
}
if (!resources_dir.empty()) {
base::PathService::Override(chrome::DIR_RESOURCES, resources_dir);
}
if (command_line->HasSwitch(switches::kLocalesDirPath)) {
const auto& locales_dir =
command_line->GetSwitchValuePath(switches::kLocalesDirPath);
if (!locales_dir.empty()) {
base::PathService::Override(ui::DIR_LOCALES, locales_dir);
}
}
#if !BUILDFLAG(IS_WIN)
// Call after InitLogging() potentially changes values in
// chrome/app/chrome_main_delegate.cc.
InitLogging(command_line);
#endif
}
void ChromeMainDelegateCef::SandboxInitialized(
const std::string& process_type) {
ChromeMainDelegate::SandboxInitialized(process_type);
#if BUILDFLAG(IS_WIN)
// Call after InitLogging() potentially changes values in
// chrome/app/chrome_main_delegate.cc.
InitLogging(base::CommandLine::ForCurrentProcess());
#endif
}
std::optional<int> ChromeMainDelegateCef::PreBrowserMain() {

View File

@ -12,6 +12,7 @@
#include "libcef/common/app_manager.h"
#include "libcef/common/chrome/chrome_content_client_cef.h"
#include "libcef/common/main_runner_handler.h"
#include "libcef/common/resource_bundle_delegate.h"
#include "libcef/common/task_runner_manager.h"
#include "chrome/app/chrome_main_delegate.h"
@ -38,6 +39,7 @@ class ChromeMainDelegateCef : public ChromeMainDelegate,
// ChromeMainDelegate overrides.
std::optional<int> BasicStartupComplete() override;
void PreSandboxStartup() override;
void SandboxInitialized(const std::string& process_type) override;
std::optional<int> PreBrowserMain() override;
std::optional<int> PostEarlyInitialization(InvokedIn invoked_in) override;
absl::variant<int, content::MainFunctionParams> RunProcess(
@ -71,6 +73,11 @@ class ChromeMainDelegateCef : public ChromeMainDelegate,
scoped_refptr<base::SingleThreadTaskRunner> GetRenderTaskRunner() override;
scoped_refptr<base::SingleThreadTaskRunner> GetWebWorkerTaskRunner() override;
// ChromeMainDelegate overrides.
ui::ResourceBundle::Delegate* GetResourceBundleDelegate() override {
return &resource_bundle_delegate_;
}
private:
ChromeContentBrowserClientCef* content_browser_client() const;
ChromeContentRendererClientCef* content_renderer_client() const;
@ -81,6 +88,8 @@ class ChromeMainDelegateCef : public ChromeMainDelegate,
// We use this instead of ChromeMainDelegate::chrome_content_client_.
ChromeContentClientCef chrome_content_client_cef_;
CefResourceBundleDelegate resource_bundle_delegate_;
};
#endif // CEF_LIBCEF_COMMON_CHROME_CHROME_MAIN_DELEGATE_CEF_

View File

@ -1,6 +1,14 @@
#include "libcef/common/resource_bundle_delegate.h"
#include "libcef/common/app_manager.h"
#include "libcef/features/runtime.h"
CefResourceBundleDelegate::CefResourceBundleDelegate() {
// Alloy bootstrap explicitly enables pack file loading in
// AlloyMainDelegate::InitializeResourceBundle, and it is otherwise disabled
// by default. Chrome bootstrap does not support this.
allow_pack_file_load_ = cef::IsChromeRuntimeEnabled();
}
base::FilePath CefResourceBundleDelegate::GetPathForResourcePack(
const base::FilePath& pack_path,

View File

@ -7,13 +7,16 @@
#define CEF_LIBCEF_COMMON_RESOURCE_BUNDLE_DELEGATE_H_
#pragma once
#include "cef/libcef/features/features.h"
#include "ui/base/resource/resource_bundle.h"
class AlloyContentClient;
class CefResourceBundleDelegate : public ui::ResourceBundle::Delegate {
public:
CefResourceBundleDelegate() = default;
CefResourceBundleDelegate();
CefResourceBundleDelegate(const CefResourceBundleDelegate&) = delete;
CefResourceBundleDelegate& operator=(const CefResourceBundleDelegate&) =
delete;
void set_pack_loading_disabled(bool val) { pack_loading_disabled_ = val; }
bool pack_loading_disabled() const { return pack_loading_disabled_; }
@ -40,7 +43,7 @@ class CefResourceBundleDelegate : public ui::ResourceBundle::Delegate {
private:
bool pack_loading_disabled_ = false;
bool allow_pack_file_load_ = false;
bool allow_pack_file_load_;
};
#endif // CEF_LIBCEF_COMMON_RESOURCE_BUNDLE_DELEGATE_H_

View File

@ -223,6 +223,9 @@ patches = [
#
# Apply dynamic light/dark theme changes to web content.
# https://issues.chromium.org/issues/332328864#comment3
#
# Pass ui::ResourceBundle::Delegate to InitSharedInstanceWithLocale.
# https://github.com/chromiumembedded/cef/issues/3685
'name': 'chrome_runtime',
},
{
@ -348,6 +351,11 @@ patches = [
# https://github.com/chromiumembedded/cef/issues/2969
'name': 'chrome_browser_profile_menu',
},
{
# chrome: Enable logging by default for Release builds.
# https://github.com/chromiumembedded/cef/issues/2969
'name': 'chrome_common_logging',
},
{
# alloy: Don't require heap profiler for utility processes.
# Avoids a DCHECK added in https://crrev.com/c21e9f71d1f2e
@ -736,6 +744,9 @@ patches = [
#
# mac: Add fallback for unsupported --lang values.
# https://github.com/chromiumembedded/cef/issues/3653
#
# Pass ui::ResourceBundle::Delegate to InitSharedInstanceWithLocale.
# https://github.com/chromiumembedded/cef/issues/3685
'name': 'mac_chrome_locale_3623'
},
{

View File

@ -0,0 +1,35 @@
diff --git chrome/common/features.gni chrome/common/features.gni
index 01367ff6efd6c..975ea8e446dce 100644
--- chrome/common/features.gni
+++ chrome/common/features.gni
@@ -7,6 +7,7 @@ import("//build/config/chromeos/ui_mode.gni")
import("//build/config/compiler/compiler.gni")
import("//build/config/dcheck_always_on.gni")
import("//build/config/features.gni")
+import("//cef/libcef/features/features.gni")
import("//components/compose/features.gni")
import("//components/feed/features.gni")
import("//components/nacl/features.gni")
@@ -31,7 +32,7 @@ assert(use_blink, "Chromium without blink shouldn't use anything in //chrome")
declare_args() {
# Enables the build to have logging enabled by default.
# This is intended for use only in developer builds.
- chrome_enable_logging_by_default = is_debug
+ chrome_enable_logging_by_default = is_debug || enable_cef
# Platforms where Chrome x509 server certificate enterprise policies are
# supported. This must must match the supported_on/future_on list of the
@@ -90,11 +91,13 @@ declare_args() {
# optimize_webui was moved to ui/base/ui_features.gni
}
+if (!enable_cef) {
# Logging must be disabled by default in all official builds (including special
# DCHECK-enabled builds). Logging is enabled by default for debug builds, and
# may be selectively enabled by default for release builds.
assert(!chrome_enable_logging_by_default || !is_official_build,
"Logging must be disabled by default in Official builds")
+}
# Use brlapi from brltty for braille display support.
use_brlapi = is_chromeos_ash

View File

@ -1,5 +1,5 @@
diff --git chrome/app/chrome_main_delegate.cc chrome/app/chrome_main_delegate.cc
index 363f485ce3564..0afa082daf7e7 100644
index 363f485ce3564..91aa4ec8b2689 100644
--- chrome/app/chrome_main_delegate.cc
+++ chrome/app/chrome_main_delegate.cc
@@ -37,6 +37,7 @@
@ -40,7 +40,17 @@ index 363f485ce3564..0afa082daf7e7 100644
// In the case the process is not the singleton process, the uninstall tasks
// need to be executed here. A window will be displayed asking to close all
// running instances.
@@ -1062,7 +1070,8 @@ std::optional<int> ChromeMainDelegate::PostEarlyInitialization(
@@ -1043,7 +1051,8 @@ std::optional<int> ChromeMainDelegate::PostEarlyInitialization(
// Initializes the resource bundle and determines the locale.
std::string actual_locale = LoadLocalState(
- chrome_feature_list_creator, invoked_in_browser->is_running_test);
+ chrome_feature_list_creator, GetResourceBundleDelegate(),
+ invoked_in_browser->is_running_test);
chrome_feature_list_creator->SetApplicationLocale(actual_locale);
chrome_feature_list_creator->OverrideCachedUIStrings();
@@ -1062,7 +1071,8 @@ std::optional<int> ChromeMainDelegate::PostEarlyInitialization(
if (base::FeatureList::IsEnabled(
features::kWriteBasicSystemProfileToPersistentHistogramsFile)) {
@ -50,7 +60,7 @@ index 363f485ce3564..0afa082daf7e7 100644
#if BUILDFLAG(IS_ANDROID)
record =
base::FeatureList::IsEnabled(chrome::android::kUmaBackgroundSessions);
@@ -1507,6 +1516,7 @@ void ChromeMainDelegate::PreSandboxStartup() {
@@ -1507,6 +1517,7 @@ void ChromeMainDelegate::PreSandboxStartup() {
std::string process_type =
command_line.GetSwitchValueASCII(switches::kProcessType);
@ -58,7 +68,7 @@ index 363f485ce3564..0afa082daf7e7 100644
crash_reporter::InitializeCrashKeys();
#if BUILDFLAG(IS_CHROMEOS_LACROS)
@@ -1525,6 +1535,7 @@ void ChromeMainDelegate::PreSandboxStartup() {
@@ -1525,6 +1536,7 @@ void ChromeMainDelegate::PreSandboxStartup() {
InitMacCrashReporter(command_line, process_type);
SetUpInstallerPreferences(command_line);
#endif
@ -66,7 +76,17 @@ index 363f485ce3564..0afa082daf7e7 100644
#if BUILDFLAG(IS_WIN)
child_process_logging::Init();
@@ -1735,6 +1746,7 @@ void ChromeMainDelegate::PreSandboxStartup() {
@@ -1705,7 +1717,8 @@ void ChromeMainDelegate::PreSandboxStartup() {
#else
const std::string loaded_locale =
ui::ResourceBundle::InitSharedInstanceWithLocale(
- locale, nullptr, ui::ResourceBundle::LOAD_COMMON_RESOURCES);
+ locale, GetResourceBundleDelegate(),
+ ui::ResourceBundle::LOAD_COMMON_RESOURCES);
base::FilePath resources_pack_path;
base::PathService::Get(chrome::FILE_RESOURCES_PACK, &resources_pack_path);
@@ -1735,6 +1748,7 @@ void ChromeMainDelegate::PreSandboxStartup() {
CHECK(!loaded_locale.empty()) << "Locale could not be found for " << locale;
}
@ -74,7 +94,7 @@ index 363f485ce3564..0afa082daf7e7 100644
#if BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_MAC)
// Zygote needs to call InitCrashReporter() in RunZygote().
if (process_type != switches::kZygoteProcess) {
@@ -1770,6 +1782,7 @@ void ChromeMainDelegate::PreSandboxStartup() {
@@ -1770,6 +1784,7 @@ void ChromeMainDelegate::PreSandboxStartup() {
// After all the platform Breakpads have been initialized, store the command
// line for crash reporting.
crash_keys::SetCrashKeysFromCommandLine(command_line);
@ -82,7 +102,7 @@ index 363f485ce3564..0afa082daf7e7 100644
#if BUILDFLAG(ENABLE_PDF)
MaybePatchGdiGetFontData();
@@ -1895,6 +1908,7 @@ void ChromeMainDelegate::ZygoteForked() {
@@ -1895,6 +1910,7 @@ void ChromeMainDelegate::ZygoteForked() {
SetUpProfilingShutdownHandler();
}
@ -90,7 +110,7 @@ index 363f485ce3564..0afa082daf7e7 100644
// Needs to be called after we have chrome::DIR_USER_DATA. BrowserMain sets
// this up for the browser process in a different manner.
const base::CommandLine* command_line =
@@ -1907,6 +1921,7 @@ void ChromeMainDelegate::ZygoteForked() {
@@ -1907,6 +1923,7 @@ void ChromeMainDelegate::ZygoteForked() {
// Reset the command line for the newly spawned process.
crash_keys::SetCrashKeysFromCommandLine(*command_line);
@ -98,7 +118,7 @@ index 363f485ce3564..0afa082daf7e7 100644
}
#endif // BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
@@ -2003,6 +2018,7 @@ void ChromeMainDelegate::InitializeMemorySystem() {
@@ -2003,6 +2020,7 @@ void ChromeMainDelegate::InitializeMemorySystem() {
const bool is_browser_process = process_type.empty();
const bool gwp_asan_boost_sampling = is_browser_process || IsCanaryDev();
@ -106,7 +126,7 @@ index 363f485ce3564..0afa082daf7e7 100644
memory_system::Initializer()
.SetGwpAsanParameters(gwp_asan_boost_sampling, process_type)
.SetProfilingClientParameters(chrome::GetChannel(),
@@ -2012,5 +2028,5 @@ void ChromeMainDelegate::InitializeMemorySystem() {
@@ -2012,5 +2030,5 @@ void ChromeMainDelegate::InitializeMemorySystem() {
memory_system::DispatcherParameters::
AllocationTraceRecorderInclusion::kDynamic,
process_type)
@ -114,10 +134,18 @@ index 363f485ce3564..0afa082daf7e7 100644
+ .Initialize(*memory_system_);
}
diff --git chrome/app/chrome_main_delegate.h chrome/app/chrome_main_delegate.h
index 3553377e96017..5207128b768f2 100644
index 3553377e96017..9f6edc70ef1d4 100644
--- chrome/app/chrome_main_delegate.h
+++ chrome/app/chrome_main_delegate.h
@@ -49,6 +49,8 @@ class ChromeMainDelegate : public content::ContentMainDelegate {
@@ -16,6 +16,7 @@
#include "chrome/common/chrome_content_client.h"
#include "components/memory_system/memory_system.h"
#include "content/public/app/content_main_delegate.h"
+#include "ui/base/resource/resource_bundle.h"
namespace base {
class CommandLine;
@@ -49,6 +50,8 @@ class ChromeMainDelegate : public content::ContentMainDelegate {
~ChromeMainDelegate() override;
@ -126,7 +154,17 @@ index 3553377e96017..5207128b768f2 100644
protected:
// content::ContentMainDelegate:
std::optional<int> BasicStartupComplete() override;
@@ -98,7 +100,7 @@ class ChromeMainDelegate : public content::ContentMainDelegate {
@@ -92,13 +95,17 @@ class ChromeMainDelegate : public content::ContentMainDelegate {
void InitializeMemorySystem();
+ virtual ui::ResourceBundle::Delegate* GetResourceBundleDelegate() {
+ return nullptr;
+ }
+
std::unique_ptr<ChromeContentBrowserClient> chrome_content_browser_client_;
std::unique_ptr<ChromeContentUtilityClient> chrome_content_utility_client_;
std::unique_ptr<tracing::TracingSamplerProfiler> tracing_sampler_profiler_;
ChromeContentClient chrome_content_client_;

View File

@ -233,7 +233,7 @@ index 0ccfe39eb5696..c9424316b6d14 100644
return gfx::Rect();
}
diff --git chrome/browser/ui/views/frame/browser_frame.cc chrome/browser/ui/views/frame/browser_frame.cc
index 8dd3620ba2720..ab3a92fd7ebe4 100644
index 8dd3620ba2720..e3bac8207de24 100644
--- chrome/browser/ui/views/frame/browser_frame.cc
+++ chrome/browser/ui/views/frame/browser_frame.cc
@@ -114,15 +114,23 @@ ui::ColorProviderKey::SchemeVariant GetSchemeVariant(
@ -332,16 +332,7 @@ index 8dd3620ba2720..ab3a92fd7ebe4 100644
chrome::SaveWindowWorkspace(browser_view_->browser(), GetWorkspace());
chrome::SaveWindowVisibleOnAllWorkspaces(browser_view_->browser(),
IsVisibleOnAllWorkspaces());
@@ -483,6 +515,8 @@ void BrowserFrame::OnNativeThemeUpdated(ui::NativeTheme* observed_theme) {
ui::ColorProviderKey BrowserFrame::GetColorProviderKey() const {
auto key = Widget::GetColorProviderKey();
+ if (!browser_view_)
+ return key;
key.app_controller = browser_view_->browser()->app_controller();
@@ -572,6 +606,13 @@ void BrowserFrame::SelectNativeTheme() {
@@ -572,6 +604,13 @@ void BrowserFrame::SelectNativeTheme() {
return;
}
@ -355,7 +346,7 @@ index 8dd3620ba2720..ab3a92fd7ebe4 100644
// Ignore the system theme for web apps with window-controls-overlay as the
// display_override so the web contents can blend with the overlay by using
// the developer-provided theme color for a better experience. Context:
@@ -637,5 +678,8 @@ bool BrowserFrame::RegenerateFrameOnThemeChange(
@@ -637,5 +676,8 @@ bool BrowserFrame::RegenerateFrameOnThemeChange(
}
bool BrowserFrame::IsIncognitoBrowser() const {

View File

@ -1,8 +1,21 @@
diff --git chrome/browser/chrome_resource_bundle_helper.cc chrome/browser/chrome_resource_bundle_helper.cc
index 0cfc966050b60..8268a8b1f4fcb 100644
index 0cfc966050b60..bbc20cffaee1a 100644
--- chrome/browser/chrome_resource_bundle_helper.cc
+++ chrome/browser/chrome_resource_bundle_helper.cc
@@ -82,16 +82,8 @@ std::string InitResourceBundleAndDetermineLocale(PrefService* local_state,
@@ -68,8 +68,10 @@ extern void InitializeLocalState(
// Initializes the shared instance of ResourceBundle and returns the application
// locale. An empty |actual_locale| value indicates failure.
-std::string InitResourceBundleAndDetermineLocale(PrefService* local_state,
- bool is_running_tests) {
+std::string InitResourceBundleAndDetermineLocale(
+ PrefService* local_state,
+ ui::ResourceBundle::Delegate* resource_bundle_delegate,
+ bool is_running_tests) {
#if BUILDFLAG(IS_ANDROID)
// In order for SetLoadSecondaryLocalePaks() to work ResourceBundle must
// not have been created yet.
@@ -82,16 +84,8 @@ std::string InitResourceBundleAndDetermineLocale(PrefService* local_state,
.empty());
#endif
@ -20,6 +33,52 @@ index 0cfc966050b60..8268a8b1f4fcb 100644
#if BUILDFLAG(IS_CHROMEOS_ASH)
ui::ResourceBundle::SetLottieParsingFunctions(
@@ -103,7 +97,8 @@ std::string InitResourceBundleAndDetermineLocale(PrefService* local_state,
// On a POSIX OS other than ChromeOS, the parameter that is passed to the
// method InitSharedInstance is ignored.
std::string actual_locale = ui::ResourceBundle::InitSharedInstanceWithLocale(
- preferred_locale, nullptr, ui::ResourceBundle::LOAD_COMMON_RESOURCES);
+ preferred_locale, resource_bundle_delegate,
+ ui::ResourceBundle::LOAD_COMMON_RESOURCES);
CHECK(!actual_locale.empty())
<< "Locale could not be found for " << preferred_locale;
@@ -155,6 +150,7 @@ std::string InitResourceBundleAndDetermineLocale(PrefService* local_state,
std::string LoadLocalState(
ChromeFeatureListCreator* chrome_feature_list_creator,
+ ui::ResourceBundle::Delegate* resource_bundle_delegate,
bool is_running_tests) {
base::FilePath user_data_dir;
if (!base::PathService::Get(chrome::DIR_USER_DATA, &user_data_dir))
@@ -166,5 +162,6 @@ std::string LoadLocalState(
new ChromeCommandLinePrefStore(base::CommandLine::ForCurrentProcess()));
return InitResourceBundleAndDetermineLocale(
- chrome_feature_list_creator->local_state(), is_running_tests);
+ chrome_feature_list_creator->local_state(), resource_bundle_delegate,
+ is_running_tests);
}
diff --git chrome/browser/chrome_resource_bundle_helper.h chrome/browser/chrome_resource_bundle_helper.h
index 0b22e445bc3ff..1d7c6b319ba4b 100644
--- chrome/browser/chrome_resource_bundle_helper.h
+++ chrome/browser/chrome_resource_bundle_helper.h
@@ -7,12 +7,15 @@
#include <string>
+#include "ui/base/resource/resource_bundle.h"
+
class ChromeFeatureListCreator;
// Loads the local state, and returns the application locale. An empty return
// value indicates the ResouceBundle couldn't be loaded.
std::string LoadLocalState(
ChromeFeatureListCreator* chrome_feature_list_creator,
+ ui::ResourceBundle::Delegate* resource_bundle_delegate,
bool is_running_tests);
#endif // CHROME_BROWSER_CHROME_RESOURCE_BUNDLE_HELPER_H_
diff --git components/language/core/browser/locale_util.cc components/language/core/browser/locale_util.cc
index aa43742055b04..e84f21ab963cc 100644
--- components/language/core/browser/locale_util.cc