Skip to content

Commit

Permalink
Bug 1524443 - Hold mozSpellChecker when using async IPC. r=masayuki
Browse files Browse the repository at this point in the history
When using `CheckAsync` IPC, we don't hold `mozSpellChecker`. It causes that
`mozSpellChecker` may be destroyed during IPC call.

The destructor of `mozSpellChecker` destroys actor of spellchecker IPC via
`Send__delete__`. Although IPC rejects pending promises of async IPC during
destroying actor, it cannot remove replay messages from parent process.
So route error occurs.

So we have to keep `mozSpellChecker` during async IPC.

And we cannot convert attached test case to crashtest or mochitest since this
depends on navigation and timing. So I don't add it.

Differential Revision: https://phabricator.services.mozilla.com/D30347

--HG--
extra : moz-landing-system : lando
  • Loading branch information
makotokato committed May 8, 2019
1 parent e65a7d6 commit d75677f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,20 @@ RemoteSpellcheckEngineChild::SetCurrentDictionaryFromList(
});
}

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
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ class RemoteSpellcheckEngineChild
RefPtr<GenericPromise> SetCurrentDictionaryFromList(
const nsTArray<nsString>& aList);

RefPtr<CheckWordPromise> CheckWords(const nsTArray<nsString>& aWords);

private:
mozSpellChecker* mOwner;
};
Expand Down
11 changes: 1 addition & 10 deletions extensions/spellcheck/src/mozSpellChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,16 +117,7 @@ nsresult mozSpellChecker::NextMisspelledWord(nsAString& aWord,
RefPtr<CheckWordPromise> mozSpellChecker::CheckWords(
const nsTArray<nsString>& aWords) {
if (XRE_IsContentProcess()) {
return mEngine->SendCheckAsync(aWords)->Then(
GetMainThreadSerialEventTarget(), __func__,
[](nsTArray<bool>&& aIsMisspelled) {
return CheckWordPromise::CreateAndResolve(std::move(aIsMisspelled),
__func__);
},
[](mozilla::ipc::ResponseRejectReason&& aReason) {
return CheckWordPromise::CreateAndReject(NS_ERROR_NOT_AVAILABLE,
__func__);
});
return mEngine->CheckWords(aWords);
}

nsTArray<bool> misspells;
Expand Down

0 comments on commit d75677f

Please sign in to comment.