Backed out 2 changesets (bug 1335983) for build bustage a=backout

Backed out changeset 5a9559ded976 (bug 1335983)
Backed out changeset de2b0d90e2da (bug 1335983)

MozReview-Commit-ID: 377KQDU1QqJ
This commit is contained in:
Wes Kocher 2017-02-07 12:34:30 -08:00
Родитель 64d03c523f
Коммит a9ce32d9a5
16 изменённых файлов: 222 добавлений и 65 удалений

Просмотреть файл

@ -9,6 +9,8 @@
#include "txExpr.h"
#include "txCore.h"
#include "nsCollationCID.h"
#include "nsILocale.h"
#include "nsILocaleService.h"
#include "nsIServiceManager.h"
#include "prmem.h"
@ -33,16 +35,25 @@ nsresult txResultStringComparator::init(const nsAFlatString& aLanguage)
{
nsresult rv;
nsCOMPtr<nsILocaleService> localeService =
do_GetService(NS_LOCALESERVICE_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsILocale> locale;
if (!aLanguage.IsEmpty()) {
rv = localeService->NewLocale(aLanguage,
getter_AddRefs(locale));
}
else {
rv = localeService->GetApplicationLocale(getter_AddRefs(locale));
}
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsICollationFactory> colFactory =
do_CreateInstance(NS_COLLATIONFACTORY_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
if (aLanguage.IsEmpty()) {
rv = colFactory->CreateCollation(getter_AddRefs(mCollation));
} else {
rv = colFactory->CreateCollationForLocale(NS_ConvertUTF16toUTF8(aLanguage), getter_AddRefs(mCollation));
}
rv = colFactory->CreateCollation(locale, getter_AddRefs(mCollation));
NS_ENSURE_SUCCESS(rv, rv);
return NS_OK;

Просмотреть файл

@ -52,6 +52,8 @@
#include "nsIScriptableDateFormat.h"
#include "nsICollation.h"
#include "nsCollationCID.h"
#include "nsILocale.h"
#include "nsILocaleService.h"
#include "nsIConsoleService.h"
#include "nsEscape.h"
@ -123,14 +125,27 @@ nsICollation*
nsXULContentUtils::GetCollation()
{
if (!gCollation) {
nsCOMPtr<nsICollationFactory> colFactory =
do_CreateInstance(NS_COLLATIONFACTORY_CONTRACTID);
if (colFactory) {
rv = colFactory->CreateCollation(&gCollation);
NS_ASSERTION(NS_SUCCEEDED(rv),
"couldn't create collation instance");
nsresult rv;
// get a locale service
nsCOMPtr<nsILocaleService> localeService =
do_GetService(NS_LOCALESERVICE_CONTRACTID, &rv);
if (NS_SUCCEEDED(rv)) {
nsCOMPtr<nsILocale> locale;
rv = localeService->GetApplicationLocale(getter_AddRefs(locale));
if (NS_SUCCEEDED(rv) && locale) {
nsCOMPtr<nsICollationFactory> colFactory =
do_CreateInstance(NS_COLLATIONFACTORY_CONTRACTID);
if (colFactory) {
rv = colFactory->CreateCollation(locale, &gCollation);
NS_ASSERTION(NS_SUCCEEDED(rv),
"couldn't create collation instance");
} else
NS_ERROR("couldn't create instance of collation factory");
} else
NS_ERROR("unable to get application locale");
} else
NS_ERROR("couldn't create instance of collation factory");
NS_ERROR("couldn't get locale factory");
}
return gCollation;

Просмотреть файл

@ -4,6 +4,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "nsCollationMacUC.h"
#include "nsILocaleService.h"
#include "nsIPrefBranch.h"
#include "nsIPrefService.h"
#include "nsIServiceManager.h"
@ -15,6 +16,7 @@ NS_IMPL_ISUPPORTS(nsCollationMacUC, nsICollation)
nsCollationMacUC::nsCollationMacUC()
: mInit(false)
, mHasCollator(false)
, mLocaleICU(nullptr)
, mLastStrength(-1)
, mCollatorICU(nullptr)
{ }
@ -26,6 +28,10 @@ nsCollationMacUC::~nsCollationMacUC()
#endif
CleanUpCollator();
NS_ASSERTION(NS_SUCCEEDED(res), "CleanUpCollator failed");
if (mLocaleICU) {
free(mLocaleICU);
mLocaleICU = nullptr;
}
}
nsresult nsCollationMacUC::ConvertStrength(const int32_t aNSStrength,
@ -62,6 +68,28 @@ nsresult nsCollationMacUC::ConvertStrength(const int32_t aNSStrength,
return NS_OK;
}
nsresult nsCollationMacUC::ConvertLocaleICU(nsILocale* aNSLocale, char** aICULocale)
{
NS_ENSURE_ARG_POINTER(aNSLocale);
NS_ENSURE_ARG_POINTER(aICULocale);
nsAutoString localeString;
nsresult res = aNSLocale->GetCategory(NS_LITERAL_STRING("NSILOCALE_COLLATE"), localeString);
NS_ENSURE_TRUE(NS_SUCCEEDED(res) && !localeString.IsEmpty(),
NS_ERROR_FAILURE);
NS_LossyConvertUTF16toASCII tmp(localeString);
tmp.ReplaceChar('-', '_');
char* locale = (char*)malloc(tmp.Length() + 1);
if (!locale) {
return NS_ERROR_OUT_OF_MEMORY;
}
strcpy(locale, tmp.get());
*aICULocale = locale;
return NS_OK;
}
nsresult nsCollationMacUC::EnsureCollator(const int32_t newStrength)
{
NS_ENSURE_TRUE(mInit, NS_ERROR_NOT_INITIALIZED);
@ -72,9 +100,11 @@ nsresult nsCollationMacUC::EnsureCollator(const int32_t newStrength)
res = CleanUpCollator();
NS_ENSURE_SUCCESS(res, res);
NS_ENSURE_TRUE(mLocaleICU, NS_ERROR_NOT_INITIALIZED);
UErrorCode status;
status = U_ZERO_ERROR;
mCollatorICU = ucol_open(mLocale.get(), &status);
mCollatorICU = ucol_open(mLocaleICU, &status);
NS_ENSURE_TRUE(U_SUCCESS(status), NS_ERROR_FAILURE);
UCollationStrength strength;
@ -112,12 +142,22 @@ nsresult nsCollationMacUC::CleanUpCollator(void)
return NS_OK;
}
NS_IMETHODIMP nsCollationMacUC::Initialize(const nsACString& locale)
NS_IMETHODIMP nsCollationMacUC::Initialize(nsILocale* locale)
{
NS_ENSURE_TRUE((!mInit), NS_ERROR_ALREADY_INITIALIZED);
nsCOMPtr<nsILocale> appLocale;
mLocale = locale;
nsresult rv;
if (!locale) {
nsCOMPtr<nsILocaleService> localeService = do_GetService(NS_LOCALESERVICE_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
rv = localeService->GetApplicationLocale(getter_AddRefs(appLocale));
NS_ENSURE_SUCCESS(rv, rv);
locale = appLocale;
}
rv = ConvertLocaleICU(locale, &mLocaleICU);
NS_ENSURE_SUCCESS(rv, rv);
mInit = true;
return NS_OK;

Просмотреть файл

@ -6,10 +6,9 @@
#ifndef nsCollationMacUC_h_
#define nsCollationMacUC_h_
#include "mozilla/Attributes.h"
#include "nsICollation.h"
#include "nsCollation.h"
#include "nsString.h"
#include "mozilla/Attributes.h"
#include "unicode/ucol.h"
@ -27,6 +26,7 @@ public:
protected:
~nsCollationMacUC();
nsresult ConvertLocaleICU(nsILocale* aNSLocale, char** aICULocale);
nsresult ConvertStrength(const int32_t aStrength,
UCollationStrength* aStrengthOut,
UColAttributeValue* aCaseLevelOut);
@ -36,7 +36,7 @@ protected:
private:
bool mInit;
bool mHasCollator;
nsCString mLocale;
char* mLocaleICU;
int32_t mLastStrength;
UCollator* mCollatorICU;
};

Просмотреть файл

@ -10,7 +10,6 @@
#include "nsIUnicodeEncoder.h"
#include "nsServiceManagerUtils.h"
#include "mozilla/dom/EncodingUtils.h"
#include "mozilla/intl/LocaleService.h"
using mozilla::dom::EncodingUtils;
@ -20,16 +19,7 @@ NS_DEFINE_CID(kCollationCID, NS_COLLATION_CID);
NS_IMPL_ISUPPORTS(nsCollationFactory, nsICollationFactory)
nsresult nsCollationFactory::CreateCollation(nsICollation** instancePtr)
{
nsAutoCString appLocale;
mozilla::intl::LocaleService::GetInstance()->GetAppLocale(appLocale);
return CreateCollationForLocale(appLocale, instancePtr);
}
nsresult
nsCollationFactory::CreateCollationForLocale(const nsACString& locale, nsICollation** instancePtr)
nsresult nsCollationFactory::CreateCollation(nsILocale* locale, nsICollation** instancePtr)
{
// Create a collation interface instance.
//
@ -42,7 +32,6 @@ nsCollationFactory::CreateCollationForLocale(const nsACString& locale, nsICollat
}
inst->Initialize(locale);
*instancePtr = inst;
return res;

Просмотреть файл

@ -14,7 +14,7 @@
class nsIUnicodeEncoder;
// Create a collation interface for the current app's locale.
// Create a collation interface for an input locale.
//
class nsCollationFactory final : public nsICollationFactory {
@ -23,8 +23,7 @@ class nsCollationFactory final : public nsICollationFactory {
public:
NS_DECL_ISUPPORTS
NS_IMETHOD CreateCollation(nsICollation** instancePtr) override;
NS_IMETHOD CreateCollationForLocale(const nsACString& locale, nsICollation** instancePtr) override;
NS_IMETHOD CreateCollation(nsILocale* locale, nsICollation** instancePtr) override;
nsCollationFactory() {}
};

Просмотреть файл

@ -11,18 +11,17 @@ interface nsICollation;
interface nsICollationFactory : nsISupports
{
/**
* Create a new collation for the current application locale.
* Create the collation for a given locale.
*
* @return A new collation.
*/
nsICollation CreateCollation();
/**
* Create a new collation for a given locale.
* Use NULL as the locale parameter to use the user's locale preference
* from the operating system.
*
* @return A new collation.
* @param locale
* The locale for which to create the collation or null to use
* user preference.
* @return A collation for the given locale.
*/
nsICollation CreateCollationForLocale(in ACString locale);
nsICollation CreateCollation(in nsILocale locale);
};
[scriptable, uuid(b0132cc0-3786-4557-9874-910d7def5f93)]
@ -44,7 +43,7 @@ interface nsICollation : nsISupports {
const long kCollationCaseInSensitive = (kCollationCaseInsensitiveAscii | kCollationAccentInsenstive);
// init this interface to a specified locale (should only be called by collation factory)
void initialize(in ACString locale);
void initialize(in nsILocale locale);
// compare two strings
// result is same as strcmp

Просмотреть файл

@ -20,9 +20,11 @@ function run_test()
];
function test(locale, expected) {
var localeSvc = Cc["@mozilla.org/intl/nslocaleservice;1"].
getService(Ci.nsILocaleService);
var collator = Cc["@mozilla.org/intl/collation-factory;1"].
createInstance(Ci.nsICollationFactory).
CreateCollationForLocale(locale);
CreateCollation(localeSvc.newLocale(locale));
var strength = Ci.nsICollation.kCollationStrengthDefault;
var actual = input.sort((x, y) => collator.compareString(strength, x,y));
deepEqual(actual, expected, locale);

Просмотреть файл

@ -8,6 +8,7 @@
#include "nsCollationUnix.h"
#include "nsIServiceManager.h"
#include "nsIComponentManager.h"
#include "nsILocaleService.h"
#include "nsIPlatformCharset.h"
#include "nsPosixLocale.h"
#include "nsCOMPtr.h"
@ -43,7 +44,7 @@ nsCollationUnix::~nsCollationUnix()
NS_IMPL_ISUPPORTS(nsCollationUnix, nsICollation)
nsresult nsCollationUnix::Initialize(const nsACString& locale)
nsresult nsCollationUnix::Initialize(nsILocale* locale)
{
#define kPlatformLocaleLength 64
NS_ASSERTION(!mCollation, "Should only be initialized once");
@ -52,12 +53,46 @@ nsresult nsCollationUnix::Initialize(const nsACString& locale)
mCollation = new nsCollation;
nsCOMPtr <nsIPlatformCharset> platformCharset = do_GetService(NS_PLATFORMCHARSET_CONTRACTID, &res);
if (NS_SUCCEEDED(res)) {
nsAutoCString mappedCharset;
res = platformCharset->GetDefaultCharsetForLocale(NS_ConvertUTF8toUTF16(locale), mappedCharset);
// default platform locale
mLocale.Assign('C');
nsAutoString localeStr;
NS_NAMED_LITERAL_STRING(aCategory, "NSILOCALE_COLLATE##PLATFORM");
// get locale string, use app default if no locale specified
if (locale == nullptr) {
nsCOMPtr<nsILocaleService> localeService =
do_GetService(NS_LOCALESERVICE_CONTRACTID, &res);
if (NS_SUCCEEDED(res)) {
mCollation->SetCharset(mappedCharset.get());
nsCOMPtr<nsILocale> appLocale;
res = localeService->GetApplicationLocale(getter_AddRefs(appLocale));
if (NS_SUCCEEDED(res)) {
res = appLocale->GetCategory(aCategory, localeStr);
NS_ASSERTION(NS_SUCCEEDED(res), "failed to get app locale info");
}
}
}
else {
res = locale->GetCategory(aCategory, localeStr);
NS_ASSERTION(NS_SUCCEEDED(res), "failed to get locale info");
}
// Get platform locale and charset name from locale, if available
if (NS_SUCCEEDED(res)) {
// keep the same behavior as 4.x as well as avoiding Linux collation key problem
if (localeStr.LowerCaseEqualsLiteral("en_us")) { // note: locale is in platform format
localeStr.Assign('C');
}
nsPosixLocale::GetPlatformLocale(localeStr, mLocale);
nsCOMPtr <nsIPlatformCharset> platformCharset = do_GetService(NS_PLATFORMCHARSET_CONTRACTID, &res);
if (NS_SUCCEEDED(res)) {
nsAutoCString mappedCharset;
res = platformCharset->GetDefaultCharsetForLocale(localeStr, mappedCharset);
if (NS_SUCCEEDED(res)) {
mCollation->SetCharset(mappedCharset.get());
}
}
}

Просмотреть файл

@ -7,6 +7,7 @@
#include "nsCollationWin.h"
#include "nsIServiceManager.h"
#include "nsIComponentManager.h"
#include "nsILocaleService.h"
#include "nsIPlatformCharset.h"
#include "nsWin32Locale.h"
#include "nsCOMPtr.h"
@ -29,7 +30,7 @@ nsCollationWin::~nsCollationWin()
delete mCollation;
}
nsresult nsCollationWin::Initialize(const nsACString& locale)
nsresult nsCollationWin::Initialize(nsILocale* locale)
{
NS_ASSERTION(!mCollation, "Should only be initialized once.");
@ -37,14 +38,32 @@ nsresult nsCollationWin::Initialize(const nsACString& locale)
mCollation = new nsCollation;
NS_ConvertASCIItoUTF16 wideLocale(locale);
// default LCID (en-US)
mLCID = 1033;
nsAutoString localeStr;
// get locale string, use app default if no locale specified
if (!locale) {
nsCOMPtr<nsILocaleService> localeService =
do_GetService(NS_LOCALESERVICE_CONTRACTID);
if (localeService) {
nsCOMPtr<nsILocale> appLocale;
res = localeService->GetApplicationLocale(getter_AddRefs(appLocale));
if (NS_SUCCEEDED(res)) {
res = appLocale->GetCategory(NS_LITERAL_STRING("NSILOCALE_COLLATE"),
localeStr);
}
}
}
else {
res = locale->GetCategory(NS_LITERAL_STRING("NSILOCALE_COLLATE"),
localeStr);
}
// Get LCID and charset name from locale, if available
LCID lcid;
res = nsWin32Locale::GetPlatformLocale(wideLocale, &lcid);
res = nsWin32Locale::GetPlatformLocale(localeStr, &lcid);
if (NS_SUCCEEDED(res)) {
mLCID = lcid;
}
@ -53,7 +72,7 @@ nsresult nsCollationWin::Initialize(const nsACString& locale)
do_GetService(NS_PLATFORMCHARSET_CONTRACTID);
if (platformCharset) {
nsAutoCString mappedCharset;
res = platformCharset->GetDefaultCharsetForLocale(wideLocale, mappedCharset);
res = platformCharset->GetDefaultCharsetForLocale(localeStr, mappedCharset);
if (NS_SUCCEEDED(res)) {
mCollation->SetCharset(mappedCharset.get());
}

Просмотреть файл

@ -126,11 +126,21 @@ private:
nsresult rv;
if (!mCollation) {
nsCOMPtr<nsICollationFactory> colFactory =
do_CreateInstance(NS_COLLATIONFACTORY_CONTRACTID, &rv);
nsCOMPtr<nsILocaleService> localeService =
do_GetService(NS_LOCALESERVICE_CONTRACTID, &rv);
if (NS_SUCCEEDED(rv)) {
rv = colFactory->CreateCollation(getter_AddRefs(mCollation));
nsCOMPtr<nsILocale> locale;
rv = localeService->GetApplicationLocale(getter_AddRefs(locale));
if (NS_SUCCEEDED(rv)) {
nsCOMPtr<nsICollationFactory> colFactory =
do_CreateInstance(NS_COLLATIONFACTORY_CONTRACTID, &rv);
if (NS_SUCCEEDED(rv)) {
rv = colFactory->CreateCollation(locale, getter_AddRefs(mCollation));
}
}
}
if (NS_FAILED(rv)) {

Просмотреть файл

@ -22,6 +22,8 @@
#ifdef THREADSAFE_I18N
#include "nsCollationCID.h"
#include "nsICollation.h"
#include "nsILocale.h"
#include "nsILocaleService.h"
#endif
#include "nsIFile.h"
#include "nsURLHelper.h"
@ -118,12 +120,20 @@ nsDirectoryIndexStream::Init(nsIFile* aDir)
}
#ifdef THREADSAFE_I18N
nsCOMPtr<nsILocaleService> ls = do_GetService(NS_LOCALESERVICE_CONTRACTID,
&rv);
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsILocale> locale;
rv = ls->GetApplicationLocale(getter_AddRefs(locale));
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsICollationFactory> cf = do_CreateInstance(NS_COLLATIONFACTORY_CONTRACTID,
&rv);
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsICollation> coll;
rv = cf->CreateCollation(getter_AddRefs(coll));
rv = cf->CreateCollation(locale, getter_AddRefs(coll));
if (NS_FAILED(rv)) return rv;
mArray.Sort(compare, coll);

Просмотреть файл

@ -14,6 +14,8 @@
#include "nsEmbedCID.h"
#include "nsThreadUtils.h"
#include "mozStoragePrivateHelpers.h"
#include "nsILocale.h"
#include "nsILocaleService.h"
#include "nsIXPConnect.h"
#include "nsIObserverService.h"
#include "nsIPropertyBag2.h"
@ -606,6 +608,19 @@ Service::getLocaleCollation()
if (mLocaleCollation)
return mLocaleCollation;
nsCOMPtr<nsILocaleService> svc(do_GetService(NS_LOCALESERVICE_CONTRACTID));
if (!svc) {
NS_WARNING("Could not get locale service");
return nullptr;
}
nsCOMPtr<nsILocale> appLocale;
nsresult rv = svc->GetApplicationLocale(getter_AddRefs(appLocale));
if (NS_FAILED(rv)) {
NS_WARNING("Could not get application locale");
return nullptr;
}
nsCOMPtr<nsICollationFactory> collFact =
do_CreateInstance(NS_COLLATIONFACTORY_CONTRACTID);
if (!collFact) {
@ -613,7 +628,7 @@ Service::getLocaleCollation()
return nullptr;
}
nsresult rv = collFact->CreateCollation(getter_AddRefs(mLocaleCollation));
rv = collFact->CreateCollation(appLocale, getter_AddRefs(mLocaleCollation));
if (NS_FAILED(rv)) {
NS_WARNING("Could not create collation");
return nullptr;

Просмотреть файл

@ -232,9 +232,11 @@ function setup() {
gUtf16Conn = createUtf16Database();
initTableWithStrings(gStrings, gUtf16Conn);
let localeSvc = Cc["@mozilla.org/intl/nslocaleservice;1"].
getService(Ci.nsILocaleService);
let collFact = Cc["@mozilla.org/intl/collation-factory;1"].
createInstance(Ci.nsICollationFactory);
gLocaleCollation = collFact.CreateCollation();
gLocaleCollation = collFact.CreateCollation(localeSvc.getApplicationLocale());
}
// Test Runs

Просмотреть файл

@ -20,6 +20,7 @@
#include "nsTArray.h"
#include "nsCollationCID.h"
#include "nsILocaleService.h"
#include "nsNetUtil.h"
#include "nsPrintfCString.h"
#include "nsPromiseFlatString.h"
@ -4478,11 +4479,18 @@ nsNavHistory::GetCollation()
if (mCollation)
return mCollation;
// locale
nsCOMPtr<nsILocale> locale;
nsCOMPtr<nsILocaleService> ls(do_GetService(NS_LOCALESERVICE_CONTRACTID));
NS_ENSURE_TRUE(ls, nullptr);
nsresult rv = ls->GetApplicationLocale(getter_AddRefs(locale));
NS_ENSURE_SUCCESS(rv, nullptr);
// collation
nsCOMPtr<nsICollationFactory> cfact =
do_CreateInstance(NS_COLLATIONFACTORY_CONTRACTID);
NS_ENSURE_TRUE(cfact, nullptr);
nsresult rv = cfact->CreateCollation(getter_AddRefs(mCollation));
rv = cfact->CreateCollation(locale, getter_AddRefs(mCollation));
NS_ENSURE_SUCCESS(rv, nullptr);
return mCollation;

Просмотреть файл

@ -3868,9 +3868,12 @@ SearchService.prototype = {
alphaEngines.push(this._engines[engine.name]);
}
let locale = Cc["@mozilla.org/intl/nslocaleservice;1"]
.getService(Ci.nsILocaleService)
.newLocale(getLocale());
let collation = Cc["@mozilla.org/intl/collation-factory;1"]
.createInstance(Ci.nsICollationFactory)
.CreateCollation();
.CreateCollation(locale);
const strength = Ci.nsICollation.kCollationCaseInsensitiveAscii;
let comparator = (a, b) => collation.compareString(strength, a.name, b.name);
alphaEngines.sort(comparator);