Skip to content

Commit

Permalink
Merge branch 'fix/white_webview' into hotfix/4.0.9
Browse files Browse the repository at this point in the history
  • Loading branch information
brindy committed Jan 23, 2018
2 parents dc851ca + af79fd7 commit 4b38391
Showing 1 changed file with 5 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class BrowserWebViewClient @Inject constructor(
) : WebViewClient() {

var webViewClientListener: WebViewClientListener? = null

var currentUrl: String? = null

/**
* This is the new method of url overriding available from API 24 onwards
Expand Down Expand Up @@ -84,6 +84,7 @@ class BrowserWebViewClient @Inject constructor(
}

override fun onPageStarted(view: WebView?, url: String?, favicon: Bitmap?) {
currentUrl = url
webViewClientListener?.loadingStarted()
webViewClientListener?.urlChanged(url)
}
Expand All @@ -94,15 +95,15 @@ class BrowserWebViewClient @Inject constructor(

@WorkerThread
override fun shouldInterceptRequest(view: WebView, request: WebResourceRequest): WebResourceResponse? {
Timber.v("Intercepting resource ${request.url} on page ${view.urlFromAnyThread()}}")
Timber.v("Intercepting resource ${request.url} on page ${currentUrl}}")

if (shouldUpgrade(request)) {
val newUri = httpsUpgrader.upgrade(request.url)
view.post { view.loadUrl(newUri.toString()) }
return WebResourceResponse(null, null, null)
}

val documentUrl = view.urlFromAnyThread() ?: return null
val documentUrl = currentUrl ?: return null

if (TrustedSites.isTrusted(documentUrl)) {
return null
Expand Down Expand Up @@ -138,26 +139,9 @@ class BrowserWebViewClient @Inject constructor(
* Utility to function to execute a function, and then return true
*
* Useful to reduce clutter in repeatedly including `return true` after doing the real work.
*/
*/
private inline fun consume(function: () -> Unit): Boolean {
function()
return true
}

/**
* Access WebView.url from any thread. If you are on the main thread it is more efficient to use
* WebView.url directly.
*/
@AnyThread
private fun WebView.urlFromAnyThread(): String? {
val latch = CountDownLatch(1)
var safeUrl: String? = null
post {
safeUrl = url
latch.countDown()
}
latch.await()
return safeUrl
}

}

0 comments on commit 4b38391

Please sign in to comment.