pull/45/head
kunfei 5 years ago
parent cec6982764
commit cc0bbe5afa
  1. 37
      app/src/main/java/io/legado/app/help/http/AjaxWebView.kt

@ -60,7 +60,6 @@ class AjaxWebView {
webView.webViewClient = SnifferWebClient(params, handler) webView.webViewClient = SnifferWebClient(params, handler)
} else { } else {
webView.webViewClient = HtmlWebViewClient(params, handler) webView.webViewClient = HtmlWebViewClient(params, handler)
webView.addJavascriptInterface(JavaInjectMethod(handler), "OUTHTML")
} }
when (params.requestMethod) { when (params.requestMethod) {
RequestMethod.POST -> webView.postUrl(params.url, params.postData) RequestMethod.POST -> webView.postUrl(params.url, params.postData)
@ -94,16 +93,6 @@ class AjaxWebView {
mHandler.obtainMessage(DESTROY_WEB_VIEW) mHandler.obtainMessage(DESTROY_WEB_VIEW)
} }
class JavaInjectMethod(private val handler: Handler) {
@JavascriptInterface
fun processHTML(html: String) {
handler.obtainMessage(MSG_SUCCESS, html)
.sendToTarget()
}
}
class AjaxParams(val context: Context, private val tag: String) { class AjaxParams(val context: Context, private val tag: String) {
var requestMethod: RequestMethod? = null var requestMethod: RequestMethod? = null
get() { get() {
@ -118,9 +107,7 @@ class AjaxWebView {
private var audioSuffixList: List<String>? = null private var audioSuffixList: List<String>? = null
val userAgent: String? val userAgent: String?
get() = if (this.headerMap != null) { get() = this.headerMap?.get("User-Agent")
this.headerMap!!.get("User-Agent")
} else null
val isSniff: Boolean val isSniff: Boolean
get() = !TextUtils.isEmpty(audioSuffix) get() = !TextUtils.isEmpty(audioSuffix)
@ -192,15 +179,14 @@ class AjaxWebView {
private val handler: Handler private val handler: Handler
) : WebViewClient() { ) : WebViewClient() {
override fun onPageFinished(view: WebView, url: String) { override fun onPageFinished(view: WebView, url: String) {
params.setCookie(url) params.setCookie(url)
evaluateJavascript(view) handler.postDelayed({
view.evaluateJavascript("document.documentElement.outerHTML") {
handler.obtainMessage(MSG_SUCCESS, it)
.sendToTarget()
} }
}, 1000)
override fun onLoadResource(view: WebView, url: String) {
super.onLoadResource(view, url)
} }
override fun onReceivedError( override fun onReceivedError(
@ -232,17 +218,6 @@ class AjaxWebView {
override fun onReceivedSslError(view: WebView, handler: SslErrorHandler, error: SslError) { override fun onReceivedSslError(view: WebView, handler: SslErrorHandler, error: SslError) {
handler.proceed() handler.proceed()
} }
private fun evaluateJavascript(webView: WebView) {
val runnable = ScriptRunnable(webView, OUTER_HTML)
handler.postDelayed(runnable, 1000L)
}
companion object {
const val OUTER_HTML =
"window.OUTHTML.processHTML('<head>'+document.getElementsByTagName('html')[0].innerHTML+'</head>');"
}
} }
class SnifferWebClient( class SnifferWebClient(

Loading…
Cancel
Save