TikTok.apk(点击下载) / JC9.java


package X;

import android.text.TextUtils;
import android.util.Base64;
import android.webkit.JavascriptInterface;
import android.webkit.ValueCallback;
import com.bytedance.covode.number.Covode;
import java.nio.charset.Charset;
import java.util.Arrays;
import kotlin.g.b.m;
import org.json.JSONObject;

public final class JC9 extends JCB {
    public final C48716JAz LIZ;
    public final String LJ = "JSB3BridgeImpl";

    static {
        Covode.recordClassIndex(32168);
    }

    /* JADX INFO: super call moved to the top of the method (can break code semantics) */
    public JC9(C48716JAz jAz) {
        super(jAz);
        C21090sc.LIZ(jAz);
        this.LIZ = jAz;
    }

    @Override // X.JCB
    public final String LIZ(JC3 jc3, C48704JAn jAn) {
        C21090sc.LIZ(jc3, jAn);
        JSONObject jSONObject = new JSONObject();
        jSONObject.put("__callback_id", jc3.LIZ);
        jSONObject.put("__params", jAn.LIZ());
        jSONObject.put("__msg_type", "callback");
        if (TextUtils.isEmpty(jc3.LJII)) {
            return "javascript:ToutiaoJSBridge._handleMessageFromToutiao(" + jSONObject + ')';
        }
        String str = jc3.LJII;
        Charset charset = C23650wk.LIZ;
        if (str != null) {
            byte[] bytes = str.getBytes(charset);
            m.LIZ((Object) bytes, "");
            String encodeToString = Base64.encodeToString(bytes, 2);
            m.LIZ((Object) encodeToString, "");
            String LIZ2 = AnonymousClass0EJ.LIZ("iframe[src=\"%s\"", Arrays.copyOf(new Object[]{str}, 1));
            m.LIZ((Object) LIZ2, "");
            Charset charset2 = C23650wk.LIZ;
            if (LIZ2 != null) {
                byte[] bytes2 = LIZ2.getBytes(charset2);
                m.LIZ((Object) bytes2, "");
                String encodeToString2 = Base64.encodeToString(bytes2, 2);
                m.LIZ((Object) encodeToString2, "");
                String LIZ3 = AnonymousClass0EJ.LIZ("javascript:(function(){   const iframe = document.querySelector(atob('%s'));   if (iframe && iframe.contentWindow) {        iframe.contentWindow.postMessage(%s, atob('%s'));   }})()", Arrays.copyOf(new Object[]{encodeToString2, jSONObject, encodeToString}, 3));
                m.LIZ((Object) LIZ3, "");
                return LIZ3;
            }
            throw new C23830x2("null cannot be cast to non-null type java.lang.String");
        }
        throw new C23830x2("null cannot be cast to non-null type java.lang.String");
    }

    @Override // X.JCB
    public final void LIZ(String str, JSONObject jSONObject) {
        C21090sc.LIZ(str);
        JSONObject jSONObject2 = new JSONObject();
        try {
            jSONObject2.put("__msg_type", C59681Nby.LJIIIIZZ);
            jSONObject2.put("__event_id", str);
            jSONObject2.put("__params", jSONObject);
            LIZ("javascript:window.ToutiaoJSBridge && ToutiaoJSBridge._handleMessageFromToutiao && ToutiaoJSBridge._handleMessageFromToutiao(" + jSONObject2 + ')', (ValueCallback<String>) null);
        } catch (Throwable th) {
            Throwable r3 = C23790wy.m6exceptionOrNullimpl(C23790wy.m3constructorimpl(C23800wz.LIZ(th)));
            if (r3 != null) {
                C21090sc.LIZ(this.LJ, "parse event failed,reason=" + r3.getMessage());
            }
        }
    }

    @Override // X.JCB
    public final String LIZIZ() {
        return "ToutiaoJSBridge";
    }

    @Override // X.JCB
    public final JC3 LIZLLL(String str) {
        String str2;
        C21090sc.LIZ(str);
        JC3 jc3 = new JC3(this.LIZ);
        try {
            JSONObject jSONObject = new JSONObject(str);
            String optString = jSONObject.optString("__callback_id");
            m.LIZ((Object) optString, "");
            jc3.LIZ(optString);
            String optString2 = jSONObject.optString("func");
            m.LIZ((Object) optString2, "");
            jc3.LIZIZ(optString2);
            JCK jck = this.LIZIZ;
            if (jck == null || (str2 = jck.LIZ()) == null) {
                str2 = "";
            }
            jc3.LIZJ(str2);
            String optString3 = jSONObject.optString("__msg_type");
            m.LIZ((Object) optString3, "");
            jc3.LIZLLL(optString3);
            jc3.LJ = jSONObject.opt("params");
            String optString4 = jSONObject.optString("JSSDK");
            m.LIZ((Object) optString4, "");
            jc3.LJ(optString4);
            String optString5 = jSONObject.optString("namespace", "DEFAULT");
            m.LIZ((Object) optString5, "");
            jc3.LJFF(optString5);
            String optString6 = jSONObject.optString("__iframe_url");
            m.LIZ((Object) optString6, "");
            jc3.LJI(optString6);
            jc3.LJIIIIZZ = jSONObject.optLong("__timestamp", System.currentTimeMillis());
            jc3.LIZ(JCM.Web);
            jc3.LJII(str);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return jc3;
    }

    @JavascriptInterface
    public final void invokeMethod(String str) {
        LIZ(str, (JCH) null);
    }
}