mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-10 17:24:29 +00:00
Bug 1671764 - Part 1. Use ACString for dictionary language instead. r=masayuki
Actually, our locale service doesn't use UTF-16 for locale name and it will be ASCII. Although dictionary name of spell checker is locale/language name, it still uses UTF-16. To use locale API, I should replace it with `ACString`. Differential Revision: https://phabricator.services.mozilla.com/D99336
This commit is contained in:
parent
c5e26aebfa
commit
ddeba05428
@ -1639,7 +1639,7 @@ mozilla::ipc::IPCResult ContentChild::RecvSetProcessSandbox(
|
||||
CrashReporter::Annotation::ContentSandboxCapabilities,
|
||||
static_cast<int>(SandboxInfo::Get().AsInteger()));
|
||||
# endif /* XP_LINUX && !OS_ANDROID */
|
||||
#endif /* MOZ_SANDBOX */
|
||||
#endif /* MOZ_SANDBOX */
|
||||
|
||||
return IPC_OK();
|
||||
}
|
||||
@ -1751,7 +1751,8 @@ mozilla::ipc::IPCResult ContentChild::RecvConstructBrowser(
|
||||
return IPC_OK();
|
||||
}
|
||||
|
||||
void ContentChild::GetAvailableDictionaries(nsTArray<nsString>& aDictionaries) {
|
||||
void ContentChild::GetAvailableDictionaries(
|
||||
nsTArray<nsCString>& aDictionaries) {
|
||||
aDictionaries = mAvailableDictionaries.Clone();
|
||||
}
|
||||
|
||||
@ -2158,7 +2159,7 @@ void ContentChild::ActorDestroy(ActorDestroyReason why) {
|
||||
CrashReporterClient::DestroySingleton();
|
||||
|
||||
XRE_ShutdownChildProcess();
|
||||
#endif // NS_FREE_PERMANENT_DATA
|
||||
#endif // NS_FREE_PERMANENT_DATA
|
||||
}
|
||||
|
||||
void ContentChild::ProcessingError(Result aCode, const char* aReason) {
|
||||
@ -2388,7 +2389,7 @@ mozilla::ipc::IPCResult ContentChild::RecvGeolocationError(
|
||||
}
|
||||
|
||||
mozilla::ipc::IPCResult ContentChild::RecvUpdateDictionaryList(
|
||||
nsTArray<nsString>&& aDictionaries) {
|
||||
nsTArray<nsCString>&& aDictionaries) {
|
||||
mAvailableDictionaries = std::move(aDictionaries);
|
||||
mozInlineSpellChecker::UpdateCanEnableInlineSpellChecking();
|
||||
return IPC_OK();
|
||||
|
@ -361,7 +361,7 @@ class ContentChild final : public PContentChild,
|
||||
mozilla::ipc::IPCResult RecvGeolocationError(const uint16_t& errorCode);
|
||||
|
||||
mozilla::ipc::IPCResult RecvUpdateDictionaryList(
|
||||
nsTArray<nsString>&& aDictionaries);
|
||||
nsTArray<nsCString>&& aDictionaries);
|
||||
|
||||
mozilla::ipc::IPCResult RecvUpdateFontList(
|
||||
nsTArray<SystemFontListEntry>&& aFontList);
|
||||
@ -504,7 +504,7 @@ class ContentChild final : public PContentChild,
|
||||
|
||||
FORWARD_SHMEM_ALLOCATOR_TO(PContentChild)
|
||||
|
||||
void GetAvailableDictionaries(nsTArray<nsString>& aDictionaries);
|
||||
void GetAvailableDictionaries(nsTArray<nsCString>& aDictionaries);
|
||||
|
||||
PWebrtcGlobalChild* AllocPWebrtcGlobalChild();
|
||||
|
||||
@ -850,7 +850,7 @@ class ContentChild final : public PContentChild,
|
||||
|
||||
nsTHashtable<nsPtrHashKey<nsIObserver>> mIdleObservers;
|
||||
|
||||
nsTArray<nsString> mAvailableDictionaries;
|
||||
nsTArray<nsCString> mAvailableDictionaries;
|
||||
|
||||
// Temporary storage for a list of available fonts, passed from the
|
||||
// parent process and used to initialize gfx in the child. Currently used
|
||||
|
@ -4825,7 +4825,7 @@ void ContentParent::NotifyUpdatedDictionaries() {
|
||||
RefPtr<mozSpellChecker> spellChecker(mozSpellChecker::Create());
|
||||
MOZ_ASSERT(spellChecker, "No spell checker?");
|
||||
|
||||
nsTArray<nsString> dictionaries;
|
||||
nsTArray<nsCString> dictionaries;
|
||||
spellChecker->GetDictionaryList(&dictionaries);
|
||||
|
||||
for (auto* cp : AllProcesses(eLive)) {
|
||||
|
@ -315,7 +315,7 @@ struct XPCOMInitData
|
||||
int32_t captivePortalState;
|
||||
bool isLangRTL;
|
||||
bool haveBidiKeyboards;
|
||||
nsString[] dictionaries;
|
||||
nsCString[] dictionaries;
|
||||
ClipboardCapabilities clipboardCaps;
|
||||
DomainPolicyClone domainPolicy;
|
||||
nsIURI userContentSheetURL;
|
||||
@ -600,7 +600,7 @@ child:
|
||||
|
||||
async GeolocationError(uint16_t errorCode);
|
||||
|
||||
async UpdateDictionaryList(nsString[] dictionaries);
|
||||
async UpdateDictionaryList(nsCString[] dictionaries);
|
||||
|
||||
async UpdateFontList(SystemFontListEntry[] fontList);
|
||||
|
||||
|
@ -109,17 +109,17 @@ interface nsIEditorSpellCheck : nsISupports
|
||||
*
|
||||
* @see mozISpellCheckingEngine::GetDictionaryList
|
||||
*/
|
||||
Array<AString> GetDictionaryList();
|
||||
Array<ACString> GetDictionaryList();
|
||||
|
||||
/**
|
||||
* @see mozSpellChecker::GetCurrentDictionary
|
||||
*/
|
||||
AString GetCurrentDictionary();
|
||||
ACString GetCurrentDictionary();
|
||||
|
||||
/**
|
||||
* @see mozSpellChecker::SetCurrentDictionary
|
||||
*/
|
||||
void SetCurrentDictionary(in AString dictionary);
|
||||
void SetCurrentDictionary(in ACString dictionary);
|
||||
|
||||
/**
|
||||
* Call this to free up the spell checking object. It will also save the
|
||||
|
@ -13,6 +13,7 @@
|
||||
#include "mozilla/dom/Selection.h"
|
||||
#include "mozilla/dom/StaticRange.h"
|
||||
#include "mozilla/intl/LocaleService.h" // for retrieving app locale
|
||||
#include "mozilla/intl/MozLocale.h" // for mozilla::intl::Locale
|
||||
#include "mozilla/mozalloc.h" // for operator delete, etc
|
||||
#include "mozilla/mozSpellChecker.h" // for mozSpellChecker
|
||||
#include "mozilla/Preferences.h" // for Preferences
|
||||
@ -198,7 +199,7 @@ DictionaryFetcher::Fetch(nsIEditor* aEditor) {
|
||||
* Stores the current dictionary for aEditor's document URL.
|
||||
*/
|
||||
static nsresult StoreCurrentDictionary(EditorBase* aEditorBase,
|
||||
const nsAString& aDictionary) {
|
||||
const nsACString& aDictionary) {
|
||||
NS_ENSURE_ARG_POINTER(aEditorBase);
|
||||
|
||||
nsresult rv;
|
||||
@ -213,7 +214,7 @@ static nsresult StoreCurrentDictionary(EditorBase* aEditorBase,
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
RefPtr<nsVariant> prefValue = new nsVariant();
|
||||
prefValue->SetAsAString(aDictionary);
|
||||
prefValue->SetAsAString(NS_ConvertUTF8toUTF16(aDictionary));
|
||||
|
||||
nsCOMPtr<nsIContentPrefService2> contentPrefService =
|
||||
do_GetService(NS_CONTENT_PREF_SERVICE_CONTRACTID);
|
||||
@ -288,7 +289,7 @@ EditorSpellCheck::CanSpellCheck(bool* aCanSpellCheck) {
|
||||
spellChecker = mozSpellChecker::Create();
|
||||
MOZ_ASSERT(spellChecker);
|
||||
}
|
||||
nsTArray<nsString> dictList;
|
||||
nsTArray<nsCString> dictList;
|
||||
nsresult rv = spellChecker->GetDictionaryList(&dictList);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
@ -506,21 +507,21 @@ EditorSpellCheck::RemoveWordFromDictionary(const nsAString& aWord) {
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
EditorSpellCheck::GetDictionaryList(nsTArray<nsString>& aList) {
|
||||
EditorSpellCheck::GetDictionaryList(nsTArray<nsCString>& aList) {
|
||||
NS_ENSURE_TRUE(mSpellChecker, NS_ERROR_NOT_INITIALIZED);
|
||||
|
||||
return mSpellChecker->GetDictionaryList(&aList);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
EditorSpellCheck::GetCurrentDictionary(nsAString& aDictionary) {
|
||||
EditorSpellCheck::GetCurrentDictionary(nsACString& aDictionary) {
|
||||
NS_ENSURE_TRUE(mSpellChecker, NS_ERROR_NOT_INITIALIZED);
|
||||
|
||||
return mSpellChecker->GetCurrentDictionary(aDictionary);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
EditorSpellCheck::SetCurrentDictionary(const nsAString& aDictionary) {
|
||||
EditorSpellCheck::SetCurrentDictionary(const nsACString& aDictionary) {
|
||||
NS_ENSURE_TRUE(mSpellChecker, NS_ERROR_NOT_INITIALIZED);
|
||||
|
||||
RefPtr<EditorSpellCheck> kungFuDeathGrip = this;
|
||||
@ -539,7 +540,7 @@ EditorSpellCheck::SetCurrentDictionary(const nsAString& aDictionary) {
|
||||
if (!aDictionary.IsEmpty() &&
|
||||
(mPreferredLang.IsEmpty() ||
|
||||
!mPreferredLang.Equals(aDictionary,
|
||||
nsCaseInsensitiveStringComparator))) {
|
||||
nsCaseInsensitiveCStringComparator))) {
|
||||
// When user sets dictionary manually, we store this value associated
|
||||
// with editor url, if it doesn't match the document language exactly.
|
||||
// For example on "en" sites, we need to store "en-GB", otherwise
|
||||
@ -548,7 +549,7 @@ EditorSpellCheck::SetCurrentDictionary(const nsAString& aDictionary) {
|
||||
StoreCurrentDictionary(mEditor, aDictionary);
|
||||
#ifdef DEBUG_DICT
|
||||
printf("***** Writing content preferences for |%s|\n",
|
||||
NS_ConvertUTF16toUTF8(aDictionary).get());
|
||||
aDictionary.get());
|
||||
#endif
|
||||
} else {
|
||||
// If user sets a dictionary matching the language defined by
|
||||
@ -557,7 +558,7 @@ EditorSpellCheck::SetCurrentDictionary(const nsAString& aDictionary) {
|
||||
ClearCurrentDictionary(mEditor);
|
||||
#ifdef DEBUG_DICT
|
||||
printf("***** Clearing content preferences for |%s|\n",
|
||||
NS_ConvertUTF16toUTF8(aDictionary).get());
|
||||
aDictionary.get());
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -569,10 +570,10 @@ EditorSpellCheck::SetCurrentDictionary(const nsAString& aDictionary) {
|
||||
// necessary to stop libpref from throwing errors. But this should
|
||||
// probably be handled in a better way.
|
||||
if (XRE_IsParentProcess()) {
|
||||
Preferences::SetString("spellchecker.dictionary", aDictionary);
|
||||
Preferences::SetCString("spellchecker.dictionary", aDictionary);
|
||||
#ifdef DEBUG_DICT
|
||||
printf("***** Possibly storing spellchecker.dictionary |%s|\n",
|
||||
NS_ConvertUTF16toUTF8(aDictionary).get());
|
||||
aDictionary.get());
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@ -664,30 +665,30 @@ EditorSpellCheck::UpdateCurrentDictionary(
|
||||
|
||||
// Helper function that iterates over the list of dictionaries and sets the one
|
||||
// that matches based on a given comparison type.
|
||||
void EditorSpellCheck::BuildDictionaryList(const nsAString& aDictName,
|
||||
const nsTArray<nsString>& aDictList,
|
||||
void EditorSpellCheck::BuildDictionaryList(const nsACString& aDictName,
|
||||
const nsTArray<nsCString>& aDictList,
|
||||
enum dictCompare aCompareType,
|
||||
nsTArray<nsString>& aOutList) {
|
||||
for (uint32_t i = 0; i < aDictList.Length(); i++) {
|
||||
nsAutoString dictStr(aDictList.ElementAt(i));
|
||||
nsTArray<nsCString>& aOutList) {
|
||||
for (const auto& dictStr : aDictList) {
|
||||
bool equals = false;
|
||||
switch (aCompareType) {
|
||||
case DICT_NORMAL_COMPARE:
|
||||
equals = aDictName.Equals(dictStr);
|
||||
break;
|
||||
case DICT_COMPARE_CASE_INSENSITIVE:
|
||||
equals = aDictName.Equals(dictStr, nsCaseInsensitiveStringComparator);
|
||||
equals = aDictName.Equals(dictStr, nsCaseInsensitiveCStringComparator);
|
||||
break;
|
||||
case DICT_COMPARE_DASHMATCH:
|
||||
equals = nsStyleUtil::DashMatchCompare(
|
||||
dictStr, aDictName, nsCaseInsensitiveStringComparator);
|
||||
NS_ConvertUTF8toUTF16(dictStr), NS_ConvertUTF8toUTF16(aDictName),
|
||||
nsCaseInsensitiveStringComparator);
|
||||
break;
|
||||
}
|
||||
if (equals) {
|
||||
aOutList.AppendElement(dictStr);
|
||||
#ifdef DEBUG_DICT
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
printf("***** Trying |%s|.\n", NS_ConvertUTF16toUTF8(dictStr).get());
|
||||
printf("***** Trying |%s|.\n", dictStr.get());
|
||||
}
|
||||
#endif
|
||||
// We always break here. We tried to set the dictionary to an existing
|
||||
@ -739,23 +740,22 @@ nsresult EditorSpellCheck::DictionaryFetched(DictionaryFetcher* aFetcher) {
|
||||
// Get the language from the element or its closest parent according to:
|
||||
// https://html.spec.whatwg.org/#attr-lang
|
||||
// This is used in SetCurrentDictionary.
|
||||
mPreferredLang.Assign(aFetcher->mRootContentLang);
|
||||
CopyUTF16toUTF8(aFetcher->mRootContentLang, mPreferredLang);
|
||||
#ifdef DEBUG_DICT
|
||||
printf("***** mPreferredLang (element) |%s|\n",
|
||||
NS_ConvertUTF16toUTF8(mPreferredLang).get());
|
||||
printf("***** mPreferredLang (element) |%s|\n", mPreferredLang.get());
|
||||
#endif
|
||||
|
||||
// If no luck, try the "Content-Language" header.
|
||||
if (mPreferredLang.IsEmpty()) {
|
||||
mPreferredLang.Assign(aFetcher->mRootDocContentLang);
|
||||
CopyUTF16toUTF8(aFetcher->mRootDocContentLang, mPreferredLang);
|
||||
#ifdef DEBUG_DICT
|
||||
printf("***** mPreferredLang (content-language) |%s|\n",
|
||||
NS_ConvertUTF16toUTF8(mPreferredLang).get());
|
||||
mPreferredLang.get());
|
||||
#endif
|
||||
}
|
||||
|
||||
// We obtain a list of available dictionaries.
|
||||
AutoTArray<nsString, 8> dictList;
|
||||
AutoTArray<nsCString, 8> dictList;
|
||||
nsresult rv = mSpellChecker->GetDictionaryList(&dictList);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
EndUpdateDictionary();
|
||||
@ -769,13 +769,13 @@ nsresult EditorSpellCheck::DictionaryFetched(DictionaryFetcher* aFetcher) {
|
||||
// If we successfully fetched a dictionary from content prefs, do not go
|
||||
// further. Use this exact dictionary.
|
||||
// Don't use content preferences for editor with eEditorMailMask flag.
|
||||
nsAutoString dictName;
|
||||
nsAutoCString dictName;
|
||||
uint32_t flags;
|
||||
mEditor->GetFlags(&flags);
|
||||
if (!(flags & nsIEditor::eEditorMailMask)) {
|
||||
dictName.Assign(aFetcher->mDictionary);
|
||||
CopyUTF16toUTF8(aFetcher->mDictionary, dictName);
|
||||
if (!dictName.IsEmpty()) {
|
||||
AutoTArray<nsString, 1> tryDictList;
|
||||
AutoTArray<nsCString, 1> tryDictList;
|
||||
BuildDictionaryList(dictName, dictList, DICT_NORMAL_COMPARE, tryDictList);
|
||||
|
||||
RefPtr<EditorSpellCheck> self = this;
|
||||
@ -786,7 +786,7 @@ nsresult EditorSpellCheck::DictionaryFetched(DictionaryFetcher* aFetcher) {
|
||||
[self, fetcher]() {
|
||||
#ifdef DEBUG_DICT
|
||||
printf("***** Assigned from content preferences |%s|\n",
|
||||
NS_ConvertUTF16toUTF8(dictName).get());
|
||||
dictName.get());
|
||||
#endif
|
||||
// We take an early exit here, so let's not forget to clear
|
||||
// the word list.
|
||||
@ -818,10 +818,10 @@ nsresult EditorSpellCheck::DictionaryFetched(DictionaryFetcher* aFetcher) {
|
||||
void EditorSpellCheck::SetFallbackDictionary(DictionaryFetcher* aFetcher) {
|
||||
MOZ_ASSERT(mUpdateDictionaryRunning);
|
||||
|
||||
AutoTArray<nsString, 6> tryDictList;
|
||||
AutoTArray<nsCString, 6> tryDictList;
|
||||
|
||||
// We obtain a list of available dictionaries.
|
||||
AutoTArray<nsString, 8> dictList;
|
||||
AutoTArray<nsCString, 8> dictList;
|
||||
nsresult rv = mSpellChecker->GetDictionaryList(&dictList);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
EndUpdateDictionary();
|
||||
@ -834,15 +834,14 @@ void EditorSpellCheck::SetFallbackDictionary(DictionaryFetcher* aFetcher) {
|
||||
// Priority 2:
|
||||
// After checking the content preferences, we use the language of the element
|
||||
// or document.
|
||||
nsAutoString dictName(mPreferredLang);
|
||||
nsAutoCString dictName(mPreferredLang);
|
||||
#ifdef DEBUG_DICT
|
||||
printf("***** Assigned from element/doc |%s|\n",
|
||||
NS_ConvertUTF16toUTF8(dictName).get());
|
||||
printf("***** Assigned from element/doc |%s|\n", dictName.get());
|
||||
#endif
|
||||
|
||||
// Get the preference value.
|
||||
nsAutoString preferredDict;
|
||||
Preferences::GetLocalizedString("spellchecker.dictionary", preferredDict);
|
||||
nsAutoCString preferredDict;
|
||||
Preferences::GetLocalizedCString("spellchecker.dictionary", preferredDict);
|
||||
|
||||
if (!dictName.IsEmpty()) {
|
||||
// RFC 5646 explicitly states that matches should be case-insensitive.
|
||||
@ -850,29 +849,24 @@ void EditorSpellCheck::SetFallbackDictionary(DictionaryFetcher* aFetcher) {
|
||||
tryDictList);
|
||||
|
||||
#ifdef DEBUG_DICT
|
||||
printf("***** Trying from element/doc |%s| \n",
|
||||
NS_ConvertUTF16toUTF8(dictName).get());
|
||||
printf("***** Trying from element/doc |%s| \n", dictName.get());
|
||||
#endif
|
||||
|
||||
// Required dictionary was not available. Try to get a dictionary
|
||||
// matching at least language part of dictName.
|
||||
nsAutoString langCode;
|
||||
int32_t dashIdx = dictName.FindChar('-');
|
||||
if (dashIdx != -1) {
|
||||
langCode.Assign(Substring(dictName, 0, dashIdx));
|
||||
} else {
|
||||
langCode.Assign(dictName);
|
||||
}
|
||||
mozilla::intl::Locale loc = mozilla::intl::Locale(dictName);
|
||||
nsAutoCString langCode(loc.GetLanguage());
|
||||
|
||||
// Try dictionary.spellchecker preference, if it starts with langCode,
|
||||
// so we don't just get any random dictionary matching the language.
|
||||
if (!preferredDict.IsEmpty() &&
|
||||
nsStyleUtil::DashMatchCompare(preferredDict, langCode,
|
||||
nsStyleUtil::DashMatchCompare(NS_ConvertUTF8toUTF16(preferredDict),
|
||||
NS_ConvertUTF8toUTF16(langCode),
|
||||
nsTDefaultStringComparator)) {
|
||||
#ifdef DEBUG_DICT
|
||||
printf(
|
||||
"***** Trying preference value |%s| since it matches language code\n",
|
||||
NS_ConvertUTF16toUTF8(preferredDict).get());
|
||||
preferredDict.get());
|
||||
#endif
|
||||
BuildDictionaryList(preferredDict, dictList,
|
||||
DICT_COMPARE_CASE_INSENSITIVE, tryDictList);
|
||||
@ -881,7 +875,7 @@ void EditorSpellCheck::SetFallbackDictionary(DictionaryFetcher* aFetcher) {
|
||||
// Use any dictionary with the required language.
|
||||
#ifdef DEBUG_DICT
|
||||
printf("***** Trying to find match for language code |%s|\n",
|
||||
NS_ConvertUTF16toUTF8(langCode).get());
|
||||
langCode.get());
|
||||
#endif
|
||||
BuildDictionaryList(langCode, dictList, DICT_COMPARE_DASHMATCH,
|
||||
tryDictList);
|
||||
@ -892,8 +886,7 @@ void EditorSpellCheck::SetFallbackDictionary(DictionaryFetcher* aFetcher) {
|
||||
// try the user preference next.
|
||||
if (!preferredDict.IsEmpty()) {
|
||||
#ifdef DEBUG_DICT
|
||||
printf("***** Trying preference value |%s|\n",
|
||||
NS_ConvertUTF16toUTF8(preferredDict).get());
|
||||
printf("***** Trying preference value |%s|\n", preferredDict.get());
|
||||
#endif
|
||||
BuildDictionaryList(preferredDict, dictList, DICT_NORMAL_COMPARE,
|
||||
tryDictList);
|
||||
@ -901,12 +894,9 @@ void EditorSpellCheck::SetFallbackDictionary(DictionaryFetcher* aFetcher) {
|
||||
|
||||
// Priority 4:
|
||||
// As next fallback, try the current locale.
|
||||
nsAutoCString utf8DictName;
|
||||
LocaleService::GetInstance()->GetAppLocaleAsBCP47(utf8DictName);
|
||||
|
||||
CopyUTF8toUTF16(utf8DictName, dictName);
|
||||
LocaleService::GetInstance()->GetAppLocaleAsBCP47(dictName);
|
||||
#ifdef DEBUG_DICT
|
||||
printf("***** Trying locale |%s|\n", NS_ConvertUTF16toUTF8(dictName).get());
|
||||
printf("***** Trying locale |%s|\n", dictName.get());
|
||||
#endif
|
||||
BuildDictionaryList(dictName, dictList, DICT_COMPARE_CASE_INSENSITIVE,
|
||||
tryDictList);
|
||||
@ -914,12 +904,11 @@ void EditorSpellCheck::SetFallbackDictionary(DictionaryFetcher* aFetcher) {
|
||||
// Priority 5:
|
||||
// If we have a current dictionary and we don't have no item in try list,
|
||||
// don't try anything else.
|
||||
nsAutoString currentDictionary;
|
||||
nsAutoCString currentDictionary;
|
||||
GetCurrentDictionary(currentDictionary);
|
||||
if (!currentDictionary.IsEmpty() && tryDictList.IsEmpty()) {
|
||||
#ifdef DEBUG_DICT
|
||||
printf("***** Retrieved current dict |%s|\n",
|
||||
NS_ConvertUTF16toUTF8(currentDictionary).get());
|
||||
printf("***** Retrieved current dict |%s|\n", currentDictionary.get());
|
||||
#endif
|
||||
EndUpdateDictionary();
|
||||
if (aFetcher->mCallback) {
|
||||
@ -933,7 +922,7 @@ void EditorSpellCheck::SetFallbackDictionary(DictionaryFetcher* aFetcher) {
|
||||
// LANG = language[_territory][.charset]
|
||||
char* env_lang = getenv("LANG");
|
||||
if (env_lang) {
|
||||
nsString lang = NS_ConvertUTF8toUTF16(env_lang);
|
||||
nsAutoCString lang(env_lang);
|
||||
// Strip trailing charset, if there is any.
|
||||
int32_t dot_pos = lang.FindChar('.');
|
||||
if (dot_pos != -1) {
|
||||
@ -944,8 +933,7 @@ void EditorSpellCheck::SetFallbackDictionary(DictionaryFetcher* aFetcher) {
|
||||
if (underScore != -1) {
|
||||
lang.Replace(underScore, 1, '-');
|
||||
#ifdef DEBUG_DICT
|
||||
printf("***** Trying LANG from environment |%s|\n",
|
||||
NS_ConvertUTF16toUTF8(lang).get());
|
||||
printf("***** Trying LANG from environment |%s|\n", lang.get());
|
||||
#endif
|
||||
BuildDictionaryList(lang, dictList, DICT_COMPARE_CASE_INSENSITIVE,
|
||||
tryDictList);
|
||||
@ -958,8 +946,7 @@ void EditorSpellCheck::SetFallbackDictionary(DictionaryFetcher* aFetcher) {
|
||||
BuildDictionaryList(dictList[0], dictList, DICT_NORMAL_COMPARE,
|
||||
tryDictList);
|
||||
#ifdef DEBUG_DICT
|
||||
printf("***** Trying first of list |%s|\n",
|
||||
NS_ConvertUTF16toUTF8(dictList[0]).get());
|
||||
printf("***** Trying first of list |%s|\n", dictList[0].get());
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -68,7 +68,7 @@ class EditorSpellCheck final : public nsIEditorSpellCheck {
|
||||
// GetPersonalDictionary must be called to load them.
|
||||
nsTArray<nsString> mDictionaryList;
|
||||
|
||||
nsString mPreferredLang;
|
||||
nsCString mPreferredLang;
|
||||
|
||||
uint32_t mTxtSrvFilterType;
|
||||
int32_t mSuggestedWordIndex;
|
||||
@ -79,10 +79,10 @@ class EditorSpellCheck final : public nsIEditorSpellCheck {
|
||||
|
||||
nsresult DeleteSuggestedWordList();
|
||||
|
||||
void BuildDictionaryList(const nsAString& aDictName,
|
||||
const nsTArray<nsString>& aDictList,
|
||||
void BuildDictionaryList(const nsACString& aDictName,
|
||||
const nsTArray<nsCString>& aDictList,
|
||||
enum dictCompare aCompareType,
|
||||
nsTArray<nsString>& aTryList);
|
||||
nsTArray<nsCString>& aOutList);
|
||||
|
||||
nsresult DictionaryFetched(DictionaryFetcher* aFetchState);
|
||||
|
||||
|
@ -16,7 +16,7 @@ parent:
|
||||
|
||||
sync CheckAndSuggest(nsString aWord) returns (bool aIsMisspelled, nsString[] aSuggestions);
|
||||
|
||||
sync SetDictionary(nsString aDictionary) returns (bool success);
|
||||
sync SetDictionary(nsCString aDictionary) returns (bool success);
|
||||
|
||||
/*
|
||||
* Set current dictionary from list of dictionary name.
|
||||
@ -26,8 +26,8 @@ parent:
|
||||
* @aSuccess true if setting dictionary is successful
|
||||
* @aDictionary Return current dictionary name that set by this method.
|
||||
*/
|
||||
async SetDictionaryFromList(nsString[] aList)
|
||||
returns (bool aSuccess, nsString aDictionary);
|
||||
async SetDictionaryFromList(nsCString[] aList)
|
||||
returns (bool aSuccess, nsCString aDictionary);
|
||||
};
|
||||
|
||||
} // namespace mozilla
|
||||
|
@ -19,12 +19,12 @@ RemoteSpellcheckEngineChild::~RemoteSpellcheckEngineChild() {
|
||||
|
||||
RefPtr<GenericPromise>
|
||||
RemoteSpellcheckEngineChild::SetCurrentDictionaryFromList(
|
||||
const nsTArray<nsString>& aList) {
|
||||
const nsTArray<nsCString>& aList) {
|
||||
RefPtr<mozSpellChecker> spellChecker = mOwner;
|
||||
|
||||
return SendSetDictionaryFromList(aList)->Then(
|
||||
GetMainThreadSerialEventTarget(), __func__,
|
||||
[spellChecker](Tuple<bool, nsString>&& aParam) {
|
||||
[spellChecker](Tuple<bool, nsCString>&& aParam) {
|
||||
if (!Get<0>(aParam)) {
|
||||
spellChecker->mCurrentDictionary.Truncate();
|
||||
return GenericPromise::CreateAndReject(NS_ERROR_NOT_AVAILABLE,
|
||||
|
@ -20,7 +20,7 @@ class RemoteSpellcheckEngineChild
|
||||
virtual ~RemoteSpellcheckEngineChild();
|
||||
|
||||
RefPtr<GenericPromise> SetCurrentDictionaryFromList(
|
||||
const nsTArray<nsString>& aList);
|
||||
const nsTArray<nsCString>& aList);
|
||||
|
||||
RefPtr<CheckWordPromise> CheckWords(const nsTArray<nsString>& aWords);
|
||||
|
||||
|
@ -17,22 +17,22 @@ RemoteSpellcheckEngineParent::RemoteSpellcheckEngineParent() {
|
||||
RemoteSpellcheckEngineParent::~RemoteSpellcheckEngineParent() {}
|
||||
|
||||
mozilla::ipc::IPCResult RemoteSpellcheckEngineParent::RecvSetDictionary(
|
||||
const nsString& aDictionary, bool* success) {
|
||||
const nsCString& aDictionary, bool* success) {
|
||||
nsresult rv = mSpellChecker->SetCurrentDictionary(aDictionary);
|
||||
*success = NS_SUCCEEDED(rv);
|
||||
return IPC_OK();
|
||||
}
|
||||
|
||||
mozilla::ipc::IPCResult RemoteSpellcheckEngineParent::RecvSetDictionaryFromList(
|
||||
nsTArray<nsString>&& aList, SetDictionaryFromListResolver&& aResolve) {
|
||||
nsTArray<nsCString>&& aList, SetDictionaryFromListResolver&& aResolve) {
|
||||
for (auto& dictionary : aList) {
|
||||
nsresult rv = mSpellChecker->SetCurrentDictionary(dictionary);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
aResolve(Tuple<const bool&, const nsString&>(true, dictionary));
|
||||
aResolve(Tuple<const bool&, const nsCString&>(true, dictionary));
|
||||
return IPC_OK();
|
||||
}
|
||||
}
|
||||
aResolve(Tuple<const bool&, const nsString&>(false, u""_ns));
|
||||
aResolve(Tuple<const bool&, const nsCString&>(false, ""_ns));
|
||||
return IPC_OK();
|
||||
}
|
||||
|
||||
|
@ -20,11 +20,11 @@ class RemoteSpellcheckEngineParent : public PRemoteSpellcheckEngineParent {
|
||||
|
||||
virtual void ActorDestroy(ActorDestroyReason aWhy) override;
|
||||
|
||||
virtual mozilla::ipc::IPCResult RecvSetDictionary(const nsString& aDictionary,
|
||||
bool* success);
|
||||
virtual mozilla::ipc::IPCResult RecvSetDictionary(
|
||||
const nsCString& aDictionary, bool* success);
|
||||
|
||||
virtual mozilla::ipc::IPCResult RecvSetDictionaryFromList(
|
||||
nsTArray<nsString>&& aList, SetDictionaryFromListResolver&& aResolve);
|
||||
nsTArray<nsCString>&& aList, SetDictionaryFromListResolver&& aResolve);
|
||||
|
||||
virtual mozilla::ipc::IPCResult RecvCheckAsync(nsTArray<nsString>&& aWord,
|
||||
CheckAsyncResolver&& aResolve);
|
||||
|
@ -137,8 +137,8 @@ mozHunspell::~mozHunspell() {
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
mozHunspell::GetDictionary(nsAString& aDictionary) {
|
||||
aDictionary = mDictionary;
|
||||
mozHunspell::GetDictionary(nsACString& aDictionary) {
|
||||
CopyUTF16toUTF8(mDictionary, aDictionary);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@ -147,7 +147,7 @@ mozHunspell::GetDictionary(nsAString& aDictionary) {
|
||||
* dictionaries converter
|
||||
*/
|
||||
NS_IMETHODIMP
|
||||
mozHunspell::SetDictionary(const nsAString& aDictionary) {
|
||||
mozHunspell::SetDictionary(const nsACString& aDictionary) {
|
||||
if (aDictionary.IsEmpty()) {
|
||||
delete mHunspell;
|
||||
mHunspell = nullptr;
|
||||
@ -159,7 +159,8 @@ mozHunspell::SetDictionary(const nsAString& aDictionary) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsIURI* affFile = mDictionaries.GetWeak(aDictionary);
|
||||
NS_ConvertUTF8toUTF16 dict(aDictionary);
|
||||
nsIURI* affFile = mDictionaries.GetWeak(dict);
|
||||
if (!affFile) {
|
||||
return NS_ERROR_FILE_NOT_FOUND;
|
||||
}
|
||||
@ -184,7 +185,7 @@ mozHunspell::SetDictionary(const nsAString& aDictionary) {
|
||||
// valid mHunspell instance which needs cleaned up.
|
||||
delete mHunspell;
|
||||
|
||||
mDictionary = aDictionary;
|
||||
mDictionary = dict;
|
||||
mAffixFileName = affFileName;
|
||||
|
||||
RegisterHunspellCallbacks(
|
||||
@ -218,10 +219,10 @@ NS_IMETHODIMP mozHunspell::SetPersonalDictionary(
|
||||
}
|
||||
|
||||
NS_IMETHODIMP mozHunspell::GetDictionaryList(
|
||||
nsTArray<nsString>& aDictionaries) {
|
||||
nsTArray<nsCString>& aDictionaries) {
|
||||
MOZ_ASSERT(aDictionaries.IsEmpty());
|
||||
for (auto iter = mDictionaries.Iter(); !iter.Done(); iter.Next()) {
|
||||
aDictionaries.AppendElement(iter.Key());
|
||||
aDictionaries.AppendElement(NS_ConvertUTF16toUTF8(iter.Key()));
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
@ -299,14 +300,14 @@ void mozHunspell::DictionariesChanged(bool aNotifyChildProcesses) {
|
||||
// Check if the current dictionary is still available.
|
||||
// If not, try to replace it with another dictionary of the same language.
|
||||
if (!mDictionary.IsEmpty()) {
|
||||
nsresult rv = SetDictionary(mDictionary);
|
||||
nsresult rv = SetDictionary(NS_ConvertUTF16toUTF8(mDictionary));
|
||||
if (NS_SUCCEEDED(rv)) return;
|
||||
}
|
||||
|
||||
// If the current dictionary has gone, and we don't have a good replacement,
|
||||
// set no current dictionary.
|
||||
if (!mDictionary.IsEmpty()) {
|
||||
SetDictionary(u""_ns);
|
||||
SetDictionary(EmptyCString());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -23,7 +23,7 @@ interface mozISpellCheckingEngine : nsISupports {
|
||||
* If the dictionary is changed to no dictionary (the empty string), an
|
||||
* observer is allowed to set another dictionary before it returns.
|
||||
*/
|
||||
attribute AString dictionary;
|
||||
attribute ACString dictionary;
|
||||
|
||||
/**
|
||||
* the personal dictionary
|
||||
@ -33,7 +33,7 @@ interface mozISpellCheckingEngine : nsISupports {
|
||||
/**
|
||||
* Get the list of dictionaries
|
||||
*/
|
||||
Array<AString> getDictionaryList();
|
||||
Array<ACString> getDictionaryList();
|
||||
|
||||
/**
|
||||
* check a word
|
||||
|
@ -1518,7 +1518,7 @@ nsresult mozInlineSpellChecker::ResumeCheck(
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
nsAutoString currentDictionary;
|
||||
nsAutoCString currentDictionary;
|
||||
rv = mSpellCheck->GetCurrentDictionary(currentDictionary);
|
||||
if (NS_FAILED(rv)) {
|
||||
// no active dictionary
|
||||
|
@ -302,7 +302,7 @@ nsresult mozSpellChecker::GetPersonalDictionary(nsTArray<nsString>* aWordList) {
|
||||
}
|
||||
|
||||
nsresult mozSpellChecker::GetDictionaryList(
|
||||
nsTArray<nsString>* aDictionaryList) {
|
||||
nsTArray<nsCString>* aDictionaryList) {
|
||||
MOZ_ASSERT(aDictionaryList->IsEmpty());
|
||||
if (XRE_IsContentProcess()) {
|
||||
ContentChild* child = ContentChild::GetSingleton();
|
||||
@ -313,7 +313,7 @@ nsresult mozSpellChecker::GetDictionaryList(
|
||||
nsresult rv;
|
||||
|
||||
// For catching duplicates
|
||||
nsTHashtable<nsStringHashKey> dictionaries;
|
||||
nsTHashtable<nsCStringHashKey> dictionaries;
|
||||
|
||||
nsCOMArray<mozISpellCheckingEngine> spellCheckingEngines;
|
||||
rv = GetEngineList(&spellCheckingEngines);
|
||||
@ -322,7 +322,7 @@ nsresult mozSpellChecker::GetDictionaryList(
|
||||
for (int32_t i = 0; i < spellCheckingEngines.Count(); i++) {
|
||||
nsCOMPtr<mozISpellCheckingEngine> engine = spellCheckingEngines[i];
|
||||
|
||||
nsTArray<nsString> dictNames;
|
||||
nsTArray<nsCString> dictNames;
|
||||
engine->GetDictionaryList(dictNames);
|
||||
for (auto& dictName : dictNames) {
|
||||
// Skip duplicate dictionaries. Only take the first one
|
||||
@ -337,7 +337,7 @@ nsresult mozSpellChecker::GetDictionaryList(
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult mozSpellChecker::GetCurrentDictionary(nsAString& aDictionary) {
|
||||
nsresult mozSpellChecker::GetCurrentDictionary(nsACString& aDictionary) {
|
||||
if (XRE_IsContentProcess()) {
|
||||
aDictionary = mCurrentDictionary;
|
||||
return NS_OK;
|
||||
@ -351,9 +351,9 @@ nsresult mozSpellChecker::GetCurrentDictionary(nsAString& aDictionary) {
|
||||
return mSpellCheckingEngine->GetDictionary(aDictionary);
|
||||
}
|
||||
|
||||
nsresult mozSpellChecker::SetCurrentDictionary(const nsAString& aDictionary) {
|
||||
nsresult mozSpellChecker::SetCurrentDictionary(const nsACString& aDictionary) {
|
||||
if (XRE_IsContentProcess()) {
|
||||
nsString wrappedDict = nsString(aDictionary);
|
||||
nsCString wrappedDict = nsCString(aDictionary);
|
||||
bool isSuccess;
|
||||
mEngine->SendSetDictionary(wrappedDict, &isSuccess);
|
||||
if (!isSuccess) {
|
||||
@ -404,7 +404,7 @@ nsresult mozSpellChecker::SetCurrentDictionary(const nsAString& aDictionary) {
|
||||
}
|
||||
|
||||
RefPtr<GenericPromise> mozSpellChecker::SetCurrentDictionaryFromList(
|
||||
const nsTArray<nsString>& aList) {
|
||||
const nsTArray<nsCString>& aList) {
|
||||
if (aList.IsEmpty()) {
|
||||
return GenericPromise::CreateAndReject(NS_ERROR_INVALID_ARG, __func__);
|
||||
}
|
||||
|
@ -120,7 +120,7 @@ class mozSpellChecker final {
|
||||
* @param aDictionaryList is an array of nsStrings that represent the
|
||||
* dictionaries supported by the spellchecker.
|
||||
*/
|
||||
nsresult GetDictionaryList(nsTArray<nsString>* aDictionaryList);
|
||||
nsresult GetDictionaryList(nsTArray<nsCString>* aDictionaryList);
|
||||
|
||||
/**
|
||||
* Returns a string representing the current dictionary.
|
||||
@ -128,7 +128,7 @@ class mozSpellChecker final {
|
||||
* This name is the same string that is in the list returned
|
||||
* by GetDictionaryList().
|
||||
*/
|
||||
nsresult GetCurrentDictionary(nsAString& aDictionary);
|
||||
nsresult GetCurrentDictionary(nsACString& aDictionary);
|
||||
|
||||
/**
|
||||
* Tells the spellchecker to use a specific dictionary.
|
||||
@ -136,14 +136,14 @@ class mozSpellChecker final {
|
||||
* by GetDictionaryList() or an empty string. If aDictionary is
|
||||
* empty string, spellchecker will be disabled.
|
||||
*/
|
||||
nsresult SetCurrentDictionary(const nsAString& aDictionary);
|
||||
nsresult SetCurrentDictionary(const nsACString& aDictionary);
|
||||
|
||||
/**
|
||||
* Tells the spellchecker to use a specific dictionary from list.
|
||||
* @param aList a preferred dictionary list
|
||||
*/
|
||||
RefPtr<mozilla::GenericPromise> SetCurrentDictionaryFromList(
|
||||
const nsTArray<nsString>& aList);
|
||||
const nsTArray<nsCString>& aList);
|
||||
|
||||
void DeleteRemoteEngine() { mEngine = nullptr; }
|
||||
|
||||
@ -162,7 +162,7 @@ class mozSpellChecker final {
|
||||
nsCOMPtr<mozISpellCheckingEngine> mSpellCheckingEngine;
|
||||
bool mFromStart;
|
||||
|
||||
nsString mCurrentDictionary;
|
||||
nsCString mCurrentDictionary;
|
||||
|
||||
MOZ_CAN_RUN_SCRIPT
|
||||
nsresult SetupDoc(int32_t* outBlockOffset);
|
||||
|
Loading…
x
Reference in New Issue
Block a user