package com.iBookStar.views; import android.content.Context; import android.graphics.Bitmap; import android.os.Build; import android.util.AttributeSet; import android.util.Log; import com.iBookStar.utils.s; import com.iBookStar.views.CommonWebView; import com.tencent.smtt.export.external.extension.interfaces.IX5WebViewExtension; import com.tencent.smtt.export.external.interfaces.SslError; import com.tencent.smtt.export.external.interfaces.SslErrorHandler; import com.tencent.smtt.sdk.CookieManager; import com.tencent.smtt.sdk.CookieSyncManager; import com.tencent.smtt.sdk.DownloadListener; import com.tencent.smtt.sdk.QbSdk; import com.tencent.smtt.sdk.WebBackForwardList; import com.tencent.smtt.sdk.WebChromeClient; import com.tencent.smtt.sdk.WebHistoryItem; import com.tencent.smtt.sdk.WebSettings; import com.tencent.smtt.sdk.WebStorage; import com.tencent.smtt.sdk.WebView; import com.tencent.smtt.sdk.WebViewClient; import java.util.Map; public class X5WebView extends WebView implements DownloadListener { private CommonWebView.f2 b; private CommonWebView.d2 c; private CommonWebView d; private boolean e = true; private float f = 1.0f; private boolean g = false; /* access modifiers changed from: package-private */ public class a extends WebViewClient { final /* synthetic */ CommonWebView a; a(CommonWebView commonWebView) { this.a = commonWebView; } @Override // com.tencent.smtt.sdk.WebViewClient public void onPageFinished(WebView webView, String str) { if (X5WebView.this.b != null) { X5WebView.this.b.a(this.a, str); } super.onPageFinished(webView, str); } @Override // com.tencent.smtt.sdk.WebViewClient public void onPageStarted(WebView webView, String str, Bitmap bitmap) { if (X5WebView.this.b != null) { X5WebView.this.b.a(this.a, str, bitmap); } super.onPageStarted(webView, str, bitmap); } @Override // com.tencent.smtt.sdk.WebViewClient public void onReceivedSslError(WebView webView, SslErrorHandler sslErrorHandler, SslError sslError) { sslErrorHandler.proceed(); } @Override // com.tencent.smtt.sdk.WebViewClient public void onScaleChanged(WebView webView, float f, float f2) { X5WebView.this.f = f2; } @Override // com.tencent.smtt.sdk.WebViewClient public boolean shouldOverrideUrlLoading(WebView webView, String str) { if (X5WebView.this.b == null || !X5WebView.this.b.b(this.a, str)) { return super.shouldOverrideUrlLoading(webView, str); } return true; } } /* access modifiers changed from: package-private */ public class b extends WebChromeClient { final /* synthetic */ CommonWebView a; b(CommonWebView commonWebView) { this.a = commonWebView; } @Override // com.tencent.smtt.sdk.WebChromeClient public void onProgressChanged(WebView webView, int i) { if (X5WebView.this.c != null) { X5WebView.this.c.a(this.a, i); } } @Override // com.tencent.smtt.sdk.WebChromeClient public void onReceivedTitle(WebView webView, String str) { if (X5WebView.this.c != null) { X5WebView.this.c.a(this.a, str); } } } /* access modifiers changed from: package-private */ public class c extends WebViewClient { final /* synthetic */ X5WebView a; c(X5WebView x5WebView) { this.a = x5WebView; } @Override // com.tencent.smtt.sdk.WebViewClient public void onPageFinished(WebView webView, String str) { super.onPageFinished(webView, str); try { String cookie = CookieManager.getInstance().getCookie("http://boardy.huanqiu.com"); CookieManager.getInstance().removeAllCookie(); CookieManager.getInstance().removeSessionCookie(); if (s.c(cookie)) { for (String str2 : cookie.split(";")) { String trim = str2.trim(); String[] split = trim.split("="); if (split.length > 1) { String trim2 = split[0].trim(); if (!trim2.startsWith("smuc")) { if (!trim2.startsWith("smub")) { CookieManager.getInstance().setCookie("http://boardy.huanqiu.com", trim); } } this.a.loadUrl("javascript:localStorage.removeItem('" + trim2 + "')"); } } } } catch (Exception e) { e.printStackTrace(); } X5WebView.this.reload(); } @Override // com.tencent.smtt.sdk.WebViewClient public boolean shouldOverrideUrlLoading(WebView webView, String str) { webView.loadUrl(str); return true; } } /* access modifiers changed from: package-private */ public class d extends WebViewClient { final /* synthetic */ X5WebView a; final /* synthetic */ String b; d(X5WebView x5WebView, String str) { this.a = x5WebView; this.b = str; } @Override // com.tencent.smtt.sdk.WebViewClient public void onPageFinished(WebView webView, String str) { super.onPageFinished(webView, str); try { CookieSyncManager.createInstance(com.iBookStar.b.a.k()); CookieManager instance = CookieManager.getInstance(); if (Build.VERSION.SDK_INT >= 21) { instance.removeAllCookie(); instance.removeSessionCookie(); instance.flush(); } else { instance.removeAllCookie(); instance.removeSessionCookie(); CookieSyncManager.getInstance().sync(); } this.a.loadUrl("javascript:localStorage.clear()"); X5WebView x5WebView = X5WebView.this; x5WebView.loadUrl("javascript:" + this.b + "()"); } catch (Exception e) { e.printStackTrace(); } } @Override // com.tencent.smtt.sdk.WebViewClient public boolean shouldOverrideUrlLoading(WebView webView, String str) { webView.loadUrl(str); return true; } } public static class e implements CommonWebView.c2 { private WebBackForwardList a; public e(WebBackForwardList webBackForwardList) { this.a = webBackForwardList; } @Override // com.iBookStar.views.CommonWebView.c2 public int a() { WebBackForwardList webBackForwardList = this.a; if (webBackForwardList != null) { return webBackForwardList.getCurrentIndex(); } return 0; } @Override // com.iBookStar.views.CommonWebView.c2 public CommonWebView.e2 a(int i) { WebBackForwardList webBackForwardList = this.a; if (webBackForwardList == null || i < 0 || i >= webBackForwardList.getSize()) { return null; } return new f(this.a.getItemAtIndex(i)); } } public static class f implements CommonWebView.e2 { private WebHistoryItem a; public f(WebHistoryItem webHistoryItem) { this.a = webHistoryItem; } @Override // com.iBookStar.views.CommonWebView.e2 public String a() { WebHistoryItem webHistoryItem = this.a; if (webHistoryItem != null) { return webHistoryItem.getOriginalUrl(); } return null; } @Override // com.iBookStar.views.CommonWebView.e2 public String b() { WebHistoryItem webHistoryItem = this.a; if (webHistoryItem != null) { return webHistoryItem.getUrl(); } return null; } } public X5WebView(Context context) { super(context); } public X5WebView(Context context, AttributeSet attributeSet) { super(context, attributeSet); } public X5WebView(Context context, AttributeSet attributeSet, int i) { super(context, attributeSet, i); } public X5WebView(Context context, AttributeSet attributeSet, int i, Map<String, Object> map, boolean z) { super(context, attributeSet, i, map, z); } public X5WebView(Context context, AttributeSet attributeSet, int i, boolean z) { super(context, attributeSet, i, z); } public X5WebView(Context context, boolean z) { super(context, z); } /* access modifiers changed from: protected */ public void a(CommonWebView commonWebView) { IX5WebViewExtension x5WebViewExtension = getX5WebViewExtension(); if (x5WebViewExtension != null) { this.g = true; try { if (s.a(com.iBookStar.b.a.s)) { com.iBookStar.b.a.s = String.valueOf(QbSdk.getTbsSdkVersion()); } if (s.a(com.iBookStar.b.a.t)) { com.iBookStar.b.a.t = String.valueOf(QbSdk.getTbsVersion(com.iBookStar.b.a.k())); } } catch (Throwable unused) { } Log.i("TBS_LOG_TAG", String.format("x5 core loaded, tv=%s, tsv=%s", com.iBookStar.b.a.t, com.iBookStar.b.a.s)); } this.d = commonWebView; getSettings().setJavaScriptEnabled(true); getSettings().setJavaScriptCanOpenWindowsAutomatically(true); getSettings().setLoadsImagesAutomatically(true); getSettings().setAllowFileAccess(true); addJavascriptInterface(commonWebView, "Client"); CookieManager.getInstance().setAcceptCookie(true); if (Build.VERSION.SDK_INT >= 21) { getSettings().setMixedContentMode(0); CookieManager.getInstance().setAcceptThirdPartyCookies(this, true); } getSettings().setUseWideViewPort(true); getSettings().setLoadWithOverviewMode(true); getSettings().setSaveFormData(true); getSettings().setSavePassword(true); getSettings().setDefaultZoom(WebSettings.ZoomDensity.MEDIUM); getSettings().setSupportZoom(true); getSettings().setTextZoom(100); getSettings().setBuiltInZoomControls(true); if (Build.VERSION.SDK_INT >= 11) { getSettings().setDisplayZoomControls(false); } if (Build.VERSION.SDK_INT > 8) { getSettings().setPluginState(WebSettings.PluginState.ON_DEMAND); } getSettings().setAppCacheEnabled(true); getSettings().setDatabaseEnabled(true); getSettings().setDomStorageEnabled(true); setLongClickable(true); if (x5WebViewExtension != null) { x5WebViewExtension.setVerticalScrollBarEnabled(false); x5WebViewExtension.setHorizontalScrollBarEnabled(false); } else { getView().setVerticalScrollBarEnabled(false); getView().setHorizontalScrollBarEnabled(false); } setWebViewClient(new a(commonWebView)); setWebChromeClient(new b(commonWebView)); setDownloadListener(this); this.f = super.getScale(); } /* access modifiers changed from: protected */ public void a(String str) { if (com.iBookStar.c.c.k()) { try { CookieSyncManager.createInstance(com.iBookStar.b.a.k()); CookieManager instance = CookieManager.getInstance(); if (Build.VERSION.SDK_INT >= 21) { instance.removeAllCookie(); instance.removeSessionCookie(); instance.flush(); } else { instance.removeAllCookie(); instance.removeSessionCookie(); CookieSyncManager.getInstance().sync(); } WebStorage.getInstance().deleteAllData(); loadUrl("javascript:" + str + "()"); } catch (Exception e2) { e2.printStackTrace(); } } else { X5WebView x5WebView = new X5WebView(getContext()); x5WebView.a(this.d); x5WebView.setDownloadEnable(false); x5WebView.setWebViewClient(new d(x5WebView, str)); x5WebView.loadUrl("http://boardy.huanqiu.com"); } } /* access modifiers changed from: protected */ public void g() { try { X5WebView x5WebView = new X5WebView(getContext()); x5WebView.a(this.d); x5WebView.setDownloadEnable(false); x5WebView.setWebViewClient(new c(x5WebView)); x5WebView.loadUrl("http://boardy.huanqiu.com"); } catch (Exception e2) { e2.printStackTrace(); } } @Override // com.tencent.smtt.sdk.WebView public float getScale() { return this.f; } public String getUA() { return getSettings().getUserAgentString(); } /* access modifiers changed from: protected */ public boolean h() { try { String cookie = CookieManager.getInstance().getCookie("http://boardy.huanqiu.com"); if (s.c(cookie)) { for (String str : cookie.split(";")) { if (str.contains("smub")) { return false; } } } } catch (Exception e2) { e2.printStackTrace(); } return true; } public boolean isX5CoreLoaded() { return this.g; } @Override // com.tencent.smtt.sdk.DownloadListener public void onDownloadStart(String str, String str2, String str3, String str4, long j) { if (this.e) { this.d.onDownloadStart(str, str2, str3, str4, j); } } public void setCacheMode(int i) { getSettings().setCacheMode(i); } public void setCommonWebChromeClient(CommonWebView.d2 d2Var) { this.c = d2Var; } public void setCommonWebViewClient(CommonWebView.f2 f2Var) { this.b = f2Var; } public void setDownloadEnable(boolean z) { this.e = z; } public void setJavaScriptEnabled(boolean z) { getSettings().setJavaScriptEnabled(z); } public void setMediaPlaybackRequiresUserGesture(boolean z) { if (Build.VERSION.SDK_INT >= 17) { getSettings().setMediaPlaybackRequiresUserGesture(z); } } public CommonWebView.c2 x5copyBackForwardList() { return new e(super.copyBackForwardList()); } }