package com.ss.android.ugc.aweme.compliance.business.webview;

import X.2sG;
import X.AnonymousClass9W0;
import X.AnonymousClass9W2;
import X.AnonymousClass9W5;
import X.AnonymousClass9WS;
import X.C25348eL;
import X.M12;
import android.webkit.JavascriptInterface;
import android.webkit.WebView;
import com.bytedance.covode.number.Covode;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
import kotlin.h.b.n;
import org.json.JSONObject;

public final class TTHYBRIDXHR {
    public static final Map<Integer, String> LIZJ = new LinkedHashMap();
    public static final AnonymousClass9W0 LIZLLL = new AnonymousClass9W0((byte) 0);
    public boolean LIZ;
    public final WebView LIZIZ;

    static {
        Covode.recordClassIndex(61199);
    }

    public TTHYBRIDXHR(WebView webView) {
        M12.LIZ(webView);
        this.LIZIZ = webView;
    }

    @JavascriptInterface
    public final String postMessage(String str) {
        M12.LIZ(str);
        if (!this.LIZ) {
            return "disabled";
        }
        2sG r11 = new 2sG();
        r11.element = "";
        try {
            JSONObject jSONObject = new JSONObject(str);
            String optString = jSONObject.optString("method");
            String optString2 = jSONObject.optString("id");
            2sG r7 = new 2sG();
            r7.element = jSONObject.optString("url");
            String optString3 = jSONObject.optString("data");
            JSONObject optJSONObject = jSONObject.optJSONObject("headers");
            if (optJSONObject == null) {
                optJSONObject = new JSONObject();
            }
            String str2 = (String) r7.element;
            n.LIZIZ(str2, "");
            r11.element = str2;
            LinkedHashMap linkedHashMap = new LinkedHashMap();
            Iterator<String> keys = optJSONObject.keys();
            n.LIZIZ(keys, "");
            while (keys.hasNext()) {
                String next = keys.next();
                n.LIZIZ(next, "");
                String optString4 = optJSONObject.optString(next);
                n.LIZIZ(optString4, "");
                linkedHashMap.put(next, optString4);
            }
            C25348eL.LIZ().execute(new AnonymousClass9W5(linkedHashMap, this, optJSONObject, r7, optString, optString3, optString2, r11));
            return "success";
        } catch (Exception e) {
            this.LIZIZ.post(new AnonymousClass9W2(this, r11, e));
            StringBuilder sb = new StringBuilder();
            Iterator LIZ2 = AnonymousClass9WS.LIZ(e.getStackTrace());
            while (LIZ2.hasNext()) {
                sb.append(((StackTraceElement) LIZ2.next()).toString() + "\n");
            }
            String sb2 = sb.toString();
            n.LIZIZ(sb2, "");
            return sb2;
        }
    }
}
