Bug 1797506 - Add EnsureAndLoadStringBundle to preload the string bundle on main thread. r=kmag

Differential Revision: https://phabricator.services.mozilla.com/D163309
This commit is contained in:
Yoshi Cheng-Hao Huang 2022-12-12 13:25:09 +00:00
parent 26d2865682
commit c19e34d15c
3 changed files with 22 additions and 0 deletions

View file

@ -365,6 +365,7 @@
#include "nsStreamUtils.h"
#include "nsString.h"
#include "nsStringBuffer.h"
#include "nsStringBundle.h"
#include "nsStringFlags.h"
#include "nsStringFwd.h"
#include "nsStringIterator.h"
@ -4084,6 +4085,16 @@ static const char* gPropertiesFiles[nsContentUtils::PropertiesFile_COUNT] = {
"resource://gre/res/locale/layout/HtmlForm.properties",
"resource://gre/res/locale/dom/dom.properties"};
/* static */
nsresult nsContentUtils::EnsureAndLoadStringBundle(PropertiesFile aFile) {
MOZ_ASSERT(NS_IsMainThread(), "Should be called on main thread.");
nsresult rv = EnsureStringBundle(aFile);
if (NS_FAILED(rv)) {
return rv;
}
return nsStringBundleBase::Cast(sStringBundles[aFile])->LoadProperties();
}
/* static */
nsresult nsContentUtils::EnsureStringBundle(PropertiesFile aFile) {
if (!sStringBundles[aFile]) {

View file

@ -3358,6 +3358,13 @@ class nsContentUtils {
*/
static uint32_t ResolveObjectType(uint32_t aType);
/**
* Create and load the string bundle for the 'aFile'.
* This API is used to preload the string bundle on the main thread so later
* other thread could access it.
*/
static nsresult EnsureAndLoadStringBundle(PropertiesFile aFile);
private:
static bool InitializeEventTable();

View file

@ -20,6 +20,10 @@ LOCAL_INCLUDES += [
"/xpcom/ds",
]
EXPORTS += [
"nsStringBundle.h",
]
include("/ipc/chromium/chromium-config.mozbuild")
FINAL_LIBRARY = "xul"