From 4089620729dbeba5a09e97d26c46ac35a75911a5 Mon Sep 17 00:00:00 2001 From: deepak1556 Date: Thu, 10 Jan 2019 21:49:25 +0530 Subject: [PATCH] fix: Initialize resource bundle for the browser process earlier --- atom/app/atom_main_delegate.cc | 30 +++++++++++++++++++++++++ atom/app/atom_main_delegate.h | 1 + atom/browser/atom_browser_client.cc | 2 -- atom/browser/atom_browser_main_parts.cc | 28 ----------------------- atom/browser/atom_browser_main_parts.h | 1 - 5 files changed, 31 insertions(+), 31 deletions(-) diff --git a/atom/app/atom_main_delegate.cc b/atom/app/atom_main_delegate.cc index a667d7e8ddb1..787cfb609413 100644 --- a/atom/app/atom_main_delegate.cc +++ b/atom/app/atom_main_delegate.cc @@ -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(); diff --git a/atom/app/atom_main_delegate.h b/atom/app/atom_main_delegate.h index 317be4804eaf..3c2dfe194bbb 100644 --- a/atom/app/atom_main_delegate.h +++ b/atom/app/atom_main_delegate.h @@ -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; diff --git a/atom/browser/atom_browser_client.cc b/atom/browser/atom_browser_client.cc index f6237912eb1b..55bb7b020e34 100644 --- a/atom/browser/atom_browser_client.cc +++ b/atom/browser/atom_browser_client.cc @@ -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}, diff --git a/atom/browser/atom_browser_main_parts.cc b/atom/browser/atom_browser_main_parts.cc index e55bb579563c..12a12dac23b3 100644 --- a/atom/browser/atom_browser_main_parts.cc +++ b/atom/browser/atom_browser_main_parts.cc @@ -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 diff --git a/atom/browser/atom_browser_main_parts.h b/atom/browser/atom_browser_main_parts.h index dee3ff6a83e7..930675a8bfa1 100644 --- a/atom/browser/atom_browser_main_parts.h +++ b/atom/browser/atom_browser_main_parts.h @@ -112,7 +112,6 @@ class AtomBrowserMainParts : public content::BrowserMainParts { #endif std::unique_ptr layout_provider_; - std::string custom_locale_; // A fake BrowserProcess object that used to feed the source code from chrome. std::unique_ptr fake_browser_process_;