Bug 1330912 - Part 1. Add async version of SetCurrentDictionary using list. r=Ehsan

Now, mozInlineSpellChecker::UpdateCurrentDictionary uses several sync IPC message to update spellcheck dictionary.  So I want async IPC to set dictionary.

Also, since nsEditorSpellCheck::DictionaryFetched calls SetCurrentDictionary several times (max: 6 times), so to reduce calls, we should use list of dictionary.

MozReview-Commit-ID: EVMAJxpMT2X

--HG--
extra : rebase_source : 5a1ed28bd6eb1dd9d3a6a634a286531b7ebb32c7
This commit is contained in:
Makoto Kato 2017-04-10 18:29:16 +09:00
Родитель a866f48455
Коммит 55e9044079
8 изменённых файлов: 106 добавлений и 2 удалений

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

@ -6,6 +6,7 @@
#ifndef nsISpellChecker_h__
#define nsISpellChecker_h__
#include "mozilla/MozPromise.h"
#include "nsISupports.h"
#include "nsTArray.h"
@ -114,6 +115,13 @@ public:
* empty string, spellchecker will be disabled.
*/
NS_IMETHOD SetCurrentDictionary(const nsAString &aDictionary) = 0;
/**
* Tells the spellchecker to use a specific dictionary from list.
* @param aList a preferred dictionary list
*/
NS_IMETHOD_(RefPtr<mozilla::GenericPromise>)
SetCurrentDictionaryFromList(const nsTArray<nsString>& aList) = 0;
};
NS_DEFINE_STATIC_IID_ACCESSOR(nsISpellChecker, NS_ISPELLCHECKER_IID)

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

@ -17,6 +17,11 @@ parent:
sync CheckAndSuggest(nsString aWord) returns (bool aIsMisspelled, nsString[] aSuggestions);
sync SetDictionary(nsString aDictionary) returns (bool success);
async SetDictionaryFromList(nsString[] aList, intptr_t aPromiseId);
child:
async NotifyOfCurrentDictionary(nsString aDictionary, intptr_t aPromiseId);
};
} // namespace mozilla

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

@ -2,6 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "mozilla/UniquePtr.h"
#include "RemoteSpellCheckEngineChild.h"
namespace mozilla {
@ -18,4 +19,37 @@ RemoteSpellcheckEngineChild::~RemoteSpellcheckEngineChild()
mOwner->DeleteRemoteEngine();
}
RefPtr<GenericPromise>
RemoteSpellcheckEngineChild::SetCurrentDictionaryFromList(
const nsTArray<nsString>& aList)
{
MozPromiseHolder<GenericPromise>* promiseHolder =
new MozPromiseHolder<GenericPromise>();
if (!SendSetDictionaryFromList(
aList,
reinterpret_cast<intptr_t>(promiseHolder))) {
delete promiseHolder;
return GenericPromise::CreateAndReject(NS_ERROR_FAILURE, __func__);
}
// promiseHolder will removed by receive message
return promiseHolder->Ensure(__func__);
}
mozilla::ipc::IPCResult
RemoteSpellcheckEngineChild::RecvNotifyOfCurrentDictionary(
const nsString& aDictionary,
const intptr_t& aId)
{
MozPromiseHolder<GenericPromise>* promiseHolder =
reinterpret_cast<MozPromiseHolder<GenericPromise>*>(aId);
mOwner->mCurrentDictionary = aDictionary;
if (aDictionary.IsEmpty()) {
promiseHolder->RejectIfExists(NS_ERROR_NOT_AVAILABLE, __func__);
} else {
promiseHolder->ResolveIfExists(true, __func__);
}
delete promiseHolder;
return IPC_OK();
}
} //namespace mozilla

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

@ -5,6 +5,7 @@
#ifndef RemoteSpellcheckEngineChild_h_
#define RemoteSpellcheckEngineChild_h_
#include "mozilla/MozPromise.h"
#include "mozilla/PRemoteSpellcheckEngineChild.h"
#include "mozSpellChecker.h"
@ -18,6 +19,13 @@ public:
explicit RemoteSpellcheckEngineChild(mozSpellChecker *aOwner);
virtual ~RemoteSpellcheckEngineChild();
virtual mozilla::ipc::IPCResult RecvNotifyOfCurrentDictionary(
const nsString& aDictionary,
const intptr_t& aPromiseId) override;
RefPtr<GenericPromise> SetCurrentDictionaryFromList(
const nsTArray<nsString>& aList);
private:
mozSpellChecker *mOwner;
};

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

@ -4,6 +4,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "RemoteSpellCheckEngineParent.h"
#include "mozilla/Unused.h"
#include "nsISpellChecker.h"
#include "nsServiceManagerUtils.h"
@ -28,6 +29,23 @@ RemoteSpellcheckEngineParent::RecvSetDictionary(
return IPC_OK();
}
mozilla::ipc::IPCResult
RemoteSpellcheckEngineParent::RecvSetDictionaryFromList(
nsTArray<nsString>&& aList,
const intptr_t& aPromiseId)
{
for (auto& dictionary : aList) {
MOZ_ASSERT(!dictionary.IsEmpty());
nsresult rv = mSpellChecker->SetCurrentDictionary(dictionary);
if (NS_SUCCEEDED(rv)) {
Unused << SendNotifyOfCurrentDictionary(dictionary, aPromiseId);
return IPC_OK();
}
}
Unused << SendNotifyOfCurrentDictionary(EmptyString(), aPromiseId);
return IPC_OK();
}
mozilla::ipc::IPCResult
RemoteSpellcheckEngineParent::RecvCheck(
const nsString& aWord,

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

@ -6,6 +6,7 @@
#include "mozilla/PRemoteSpellcheckEngineParent.h"
#include "nsCOMPtr.h"
#include "nsTArray.h"
class nsISpellChecker;
@ -23,6 +24,10 @@ public:
virtual mozilla::ipc::IPCResult RecvSetDictionary(const nsString& aDictionary,
bool* success) override;
virtual mozilla::ipc::IPCResult RecvSetDictionaryFromList(
nsTArray<nsString>&& aList,
const intptr_t& aPromiseId) override;
virtual mozilla::ipc::IPCResult RecvCheck(const nsString& aWord, bool* aIsMisspelled) override;
virtual mozilla::ipc::IPCResult RecvCheckAndSuggest(const nsString& aWord,

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

@ -16,6 +16,7 @@
#include "nsXULAppAPI.h"
using mozilla::dom::ContentChild;
using mozilla::GenericPromise;
using mozilla::PRemoteSpellcheckEngineChild;
using mozilla::RemoteSpellcheckEngineChild;
@ -429,6 +430,28 @@ mozSpellChecker::SetCurrentDictionary(const nsAString &aDictionary)
return NS_ERROR_NOT_AVAILABLE;
}
NS_IMETHODIMP_(RefPtr<GenericPromise>)
mozSpellChecker::SetCurrentDictionaryFromList(const nsTArray<nsString>& aList)
{
if (aList.IsEmpty()) {
return GenericPromise::CreateAndReject(NS_ERROR_INVALID_ARG, __func__);
}
if (XRE_IsContentProcess()) {
// mCurrentDictionary will be set by RemoteSpellCheckEngineChild
return mEngine->SetCurrentDictionaryFromList(aList);
}
for (auto& dictionary : aList) {
nsresult rv = SetCurrentDictionary(dictionary);
if (NS_SUCCEEDED(rv)) {
return GenericPromise::CreateAndResolve(true, __func__);
}
}
// We could not find any engine with the requested dictionary
return GenericPromise::CreateAndReject(NS_ERROR_NOT_AVAILABLE, __func__);
}
nsresult
mozSpellChecker::SetupDoc(int32_t *outBlockOffset)
{

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

@ -20,7 +20,6 @@
#include "RemoteSpellCheckEngineChild.h"
namespace mozilla {
class PRemoteSpellcheckEngineChild;
class RemoteSpellcheckEngineChild;
} // namespace mozilla
@ -48,6 +47,8 @@ public:
NS_IMETHOD GetDictionaryList(nsTArray<nsString> *aDictionaryList) override;
NS_IMETHOD GetCurrentDictionary(nsAString &aDictionary) override;
NS_IMETHOD SetCurrentDictionary(const nsAString &aDictionary) override;
NS_IMETHOD_(RefPtr<mozilla::GenericPromise>)
SetCurrentDictionaryFromList(const nsTArray<nsString>& aList) override;
void DeleteRemoteEngine() {
mEngine = nullptr;
@ -71,6 +72,8 @@ protected:
nsresult GetEngineList(nsCOMArray<mozISpellCheckingEngine> *aDictionaryList);
mozilla::PRemoteSpellcheckEngineChild *mEngine;
mozilla::RemoteSpellcheckEngineChild *mEngine;
friend class mozilla::RemoteSpellcheckEngineChild;
};
#endif // mozSpellChecker_h__