X-Git-Url: https://gitweb.stoutner.com/?p=PrivacyBrowserAndroid.git;a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fcom%2Fstoutner%2Fprivacybrowser%2Fasynctasks%2FGetHostIpAddresses.java;h=3c7f37cfbb65bf0086e7a017d3a9a9fe9ee01011;hp=1e004d13ba4dc4dbca8f04971686c14d623503a1;hb=9d5e4c56326502b6b74e8f3e463275f5c1e176cc;hpb=3d167d1ec7d0cef1ef032f20859bb0de8ddb01cf diff --git a/app/src/main/java/com/stoutner/privacybrowser/asynctasks/GetHostIpAddresses.java b/app/src/main/java/com/stoutner/privacybrowser/asynctasks/GetHostIpAddresses.java index 1e004d13..3c7f37cf 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/asynctasks/GetHostIpAddresses.java +++ b/app/src/main/java/com/stoutner/privacybrowser/asynctasks/GetHostIpAddresses.java @@ -22,7 +22,11 @@ package com.stoutner.privacybrowser.asynctasks; import android.app.Activity; import android.os.AsyncTask; +import androidx.fragment.app.FragmentManager; + import com.stoutner.privacybrowser.activities.MainWebViewActivity; +import com.stoutner.privacybrowser.helpers.CheckPinnedMismatchHelper; +import com.stoutner.privacybrowser.views.NestedScrollWebView; import java.lang.ref.WeakReference; import java.net.InetAddress; @@ -32,39 +36,25 @@ import java.net.UnknownHostException; public class GetHostIpAddresses extends AsyncTask { // The weak references are used to determine if the activity have disappeared while the AsyncTask is running. private final WeakReference activityWeakReference; - private final int domainSettingsDatabaseId; + private final WeakReference fragmentManagerWeakReference; + private final WeakReference nestedScrollWebViewWeakReference; - public GetHostIpAddresses(Activity activity, int domainSettingsDatabaseId) { - // Populate the weak activity reference. + public GetHostIpAddresses(Activity activity, FragmentManager fragmentManager, NestedScrollWebView nestedScrollWebView) { + // Populate the weak references. activityWeakReference = new WeakReference<>(activity); - - // Populate the domain settings database ID. - this.domainSettingsDatabaseId = domainSettingsDatabaseId; - } - - // `onPreExecute()` operates on the UI thread. - @Override - protected void onPreExecute() { - // Get a handle for the activity. - Activity activity = activityWeakReference.get(); - - // Abort if the activity is gone. - if ((activity == null) || activity.isFinishing()) { - return; - } - - // Set the getting IP addresses tracker. - MainWebViewActivity.gettingIpAddresses = true; + fragmentManagerWeakReference = new WeakReference<>(fragmentManager); + nestedScrollWebViewWeakReference = new WeakReference<>(nestedScrollWebView); } - @Override protected String doInBackground(String... domainName) { - // Get a handle for the activity. + // Get a handles for the weak references. Activity activity = activityWeakReference.get(); + FragmentManager fragmentManager = fragmentManagerWeakReference.get(); + NestedScrollWebView nestedScrollWebView = nestedScrollWebViewWeakReference.get(); - // Abort if the activity is gone. - if ((activity == null) || activity.isFinishing()) { + // Abort if the activity or its components are gone. + if ((activity == null) || activity.isFinishing() || fragmentManager == null || nestedScrollWebView == null) { // Return an empty spannable string builder. return ""; } @@ -101,22 +91,22 @@ public class GetHostIpAddresses extends AsyncTask { // `onPostExecute()` operates on the UI thread. @Override protected void onPostExecute(String ipAddresses) { - // Get a handle for the activity. + // Get a handle for the activity and the nested scroll WebView. Activity activity = activityWeakReference.get(); + FragmentManager fragmentManager = fragmentManagerWeakReference.get(); + NestedScrollWebView nestedScrollWebView = nestedScrollWebViewWeakReference.get(); - // Abort if the activity is gone. - if ((activity == null) || activity.isFinishing()) { + // Abort if the activity or its components are gone. + if ((activity == null) || activity.isFinishing() || fragmentManager == null || nestedScrollWebView == null) { return; } // Store the IP addresses. - MainWebViewActivity.currentHostIpAddresses = ipAddresses; + nestedScrollWebView.setCurrentIpAddresses(ipAddresses); - if (!MainWebViewActivity.urlIsLoading) { - MainWebViewActivity.checkPinnedMismatch(domainSettingsDatabaseId); + //TODO. Move `urlIsLoading` to the WebView. + if (!MainWebViewActivity.urlIsLoading && !nestedScrollWebView.ignorePinnedDomainInformation() && (nestedScrollWebView.hasPinnedSslCertificate() || nestedScrollWebView.hasPinnedIpAddresses())) { + CheckPinnedMismatchHelper.checkPinnedMismatch(fragmentManager, nestedScrollWebView); } - - // Reset the getting IP addresses tracker. - MainWebViewActivity.gettingIpAddresses = false; } } \ No newline at end of file