Skip to content

Commit

Permalink
[connect] Remove JS bridge workaround (#9751)
Browse files Browse the repository at this point in the history
* rm JS bridge workaround

* don't clear cache
  • Loading branch information
lng-stripe authored Dec 6, 2024
1 parent 2b36058 commit c1afa5d
Showing 1 changed file with 0 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,7 @@ internal class StripeConnectWebViewContainerImpl<Listener : StripeEmbeddedCompon
}

setDownloadListener(StripeDownloadListener(webView.context))

addJavascriptInterface(StripeJsInterface(), ANDROID_JS_INTERFACE)
addJavascriptInterface(StripeJsInterfaceInternal(), ANDROID_JS_INTERNAL_INTERFACE)
}
}

Expand Down Expand Up @@ -178,7 +176,6 @@ internal class StripeConnectWebViewContainerImpl<Listener : StripeEmbeddedCompon
}

override fun loadUrl(url: String) {
webView?.clearCache(true)
webView?.loadUrl(url)
}

Expand All @@ -196,7 +193,6 @@ internal class StripeConnectWebViewContainerImpl<Listener : StripeEmbeddedCompon
@VisibleForTesting
internal inner class StripeConnectWebViewClient : WebViewClient() {
override fun onPageStarted(view: WebView, url: String?, favicon: Bitmap?) {
initJavascriptBridge(view)
controller?.onPageStarted()
}

Expand All @@ -219,41 +215,6 @@ internal class StripeConnectWebViewContainerImpl<Listener : StripeEmbeddedCompon
controller?.onReceivedError(request.url.toString(), errorMessage = errorMessage)
}

private fun initJavascriptBridge(webView: WebView) {
logger.debug("Initializing Javascript Bridge")
webView.evaluateJavascript(
"""
$ANDROID_JS_INTERFACE.accountSessionClaimed = (message) => {
$ANDROID_JS_INTERNAL_INTERFACE.accountSessionClaimed(JSON.stringify(message));
};
$ANDROID_JS_INTERFACE.pageDidLoad = (message) => {
$ANDROID_JS_INTERNAL_INTERFACE.pageDidLoad(JSON.stringify(message));
};
$ANDROID_JS_INTERFACE.fetchInitParams = () => {
let params = $ANDROID_JS_INTERNAL_INTERFACE.fetchInitParams();
return Promise.resolve(JSON.parse(params));
};
$ANDROID_JS_INTERFACE.fetchClientSecret = () => {
return new Promise((resolve, reject) => {
try {
let clientSecret = $ANDROID_JS_INTERNAL_INTERFACE.fetchClientSecret()
resolve(clientSecret);
} catch (e) {
reject(e);
}
});
};
$ANDROID_JS_INTERFACE.onSetterFunctionCalled = (message) => {
$ANDROID_JS_INTERNAL_INTERFACE.onSetterFunctionCalled(JSON.stringify(message));
};
$ANDROID_JS_INTERFACE.openSecureWebView = (message) => {
$ANDROID_JS_INTERNAL_INTERFACE.openSecureWebView(JSON.stringify(message));
};
""".trimIndent(),
{ resultString -> logger.debug("Javascript Bridge initialized. Result: \"$resultString\"") }
)
}

override fun shouldOverrideUrlLoading(view: WebView, request: WebResourceRequest): Boolean {
return controller?.shouldOverrideUrlLoading(view.context, request) ?: false
}
Expand All @@ -278,9 +239,7 @@ internal class StripeConnectWebViewContainerImpl<Listener : StripeEmbeddedCompon
fun fetchInitComponentProps() {
logger.debug("InitComponentProps fetched")
}
}

private inner class StripeJsInterfaceInternal {
@JavascriptInterface
fun log(message: String) {
logger.debug("Log from JS: $message")
Expand Down Expand Up @@ -340,6 +299,5 @@ internal class StripeConnectWebViewContainerImpl<Listener : StripeEmbeddedCompon

internal companion object {
private const val ANDROID_JS_INTERFACE = "Android"
private const val ANDROID_JS_INTERNAL_INTERFACE = "AndroidInternal"
}
}

0 comments on commit c1afa5d

Please sign in to comment.