Commit d3ec80bc authored by Miyoung Shin's avatar Miyoung Shin Committed by Chromium LUCI CQ

[remoteobjects] Pass all tests with MojoTestParams from JavaBridgeArrayCoercionTest

This CL update the codes so that all tests from
JavaBridgeArrayCoercionTest pass with MojoTestParams.

Bug: 1148997
Change-Id: Iaf3fce7ef63e5e7732296ce3775fa6be0d04f108
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2571031Reviewed-by: default avatarKinuko Yasuda <kinuko@chromium.org>
Reviewed-by: default avatarRichard Coles <torne@chromium.org>
Reviewed-by: default avatarOksana Zhuravlova <oksamyt@chromium.org>
Reviewed-by: default avatarJeremy Roman <jbroman@chromium.org>
Commit-Queue: Miyoung Shin <myid.shin@igalia.com>
Cr-Commit-Position: refs/heads/master@{#843828}
parent a210a63b
......@@ -587,6 +587,7 @@ junit_binary("content_junit_tests") {
"//base:base_junit_test_support",
"//content/public/test/android:content_java_test_support",
"//media/mojo/mojom:mojom_java",
"//mojo/public/java:base_java",
"//mojo/public/java:bindings_java",
"//mojo/public/mojom/base:base_java",
"//services/device/public/mojom:mojom_java",
......
......@@ -6,13 +6,16 @@ package org.chromium.content.browser.remoteobjects;
import androidx.annotation.IntDef;
import org.chromium.blink.mojom.RemoteArrayType;
import org.chromium.blink.mojom.RemoteInvocationArgument;
import org.chromium.blink.mojom.RemoteInvocationError;
import org.chromium.blink.mojom.RemoteInvocationResult;
import org.chromium.blink.mojom.RemoteInvocationResultValue;
import org.chromium.blink.mojom.RemoteObject;
import org.chromium.blink.mojom.RemoteTypedArray;
import org.chromium.blink.mojom.SingletonJavaScriptValue;
import org.chromium.mojo.system.MojoException;
import org.chromium.mojo_base.BigBufferUtil;
import org.chromium.mojo_base.mojom.String16;
import java.lang.annotation.Annotation;
......@@ -22,6 +25,12 @@ import java.lang.ref.WeakReference;
import java.lang.reflect.Array;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.DoubleBuffer;
import java.nio.FloatBuffer;
import java.nio.IntBuffer;
import java.nio.ShortBuffer;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
......@@ -112,6 +121,10 @@ class RemoteObjectImpl implements RemoteObject {
private boolean mNotifiedReleasedObject;
public static final short UNSIGNED_BYTE_MASK = 0xff;
public static final int UNSIGNED_SHORT_MASK = 0xffff;
public static final long UNSIGNED_INT_MASK = 0xffffffffL;
public RemoteObjectImpl(Object target, Class<? extends Annotation> safeAnnotationClass,
Auditor auditor, ObjectIdAllocator objectIdAllocator, boolean allowInspection) {
mTarget = new WeakReference<>(target);
......@@ -271,6 +284,153 @@ class RemoteObjectImpl implements RemoteObject {
int COERCE = 1;
}
private static Object convertPrimitiveArrayElement(Number number, Class<?> parameterType) {
assert (parameterType.isPrimitive() && parameterType != boolean.class);
if (parameterType == byte.class) {
return number.byteValue();
} else if (parameterType == char.class) {
return (char) (number.intValue() & UNSIGNED_SHORT_MASK);
} else if (parameterType == short.class) {
return number.shortValue();
} else if (parameterType == int.class) {
return number.intValue();
} else if (parameterType == long.class) {
return number.longValue();
} else if (parameterType == float.class) {
return number.floatValue();
}
return number.doubleValue();
}
private abstract static class WrapBuffer {
private Class<?> mParameterType;
protected int mLength;
WrapBuffer(Class<?> parameterType) {
mParameterType = parameterType;
}
public Object copyArray() {
if (mParameterType == boolean.class) {
// LIVECONNECT_COMPLIANCE: Existing behavior is to convert to false. Spec
// requires converting to false for 0 or NaN, true otherwise.
// The default value of the boolean elements in a boolean array is false.
return new boolean[mLength];
} else if (isFloatType() && mParameterType == char.class) {
// LIVECONNECT_COMPLIANCE: Existing behavior is to convert floating-point types to
// 0. Spec requires converting doubles similarly to how we convert floating-point
// types to other numeric types.
// The default value of the char elements in a char array is 0.
return new char[mLength];
} else if (mParameterType == String.class) {
// LIVECONNECT_COMPLIANCE: Existing behavior is to convert to null for all.
// The default value of the String elements in a String array is null.
return new String[mLength];
}
Object result = Array.newInstance(mParameterType, mLength);
for (int i = 0; i < mLength; i++) {
Array.set(result, i, convertPrimitiveArrayElement(get(i), mParameterType));
}
return result;
}
protected abstract Number get(int index);
protected boolean isFloatType() {
return false;
}
}
private static class WrapByteBuffer extends WrapBuffer {
ByteBuffer mBuffer;
boolean mUnsigned;
WrapByteBuffer(ByteBuffer buffer, Class<?> parameterType, boolean unsigned) {
super(parameterType);
mBuffer = buffer;
mLength = mBuffer.limit();
mUnsigned = unsigned;
}
@Override
protected Number get(int index) {
byte number = mBuffer.get(index);
return (mUnsigned ? (short) (number & UNSIGNED_BYTE_MASK) : number);
}
}
private static class WrapShortBuffer extends WrapBuffer {
ShortBuffer mBuffer;
boolean mUnsigned;
WrapShortBuffer(ShortBuffer buffer, Class<?> parameterType, boolean unsigned) {
super(parameterType);
mBuffer = buffer;
mLength = mBuffer.limit();
mUnsigned = unsigned;
}
@Override
protected Number get(int index) {
short number = mBuffer.get(index);
return (mUnsigned ? (int) (number & UNSIGNED_SHORT_MASK) : number);
}
}
private static class WrapIntBuffer extends WrapBuffer {
IntBuffer mBuffer;
boolean mUnsigned;
WrapIntBuffer(IntBuffer buffer, Class<?> parameterType, boolean unsigned) {
super(parameterType);
mBuffer = buffer;
mLength = mBuffer.limit();
mUnsigned = unsigned;
}
@Override
protected Number get(int index) {
int number = mBuffer.get(index);
return (mUnsigned ? (long) (number & UNSIGNED_INT_MASK) : number);
}
}
private static class WrapFloatBuffer extends WrapBuffer {
FloatBuffer mBuffer;
WrapFloatBuffer(FloatBuffer buffer, Class<?> parameterType) {
super(parameterType);
mBuffer = buffer;
mLength = mBuffer.limit();
}
@Override
protected Number get(int index) {
return mBuffer.get(index);
}
@Override
protected boolean isFloatType() {
return true;
}
}
private static class WrapDoubleBuffer extends WrapBuffer {
DoubleBuffer mBuffer;
WrapDoubleBuffer(DoubleBuffer buffer, Class<?> parameterType) {
super(parameterType);
mBuffer = buffer;
mLength = mBuffer.limit();
}
@Override
protected Number get(int index) {
return mBuffer.get(index);
}
@Override
protected boolean isFloatType() {
return true;
}
}
private static Object convertArgument(RemoteInvocationArgument argument, Class<?> parameterType,
@StringCoercionMode int stringCoercionMode) {
switch (argument.which()) {
......@@ -404,6 +564,62 @@ class RemoteObjectImpl implements RemoteObject {
// raising a JavaScript exception.
return null;
}
case RemoteInvocationArgument.Tag.TypedArrayValue:
RemoteTypedArray typedArrayValue = argument.getTypedArrayValue();
if (parameterType.isArray()) {
Class<?> componentType = parameterType.getComponentType();
// LIVECONNECT_COMPLIANCE: Existing behavior is to return null for
// multi-dimensional and object arrays. Spec requires handling them.
if (!componentType.isPrimitive() && componentType != String.class) {
return null;
} else if (componentType.isArray()) {
// LIVECONNECT_COMPLIANCE: Existing behavior is to convert to NULL. Spec
// requires raising a JavaScript exception.
return null;
}
// TODO(crbug.com/794320): Remove unnecessary copy for the performance.
ByteBuffer typedBuffer = ByteBuffer.wrap(
BigBufferUtil.getBytesFromBigBuffer(typedArrayValue.buffer));
typedBuffer.order(ByteOrder.nativeOrder());
if (typedArrayValue.type == RemoteArrayType.INT8_ARRAY) {
return new WrapByteBuffer(typedBuffer, componentType, false).copyArray();
} else if (typedArrayValue.type == RemoteArrayType.UINT8_ARRAY) {
return new WrapByteBuffer(typedBuffer, componentType, true).copyArray();
} else if (typedArrayValue.type == RemoteArrayType.INT16_ARRAY) {
return new WrapShortBuffer(
typedBuffer.asShortBuffer(), componentType, false)
.copyArray();
} else if (typedArrayValue.type == RemoteArrayType.UINT16_ARRAY) {
return new WrapShortBuffer(typedBuffer.asShortBuffer(), componentType, true)
.copyArray();
} else if (typedArrayValue.type == RemoteArrayType.INT32_ARRAY) {
return new WrapIntBuffer(typedBuffer.asIntBuffer(), componentType, false)
.copyArray();
} else if (typedArrayValue.type == RemoteArrayType.UINT32_ARRAY) {
return new WrapIntBuffer(typedBuffer.asIntBuffer(), componentType, true)
.copyArray();
} else if (typedArrayValue.type == RemoteArrayType.FLOAT32_ARRAY) {
return new WrapFloatBuffer(typedBuffer.asFloatBuffer(), componentType)
.copyArray();
} else if (typedArrayValue.type == RemoteArrayType.FLOAT64_ARRAY) {
return new WrapDoubleBuffer(typedBuffer.asDoubleBuffer(), componentType)
.copyArray();
} else {
return null;
}
} else if (parameterType == String.class) {
return stringCoercionMode == StringCoercionMode.COERCE ? "undefined" : null;
} else if (parameterType.isPrimitive()) {
return getPrimitiveZero(parameterType);
} else {
// LIVECONNECT_COMPLIANCE: Existing behavior is to pass null. Spec requires
// converting if the target type is netscape.javascript.JSObject, otherwise
// raising a JavaScript exception.
return null;
}
default:
throw new RuntimeException("invalid wire argument type");
}
......
......@@ -705,7 +705,7 @@ public class JavaBridgeArrayCoercionTest {
@Test
@SmallTest
@Feature({"AndroidWebView", "Android-JavaBridge"})
@UseMethodParameter(JavaBridgeActivityTestRule.LegacyTestParams.class)
@UseMethodParameter(JavaBridgeActivityTestRule.MojoTestParams.class)
public void testPassInt8Array(boolean useMojo) throws Throwable {
mActivityTestRule.executeJavaScript("buffer = new ArrayBuffer(1);");
mActivityTestRule.executeJavaScript("int8_array = new Int8Array(buffer);");
......@@ -781,7 +781,7 @@ public class JavaBridgeArrayCoercionTest {
@Test
@SmallTest
@Feature({"AndroidWebView", "Android-JavaBridge"})
@UseMethodParameter(JavaBridgeActivityTestRule.LegacyTestParams.class)
@UseMethodParameter(JavaBridgeActivityTestRule.MojoTestParams.class)
public void testPassUint8Array(boolean useMojo) throws Throwable {
mActivityTestRule.executeJavaScript("buffer = new ArrayBuffer(1);");
mActivityTestRule.executeJavaScript("uint8_array = new Uint8Array(buffer);");
......@@ -856,7 +856,7 @@ public class JavaBridgeArrayCoercionTest {
@Test
@SmallTest
@Feature({"AndroidWebView", "Android-JavaBridge"})
@UseMethodParameter(JavaBridgeActivityTestRule.LegacyTestParams.class)
@UseMethodParameter(JavaBridgeActivityTestRule.MojoTestParams.class)
public void testPassInt16Array(boolean useMojo) throws Throwable {
mActivityTestRule.executeJavaScript("buffer = new ArrayBuffer(2);");
mActivityTestRule.executeJavaScript("int16_array = new Int16Array(buffer);");
......@@ -900,7 +900,7 @@ public class JavaBridgeArrayCoercionTest {
@Test
@SmallTest
@Feature({"AndroidWebView", "Android-JavaBridge"})
@UseMethodParameter(JavaBridgeActivityTestRule.LegacyTestParams.class)
@UseMethodParameter(JavaBridgeActivityTestRule.MojoTestParams.class)
public void testPassUint16Array(boolean useMojo) throws Throwable {
mActivityTestRule.executeJavaScript("buffer = new ArrayBuffer(2);");
mActivityTestRule.executeJavaScript("uint16_array = new Uint16Array(buffer);");
......@@ -944,7 +944,7 @@ public class JavaBridgeArrayCoercionTest {
@Test
@SmallTest
@Feature({"AndroidWebView", "Android-JavaBridge"})
@UseMethodParameter(JavaBridgeActivityTestRule.LegacyTestParams.class)
@UseMethodParameter(JavaBridgeActivityTestRule.MojoTestParams.class)
public void testPassUint16ArrayWithMaxValue(boolean useMojo) throws Throwable {
mActivityTestRule.executeJavaScript("buffer = new ArrayBuffer(2);");
mActivityTestRule.executeJavaScript("uint16_array = new Uint16Array(buffer);");
......@@ -979,7 +979,7 @@ public class JavaBridgeArrayCoercionTest {
@Test
@SmallTest
@Feature({"AndroidWebView", "Android-JavaBridge"})
@UseMethodParameter(JavaBridgeActivityTestRule.LegacyTestParams.class)
@UseMethodParameter(JavaBridgeActivityTestRule.MojoTestParams.class)
public void testPassInt32Array(boolean useMojo) throws Throwable {
mActivityTestRule.executeJavaScript("buffer = new ArrayBuffer(4);");
mActivityTestRule.executeJavaScript("int32_array = new Int32Array(buffer);");
......@@ -1023,7 +1023,7 @@ public class JavaBridgeArrayCoercionTest {
@Test
@SmallTest
@Feature({"AndroidWebView", "Android-JavaBridge"})
@UseMethodParameter(JavaBridgeActivityTestRule.LegacyTestParams.class)
@UseMethodParameter(JavaBridgeActivityTestRule.MojoTestParams.class)
public void testPassUint32Array(boolean useMojo) throws Throwable {
mActivityTestRule.executeJavaScript("buffer = new ArrayBuffer(4);");
mActivityTestRule.executeJavaScript("uint32_array = new Uint32Array(buffer);");
......@@ -1067,7 +1067,7 @@ public class JavaBridgeArrayCoercionTest {
@Test
@SmallTest
@Feature({"AndroidWebView", "Android-JavaBridge"})
@UseMethodParameter(JavaBridgeActivityTestRule.LegacyTestParams.class)
@UseMethodParameter(JavaBridgeActivityTestRule.MojoTestParams.class)
public void testPassUint32ArrayWithMaxValue(boolean useMojo) throws Throwable {
mActivityTestRule.executeJavaScript("buffer = new ArrayBuffer(4);");
mActivityTestRule.executeJavaScript("uint32_array = new Uint32Array(buffer);");
......@@ -1103,7 +1103,7 @@ public class JavaBridgeArrayCoercionTest {
@Test
@SmallTest
@Feature({"AndroidWebView", "Android-JavaBridge"})
@UseMethodParameter(JavaBridgeActivityTestRule.LegacyTestParams.class)
@UseMethodParameter(JavaBridgeActivityTestRule.MojoTestParams.class)
public void testPassFloat32Array(boolean useMojo) throws Throwable {
mActivityTestRule.executeJavaScript("buffer = new ArrayBuffer(4);");
mActivityTestRule.executeJavaScript("float32_array = new Float32Array(buffer);");
......@@ -1147,7 +1147,7 @@ public class JavaBridgeArrayCoercionTest {
@Test
@SmallTest
@Feature({"AndroidWebView", "Android-JavaBridge"})
@UseMethodParameter(JavaBridgeActivityTestRule.LegacyTestParams.class)
@UseMethodParameter(JavaBridgeActivityTestRule.MojoTestParams.class)
public void testPassFloat64Array(boolean useMojo) throws Throwable {
mActivityTestRule.executeJavaScript("buffer = new ArrayBuffer(8);");
mActivityTestRule.executeJavaScript("float64_array = new Float64Array(buffer);");
......
......@@ -24,12 +24,15 @@ import org.mockito.InOrder;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.chromium.blink.mojom.RemoteArrayType;
import org.chromium.blink.mojom.RemoteInvocationArgument;
import org.chromium.blink.mojom.RemoteInvocationError;
import org.chromium.blink.mojom.RemoteInvocationResult;
import org.chromium.blink.mojom.RemoteInvocationResultValue;
import org.chromium.blink.mojom.RemoteObject;
import org.chromium.blink.mojom.RemoteTypedArray;
import org.chromium.blink.mojom.SingletonJavaScriptValue;
import org.chromium.mojo_base.BigBufferUtil;
import org.chromium.mojo_base.mojom.String16;
import java.lang.annotation.Annotation;
......@@ -398,10 +401,22 @@ public final class RemoteObjectImplTest {
mConsumer.accept(oa);
}
@TestJavascriptInterface
public void consumeBooleanArray(boolean[] ba) {
mConsumer.accept(ba);
}
@TestJavascriptInterface
public void consumeIntArray(int[] ia) {
mConsumer.accept(ia);
}
@TestJavascriptInterface
public void consumeFloatArray(float[] fa) {
mConsumer.accept(fa);
}
@TestJavascriptInterface
public void consumeDoubleArray(double[] da) {
mConsumer.accept(da);
}
@TestJavascriptInterface
public void consumeStringArray(String[] sa) {
mConsumer.accept(sa);
}
......@@ -662,6 +677,94 @@ public final class RemoteObjectImplTest {
verify(consumer, times(2)).accept(null);
}
@Test
public void testArgumentConversionTypedIntArray() {
final Consumer<Object> consumer = (Consumer<Object>) mock(Consumer.class);
Object target = new VariantConsumer(consumer);
RemoteObject remoteObject = newRemoteObjectImpl(target, TestJavascriptInterface.class);
RemoteObject.InvokeMethodResponse response = mock(RemoteObject.InvokeMethodResponse.class);
RemoteInvocationArgument args[] = {typedArrayArgument(RemoteArrayType.INT8_ARRAY,
BigBufferUtil.createBigBufferFromBytes(new byte[] {3, 2, 1, 0}))};
remoteObject.invokeMethod("consumeByte", args, response);
remoteObject.invokeMethod("consumeChar", args, response);
remoteObject.invokeMethod("consumeShort", args, response);
remoteObject.invokeMethod("consumeInt", args, response);
remoteObject.invokeMethod("consumeLong", args, response);
remoteObject.invokeMethod("consumeFloat", args, response);
remoteObject.invokeMethod("consumeDouble", args, response);
remoteObject.invokeMethod("consumeBoolean", args, response);
remoteObject.invokeMethod("consumeString", args, response);
remoteObject.invokeMethod("consumeBooleanArray", args, response);
remoteObject.invokeMethod("consumeIntArray", args, response);
remoteObject.invokeMethod("consumeFloatArray", args, response);
remoteObject.invokeMethod("consumeDoubleArray", args, response);
remoteObject.invokeMethod("consumeStringArray", args, response);
remoteObject.invokeMethod("consumeObjectArray", args, response);
remoteObject.invokeMethod("consumeObject", args, response);
verify(consumer).accept((byte) 0);
verify(consumer).accept('\u0000');
verify(consumer).accept((short) 0);
verify(consumer).accept((int) 0);
verify(consumer).accept((long) 0);
verify(consumer).accept((float) 0);
verify(consumer).accept((double) 0);
verify(consumer).accept(false);
verify(consumer).accept("undefined");
verify(consumer).accept(aryEq(new boolean[] {false, false, false, false}));
verify(consumer).accept(aryEq(new int[] {3, 2, 1, 0}));
verify(consumer).accept(aryEq(new float[] {3, 2, 1, 0}));
verify(consumer).accept(aryEq(new double[] {3, 2, 1, 0}));
verify(consumer).accept(aryEq(new String[] {null, null, null, null}));
verify(consumer, times(2)).accept(null);
}
@Test
public void testArgumentConversionTypedDoubleArray() {
final Consumer<Object> consumer = (Consumer<Object>) mock(Consumer.class);
Object target = new VariantConsumer(consumer);
RemoteObject remoteObject = newRemoteObjectImpl(target, TestJavascriptInterface.class);
RemoteObject.InvokeMethodResponse response = mock(RemoteObject.InvokeMethodResponse.class);
RemoteInvocationArgument args[] = {typedArrayArgument(RemoteArrayType.FLOAT64_ARRAY,
BigBufferUtil.createBigBufferFromBytes(
new byte[] {51, 51, 51, 51, 51, 51, 36, 64}))};
remoteObject.invokeMethod("consumeByte", args, response);
remoteObject.invokeMethod("consumeChar", args, response);
remoteObject.invokeMethod("consumeShort", args, response);
remoteObject.invokeMethod("consumeInt", args, response);
remoteObject.invokeMethod("consumeLong", args, response);
remoteObject.invokeMethod("consumeFloat", args, response);
remoteObject.invokeMethod("consumeDouble", args, response);
remoteObject.invokeMethod("consumeBoolean", args, response);
remoteObject.invokeMethod("consumeString", args, response);
remoteObject.invokeMethod("consumeBooleanArray", args, response);
remoteObject.invokeMethod("consumeIntArray", args, response);
remoteObject.invokeMethod("consumeFloatArray", args, response);
remoteObject.invokeMethod("consumeDoubleArray", args, response);
remoteObject.invokeMethod("consumeStringArray", args, response);
remoteObject.invokeMethod("consumeObjectArray", args, response);
remoteObject.invokeMethod("consumeObject", args, response);
verify(consumer).accept((byte) 0);
verify(consumer).accept('\u0000');
verify(consumer).accept((short) 0);
verify(consumer).accept((int) 0);
verify(consumer).accept((long) 0);
verify(consumer).accept((float) 0);
verify(consumer).accept((double) 0);
verify(consumer).accept(false);
verify(consumer).accept("undefined");
verify(consumer).accept(aryEq(new boolean[] {false}));
verify(consumer).accept(aryEq(new int[] {10}));
verify(consumer).accept(aryEq(new float[] {10.1f}));
verify(consumer).accept(aryEq(new double[] {10.1}));
verify(consumer).accept(aryEq(new String[] {null}));
verify(consumer, times(2)).accept(null);
}
@Test
public void testResultConversionVoid() {
Object target = new Object() {
......@@ -889,6 +992,16 @@ public final class RemoteObjectImplTest {
return argument;
}
private RemoteInvocationArgument typedArrayArgument(
int type, org.chromium.mojo_base.mojom.BigBuffer buffer) {
RemoteInvocationArgument argument = new RemoteInvocationArgument();
RemoteTypedArray typedArray = new RemoteTypedArray();
typedArray.type = type;
typedArray.buffer = buffer;
argument.setTypedArrayValue(typedArray);
return argument;
}
private RemoteObjectImpl newRemoteObjectImpl(
Object target, Class<? extends Annotation> annotation) {
return newRemoteObjectImpl(target, annotation, true);
......
......@@ -4,6 +4,7 @@
module blink.mojom;
import "mojo/public/mojom/base/big_buffer.mojom";
import "mojo/public/mojom/base/string16.mojom";
// These interfaces allow an object implemented outside the Blink renderer
......@@ -65,12 +66,29 @@ enum SingletonJavaScriptValue {
kUndefined,
};
enum RemoteArrayType {
kInt8Array = 1,
kUint8Array,
kInt16Array,
kUint16Array,
kInt32Array,
kUint32Array,
kFloat32Array,
kFloat64Array,
};
struct RemoteTypedArray {
RemoteArrayType type;
mojo_base.mojom.BigBuffer buffer;
};
union RemoteInvocationArgument {
double number_value;
bool boolean_value;
mojo_base.mojom.String16 string_value;
SingletonJavaScriptValue singleton_value;
array<RemoteInvocationArgument> array_value;
RemoteTypedArray typed_array_value;
};
enum RemoteInvocationError {
......
......@@ -130,6 +130,41 @@ mojom::blink::RemoteInvocationArgumentPtr JSValueToMojom(
std::move(nested_arguments));
}
if (js_value->IsTypedArray()) {
auto typed_array = js_value.As<v8::TypedArray>();
mojom::blink::RemoteArrayType array_type;
if (typed_array->IsInt8Array()) {
array_type = mojom::blink::RemoteArrayType::kInt8Array;
} else if (typed_array->IsUint8Array() ||
typed_array->IsUint8ClampedArray()) {
array_type = mojom::blink::RemoteArrayType::kUint8Array;
} else if (typed_array->IsInt16Array()) {
array_type = mojom::blink::RemoteArrayType::kInt16Array;
} else if (typed_array->IsUint16Array()) {
array_type = mojom::blink::RemoteArrayType::kUint16Array;
} else if (typed_array->IsInt32Array()) {
array_type = mojom::blink::RemoteArrayType::kInt32Array;
} else if (typed_array->IsUint32Array()) {
array_type = mojom::blink::RemoteArrayType::kUint32Array;
} else if (typed_array->IsFloat32Array()) {
array_type = mojom::blink::RemoteArrayType::kFloat32Array;
} else if (typed_array->IsFloat64Array()) {
array_type = mojom::blink::RemoteArrayType::kFloat64Array;
} else {
return nullptr;
}
auto remote_typed_array = mojom::blink::RemoteTypedArray::New();
mojo_base::BigBuffer buffer(typed_array->ByteLength());
typed_array->CopyContents(buffer.data(), buffer.size());
remote_typed_array->buffer = std::move(buffer);
remote_typed_array->type = array_type;
return mojom::blink::RemoteInvocationArgument::NewTypedArrayValue(
std::move(remote_typed_array));
}
return nullptr;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment