From cc0bbe5afaabf7057c375a3c91ba444146b78e21 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 3 Nov 2019 10:13:49 +0800 Subject: [PATCH] up --- .../io/legado/app/help/http/AjaxWebView.kt | 39 ++++--------------- 1 file changed, 7 insertions(+), 32 deletions(-) diff --git a/app/src/main/java/io/legado/app/help/http/AjaxWebView.kt b/app/src/main/java/io/legado/app/help/http/AjaxWebView.kt index 9adc7838c..1ade0e294 100644 --- a/app/src/main/java/io/legado/app/help/http/AjaxWebView.kt +++ b/app/src/main/java/io/legado/app/help/http/AjaxWebView.kt @@ -60,7 +60,6 @@ class AjaxWebView { webView.webViewClient = SnifferWebClient(params, handler) } else { webView.webViewClient = HtmlWebViewClient(params, handler) - webView.addJavascriptInterface(JavaInjectMethod(handler), "OUTHTML") } when (params.requestMethod) { RequestMethod.POST -> webView.postUrl(params.url, params.postData) @@ -94,16 +93,6 @@ class AjaxWebView { 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) { var requestMethod: RequestMethod? = null get() { @@ -118,9 +107,7 @@ class AjaxWebView { private var audioSuffixList: List? = null val userAgent: String? - get() = if (this.headerMap != null) { - this.headerMap!!.get("User-Agent") - } else null + get() = this.headerMap?.get("User-Agent") val isSniff: Boolean get() = !TextUtils.isEmpty(audioSuffix) @@ -192,15 +179,14 @@ class AjaxWebView { private val handler: Handler ) : WebViewClient() { - override fun onPageFinished(view: WebView, url: String) { params.setCookie(url) - evaluateJavascript(view) - } - - - override fun onLoadResource(view: WebView, url: String) { - super.onLoadResource(view, url) + handler.postDelayed({ + view.evaluateJavascript("document.documentElement.outerHTML") { + handler.obtainMessage(MSG_SUCCESS, it) + .sendToTarget() + } + }, 1000) } override fun onReceivedError( @@ -232,17 +218,6 @@ class AjaxWebView { override fun onReceivedSslError(view: WebView, handler: SslErrorHandler, error: SslError) { 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(''+document.getElementsByTagName('html')[0].innerHTML+'');" - } } class SnifferWebClient(