Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ class DriveFragment :
// This property is only valid between onCreateView and onDestroyView.
private val binding get() = _binding!!

private val jsList = HashMap<String, Any>()

private val pushScriptUtil: PushScriptUtil by lazy {
PushScriptUtil()
}
Expand Down Expand Up @@ -328,6 +330,8 @@ class DriveFragment :
webView.destroy()
}

jsList.clear()

webView = null

ioxUsbModule.stop()
Expand Down Expand Up @@ -432,6 +436,10 @@ class DriveFragment :
}

this.webView?.addJavascriptInterface(this, Module.interfaceName)
// js listeners
jsList.forEach { name, listener ->
this.webView?.addJavascriptInterface(listener, name)
}
this.webView?.webViewClient = webViewClientUserContentController
isWebViewConfigured = true
this.webView?.webChromeClient = WebViewChromeClient(fileChooserHelper = FileChooserHelper(this))
Expand Down Expand Up @@ -646,6 +654,17 @@ class DriveFragment :
ioxUsbModule.deviceEventCallback = callback
}

@SuppressLint("JavascriptInterface")
override fun addJavascriptInterface(listener: Any, name: String) {
this.webView?.addJavascriptInterface(listener, name) ?: kotlin.run {
this.jsList.put(name, listener)
}
}

override fun removeJavascriptInterface(name: String) {
this.webView?.removeJavascriptInterface(name)
}

private fun setUrlToWebView(urlString: String) {
this.webView?.loadUrl(urlString)
this.customUrl = null
Expand Down Expand Up @@ -678,7 +697,7 @@ class DriveFragment :
val url = list.getItemAtIndex(i).url
val indx = url.indexOf('#')
if (indx != -1 && !url.substring(indx + 1)
.contains("login", ignoreCase = true)
.contains("login", ignoreCase = true)
) {
webView.goBackOrForward(i - (list.size - 1))
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,17 @@ interface DriveSdk {
* - DeviceEvent is the Json string of the device event object.
*/
fun getDeviceEvents(callback: (Result<Success<String>, Failure>) -> Unit)

/**
* Add a JavaScript interface on the webView
* @param listener the class that wil receive the callbacks
* @param name JsInterface name, needs to be aligned with the web implementation
*/
fun addJavascriptInterface(listener: Any, name: String)

/**
* Removes a JavaScript interface for a given name
* @param name JsInterface name
*/
fun removeJavascriptInterface(name: String)
}