正在查看: Kaspi.kz v5.85.1 应用的 ACWebViewClient.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
正在查看: Kaspi.kz v5.85.1 应用的 ACWebViewClient.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
package com.iap.android.mppclient.container.presenter;
import android.content.Intent;
import android.graphics.Bitmap;
import android.net.Uri;
import android.net.http.SslError;
import android.os.Handler;
import android.os.Looper;
import android.text.TextUtils;
import android.util.Log;
import android.webkit.SslErrorHandler;
import android.webkit.WebResourceRequest;
import android.webkit.WebResourceResponse;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import com.iap.android.mppclient.R;
import com.iap.android.mppclient.container.ACContainer;
import com.iap.android.mppclient.container.ACContainerManager;
import com.iap.android.mppclient.container.activity.ACContainerActivity;
import com.iap.android.mppclient.container.cache.ResourceCacheManager;
import com.iap.android.mppclient.container.event.ContainerEvent;
import com.iap.android.mppclient.container.event.ContainerPerformanceListener;
import com.iap.android.mppclient.container.js.ACJSBridge;
import com.iap.android.mppclient.container.model.CacheRecord;
import com.iap.android.mppclient.container.provider.ReceivedSslErrorHandler;
import com.iap.android.mppclient.container.utils.IOUtils;
import java.io.IOException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.concurrent.CopyOnWriteArrayList;
import org.json.JSONException;
import org.json.JSONObject;
public class ACWebViewClient extends WebViewClient {
private static final String TAG = "ACWebViewClient";
private String bizCode;
private ACContainerPresenter containerPresenter;
private ACContainerActivity mContext;
private WebView mWebView;
private String originalUrl;
Map<String, Long> pageStartTime = new HashMap();
private HttpRequestRecord httpRequestRecord = new HttpRequestRecord();
public ACWebViewClient(ACContainerActivity aCContainerActivity, WebView webView, ACContainerPresenter aCContainerPresenter, String str, String str2) {
this.mContext = aCContainerActivity;
this.mWebView = webView;
this.containerPresenter = aCContainerPresenter;
this.bizCode = str;
this.originalUrl = str2;
}
private boolean isPreInjectJSBridge() {
ACContainerActivity aCContainerActivity = this.mContext;
if (aCContainerActivity == null || aCContainerActivity.getIntent() == null) {
return false;
}
return this.mContext.getIntent().getExtras().getBoolean("preInjectJSBridge", false);
}
private boolean isLocalCacheEnable() {
ACContainerActivity aCContainerActivity = this.mContext;
if (aCContainerActivity == null || aCContainerActivity.getIntent() == null) {
return false;
}
boolean z = this.mContext.getIntent().getExtras().getBoolean("enableLocalCache", false);
HttpRequestRecord httpRequestRecord = this.httpRequestRecord;
if (httpRequestRecord != null) {
httpRequestRecord.enabled = z;
}
return z;
}
private String getErrorPageUrl() {
ACContainerActivity aCContainerActivity = this.mContext;
if (aCContainerActivity == null || aCContainerActivity.getIntent() == null) {
return null;
}
return this.mContext.getIntent().getExtras().getString("h5ErrorPageURL");
}
@Override
public void onPageStarted(WebView webView, String str, Bitmap bitmap) {
if (webView == null) {
return;
}
Log.i("onPageStarted", "" + isPreInjectJSBridge());
if (isPreInjectJSBridge()) {
try {
ACJSBridge.getInstance(this.bizCode).loadJavascript(R.raw.h5_bridge, this.mContext, this.mWebView);
} catch (Exception unused) {
}
}
String url = webView.getUrl();
ACContainerPresenter aCContainerPresenter = this.containerPresenter;
if (aCContainerPresenter != null) {
aCContainerPresenter.onPageStarted(url);
}
this.pageStartTime.put(url, Long.valueOf(System.currentTimeMillis()));
if (!onPageEvent(url, "h5PageStarted")) {
super.onPageStarted(webView, url, bitmap);
}
HttpRequestRecord httpRequestRecord = this.httpRequestRecord;
if (httpRequestRecord != null) {
httpRequestRecord.startRecord(url);
}
}
@Override
public void onPageFinished(WebView webView, String str) {
if (webView == null) {
return;
}
String url = webView.getUrl();
ACContainerPresenter aCContainerPresenter = this.containerPresenter;
if (aCContainerPresenter != null) {
aCContainerPresenter.onPageFinished(url);
}
if (!isPreInjectJSBridge()) {
try {
ACJSBridge.getInstance(this.bizCode).loadJavascript(R.raw.h5_bridge, this.mContext, this.mWebView);
} catch (Exception unused) {
}
}
if (!onPageEvent(url, "h5PageFinished")) {
super.onPageFinished(webView, url);
}
HttpRequestRecord httpRequestRecord = this.httpRequestRecord;
if (httpRequestRecord != null) {
httpRequestRecord.finishRecord(url);
}
}
@Override
public boolean shouldOverrideUrlLoading(WebView webView, WebResourceRequest webResourceRequest) {
if (webResourceRequest != null && webResourceRequest.getUrl() != null) {
return shouldOverrideUrlLoading(webView, webResourceRequest.getUrl().toString());
}
return super.shouldOverrideUrlLoading(webView, webResourceRequest);
}
@Override
public boolean shouldOverrideUrlLoading(WebView webView, String str) {
if (webView == null || TextUtils.isEmpty(str)) {
return false;
}
if (onPageEvent(str, "h5PageShouldLoadUrl")) {
return true;
}
try {
if (!str.startsWith("http://") && !str.startsWith("https://") && !str.startsWith("file:///android_asset/")) {
Intent intent = new Intent("android.intent.action.VIEW", Uri.parse(str));
ACContainerActivity aCContainerActivity = this.mContext;
if (aCContainerActivity != null) {
aCContainerActivity.startActivity(intent);
}
return true;
}
} catch (Exception unused) {
}
return false;
}
@Override
public void onReceivedSslError(WebView webView, SslErrorHandler sslErrorHandler, SslError sslError) {
if (handleSslError(webView, sslErrorHandler, sslError)) {
return;
}
super.onReceivedSslError(webView, sslErrorHandler, sslError);
}
@Override
public void onReceivedError(WebView webView, int i, String str, String str2) {
loadErrorPage(str2, i);
}
@Override
public void onReceivedHttpError(WebView webView, WebResourceRequest webResourceRequest, WebResourceResponse webResourceResponse) {
String uri = (webResourceRequest == null || webResourceRequest.getUrl() == null) ? null : webResourceRequest.getUrl().toString();
if (!TextUtils.equals(uri, this.originalUrl)) {
Log.d(TAG, "onReceivedHttpError:" + uri);
return;
}
loadErrorPage(uri, webResourceResponse != null ? webResourceResponse.getStatusCode() : 0);
}
@Override
public WebResourceResponse shouldInterceptRequest(WebView webView, WebResourceRequest webResourceRequest) {
HttpRequestRecord httpRequestRecord = this.httpRequestRecord;
if (httpRequestRecord != null) {
httpRequestRecord.addRequestNumber(webResourceRequest.getUrl().toString());
}
WebResourceResponse webResourceResponse = getWebResourceResponse((webResourceRequest == null || webResourceRequest.getUrl() == null) ? "" : webResourceRequest.getUrl().toString());
return webResourceResponse != null ? webResourceResponse : super.shouldInterceptRequest(webView, webResourceRequest);
}
@Override
public WebResourceResponse shouldInterceptRequest(WebView webView, String str) {
HttpRequestRecord httpRequestRecord = this.httpRequestRecord;
if (httpRequestRecord != null) {
httpRequestRecord.addRequestNumber(str);
}
WebResourceResponse webResourceResponse = getWebResourceResponse(str);
return webResourceResponse != null ? webResourceResponse : super.shouldInterceptRequest(webView, str);
}
private WebResourceResponse getWebResourceResponse(String str) {
if (!isLocalCacheEnable() || !ResourceCacheManager.isResourceManagerExist() || TextUtils.isEmpty(str)) {
return null;
}
WebResourceResponse cachedWebResourceResponse = ResourceCacheManager.getCachedWebResourceResponse(str);
if (cachedWebResourceResponse != null) {
HttpRequestRecord httpRequestRecord = this.httpRequestRecord;
if (httpRequestRecord != null) {
httpRequestRecord.addCacheNumber(str);
}
return cachedWebResourceResponse;
}
Log.d(TAG, "WebResourceResponse from cache is null");
return null;
}
private boolean handleSslError(WebView webView, SslErrorHandler sslErrorHandler, SslError sslError) {
ReceivedSslErrorHandler receivedSslErrorHandler = (ReceivedSslErrorHandler) ACContainer.INSTANCE.getProvider(ReceivedSslErrorHandler.class.getName());
if (receivedSslErrorHandler == null) {
return false;
}
receivedSslErrorHandler.onReceivedSslError(new ACWebView(webView), new ACSslErrorHandler(sslErrorHandler), sslError);
return true;
}
private boolean onPageEvent(String str, String str2) {
ContainerEvent containerEvent = new ContainerEvent(str2, this.containerPresenter);
JSONObject jSONObject = new JSONObject();
try {
jSONObject.put("url", str);
} catch (JSONException unused) {
}
containerEvent.params = jSONObject;
ACContainer aCContainer = ACContainer.INSTANCE;
return aCContainer.handleContainerEvent(containerEvent) || aCContainer.interceptContainerEvent(containerEvent);
}
private void loadErrorPage(String str, int i) {
Log.d(TAG, "loadError:" + str);
String errorPageUrl = getErrorPageUrl();
if (TextUtils.equals(str, errorPageUrl)) {
return;
}
Log.e(TAG, "loadErrorPage:" + str);
if (!TextUtils.isEmpty(errorPageUrl)) {
Uri.Builder buildUpon = Uri.parse(errorPageUrl).buildUpon();
buildUpon.appendQueryParameter("errorCode", i + "");
buildUpon.appendQueryParameter("url", str);
String uri = buildUpon.build().toString();
String readAsset = IOUtils.readAsset(this.mContext.getResources(), "containererrorpage/griver_custom_h5_page_error.html");
if (readAsset == null) {
return;
}
this.mWebView.loadDataWithBaseURL(str, readAsset.replace("&&&&", uri), "text/html", "utf-8", str);
return;
}
String readAsset2 = IOUtils.readAsset(this.mContext.getResources(), "containererrorpage/griver_page_error.html");
if (readAsset2 == null) {
return;
}
this.mWebView.loadDataWithBaseURL(str, readAsset2.replace("&&&&", errorPageUrl).replace("!!!!", i + ""), "text/html", "utf-8", str);
new Handler(Looper.getMainLooper()).postDelayed(new Runnable() {
@Override
public void run() {
try {
ACJSBridge.getInstance(ACWebViewClient.this.bizCode).loadJavascript(R.raw.h5_bridge, ACWebViewClient.this.mContext, ACWebViewClient.this.mWebView);
} catch (IOException e) {
Log.d(ACWebViewClient.TAG, "loadJavascript:" + e.getMessage());
}
}
}, 300L);
}
public class HttpRequestRecord {
public int cacheNumber;
public boolean enabled;
private boolean pageFinished;
private boolean pageStarted;
public int requestNumber;
public long startTime;
public HttpRequestRecord() {
}
public void startRecord(String str) {
if (this.pageStarted) {
return;
}
this.pageStarted = true;
this.startTime = System.currentTimeMillis();
Iterator<ContainerPerformanceListener> it = getContainerPerformanceListeners().iterator();
while (it.hasNext()) {
ContainerPerformanceListener next = it.next();
if (next != null) {
next.onPageStart(ACWebViewClient.this.originalUrl);
}
}
}
public void addRequestNumber(String str) {
if (this.pageFinished) {
return;
}
Log.d(ACWebViewClient.TAG, "request:" + str);
this.requestNumber = this.requestNumber + 1;
}
public void addCacheNumber(String str) {
if (this.pageFinished) {
return;
}
Log.d(ACWebViewClient.TAG, "cache:" + str);
this.cacheNumber = this.cacheNumber + 1;
}
public void finishRecord(String str) {
if (this.pageFinished) {
return;
}
this.pageFinished = true;
long currentTimeMillis = System.currentTimeMillis();
long j = this.startTime;
CopyOnWriteArrayList<ContainerPerformanceListener> containerPerformanceListeners = getContainerPerformanceListeners();
CacheRecord cacheRecord = new CacheRecord();
cacheRecord.requestNumber = this.requestNumber;
cacheRecord.cacheNumber = this.cacheNumber;
cacheRecord.enabled = this.enabled;
Iterator<ContainerPerformanceListener> it = containerPerformanceListeners.iterator();
while (it.hasNext()) {
ContainerPerformanceListener next = it.next();
if (next != null) {
next.onPageLoaded(ACWebViewClient.this.originalUrl, cacheRecord, Long.valueOf(currentTimeMillis - j));
}
}
}
private CopyOnWriteArrayList<ContainerPerformanceListener> getContainerPerformanceListeners() {
CopyOnWriteArrayList<ContainerPerformanceListener> performanceListeners = ACContainerManager.getInstance().performanceListeners();
return performanceListeners == null ? new CopyOnWriteArrayList<>() : performanceListeners;
}
}
}