package m7;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.RemoteException;
import android.text.TextUtils;
import android.webkit.WebResourceError;
import android.webkit.WebResourceRequest;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import com.google.android.gms.internal.ads.sb1;
import java.util.Objects;
import n7.x;

/* JADX INFO: loaded from: classes2.dex */
public final class j extends WebViewClient {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final /* synthetic */ m f30454a;

    public j(m mVar) {
        Objects.requireNonNull(mVar);
        this.f30454a = mVar;
    }

    @Override // android.webkit.WebViewClient
    public final void onReceivedError(WebView webView, WebResourceRequest webResourceRequest, WebResourceError webResourceError) {
        m mVar = this.f30454a;
        if (mVar.U2() != null) {
            try {
                mVar.U2().y(sb1.zzd(1, null, null));
            } catch (RemoteException e10) {
                q7.j.zzl("#007 Could not call remote method.", e10);
            }
        }
        if (mVar.U2() != null) {
            try {
                mVar.U2().C(0);
            } catch (RemoteException e11) {
                q7.j.zzl("#007 Could not call remote method.", e11);
            }
        }
    }

    @Override // android.webkit.WebViewClient
    public final boolean shouldOverrideUrlLoading(WebView webView, String str) {
        m mVar = this.f30454a;
        int iG = 0;
        if (str.startsWith(mVar.S2())) {
            return false;
        }
        if (str.startsWith("gmsg://noAdLoaded")) {
            if (mVar.U2() != null) {
                try {
                    mVar.U2().y(sb1.zzd(3, null, null));
                } catch (RemoteException e10) {
                    q7.j.zzl("#007 Could not call remote method.", e10);
                }
            }
            if (mVar.U2() != null) {
                try {
                    mVar.U2().C(3);
                } catch (RemoteException e11) {
                    q7.j.zzl("#007 Could not call remote method.", e11);
                }
            }
            mVar.R2(0);
            return true;
        }
        if (str.startsWith("gmsg://scriptLoadFailed")) {
            if (mVar.U2() != null) {
                try {
                    mVar.U2().y(sb1.zzd(1, null, null));
                } catch (RemoteException e12) {
                    q7.j.zzl("#007 Could not call remote method.", e12);
                }
            }
            if (mVar.U2() != null) {
                try {
                    mVar.U2().C(0);
                } catch (RemoteException e13) {
                    q7.j.zzl("#007 Could not call remote method.", e13);
                }
            }
            mVar.R2(0);
            return true;
        }
        boolean zStartsWith = str.startsWith("gmsg://adResized");
        Context context = mVar.f30459c;
        if (zStartsWith) {
            if (mVar.U2() != null) {
                try {
                    mVar.U2().zzf();
                } catch (RemoteException e14) {
                    q7.j.zzl("#007 Could not call remote method.", e14);
                }
            }
            String queryParameter = Uri.parse(str).getQueryParameter("height");
            if (!TextUtils.isEmpty(queryParameter)) {
                try {
                    q7.e eVar = x.f31085g.f31086a;
                    iG = q7.e.g(context.getResources().getDisplayMetrics(), Integer.parseInt(queryParameter));
                } catch (NumberFormatException unused) {
                }
            }
            mVar.R2(iG);
            return true;
        }
        if (str.startsWith("gmsg://")) {
            return true;
        }
        if (mVar.U2() != null) {
            try {
                mVar.U2().zzh();
                mVar.U2().zze();
            } catch (RemoteException e15) {
                q7.j.zzl("#007 Could not call remote method.", e15);
            }
        }
        Intent intent = new Intent("android.intent.action.VIEW");
        intent.setData(Uri.parse(str));
        context.startActivity(intent);
        return true;
    }
}
