|
1 | 1 | package com.reactnativecommunity.webview.extension.file |
2 | 2 |
|
3 | | -import android.content.Context |
4 | 3 | import android.webkit.JavascriptInterface |
5 | 4 | import com.reactnativecommunity.webview.RNCWebView |
6 | 5 | import com.reactnativecommunity.webview.extension.file.Base64FileDownloader.downloadBase64File |
7 | 6 | import java.io.IOException |
8 | 7 |
|
9 | 8 | internal fun RNCWebView.addBlobFileDownloaderJavascriptInterface(downloadingMessage: String, requestFilePermission: (String) -> Unit) { |
10 | 9 | this.addJavascriptInterface( |
11 | | - BlobFileDownloader(this.context, downloadingMessage, requestFilePermission), |
| 10 | + BlobFileDownloader(this, downloadingMessage, requestFilePermission), |
12 | 11 | BlobFileDownloader.JS_INTERFACE_TAG, |
13 | 12 | ) |
14 | 13 | } |
15 | 14 |
|
16 | 15 | internal class BlobFileDownloader( |
17 | | - private val context: Context, |
| 16 | + private val webView: RNCWebView, |
18 | 17 | private val downloadingMessage: String, |
19 | 18 | private val requestFilePermission: (String) -> Unit, |
20 | 19 | ) { |
21 | 20 |
|
22 | 21 | @JavascriptInterface |
23 | 22 | @Throws(IOException::class) |
24 | 23 | fun getBase64FromBlobData(base64: String) { |
25 | | - downloadBase64File(context, base64, downloadingMessage, requestFilePermission) |
| 24 | + if (!webView.allowFileDownloads) { |
| 25 | + return |
| 26 | + } |
| 27 | + downloadBase64File(webView.context, base64, downloadingMessage, requestFilePermission) |
26 | 28 | } |
27 | 29 |
|
28 | 30 | companion object { |
|
0 commit comments