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 JC8 extends JCB { public final C48716JAz LIZ; public final String LJ = "JSB4BridgeImpl"; static { Covode.recordClassIndex(32170); } /* JADX INFO: super call moved to the top of the method (can break code semantics) */ public JC8(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("__msg_type", "callback"); jSONObject.put("__callback_id", jc3.LIZ); jSONObject.put("__params", jAn.LIZ()); jSONObject.put("__timestamp", System.currentTimeMillis()); jSONObject.put("__sdk_version", "4.0"); if (TextUtils.isEmpty(jc3.LJII)) { return "javascript:BDXBridge._handleMessageFromApp(" + 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) { Object obj; JSONObject jSONObject2; C21090sc.LIZ(str); JSONObject jSONObject3 = new JSONObject(); if (jSONObject != null) { try { jSONObject2 = new JSONObject(jSONObject.toString()); if (!jSONObject2.has("code")) { jSONObject2.put("code", 1); } } catch (Throwable th) { obj = C23790wy.m3constructorimpl(C23800wz.LIZ(th)); } } else { jSONObject2 = new JSONObject().put("code", 1); } jSONObject3.put("__msg_type", C59681Nby.LJIIIIZZ); jSONObject3.put("__event_id", str); jSONObject3.put("__params", jSONObject2); jSONObject3.put("__timestamp", System.currentTimeMillis()); jSONObject3.put("__sdk_version", "4.0"); LIZ("javascript:window.BDXBridge && BDXBridge._handleMessageFromApp && BDXBridge._handleMessageFromApp(" + jSONObject3 + ')', (ValueCallback<String>) null); obj = C23790wy.m3constructorimpl(C23860x5.LIZ); Throwable r3 = C23790wy.m6exceptionOrNullimpl(obj); if (r3 != null) { C21090sc.LIZ(this.LJ, "parse event failed,reason=" + r3.getMessage()); } } @Override // X.JCB public final String LIZIZ() { return "BDXBridge"; } @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("func"); m.LIZ((Object) optString, ""); jc3.LIZIZ(optString); jc3.LJ = jSONObject.opt("params"); String optString2 = jSONObject.optString("JSSDK"); m.LIZ((Object) optString2, ""); jc3.LJ(optString2); jc3.LJIIIIZZ = jSONObject.optLong("__timestamp", System.currentTimeMillis()); String optString3 = jSONObject.optString("__msg_type"); m.LIZ((Object) optString3, ""); jc3.LIZLLL(optString3); String optString4 = jSONObject.optString("__iframe_url"); m.LIZ((Object) optString4, ""); jc3.LJI(optString4); String optString5 = jSONObject.optString("__callback_id"); m.LIZ((Object) optString5, ""); jc3.LIZ(optString5); JCK jck = this.LIZIZ; if (jck == null || (str2 = jck.LIZ()) == null) { str2 = ""; } jc3.LIZJ(str2); String optString6 = jSONObject.optString("namespace", "DEFAULT"); m.LIZ((Object) optString6, ""); jc3.LJFF(optString6); jc3.LJII(str); jc3.LIZ(JCM.Web); } catch (Exception e) { e.printStackTrace(); } return jc3; } @JavascriptInterface public final void _invokeMethod(String str) { LIZ(str, new JCH()); } }