mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-24 13:21:05 +00:00
Bug 1689745 - Throw ImageProcessingException in Image#getBitmap. r=aklotz,esawin
Differential Revision: https://phabricator.services.mozilla.com/D103527
This commit is contained in:
parent
0619bca001
commit
90780fa3c1
@ -18,6 +18,7 @@ import org.junit.runners.Parameterized
|
||||
import org.mozilla.geckoview.GeckoResult
|
||||
import org.mozilla.geckoview.GeckoSession
|
||||
import org.mozilla.geckoview.WebExtension
|
||||
import org.mozilla.geckoview.Image.ImageProcessingException
|
||||
import org.mozilla.geckoview.test.rule.GeckoSessionTestRule
|
||||
import org.mozilla.geckoview.test.rule.GeckoSessionTestRule.AssertCalled
|
||||
|
||||
@ -466,7 +467,9 @@ class ExtensionActionTest : BaseSessionTest() {
|
||||
action.icon!!.getBitmap(38).accept({
|
||||
error.completeExceptionally(RuntimeException("Should not succeed."))
|
||||
}, { exception ->
|
||||
assertTrue(exception is IllegalArgumentException)
|
||||
if (!(exception is ImageProcessingException)) {
|
||||
throw exception!!;
|
||||
}
|
||||
error.complete(null)
|
||||
})
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ import android.graphics.Bitmap;
|
||||
import androidx.annotation.AnyThread;
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import org.mozilla.gecko.annotation.WrapForJNI;
|
||||
import org.mozilla.gecko.util.GeckoBundle;
|
||||
import org.mozilla.gecko.util.ImageResource;
|
||||
|
||||
@ -37,9 +38,26 @@ public class Image {
|
||||
* @param size pixel size at which this image will be displayed at.
|
||||
*
|
||||
* @return A {@link GeckoResult} that resolves to the bitmap when ready.
|
||||
* Will resolve exceptionally to {@link ImageProcessingException} if the image
|
||||
* cannot be processed.
|
||||
*/
|
||||
@NonNull
|
||||
public GeckoResult<Bitmap> getBitmap(final int size) {
|
||||
return mCollection.getBitmap(size);
|
||||
}
|
||||
|
||||
/**
|
||||
* Thrown whenever an image cannot be processed by {@link #getBitmap}
|
||||
*/
|
||||
@WrapForJNI
|
||||
public static class ImageProcessingException extends RuntimeException {
|
||||
/**
|
||||
* Build an instance of this class.
|
||||
*
|
||||
* @param message description of the error.
|
||||
*/
|
||||
public ImageProcessingException(final String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -12,6 +12,7 @@
|
||||
#include "JavaExceptions.h"
|
||||
#include "mozilla/gfx/Point.h"
|
||||
#include "mozilla/gfx/Swizzle.h"
|
||||
#include "mozilla/java/ImageWrappers.h"
|
||||
#include "nsNetUtil.h"
|
||||
|
||||
namespace mozilla {
|
||||
@ -31,7 +32,7 @@ class ImageCallbackHelper : public imgIContainerCallback,
|
||||
|
||||
void CompleteExceptionally(const char* aMessage) {
|
||||
mResult->CompleteExceptionally(
|
||||
java::sdk::IllegalArgumentException::New(aMessage)
|
||||
java::Image::ImageProcessingException::New(aMessage)
|
||||
.Cast<jni::Throwable>());
|
||||
gDecodeRequests.remove(this);
|
||||
}
|
||||
@ -59,7 +60,8 @@ class ImageCallbackHelper : public imgIContainerCallback,
|
||||
MOZ_ALWAYS_TRUE(gDecodeRequests.putNew(this));
|
||||
|
||||
if (NS_FAILED(aStatus)) {
|
||||
CompleteExceptionally("Could not process image.");
|
||||
nsPrintfCString error("Could not process image: %d", aStatus);
|
||||
CompleteExceptionally(error.get());
|
||||
return aStatus;
|
||||
}
|
||||
|
||||
|
@ -61,6 +61,7 @@ classes_with_WrapForJNI = [
|
||||
"GeckoVideoInfo",
|
||||
"GeckoWebExecutor",
|
||||
"HardwareCodecCapabilityUtils",
|
||||
"Image",
|
||||
"ImageDecoder",
|
||||
"MediaDrmProxy",
|
||||
"PanZoomController",
|
||||
|
Loading…
Reference in New Issue
Block a user