Backed out 2 changesets (bug 1959147) for causing build bustages @txMozillaXSLTProcessor.cpp. CLOSED TREE

Backed out changeset a019651cc743 (bug 1959147)
Backed out changeset d57f3a859955 (bug 1959147)
This commit is contained in:
Goloman Adrian
2025-04-28 12:20:37 +03:00
parent db34c619e8
commit 06a37705e3
12 changed files with 174 additions and 246 deletions

View File

@@ -78,6 +78,16 @@ interface nsIStringBundleService : nsISupports
{
nsIStringBundle createBundle(in string aURLSpec);
/**
* Formats a message string from a status code and status arguments.
* @param aStatus - The status code. This is mapped into a string ID and
* used in the string lookup process.
* @param aStatusArg - The status message argument(s). Multiple arguments
* can be separated by newline ('\n') characters.
* @return the formatted message
*/
AString formatStatusMessage(in nsresult aStatus, in wstring aStatusArg);
/**
* flushes the string bundle cache - useful when the locale changes or
* when we need to get some extra memory back

View File

@@ -25,6 +25,7 @@
#include "nsQueryObject.h"
#include "nsSimpleEnumerator.h"
#include "nsStringStream.h"
#include "mozilla/dom/txXSLTMsgsURL.h"
#include "mozilla/ipc/SharedMemoryHandle.h"
#include "mozilla/BinarySearch.h"
#include "mozilla/ClearOnShutdown.h"
@@ -844,9 +845,8 @@ void nsStringBundleService::RegisterContentBundle(
mSharedBundles.insertBack(cacheEntry);
}
NS_IMETHODIMP
nsStringBundleService::CreateBundle(const char* aURLSpec,
nsIStringBundle** aResult) {
void nsStringBundleService::getStringBundle(const char* aURLSpec,
nsIStringBundle** aResult) {
nsDependentCString key(aURLSpec);
bundleCacheEntry_t* cacheEntry = mBundleMap.Get(key);
@@ -898,8 +898,6 @@ nsStringBundleService::CreateBundle(const char* aURLSpec,
// finally, return the value
*aResult = cacheEntry->mBundle;
NS_ADDREF(*aResult);
return NS_OK;
}
UniquePtr<bundleCacheEntry_t> nsStringBundleService::evictOneEntry() {
@@ -933,3 +931,82 @@ bundleCacheEntry_t* nsStringBundleService::insertIntoCache(
return cacheEntry.release();
}
NS_IMETHODIMP
nsStringBundleService::CreateBundle(const char* aURLSpec,
nsIStringBundle** aResult) {
getStringBundle(aURLSpec, aResult);
return NS_OK;
}
#define GLOBAL_PROPERTIES "chrome://global/locale/global-strres.properties"
nsresult nsStringBundleService::FormatWithBundle(
nsIStringBundle* bundle, nsresult aStatus,
const nsTArray<nsString>& argArray, nsAString& result) {
nsresult rv;
// try looking up the error message with the int key:
uint16_t code = NS_ERROR_GET_CODE(aStatus);
rv = bundle->FormatStringFromID(code, argArray, result);
// If the int key fails, try looking up the default error message. E.g. print:
// An unknown error has occurred (0x804B0003).
if (NS_FAILED(rv)) {
AutoTArray<nsString, 1> otherArgArray;
otherArgArray.AppendElement()->AppendInt(static_cast<uint32_t>(aStatus),
16);
uint16_t code = NS_ERROR_GET_CODE(NS_ERROR_FAILURE);
rv = bundle->FormatStringFromID(code, otherArgArray, result);
}
return rv;
}
NS_IMETHODIMP
nsStringBundleService::FormatStatusMessage(nsresult aStatus,
const char16_t* aStatusArg,
nsAString& result) {
uint32_t i, argCount = 0;
nsCOMPtr<nsIStringBundle> bundle;
// XXX hack for mailnews who has already formatted their messages:
if (aStatus == NS_OK && aStatusArg) {
result.Assign(aStatusArg);
return NS_OK;
}
if (aStatus == NS_OK) {
return NS_ERROR_FAILURE; // no message to format
}
// format the arguments:
const nsDependentString args(aStatusArg);
argCount = args.CountChar(char16_t('\n')) + 1;
NS_ENSURE_ARG(argCount <= 10); // enforce 10-parameter limit
AutoTArray<nsString, 10> argArray;
// convert the aStatusArg into an nsString array
if (argCount == 1) {
argArray.AppendElement(aStatusArg);
} else if (argCount > 1) {
int32_t offset = 0;
for (i = 0; i < argCount; i++) {
int32_t pos = args.FindChar('\n', offset);
if (pos == -1) pos = args.Length();
argArray.AppendElement(Substring(args, offset, pos - offset));
offset = pos + 1;
}
}
switch (NS_ERROR_GET_MODULE(aStatus)) {
case NS_ERROR_MODULE_XSLT:
getStringBundle(XSLT_MSGS_URL, getter_AddRefs(bundle));
break;
default:
getStringBundle(GLOBAL_PROPERTIES, getter_AddRefs(bundle));
break;
}
return FormatWithBundle(bundle, aStatus, argArray, result);
}

View File

@@ -47,6 +47,11 @@ class nsStringBundleService : public nsIStringBundleService,
private:
virtual ~nsStringBundleService();
void getStringBundle(const char* aUrl, nsIStringBundle** aResult);
nsresult FormatWithBundle(nsIStringBundle* bundle, nsresult aStatus,
const nsTArray<nsString>& argArray,
nsAString& result);
void flushBundleCache(bool ignoreShared = true);
mozilla::UniquePtr<bundleCacheEntry_t> evictOneEntry();