导航菜单

页面标题

页面副标题

Rilo v2.0.21 - PaymentAuthWebViewClient.java 源代码

正在查看: Rilo v2.0.21 应用的 PaymentAuthWebViewClient.java JAVA 源代码文件

本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。


package com.stripe.android.view;

import android.content.Intent;
import android.net.Uri;
import android.webkit.URLUtil;
import android.webkit.WebResourceRequest;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import com.stripe.android.core.Logger;
import com.stripe.android.payments.DefaultReturnUrl;
import java.util.Collection;
import java.util.Iterator;
import java.util.Set;
import kotlin.Metadata;
import kotlin.Result;
import kotlin.ResultKt;
import kotlin.Unit;
import kotlin.collections.SetsKt;
import kotlin.jvm.functions.Function1;
import kotlin.jvm.internal.DefaultConstructorMarker;
import kotlin.jvm.internal.Intrinsics;
import kotlin.text.StringsKt;
import kotlinx.coroutines.flow.MutableStateFlow;

@Metadata(d1 = {"\u0000P\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\u0010\u000b\n\u0000\n\u0002\u0010\u000e\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\u0010\u0002\n\u0000\n\u0002\u0010\u0003\n\u0002\b\u000b\n\u0002\u0018\u0002\n\u0002\b\b\n\u0002\u0018\u0002\n\u0002\b\u0006\n\u0002\u0018\u0002\n\u0002\b\u0003\b\u0000\u0018\u0000 -2\u00020\u0001:\u0001-BW\u0012\u0006\u0010\u0002\u001a\u00020\u0003\u0012\f\u0010\u0004\u001a\b\u0012\u0004\u0012\u00020\u00060\u0005\u0012\u0006\u0010\u0007\u001a\u00020\b\u0012\b\u0010\t\u001a\u0004\u0018\u00010\b\u0012\u0012\u0010\n\u001a\u000e\u0012\u0004\u0012\u00020\f\u0012\u0004\u0012\u00020\r0\u000b\u0012\u0014\u0010\u000e\u001a\u0010\u0012\u0006\u0012\u0004\u0018\u00010\u000f\u0012\u0004\u0012\u00020\r0\u000b¢\u0006\u0002\u0010\u0010J\b\u0010\u001c\u001a\u00020\rH\u0002J\u0010\u0010\u001d\u001a\u00020\u00062\u0006\u0010\u001e\u001a\u00020\u001bH\u0002J\u0010\u0010\u001f\u001a\u00020\u00062\u0006\u0010\u001e\u001a\u00020\u001bH\u0002J\u0014\u0010 \u001a\u00020\r2\n\b\u0002\u0010!\u001a\u0004\u0018\u00010\u000fH\u0002J\u001a\u0010\"\u001a\u00020\r2\u0006\u0010#\u001a\u00020$2\b\u0010%\u001a\u0004\u0018\u00010\bH\u0016J\u0010\u0010&\u001a\u00020\r2\u0006\u0010'\u001a\u00020\fH\u0002J\u0010\u0010(\u001a\u00020\r2\u0006\u0010\u001e\u001a\u00020\u001bH\u0002J\u0018\u0010)\u001a\u00020\u00062\u0006\u0010#\u001a\u00020$2\u0006\u0010*\u001a\u00020+H\u0016J\u0010\u0010,\u001a\u00020\r2\u0006\u0010\u001e\u001a\u00020\u001bH\u0002R\u001c\u0010\u000e\u001a\u0010\u0012\u0006\u0012\u0004\u0018\u00010\u000f\u0012\u0004\u0012\u00020\r0\u000bX\u0082\u0004¢\u0006\u0002\n\u0000R\u001a\u0010\n\u001a\u000e\u0012\u0004\u0012\u00020\f\u0012\u0004\u0012\u00020\r0\u000bX\u0082\u0004¢\u0006\u0002\n\u0000R\u000e\u0010\u0007\u001a\u00020\bX\u0082\u0004¢\u0006\u0002\n\u0000R\"\u0010\u0012\u001a\u0004\u0018\u00010\b2\b\u0010\u0011\u001a\u0004\u0018\u00010\b@BX\u0086\u000e¢\u0006\b\n\u0000\u001a\u0004\b\u0013\u0010\u0014R\u001a\u0010\u0015\u001a\u00020\u0006X\u0080\u000e¢\u0006\u000e\n\u0000\u001a\u0004\b\u0016\u0010\u0017\"\u0004\b\u0018\u0010\u0019R\u0014\u0010\u0004\u001a\b\u0012\u0004\u0012\u00020\u00060\u0005X\u0082\u0004¢\u0006\u0002\n\u0000R\u000e\u0010\u0002\u001a\u00020\u0003X\u0082\u0004¢\u0006\u0002\n\u0000R\u0010\u0010\u001a\u001a\u0004\u0018\u00010\u001bX\u0082\u0004¢\u0006\u0002\n\u0000¨\u0006."}, d2 = {"Lcom/stripe/android/view/PaymentAuthWebViewClient;", "Landroid/webkit/WebViewClient;", "logger", "Lcom/stripe/android/core/Logger;", "isPageLoaded", "Lkotlinx/coroutines/flow/MutableStateFlow;", "", "clientSecret", "", "returnUrl", "activityStarter", "Lkotlin/Function1;", "Landroid/content/Intent;", "", "activityFinisher", "", "(Lcom/stripe/android/core/Logger;Lkotlinx/coroutines/flow/MutableStateFlow;Ljava/lang/String;Ljava/lang/String;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)V", "<set-?>", "completionUrlParam", "getCompletionUrlParam", "()Ljava/lang/String;", "hasLoadedBlank", "getHasLoadedBlank$payments_core_release", "()Z", "setHasLoadedBlank$payments_core_release", "(Z)V", "userReturnUri", "Landroid/net/Uri;", "hideProgressBar", "isPredefinedReturnUrl", "uri", "isReturnUrl", "onAuthCompleted", "error", "onPageFinished", "view", "Landroid/webkit/WebView;", "url", "openIntent", "intent", "openIntentScheme", "shouldOverrideUrlLoading", "request", "Landroid/webkit/WebResourceRequest;", "updateCompletionUrl", "Companion", "payments-core_release"}, k = 1, mv = {1, 8, 0}, xi = 48)
public final class PaymentAuthWebViewClient extends WebViewClient {
    public static final String BLANK_PAGE = "about:blank";
    public static final String PARAM_PAYMENT_CLIENT_SECRET = "payment_intent_client_secret";
    private static final String PARAM_RETURN_URL = "return_url";
    public static final String PARAM_SETUP_CLIENT_SECRET = "setup_intent_client_secret";
    private final Function1<Throwable, Unit> activityFinisher;
    private final Function1<Intent, Unit> activityStarter;
    private final String clientSecret;
    private String completionUrlParam;
    private boolean hasLoadedBlank;
    private final MutableStateFlow<Boolean> isPageLoaded;
    private final Logger logger;
    private final Uri userReturnUri;

    public static final Companion INSTANCE = new Companion(null);
    private static final Set<String> AUTHENTICATE_URLS = SetsKt.setOf("https://hooks.stripe.com/three_d_secure/authenticate");
    private static final Set<String> COMPLETION_URLS = SetsKt.setOf(new String[]{"https://hooks.stripe.com/redirect/complete/", "https://hooks.stripe.com/3d_secure/complete/", "https://hooks.stripe.com/3d_secure_2/hosted/complete"});

    public PaymentAuthWebViewClient(Logger logger, MutableStateFlow<Boolean> mutableStateFlow, String str, String str2, Function1<? super Intent, Unit> function1, Function1<? super Throwable, Unit> function12) {
        Intrinsics.checkNotNullParameter(logger, "logger");
        Intrinsics.checkNotNullParameter(mutableStateFlow, "isPageLoaded");
        Intrinsics.checkNotNullParameter(str, "clientSecret");
        Intrinsics.checkNotNullParameter(function1, "activityStarter");
        Intrinsics.checkNotNullParameter(function12, "activityFinisher");
        this.logger = logger;
        this.isPageLoaded = mutableStateFlow;
        this.clientSecret = str;
        this.activityStarter = function1;
        this.activityFinisher = function12;
        this.userReturnUri = str2 != null ? Uri.parse(str2) : null;
    }

    public final String getCompletionUrlParam() {
        return this.completionUrlParam;
    }

    public final boolean getHasLoadedBlank() {
        return this.hasLoadedBlank;
    }

    public final void setHasLoadedBlank$payments_core_release(boolean z) {
        this.hasLoadedBlank = z;
    }

    @Override
    public void onPageFinished(WebView view, String url) {
        Intrinsics.checkNotNullParameter(view, "view");
        this.logger.debug("PaymentAuthWebViewClient#onPageFinished() - " + url);
        super.onPageFinished(view, url);
        if (!this.hasLoadedBlank) {
            hideProgressBar();
        }
        if (url == null || !INSTANCE.isCompletionUrl$payments_core_release(url)) {
            return;
        }
        this.logger.debug(url + " is a completion URL");
        onAuthCompleted$default(this, null, 1, null);
    }

    private final void hideProgressBar() {
        this.logger.debug("PaymentAuthWebViewClient#hideProgressBar()");
        this.isPageLoaded.setValue(true);
    }

    @Override
    public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
        Intrinsics.checkNotNullParameter(view, "view");
        Intrinsics.checkNotNullParameter(request, "request");
        Uri url = request.getUrl();
        this.logger.debug("PaymentAuthWebViewClient#shouldOverrideUrlLoading(): " + url);
        Intrinsics.checkNotNullExpressionValue(url, "url");
        updateCompletionUrl(url);
        if (isReturnUrl(url)) {
            this.logger.debug("PaymentAuthWebViewClient#shouldOverrideUrlLoading() - handle return URL");
            onAuthCompleted$default(this, null, 1, null);
            return true;
        }
        if (StringsKt.equals("intent", url.getScheme(), true)) {
            openIntentScheme(url);
            return true;
        }
        if (!URLUtil.isNetworkUrl(url.toString())) {
            openIntent(new Intent("android.intent.action.VIEW", url));
            return true;
        }
        return super.shouldOverrideUrlLoading(view, request);
    }

    private final void openIntentScheme(Uri uri) {
        Object m1547constructorimpl;
        this.logger.debug("PaymentAuthWebViewClient#openIntentScheme()");
        try {
            Result.Companion companion = Result.INSTANCE;
            PaymentAuthWebViewClient paymentAuthWebViewClient = this;
            Intent parseUri = Intent.parseUri(uri.toString(), 1);
            Intrinsics.checkNotNullExpressionValue(parseUri, "parseUri(uri.toString(), Intent.URI_INTENT_SCHEME)");
            openIntent(parseUri);
            m1547constructorimpl = Result.m1547constructorimpl(Unit.INSTANCE);
        } catch (Throwable th) {
            Result.Companion companion2 = Result.INSTANCE;
            m1547constructorimpl = Result.m1547constructorimpl(ResultKt.createFailure(th));
        }
        Throwable m1550exceptionOrNullimpl = Result.m1550exceptionOrNullimpl(m1547constructorimpl);
        if (m1550exceptionOrNullimpl != null) {
            this.logger.error("Failed to start Intent.", m1550exceptionOrNullimpl);
            onAuthCompleted(m1550exceptionOrNullimpl);
        }
    }

    private final void openIntent(Intent intent) {
        Object m1547constructorimpl;
        this.logger.debug("PaymentAuthWebViewClient#openIntent()");
        try {
            Result.Companion companion = Result.INSTANCE;
            PaymentAuthWebViewClient paymentAuthWebViewClient = this;
            this.activityStarter.invoke(intent);
            m1547constructorimpl = Result.m1547constructorimpl(Unit.INSTANCE);
        } catch (Throwable th) {
            Result.Companion companion2 = Result.INSTANCE;
            m1547constructorimpl = Result.m1547constructorimpl(ResultKt.createFailure(th));
        }
        Throwable m1550exceptionOrNullimpl = Result.m1550exceptionOrNullimpl(m1547constructorimpl);
        if (m1550exceptionOrNullimpl != null) {
            this.logger.error("Failed to start Intent.", m1550exceptionOrNullimpl);
            if (Intrinsics.areEqual(intent.getScheme(), "alipays")) {
                return;
            }
            onAuthCompleted(m1550exceptionOrNullimpl);
        }
    }

    private final void updateCompletionUrl(Uri uri) {
        this.logger.debug("PaymentAuthWebViewClient#updateCompletionUrl()");
        Companion companion = INSTANCE;
        String uri2 = uri.toString();
        Intrinsics.checkNotNullExpressionValue(uri2, "uri.toString()");
        String queryParameter = companion.isAuthenticateUrl(uri2) ? uri.getQueryParameter("return_url") : null;
        String str = queryParameter;
        if (str == null || StringsKt.isBlank(str)) {
            return;
        }
        this.completionUrlParam = queryParameter;
    }

    private final boolean isReturnUrl(Uri uri) {
        String queryParameter;
        this.logger.debug("PaymentAuthWebViewClient#isReturnUrl()");
        if (isPredefinedReturnUrl(uri)) {
            return true;
        }
        Uri uri2 = this.userReturnUri;
        if (uri2 != null) {
            return uri2.getScheme() != null && Intrinsics.areEqual(this.userReturnUri.getScheme(), uri.getScheme()) && this.userReturnUri.getHost() != null && Intrinsics.areEqual(this.userReturnUri.getHost(), uri.getHost());
        }
        if (uri.isOpaque()) {
            return false;
        }
        Set<String> queryParameterNames = uri.getQueryParameterNames();
        if (queryParameterNames.contains(PARAM_PAYMENT_CLIENT_SECRET)) {
            queryParameter = uri.getQueryParameter(PARAM_PAYMENT_CLIENT_SECRET);
        } else {
            queryParameter = queryParameterNames.contains(PARAM_SETUP_CLIENT_SECRET) ? uri.getQueryParameter(PARAM_SETUP_CLIENT_SECRET) : null;
        }
        return Intrinsics.areEqual(this.clientSecret, queryParameter);
    }

    private final boolean isPredefinedReturnUrl(Uri uri) {
        if (!Intrinsics.areEqual("stripejs://use_stripe_sdk/return_url", uri.toString())) {
            String uri2 = uri.toString();
            Intrinsics.checkNotNullExpressionValue(uri2, "uri.toString()");
            if (!StringsKt.startsWith$default(uri2, DefaultReturnUrl.PREFIX, false, 2, (Object) null)) {
                return false;
            }
        }
        return true;
    }

    static void onAuthCompleted$default(PaymentAuthWebViewClient paymentAuthWebViewClient, Throwable th, int i2, Object obj) {
        if ((i2 & 1) != 0) {
            th = null;
        }
        paymentAuthWebViewClient.onAuthCompleted(th);
    }

    private final void onAuthCompleted(Throwable error) {
        this.logger.debug("PaymentAuthWebViewClient#onAuthCompleted()");
        this.activityFinisher.invoke(error);
    }

    @Metadata(d1 = {"\u0000 \n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0002\b\u0002\n\u0002\u0010\"\n\u0002\u0010\u000e\n\u0002\b\u0006\n\u0002\u0010\u000b\n\u0002\b\u0004\b\u0080\u0003\u0018\u00002\u00020\u0001B\u0007\b\u0002¢\u0006\u0002\u0010\u0002J\u0010\u0010\u000b\u001a\u00020\f2\u0006\u0010\r\u001a\u00020\u0005H\u0002J\u0015\u0010\u000e\u001a\u00020\f2\u0006\u0010\r\u001a\u00020\u0005H\u0001¢\u0006\u0002\b\u000fR\u0014\u0010\u0003\u001a\b\u0012\u0004\u0012\u00020\u00050\u0004X\u0082\u0004¢\u0006\u0002\n\u0000R\u000e\u0010\u0006\u001a\u00020\u0005X\u0080T¢\u0006\u0002\n\u0000R\u0014\u0010\u0007\u001a\b\u0012\u0004\u0012\u00020\u00050\u0004X\u0082\u0004¢\u0006\u0002\n\u0000R\u000e\u0010\b\u001a\u00020\u0005X\u0080T¢\u0006\u0002\n\u0000R\u000e\u0010\t\u001a\u00020\u0005X\u0082T¢\u0006\u0002\n\u0000R\u000e\u0010\n\u001a\u00020\u0005X\u0080T¢\u0006\u0002\n\u0000¨\u0006\u0010"}, d2 = {"Lcom/stripe/android/view/PaymentAuthWebViewClient$Companion;", "", "()V", "AUTHENTICATE_URLS", "", "", "BLANK_PAGE", "COMPLETION_URLS", "PARAM_PAYMENT_CLIENT_SECRET", "PARAM_RETURN_URL", "PARAM_SETUP_CLIENT_SECRET", "isAuthenticateUrl", "", "url", "isCompletionUrl", "isCompletionUrl$payments_core_release", "payments-core_release"}, k = 1, mv = {1, 8, 0}, xi = 48)
    public static final class Companion {
        public Companion(DefaultConstructorMarker defaultConstructorMarker) {
            this();
        }

        private Companion() {
        }

        public final boolean isCompletionUrl$payments_core_release(String url) {
            Intrinsics.checkNotNullParameter(url, "url");
            Set set = PaymentAuthWebViewClient.COMPLETION_URLS;
            if ((set instanceof Collection) && set.isEmpty()) {
                return false;
            }
            Iterator it2 = set.iterator();
            while (it2.hasNext()) {
                if (StringsKt.startsWith$default(url, (String) it2.next(), false, 2, (Object) null)) {
                    return true;
                }
            }
            return false;
        }

        public final boolean isAuthenticateUrl(String url) {
            Set set = PaymentAuthWebViewClient.AUTHENTICATE_URLS;
            if ((set instanceof Collection) && set.isEmpty()) {
                return false;
            }
            Iterator it2 = set.iterator();
            while (it2.hasNext()) {
                if (StringsKt.startsWith$default(url, (String) it2.next(), false, 2, (Object) null)) {
                    return true;
                }
            }
            return false;
        }
    }
}