畅玩新葡京 v8.2.8版本的 MD5 值为:1e36e0a7adef719a26e0a466b52c398d
以下内容为反编译后的 Cocos2dxWebView.java 源代码,内容仅作参考
package org.cocos2dx.lib;
import android.annotation.SuppressLint;
import android.content.Context;
import android.text.TextUtils;
import android.util.Log;
import android.webkit.WebChromeClient;
import android.webkit.WebResourceRequest;
import android.webkit.WebResourceResponse;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.FrameLayout;
import java.net.URI;
import java.util.concurrent.CountDownLatch;
public class Cocos2dxWebView extends WebView {
private static final String TAG = Cocos2dxWebViewHelper.class.getSimpleName();
private String mJSScheme;
private int mViewTag;
class Cocos2dxWebViewClient extends WebViewClient {
Cocos2dxWebViewClient() {
}
@Override
public void onPageFinished(WebView webView, final String str) {
super.onPageFinished(webView, str);
((Cocos2dxActivity) Cocos2dxWebView.this.getContext()).runOnGLThread(new Runnable() {
@Override
public void run() {
Cocos2dxWebViewHelper._didFinishLoading(Cocos2dxWebView.this.mViewTag, str);
}
});
}
@Override
public void onReceivedError(WebView webView, int i, String str, final String str2) {
super.onReceivedError(webView, i, str, str2);
((Cocos2dxActivity) Cocos2dxWebView.this.getContext()).runOnGLThread(new Runnable() {
@Override
public void run() {
Cocos2dxWebViewHelper._didFailLoading(Cocos2dxWebView.this.mViewTag, str2);
}
});
}
@Override
public WebResourceResponse shouldInterceptRequest(WebView webView, WebResourceRequest webResourceRequest) {
WebResourceResponse shouldInterceptRequest = super.shouldInterceptRequest(webView, webResourceRequest);
if (webResourceRequest.getUrl() == null || webResourceRequest.getUrl().getPath() == null) {
return shouldInterceptRequest;
}
if (webResourceRequest.getUrl().getPath().contains("vcaptcha10.js") || webResourceRequest.getUrl().getPath().contains("vcaptcha20.js")) {
Log.e("WEBVIEW", "getUrl=>" + webResourceRequest.getUrl().toString());
try {
String path = webResourceRequest.getUrl().getPath();
return new WebResourceResponse("application/x-javascript", "UTF-8", Cocos2dxWebView.this.getContext().getAssets().open(path.subSequence(1, path.length()).toString()));
} catch (Exception e) {
Log.e("WEBVIEW", e.toString());
return shouldInterceptRequest;
}
}
return shouldInterceptRequest;
}
@Override
public boolean shouldOverrideUrlLoading(WebView webView, final String str) {
Cocos2dxActivity cocos2dxActivity = (Cocos2dxActivity) Cocos2dxWebView.this.getContext();
if (!TextUtils.isEmpty(str) && str.contains("www.baidu.com")) {
Cocos2dxWebView.this.loadUrl("javascript:document.location = 'custom://exit';");
}
try {
URI create = URI.create(str);
if (create != null && create.getScheme().equals(Cocos2dxWebView.this.mJSScheme)) {
cocos2dxActivity.runOnGLThread(new Runnable() {
@Override
public void run() {
Cocos2dxWebViewHelper._onJsCallback(Cocos2dxWebView.this.mViewTag, str);
}
});
return true;
}
} catch (Exception unused) {
Log.d(Cocos2dxWebView.TAG, "Fail ed to create URI from url");
}
boolean[] zArr = {true};
CountDownLatch countDownLatch = new CountDownLatch(1);
cocos2dxActivity.runOnGLThread(new ShouldStartLoadingWorker(countDownLatch, zArr, Cocos2dxWebView.this.mViewTag, str));
try {
countDownLatch.await();
} catch (InterruptedException unused2) {
Log.d(Cocos2dxWebView.TAG, "'shouldOverrideUrlLoading' failed");
}
return zArr[0];
}
}
public Cocos2dxWebView(Context context) {
this(context, -1);
}
@SuppressLint({"SetJavaScriptEnabled"})
public Cocos2dxWebView(Context context, int i) {
super(context);
this.mViewTag = i;
this.mJSScheme = "";
setFocusable(true);
setFocusableInTouchMode(true);
getSettings().setSupportZoom(false);
getSettings().setDomStorageEnabled(true);
getSettings().setJavaScriptEnabled(true);
getSettings().setAllowContentAccess(true);
getSettings().setAllowFileAccess(true);
getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
try {
getClass().getMethod("removeJavascriptInterface", String.class).invoke(this, "searchBoxJavaBridge_");
} catch (Exception unused) {
Log.d(TAG, "This API level do not support `removeJavascriptInterface`");
}
setWebViewClient(new Cocos2dxWebViewClient());
setWebChromeClient(new WebChromeClient());
setBackgroundColor(0);
}
public void setJavascriptInterfaceScheme(String str) {
if (str == null) {
str = "";
}
this.mJSScheme = str;
}
public void setScalesPageToFit(boolean z) {
getSettings().setSupportZoom(z);
}
public void setWebViewRect(int i, int i2, int i3, int i4) {
FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(-1, -1);
layoutParams.leftMargin = i;
layoutParams.topMargin = i2;
layoutParams.width = i3;
layoutParams.height = i4;
setLayoutParams(layoutParams);
}
}