- 28,932 files - Full Java source code - Smali files - Resources Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
100 lines
4.4 KiB
Java
100 lines
4.4 KiB
Java
package androidx.webkit.internal;
|
|
|
|
import androidx.annotation.NonNull;
|
|
import androidx.annotation.Nullable;
|
|
import androidx.webkit.WebMessageCompat;
|
|
import androidx.webkit.WebMessagePortCompat;
|
|
import androidx.webkit.WebViewFeature;
|
|
import java.lang.reflect.InvocationHandler;
|
|
import java.util.Objects;
|
|
import org.chromium.support_lib_boundary.WebMessageBoundaryInterface;
|
|
import org.chromium.support_lib_boundary.WebMessagePayloadBoundaryInterface;
|
|
import org.chromium.support_lib_boundary.util.BoundaryInterfaceReflectionUtil;
|
|
|
|
/* loaded from: classes.dex */
|
|
public class WebMessageAdapter implements WebMessageBoundaryInterface {
|
|
private static final String[] sFeatures = {WebViewFeature.WEB_MESSAGE_ARRAY_BUFFER};
|
|
private WebMessageCompat mWebMessageCompat;
|
|
|
|
@Override // org.chromium.support_lib_boundary.FeatureFlagHolderBoundaryInterface
|
|
@NonNull
|
|
public String[] getSupportedFeatures() {
|
|
return sFeatures;
|
|
}
|
|
|
|
public WebMessageAdapter(@NonNull WebMessageCompat webMessageCompat) {
|
|
this.mWebMessageCompat = webMessageCompat;
|
|
}
|
|
|
|
@Override // org.chromium.support_lib_boundary.WebMessageBoundaryInterface
|
|
@Nullable
|
|
@Deprecated
|
|
public String getData() {
|
|
return this.mWebMessageCompat.getData();
|
|
}
|
|
|
|
@Override // org.chromium.support_lib_boundary.WebMessageBoundaryInterface
|
|
@Nullable
|
|
public InvocationHandler getMessagePayload() {
|
|
WebMessagePayloadAdapter webMessagePayloadAdapter;
|
|
int type = this.mWebMessageCompat.getType();
|
|
if (type == 0) {
|
|
webMessagePayloadAdapter = new WebMessagePayloadAdapter(this.mWebMessageCompat.getData());
|
|
} else if (type == 1) {
|
|
byte[] arrayBuffer = this.mWebMessageCompat.getArrayBuffer();
|
|
Objects.requireNonNull(arrayBuffer);
|
|
webMessagePayloadAdapter = new WebMessagePayloadAdapter(arrayBuffer);
|
|
} else {
|
|
throw new IllegalStateException("Unknown web message payload type: " + this.mWebMessageCompat.getType());
|
|
}
|
|
return BoundaryInterfaceReflectionUtil.createInvocationHandlerFor(webMessagePayloadAdapter);
|
|
}
|
|
|
|
@Override // org.chromium.support_lib_boundary.WebMessageBoundaryInterface
|
|
@Nullable
|
|
public InvocationHandler[] getPorts() {
|
|
WebMessagePortCompat[] ports = this.mWebMessageCompat.getPorts();
|
|
if (ports == null) {
|
|
return null;
|
|
}
|
|
InvocationHandler[] invocationHandlerArr = new InvocationHandler[ports.length];
|
|
for (int i = 0; i < ports.length; i++) {
|
|
invocationHandlerArr[i] = ports[i].getInvocationHandler();
|
|
}
|
|
return invocationHandlerArr;
|
|
}
|
|
|
|
public static boolean isMessagePayloadTypeSupportedByWebView(int i) {
|
|
if (i != 0) {
|
|
return i == 1 && WebViewFeatureInternal.WEB_MESSAGE_ARRAY_BUFFER.isSupportedByWebView();
|
|
}
|
|
return true;
|
|
}
|
|
|
|
@Nullable
|
|
public static WebMessageCompat webMessageCompatFromBoundaryInterface(@NonNull WebMessageBoundaryInterface webMessageBoundaryInterface) {
|
|
WebMessagePortCompat[] webMessagePortCompats = toWebMessagePortCompats(webMessageBoundaryInterface.getPorts());
|
|
if (WebViewFeatureInternal.WEB_MESSAGE_ARRAY_BUFFER.isSupportedByWebView()) {
|
|
WebMessagePayloadBoundaryInterface webMessagePayloadBoundaryInterface = (WebMessagePayloadBoundaryInterface) BoundaryInterfaceReflectionUtil.castToSuppLibClass(WebMessagePayloadBoundaryInterface.class, webMessageBoundaryInterface.getMessagePayload());
|
|
int type = webMessagePayloadBoundaryInterface.getType();
|
|
if (type == 0) {
|
|
return new WebMessageCompat(webMessagePayloadBoundaryInterface.getAsString(), webMessagePortCompats);
|
|
}
|
|
if (type != 1) {
|
|
return null;
|
|
}
|
|
return new WebMessageCompat(webMessagePayloadBoundaryInterface.getAsArrayBuffer(), webMessagePortCompats);
|
|
}
|
|
return new WebMessageCompat(webMessageBoundaryInterface.getData(), webMessagePortCompats);
|
|
}
|
|
|
|
@NonNull
|
|
private static WebMessagePortCompat[] toWebMessagePortCompats(InvocationHandler[] invocationHandlerArr) {
|
|
WebMessagePortCompat[] webMessagePortCompatArr = new WebMessagePortCompat[invocationHandlerArr.length];
|
|
for (int i = 0; i < invocationHandlerArr.length; i++) {
|
|
webMessagePortCompatArr[i] = new WebMessagePortImpl(invocationHandlerArr[i]);
|
|
}
|
|
return webMessagePortCompatArr;
|
|
}
|
|
}
|