summaryrefslogtreecommitdiffstats
path: root/extensions/spellcheck/hunspell/glue/RemoteSpellCheckEngineChild.cpp
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /extensions/spellcheck/hunspell/glue/RemoteSpellCheckEngineChild.cpp
parentInitial commit. (diff)
downloadfirefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz
firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'extensions/spellcheck/hunspell/glue/RemoteSpellCheckEngineChild.cpp')
-rw-r--r--extensions/spellcheck/hunspell/glue/RemoteSpellCheckEngineChild.cpp84
1 files changed, 84 insertions, 0 deletions
diff --git a/extensions/spellcheck/hunspell/glue/RemoteSpellCheckEngineChild.cpp b/extensions/spellcheck/hunspell/glue/RemoteSpellCheckEngineChild.cpp
new file mode 100644
index 0000000000..8971694db3
--- /dev/null
+++ b/extensions/spellcheck/hunspell/glue/RemoteSpellCheckEngineChild.cpp
@@ -0,0 +1,84 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * 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 {
+
+RemoteSpellcheckEngineChild::RemoteSpellcheckEngineChild(
+ mozSpellChecker* aOwner)
+ : mOwner(aOwner) {}
+
+RemoteSpellcheckEngineChild::~RemoteSpellcheckEngineChild() {
+ // null out the owner's SpellcheckEngineChild to prevent state corruption
+ // during shutdown
+ mOwner->DeleteRemoteEngine();
+}
+
+RefPtr<GenericPromise> RemoteSpellcheckEngineChild::SetCurrentDictionaries(
+ const nsTArray<nsCString>& aDictionaries) {
+ RefPtr<mozSpellChecker> spellChecker = mOwner;
+
+ return SendSetDictionaries(aDictionaries)
+ ->Then(
+ GetMainThreadSerialEventTarget(), __func__,
+ [spellChecker, dictionaries = aDictionaries.Clone()](bool&& aParam) {
+ if (aParam) {
+ spellChecker->mCurrentDictionaries = dictionaries.Clone();
+ return GenericPromise::CreateAndResolve(true, __func__);
+ }
+ spellChecker->mCurrentDictionaries.Clear();
+ return GenericPromise::CreateAndReject(NS_ERROR_NOT_AVAILABLE,
+ __func__);
+ },
+ [spellChecker](ResponseRejectReason&& aReason) {
+ spellChecker->mCurrentDictionaries.Clear();
+ return GenericPromise::CreateAndReject(NS_ERROR_NOT_AVAILABLE,
+ __func__);
+ });
+}
+
+RefPtr<GenericPromise>
+RemoteSpellcheckEngineChild::SetCurrentDictionaryFromList(
+ const nsTArray<nsCString>& aList) {
+ RefPtr<mozSpellChecker> spellChecker = mOwner;
+
+ return SendSetDictionaryFromList(aList)->Then(
+ GetMainThreadSerialEventTarget(), __func__,
+ [spellChecker](std::tuple<bool, nsCString>&& aParam) {
+ if (!std::get<0>(aParam)) {
+ spellChecker->mCurrentDictionaries.Clear();
+ return GenericPromise::CreateAndReject(NS_ERROR_NOT_AVAILABLE,
+ __func__);
+ }
+ spellChecker->mCurrentDictionaries.Clear();
+ spellChecker->mCurrentDictionaries.AppendElement(
+ std::move(std::get<1>(aParam)));
+ return GenericPromise::CreateAndResolve(true, __func__);
+ },
+ [spellChecker](ResponseRejectReason&& aReason) {
+ spellChecker->mCurrentDictionaries.Clear();
+ return GenericPromise::CreateAndReject(NS_ERROR_NOT_AVAILABLE,
+ __func__);
+ });
+}
+
+RefPtr<CheckWordPromise> RemoteSpellcheckEngineChild::CheckWords(
+ const nsTArray<nsString>& aWords) {
+ RefPtr<mozSpellChecker> kungFuDeathGrip = mOwner;
+
+ return SendCheckAsync(aWords)->Then(
+ GetMainThreadSerialEventTarget(), __func__,
+ [kungFuDeathGrip](nsTArray<bool>&& aIsMisspelled) {
+ return CheckWordPromise::CreateAndResolve(std::move(aIsMisspelled),
+ __func__);
+ },
+ [kungFuDeathGrip](mozilla::ipc::ResponseRejectReason&& aReason) {
+ return CheckWordPromise::CreateAndReject(NS_ERROR_NOT_AVAILABLE,
+ __func__);
+ });
+}
+
+} // namespace mozilla