forked from mirrors/gecko-dev
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:
parent
3c31a491e8
commit
e37e4cf2d7
2 changed files with 11 additions and 4 deletions
|
|
@ -5219,6 +5219,11 @@ mozilla::ipc::IPCResult ContentParent::RecvCopyFavicon(
|
||||||
mozilla::ipc::IPCResult ContentParent::RecvFindImageText(
|
mozilla::ipc::IPCResult ContentParent::RecvFindImageText(
|
||||||
IPCImage&& aImage, nsTArray<nsCString>&& aLanguages,
|
IPCImage&& aImage, nsTArray<nsCString>&& aLanguages,
|
||||||
FindImageTextResolver&& aResolver) {
|
FindImageTextResolver&& aResolver) {
|
||||||
|
if (!TextRecognition::IsSupported() ||
|
||||||
|
!Preferences::GetBool("dom.text-recognition.enabled")) {
|
||||||
|
return IPC_FAIL(this, "Text recognition not available.");
|
||||||
|
}
|
||||||
|
|
||||||
RefPtr<DataSourceSurface> surf =
|
RefPtr<DataSourceSurface> surf =
|
||||||
nsContentUtils::IPCImageToSurface(std::move(aImage));
|
nsContentUtils::IPCImageToSurface(std::move(aImage));
|
||||||
if (!surf) {
|
if (!surf) {
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,11 @@ auto TextRecognition::FindText(imgIContainer& aImage,
|
||||||
auto TextRecognition::FindText(gfx::DataSourceSurface& aSurface,
|
auto TextRecognition::FindText(gfx::DataSourceSurface& aSurface,
|
||||||
const nsTArray<nsCString>& aLanguages)
|
const nsTArray<nsCString>& aLanguages)
|
||||||
-> RefPtr<NativePromise> {
|
-> RefPtr<NativePromise> {
|
||||||
|
if (!IsSupported()) {
|
||||||
|
return NativePromise::CreateAndReject("Text recognition not available"_ns,
|
||||||
|
__func__);
|
||||||
|
}
|
||||||
|
|
||||||
if (XRE_IsContentProcess()) {
|
if (XRE_IsContentProcess()) {
|
||||||
auto* contentChild = ContentChild::GetSingleton();
|
auto* contentChild = ContentChild::GetSingleton();
|
||||||
auto image = nsContentUtils::SurfaceToIPCImage(aSurface);
|
auto image = nsContentUtils::SurfaceToIPCImage(aSurface);
|
||||||
|
|
@ -108,10 +113,7 @@ void TextRecognition::FillShadow(ShadowRoot& aShadow,
|
||||||
auto TextRecognition::DoFindText(gfx::DataSourceSurface&,
|
auto TextRecognition::DoFindText(gfx::DataSourceSurface&,
|
||||||
const nsTArray<nsCString>&)
|
const nsTArray<nsCString>&)
|
||||||
-> RefPtr<NativePromise> {
|
-> RefPtr<NativePromise> {
|
||||||
MOZ_RELEASE_ASSERT(XRE_IsParentProcess(),
|
MOZ_CRASH("DoFindText is not implemented on this platform");
|
||||||
"This should only run in the parent process");
|
|
||||||
return NativePromise::CreateAndReject("Text recognition not available"_ns,
|
|
||||||
__func__);
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue