@@ -47,7 +47,6 @@ import org.readium.r2.shared.util.Url
4747import org.readium.r2.shared.util.data.decodeString
4848import org.readium.r2.shared.util.flatMap
4949import org.readium.r2.shared.util.resource.Resource
50- import org.readium.r2.shared.util.toUrl
5150import org.readium.r2.shared.util.use
5251import timber.log.Timber
5352
@@ -89,7 +88,7 @@ internal open class R2BasicWebView(context: Context, attrs: AttributeSet) : WebV
8988 fun shouldInterceptRequest (webView : WebView , request : WebResourceRequest ): WebResourceResponse ? = null
9089
9190 @InternalReadiumApi
92- fun shouldFollowFootnoteLink (url : AbsoluteUrl , context : HyperlinkNavigator .FootnoteContext ): Boolean
91+ fun onFootnoteLinkActivated (url : AbsoluteUrl , context : HyperlinkNavigator .FootnoteContext )
9392
9493 @InternalReadiumApi
9594 fun resourceAtUrl (url : Url ): Resource ? = null
@@ -131,12 +130,6 @@ internal open class R2BasicWebView(context: Context, attrs: AttributeSet) : WebV
131130
132131 private val uiScope = CoroutineScope (Dispatchers .Main )
133132
134- /*
135- * Url already handled by listener.shouldFollowFootnoteLink,
136- * Tries to ignore the matching shouldOverrideUrlLoading call.
137- */
138- private var urlNotToOverrideLoading: AbsoluteUrl ? = null
139-
140133 init {
141134 setWebContentsDebuggingEnabled(BuildConfig .DEBUG )
142135 }
@@ -382,14 +375,10 @@ internal open class R2BasicWebView(context: Context, attrs: AttributeSet) : WebV
382375 noteContent = safe
383376 )
384377
385- val shouldFollowLink = listener?.shouldFollowFootnoteLink(absoluteUrl, context) ? : true
386-
387- if (shouldFollowLink) {
388- urlNotToOverrideLoading = absoluteUrl
389- }
378+ listener?.onFootnoteLinkActivated(absoluteUrl, context)
390379
391- // Consume event if the link should not be followed .
392- return ! shouldFollowLink
380+ // Consume the event to prevent the Webview from loading the link .
381+ return true
393382 }
394383
395384 @android.webkit.JavascriptInterface
@@ -584,15 +573,7 @@ internal open class R2BasicWebView(context: Context, attrs: AttributeSet) : WebV
584573 }
585574
586575 internal fun shouldOverrideUrlLoading (request : WebResourceRequest ): Boolean {
587- val requestUrl = request.url.toUrl() ? : return false
588-
589- // FIXME: I doubt this can work well. hasGesture considers itself unreliable.
590- return if (urlNotToOverrideLoading?.isEquivalent(requestUrl) == true && request.hasGesture()) {
591- urlNotToOverrideLoading = null
592- false
593- } else {
594- listener?.shouldOverrideUrlLoading(this , request) ? : false
595- }
576+ return listener?.shouldOverrideUrlLoading(this , request) ? : false
596577 }
597578
598579 internal fun shouldInterceptRequest (webView : WebView , request : WebResourceRequest ): WebResourceResponse ? {
0 commit comments