Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save allstarschh/aaf0dfad7cf78e68621bf6672518d9e5 to your computer and use it in GitHub Desktop.
Save allstarschh/aaf0dfad7cf78e68621bf6672518d9e5 to your computer and use it in GitHub Desktop.
From 1d652ba5dae756e39f275441d2d077e8d15b507f Mon Sep 17 00:00:00 2001
From: Yoshi Cheng-Hao Huang <allstars.chh@gmail.com>
Date: Wed, 2 Nov 2022 12:15:33 +0100
Subject: Add a EnsureAndLoadStringBundle to preload the resources in main
thread
---
dom/base/nsContentUtils.cpp | 10 ++++++++++
dom/base/nsContentUtils.h | 5 +++++
intl/strres/moz.build | 4 ++++
3 files changed, 19 insertions(+)
diff --git a/dom/base/nsContentUtils.cpp b/dom/base/nsContentUtils.cpp
index c52c73693544e..9ce5a34679b22 100644
--- a/dom/base/nsContentUtils.cpp
+++ b/dom/base/nsContentUtils.cpp
@@ -358,16 +358,17 @@
#include "nsRange.h"
#include "nsRefPtrHashtable.h"
#include "nsSandboxFlags.h"
#include "nsScriptSecurityManager.h"
#include "nsServiceManagerUtils.h"
#include "nsStreamUtils.h"
#include "nsString.h"
#include "nsStringBuffer.h"
+#include "nsStringBundle.h"
#include "nsStringFlags.h"
#include "nsStringFwd.h"
#include "nsStringIterator.h"
#include "nsStringStream.h"
#include "nsTArray.h"
#include "nsTLiteralString.h"
#include "nsTPromiseFlatString.h"
#include "nsTStringRepr.h"
@@ -4041,16 +4042,25 @@ static const char* gPropertiesFiles[nsContentUtils::PropertiesFile_COUNT] = {
"chrome://branding/locale/brand.properties",
"chrome://global/locale/commonDialogs.properties",
"chrome://global/locale/mathml/mathml.properties",
"chrome://global/locale/security/security.properties",
"chrome://necko/locale/necko.properties",
"resource://gre/res/locale/layout/HtmlForm.properties",
"resource://gre/res/locale/dom/dom.properties"};
+/* static */
+nsresult nsContentUtils::EnsureAndLoadStringBundle(PropertiesFile aFile) {
+ 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]) {
if (!sStringBundleService) {
nsresult rv =
CallGetService(NS_STRINGBUNDLE_CONTRACTID, &sStringBundleService);
NS_ENSURE_SUCCESS(rv, rv);
}
diff --git a/dom/base/nsContentUtils.h b/dom/base/nsContentUtils.h
index 4b0ca1ed2d4dd..798f036cd5cbb 100644
--- a/dom/base/nsContentUtils.h
+++ b/dom/base/nsContentUtils.h
@@ -3345,16 +3345,21 @@ class nsContentUtils {
/**
* Returns the object type that the object loading content will actually use
* to load the resource. Used for ORB and loading images into synthetic
* documents.
*/
static uint32_t ResolveObjectType(uint32_t aType);
+ /**
+ * TODO
+ */
+ static nsresult EnsureAndLoadStringBundle(PropertiesFile aFile);
+
private:
static bool InitializeEventTable();
static nsresult EnsureStringBundle(PropertiesFile aFile);
static bool CanCallerAccess(nsIPrincipal* aSubjectPrincipal,
nsIPrincipal* aPrincipal);
diff --git a/intl/strres/moz.build b/intl/strres/moz.build
index 564d3d690ea82..1c420d69cb6b7 100644
--- a/intl/strres/moz.build
+++ b/intl/strres/moz.build
@@ -15,11 +15,15 @@ XPIDL_MODULE = "intl"
UNIFIED_SOURCES += [
"nsStringBundle.cpp",
]
LOCAL_INCLUDES += [
"/xpcom/ds",
]
+EXPORTS += [
+ "nsStringBundle.h"
+]
+
include("/ipc/chromium/chromium-config.mozbuild")
FINAL_LIBRARY = "xul"
--
2.34.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment