fix: Initialize resource bundle for the browser process earlier
This commit is contained in:
parent
1de0152b6b
commit
4089620729
5 changed files with 31 additions and 31 deletions
|
@ -182,6 +182,36 @@ bool AtomMainDelegate::BasicStartupComplete(int* exit_code) {
|
|||
return false;
|
||||
}
|
||||
|
||||
void AtomMainDelegate::PostEarlyInitialization(bool is_running_tests) {
|
||||
std::string custom_locale;
|
||||
ui::ResourceBundle::InitSharedInstanceWithLocale(
|
||||
custom_locale, nullptr, ui::ResourceBundle::LOAD_COMMON_RESOURCES);
|
||||
auto* cmd_line = base::CommandLine::ForCurrentProcess();
|
||||
if (cmd_line->HasSwitch(::switches::kLang)) {
|
||||
const std::string locale = cmd_line->GetSwitchValueASCII(::switches::kLang);
|
||||
const base::FilePath locale_file_path =
|
||||
ui::ResourceBundle::GetSharedInstance().GetLocaleFilePath(locale, true);
|
||||
if (!locale_file_path.empty()) {
|
||||
custom_locale = locale;
|
||||
#if defined(OS_LINUX)
|
||||
/* When built with USE_GLIB, libcc's GetApplicationLocaleInternal() uses
|
||||
* glib's g_get_language_names(), which keys off of getenv("LC_ALL") */
|
||||
g_setenv("LC_ALL", custom_locale.c_str(), TRUE);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(OS_MACOSX)
|
||||
if (custom_locale.empty())
|
||||
l10n_util::OverrideLocaleWithCocoaLocale();
|
||||
#endif
|
||||
|
||||
LoadResourceBundle(custom_locale);
|
||||
|
||||
AtomBrowserClient::SetApplicationLocale(
|
||||
l10n_util::GetApplicationLocale(custom_locale));
|
||||
}
|
||||
|
||||
void AtomMainDelegate::PreSandboxStartup() {
|
||||
auto* command_line = base::CommandLine::ForCurrentProcess();
|
||||
|
||||
|
|
|
@ -25,6 +25,7 @@ class AtomMainDelegate : public content::ContentMainDelegate {
|
|||
bool BasicStartupComplete(int* exit_code) override;
|
||||
void PreSandboxStartup() override;
|
||||
void PreCreateMainMessageLoop() override;
|
||||
void PostEarlyInitialization(bool is_running_tests) override;
|
||||
content::ContentBrowserClient* CreateContentBrowserClient() override;
|
||||
content::ContentRendererClient* CreateContentRendererClient() override;
|
||||
content::ContentUtilityClient* CreateContentUtilityClient() override;
|
||||
|
|
|
@ -158,8 +158,6 @@ AtomBrowserClient* AtomBrowserClient::Get() {
|
|||
|
||||
// static
|
||||
void AtomBrowserClient::SetApplicationLocale(const std::string& locale) {
|
||||
DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
||||
|
||||
if (!BrowserThread::IsThreadInitialized(BrowserThread::IO) ||
|
||||
!base::PostTaskWithTraits(
|
||||
FROM_HERE, {BrowserThread::IO},
|
||||
|
|
|
@ -47,9 +47,7 @@
|
|||
#include "services/device/public/mojom/constants.mojom.h"
|
||||
#include "services/service_manager/public/cpp/connector.h"
|
||||
#include "ui/base/idle/idle.h"
|
||||
#include "ui/base/l10n/l10n_util.h"
|
||||
#include "ui/base/material_design/material_design_controller.h"
|
||||
#include "ui/base/resource/resource_bundle.h"
|
||||
#include "ui/base/ui_base_switches.h"
|
||||
|
||||
#if defined(USE_AURA)
|
||||
|
@ -355,9 +353,6 @@ int AtomBrowserMainParts::PreCreateThreads() {
|
|||
layout_provider_.reset(new views::LayoutProvider());
|
||||
|
||||
// Initialize the app locale.
|
||||
AtomBrowserClient::SetApplicationLocale(
|
||||
l10n_util::GetApplicationLocale(custom_locale_));
|
||||
|
||||
fake_browser_process_->SetApplicationLocale(
|
||||
AtomBrowserClient::Get()->GetApplicationLocale());
|
||||
|
||||
|
@ -513,29 +508,6 @@ void AtomBrowserMainParts::PreMainMessageLoopStart() {
|
|||
#endif
|
||||
|
||||
void AtomBrowserMainParts::PreMainMessageLoopStartCommon() {
|
||||
// Initialize ui::ResourceBundle.
|
||||
ui::ResourceBundle::InitSharedInstanceWithLocale(
|
||||
"", nullptr, ui::ResourceBundle::DO_NOT_LOAD_COMMON_RESOURCES);
|
||||
auto* cmd_line = base::CommandLine::ForCurrentProcess();
|
||||
if (cmd_line->HasSwitch(switches::kLang)) {
|
||||
const std::string locale = cmd_line->GetSwitchValueASCII(switches::kLang);
|
||||
const base::FilePath locale_file_path =
|
||||
ui::ResourceBundle::GetSharedInstance().GetLocaleFilePath(locale, true);
|
||||
if (!locale_file_path.empty()) {
|
||||
custom_locale_ = locale;
|
||||
#if defined(OS_LINUX)
|
||||
/* When built with USE_GLIB, libcc's GetApplicationLocaleInternal() uses
|
||||
* glib's g_get_language_names(), which keys off of getenv("LC_ALL") */
|
||||
g_setenv("LC_ALL", custom_locale_.c_str(), TRUE);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(OS_MACOSX)
|
||||
if (custom_locale_.empty())
|
||||
l10n_util::OverrideLocaleWithCocoaLocale();
|
||||
#endif
|
||||
LoadResourceBundle(custom_locale_);
|
||||
#if defined(OS_MACOSX)
|
||||
InitializeMainNib();
|
||||
#endif
|
||||
|
|
|
@ -112,7 +112,6 @@ class AtomBrowserMainParts : public content::BrowserMainParts {
|
|||
#endif
|
||||
|
||||
std::unique_ptr<views::LayoutProvider> layout_provider_;
|
||||
std::string custom_locale_;
|
||||
|
||||
// A fake BrowserProcess object that used to feed the source code from chrome.
|
||||
std::unique_ptr<BrowserProcessImpl> fake_browser_process_;
|
||||
|
|
Loading…
Reference in a new issue