@@ -42,7 +42,7 @@ class BrowserWebViewClient @Inject constructor(
4242) : WebViewClient() {
4343
4444 var webViewClientListener: WebViewClientListener ? = null
45-
45+ var currentUrl : String? = null
4646
4747 /* *
4848 * This is the new method of url overriding available from API 24 onwards
@@ -84,6 +84,7 @@ class BrowserWebViewClient @Inject constructor(
8484 }
8585
8686 override fun onPageStarted (view : WebView ? , url : String? , favicon : Bitmap ? ) {
87+ currentUrl = url
8788 webViewClientListener?.loadingStarted()
8889 webViewClientListener?.urlChanged(url)
8990 }
@@ -94,15 +95,15 @@ class BrowserWebViewClient @Inject constructor(
9495
9596 @WorkerThread
9697 override fun shouldInterceptRequest (view : WebView , request : WebResourceRequest ): WebResourceResponse ? {
97- Timber .v(" Intercepting resource ${request.url} on page ${view.urlFromAnyThread() } }" )
98+ Timber .v(" Intercepting resource ${request.url} on page ${currentUrl } }" )
9899
99100 if (shouldUpgrade(request)) {
100101 val newUri = httpsUpgrader.upgrade(request.url)
101102 view.post { view.loadUrl(newUri.toString()) }
102103 return WebResourceResponse (null , null , null )
103104 }
104105
105- val documentUrl = view.urlFromAnyThread() ? : return null
106+ val documentUrl = currentUrl ? : return null
106107
107108 if (TrustedSites .isTrusted(documentUrl)) {
108109 return null
@@ -138,26 +139,9 @@ class BrowserWebViewClient @Inject constructor(
138139 * Utility to function to execute a function, and then return true
139140 *
140141 * Useful to reduce clutter in repeatedly including `return true` after doing the real work.
141- */
142+ */
142143 private inline fun consume (function : () -> Unit ): Boolean {
143144 function()
144145 return true
145146 }
146-
147- /* *
148- * Access WebView.url from any thread. If you are on the main thread it is more efficient to use
149- * WebView.url directly.
150- */
151- @AnyThread
152- private fun WebView.urlFromAnyThread (): String? {
153- val latch = CountDownLatch (1 )
154- var safeUrl: String? = null
155- post {
156- safeUrl = url
157- latch.countDown()
158- }
159- latch.await()
160- return safeUrl
161- }
162-
163147}
0 commit comments