From 8277a0304d367a8848f9c13c9ba6d196f27c93fa Mon Sep 17 00:00:00 2001 From: Soren Stoutner Date: Thu, 26 Feb 2026 12:32:54 -0700 Subject: [PATCH] Define third-party as any non-exact domain name. https://redmine.stoutner.com/issues/481 --- .../activities/MainWebViewActivity.kt | 28 ++++--------------- 1 file changed, 5 insertions(+), 23 deletions(-) diff --git a/app/src/main/java/com/stoutner/privacybrowser/activities/MainWebViewActivity.kt b/app/src/main/java/com/stoutner/privacybrowser/activities/MainWebViewActivity.kt index 3ac67a51..b31b75d2 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/activities/MainWebViewActivity.kt +++ b/app/src/main/java/com/stoutner/privacybrowser/activities/MainWebViewActivity.kt @@ -5410,31 +5410,13 @@ class MainWebViewActivity : AppCompatActivity(), CreateBookmarkDialog.CreateBook // Create an empty web resource response to be used if the resource request is blocked. val emptyWebResourceResponse = WebResourceResponse("text/plain", "utf8", ByteArrayInputStream("".toByteArray())) - // Get the current URL. `.getUrl()` throws an error because operations on the WebView cannot be made from this thread. - var currentBaseDomain = nestedScrollWebView.currentDomainName - - // Populate the request data class web page URL. - requestDataClass.firstPartyHostString = currentBaseDomain - - // Get the request host name. - var requestBaseDomain = webResourceRequest.url.host - - // Only check for third-party requests if the current base domain is not empty and the request domain is not null. - if (currentBaseDomain.isNotEmpty() && (requestBaseDomain != null)) { - // Determine the current base domain. - while (currentBaseDomain.indexOf(".", currentBaseDomain.indexOf(".") + 1) > 0) { // There is at least one subdomain. - // Remove the first subdomain. - currentBaseDomain = currentBaseDomain.substring(currentBaseDomain.indexOf(".") + 1) - } - - // Determine the request base domain. - while (requestBaseDomain!!.indexOf(".", requestBaseDomain.indexOf(".") + 1) > 0) { // There is at least one subdomain. - // Remove the first subdomain. - requestBaseDomain = requestBaseDomain.substring(requestBaseDomain.indexOf(".") + 1) - } + // Populate the request data class web page URL. `.getUrl()` throws an error because operations on the WebView cannot be made from this thread. + requestDataClass.firstPartyHostString = nestedScrollWebView.currentDomainName + // Only check for third-party requests if the first-party host string is not empty and the request domain is not null. + if (requestDataClass.firstPartyHostString.isNotEmpty() && (webResourceRequest.url.host != null)) { // Update the third party request tracker. - requestDataClass.isThirdPartyRequest = currentBaseDomain != requestBaseDomain + requestDataClass.isThirdPartyRequest = (requestDataClass.firstPartyHostString != webResourceRequest.url.host) } // Get the current WebView page position. -- 2.51.0