package mj2; import android.content.Context; import android.net.Uri; import android.os.Bundle; import com.google.android.gms.common.GoogleApiAvailabilityLight; import com.google.android.gms.common.internal.ServiceSpecificExtraArgs; import com.google.gson.reflect.TypeToken; import com.tencent.cos.xml.common.COSRequestHeaderKey; import com.tencent.matrix.iocanary.config.SharePluginInfo; import com.uber.autodispose.a0; import com.uber.autodispose.y; import com.xingin.webviewresourcecache.provider.LoadService; import iv2.d; import ja.b1; import java.io.InputStream; import java.lang.reflect.Type; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.TimeUnit; import java.util.regex.Pattern; import jv2.v0; import kotlin.Lazy; import kotlin.LazyKt__LazyJVMKt; import kotlin.Metadata; import kotlin.Unit; import kotlin.collections.CollectionsKt__CollectionsKt; import kotlin.collections.MapsKt__MapsKt; import kotlin.jvm.functions.Function0; import kotlin.jvm.functions.Function1; import kotlin.jvm.internal.DefaultConstructorMarker; import kotlin.jvm.internal.Intrinsics; import kotlin.jvm.internal.Lambda; import kotlin.jvm.internal.Reflection; import kotlin.text.StringsKt__StringsJVMKt; import okhttp3.HttpUrl; import okhttp3.ResponseBody; import retrofit2.r; import sv2.n; import w13.sb; import z60.h; @Metadata(bv = {}, d1 = {"\u0000d\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\u0002\n\u0002\b\u0002\n\u0002\u0010\u000e\n\u0000\n\u0002\u0010\u000b\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0010\t\n\u0002\b\u0005\n\u0002\u0010\b\n\u0002\b\u000e\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010%\n\u0000\n\u0002\u0010$\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0006\u0018\u00002\u00020\u0001:\u00014B\t\b\u0002¢\u0006\u0004\b2\u00103J\u0016\u0010\u0007\u001a\u00020\u00062\u0006\u0010\u0003\u001a\u00020\u00022\u0006\u0010\u0005\u001a\u00020\u0004J\u000e\u0010\b\u001a\u00020\u00062\u0006\u0010\u0003\u001a\u00020\u0002J\u000e\u0010\f\u001a\u00020\u000b2\u0006\u0010\n\u001a\u00020\tJ\u000e\u0010\r\u001a\u00020\u00062\u0006\u0010\n\u001a\u00020\tJ\u0010\u0010\u000f\u001a\u0004\u0018\u00010\u000e2\u0006\u0010\n\u001a\u00020\tJ\u000e\u0010\u0010\u001a\u00020\u00062\u0006\u0010\n\u001a\u00020\tJ\u0016\u0010\u0013\u001a\u00020\u00062\u0006\u0010\n\u001a\u00020\t2\u0006\u0010\u0012\u001a\u00020\u0011JL\u0010\u001c\u001a\u00020\u00062\u0006\u0010\u0014\u001a\u00020\u00112\u0006\u0010\u0015\u001a\u00020\u00112\u0006\u0010\u0016\u001a\u00020\u00112\b\u0010\n\u001a\u0004\u0018\u00010\t2\u0006\u0010\u0018\u001a\u00020\u00172\u0006\u0010\u0019\u001a\u00020\u00172\b\u0010\u001a\u001a\u0004\u0018\u00010\t2\b\u0010\u001b\u001a\u0004\u0018\u00010\tJ\u0011\u0010\u001d\u001a\u0004\u0018\u00010\u0017H\u0002¢\u0006\u0004\b\u001d\u0010\u001eJ\u0010\u0010 \u001a\u00020\u000b2\u0006\u0010\u001f\u001a\u00020\tH\u0002J\u0010\u0010!\u001a\u00020\u000b2\u0006\u0010\u001f\u001a\u00020\tH\u0002J\u0010\u0010\"\u001a\u00020\u000b2\u0006\u0010\n\u001a\u00020\tH\u0002J\u0012\u0010#\u001a\u0004\u0018\u00010\u000e2\u0006\u0010\n\u001a\u00020\tH\u0002J*\u0010(\u001a\u00020\u000e2\u0006\u0010$\u001a\u00020\t2\u0006\u0010%\u001a\u00020\t2\u0006\u0010\u0019\u001a\u00020\u00172\b\u0010'\u001a\u0004\u0018\u00010&H\u0002J\u0010\u0010*\u001a\u00020)2\u0006\u0010\n\u001a\u00020\tH\u0002J0\u0010.\u001a\u000e\u0012\u0004\u0012\u00020\t\u0012\u0004\u0012\u00020\t0-2\u0006\u0010\n\u001a\u00020\t2\u0012\u0010,\u001a\u000e\u0012\u0004\u0012\u00020\t\u0012\u0004\u0012\u00020\t0+H\u0002J\u0018\u00101\u001a\u00020\u00062\u0006\u00100\u001a\u00020/2\u0006\u0010\n\u001a\u00020\tH\u0002¨\u00065"}, d2 = {"Lmj2/g;", "", "Landroid/content/Context;", "context", "Lmj2/a;", ServiceSpecificExtraArgs.CastExtraArgs.LISTENER, "", "r", "x", "", "url", "", h.f160753a, "o", "Ljv2/v0;", "k", "s", "", "currentTimeMillis", "w", "startTime", "endTime", "loadTime", "", "status", "code", "errorType", "errorMsg", "u", "e", "()Ljava/lang/Integer;", SharePluginInfo.ISSUE_FILE_PATH, "i", y7.f.f156778k, "g", "j", "mimeType", "encoding", "Ljava/io/InputStream;", "data", GoogleApiAvailabilityLight.TRACKING_SOURCE_NOTIFICATION, "Lokhttp3/HttpUrl;", "l", "", "requestHeaders", "", "m", "Lmj2/h;", "cache", "t", "<init>", "()V", "b", "hybrid_webview_library_release"}, k = 1, mv = {1, 6, 0}) /* compiled from: XhsSsrHtmlPreloadCacheProvider.kt */ public final class g { /* renamed from: d reason: collision with root package name */ public static final b f106661d = new b(null); /* renamed from: e reason: collision with root package name */ public static final Lazy<g> f106662e = LazyKt__LazyJVMKt.lazy(a.f106666a); /* renamed from: a reason: collision with root package name */ public final ConcurrentHashMap<String, h> f106663a; /* renamed from: b reason: collision with root package name */ public final LoadService f106664b; /* renamed from: c reason: collision with root package name */ public ConcurrentHashMap<Context, a> f106665c; @Metadata(bv = {}, d1 = {"\u0000\b\n\u0002\u0018\u0002\n\u0002\b\u0002\u0010\u0001\u001a\u00020\u0000H\n¢\u0006\u0004\b\u0001\u0010\u0002"}, d2 = {"Lmj2/g;", "a", "()Lmj2/g;"}, k = 3, mv = {1, 6, 0}) /* compiled from: XhsSsrHtmlPreloadCacheProvider.kt */ public static final class a extends Lambda implements Function0<g> { /* renamed from: a reason: collision with root package name */ public static final a f106666a = new a(); public a() { super(0); } /* renamed from: a */ public final g invoke() { return new g(null); } } @Metadata(bv = {}, d1 = {"\u0000 \n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0002\u0018\u0002\n\u0002\b\u0005\n\u0002\u0010\u000e\n\u0002\b\u0002\n\u0002\u0010\b\n\u0002\b\n\b\u0003\u0018\u00002\u00020\u0001B\t\b\u0002¢\u0006\u0004\b\u0013\u0010\u0014R\u001b\u0010\u0007\u001a\u00020\u00028FX\u0002¢\u0006\f\n\u0004\b\u0003\u0010\u0004\u001a\u0004\b\u0005\u0010\u0006R\u0014\u0010\t\u001a\u00020\b8\u0006XT¢\u0006\u0006\n\u0004\b\t\u0010\nR\u0014\u0010\f\u001a\u00020\u000b8\u0006XT¢\u0006\u0006\n\u0004\b\f\u0010\rR\u0014\u0010\u000e\u001a\u00020\u000b8\u0006XT¢\u0006\u0006\n\u0004\b\u000e\u0010\rR\u0014\u0010\u000f\u001a\u00020\u000b8\u0006XT¢\u0006\u0006\n\u0004\b\u000f\u0010\rR\u0014\u0010\u0010\u001a\u00020\b8\u0006XT¢\u0006\u0006\n\u0004\b\u0010\u0010\nR\u0014\u0010\u0011\u001a\u00020\b8\u0006XT¢\u0006\u0006\n\u0004\b\u0011\u0010\nR\u0014\u0010\u0012\u001a\u00020\b8\u0006XT¢\u0006\u0006\n\u0004\b\u0012\u0010\n¨\u0006\u0015"}, d2 = {"Lmj2/g$b;", "", "Lmj2/g;", "instance$delegate", "Lkotlin/Lazy;", "a", "()Lmj2/g;", "instance", "", "KEY_USE_NATIVE_CHANNEL", "Ljava/lang/String;", "", "STATUS_ALL", "I", "STATUS_CLOSE", "STATUS_GRAY", "TAG", "WHITE_HOST", "WILDCARD", "<init>", "()V", "hybrid_webview_library_release"}, k = 1, mv = {1, 6, 0}) /* compiled from: XhsSsrHtmlPreloadCacheProvider.kt */ public static final class b { public b() { } public /* synthetic */ b(DefaultConstructorMarker defaultConstructorMarker) { this(); } public final g a() { return (g) g.f106662e.getValue(); } } @Metadata(bv = {}, d1 = {"\u0000\u000b\n\u0000\n\u0002\u0018\u0002\n\u0000*\u0001\u0000\b\n\u0018\u00002\b\u0012\u0004\u0012\u00028\u00000\u0001¨\u0006\u0002"}, d2 = {"mj2/g$c", "Lcom/google/gson/reflect/TypeToken;", "xy_configcenter_library_release"}, k = 1, mv = {1, 6, 0}) /* compiled from: Config.kt */ public static final class c extends TypeToken<Integer> { } @Metadata(bv = {}, d1 = {"\u0000\u000b\n\u0000\n\u0002\u0018\u0002\n\u0000*\u0001\u0000\b\n\u0018\u00002\b\u0012\u0004\u0012\u00028\u00000\u0001¨\u0006\u0002"}, d2 = {"mj2/g$d", "Lcom/google/gson/reflect/TypeToken;", "xy_configcenter_library_release"}, k = 1, mv = {1, 6, 0}) /* compiled from: Config.kt */ public static final class d extends TypeToken<List<? extends String>> { } @Metadata(bv = {}, d1 = {"\u0000\u000b\n\u0000\n\u0002\u0018\u0002\n\u0000*\u0001\u0000\b\n\u0018\u00002\b\u0012\u0004\u0012\u00028\u00000\u0001¨\u0006\u0002"}, d2 = {"mj2/g$e", "Lcom/google/gson/reflect/TypeToken;", "xy_configcenter_library_release"}, k = 1, mv = {1, 6, 0}) /* compiled from: Config.kt */ public static final class e extends TypeToken<List<? extends String>> { } @Metadata(bv = {}, d1 = {"\u0000\f\n\u0002\u0018\u0002\n\u0002\u0010\u0002\n\u0002\b\u0002\u0010\u0002\u001a\u00020\u0001*\u00020\u0000H\n¢\u0006\u0004\b\u0002\u0010\u0003"}, d2 = {"Lw13/sb$a;", "", "a", "(Lw13/sb$a;)V"}, k = 3, mv = {1, 6, 0}) /* compiled from: XhsSsrHtmlPreloadCacheProvider.kt */ public static final class f extends Lambda implements Function1<sb.a, Unit> { /* renamed from: a reason: collision with root package name */ public final /* synthetic */ long f106667a; /* renamed from: b reason: collision with root package name */ public final /* synthetic */ long f106668b; /* renamed from: c reason: collision with root package name */ public final /* synthetic */ long f106669c; /* renamed from: d reason: collision with root package name */ public final /* synthetic */ String f106670d; /* renamed from: e reason: collision with root package name */ public final /* synthetic */ int f106671e; /* renamed from: f reason: collision with root package name */ public final /* synthetic */ int f106672f; /* renamed from: g reason: collision with root package name */ public final /* synthetic */ String f106673g; /* JADX INFO: super call moved to the top of the method (can break code semantics) */ public f(long j14, long j15, long j16, String str, int i10, int i14, String str2) { super(1); this.f106667a = j14; this.f106668b = j15; this.f106669c = j16; this.f106670d = str; this.f106671e = i10; this.f106672f = i14; this.f106673g = str2; } public final void a(sb.a aVar) { Intrinsics.checkNotNullParameter(aVar, "$this$withHybridH5WebviewSsrTime"); aVar.x(410); aVar.y(1.0f); aVar.z(this.f106667a); aVar.t(this.f106668b); aVar.w(this.f106669c); aVar.B(this.f106670d); aVar.A(this.f106671e); aVar.s(this.f106672f); aVar.u(aVar.r()); aVar.v(this.f106673g); } /* Return type fixed from 'java.lang.Object' to match base method */ /* JADX DEBUG: Method arguments types fixed to match base method, original types: [java.lang.Object] */ @Override // kotlin.jvm.functions.Function1 public /* bridge */ /* synthetic */ Unit invoke(sb.a aVar) { a(aVar); return Unit.INSTANCE; } } public g() { this.f106663a = new ConcurrentHashMap<>(); this.f106664b = (LoadService) fz1.b.f80449a.a(LoadService.class); this.f106665c = new ConcurrentHashMap<>(); } public /* synthetic */ g(DefaultConstructorMarker defaultConstructorMarker) { this(); } public static final void p(g gVar, String str, r rVar) { Intrinsics.checkNotNullParameter(gVar, "this$0"); Intrinsics.checkNotNullParameter(str, "$url"); h hVar = gVar.f106663a.get(str); if (hVar != null) { n.b("PagePreload", "获取到html资源,写入缓存"); synchronized (hVar.h()) { hVar.o(System.currentTimeMillis()); hVar.u(rVar.f() ? 1 : 0); hVar.l(rVar.b()); String g10 = rVar.g(); Intrinsics.checkNotNullExpressionValue(g10, "it.message()"); hVar.p(g10); if (rVar.f()) { int b14 = rVar.b(); ResponseBody responseBody = (ResponseBody) rVar.a(); hVar.m(new i("text/html", "UTF8", b14, responseBody != null ? responseBody.byteStream() : null)); } hVar.n(true); hVar.h().notifyAll(); Unit unit = Unit.INSTANCE; } } } public static final void q(g gVar, String str, Throwable th3) { Intrinsics.checkNotNullParameter(gVar, "this$0"); Intrinsics.checkNotNullParameter(str, "$url"); h hVar = gVar.f106663a.get(str); if (hVar != null) { synchronized (hVar.h()) { hVar.o(System.currentTimeMillis()); hVar.u(0); hVar.l(-1); hVar.q(th3.getClass().getSimpleName()); String message = th3.getMessage(); if (message == null) { message = ""; } hVar.p(message); hVar.n(true); hVar.h().notifyAll(); Unit unit = Unit.INSTANCE; } n.b("PagePreload", "提前加载失败:" + th3.getClass().getSimpleName() + ':' + th3.getMessage()); } } public static final void v(long j14, long j15, long j16, String str, int i10, int i14, String str2) { qe2.a.a().p4("hybrid_h5_webview_ssr_time").x3(new f(j14, j15, j16, str, i10, i14, str2)).b(); } public final Integer e() { ds0.f a14 = ds0.b.a(); Type type = new c().getType(); Intrinsics.checkExpressionValueIsNotNull(type, "object : TypeToken<T>() {}.type"); return (Integer) a14.m("all_ssr_state", type, 0); } /* JADX WARNING: Removed duplicated region for block: B:5:0x002b */ public final boolean f(String str) { ds0.f a14 = ds0.b.a(); List list = CollectionsKt__CollectionsKt.emptyList(); Type type = new d().getType(); Intrinsics.checkExpressionValueIsNotNull(type, "object : TypeToken<T>() {}.type"); List<String> list2 = (List) a14.m("all_ssr_black_list", type, list); if (list2 != null) { for (String str2 : list2) { if (Intrinsics.areEqual(str2, "*") || (StringsKt__StringsJVMKt.startsWith$default(str, str2, false, 2, null))) { return true; } while (r0.hasNext()) { } } } return false; } public final boolean g(String str) { Iterator<T> it3 = m.f106699e.a().iterator(); while (it3.hasNext()) { String matchRule = it3.next().getMatchRule(); if (matchRule == null) { matchRule = ""; } if (Pattern.compile(matchRule).matcher(str).lookingAt()) { return true; } } return false; } /* JADX WARNING: Removed duplicated region for block: B:37:0x0093 */ public final boolean h(String str) { boolean z14; Intrinsics.checkNotNullParameter(str, "url"); if (g(str)) { return false; } Integer e14 = e(); if ((e14 != null && e14.intValue() == 0) || !((Boolean) da.c.c().i("Android_webview_ssr_v2_monitor", Reflection.getOrCreateKotlinClass(Boolean.class))).booleanValue()) { return false; } Uri parse = Uri.parse(str); String host = parse.getHost(); String str2 = ""; if (host == null) { host = str2; } String queryParameter = parse.getQueryParameter("useNativeChannel"); if (!(StringsKt__StringsJVMKt.endsWith$default(host, "xiaohongshu.com", false, 2, null)) || (StringsKt__StringsJVMKt.equals(queryParameter, "no", true))) { return false; } String path = parse.getPath(); if (path != null) { str2 = path; } if (e14 != null && e14.intValue() == 1) { if (!f(str2)) { z14 = i(str2); if (!z14 || (StringsKt__StringsJVMKt.startsWith$default(str, "http://feanubis.int.sit.xiaohongshu.com/xhsbridge/schemalist", false, 2, null))) { return true; } return false; } } else if (e14 != null && e14.intValue() == 2 && (i(str2) || !f(str2))) { z14 = true; if (!z14) { } return true; } z14 = false; if (!z14) { } return true; } /* JADX WARNING: Removed duplicated region for block: B:5:0x002b */ public final boolean i(String str) { ds0.f a14 = ds0.b.a(); List list = CollectionsKt__CollectionsKt.emptyList(); Type type = new e().getType(); Intrinsics.checkExpressionValueIsNotNull(type, "object : TypeToken<T>() {}.type"); List<String> list2 = (List) a14.m("all_ssr_white_list", type, list); if (list2 != null) { for (String str2 : list2) { if (Intrinsics.areEqual(str2, "*") || (StringsKt__StringsJVMKt.startsWith$default(str, str2, false, 2, null))) { return true; } while (r0.hasNext()) { } } } return false; } public final v0 j(String str) { h hVar; if (!h(str) || (hVar = this.f106663a.get(str)) == null) { return null; } n.b("PagePreload", "webview触发请求"); if (!hVar.k()) { synchronized (hVar.h()) { while (!hVar.k()) { n.b("PagePreload", "获取资源,阻塞"); hVar.h().wait(); n.b("PagePreload", "获取资源,唤醒"); } Unit unit = Unit.INSTANCE; } } i b14 = hVar.b(); hVar.s(System.currentTimeMillis()); if (!hVar.k() || b14 == null) { t(hVar, str); s(str); return null; } for (Map.Entry<Context, a> entry : this.f106665c.entrySet()) { entry.getValue().a(entry.getKey(), hVar); } s(str); t(hVar, str); n.b("PagePreload", "锁释放,缓存中获取到资源,丢给webview"); return n(b14.d(), b14.c(), b14.a(), b14.b()); } public final v0 k(String str) { Intrinsics.checkNotNullParameter(str, "url"); v0 j14 = j(str); if (j14 != null) { return j14; } return null; } public final HttpUrl l(String str) { HttpUrl parse = HttpUrl.parse(str); if (parse != null) { return parse; } HttpUrl build = new HttpUrl.Builder().build(); Intrinsics.checkNotNullExpressionValue(build, "Builder().build()"); return build; } public final Map<String, String> m(String str, Map<String, String> map) { LinkedHashMap linkedHashMap = new LinkedHashMap(); linkedHashMap.putAll(map); String e14 = pj2.f.f118491a.e(str); linkedHashMap.remove("User-Agent"); linkedHashMap.put(COSRequestHeaderKey.ORIGIN, e14); linkedHashMap.put("Authorization", b1.f94179a.S0().getSessionId()); linkedHashMap.put("access-control-allow-origin", "*"); linkedHashMap.put(com.alipay.sdk.packet.e.f18213d, "text/html"); return linkedHashMap; } public final v0 n(String str, String str2, int i10, InputStream inputStream) { v0 v0Var = new v0(str, str2, inputStream); v0Var.setStatusCode(i10); v0Var.setReasonPhrase("intercept"); v0Var.setResponseHeaders(MapsKt__MapsKt.emptyMap()); return v0Var; } public final void o(String str) { Intrinsics.checkNotNullParameter(str, "url"); if (h(str)) { n.b("PagePreload", "命中url,准备preload html"); ConcurrentHashMap<String, h> concurrentHashMap = this.f106663a; h hVar = new h(str, null, false); hVar.t(System.currentTimeMillis()); concurrentHashMap.put(str, hVar); dw2.r<r<ResponseBody>> J1 = this.f106664b.getStreamCall(l(str), m(str, new LinkedHashMap())).W0(mi2.a.P()).J1(com.igexin.push.config.c.f25230t, TimeUnit.MILLISECONDS); Intrinsics.checkNotNullExpressionValue(J1, "api.getStreamCall(makeHt…0, TimeUnit.MILLISECONDS)"); a0 a0Var = a0.D; Intrinsics.checkNotNullExpressionValue(a0Var, "UNBOUND"); Object n14 = J1.n(com.uber.autodispose.d.b(a0Var)); Intrinsics.checkExpressionValueIsNotNull(n14, "this.`as`(AutoDispose.autoDisposable(provider))"); ((y) n14).a(new e(this, str), new d(this, str)); } } public final void r(Context context, a aVar) { Intrinsics.checkNotNullParameter(context, "context"); Intrinsics.checkNotNullParameter(aVar, ServiceSpecificExtraArgs.CastExtraArgs.LISTENER); this.f106665c.put(context, aVar); } public final void s(String str) { Intrinsics.checkNotNullParameter(str, "url"); if (this.f106663a.containsKey(str)) { this.f106663a.remove(str); n.b("PagePreload", "缓存释放:" + str); } } public final void t(h hVar, String str) { if (!(StringsKt__StringsJVMKt.startsWith$default(str, "http://feanubis.int.sit.xiaohongshu.com/xhsbridge/schemalist", false, 2, null))) { long f14 = hVar.f() - hVar.i(); long c14 = hVar.c() - hVar.i(); long g10 = hVar.g() - hVar.c(); if (ki2.d.f98474d.a().e()) { u(f14, c14, g10, str, hVar.j(), hVar.a(), hVar.e(), hVar.d()); return; } d.a aVar = iv2.d.f92449e; Bundle bundle = new Bundle(); bundle.putLong("start", f14); bundle.putLong("end", c14); bundle.putLong("load", g10); bundle.putString("url", str); bundle.putInt("status", hVar.j()); bundle.putInt("code", hVar.a()); bundle.putString("errorType", hVar.e()); bundle.putString("errormsg", hVar.d()); Unit unit = Unit.INSTANCE; d.a.b(aVar, "trackSsrTime", bundle, null, 4, null); } } public final void u(long j14, long j15, long j16, String str, int i10, int i14, String str2, String str3) { we2.d.c(new f(j14, j15, j16, str, i10, i14, str3)); n.b("PagePreload", "\nstarTime:" + j14 + "\nendTime:" + j15 + "\nloadTime:" + j16 + "\nstatus:" + i10 + "\ncode:" + i14 + "\nerrorType:" + str2 + "\nerrorMsg:" + str3 + "\nurl:" + str); } public final void w(String str, long j14) { h hVar; Intrinsics.checkNotNullParameter(str, "url"); if (h(str) && (hVar = this.f106663a.get(str)) != null) { hVar.r(j14); } } public final void x(Context context) { Intrinsics.checkNotNullParameter(context, "context"); this.f106665c.remove(context); } }