Line data Source code
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 "mozilla/UniquePtr.h"
6 : #include "RemoteSpellCheckEngineChild.h"
7 :
8 : namespace mozilla {
9 :
10 0 : RemoteSpellcheckEngineChild::RemoteSpellcheckEngineChild(mozSpellChecker *aOwner)
11 0 : : mOwner(aOwner)
12 : {
13 0 : }
14 :
15 0 : RemoteSpellcheckEngineChild::~RemoteSpellcheckEngineChild()
16 : {
17 : // null out the owner's SpellcheckEngineChild to prevent state corruption
18 : // during shutdown
19 0 : mOwner->DeleteRemoteEngine();
20 0 : }
21 :
22 : RefPtr<GenericPromise>
23 0 : RemoteSpellcheckEngineChild::SetCurrentDictionaryFromList(
24 : const nsTArray<nsString>& aList)
25 : {
26 : MozPromiseHolder<GenericPromise>* promiseHolder =
27 0 : new MozPromiseHolder<GenericPromise>();
28 0 : if (!SendSetDictionaryFromList(
29 : aList,
30 0 : reinterpret_cast<intptr_t>(promiseHolder))) {
31 0 : delete promiseHolder;
32 0 : return GenericPromise::CreateAndReject(NS_ERROR_FAILURE, __func__);
33 : }
34 : // promiseHolder will removed by receive message
35 0 : return promiseHolder->Ensure(__func__);
36 : }
37 :
38 : mozilla::ipc::IPCResult
39 0 : RemoteSpellcheckEngineChild::RecvNotifyOfCurrentDictionary(
40 : const nsString& aDictionary,
41 : const intptr_t& aId)
42 : {
43 : MozPromiseHolder<GenericPromise>* promiseHolder =
44 0 : reinterpret_cast<MozPromiseHolder<GenericPromise>*>(aId);
45 0 : mOwner->mCurrentDictionary = aDictionary;
46 0 : if (aDictionary.IsEmpty()) {
47 0 : promiseHolder->RejectIfExists(NS_ERROR_NOT_AVAILABLE, __func__);
48 : } else {
49 0 : promiseHolder->ResolveIfExists(true, __func__);
50 : }
51 0 : delete promiseHolder;
52 0 : return IPC_OK();
53 : }
54 :
55 : } //namespace mozilla
|