Bug 1859680 - Reject RecvFindImageText() messages on unsupported platforms. r=gregtatum

Also, avoid calling SendFindImageText() on unsupported platforms, so that
test_image_recognition_unsupported.html will pass.

Differential Revision: https://phabricator.services.mozilla.com/D191678
This commit is contained in:
Andrew McCreight 2023-10-24 19:04:55 +00:00
Родитель 3c31a491e8
Коммит e37e4cf2d7
2 изменённых файлов: 11 добавлений и 4 удалений

Просмотреть файл

@ -5219,6 +5219,11 @@ mozilla::ipc::IPCResult ContentParent::RecvCopyFavicon(
mozilla::ipc::IPCResult ContentParent::RecvFindImageText(
IPCImage&& aImage, nsTArray<nsCString>&& aLanguages,
FindImageTextResolver&& aResolver) {
if (!TextRecognition::IsSupported() ||
!Preferences::GetBool("dom.text-recognition.enabled")) {
return IPC_FAIL(this, "Text recognition not available.");
}
RefPtr<DataSourceSurface> surf =
nsContentUtils::IPCImageToSurface(std::move(aImage));
if (!surf) {

Просмотреть файл

@ -35,6 +35,11 @@ auto TextRecognition::FindText(imgIContainer& aImage,
auto TextRecognition::FindText(gfx::DataSourceSurface& aSurface,
const nsTArray<nsCString>& aLanguages)
-> RefPtr<NativePromise> {
if (!IsSupported()) {
return NativePromise::CreateAndReject("Text recognition not available"_ns,
__func__);
}
if (XRE_IsContentProcess()) {
auto* contentChild = ContentChild::GetSingleton();
auto image = nsContentUtils::SurfaceToIPCImage(aSurface);
@ -108,10 +113,7 @@ void TextRecognition::FillShadow(ShadowRoot& aShadow,
auto TextRecognition::DoFindText(gfx::DataSourceSurface&,
const nsTArray<nsCString>&)
-> RefPtr<NativePromise> {
MOZ_RELEASE_ASSERT(XRE_IsParentProcess(),
"This should only run in the parent process");
return NativePromise::CreateAndReject("Text recognition not available"_ns,
__func__);
MOZ_CRASH("DoFindText is not implemented on this platform");
}
#endif