From 26a029d407be480d791972afb5975cf62c9360a6 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 02:47:55 +0200 Subject: Adding upstream version 124.0.1. Signed-off-by: Daniel Baumann --- .../spellcheck/ipc/PRemoteSpellcheckEngine.ipdl | 46 ++++++++++++ .../spellcheck/ipc/RemoteSpellCheckEngineChild.cpp | 84 +++++++++++++++++++++ .../spellcheck/ipc/RemoteSpellCheckEngineChild.h | 36 +++++++++ .../ipc/RemoteSpellCheckEngineParent.cpp | 85 ++++++++++++++++++++++ .../spellcheck/ipc/RemoteSpellCheckEngineParent.h | 46 ++++++++++++ extensions/spellcheck/ipc/moz.build | 23 ++++++ 6 files changed, 320 insertions(+) create mode 100644 extensions/spellcheck/ipc/PRemoteSpellcheckEngine.ipdl create mode 100644 extensions/spellcheck/ipc/RemoteSpellCheckEngineChild.cpp create mode 100644 extensions/spellcheck/ipc/RemoteSpellCheckEngineChild.h create mode 100644 extensions/spellcheck/ipc/RemoteSpellCheckEngineParent.cpp create mode 100644 extensions/spellcheck/ipc/RemoteSpellCheckEngineParent.h create mode 100644 extensions/spellcheck/ipc/moz.build (limited to 'extensions/spellcheck/ipc') diff --git a/extensions/spellcheck/ipc/PRemoteSpellcheckEngine.ipdl b/extensions/spellcheck/ipc/PRemoteSpellcheckEngine.ipdl new file mode 100644 index 0000000000..c327d97e65 --- /dev/null +++ b/extensions/spellcheck/ipc/PRemoteSpellcheckEngine.ipdl @@ -0,0 +1,46 @@ +/* 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 protocol PContent; + +include "mozilla/RemoteSpellCheckEngineParent.h"; +include "mozilla/RemoteSpellCheckEngineChild.h"; + +namespace mozilla { + +[ManualDealloc, ChildImpl="RemoteSpellcheckEngineChild", ParentImpl="RemoteSpellcheckEngineParent"] +sync protocol PRemoteSpellcheckEngine { + manager PContent; + +parent: + async __delete__(); + + async CheckAsync(nsString[] aWord) returns (bool[] aIsMisspelled); + + sync SetDictionary(nsCString aDictionary) returns (bool success); + + /* + * Set multiple current dictionaries from a list of dictionary names. + * + * @aDictionaries An array of dictionary names to use. If the array is empty, + * no dictionary will be used. + * @aSuccess true if setting the dictionaries succeeded, false otherwise. + */ + async SetDictionaries(nsCString[] aDictionaries) returns (bool success); + + async Suggest(nsString aWord, uint32_t aCount) returns (nsString[] aSuggestions); + + /* + * Set current dictionary from list of dictionary name. + * + * @aList A list of dictionary name. If a string into this list is + * empty string, dictionary selection is reset + * @aSuccess true if setting dictionary is successful + * @aDictionary Return current dictionary name that set by this method. + */ + async SetDictionaryFromList(nsCString[] aList) + returns (bool aSuccess, nsCString aDictionary); +}; + +} // namespace mozilla diff --git a/extensions/spellcheck/ipc/RemoteSpellCheckEngineChild.cpp b/extensions/spellcheck/ipc/RemoteSpellCheckEngineChild.cpp new file mode 100644 index 0000000000..8971694db3 --- /dev/null +++ b/extensions/spellcheck/ipc/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 RemoteSpellcheckEngineChild::SetCurrentDictionaries( + const nsTArray& aDictionaries) { + RefPtr 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 +RemoteSpellcheckEngineChild::SetCurrentDictionaryFromList( + const nsTArray& aList) { + RefPtr spellChecker = mOwner; + + return SendSetDictionaryFromList(aList)->Then( + GetMainThreadSerialEventTarget(), __func__, + [spellChecker](std::tuple&& 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 RemoteSpellcheckEngineChild::CheckWords( + const nsTArray& aWords) { + RefPtr kungFuDeathGrip = mOwner; + + return SendCheckAsync(aWords)->Then( + GetMainThreadSerialEventTarget(), __func__, + [kungFuDeathGrip](nsTArray&& aIsMisspelled) { + return CheckWordPromise::CreateAndResolve(std::move(aIsMisspelled), + __func__); + }, + [kungFuDeathGrip](mozilla::ipc::ResponseRejectReason&& aReason) { + return CheckWordPromise::CreateAndReject(NS_ERROR_NOT_AVAILABLE, + __func__); + }); +} + +} // namespace mozilla diff --git a/extensions/spellcheck/ipc/RemoteSpellCheckEngineChild.h b/extensions/spellcheck/ipc/RemoteSpellCheckEngineChild.h new file mode 100644 index 0000000000..1579908f46 --- /dev/null +++ b/extensions/spellcheck/ipc/RemoteSpellCheckEngineChild.h @@ -0,0 +1,36 @@ +/* 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/. */ + +#ifndef RemoteSpellcheckEngineChild_h_ +#define RemoteSpellcheckEngineChild_h_ + +#include "mozilla/MozPromise.h" +#include "mozilla/mozSpellChecker.h" +#include "mozilla/PRemoteSpellcheckEngineChild.h" + +class mozSpellChecker; + +namespace mozilla { + +class RemoteSpellcheckEngineChild + : public mozilla::PRemoteSpellcheckEngineChild { + public: + explicit RemoteSpellcheckEngineChild(mozSpellChecker* aOwner); + virtual ~RemoteSpellcheckEngineChild(); + + RefPtr SetCurrentDictionaries( + const nsTArray& aDictionaries); + + RefPtr SetCurrentDictionaryFromList( + const nsTArray& aList); + + RefPtr CheckWords(const nsTArray& aWords); + + private: + mozSpellChecker* mOwner; +}; + +} // namespace mozilla + +#endif // RemoteSpellcheckEngineChild_h_ diff --git a/extensions/spellcheck/ipc/RemoteSpellCheckEngineParent.cpp b/extensions/spellcheck/ipc/RemoteSpellCheckEngineParent.cpp new file mode 100644 index 0000000000..e9f341d524 --- /dev/null +++ b/extensions/spellcheck/ipc/RemoteSpellCheckEngineParent.cpp @@ -0,0 +1,85 @@ +/* vim: set ts=2 sw=2 sts=2 tw=80: */ +/* 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 "RemoteSpellCheckEngineParent.h" +#include "mozilla/Unused.h" +#include "mozilla/mozSpellChecker.h" +#include "nsServiceManagerUtils.h" + +namespace mozilla { + +RemoteSpellcheckEngineParent::RemoteSpellcheckEngineParent() { + mSpellChecker = mozSpellChecker::Create(); +} + +RemoteSpellcheckEngineParent::~RemoteSpellcheckEngineParent() {} + +mozilla::ipc::IPCResult RemoteSpellcheckEngineParent::RecvSetDictionary( + const nsACString& aDictionary, bool* success) { + nsresult rv = mSpellChecker->SetCurrentDictionary(aDictionary); + *success = NS_SUCCEEDED(rv); + return IPC_OK(); +} + +mozilla::ipc::IPCResult RemoteSpellcheckEngineParent::RecvSetDictionaries( + const nsTArray& aDictionaries, + SetDictionariesResolver&& aResolve) { + mSpellChecker->SetCurrentDictionaries(aDictionaries) + ->Then( + GetMainThreadSerialEventTarget(), __func__, + [aResolve]() { aResolve(true); }, [aResolve]() { aResolve(false); }); + return IPC_OK(); +} + +mozilla::ipc::IPCResult RemoteSpellcheckEngineParent::RecvSetDictionaryFromList( + nsTArray&& aList, SetDictionaryFromListResolver&& aResolve) { + for (auto& dictionary : aList) { + nsresult rv = mSpellChecker->SetCurrentDictionary(dictionary); + if (NS_SUCCEEDED(rv)) { + aResolve(std::tuple(true, dictionary)); + return IPC_OK(); + } + } + aResolve(std::tuple(false, ""_ns)); + return IPC_OK(); +} + +mozilla::ipc::IPCResult RemoteSpellcheckEngineParent::RecvCheckAsync( + nsTArray&& aWords, CheckAsyncResolver&& aResolve) { + nsTArray misspells; + misspells.SetCapacity(aWords.Length()); + for (auto& word : aWords) { + bool misspelled; + nsresult rv = mSpellChecker->CheckWord(word, &misspelled, nullptr); + // If CheckWord failed, we can't tell whether the word is correctly spelled + if (NS_FAILED(rv)) { + misspelled = false; + } + misspells.AppendElement(misspelled); + } + aResolve(std::move(misspells)); + return IPC_OK(); +} + +mozilla::ipc::IPCResult RemoteSpellcheckEngineParent::RecvSuggest( + const nsAString& aWord, uint32_t aCount, SuggestResolver&& aResolve) { + nsTArray suggestions; + mSpellChecker->Suggest(aWord, aCount) + ->Then( + GetMainThreadSerialEventTarget(), __func__, + [aResolve](CopyableTArray aSuggestions) { + aResolve(std::move(aSuggestions)); + }, + [aResolve](nsresult aError) { + // No suggestions due to error + nsTArray suggestions; + aResolve(std::move(suggestions)); + }); + return IPC_OK(); +} + +void RemoteSpellcheckEngineParent::ActorDestroy(ActorDestroyReason aWhy) {} + +} // namespace mozilla diff --git a/extensions/spellcheck/ipc/RemoteSpellCheckEngineParent.h b/extensions/spellcheck/ipc/RemoteSpellCheckEngineParent.h new file mode 100644 index 0000000000..06f4a7e8f5 --- /dev/null +++ b/extensions/spellcheck/ipc/RemoteSpellCheckEngineParent.h @@ -0,0 +1,46 @@ +/* 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/. */ +#ifndef RemoteSpellcheckEngineParent_h_ +#define RemoteSpellcheckEngineParent_h_ + +#include "mozilla/PRemoteSpellcheckEngineParent.h" +#include "nsCOMPtr.h" +#include "nsTArray.h" + +class mozSpellChecker; + +namespace mozilla { + +class RemoteSpellcheckEngineParent : public PRemoteSpellcheckEngineParent { + public: + RemoteSpellcheckEngineParent(); + + virtual ~RemoteSpellcheckEngineParent(); + + virtual void ActorDestroy(ActorDestroyReason aWhy) override; + + virtual mozilla::ipc::IPCResult RecvSetDictionary( + const nsACString& aDictionary, bool* success); + + virtual mozilla::ipc::IPCResult RecvSetDictionaries( + const nsTArray& aDictionaries, + SetDictionariesResolver&& aResolve); + + virtual mozilla::ipc::IPCResult RecvSetDictionaryFromList( + nsTArray&& aList, SetDictionaryFromListResolver&& aResolve); + + virtual mozilla::ipc::IPCResult RecvCheckAsync(nsTArray&& aWord, + CheckAsyncResolver&& aResolve); + + virtual mozilla::ipc::IPCResult RecvSuggest(const nsAString& aWord, + uint32_t aCount, + SuggestResolver&& aResolve); + + private: + RefPtr mSpellChecker; +}; + +} // namespace mozilla + +#endif diff --git a/extensions/spellcheck/ipc/moz.build b/extensions/spellcheck/ipc/moz.build new file mode 100644 index 0000000000..0e424dc72e --- /dev/null +++ b/extensions/spellcheck/ipc/moz.build @@ -0,0 +1,23 @@ +# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*- +# vim: set filetype=python: +# 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/. + +UNIFIED_SOURCES += [ + "RemoteSpellCheckEngineChild.cpp", + "RemoteSpellCheckEngineParent.cpp", +] + +FINAL_LIBRARY = "xul" + +include("/ipc/chromium/chromium-config.mozbuild") + +IPDL_SOURCES = [ + "PRemoteSpellcheckEngine.ipdl", +] + +EXPORTS.mozilla += [ + "RemoteSpellCheckEngineChild.h", + "RemoteSpellCheckEngineParent.h", +] -- cgit v1.2.3