chromiumembedded / cef

Chromium Embedded Framework (CEF). A simple framework for embedding Chromium-based browsers in other applications.
https://bitbucket.org/chromiumembedded/cef/
Other
3.09k stars 450 forks source link

`CefSettings::locale` and `--lang` flag are ignored when Chrome Runtime is enabled #3623

Closed nik-sp closed 6 months ago

nik-sp commented 6 months ago

Describe the bug

The _cef_settings_t::locale parameter and --lang flag seem to be ignored when Chrome Runtime is enabled.

This issue is specifically affecting the mirroring of window buttons in macOS, causing layout discrepancies when the language is set to RTL (Right-to-Left), such as Hebrew.

To Reproduce

Steps to reproduce the behavior:

  1. Set the _cef_settings_t::locale value to he or use the --lang=he flag.
  2. Launch the cefclient with the following flags: --use-views --enable-chrome-runtime
  3. Observe the layout of window buttons, and note that they are not mirrored as expected.

Expected behavior

The Window buttons should be mirrored correctly according to the RTL layout specified by the language (Hebrew, in this case) when _cef_settings_t::locale parameter or --lang flag is set.

Screenshots

With Chrome Runtime: ./cefclient --use-views --enable-chrome-runtime --lang=he צילום מסך 2024-01-02 ב-14 46 49 With Alloy Runtime: ./cefclient --use-views --lang=he צילום מסך 2024-01-02 ב-14 48 28

Versions (please complete the following information):

Additional context

Probably relates to https://github.com/chromiumembedded/cef/issues/3583

The problem does not reproduce with Google Chrome at the same version.

I can see that the locale is passed in the InitializeResourceBundle method of AlloyMainDelegate: https://github.com/chromiumembedded/cef/blob/e4acacee18d66d9bfe65a15072307d619117bd32/libcef/common/alloy/alloy_main_delegate.cc#L704-L707 But there is no passing of locale in ChromeMainDelegateCef so default locale "en_US" is used.

magreenblatt commented 6 months ago

This also impacts the mirroring of UI elements and menu localization on macOS. Those work as expected on Windows.

magreenblatt commented 6 months ago

On MacOS with Chrome Runtime (M121), ResourceBundle::InitSharedInstanceWithLocale is called via:

* thread #1, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1
  * frame #0: 0x00000001c950d2c2 Chromium Embedded Framework`ui::ResourceBundle::InitSharedInstanceWithLocale(pref_locale="", delegate=0x0000000000000000, load_resources=LOAD_COMMON_RESOURCES) at resource_bundle.cc:288:22
    frame #1: 0x00000001cbf4441e Chromium Embedded Framework`(anonymous namespace)::InitResourceBundleAndDetermineLocale(local_state=0x0000600000238340, is_running_tests=false) at chrome_resource_bundle_helper.cc:105:31
    frame #2: 0x00000001cbf440f5 Chromium Embedded Framework`LoadLocalState(chrome_feature_list_creator=0x0000600001a25040, is_running_tests=false) at chrome_resource_bundle_helper.cc:168:10
    frame #3: 0x00000001b20eb460 Chromium Embedded Framework`ChromeMainDelegate::PostEarlyInitialization(this=0x00007fbda1315630, invoked_in=content::ContentMainDelegate::InvokedIn @ 0x00007ff7bfefd8a0) at chrome_main_delegate.cc:941:31
    frame #4: 0x00000001b2020257 Chromium Embedded Framework`ChromeMainDelegateCef::PostEarlyInitialization(this=0x00007fbda1315630, invoked_in=content::ContentMainDelegate::InvokedIn @ 0x00007ff7bfefd940) at chrome_main_delegate_cef.cc:215:43

And the |pref_locale| argument is empty because of the code here.

magreenblatt commented 6 months ago

And the |pref_locale| argument is empty because of the code here.

After changing that code we get a crash:

[12468:259:0103/132421.284341:FATAL:variations_service.cc(513)] Check failed: locale == field_trial_creator_.application_locale() (he vs. en-US)
0   Chromium Embedded Framework         0x00000001ccdc375c base::debug::CollectStackTrace(void const**, unsigned long) + 44
1   Chromium Embedded Framework         0x00000001ccd987e8 base::debug::StackTrace::StackTrace(unsigned long) + 72
2   Chromium Embedded Framework         0x00000001ccd9886d base::debug::StackTrace::StackTrace(unsigned long) + 29
3   Chromium Embedded Framework         0x00000001ccd98845 base::debug::StackTrace::StackTrace() + 37
4   Chromium Embedded Framework         0x00000001ccaf366a logging::LogMessage::~LogMessage() + 202
5   Chromium Embedded Framework         0x00000001ccaf4605 logging::LogMessage::~LogMessage() + 21
6   Chromium Embedded Framework         0x00000001ccaf4629 logging::LogMessage::~LogMessage() + 25
7   Chromium Embedded Framework         0x00000001ccab669d logging::CheckError::~CheckError() + 77
8   Chromium Embedded Framework         0x00000001ccab66e5 logging::CheckError::~CheckError() + 21
9   Chromium Embedded Framework         0x00000001d6f41f57 variations::VariationsService::EnsureLocaleEquals(std::__Cr::basic_string<char, std::__Cr::char_traits<char>, std::__Cr::allocator<char>> const&) + 535
10  Chromium Embedded Framework         0x00000001d3339c06 ChromeFeatureListCreator::SetApplicationLocale(std::__Cr::basic_string<char, std::__Cr::char_traits<char>, std::__Cr::allocator<char>> const&) + 70
11  Chromium Embedded Framework         0x00000001b92eb473 ChromeMainDelegate::PostEarlyInitialization(absl::variant<content::ContentMainDelegate::InvokedInBrowserProcess, content::ContentMainDelegate::InvokedInChildProcess>) + 723
12  Chromium Embedded Framework         0x00000001b9220257 ChromeMainDelegateCef::PostEarlyInitialization(absl::variant<content::ContentMainDelegate::InvokedInBrowserProcess, content::ContentMainDelegate::InvokedInChildProcess>) + 215

Likely due to code in language::GetApplicationLocale called from VariationsFieldTrialCreator.

magreenblatt commented 6 months ago

After fixing code in both places, it works as expected:

$ cefclient --lang=he --use-views --enable-chrome-runtime

image