夜约 v1.0.0版本的 MD5 值为:0c1dd8fb406d76d05a28810cfc5e943b
以下内容为反编译后的 WebLoadEvent.java 源代码,内容仅作参考
package io.dcloud.common.adapter.ui.webview;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Bitmap;
import android.net.Uri;
import android.net.http.SslError;
import android.os.Build;
import android.text.TextUtils;
import android.util.Log;
import android.view.KeyEvent;
import android.view.ViewGroup;
import android.webkit.CookieSyncManager;
import android.webkit.MimeTypeMap;
import android.webkit.SslErrorHandler;
import android.webkit.URLUtil;
import android.webkit.WebResourceResponse;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.AbsoluteLayout;
import android.widget.ProgressBar;
import androidx.webkit.internal.AssetHelper;
import com.nostra13.dcloudimageloader.core.ImageLoaderL;
import com.nostra13.dcloudimageloader.core.download.BaseImageDownloader;
import com.taobao.weex.el.parse.Operators;
import io.dcloud.base.R;
import io.dcloud.common.DHInterface.IApp;
import io.dcloud.common.DHInterface.IDCloudWebviewClientListener;
import io.dcloud.common.DHInterface.IFrameView;
import io.dcloud.common.DHInterface.ISysEventListener;
import io.dcloud.common.DHInterface.ITitleNView;
import io.dcloud.common.adapter.io.DHFile;
import io.dcloud.common.adapter.ui.AdaFrameView;
import io.dcloud.common.adapter.ui.AdaWebview;
import io.dcloud.common.adapter.ui.ReceiveJSValue;
import io.dcloud.common.adapter.ui.WaitingView;
import io.dcloud.common.adapter.util.AndroidResources;
import io.dcloud.common.adapter.util.DCloudTrustManager;
import io.dcloud.common.adapter.util.DeviceInfo;
import io.dcloud.common.adapter.util.InvokeExecutorHelper;
import io.dcloud.common.adapter.util.Logger;
import io.dcloud.common.adapter.util.MessageHandler;
import io.dcloud.common.constant.AbsoluteConst;
import io.dcloud.common.constant.IntentConst;
import io.dcloud.common.util.BaseInfo;
import io.dcloud.common.util.DLGeolocation;
import io.dcloud.common.util.IOUtil;
import io.dcloud.common.util.ImageLoaderUtil;
import io.dcloud.common.util.Md5Utils;
import io.dcloud.common.util.PdrUtil;
import io.dcloud.common.util.StringUtil;
import io.dcloud.common.util.TitleNViewUtil;
import io.src.dcloud.adapter.DCloudAdapterUtil;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.lang.ref.SoftReference;
import java.lang.ref.WeakReference;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.regex.Pattern;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLSocketFactory;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
public final class WebLoadEvent extends WebViewClient {
private static final String DIFFERENT_VERSION_JS = "window.plus && (plus.android.import=plus.android.importClass);";
public static final String ENABLE = "enable";
private static final String ERROR_TEMPLATE = "javascript:(function(){var b=document.createEvent('HTMLEvents');var a='%s';b.url='%s';b.href='%s';b.initEvent(a,false,true);console.error(a);document.dispatchEvent(b);})();";
private static final String IF_LOAD_TEMPLATE = "(function(){/*console.log('eval js loading href=' + location.href);*/if(location.__page__load__over__){return 2}if(location.__plusready__||window.__html5plus__){return 1}return 0})();";
private static final String IF_PLUSREADY_EVENT_TEMPLATE = "(function(){/*console.log('plusready event loading href=' + location.href);*/if(location.__page__load__over__){return 2}if(location.__plusready__||window.__html5plus__){if(!location.__plusready__event__){location.__plusready__event__=true;return 1}else{return 2}}return 0})();";
private static final String IF_PLUSREADY_TEMPLATE = "(function(){/*console.log('all.js loading href=' + location.href);*/if(location.__page__load__over__){return 2}if(!location.__plusready__){location.__plusready__=true;return 1}else{return 2}return 0})();";
private static final String IF_PRELOAD_TEMPLATE = "(function(){/*console.log( 'preload js loading href=' + location.href);*/if(location.__page__load__over__){return 2}var jsfile='%s';if(location.__plusready__||window.__html5plus__){location.__preload__=location.__preload__||[];if(location.__preload__.indexOf(jsfile)<0){location.__preload__.push(jsfile);return 1}else{return 2}}return 0})();";
private static final int LOADABLE = 1;
private static final int LOADED = 2;
private static final int NOLOAD = 0;
public static String PAGE_FINISHED_FLAG = "javascript:setTimeout(function(){location.__page__load__over__ = true;},2000);";
public static final String PLUSREADY = "html5plus://ready";
static final String TAG = "WebLoadEvent";
static final int Timeout_Page_Finish = 6000;
static final int Timeout_Plus_Inject = 3000;
public static final String UNIAPP_READY = "uniapp://ready";
boolean isInitAmapGEO;
AdaWebview mAdaWebview;
String mAppid;
private boolean mClearCache;
long mShowLoadingTime;
boolean printLog = true;
private OnPageFinishedCallack mPageFinishedCallack = null;
private IDCloudWebviewClientListener mdcloudwebviewclientlister = null;
private String mLastPageUrl = "";
WaitingView mWap2AppBlockDialog = null;
ISysEventListener mWap2AppBlockDialogSysEventListener = null;
String mPlusJS = null;
String TYPE_JS = "type_js";
String TYPE_CSS = "type_css";
private Runnable mTitleNViewProgressStop = null;
boolean needResponseRedirect = true;
ProgressBar mWaitingForWapPage = null;
Runnable Timeout_Plus_Inject_Runnable = null;
Runnable Timeout_Page_Finish_Runnable = null;
public class CatchFile {
File mFile = null;
String mEncoding = null;
String mContentType = null;
boolean mExist = false;
CatchFile() {
}
}
static class TitleNViewProgressStop implements Runnable {
private WeakReference<AdaWebview> mAdaWebview;
public TitleNViewProgressStop(AdaWebview adaWebview) {
this.mAdaWebview = new WeakReference<>(adaWebview);
}
@Override
public void run() {
WeakReference<AdaWebview> weakReference = this.mAdaWebview;
if (weakReference == null || weakReference.get() == null || this.mAdaWebview.get().obtainFrameView() == null) {
return;
}
Object titleNView = TitleNViewUtil.getTitleNView(this.mAdaWebview.get().obtainFrameView().obtainWindowMgr(), this.mAdaWebview.get().obtainFrameView().obtainWebView(), this.mAdaWebview.get().obtainFrameView(), TitleNViewUtil.getTitleNViewId(this.mAdaWebview.get().obtainFrameView()));
if (titleNView instanceof ITitleNView) {
TitleNViewUtil.stopProcess((ITitleNView) titleNView);
}
}
}
public WebLoadEvent(AdaWebview adaWebview) {
this.mAdaWebview = null;
this.mClearCache = false;
this.mAppid = null;
this.isInitAmapGEO = false;
this.mAdaWebview = adaWebview;
this.mAppid = adaWebview.obtainApp().obtainAppId();
String obtainConfigProperty = adaWebview.obtainApp().obtainConfigProperty(IApp.ConfigProperty.CONFIG_RAM_CACHE_MODE);
if (BaseInfo.isBase(adaWebview.getContext()) && !ENABLE.equalsIgnoreCase(obtainConfigProperty)) {
this.mClearCache = true;
}
reset();
this.isInitAmapGEO = DLGeolocation.checkGeo(adaWebview.getContext());
}
private boolean checkCssFile(String str) {
return !TextUtils.isEmpty(str) && str.contains(".css");
}
private boolean checkJsFile(String str) {
return (TextUtils.isEmpty(str) || !str.contains(".js") || str.contains(".jsp")) ? false : true;
}
private WebResourceResponse checkWebResourceResponseRedirect(WebView webView, String str) {
AdaWebview adaWebview;
JSONObject obtainThridInfo;
String str2;
if (this.needResponseRedirect) {
try {
if (!URLUtil.isNetworkUrl(str) || !BaseInfo.existsStreamEnv() || (adaWebview = this.mAdaWebview) == null || adaWebview.obtainFrameView().obtainApp() == null || (obtainThridInfo = this.mAdaWebview.obtainFrameView().obtainApp().obtainThridInfo(IApp.ConfigProperty.ThridInfo.URDJsonData)) == null) {
return null;
}
JSONArray optJSONArray = obtainThridInfo.optJSONObject("data").optJSONArray(InvokeExecutorHelper.create("io.dcloud.appstream.rules.util.Tools").invoke("getTopDomainInHost", new URL(str).getHost()));
if (optJSONArray != null) {
int i = 0;
boolean z = false;
while (true) {
if (i >= optJSONArray.length()) {
str2 = null;
break;
}
JSONObject optJSONObject = optJSONArray.optJSONObject(i);
JSONArray optJSONArray2 = optJSONObject.optJSONArray("match");
str2 = optJSONObject.optString("redirect");
int i2 = 0;
while (true) {
if (i2 >= optJSONArray2.length()) {
break;
} else if (Pattern.compile(optJSONArray2.optString(i)).matcher(str).matches()) {
z = true;
break;
} else {
i2++;
}
}
if (z) {
break;
}
i++;
}
return downloadResponse(webView, str2);
}
return null;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
return null;
}
public final void completeLoadJs(final WebView webView, final String str, final String str2, final String[] strArr, final String str3, final Object... objArr) {
final SoftReference softReference = new SoftReference(this.mAdaWebview);
this.mAdaWebview.executeScript(ReceiveJSValue.registerCallback((AdaWebview) softReference.get(), StringUtil.format(str3, objArr), new ReceiveJSValue.ReceiveJSValueCallback() {
@Override
public String callback(JSONArray jSONArray) {
String[] strArr2;
try {
int i = jSONArray.getInt(1);
if (i == 0 && !PdrUtil.isEquals(str2, "onPageFinished")) {
WebLoadEvent.this.completeLoadJs(webView, str, str2, strArr, str3, objArr);
return null;
} else if (1 == i) {
for (String str4 : strArr) {
if (softReference.get() != null) {
((AdaWebview) softReference.get()).executeScript(str4);
}
}
return null;
} else {
return null;
}
} catch (JSONException e) {
e.printStackTrace();
return null;
}
}
}));
}
private boolean directPageIsLaunchPage(IApp iApp) {
return (iApp == null || TextUtils.isEmpty(iApp.getOriginalDirectPage()) || iApp.obtainWebAppIntent().hasExtra(IntentConst.DIRECT_PAGE)) ? false : true;
}
private WebResourceResponse downloadResponse(final WebView webView, final String str) {
if (URLUtil.isNetworkUrl(str)) {
try {
MessageHandler.sendMessage(new MessageHandler.IMessages() {
@Override
public void execute(Object obj) {
webView.stopLoading();
WebLoadEvent.this.needResponseRedirect = false;
webView.loadUrl(str);
}
}, null);
return new WebResourceResponse(null, null, new ByteArrayInputStream("".getBytes()));
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
return null;
}
private WebResourceResponse downloadResponseInjection(WebResourceResponse webResourceResponse, String str, String str2, String str3, String str4) {
WebResourceResponse webResourceResponse2;
byte[] bArr;
WebResourceResponse webResourceResponse3;
String str5;
String str6;
InputStream encryptionInputStream;
long currentTimeMillis = System.currentTimeMillis();
if (str4.equals(this.TYPE_JS)) {
String preLoadJsString = this.mAdaWebview.getPreLoadJsString();
AdaWebview adaWebview = this.mAdaWebview;
ByteArrayInputStream byteArrayInputStream = null;
if (!adaWebview.mForceAHeadJsFileLoaded && !TextUtils.isEmpty(adaWebview.mForceAHeadJsFile)) {
try {
AdaWebview adaWebview2 = this.mAdaWebview;
encryptionInputStream = WebResUtil.getEncryptionInputStream(adaWebview2.mForceAHeadJsFile, adaWebview2.mFrameView.obtainApp());
} catch (IOException e) {
Logger.e("Exception", e.getMessage());
}
if (encryptionInputStream != null) {
bArr = IOUtil.getBytes(encryptionInputStream);
if (!TextUtils.isEmpty(preLoadJsString) && bArr == null && TextUtils.isEmpty(this.mPlusJS)) {
return null;
}
if (!URLUtil.isNetworkUrl(str) && (this.mAdaWebview.mNeedInjection || this.isInitAmapGEO || bArr != null)) {
CatchFile urlFile = getUrlFile(str, str4);
if (urlFile != null) {
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
if (bArr != null) {
byteArrayOutputStream.write(bArr);
this.mAdaWebview.mForceAHeadJsFileLoaded = true;
}
if (!TextUtils.isEmpty(this.mPlusJS) && this.mAdaWebview.mPlusrequire.equals("ahead")) {
AdaWebview adaWebview3 = this.mAdaWebview;
adaWebview3.mPlusInjectTag = str;
adaWebview3.mPlusLoading = true;
byteArrayOutputStream.write(this.mPlusJS.getBytes());
}
if (!TextUtils.isEmpty(preLoadJsString) && this.mAdaWebview.mPlusrequire.equals("ahead")) {
Logger.i(TAG, "mPlusrequire=ahead;this=" + this);
this.mAdaWebview.mPreloadJsLoading = true;
byteArrayOutputStream.write(preLoadJsString.getBytes());
}
if (this.isInitAmapGEO && DLGeolocation.checkInjectGeo(this.mAdaWebview.mInjectGEO) && !this.mAdaWebview.mPlusrequire.equals("ahead")) {
this.mAdaWebview.mInjectGeoLoaded = true;
byteArrayOutputStream.write(DLGeolocation.getGEOJS().getBytes());
}
if (urlFile.mExist) {
try {
FileInputStream fileInputStream = new FileInputStream(urlFile.mFile);
byte[] bArr2 = new byte[4096];
while (true) {
int read = fileInputStream.read(bArr2);
if (read <= 0) {
break;
}
byteArrayOutputStream.write(bArr2, 0, read);
}
fileInputStream.close();
} catch (IOException e2) {
e2.printStackTrace();
}
}
str6 = !TextUtils.isEmpty(urlFile.mEncoding) ? urlFile.mEncoding : str3;
str5 = !TextUtils.isEmpty(urlFile.mContentType) ? urlFile.mContentType : str2;
ByteArrayInputStream byteArrayInputStream2 = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
if (this.mAdaWebview.mPlusrequire.equals("ahead")) {
listenPlusInjectTimeout((WebView) this.mAdaWebview.getDCWebView().getWebView(), this.mAdaWebview.obtainFullUrl(), "inject_with_js");
}
byteArrayInputStream = byteArrayInputStream2;
webResourceResponse3 = byteArrayInputStream != null ? new WebResourceResponse(str5, str6, byteArrayInputStream) : webResourceResponse;
if (webResourceResponse3 != null) {
try {
this.mAdaWebview.mEncoding = str6;
Logger.i(TAG, "提前注入JS成功耗时:" + (System.currentTimeMillis() - currentTimeMillis) + this.mAdaWebview.getOriginalUrl() + ";url=" + str);
} catch (Exception e3) {
e = e3;
e.printStackTrace();
return webResourceResponse3;
}
}
return webResourceResponse3;
}
} else if (!PLUSREADY.equals(str)) {
if (!TextUtils.isEmpty(this.mPlusJS)) {
Logger.i("PLUSREADY", this.mAdaWebview.getOriginalUrl() + ";url=" + str);
this.mAdaWebview.mPlusLoading = true;
byteArrayInputStream = new ByteArrayInputStream(this.mPlusJS.getBytes());
}
} else if (PdrUtil.isDeviceRootDir(str)) {
byteArrayInputStream = new FileInputStream(str);
}
str5 = str2;
str6 = str3;
if (byteArrayInputStream != null) {
}
if (webResourceResponse3 != null) {
}
return webResourceResponse3;
}
}
bArr = null;
if (!TextUtils.isEmpty(preLoadJsString)) {
}
if (!URLUtil.isNetworkUrl(str)) {
}
if (!PLUSREADY.equals(str)) {
}
str5 = str2;
str6 = str3;
if (byteArrayInputStream != null) {
}
if (webResourceResponse3 != null) {
}
return webResourceResponse3;
}
if (this.TYPE_CSS.equals(str4)) {
String cssString = this.mAdaWebview.getCssString();
if (!this.mAdaWebview.mIsAdvanceCss && !TextUtils.isEmpty(cssString)) {
try {
ByteArrayOutputStream byteArrayOutputStream2 = new ByteArrayOutputStream();
CatchFile urlFile2 = getUrlFile(str, str4);
if (urlFile2 != null) {
if (urlFile2.mExist) {
FileInputStream fileInputStream2 = new FileInputStream(urlFile2.mFile);
byte[] bArr3 = new byte[4096];
while (true) {
int read2 = fileInputStream2.read(bArr3);
if (read2 <= 0) {
break;
}
byteArrayOutputStream2.write(bArr3, 0, read2);
}
fileInputStream2.close();
}
byteArrayOutputStream2.write(cssString.getBytes());
}
String str7 = !TextUtils.isEmpty(urlFile2.mEncoding) ? urlFile2.mEncoding : str3;
webResourceResponse2 = new WebResourceResponse("text/css", str7, new ByteArrayInputStream(byteArrayOutputStream2.toByteArray()));
try {
AdaWebview adaWebview4 = this.mAdaWebview;
adaWebview4.mIsAdvanceCss = true;
adaWebview4.mEncoding = str7;
Logger.i(TAG, "提前注入CSS成功耗时:" + (System.currentTimeMillis() - currentTimeMillis) + this.mAdaWebview.getOriginalUrl() + ";url=" + str);
return webResourceResponse2;
} catch (Exception unused) {
this.mAdaWebview.mIsAdvanceCss = false;
return webResourceResponse2;
}
} catch (Exception unused2) {
webResourceResponse2 = webResourceResponse;
}
}
}
return webResourceResponse;
}
private String getCacheLocalFilePath(String str, String str2) {
IApp obtainApp;
AdaWebview adaWebview = this.mAdaWebview;
if (adaWebview == null || (obtainApp = adaWebview.obtainApp()) == null) {
return null;
}
if (this.TYPE_JS.equals(str2)) {
return obtainApp.obtainAppTempPath() + "__plus__cache__/" + Md5Utils.md5(str) + ".js";
}
return obtainApp.obtainAppTempPath() + "__plus__cache__/" + Md5Utils.md5(str) + ".css";
}
public static String getMimeType(String str) {
String fileExtensionFromUrl = MimeTypeMap.getFileExtensionFromUrl(str);
String mimeTypeFromExtension = fileExtensionFromUrl != null ? MimeTypeMap.getSingleton().getMimeTypeFromExtension(fileExtensionFromUrl) : null;
return TextUtils.isEmpty(mimeTypeFromExtension) ? AssetHelper.DEFAULT_MIME_TYPE : mimeTypeFromExtension;
}
private CatchFile getUrlFile(String str, String str2) throws Exception {
String cacheLocalFilePath = getCacheLocalFilePath(str, str2);
try {
if (DHFile.isExist(cacheLocalFilePath)) {
CatchFile catchFile = new CatchFile();
File file = new File(cacheLocalFilePath);
catchFile.mFile = file;
catchFile.mExist = file.exists();
return catchFile;
}
} catch (IOException e) {
e.printStackTrace();
}
try {
URL url = new URL(str);
HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
if (httpURLConnection instanceof HttpsURLConnection) {
try {
SSLSocketFactory sSLSocketFactory = DCloudTrustManager.getSSLSocketFactory();
if (sSLSocketFactory != null) {
((HttpsURLConnection) httpURLConnection).setSSLSocketFactory(sSLSocketFactory);
}
((HttpsURLConnection) httpURLConnection).setHostnameVerifier(DCloudTrustManager.getHostnameVerifier(true));
} catch (Exception e2) {
throw new RuntimeException(e2);
}
}
httpURLConnection.setConnectTimeout(BaseImageDownloader.DEFAULT_HTTP_CONNECT_TIMEOUT);
httpURLConnection.setReadTimeout(BaseImageDownloader.DEFAULT_HTTP_CONNECT_TIMEOUT);
httpURLConnection.setRequestMethod("GET");
httpURLConnection.setDoInput(true);
int responseCode = httpURLConnection.getResponseCode();
String contentType = httpURLConnection.getContentType();
if (!TextUtils.isEmpty(contentType) && (((str2.equals(this.TYPE_JS) && contentType.contains("javascript")) || (str2.equals(this.TYPE_CSS) && (contentType.contains("text/css") || url.getPath().endsWith(".css")))) && (responseCode == 200 || responseCode == 206))) {
InputStream inputStream = httpURLConnection.getInputStream();
boolean writeFile = DHFile.writeFile(inputStream, cacheLocalFilePath);
IOUtil.close(inputStream);
if (writeFile) {
CatchFile catchFile2 = new CatchFile();
File file2 = new File(cacheLocalFilePath);
catchFile2.mFile = file2;
catchFile2.mExist = file2.exists();
catchFile2.mEncoding = httpURLConnection.getContentEncoding();
catchFile2.mContentType = contentType;
return catchFile2;
}
File file3 = new File(cacheLocalFilePath);
if (file3.exists()) {
file3.delete();
}
}
return null;
} catch (IOException e3) {
e3.printStackTrace();
return null;
}
}
private WebResourceResponse handleDecode(String str, WebResourceResponse webResourceResponse) {
InputStream encryptionInputStream;
return (TextUtils.isEmpty(str) || (encryptionInputStream = WebResUtil.getEncryptionInputStream(str, this.mAdaWebview.obtainApp())) == null) ? webResourceResponse : new WebResourceResponse(getMimeType(str), "UTF-8", encryptionInputStream);
}
private void hideLoading() {
this.mAdaWebview.obtainMainView().post(new Runnable() {
@Override
public void run() {
if (WebLoadEvent.this.mAdaWebview == null) {
return;
}
long currentTimeMillis = System.currentTimeMillis();
WebLoadEvent webLoadEvent = WebLoadEvent.this;
if (currentTimeMillis - webLoadEvent.mShowLoadingTime < 1000) {
webLoadEvent.mAdaWebview.getDCWebView().getWebView().postDelayed(this, currentTimeMillis - WebLoadEvent.this.mShowLoadingTime);
return;
}
AdaFrameView adaFrameView = webLoadEvent.mAdaWebview.mFrameView;
adaFrameView.dispatchFrameViewEvents(AbsoluteConst.EVENTS_HIDE_LOADING, adaFrameView);
}
});
}
private void listenPlusInjectTimeout(final WebView webView, final String str, final String str2) {
AdaWebview adaWebview = this.mAdaWebview;
if (adaWebview == null && adaWebview.mPlusrequire.equals("none")) {
return;
}
Runnable runnable = this.Timeout_Plus_Inject_Runnable;
if (runnable != null) {
MessageHandler.removeCallbacks(runnable);
}
Runnable runnable2 = new Runnable() {
@Override
public void run() {
AdaWebview adaWebview2 = WebLoadEvent.this.mAdaWebview;
if (adaWebview2 == null || adaWebview2.isRealInject(str)) {
return;
}
Logger.i("WebViewData", "listenPlusInjectTimeout url=" + str);
WebLoadEvent webLoadEvent = WebLoadEvent.this;
WebView webView2 = webView;
String str3 = str;
webLoadEvent.onLoadPlusJSContent(webView2, str3, "plus_inject_timeout_" + str2);
WebLoadEvent webLoadEvent2 = WebLoadEvent.this;
webLoadEvent2.mAdaWebview.mPreloadJsLoading = false;
webLoadEvent2.Timeout_Plus_Inject_Runnable = null;
}
};
this.Timeout_Plus_Inject_Runnable = runnable2;
MessageHandler.postDelayed(runnable2, 3000L);
}
private void loadAllJSContent(WebView webView, String str, String str2) {
if (onLoadPlusJSContent(webView, str, str2)) {
injectScript(webView, str, str2);
}
}
private void onExecuteEvalJSStatck(WebView webView, String str, String str2) {
String str3 = this.mAdaWebview.get_eval_js_stack();
if (PdrUtil.isEmpty(str3)) {
return;
}
completeLoadJs(webView, str, str2, new String[]{str3}, IF_LOAD_TEMPLATE, str);
}
private void onLoadCssContent() {
AdaWebview adaWebview = this.mAdaWebview;
if (adaWebview.mIsAdvanceCss) {
Logger.i(TAG, "已经提前注入CSS完成。不需要再注入了" + this.mAdaWebview.getOriginalUrl());
} else if (adaWebview.loadCssFile()) {
Logger.i(TAG, "提前注入CSS完成" + this.mAdaWebview.getOriginalUrl());
}
}
public boolean onLoadPlusJSContent(final WebView webView, final String str, final String str2) {
if (this.mAdaWebview.mPlusrequire.equals("none")) {
return false;
}
if (this.mAdaWebview.isRealInject(str)) {
Logger.i(TAG, "all.js已经注入完成。不需要再注入了" + this.mAdaWebview.getOriginalUrl());
return true;
}
Logger.i(TAG, "onLoadPlusJSContent all.js注入 " + this.mAdaWebview.getOriginalUrl() + ";tag=" + str2 + ";mAdaWebview.mPlusrequire=" + this.mAdaWebview.mPlusrequire);
if (this.mAdaWebview.mPlusrequire.equals("later") && str2.equals("onPageFinished")) {
webView.postDelayed(new Runnable() {
@Override
public void run() {
WebLoadEvent webLoadEvent = WebLoadEvent.this;
AdaWebview adaWebview = webLoadEvent.mAdaWebview;
if (adaWebview != null) {
String str3 = str2;
adaWebview.mPlusInjectTag = str3;
adaWebview.mPlusLoading = true;
WebView webView2 = webView;
String str4 = str;
webLoadEvent.completeLoadJs(webView2, str4, str3, new String[]{webLoadEvent.mPlusJS, WebLoadEvent.DIFFERENT_VERSION_JS}, WebLoadEvent.IF_PLUSREADY_TEMPLATE, str4);
}
}
}, 2000L);
} else {
AdaWebview adaWebview = this.mAdaWebview;
adaWebview.mPlusInjectTag = str2;
adaWebview.mPlusLoading = true;
completeLoadJs(webView, str, str2, new String[]{this.mPlusJS, DIFFERENT_VERSION_JS}, IF_PLUSREADY_TEMPLATE, str);
}
return false;
}
public void onPlusreadyEvent(WebView webView, String str, String str2) {
StringBuffer stringBuffer = new StringBuffer();
stringBuffer.append(StringUtil.format(AbsoluteConst.EVENTS_DOCUMENT_EXECUTE_TEMPLATE, AbsoluteConst.EVENTS_PLUSREADY));
StringBuffer stringBuffer2 = new StringBuffer();
stringBuffer2.append(StringUtil.format(AbsoluteConst.EVENTS_IFRAME_DOUCMENT_EXECUTE_TEMPLATE, AbsoluteConst.EVENTS_PLUSREADY));
completeLoadJs(webView, str, str2, new String[]{stringBuffer.toString(), stringBuffer2.toString(), "plus.webview.currentWebview().__needTouchEvent__()"}, IF_PLUSREADY_EVENT_TEMPLATE, str);
}
private void printOpenLog(WebView webView, String str) {
IApp obtainApp;
String url = webView.getUrl();
if (!BaseInfo.isBase(webView.getContext()) || TextUtils.isEmpty(str) || TextUtils.isEmpty(url) || (obtainApp = this.mAdaWebview.mFrameView.obtainApp()) == null || str.startsWith(DeviceInfo.HTTP_PROTOCOL) || url.startsWith(DeviceInfo.HTTP_PROTOCOL) || str.startsWith(DeviceInfo.HTTPS_PROTOCOL) || url.startsWith(DeviceInfo.HTTPS_PROTOCOL)) {
return;
}
Log.i(AbsoluteConst.HBUILDER_TAG, StringUtil.format(AbsoluteConst.OPENLOG, WebResUtil.getHBuilderPrintUrl(obtainApp.convert2RelPath(WebResUtil.getOriginalUrl(url))), WebResUtil.getHBuilderPrintUrl(obtainApp.convert2RelPath(WebResUtil.getOriginalUrl(str)))));
}
private void printResourceLog(WebView webView, IApp iApp, String str, String str2) {
if (TextUtils.isEmpty(str2) || TextUtils.isEmpty(str) || webView == null || iApp == null || !BaseInfo.isBase(webView.getContext()) || str.equalsIgnoreCase(str2) || TextUtils.isEmpty(str2)) {
return;
}
if (this.mClearCache && !this.mLastPageUrl.equalsIgnoreCase(str)) {
webView.clearCache(true);
}
this.mLastPageUrl = str;
String originalUrl = WebResUtil.getOriginalUrl(str);
if (str2.startsWith(DeviceInfo.HTTP_PROTOCOL) || str2.startsWith(DeviceInfo.HTTPS_PROTOCOL)) {
return;
}
Log.i(AbsoluteConst.HBUILDER_TAG, StringUtil.format(AbsoluteConst.RESOURCELOG, WebResUtil.getHBuilderPrintUrl(iApp.convert2RelPath(originalUrl)), WebResUtil.getHBuilderPrintUrl(iApp.convert2RelPath(WebResUtil.getOriginalUrl(str2)))));
}
private boolean shouldRuntimeHandle(String str) {
return PdrUtil.isDeviceRootDir(str) || PdrUtil.isNetPath(str) || str.startsWith(DeviceInfo.FILE_PROTOCOL);
}
private void showLoading() {
this.mAdaWebview.getDCWebView().getWebView().post(new Runnable() {
@Override
public void run() {
AdaWebview adaWebview = WebLoadEvent.this.mAdaWebview;
if (adaWebview != null) {
AdaFrameView adaFrameView = adaWebview.mFrameView;
adaFrameView.dispatchFrameViewEvents(AbsoluteConst.EVENTS_SHOW_LOADING, adaFrameView);
}
}
});
this.mShowLoadingTime = System.currentTimeMillis();
}
private void startTryLoadAllJSContent(WebView webView, String str, String str2) {
loadAllJSContent(webView, str, str2);
}
public void closeWap2AppBlockDialog(boolean z) {
WaitingView waitingView = this.mWap2AppBlockDialog;
if (waitingView != null) {
waitingView.close();
this.mAdaWebview.obtainApp().unregisterSysEventListener(this.mWap2AppBlockDialogSysEventListener, ISysEventListener.SysEventType.onKeyUp);
this.mWap2AppBlockDialog = null;
this.mWap2AppBlockDialogSysEventListener = null;
if (z) {
AdaWebview adaWebview = this.mAdaWebview;
adaWebview.loadUrl(adaWebview.mRecordLastUrl);
}
}
}
public void destroy() {
this.mAdaWebview = null;
this.mPlusJS = null;
this.mTitleNViewProgressStop = null;
this.mWap2AppBlockDialog = null;
this.mWaitingForWapPage = null;
}
@Override
public void doUpdateVisitedHistory(WebView webView, String str, boolean z) {
if (PdrUtil.isEmpty(this.mdcloudwebviewclientlister)) {
return;
}
this.mdcloudwebviewclientlister.doUpdateVisitedHistory(webView, str, z);
}
String getErrorPage() {
String str = this.mAdaWebview.mFrameView.obtainFrameOptions().errorPage;
if (URLUtil.isNetworkUrl(str)) {
return str;
}
if (!TextUtils.isEmpty(str)) {
IApp obtainApp = this.mAdaWebview.obtainApp();
if ("none".equals(str)) {
return str;
}
String convert2AbsFullPath = obtainApp.convert2AbsFullPath(this.mAdaWebview.obtainFullUrl(), str);
File file = new File(convert2AbsFullPath);
if (file.exists()) {
return obtainApp.convert2WebviewFullPath(this.mAdaWebview.obtainFullUrl(), str);
}
if (BaseInfo.isWap2AppAppid(obtainApp.obtainAppId())) {
String relPath = WebResUtil.getRelPath(PdrUtil.stripQuery(PdrUtil.stripAnchor(convert2AbsFullPath)), obtainApp);
if (WebResUtil.isWap2appTemplateFile(obtainApp, relPath)) {
str = WebResUtil.handleWap2appTemplateFilePath(relPath);
file = new File(str);
}
}
if (file.exists()) {
return DeviceInfo.FILE_PROTOCOL + str;
}
String obtainConfigProperty = obtainApp.obtainConfigProperty("error");
if (!"none".equals(obtainConfigProperty)) {
return obtainApp.convert2WebviewFullPath(null, obtainConfigProperty);
}
} else {
String obtainConfigProperty2 = this.mAdaWebview.obtainApp().obtainConfigProperty("error");
if (!"none".equals(obtainConfigProperty2)) {
return this.mAdaWebview.obtainApp().convert2WebviewFullPath(null, obtainConfigProperty2);
}
}
return "none";
}
void injectScript(final WebView webView, final String str, final String str2) {
if (str2.equals("onPageFinished") && this.mAdaWebview.mPlusrequire.equals("later")) {
webView.postDelayed(new Runnable() {
@Override
public void run() {
WebLoadEvent webLoadEvent = WebLoadEvent.this;
if (webLoadEvent.mAdaWebview != null) {
webLoadEvent.onPreloadJSContent(webView, str, str2);
WebLoadEvent.this.onPlusreadyEvent(webView, str, str2);
}
}
}, 2000L);
} else {
onPreloadJSContent(webView, str, str2);
onPlusreadyEvent(webView, str, str2);
}
onLoadCssContent();
}
public void listenPageFinishTimeout(final WebView webView, final String str, final String str2) {
AdaWebview adaWebview = this.mAdaWebview;
if (adaWebview.mLoaded && adaWebview.isRealInject(str)) {
injectScript(webView, str, str2);
return;
}
Runnable runnable = this.Timeout_Page_Finish_Runnable;
if (runnable != null) {
MessageHandler.removeCallbacks(runnable);
}
Runnable runnable2 = new Runnable() {
@Override
public void run() {
AdaWebview adaWebview2 = WebLoadEvent.this.mAdaWebview;
if (adaWebview2 == null || adaWebview2.mLoaded || !adaWebview2.isRealInject(str)) {
return;
}
WebLoadEvent webLoadEvent = WebLoadEvent.this;
WebView webView2 = webView;
String str3 = str;
webLoadEvent.injectScript(webView2, str3, "page_finished_timeout_" + str2);
WebLoadEvent.this.Timeout_Page_Finish_Runnable = null;
}
};
this.Timeout_Page_Finish_Runnable = runnable2;
MessageHandler.postDelayed(runnable2, 6000L);
}
@Override
public void onLoadResource(WebView webView, String str) {
if (this.mAdaWebview == null) {
return;
}
if (this.printLog) {
Logger.i(TAG, "onLoadResource url=" + str);
}
this.needResponseRedirect = true;
printResourceLog(webView, this.mAdaWebview.mFrameView.obtainApp(), webView.getUrl(), str);
IFrameView obtainFrameView = this.mAdaWebview.obtainFrameView();
if (obtainFrameView.obtainStatus() != 3) {
obtainFrameView.onLoading();
}
if (this.mAdaWebview.checkResourceLoading(str)) {
AdaFrameView adaFrameView = this.mAdaWebview.mFrameView;
adaFrameView.dispatchFrameViewEvents(AbsoluteConst.EVENTS_LISTEN_RESOURCE_LOADING, "{url:'" + str + "'}");
}
this.mAdaWebview.dispatchWebviewStateEvent(2, str);
super.onLoadResource(webView, str);
}
@Override
public void onPageFinished(WebView webView, String str) {
boolean z;
if (this.mAdaWebview == null) {
return;
}
Logger.d(TAG, "onPageFinished=" + str);
if (PdrUtil.isEmpty(this.mAdaWebview.mFrameView.obtainApp())) {
Logger.e(TAG, "mAdaWebview.mFrameView.obtainApp()===null");
} else if (this.mAdaWebview.hadClearHistory(str)) {
this.mAdaWebview.hasErrorPage = false;
} else {
if (this.mAdaWebview.hasErrorPage) {
String errorPage = getErrorPage();
if (!PdrUtil.isEquals(str, errorPage) && (!"data:text/html,chromewebdata".equals(str) || !"none".equals(errorPage))) {
return;
}
z = true;
} else {
z = false;
}
if (this.mAdaWebview.unReceiveTitle) {
Logger.i(TAG, "onPageFinished will exe titleUpdate =" + str);
AdaWebview adaWebview = this.mAdaWebview;
adaWebview.mFrameView.dispatchFrameViewEvents(AbsoluteConst.EVENTS_TITLE_UPDATE, adaWebview.getDCWebView().getTitle());
this.mAdaWebview.unReceiveTitle = false;
}
CookieSyncManager.getInstance().sync();
Logger.i(TAG, "onPageFinished" + this.mAdaWebview.getOriginalUrl());
this.mAdaWebview.dispatchWebviewStateEvent(1, str);
this.mAdaWebview.loadForceAHeadJs();
onLoadPlusJSContent(webView, str, "onPageFinished");
if (this.mAdaWebview.isRealInject(str)) {
injectScript(webView, str, "onPageFinished");
}
AdaWebview adaWebview2 = this.mAdaWebview;
adaWebview2.mFrameView.dispatchFrameViewEvents(AbsoluteConst.EVENTS_LOADED, adaWebview2);
if (z) {
this.mAdaWebview.executeScript(StringUtil.format(ERROR_TEMPLATE, "error", this.mAdaWebview.getOriginalUrl(), this.mAdaWebview.errorPageUrl));
AdaWebview adaWebview3 = this.mAdaWebview;
adaWebview3.errorPageUrl = null;
adaWebview3.hasErrorPage = false;
}
AdaFrameView adaFrameView = this.mAdaWebview.mFrameView;
if (adaFrameView.obtainStatus() != 3) {
adaFrameView.onPreShow(null);
}
AdaWebview adaWebview4 = this.mAdaWebview;
if (!adaWebview4.mLoaded) {
adaWebview4.mLoaded = true;
adaWebview4.mPlusLoaded = true;
}
super.onPageFinished(webView, str);
if (this.mAdaWebview.justClearOption && !str.startsWith("data:")) {
Logger.d(TAG, "onPageFinished mWebViewImpl.clearHistory url=" + str);
this.mAdaWebview.getDCWebView().clearHistory();
this.mAdaWebview.justClearOption = false;
}
this.mAdaWebview.getDCWebView().webReload(false);
OnPageFinishedCallack onPageFinishedCallack = this.mPageFinishedCallack;
if (onPageFinishedCallack != null) {
onPageFinishedCallack.onLoad();
}
if (this.mWaitingForWapPage != null) {
try {
((ViewGroup) this.mAdaWebview.obtainFrameView().obtainMainView()).removeView(this.mWaitingForWapPage);
this.mWaitingForWapPage = null;
} catch (Exception e) {
e.printStackTrace();
}
}
this.mAdaWebview.checkInjectSitemap();
if (PdrUtil.isEmpty(this.mdcloudwebviewclientlister)) {
return;
}
this.mdcloudwebviewclientlister.onPageFinished(webView, str);
}
}
@Override
public void onPageStarted(WebView webView, String str, Bitmap bitmap) {
AdaWebview adaWebview = this.mAdaWebview;
if (adaWebview == null) {
return;
}
if (adaWebview.hasErrorPage) {
String errorPage = getErrorPage();
if (!PdrUtil.isEquals(str, errorPage) && ((!"data:text/html,chromewebdata".equals(str) || !"none".equals(errorPage)) && (PdrUtil.isEmpty(this.mAdaWebview.errorPageUrl) || !this.mAdaWebview.errorPageUrl.equals(str)))) {
AdaWebview adaWebview2 = this.mAdaWebview;
adaWebview2.hasErrorPage = false;
adaWebview2.errorPageUrl = null;
}
}
Logger.i(TAG, "onPageStarted url=" + str);
this.mAdaWebview.onPageStarted();
printOpenLog(webView, str);
if (this.mAdaWebview.hadClearHistory(str)) {
return;
}
if (this.mAdaWebview.mPlusrequire.equals("ahead")) {
listenPlusInjectTimeout(webView, str, "onPageStarted");
}
if (!str.startsWith("data:")) {
this.mAdaWebview.getDCWebView().setUrlStr(str);
}
this.mAdaWebview.resetPlusLoadSaveData();
if (!PdrUtil.isEmpty(this.mAdaWebview.getDCWebView().getUrlStr())) {
AdaWebview adaWebview3 = this.mAdaWebview;
adaWebview3.mFrameView.dispatchFrameViewEvents(AbsoluteConst.EVENTS_WINDOW_CLOSE, adaWebview3);
}
this.mAdaWebview.dispatchWebviewStateEvent(0, str);
AdaWebview adaWebview4 = this.mAdaWebview;
AdaFrameView adaFrameView = adaWebview4.mFrameView;
adaFrameView.dispatchFrameViewEvents("loading", adaWebview4);
if (adaFrameView.obtainStatus() != 3) {
adaFrameView.onPreLoading();
}
super.onPageStarted(webView, str, bitmap);
if (this.mAdaWebview.mFrameView.getFrameType() == 3) {
try {
if (this.mWaitingForWapPage == null) {
this.mWaitingForWapPage = new ProgressBar(this.mAdaWebview.getContext());
int i = AndroidResources.mResources.getDisplayMetrics().widthPixels;
int i2 = AndroidResources.mResources.getDisplayMetrics().heightPixels;
int parseInt = PdrUtil.parseInt("7%", i, -1);
((ViewGroup) this.mAdaWebview.obtainFrameView().obtainMainView()).addView(this.mWaitingForWapPage, new AbsoluteLayout.LayoutParams(parseInt, parseInt, (i - parseInt) / 2, (i2 - parseInt) / 2));
}
} catch (Exception e) {
e.printStackTrace();
}
}
Object titleNView = TitleNViewUtil.getTitleNView(this.mAdaWebview.obtainFrameView().obtainWindowMgr(), this.mAdaWebview.obtainFrameView().obtainWebView(), this.mAdaWebview.obtainFrameView(), TitleNViewUtil.getTitleNViewId(this.mAdaWebview.obtainFrameView()));
if (titleNView instanceof ITitleNView) {
if (this.mTitleNViewProgressStop != null) {
TitleNViewUtil.stopProcess((ITitleNView) titleNView);
this.mAdaWebview.obtainWindowView().removeCallbacks(this.mTitleNViewProgressStop);
this.mTitleNViewProgressStop = null;
}
this.mTitleNViewProgressStop = new TitleNViewProgressStop(this.mAdaWebview);
TitleNViewUtil.startProcess((ITitleNView) titleNView);
this.mAdaWebview.obtainWindowView().postDelayed(this.mTitleNViewProgressStop, 6000L);
}
if (PdrUtil.isEmpty(this.mdcloudwebviewclientlister)) {
return;
}
this.mdcloudwebviewclientlister.onPageStarted(webView, str, bitmap);
}
public void onPreloadJSContent(WebView webView, String str, String str2) {
if (this.mAdaWebview.obtainFrameView().obtainApp() == null || this.mAdaWebview.obtainFrameView().obtainApp().manifestBeParsed()) {
AdaWebview adaWebview = this.mAdaWebview;
if (adaWebview.mPreloadJsLoaded) {
Logger.i(TAG, "mPreloadJs 已经提前注入JS完成。不需要再注入了" + this.mAdaWebview.getOriginalUrl());
return;
}
String preLoadJsString = adaWebview.getPreLoadJsString();
if (PdrUtil.isEmpty(preLoadJsString)) {
return;
}
this.mAdaWebview.mPreloadJsLoading = true;
Logger.i(TAG, " tag=" + str2 + ";url=" + str);
completeLoadJs(webView, str, str2, new String[]{preLoadJsString}, IF_PRELOAD_TEMPLATE, this.mAdaWebview.mPreloadJsFile);
this.mAdaWebview.mPreloadJsLoaded = true;
}
}
@Override
public void onReceivedError(WebView webView, int i, String str, final String str2) {
if (this.mAdaWebview == null) {
return;
}
Logger.e(TAG, "onReceivedError description=" + str + ";failingUrl=" + str2 + ";errorCode=" + i);
this.mAdaWebview.dispatchWebviewStateEvent(5, str);
AdaWebview adaWebview = this.mAdaWebview;
adaWebview.mFrameView.dispatchFrameViewEvents(AbsoluteConst.EVENTS_FAILED, adaWebview);
AdaWebview adaWebview2 = this.mAdaWebview;
adaWebview2.hasErrorPage = true;
adaWebview2.errorPageUrl = str2;
final IApp obtainApp = adaWebview2.mFrameView.obtainApp();
if (obtainApp != null) {
try {
if (BaseInfo.isWap2AppAppid(obtainApp.obtainAppId()) && this.mAdaWebview.mFrameView.getFrameType() == 2 && !TextUtils.equals("none", obtainApp.obtainConfigProperty("launchError"))) {
Context context = this.mAdaWebview.getContext();
final AlertDialog create = new AlertDialog.Builder(context).create();
create.setTitle(R.string.dcloud_common_tips);
create.setCanceledOnTouchOutside(false);
create.setMessage(context.getString(R.string.dcloud_common_no_network_tips));
DialogInterface.OnClickListener onClickListener = new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i2) {
if (i2 == -2) {
WebLoadEvent.this.mAdaWebview.getActivity().startActivity(new Intent("android.settings.SETTINGS"));
} else if (i2 == -3) {
Logger.e(WebLoadEvent.TAG, "onReceivedError try again");
DCloudAdapterUtil.getIActivityHandler(WebLoadEvent.this.mAdaWebview.getActivity());
WebLoadEvent.this.mAdaWebview.loadUrl(str2);
} else if (i2 == -1) {
Activity activity = WebLoadEvent.this.mAdaWebview.getActivity();
DCloudAdapterUtil.getIActivityHandler(activity).updateParam("closewebapp", activity);
}
create.dismiss();
}
};
create.setOnKeyListener(new DialogInterface.OnKeyListener() {
@Override
public boolean onKey(DialogInterface dialogInterface, int i2, KeyEvent keyEvent) {
if (i2 == 4) {
create.dismiss();
Activity activity = WebLoadEvent.this.mAdaWebview.getActivity();
DCloudAdapterUtil.getIActivityHandler(activity).updateParam("closewebapp", activity);
return false;
}
return false;
}
});
create.setButton(-2, context.getString(R.string.dcloud_common_set_network), onClickListener);
create.setButton(-3, context.getString(R.string.dcloud_common_retry), onClickListener);
create.setButton(-1, context.getString(R.string.dcloud_common_exit), onClickListener);
create.show();
obtainApp.registerSysEventListener(new ISysEventListener() {
@Override
public boolean onExecute(ISysEventListener.SysEventType sysEventType, Object obj) {
AdaWebview adaWebview3;
if (ISysEventListener.SysEventType.onResume != sysEventType || (adaWebview3 = WebLoadEvent.this.mAdaWebview) == null) {
return false;
}
adaWebview3.obtainMainView().postDelayed(new Runnable() {
@Override
public void run() {
Logger.e(WebLoadEvent.TAG, "onReceivedError 500ms retry after the onResume");
DCloudAdapterUtil.getIActivityHandler(WebLoadEvent.this.mAdaWebview.getActivity());
AnonymousClass5 anonymousClass5 = AnonymousClass5.this;
WebLoadEvent.this.mAdaWebview.loadUrl(str2);
}
}, 500L);
obtainApp.unregisterSysEventListener(this, sysEventType);
return false;
}
}, ISysEventListener.SysEventType.onResume);
Logger.e(TAG, "onReceivedError do clearHistory");
this.mAdaWebview.clearHistory();
} else {
String errorPage = getErrorPage();
if (!"none".equals(errorPage)) {
Logger.e(TAG, "onReceivedError load errorPage " + errorPage);
this.mAdaWebview.loadUrl(errorPage);
} else {
this.mAdaWebview.hasErrorPage = false;
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
if (PdrUtil.isEmpty(this.mdcloudwebviewclientlister)) {
return;
}
this.mdcloudwebviewclientlister.onReceivedError(webView, i, str, str2);
}
@Override
public void onReceivedSslError(WebView webView, final SslErrorHandler sslErrorHandler, final SslError sslError) {
AdaWebview adaWebview = this.mAdaWebview;
if (adaWebview == null || adaWebview.obtainApp() == null) {
return;
}
String obtainConfigProperty = this.mAdaWebview.obtainApp().obtainConfigProperty(IApp.ConfigProperty.CONFIG_UNTRUSTEDCA);
Logger.i("onReceivedSslError", "onReceivedSslError++type====" + obtainConfigProperty);
if (PdrUtil.isEquals(obtainConfigProperty, "refuse")) {
sslErrorHandler.cancel();
} else if (PdrUtil.isEquals(obtainConfigProperty, "warning")) {
Context context = webView.getContext();
final AlertDialog create = new AlertDialog.Builder(context).create();
create.setIcon(17301601);
create.setTitle(R.string.dcloud_common_safety_warning);
create.setCanceledOnTouchOutside(false);
String url = Build.VERSION.SDK_INT >= 14 ? sslError.getUrl() : null;
String string = context.getString(R.string.dcloud_common_certificate_continue);
if (!TextUtils.isEmpty(url)) {
string = url + "\n" + string;
}
create.setMessage(string);
DialogInterface.OnClickListener onClickListener = new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
if (i == -2) {
create.cancel();
create.dismiss();
} else if (i == -3) {
sslError.getCertificate().getIssuedBy();
} else if (i == -1) {
WebViewFactory.setSslHandlerState(sslErrorHandler, 1);
create.dismiss();
}
}
};
create.setButton(-2, context.getResources().getString(17039360), onClickListener);
create.setButton(-1, context.getResources().getString(17039370), onClickListener);
create.show();
} else {
WebViewFactory.setSslHandlerState(sslErrorHandler, 1);
}
if (PdrUtil.isEmpty(this.mdcloudwebviewclientlister)) {
return;
}
this.mdcloudwebviewclientlister.onReceivedSslError(webView, sslErrorHandler, sslError);
}
@Override
public void onUnhandledKeyEvent(WebView webView, KeyEvent keyEvent) {
super.onUnhandledKeyEvent(webView, keyEvent);
if (webView instanceof SysWebView) {
SysWebView sysWebView = (SysWebView) webView;
if (keyEvent.getAction() == 0) {
sysWebView.doKeyDownAction(keyEvent.getKeyCode(), keyEvent);
} else if (keyEvent.getAction() == 1) {
sysWebView.doKeyUpAction(keyEvent.getKeyCode(), keyEvent);
}
}
}
public void onUpdatePlusData(WebView webView, String str, String str2) {
AdaWebview adaWebview = this.mAdaWebview;
adaWebview.executeScript(adaWebview.getScreenAndDisplayJson(adaWebview));
onExecuteEvalJSStatck(webView, str, str2);
}
public void reset() {
this.mPlusJS = "(function(){/*console.log('all.js loading href=' + location.href);*/if(location.__page__load__over__){return 2}if(!location.__plusready__){location.__plusready__=true;return 1}else{return 2}return 0})();\n" + this.mAdaWebview.mFrameView.obtainPrePlusreadyJs() + "\n" + DIFFERENT_VERSION_JS;
}
public void setDcloudwebviewclientListener(IDCloudWebviewClientListener iDCloudWebviewClientListener) {
this.mdcloudwebviewclientlister = iDCloudWebviewClientListener;
}
public void setPageFinishedCallack(OnPageFinishedCallack onPageFinishedCallack) {
this.mPageFinishedCallack = onPageFinishedCallack;
}
@Override
public WebResourceResponse shouldInterceptRequest(WebView webView, String str) {
String str2;
JSONObject jSONObject;
String str3;
File file;
File file2;
if (this.mAdaWebview == null) {
return null;
}
WebResourceResponse shouldInterceptRequest = super.shouldInterceptRequest(webView, str);
WebResourceResponse shouldInterceptRequest2 = super.shouldInterceptRequest(webView, str);
if (!PdrUtil.isEmpty(this.mdcloudwebviewclientlister)) {
shouldInterceptRequest2 = this.mdcloudwebviewclientlister.shouldInterceptRequest(webView, str);
}
WebResourceResponse checkWebResourceResponseRedirect = checkWebResourceResponseRedirect(webView, str);
if (checkWebResourceResponseRedirect != null) {
return checkWebResourceResponseRedirect;
}
String str4 = "image/gif";
if (!PdrUtil.isEmpty(str)) {
if (str.startsWith("plusfile://")) {
String replace = str.replace("plusfile://", "");
if (!replace.startsWith(BaseInfo.REL_PUBLIC_DOWNLOADS_DIR) && !replace.startsWith(BaseInfo.REL_PRIVATE_DOC_DIR) && !replace.startsWith(BaseInfo.REL_PUBLIC_DOCUMENTS_DIR)) {
file2 = new File(replace);
} else {
String convert2WebviewFullPath = this.mAdaWebview.obtainApp().convert2WebviewFullPath(null, replace);
if (convert2WebviewFullPath.startsWith("file:///")) {
convert2WebviewFullPath = convert2WebviewFullPath.substring(7);
}
if (convert2WebviewFullPath.startsWith(DeviceInfo.FILE_PROTOCOL)) {
convert2WebviewFullPath = convert2WebviewFullPath.substring(6);
}
file2 = new File(convert2WebviewFullPath);
}
if (file2.exists()) {
try {
FileInputStream fileInputStream = new FileInputStream(file2);
String mimeType = PdrUtil.getMimeType(str);
if (str.contains(".jpg")) {
mimeType = "image/jpeg";
} else if (str.contains(".png")) {
mimeType = "image/png";
} else if (str.contains(".gif")) {
mimeType = "image/gif";
}
return new WebResourceResponse(mimeType, null, fileInputStream);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
} else if (str.contains("h5pscript://")) {
InputStream encryptionInputStream = WebResUtil.getEncryptionInputStream(str.substring(str.indexOf("h5pscript://") + 12), this.mAdaWebview.obtainApp());
String mimeType2 = PdrUtil.getMimeType(str);
if (encryptionInputStream != null) {
if (str.contains(".jpg")) {
str4 = "image/jpeg";
} else if (str.contains(".png")) {
str4 = "image/png";
} else if (!str.contains(".gif")) {
str4 = mimeType2;
}
return new WebResourceResponse(str4, null, encryptionInputStream);
}
} else if (str.startsWith("plus-confusion://")) {
InputStream encryptionInputStream2 = WebResUtil.getEncryptionInputStream(this.mAdaWebview.obtainApp().convert2WebviewFullPath(this.mAdaWebview.obtainFullUrl(), str.substring(17)), this.mAdaWebview.obtainApp());
String mimeType3 = PdrUtil.getMimeType(str);
if (encryptionInputStream2 != null) {
return new WebResourceResponse(mimeType3, null, encryptionInputStream2);
}
}
}
if (ImageLoaderUtil.isDownload(str) && (file = ImageLoaderL.getInstance().getDiscCache().get(str)) != null && file.exists()) {
String mimeType4 = PdrUtil.getMimeType(str);
if (str.contains(".jpg")) {
str4 = "image/jpeg";
} else if (str.contains(".png")) {
str4 = "image/png";
} else if (!str.contains(".gif")) {
str4 = mimeType4;
}
try {
return new WebResourceResponse(str4, null, new FileInputStream(file));
} catch (FileNotFoundException e2) {
e2.printStackTrace();
}
}
AdaWebview adaWebview = this.mAdaWebview;
AdaWebview.OverrideResourceRequestItem checkResourceRequestUrl = adaWebview != null ? adaWebview.checkResourceRequestUrl(str) : null;
AdaWebview adaWebview2 = this.mAdaWebview;
if (adaWebview2 == null) {
return shouldInterceptRequest;
}
String str5 = adaWebview2.mEncoding;
if (checkResourceRequestUrl != null) {
str = checkResourceRequestUrl.redirect;
str5 = checkResourceRequestUrl.encoding;
str2 = checkResourceRequestUrl.mime;
} else {
str2 = "application/x-javascript";
}
try {
Logger.i(TAG, "shouldInterceptRequest url=" + str + ";withJs=" + this.mAdaWebview.mInjectPlusWidthJs);
shouldInterceptRequest = handleDecode(str, shouldInterceptRequest);
if (shouldInterceptRequest == null) {
if (this.mAdaWebview.mPlusrequire.equals("ahead") && this.mAdaWebview.hasPreLoadJsFile() && (((str3 = this.mAdaWebview.mInjectPlusWidthJs) == null || TextUtils.equals(str3, str)) && PdrUtil.isNetPath(str) && checkJsFile(str))) {
shouldInterceptRequest = downloadResponseInjection(shouldInterceptRequest, str, str2, str5, this.TYPE_JS);
if (shouldInterceptRequest != null) {
this.mAdaWebview.mInjectPlusWidthJs = str;
}
} else if (!TextUtils.isEmpty(this.mAdaWebview.getCssString()) && !this.mAdaWebview.mIsAdvanceCss && PdrUtil.isNetPath(str) && checkCssFile(str)) {
str2 = "text/css";
shouldInterceptRequest = downloadResponseInjection(shouldInterceptRequest, str, "text/css", str5, this.TYPE_CSS);
} else if (this.isInitAmapGEO) {
AdaWebview adaWebview3 = this.mAdaWebview;
if (!adaWebview3.mInjectGeoLoaded && DLGeolocation.checkInjectGeo(adaWebview3.mInjectGEO)) {
shouldInterceptRequest = downloadResponseInjection(shouldInterceptRequest, str, str2, str5, this.TYPE_JS);
}
}
}
if (shouldInterceptRequest == null && !BaseInfo.isWap2AppAppid(this.mAppid) && PLUSREADY.equals(str) && !this.mAdaWebview.mPlusLoaded) {
shouldInterceptRequest = downloadResponseInjection(shouldInterceptRequest, str, str2, str5, this.TYPE_JS);
}
if (shouldInterceptRequest == null) {
BaseInfo.isUniAppAppid(this.mAdaWebview.obtainApp());
}
if (shouldInterceptRequest == null && checkResourceRequestUrl != null) {
try {
shouldInterceptRequest = new WebResourceResponse(str2, str5, new FileInputStream(str));
} catch (FileNotFoundException e3) {
e3.printStackTrace();
}
}
if (shouldInterceptRequest != null && Build.VERSION.SDK_INT >= 21) {
Map<String, String> responseHeaders = shouldInterceptRequest.getResponseHeaders();
if (responseHeaders == null) {
responseHeaders = new HashMap<>();
}
responseHeaders.put("Access-Control-Allow-Credentials", AbsoluteConst.TRUE);
responseHeaders.put("Access-Control-Allow-Methods", "GET, POST, OPTIONS");
responseHeaders.put("Access-Control-Allow-Origin", "*");
if (checkResourceRequestUrl != null && (jSONObject = checkResourceRequestUrl.headerJson) != null) {
Iterator<String> keys = jSONObject.keys();
if (checkResourceRequestUrl.headerJson.length() > 0) {
while (keys.hasNext()) {
String next = keys.next();
responseHeaders.put(next, checkResourceRequestUrl.headerJson.opt(next).toString());
}
}
}
shouldInterceptRequest.setResponseHeaders(responseHeaders);
return shouldInterceptRequest;
}
} catch (Exception e4) {
e4.printStackTrace();
Logger.e(this.mAppid + ";url=" + str);
}
return (PdrUtil.isEmpty(this.mdcloudwebviewclientlister) || PdrUtil.isEmpty(shouldInterceptRequest2)) ? shouldInterceptRequest : shouldInterceptRequest2;
}
@Override
public boolean shouldOverrideKeyEvent(WebView webView, KeyEvent keyEvent) {
return false;
}
@Override
public boolean shouldOverrideUrlLoading(WebView webView, String str) {
if (this.mAdaWebview == null) {
return false;
}
Logger.e(TAG, "shouldOverrideUrlLoading url=" + str);
AdaWebview adaWebview = this.mAdaWebview;
adaWebview.mProgressIntValue = 0;
adaWebview.mRecordLastUrl = str;
if (adaWebview.checkOverrideUrl(str)) {
Logger.e(TAG, "检测拦截回调shouldOverrideUrlLoading url=" + str);
AdaFrameView adaFrameView = this.mAdaWebview.mFrameView;
adaFrameView.dispatchFrameViewEvents(AbsoluteConst.EVENTS_OVERRIDE_URL_LOADING, "{url:'" + str + "'}");
return true;
}
if (this.mAdaWebview.mFrameView.getFrameType() == 5 || (this.mAdaWebview.mFrameView.getFrameType() == 2 && directPageIsLaunchPage(this.mAdaWebview.obtainApp()))) {
this.mAdaWebview.obtainApp().updateDirectPage(str);
}
if (!shouldRuntimeHandle(str) && this.mAdaWebview.mFrameView.getFrameType() != 6) {
try {
if (str.startsWith("sms:")) {
int indexOf = str.indexOf("sms:");
int indexOf2 = str.indexOf(Operators.CONDITION_IF_STRING);
if (indexOf2 == -1) {
this.mAdaWebview.getActivity().startActivity(new Intent("android.intent.action.VIEW", Uri.parse(str)));
return true;
}
String substring = str.substring(indexOf + 4, indexOf2);
String substring2 = str.substring(indexOf2 + 1);
Intent intent = new Intent("android.intent.action.VIEW", Uri.parse("sms:" + substring));
intent.putExtra("address", substring);
intent.putExtra("sms_body", substring2);
this.mAdaWebview.getActivity().startActivity(intent);
} else if (str.startsWith("intent://")) {
Intent parseUri = Intent.parseUri(str, 1);
parseUri.addCategory("android.intent.category.BROWSABLE");
parseUri.setComponent(null);
if (Build.VERSION.SDK_INT >= 15) {
parseUri.setSelector(null);
}
if (this.mAdaWebview.getActivity().getPackageManager().queryIntentActivities(parseUri, 0).size() > 0) {
this.mAdaWebview.getActivity().startActivityIfNeeded(parseUri, -1);
}
} else {
AdaWebview adaWebview2 = this.mAdaWebview;
if (adaWebview2 != null && adaWebview2.getActivity() != null && this.mAdaWebview.obtainApp().checkSchemeWhite(str)) {
this.mAdaWebview.getActivity().startActivity(new Intent("android.intent.action.VIEW", Uri.parse(str)));
}
}
} catch (Exception unused) {
Logger.e(TAG, "ActivityNotFoundException url=" + str);
}
return true;
} else if (PdrUtil.isEmpty(this.mdcloudwebviewclientlister)) {
return false;
} else {
return this.mdcloudwebviewclientlister.shouldOverrideUrlLoading(webView, str);
}
}
private WebResourceResponse downloadResponse(WebView webView, String str, String str2, WebResourceResponse webResourceResponse, File file, boolean z) {
HttpURLConnection httpURLConnection;
int responseCode;
if (!URLUtil.isNetworkUrl(str2) || file == null) {
return webResourceResponse;
}
showLoading();
HttpURLConnection httpURLConnection2 = null;
try {
try {
httpURLConnection = (HttpURLConnection) new URL(str2).openConnection();
} catch (Throwable th) {
th = th;
}
} catch (Exception e) {
e = e;
}
try {
httpURLConnection.setConnectTimeout(BaseImageDownloader.DEFAULT_HTTP_CONNECT_TIMEOUT);
httpURLConnection.setReadTimeout(BaseImageDownloader.DEFAULT_HTTP_CONNECT_TIMEOUT);
httpURLConnection.setRequestMethod("GET");
httpURLConnection.setDoInput(true);
responseCode = httpURLConnection.getResponseCode();
} catch (Exception e2) {
e = e2;
httpURLConnection2 = httpURLConnection;
e.printStackTrace();
if (httpURLConnection2 != null) {
httpURLConnection2.disconnect();
}
hideLoading();
httpURLConnection2 = str;
return handleDecode(str, webResourceResponse);
} catch (Throwable th2) {
th = th2;
httpURLConnection2 = httpURLConnection;
if (httpURLConnection2 != null) {
httpURLConnection2.disconnect();
}
hideLoading();
throw th;
}
if (responseCode != 200 && responseCode != 206) {
if ((responseCode < 400 || responseCode >= 500) && z) {
downloadResponse(webView, str, str2, webResourceResponse, file, false);
} else {
hideLoading();
}
httpURLConnection.disconnect();
hideLoading();
httpURLConnection2 = str;
return handleDecode(str, webResourceResponse);
}
if (DHFile.writeFile(httpURLConnection.getInputStream(), file.getAbsolutePath())) {
hideLoading();
} else if (z) {
downloadResponse(webView, str, str2, webResourceResponse, file, false);
} else {
hideLoading();
}
httpURLConnection.disconnect();
hideLoading();
httpURLConnection2 = str;
return handleDecode(str, webResourceResponse);
}
}