翰林优商.apk(点击下载) / g.java


package com.mbridge.msdk.click;

import android.content.Context;
import android.graphics.Bitmap;
import android.net.http.SslError;
import android.os.Handler;
import android.os.Looper;
import android.text.TextUtils;
import android.webkit.JsPromptResult;
import android.webkit.JsResult;
import android.webkit.SslErrorHandler;
import android.webkit.URLUtil;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import com.mbridge.msdk.MBridgeConstans;
import com.mbridge.msdk.c.b;
import com.mbridge.msdk.foundation.same.report.d;
import com.mbridge.msdk.foundation.tools.w;
import com.mbridge.msdk.playercommon.exoplayer2.DefaultLoadControl;
import java.util.HashMap;
import java.util.Objects;

/* compiled from: WebViewSpider */
public class g {
    public static long a = 0;
    private static final String d = "g";
    boolean b;
    boolean c;
    private int e = DefaultLoadControl.DEFAULT_MIN_BUFFER_MS;
    private int f = 3000;
    private Handler g = new Handler(Looper.getMainLooper());
    private com.mbridge.msdk.c.a h;
    private a i;
    private String j;
    private String k;
    private WebView l;
    private boolean m;
    private String n;
    private int o;
    private boolean p = false;
    private boolean q;
    private final Runnable r = new Runnable() {
        /* class com.mbridge.msdk.click.g.AnonymousClass4 */

        public final void run() {
            g.this.p = true;
            g.this.o = 1;
            String str = g.d;
            w.d(str, "js超时!超时上限:" + g.this.f + "ms");
            g.n(g.this);
        }
    };
    private final Runnable s = new Runnable() {
        /* class com.mbridge.msdk.click.g.AnonymousClass5 */

        public final void run() {
            g.this.p = true;
            g.this.o = 2;
            String str = g.d;
            w.d(str, "http超时!超时上限:" + g.this.e + "ms");
            g.n(g.this);
        }
    };

    /* access modifiers changed from: package-private */
    /* compiled from: WebViewSpider */
    public interface a {
        void a(int i, String str, String str2, String str3);

        void a(String str, boolean z, String str2);

        boolean a(String str);

        boolean b(String str);

        boolean c(String str);
    }

    public g(boolean z) {
        com.mbridge.msdk.c.a b2 = b.a().b(com.mbridge.msdk.foundation.controller.a.f().k());
        this.h = b2;
        if (b2 == null) {
            this.h = b.a().b();
        }
        this.m = this.h.ad();
        if (z) {
            this.e = (int) this.h.Z();
            this.f = (int) this.h.Z();
            return;
        }
        this.e = (int) this.h.aa();
        this.f = (int) this.h.aa();
    }

    public final void a(String str, String str2, String str3, Context context, String str4, String str5, a aVar) {
        Objects.requireNonNull(aVar, "OverrideUrlLoadingListener can not be null");
        this.k = str5;
        this.j = str4;
        this.i = aVar;
        a(str, str2, str3, context);
    }

    public final void a(String str, String str2, String str3, Context context, String str4, a aVar) {
        Objects.requireNonNull(aVar, "OverrideUrlLoadingListener can not be null");
        this.j = str4;
        this.i = aVar;
        a(str, str2, str3, context);
    }

    private void a(final String str, final String str2, final String str3, final Context context) {
        if (Thread.currentThread() == Looper.getMainLooper().getThread()) {
            a(str, str2, str3, context, this.j);
        } else {
            this.g.post(new Runnable() {
                /* class com.mbridge.msdk.click.g.AnonymousClass1 */

                public final void run() {
                    g gVar = g.this;
                    gVar.a(str, str2, str3, context, gVar.j);
                }
            });
        }
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void a(String str, String str2, String str3, Context context, String str4) {
        try {
            a(context, str, str2, str3);
            if (!TextUtils.isEmpty(this.k)) {
                this.l.getSettings().setDefaultTextEncodingName("utf-8");
                this.f = 2000;
                this.e = 2000;
                w.b(d, this.k);
                this.l.loadDataWithBaseURL(str4, this.k, "*/*", "utf-8", str4);
            } else if (this.m) {
                HashMap hashMap = new HashMap();
                if (this.l.getUrl() != null) {
                    hashMap.put("Referer", this.l.getUrl());
                }
                this.l.loadUrl(str4, hashMap);
            } else {
                this.l.loadUrl(str4);
            }
        } catch (Throwable th) {
            try {
                a aVar = this.i;
                if (aVar != null) {
                    aVar.a(0, this.j, th.getMessage(), this.n);
                }
            } catch (Exception unused) {
            }
        }
    }

    private void a(final Context context, final String str, final String str2, final String str3) {
        WebView webView = new WebView(context);
        this.l = webView;
        webView.getSettings().setJavaScriptEnabled(true);
        this.l.getSettings().setCacheMode(2);
        this.l.getSettings().setLoadsImagesAutomatically(false);
        this.l.setWebViewClient(new WebViewClient() {
            /* class com.mbridge.msdk.click.g.AnonymousClass2 */

            public final void onPageStarted(WebView webView, String str, Bitmap bitmap) {
                try {
                    webView.loadUrl("javascript:window.navigator.vibrate([]);");
                    boolean z = false;
                    if (g.this.q) {
                        g.this.o = 0;
                        g.c(g.this);
                        return;
                    }
                    g.this.c = false;
                    if (webView.getTag() == null) {
                        webView.setTag("has_first_started");
                    } else {
                        g.this.b = true;
                    }
                    synchronized (g.d) {
                        String str2 = "加载页面-开始:";
                        if (g.this.b || g.this.c) {
                            z = true;
                        }
                        if (z) {
                            str2 = "加载页面-开始:(重定向)";
                        }
                        if (URLUtil.isHttpsUrl(str)) {
                            String str3 = g.d;
                            w.d(str3, str2 + str);
                        } else {
                            String str4 = g.d;
                            w.b(str4, str2 + str);
                        }
                        g.this.j = str;
                        if (g.this.i == null || !g.this.i.a(str)) {
                            g.e(g.this);
                        } else {
                            g.this.q = true;
                            g.c(g.this);
                        }
                    }
                } catch (Exception e2) {
                    e2.printStackTrace();
                }
            }

            /* JADX WARNING: Code restructure failed: missing block: B:17:0x006c, code lost:
                if (r3.e.m == false) goto L_0x0098;
             */
            /* JADX WARNING: Code restructure failed: missing block: B:18:0x006e, code lost:
                r4 = new java.util.HashMap();
             */
            /* JADX WARNING: Code restructure failed: missing block: B:19:0x007d, code lost:
                if (r3.e.l.getUrl() == null) goto L_0x008e;
             */
            /* JADX WARNING: Code restructure failed: missing block: B:20:0x007f, code lost:
                r4.put("Referer", r3.e.l.getUrl());
             */
            /* JADX WARNING: Code restructure failed: missing block: B:21:0x008e, code lost:
                r3.e.l.loadUrl(r5, r4);
             */
            /* JADX WARNING: Code restructure failed: missing block: B:22:0x0098, code lost:
                r3.e.l.loadUrl(r5);
             */
            /* JADX WARNING: Code restructure failed: missing block: B:23:0x00a1, code lost:
                return true;
             */
            @Override // android.webkit.WebViewClient
            public final boolean shouldOverrideUrlLoading(WebView webView, String str) {
                synchronized (g.d) {
                    String str2 = g.d;
                    w.a(str2, "override js跳转:" + str);
                    g.this.c = true;
                    g.this.d();
                    if (g.this.q) {
                        g.this.c();
                        g.c(g.this);
                        return true;
                    }
                    g.this.j = str;
                    if (g.this.i != null && g.this.i.b(str)) {
                        g.this.q = true;
                        g.this.c();
                        g.c(g.this);
                        return true;
                    }
                }
            }

            public final void onReceivedError(WebView webView, int i, String str, String str2) {
                String str3 = g.d;
                w.b(str3, "onReceivedError: errno = " + i + ", url: " + webView.getUrl() + ",\n onReceivedError:, description: " + str + ", failingUrl: " + str2);
                synchronized (g.d) {
                    g.this.q = true;
                    g.this.b();
                    g.c(g.this);
                }
                if (g.this.i != null) {
                    g.this.i.a(i, webView.getUrl(), str, g.this.n);
                }
            }

            public final void onReceivedSslError(WebView webView, SslErrorHandler sslErrorHandler, SslError sslError) {
                try {
                    String str = g.d;
                    w.a(str, "onReceivedSslError IS_SP_CBT_CF:" + MBridgeConstans.IS_SP_CBT_CF);
                    if (MBridgeConstans.IS_SP_CBT_CF && sslErrorHandler != null) {
                        sslErrorHandler.cancel();
                    }
                    if (!TextUtils.isEmpty(str3) && !TextUtils.isEmpty(str2)) {
                        new d(context).a(str, str2, str3, webView.getUrl());
                    }
                } catch (Exception e2) {
                    e2.printStackTrace();
                }
            }

            public final void onPageFinished(WebView webView, String str) {
                super.onPageFinished(webView, str);
                try {
                    webView.loadUrl("javascript:window.navigator.vibrate([]);");
                } catch (Exception e2) {
                    e2.printStackTrace();
                }
            }
        });
        this.l.setWebChromeClient(new WebChromeClient() {
            /* class com.mbridge.msdk.click.g.AnonymousClass3 */

            public final boolean onJsAlert(WebView webView, String str, String str2, JsResult jsResult) {
                return true;
            }

            public final boolean onJsConfirm(WebView webView, String str, String str2, JsResult jsResult) {
                return true;
            }

            public final boolean onJsPrompt(WebView webView, String str, String str2, String str3, JsPromptResult jsPromptResult) {
                return true;
            }

            public final void onProgressChanged(WebView webView, int i) {
                if (i == 100) {
                    try {
                        String str = g.d;
                        w.b(str, "加载页面-进度完成:" + webView.getUrl());
                        webView.loadUrl("javascript:window.navigator.vibrate([]);");
                        if (!g.this.q && !g.this.c) {
                            g.l(g.this);
                        }
                        if (g.this.i != null) {
                            g.this.i.c(webView.getUrl());
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }
        });
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void b() {
        d();
        c();
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void c() {
        this.g.removeCallbacks(this.s);
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void d() {
        this.g.removeCallbacks(this.r);
    }

    /* JADX WARNING: Missing exception handler attribute for start block: B:6:0x0014 */
    static /* synthetic */ void c(g gVar) {
        synchronized (d) {
            try {
                gVar.b();
                a aVar = gVar.i;
                if (aVar != null) {
                    aVar.a(gVar.j, gVar.p, gVar.n);
                }
            } catch (Exception unused) {
                w.d(d, "webview colse to failed");
            } catch (Throwable unknown) {
                w.d(d, "webview colse to failed");
            }
        }
    }

    static /* synthetic */ void e(g gVar) {
        gVar.c();
        boolean z = gVar.b;
        gVar.g.postDelayed(gVar.s, (long) gVar.e);
    }

    static /* synthetic */ void l(g gVar) {
        gVar.d();
        boolean z = gVar.b;
        gVar.g.postDelayed(gVar.r, (long) gVar.f);
    }

    /* JADX WARNING: Missing exception handler attribute for start block: B:6:0x0019 */
    static /* synthetic */ void n(g gVar) {
        synchronized (d) {
            try {
                gVar.b();
                gVar.l.destroy();
                a aVar = gVar.i;
                if (aVar != null) {
                    aVar.a(gVar.j, gVar.p, gVar.n);
                }
            } catch (Exception unused) {
                w.d(d, "webview colse to failed");
            } catch (Throwable unknown) {
                w.d(d, "webview colse to failed");
            }
        }
    }
}