그늘 v4.6.9版本的 MD5 值为:45bd3dac9e441bb87fea09c92b437adc
以下内容为反编译后的 AgentWebView.java 源代码,内容仅作参考
package com.just.agentweb;
import a1.i;
import android.annotation.TargetApi;
import android.content.Context;
import android.graphics.Bitmap;
import android.util.AttributeSet;
import android.util.Log;
import android.util.Pair;
import android.view.ViewGroup;
import android.view.accessibility.AccessibilityManager;
import android.webkit.JsPromptResult;
import android.webkit.WebBackForwardList;
import android.webkit.WebView;
import android.widget.Toast;
import androidx.appcompat.widget.d;
import androidx.constraintlayout.motion.utils.a;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;
import org.json.JSONObject;
public class AgentWebView extends LollipopFixedWebView {
private static final String TAG = "AgentWebView";
private FixedOnReceivedTitle mFixedOnReceivedTitle;
private Map<String, String> mInjectJavaScripts;
private Boolean mIsAccessibilityEnabledOriginal;
private boolean mIsInited;
private Map<String, JsCallJava> mJsCallJavas;
public static class AgentWebChrome extends MiddlewareWebChromeBase {
private AgentWebView mAgentWebView;
private AgentWebChrome(AgentWebView agentWebView) {
this.mAgentWebView = agentWebView;
}
@Override
public boolean onJsPrompt(WebView webView, String str, String str2, String str3, JsPromptResult jsPromptResult) {
JsCallJava jsCallJava;
String str4 = AgentWebView.TAG;
StringBuilder q = a.q("onJsPrompt:", str, " message:", str2, " d:");
q.append(str3);
q.append(" ");
Log.i(str4, q.toString());
if (this.mAgentWebView.mJsCallJavas != null && JsCallJava.isSafeWebViewCallMsg(str2)) {
JSONObject msgJSONObject = JsCallJava.getMsgJSONObject(str2);
String interfacedName = JsCallJava.getInterfacedName(msgJSONObject);
if (interfacedName != null && (jsCallJava = (JsCallJava) this.mAgentWebView.mJsCallJavas.get(interfacedName)) != null) {
jsPromptResult.confirm(jsCallJava.call(webView, msgJSONObject));
return true;
}
return true;
}
return super.onJsPrompt(webView, str, str2, str3, jsPromptResult);
}
@Override
public void onProgressChanged(WebView webView, int i) {
if (this.mAgentWebView.mJsCallJavas != null) {
this.mAgentWebView.injectJavaScript();
if (LogUtils.isDebug()) {
String str = AgentWebView.TAG;
StringBuilder i10 = d.i("injectJavaScript, onProgressChanged.newProgress = ", i, ", url = ");
i10.append(webView.getUrl());
Log.d(str, i10.toString());
}
}
if (this.mAgentWebView.mInjectJavaScripts != null) {
this.mAgentWebView.injectExtraJavaScript();
}
super.onProgressChanged(webView, i);
}
@Override
public void onReceivedTitle(WebView webView, String str) {
this.mAgentWebView.mFixedOnReceivedTitle.onReceivedTitle();
super.onReceivedTitle(webView, str);
}
}
public static class AgentWebClient extends MiddlewareWebClientBase {
private AgentWebView mAgentWebView;
private AgentWebClient(AgentWebView agentWebView) {
this.mAgentWebView = agentWebView;
}
@Override
public void onPageFinished(WebView webView, String str) {
super.onPageFinished(webView, str);
this.mAgentWebView.mFixedOnReceivedTitle.onPageFinished(webView);
if (LogUtils.isDebug()) {
String str2 = AgentWebView.TAG;
Log.d(str2, "onPageFinished.url = " + webView.getUrl());
}
}
@Override
public void onPageStarted(WebView webView, String str, Bitmap bitmap) {
super.onPageStarted(webView, str, bitmap);
if (this.mAgentWebView.mJsCallJavas != null) {
this.mAgentWebView.injectJavaScript();
if (LogUtils.isDebug()) {
String str2 = AgentWebView.TAG;
Log.d(str2, "injectJavaScript, onPageStarted.url = " + webView.getUrl());
}
}
if (this.mAgentWebView.mInjectJavaScripts != null) {
this.mAgentWebView.injectExtraJavaScript();
}
this.mAgentWebView.mFixedOnReceivedTitle.onPageStarted();
this.mAgentWebView.fixedAccessibilityInjectorExceptionForOnPageFinished(str);
}
}
public static class FixedOnReceivedTitle {
private boolean mIsOnReceivedTitle;
private android.webkit.WebChromeClient mWebChromeClient;
private FixedOnReceivedTitle() {
}
public void onPageFinished(WebView webView) {
WebBackForwardList webBackForwardList;
if (!this.mIsOnReceivedTitle && this.mWebChromeClient != null) {
try {
webBackForwardList = webView.copyBackForwardList();
} catch (NullPointerException e10) {
if (LogUtils.isDebug()) {
e10.printStackTrace();
}
webBackForwardList = null;
}
if (webBackForwardList != null && webBackForwardList.getSize() > 0 && webBackForwardList.getCurrentIndex() >= 0 && webBackForwardList.getItemAtIndex(webBackForwardList.getCurrentIndex()) != null) {
this.mWebChromeClient.onReceivedTitle(webView, webBackForwardList.getItemAtIndex(webBackForwardList.getCurrentIndex()).getTitle());
}
}
}
public void onPageStarted() {
this.mIsOnReceivedTitle = false;
}
public void onReceivedTitle() {
this.mIsOnReceivedTitle = true;
}
public void setWebChromeClient(android.webkit.WebChromeClient webChromeClient) {
this.mWebChromeClient = webChromeClient;
}
}
public AgentWebView(Context context) {
this(context, null);
}
private void fixedStillAttached() {
if (getParent() instanceof ViewGroup) {
((ViewGroup) getParent()).removeAllViewsInLayout();
}
}
public void injectExtraJavaScript() {
for (Map.Entry<String, String> entry : this.mInjectJavaScripts.entrySet()) {
loadUrl(buildNotRepeatInjectJS(entry.getKey(), entry.getValue()));
}
}
public void injectJavaScript() {
for (Map.Entry<String, JsCallJava> entry : this.mJsCallJavas.entrySet()) {
loadUrl(buildNotRepeatInjectJS(entry.getKey(), entry.getValue().getPreloadInterfaceJs()));
}
}
private boolean isAccessibilityEnabled() {
return ((AccessibilityManager) getContext().getSystemService("accessibility")).isEnabled();
}
public static Pair<Boolean, String> isWebViewPackageException(Throwable th2) {
String th3;
if (th2.getCause() == null) {
th3 = th2.toString();
} else {
th3 = th2.getCause().toString();
}
String stackTraceString = Log.getStackTraceString(th2);
if (!stackTraceString.contains("android.content.pm.PackageManager$NameNotFoundException") && !stackTraceString.contains("java.lang.RuntimeException: Cannot load WebView") && !stackTraceString.contains("android.webkit.WebViewFactory$MissingWebViewPackageException: Failed to load WebView provider: No WebView installed")) {
return new Pair<>(Boolean.FALSE, th3);
}
LogUtils.safeCheckCrash(TAG, "isWebViewPackageException", th2);
return new Pair<>(Boolean.TRUE, androidx.appcompat.graphics.drawable.a.h("WebView load failed, ", th3));
}
private void releaseConfigCallback() {
}
private void resetAccessibilityEnabled() {
Boolean bool = this.mIsAccessibilityEnabledOriginal;
if (bool != null) {
setAccessibilityEnabled(bool.booleanValue());
}
}
private void setAccessibilityEnabled(boolean z10) {
AccessibilityManager accessibilityManager = (AccessibilityManager) getContext().getSystemService("accessibility");
try {
Method declaredMethod = accessibilityManager.getClass().getDeclaredMethod("setAccessibilityState", Boolean.TYPE);
declaredMethod.setAccessible(true);
declaredMethod.invoke(accessibilityManager, Boolean.valueOf(z10));
declaredMethod.setAccessible(false);
} catch (Throwable th2) {
if (LogUtils.isDebug()) {
LogUtils.e(TAG, "setAccessibilityEnabled", th2);
}
}
}
public void addInjectJavaScript(String str) {
if (this.mInjectJavaScripts == null) {
this.mInjectJavaScripts = new HashMap();
}
this.mInjectJavaScripts.put(String.valueOf(str.hashCode()), str);
injectExtraJavaScript();
}
@Override
@Deprecated
public final void addJavascriptInterface(Object obj, String str) {
super.addJavascriptInterface(obj, str);
Log.i(TAG, "注入");
}
public void addJavascriptInterfaceSupport(Object obj, String str) {
}
public String buildNotRepeatInjectJS(String str, String str2) {
String format = String.format("__injectFlag_%1$s__", str);
StringBuilder q = a.q("javascript:try{(function(){if(window.", format, "){console.log('", format, " has been injected');return;}window.");
q.append(format);
q.append("=true;");
q.append(str2);
q.append("}())}catch(e){console.warn(e)}");
return q.toString();
}
public String buildTryCatchInjectJS(String str) {
return i.g("javascript:try{", str, "}catch(e){console.warn(e)}");
}
@Override
public void clearHistory() {
if (this.mIsInited) {
super.clearHistory();
}
}
@Override
public void destroy() {
setVisibility(8);
Map<String, JsCallJava> map = this.mJsCallJavas;
if (map != null) {
map.clear();
}
Map<String, String> map2 = this.mInjectJavaScripts;
if (map2 != null) {
map2.clear();
}
removeAllViewsInLayout();
fixedStillAttached();
releaseConfigCallback();
if (this.mIsInited) {
resetAccessibilityEnabled();
LogUtils.i(TAG, "destroy web");
super.destroy();
}
}
public void fixedAccessibilityInjectorException() {
}
public void fixedAccessibilityInjectorExceptionForOnPageFinished(String str) {
}
@Override
public boolean isPrivateBrowsingEnabled() {
return super.isPrivateBrowsingEnabled();
}
@TargetApi(11)
public boolean removeSearchBoxJavaBridge() {
return false;
}
@Override
public void setOverScrollMode(int i) {
try {
super.setOverScrollMode(i);
} catch (Throwable th2) {
Pair<Boolean, String> isWebViewPackageException = isWebViewPackageException(th2);
if (((Boolean) isWebViewPackageException.first).booleanValue()) {
Toast.makeText(getContext(), (CharSequence) isWebViewPackageException.second, 0).show();
destroy();
return;
}
throw th2;
}
}
@Override
public final void setWebChromeClient(android.webkit.WebChromeClient webChromeClient) {
AgentWebChrome agentWebChrome = new AgentWebChrome();
agentWebChrome.setDelegate(webChromeClient);
this.mFixedOnReceivedTitle.setWebChromeClient(webChromeClient);
super.setWebChromeClient(agentWebChrome);
setWebChromeClientSupport(agentWebChrome);
}
public final void setWebChromeClientSupport(android.webkit.WebChromeClient webChromeClient) {
}
@Override
public final void setWebViewClient(android.webkit.WebViewClient webViewClient) {
AgentWebClient agentWebClient = new AgentWebClient();
agentWebClient.setDelegate(webViewClient);
super.setWebViewClient(agentWebClient);
setWebViewClientSupport(agentWebClient);
}
public final void setWebViewClientSupport(android.webkit.WebViewClient webViewClient) {
}
@TargetApi(19)
public void trySetWebDebuggEnabled() {
if (LogUtils.isDebug()) {
try {
WebView.class.getMethod("setWebContentsDebuggingEnabled", Boolean.TYPE).invoke(null, Boolean.TRUE);
} catch (Throwable th2) {
if (LogUtils.isDebug()) {
th2.printStackTrace();
}
}
}
}
public AgentWebView(Context context, AttributeSet attributeSet) {
super(context, attributeSet);
removeSearchBoxJavaBridge();
this.mIsInited = true;
this.mFixedOnReceivedTitle = new FixedOnReceivedTitle();
}
}