京东到家.apk(点击下载) / d.java


package com.jingdong.manto.jsengine;

import android.content.Context;
import android.net.http.SslError;
import android.os.Build;
import android.os.Handler;
import android.os.Looper;
import android.util.Pair;
import android.webkit.SslErrorHandler;
import android.webkit.ValueCallback;
import android.webkit.WebResourceRequest;
import android.webkit.WebResourceResponse;
import android.webkit.WebSettings;
import android.webkit.WebView;
import androidx.core.app.NotificationCompat;
import com.igexin.push.f.p;
import com.jd.sentry.performance.network.instrumentation.webview.ShooterWebViewClient;
import com.jd.sentry.performance.network.instrumentation.webview.ShooterWebviewInstrumentation;
import com.jingdong.manto.pkg.a.e;
import com.jingdong.manto.utils.MantoStringUtils;
import com.jingdong.manto.utils.aa;
import com.jingdong.manto.utils.y;
import com.jingdong.sdk.jweb.sys.Wrapper;
import java.io.ByteArrayInputStream;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;

public class d extends WebView implements IMantoWebViewJS, b {
    boolean a = false;
    private Context b;

    /* renamed from: c  reason: collision with root package name */
    private Handler f1409c;
    private final LinkedList<Pair<String, ValueCallback<String>>> d = new LinkedList<>();
    private boolean e = false;
    private volatile boolean f = false;

    public d(Context context) {
        super(context);
        this.b = context;
        this.f1409c = new Handler(Looper.getMainLooper());
        WebSettings settings = getSettings();
        settings.setJavaScriptEnabled(true);
        settings.setAllowFileAccess(false);
        settings.setSavePassword(false);
        settings.setUserAgentString(aa.a(context, settings.getUserAgentString()));
        ShooterWebviewInstrumentation.setWebViewClient(this, new ShooterWebViewClient() {
            /* class com.jingdong.manto.jsengine.d.AnonymousClass1 */

            private WebResourceResponse a(String str) {
                if (!str.equals(d.this.getEngineUrl())) {
                    return null;
                }
                WebResourceResponse convert = Wrapper.convert(e.a("NAPageFrame.html"));
                return convert == null ? Build.VERSION.SDK_INT >= 21 ? new WebResourceResponse("image/*", p.b, 404, "Not Found", new HashMap(), new ByteArrayInputStream(new byte[0])) : new WebResourceResponse("image/*", p.b, new ByteArrayInputStream(new byte[0])) : convert;
            }

            @Override // com.jd.sentry.performance.network.instrumentation.webview.ShooterWebViewClient
            public void onPageFinished(WebView webView, String str) {
                synchronized (d.this.d) {
                    d.this.e = true;
                    Iterator it = d.this.d.iterator();
                    while (it.hasNext()) {
                        Pair pair = (Pair) it.next();
                        d.this.a((d) ((String) pair.first), (String) ((ValueCallback) pair.second));
                    }
                    d.this.d.clear();
                }
            }

            @Override // com.jd.sentry.performance.network.instrumentation.webview.ShooterWebViewClient
            public void onReceivedSslError(WebView webView, SslErrorHandler sslErrorHandler, SslError sslError) {
                sslErrorHandler.cancel();
            }

            @Override // android.webkit.WebViewClient
            public WebResourceResponse shouldInterceptRequest(WebView webView, String str) {
                if (MantoStringUtils.isEmpty(str)) {
                    return null;
                }
                return a(str);
            }

            @Override // android.webkit.WebViewClient
            public boolean shouldOverrideUrlLoading(WebView webView, WebResourceRequest webResourceRequest) {
                return true;
            }
        });
        setWillNotDraw(true);
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void a(final String str, final ValueCallback<String> valueCallback) {
        if (!this.f) {
            AnonymousClass3 r0 = new Runnable() {
                /* class com.jingdong.manto.jsengine.d.AnonymousClass3 */

                public void run() {
                    String str;
                    if (Build.VERSION.SDK_INT >= 19) {
                        d.super.evaluateJavascript(str, valueCallback);
                        return;
                    }
                    if (str.startsWith("javascript:")) {
                        str = str;
                    } else {
                        str = "javascript:" + str;
                    }
                    d.super.loadUrl(str);
                }
            };
            if (y.a()) {
                r0.run();
            } else {
                this.f1409c.post(r0);
            }
        }
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private String getEngineUrl() {
        return "https://service.vapp.jd.com/js-engine";
    }

    @Override // com.jingdong.manto.jsengine.IMantoWebViewJS
    public final void addJavascriptInterface(Object obj, String str) {
        if (obj != null && !MantoStringUtils.isEmpty(str)) {
            super.addJavascriptInterface(obj, str);
        }
    }

    @Override // com.jingdong.manto.jsengine.IMantoWebViewJS
    public void destroy() {
        this.f = true;
        super.destroy();
    }

    @Override // com.jingdong.manto.jsengine.IMantoWebViewJS, android.webkit.WebView
    public final void evaluateJavascript(String str, ValueCallback<String> valueCallback) {
        if (!this.a) {
            this.a = true;
            this.f1409c.post(new Runnable() {
                /* class com.jingdong.manto.jsengine.d.AnonymousClass2 */

                public void run() {
                    d dVar = d.this;
                    dVar.loadUrl(dVar.getEngineUrl());
                }
            });
        }
        synchronized (this.d) {
            if (this.e) {
                a(str, valueCallback);
            } else {
                this.d.add(new Pair<>(str, valueCallback));
            }
        }
    }

    @Override // com.jingdong.manto.jsengine.IMantoWebViewJS
    public IMantoBaseInterface getInterface(Class cls) {
        if (cls.isInstance(this)) {
            return this;
        }
        return null;
    }

    @Override // com.jingdong.manto.jsengine.IMantoWebViewJS
    public String getName() {
        return NotificationCompat.CATEGORY_SYSTEM;
    }

    @Override // com.jingdong.manto.jsengine.b
    public void setTitle(String str) {
        evaluateJavascript("document.title=\"" + str + "\"", null);
    }
}