|
|
@ -1,7 +1,6 @@ |
|
|
|
package io.legado.app.help.http |
|
|
|
package io.legado.app.help.http |
|
|
|
|
|
|
|
|
|
|
|
import android.annotation.SuppressLint |
|
|
|
import android.annotation.SuppressLint |
|
|
|
import android.content.Context |
|
|
|
|
|
|
|
import android.net.http.SslError |
|
|
|
import android.net.http.SslError |
|
|
|
import android.os.Build |
|
|
|
import android.os.Build |
|
|
|
import android.os.Handler |
|
|
|
import android.os.Handler |
|
|
@ -9,6 +8,7 @@ import android.os.Looper |
|
|
|
import android.os.Message |
|
|
|
import android.os.Message |
|
|
|
import android.text.TextUtils |
|
|
|
import android.text.TextUtils |
|
|
|
import android.webkit.* |
|
|
|
import android.webkit.* |
|
|
|
|
|
|
|
import io.legado.app.App |
|
|
|
import java.lang.ref.WeakReference |
|
|
|
import java.lang.ref.WeakReference |
|
|
|
import java.util.* |
|
|
|
import java.util.* |
|
|
|
|
|
|
|
|
|
|
@ -49,7 +49,7 @@ class AjaxWebView { |
|
|
|
|
|
|
|
|
|
|
|
@SuppressLint("SetJavaScriptEnabled", "JavascriptInterface") |
|
|
|
@SuppressLint("SetJavaScriptEnabled", "JavascriptInterface") |
|
|
|
fun createAjaxWebView(params: AjaxParams, handler: Handler): WebView { |
|
|
|
fun createAjaxWebView(params: AjaxParams, handler: Handler): WebView { |
|
|
|
val webView = WebView(params.context.applicationContext) |
|
|
|
val webView = WebView(App.INSTANCE) |
|
|
|
val settings = webView.settings |
|
|
|
val settings = webView.settings |
|
|
|
settings.javaScriptEnabled = true |
|
|
|
settings.javaScriptEnabled = true |
|
|
|
settings.domStorageEnabled = true |
|
|
|
settings.domStorageEnabled = true |
|
|
@ -63,7 +63,7 @@ class AjaxWebView { |
|
|
|
} |
|
|
|
} |
|
|
|
when (params.requestMethod) { |
|
|
|
when (params.requestMethod) { |
|
|
|
RequestMethod.POST -> webView.postUrl(params.url, params.postData) |
|
|
|
RequestMethod.POST -> webView.postUrl(params.url, params.postData) |
|
|
|
RequestMethod.GET, RequestMethod.DEFAULT -> webView.loadUrl( |
|
|
|
RequestMethod.GET -> webView.loadUrl( |
|
|
|
params.url, |
|
|
|
params.url, |
|
|
|
params.headerMap |
|
|
|
params.headerMap |
|
|
|
) |
|
|
|
) |
|
|
@ -75,29 +75,24 @@ class AjaxWebView { |
|
|
|
mWebView?.destroy() |
|
|
|
mWebView?.destroy() |
|
|
|
mWebView = null |
|
|
|
mWebView = null |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fun ajax(params: AjaxParams) { |
|
|
|
fun load(params: AjaxParams) { |
|
|
|
|
|
|
|
if (params.audioSuffix != "") { |
|
|
|
|
|
|
|
mHandler.obtainMessage(MSG_SNIFF_START, params) |
|
|
|
|
|
|
|
.sendToTarget() |
|
|
|
|
|
|
|
} else { |
|
|
|
mHandler.obtainMessage(MSG_AJAX_START, params) |
|
|
|
mHandler.obtainMessage(MSG_AJAX_START, params) |
|
|
|
.sendToTarget() |
|
|
|
.sendToTarget() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fun sniff(params: AjaxParams) { |
|
|
|
|
|
|
|
mHandler.obtainMessage(MSG_SNIFF_START, params) |
|
|
|
|
|
|
|
.sendToTarget() |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fun destroyWebView() { |
|
|
|
fun destroyWebView() { |
|
|
|
mHandler.obtainMessage(DESTROY_WEB_VIEW) |
|
|
|
mHandler.obtainMessage(DESTROY_WEB_VIEW) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
class AjaxParams(val context: Context, private val tag: String) { |
|
|
|
class AjaxParams(private val tag: String) { |
|
|
|
var requestMethod: RequestMethod? = null |
|
|
|
var requestMethod = RequestMethod.GET |
|
|
|
get() { |
|
|
|
|
|
|
|
return field ?: RequestMethod.DEFAULT |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
var url: String? = null |
|
|
|
var url: String? = null |
|
|
|
var postData: ByteArray? = null |
|
|
|
var postData: ByteArray? = null |
|
|
|
var headerMap: Map<String, String>? = null |
|
|
|
var headerMap: Map<String, String>? = null |
|
|
@ -112,41 +107,6 @@ class AjaxWebView { |
|
|
|
val isSniff: Boolean |
|
|
|
val isSniff: Boolean |
|
|
|
get() = !TextUtils.isEmpty(audioSuffix) |
|
|
|
get() = !TextUtils.isEmpty(audioSuffix) |
|
|
|
|
|
|
|
|
|
|
|
fun requestMethod(method: RequestMethod): AjaxParams { |
|
|
|
|
|
|
|
this.requestMethod = method |
|
|
|
|
|
|
|
return this |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fun url(url: String): AjaxParams { |
|
|
|
|
|
|
|
this.url = url |
|
|
|
|
|
|
|
return this |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fun postData(postData: ByteArray): AjaxParams { |
|
|
|
|
|
|
|
this.postData = postData |
|
|
|
|
|
|
|
return this |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fun headerMap(headerMap: Map<String, String>): AjaxParams { |
|
|
|
|
|
|
|
this.headerMap = headerMap |
|
|
|
|
|
|
|
return this |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fun cookieStore(cookieStore: CookieStore): AjaxParams { |
|
|
|
|
|
|
|
this.cookieStore = cookieStore |
|
|
|
|
|
|
|
return this |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fun suffix(suffix: String): AjaxParams { |
|
|
|
|
|
|
|
this.audioSuffix = suffix |
|
|
|
|
|
|
|
return this |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fun javaScript(javaScript: String): AjaxParams { |
|
|
|
|
|
|
|
this.javaScript = javaScript |
|
|
|
|
|
|
|
return this |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fun setCookie(url: String) { |
|
|
|
fun setCookie(url: String) { |
|
|
|
if (cookieStore != null) { |
|
|
|
if (cookieStore != null) { |
|
|
|
val cookie = CookieManager.getInstance().getCookie(url) |
|
|
|
val cookie = CookieManager.getInstance().getCookie(url) |
|
|
@ -300,10 +260,6 @@ class AjaxWebView { |
|
|
|
const val DESTROY_WEB_VIEW = 4 |
|
|
|
const val DESTROY_WEB_VIEW = 4 |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
enum class RequestMethod { |
|
|
|
|
|
|
|
GET, POST, DEFAULT |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
interface CookieStore { |
|
|
|
interface CookieStore { |
|
|
|
fun setCookie(url: String, cookie: String) |
|
|
|
fun setCookie(url: String, cookie: String) |
|
|
|
|
|
|
|
|
|
|
|