tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit e613f4df351a21871cfeadf7d5b4043ffad157b1
parent 67bccc13a14ac87062f32ee01083413db4dc866f
Author: Jonathan Kew <jkew@mozilla.com>
Date:   Wed,  5 Nov 2025 22:35:51 +0000

Bug 1946691 - Pass system locales from parent to child during content-process startup. r=platform-i18n-reviewers,nordzilla

This ensures that content processes use the same list of system locales as the parent,
avoiding the issue (on Windows) that sandboxing prevents the content process using
the preferred APIs, and it ends up getting a different (and less useful) list.

(For completeness, we should also modify the Refresh() method to retrieve the system
locales from the parent again, but currently nothing is hooked up to Refresh() on
Windows so it is unimportant for the time being; the user will have to restart the
browser anyhow to pick up changes in the preferred language list.)

Differential Revision: https://phabricator.services.mozilla.com/D271408

Diffstat:
Mdom/ipc/ContentChild.cpp | 3+++
Mdom/ipc/ContentParent.cpp | 3+++
Mdom/ipc/PContent.ipdl | 1+
Mintl/locale/OSPreferences.cpp | 6++++++
Mintl/locale/OSPreferences.h | 7+++++++
5 files changed, 20 insertions(+), 0 deletions(-)

diff --git a/dom/ipc/ContentChild.cpp b/dom/ipc/ContentChild.cpp @@ -96,6 +96,7 @@ #include "mozilla/hal_sandbox/PHalChild.h" #include "mozilla/intl/L10nRegistry.h" #include "mozilla/intl/LocaleService.h" +#include "mozilla/intl/OSPreferences.h" #include "mozilla/ipc/BackgroundChild.h" #include "mozilla/ipc/Endpoint.h" #include "mozilla/ipc/FileDescriptorUtils.h" @@ -1385,6 +1386,8 @@ void ContentChild::InitXPCOM( RecvSetOffline(aXPCOMInit.isOffline()); RecvSetConnectivity(aXPCOMInit.isConnected()); + OSPreferences::GetInstance()->AssignSysLocales(aXPCOMInit.sysLocales()); + LocaleService::GetInstance()->AssignAppLocales(aXPCOMInit.appLocales()); LocaleService::GetInstance()->AssignRequestedLocales( aXPCOMInit.requestedLocales()); diff --git a/dom/ipc/ContentParent.cpp b/dom/ipc/ContentParent.cpp @@ -137,6 +137,7 @@ #include "mozilla/hal_sandbox/PHalParent.h" #include "mozilla/intl/L10nRegistry.h" #include "mozilla/intl/LocaleService.h" +#include "mozilla/intl/OSPreferences.h" #include "mozilla/ipc/BackgroundChild.h" #include "mozilla/ipc/BackgroundParent.h" #include "mozilla/ipc/ByteBuf.h" @@ -2711,6 +2712,8 @@ bool ContentParent::InitInternal(ProcessPriority aInitialPriority) { spellChecker->GetDictionaryList(&xpcomInit.dictionaries()); + OSPreferences::GetInstance()->GetSystemLocales(xpcomInit.sysLocales()); + LocaleService::GetInstance()->GetAppLocalesAsBCP47(xpcomInit.appLocales()); LocaleService::GetInstance()->GetRequestedLocales( xpcomInit.requestedLocales()); diff --git a/dom/ipc/PContent.ipdl b/dom/ipc/PContent.ipdl @@ -386,6 +386,7 @@ struct XPCOMInitData GfxVarUpdate[] gfxNonDefaultVarUpdates; ContentDeviceData contentDeviceData; GfxInfoFeatureStatus[] gfxFeatureStatus; + nsCString[] sysLocales; nsCString[] appLocales; nsCString[] requestedLocales; L10nFileSourceDescriptor[] l10nFileSources; diff --git a/intl/locale/OSPreferences.cpp b/intl/locale/OSPreferences.cpp @@ -59,6 +59,12 @@ OSPreferences* OSPreferences::GetInstance() { } void OSPreferences::Refresh() { + // TODO: in content processes, get system locales from the parent process + // to ensure consistency and avoid depending on APIs that may be blocked + // by sandboxing (see bug 1946691). + // (Not strictly necessary for now as we don't currently use Refresh() on + // Windows.) + nsTArray<nsCString> newLocales; ReadSystemLocales(newLocales); diff --git a/intl/locale/OSPreferences.h b/intl/locale/OSPreferences.h @@ -98,6 +98,13 @@ class OSPreferences : public mozIOSPreferences { */ void Refresh(); + /** + * Set the list of system locales; used by content-process startup. + */ + void AssignSysLocales(const nsTArray<nsCString>& aLocales) { + mSystemLocales = aLocales.Clone(); + } + protected: nsTArray<nsCString> mSystemLocales; nsTArray<nsCString> mRegionalPrefsLocales;