RemoteSpellCheckEngineChild.cpp (3337B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 #include "RemoteSpellCheckEngineChild.h" 6 7 namespace mozilla { 8 9 RemoteSpellcheckEngineChild::RemoteSpellcheckEngineChild( 10 mozSpellChecker* aOwner) 11 : mOwner(aOwner) {} 12 13 RemoteSpellcheckEngineChild::~RemoteSpellcheckEngineChild() { 14 // null out the owner's SpellcheckEngineChild to prevent state corruption 15 // during shutdown 16 mOwner->DeleteRemoteEngine(); 17 } 18 19 RefPtr<GenericPromise> RemoteSpellcheckEngineChild::SetCurrentDictionaries( 20 const nsTArray<nsCString>& aDictionaries) { 21 RefPtr<mozSpellChecker> spellChecker = mOwner; 22 23 return SendSetDictionaries(aDictionaries) 24 ->Then( 25 GetMainThreadSerialEventTarget(), __func__, 26 [spellChecker, dictionaries = aDictionaries.Clone()](bool&& aParam) { 27 if (aParam) { 28 spellChecker->mCurrentDictionaries = dictionaries.Clone(); 29 return GenericPromise::CreateAndResolve(true, __func__); 30 } 31 spellChecker->mCurrentDictionaries.Clear(); 32 return GenericPromise::CreateAndReject(NS_ERROR_NOT_AVAILABLE, 33 __func__); 34 }, 35 [spellChecker](ResponseRejectReason&& aReason) { 36 spellChecker->mCurrentDictionaries.Clear(); 37 return GenericPromise::CreateAndReject(NS_ERROR_NOT_AVAILABLE, 38 __func__); 39 }); 40 } 41 42 RefPtr<GenericPromise> 43 RemoteSpellcheckEngineChild::SetCurrentDictionaryFromList( 44 const nsTArray<nsCString>& aList) { 45 RefPtr<mozSpellChecker> spellChecker = mOwner; 46 47 return SendSetDictionaryFromList(aList)->Then( 48 GetMainThreadSerialEventTarget(), __func__, 49 [spellChecker](std::tuple<bool, nsCString>&& aParam) { 50 if (!std::get<0>(aParam)) { 51 spellChecker->mCurrentDictionaries.Clear(); 52 return GenericPromise::CreateAndReject(NS_ERROR_NOT_AVAILABLE, 53 __func__); 54 } 55 spellChecker->mCurrentDictionaries.Clear(); 56 spellChecker->mCurrentDictionaries.AppendElement( 57 std::move(std::get<1>(aParam))); 58 return GenericPromise::CreateAndResolve(true, __func__); 59 }, 60 [spellChecker](ResponseRejectReason&& aReason) { 61 spellChecker->mCurrentDictionaries.Clear(); 62 return GenericPromise::CreateAndReject(NS_ERROR_NOT_AVAILABLE, 63 __func__); 64 }); 65 } 66 67 RefPtr<CheckWordPromise> RemoteSpellcheckEngineChild::CheckWords( 68 const nsTArray<nsString>& aWords) { 69 RefPtr<mozSpellChecker> kungFuDeathGrip = mOwner; 70 71 return SendCheckAsync(aWords)->Then( 72 GetMainThreadSerialEventTarget(), __func__, 73 [kungFuDeathGrip](nsTArray<bool>&& aIsMisspelled) { 74 return CheckWordPromise::CreateAndResolve(std::move(aIsMisspelled), 75 __func__); 76 }, 77 [kungFuDeathGrip](mozilla::ipc::ResponseRejectReason&& aReason) { 78 return CheckWordPromise::CreateAndReject(NS_ERROR_NOT_AVAILABLE, 79 __func__); 80 }); 81 } 82 83 } // namespace mozilla