package com.bytedance.sdk.openadsdk.core.widget.fm;

import android.content.MutableContextWrapper;
import android.net.Uri;
import android.os.MessageQueue;
import android.text.TextUtils;
import android.webkit.RenderProcessGoneDetail;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import com.bytedance.sdk.component.ef.wsy;
import com.bytedance.sdk.openadsdk.BuildConfig;
import com.bytedance.sdk.openadsdk.core.gof;
import com.bytedance.sdk.openadsdk.core.hxv;
import com.bytedance.sdk.openadsdk.utils.wey;
import java.util.Objects;
import java.util.concurrent.atomic.AtomicInteger;

/* JADX INFO: loaded from: classes2.dex */
public class lb implements ro {
    hxv fm;
    private final boolean jnr;

    /* JADX INFO: renamed from: lb, reason: collision with root package name */
    private final AtomicInteger f7338lb;
    private com.bytedance.sdk.component.ef.wsy ro;
    private final MessageQueue yz;

    public lb(int i10, boolean z10, MessageQueue messageQueue) {
        this.f7338lb = new AtomicInteger(i10);
        this.jnr = z10;
        this.yz = messageQueue;
    }

    private void fm(com.bytedance.sdk.component.ef.wsy wsyVar) {
        if (wsyVar == null || wsyVar.getWebView() == null) {
            return;
        }
        try {
            yz.fm(gof.fm()).fm(false).fm(wsyVar.getWebView());
            wsyVar.setVerticalScrollBarEnabled(false);
            wsyVar.setHorizontalScrollBarEnabled(false);
            yz.fm(wsyVar);
            wsyVar.dsz();
            wsyVar.setUserAgentString(wey.fm(wsyVar.getWebView(), BuildConfig.VERSION_CODE));
            wsyVar.setMixedContentMode(0);
            wsyVar.setJavaScriptEnabled(true);
            wsyVar.setJavaScriptCanOpenWindowsAutomatically(true);
            wsyVar.setDomStorageEnabled(true);
            wsyVar.setDatabaseEnabled(true);
            wsyVar.setCacheMode(-1);
            wsyVar.setAllowFileAccess(false);
            wsyVar.setSupportZoom(true);
            wsyVar.setBuiltInZoomControls(true);
            wsyVar.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS);
            wsyVar.setUseWideViewPort(true);
        } catch (Throwable th) {
            com.bytedance.sdk.component.utils.wey.lb("WebViewPool", th.toString());
        }
    }

    public void ro() {
        if (this.f7338lb.get() <= 0) {
            return;
        }
        Objects.toString(this.f7338lb);
        String strYz = com.bytedance.sdk.component.adexpress.fm.ro.ro.yz(null);
        if (this.jnr) {
            String strYz2 = com.bytedance.sdk.component.adexpress.fm.ro.ro.yz("v3");
            if (strYz != null && strYz.equals(strYz2)) {
                return;
            } else {
                strYz = strYz2;
            }
        }
        if (TextUtils.isEmpty(strYz)) {
            return;
        }
        try {
            com.bytedance.sdk.component.ef.wsy wsyVar = new com.bytedance.sdk.component.ef.wsy(new MutableContextWrapper(gof.fm()), this.jnr ? wsy.lb.ADS_V3 : wsy.lb.ADS);
            this.ro = wsyVar;
            if (wsyVar.getWebView() == null) {
                return;
            }
            this.ro.setWebViewClient(new WebViewClient() { // from class: com.bytedance.sdk.openadsdk.core.widget.fm.lb.1
                @Override // android.webkit.WebViewClient
                public boolean onRenderProcessGone(WebView webView, RenderProcessGoneDetail renderProcessGoneDetail) {
                    return true;
                }
            });
            fm(this.ro);
            Uri uriBuild = Uri.parse(strYz).buildUpon().appendQueryParameter("isPreLoad", "1").build();
            hxv hxvVar = new hxv(this.ro.getContext());
            this.fm = hxvVar;
            hxvVar.ro(this.ro).fm(this).fm(this.ro);
            com.bytedance.sdk.component.adexpress.jnr.jnr.fm().fm(this.ro, this.fm);
            this.ro.a_(uriBuild.toString());
        } catch (Exception unused) {
        }
    }

    @Override // com.bytedance.sdk.openadsdk.core.widget.fm.ro
    public void fm() {
        MessageQueue messageQueue;
        if (this.jnr) {
            com.bytedance.sdk.component.adexpress.jnr.jnr.fm().yz(this.ro);
        } else {
            com.bytedance.sdk.component.adexpress.jnr.jnr.fm().jnr(this.ro);
        }
        try {
            this.f7338lb.get();
            this.f7338lb.decrementAndGet();
            if (this.f7338lb.get() <= 0 || (messageQueue = this.yz) == null) {
                return;
            }
            messageQueue.addIdleHandler(new MessageQueue.IdleHandler() { // from class: com.bytedance.sdk.openadsdk.core.widget.fm.lb.2
                @Override // android.os.MessageQueue.IdleHandler
                public boolean queueIdle() {
                    new lb(lb.this.f7338lb.get(), lb.this.jnr, lb.this.yz).ro();
                    return false;
                }
            });
        } catch (Exception e10) {
            e10.getMessage();
        }
    }
}
