Skip to content

Commit 9e9ec5e

Browse files
committed
fix: fix allowFileDownloads edge case on old Android
1 parent 4f635e5 commit 9e9ec5e

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

android/src/main/java/com/reactnativecommunity/webview/extension/file/BlobFileDownloader.kt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,30 @@
11
package com.reactnativecommunity.webview.extension.file
22

3-
import android.content.Context
43
import android.webkit.JavascriptInterface
54
import com.reactnativecommunity.webview.RNCWebView
65
import com.reactnativecommunity.webview.extension.file.Base64FileDownloader.downloadBase64File
76
import java.io.IOException
87

98
internal fun RNCWebView.addBlobFileDownloaderJavascriptInterface(downloadingMessage: String, requestFilePermission: (String) -> Unit) {
109
this.addJavascriptInterface(
11-
BlobFileDownloader(this.context, downloadingMessage, requestFilePermission),
10+
BlobFileDownloader(this, downloadingMessage, requestFilePermission),
1211
BlobFileDownloader.JS_INTERFACE_TAG,
1312
)
1413
}
1514

1615
internal class BlobFileDownloader(
17-
private val context: Context,
16+
private val webView: RNCWebView,
1817
private val downloadingMessage: String,
1918
private val requestFilePermission: (String) -> Unit,
2019
) {
2120

2221
@JavascriptInterface
2322
@Throws(IOException::class)
2423
fun getBase64FromBlobData(base64: String) {
25-
downloadBase64File(context, base64, downloadingMessage, requestFilePermission)
24+
if (!webView.allowFileDownloads) {
25+
return
26+
}
27+
downloadBase64File(webView.context, base64, downloadingMessage, requestFilePermission)
2628
}
2729

2830
companion object {

0 commit comments

Comments
 (0)