]> gitweb.stoutner.com Git - PrivacyBrowserAndroid.git/commitdiff
Fix applying domain settings when navigating history. https://redmine.stoutner.com...
authorSoren Stoutner <soren@stoutner.com>
Wed, 17 Jul 2019 22:49:23 +0000 (15:49 -0700)
committerSoren Stoutner <soren@stoutner.com>
Wed, 17 Jul 2019 22:49:23 +0000 (15:49 -0700)
app/src/main/java/com/stoutner/privacybrowser/activities/MainWebViewActivity.java
app/src/main/java/com/stoutner/privacybrowser/dialogs/PinnedMismatchDialog.java
app/src/main/java/com/stoutner/privacybrowser/dialogs/UrlHistoryDialog.java
app/src/main/java/com/stoutner/privacybrowser/views/NestedScrollWebView.java
app/src/main/res/values-tr/strings.xml

index 5f8d80754bbef87c1b19822b4c5855a5f47eeb16..7f91e043e9aa648bf8699b22143f143b17295807 100644 (file)
@@ -73,6 +73,7 @@ import android.webkit.CookieManager;
 import android.webkit.HttpAuthHandler;
 import android.webkit.SslErrorHandler;
 import android.webkit.ValueCallback;
 import android.webkit.HttpAuthHandler;
 import android.webkit.SslErrorHandler;
 import android.webkit.ValueCallback;
+import android.webkit.WebBackForwardList;
 import android.webkit.WebChromeClient;
 import android.webkit.WebResourceResponse;
 import android.webkit.WebSettings;
 import android.webkit.WebChromeClient;
 import android.webkit.WebResourceResponse;
 import android.webkit.WebSettings;
@@ -129,6 +130,7 @@ import com.stoutner.privacybrowser.dialogs.DownloadLocationPermissionDialog;
 import com.stoutner.privacybrowser.dialogs.EditBookmarkDialog;
 import com.stoutner.privacybrowser.dialogs.EditBookmarkFolderDialog;
 import com.stoutner.privacybrowser.dialogs.HttpAuthenticationDialog;
 import com.stoutner.privacybrowser.dialogs.EditBookmarkDialog;
 import com.stoutner.privacybrowser.dialogs.EditBookmarkFolderDialog;
 import com.stoutner.privacybrowser.dialogs.HttpAuthenticationDialog;
+import com.stoutner.privacybrowser.dialogs.PinnedMismatchDialog;
 import com.stoutner.privacybrowser.dialogs.SaveWebpageImageDialog;
 import com.stoutner.privacybrowser.dialogs.SslCertificateErrorDialog;
 import com.stoutner.privacybrowser.dialogs.StoragePermissionDialog;
 import com.stoutner.privacybrowser.dialogs.SaveWebpageImageDialog;
 import com.stoutner.privacybrowser.dialogs.SslCertificateErrorDialog;
 import com.stoutner.privacybrowser.dialogs.StoragePermissionDialog;
@@ -164,8 +166,8 @@ import java.util.Set;
 // AppCompatActivity from android.support.v7.app.AppCompatActivity must be used to have access to the SupportActionBar until the minimum API is >= 21.
 public class MainWebViewActivity extends AppCompatActivity implements CreateBookmarkDialog.CreateBookmarkListener, CreateBookmarkFolderDialog.CreateBookmarkFolderListener,
         DownloadFileDialog.DownloadFileListener, DownloadImageDialog.DownloadImageListener, DownloadLocationPermissionDialog.DownloadLocationPermissionDialogListener, EditBookmarkDialog.EditBookmarkListener,
 // AppCompatActivity from android.support.v7.app.AppCompatActivity must be used to have access to the SupportActionBar until the minimum API is >= 21.
 public class MainWebViewActivity extends AppCompatActivity implements CreateBookmarkDialog.CreateBookmarkListener, CreateBookmarkFolderDialog.CreateBookmarkFolderListener,
         DownloadFileDialog.DownloadFileListener, DownloadImageDialog.DownloadImageListener, DownloadLocationPermissionDialog.DownloadLocationPermissionDialogListener, EditBookmarkDialog.EditBookmarkListener,
-        EditBookmarkFolderDialog.EditBookmarkFolderListener, NavigationView.OnNavigationItemSelectedListener, PopulateBlocklists.PopulateBlocklistsListener, SaveWebpageImageDialog.SaveWebpageImageListener,
-        StoragePermissionDialog.StoragePermissionDialogListener, WebViewTabFragment.NewTabListener {
+        EditBookmarkFolderDialog.EditBookmarkFolderListener, NavigationView.OnNavigationItemSelectedListener, PinnedMismatchDialog.PinnedMismatchListener, PopulateBlocklists.PopulateBlocklistsListener, SaveWebpageImageDialog.SaveWebpageImageListener,
+        StoragePermissionDialog.StoragePermissionDialogListener, UrlHistoryDialog.NavigateHistoryListener, WebViewTabFragment.NewTabListener {
 
     // `orbotStatus` is public static so it can be accessed from `OrbotProxyHelper`.  It is also used in `onCreate()`, `onResume()`, and `applyProxyThroughOrbot()`.
     public static String orbotStatus;
 
     // `orbotStatus` is public static so it can be accessed from `OrbotProxyHelper`.  It is also used in `onCreate()`, `onResume()`, and `applyProxyThroughOrbot()`.
     public static String orbotStatus;
@@ -1803,11 +1805,17 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook
 
             case R.id.back:
                 if (currentWebView.canGoBack()) {
 
             case R.id.back:
                 if (currentWebView.canGoBack()) {
+                    // Get the current web back forward list.
+                    WebBackForwardList webBackForwardList = currentWebView.copyBackForwardList();
+
+                    // Get the previous entry URL.
+                    String previousUrl = webBackForwardList.getItemAtIndex(webBackForwardList.getCurrentIndex() - 1).getUrl();
+
                     // Reset the current domain name so that navigation works if third-party requests are blocked.
                     currentWebView.resetCurrentDomainName();
 
                     // Reset the current domain name so that navigation works if third-party requests are blocked.
                     currentWebView.resetCurrentDomainName();
 
-                    // Set navigating history so that the domain settings are applied when the new URL is loaded.
-                    currentWebView.setNavigatingHistory(true);
+                    // Apply the domain settings.
+                    applyDomainSettings(currentWebView, previousUrl, false, false);
 
                     // Load the previous website in the history.
                     currentWebView.goBack();
 
                     // Load the previous website in the history.
                     currentWebView.goBack();
@@ -1816,11 +1824,17 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook
 
             case R.id.forward:
                 if (currentWebView.canGoForward()) {
 
             case R.id.forward:
                 if (currentWebView.canGoForward()) {
+                    // Get the current web back forward list.
+                    WebBackForwardList webBackForwardList = currentWebView.copyBackForwardList();
+
+                    // Get the next entry URL.
+                    String nextUrl = webBackForwardList.getItemAtIndex(webBackForwardList.getCurrentIndex() + 1).getUrl();
+
                     // Reset the current domain name so that navigation works if third-party requests are blocked.
                     currentWebView.resetCurrentDomainName();
 
                     // Reset the current domain name so that navigation works if third-party requests are blocked.
                     currentWebView.resetCurrentDomainName();
 
-                    // Set navigating history so that the domain settings are applied when the new URL is loaded.
-                    currentWebView.setNavigatingHistory(true);
+                    // Apply the domain settings.
+                    applyDomainSettings(currentWebView, nextUrl, false, false);
 
                     // Load the next website in the history.
                     currentWebView.goForward();
 
                     // Load the next website in the history.
                     currentWebView.goForward();
@@ -2748,7 +2762,7 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook
         }
     }
 
         }
     }
 
-    // Override `onBackPressed` to handle the navigation drawer and and the WebView.
+    // Override `onBackPressed` to handle the navigation drawer and and the WebViews.
     @Override
     public void onBackPressed() {
         // Get a handle for the drawer layout and the tab layout.
     @Override
     public void onBackPressed() {
         // Get a handle for the drawer layout and the tab layout.
@@ -2770,11 +2784,17 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook
                 loadBookmarksFolder();
             }
         } else if (currentWebView.canGoBack()) {  // There is at least one item in the current WebView history.
                 loadBookmarksFolder();
             }
         } else if (currentWebView.canGoBack()) {  // There is at least one item in the current WebView history.
+            // Get the current web back forward list.
+            WebBackForwardList webBackForwardList = currentWebView.copyBackForwardList();
+
+            // Get the previous entry URL.
+            String previousUrl = webBackForwardList.getItemAtIndex(webBackForwardList.getCurrentIndex() - 1).getUrl();
+
             // Reset the current domain name so that navigation works if third-party requests are blocked.
             currentWebView.resetCurrentDomainName();
 
             // Reset the current domain name so that navigation works if third-party requests are blocked.
             currentWebView.resetCurrentDomainName();
 
-            // Set navigating history so that the domain settings are applied when the new URL is loaded.
-            currentWebView.setNavigatingHistory(true);
+            // Apply the domain settings.
+            applyDomainSettings(currentWebView, previousUrl, false, false);
 
             // Go back.
             currentWebView.goBack();
 
             // Go back.
             currentWebView.goBack();
@@ -3594,6 +3614,36 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook
         bareWebView.destroy();
     }
 
         bareWebView.destroy();
     }
 
+    @Override
+    public void navigateHistory(String url, int steps) {
+        // Reset the current domain name so that navigation works if third-party requests are blocked.
+        currentWebView.resetCurrentDomainName();
+
+        // Apply the domain settings.
+        applyDomainSettings(currentWebView, url, false, false);
+
+        // Load the history entry.
+        currentWebView.goBackOrForward(steps);
+    }
+
+    @Override
+    public void pinnedErrorGoBack() {
+        // Get the current web back forward list.
+        WebBackForwardList webBackForwardList = currentWebView.copyBackForwardList();
+
+        // Get the previous entry URL.
+        String previousUrl = webBackForwardList.getItemAtIndex(webBackForwardList.getCurrentIndex() - 1).getUrl();
+
+        // Reset the current domain name so that navigation works if third-party requests are blocked.
+        currentWebView.resetCurrentDomainName();
+
+        // Apply the domain settings.
+        applyDomainSettings(currentWebView, previousUrl, false, false);
+
+        // Go back.
+        currentWebView.goBack();
+    }
+
     // `reloadWebsite` is used if returning from the Domains activity.  Otherwise JavaScript might not function correctly if it is newly enabled.
     @SuppressLint("SetJavaScriptEnabled")
     private boolean applyDomainSettings(NestedScrollWebView nestedScrollWebView, String url, boolean resetTab, boolean reloadWebsite) {
     // `reloadWebsite` is used if returning from the Domains activity.  Otherwise JavaScript might not function correctly if it is newly enabled.
     @SuppressLint("SetJavaScriptEnabled")
     private boolean applyDomainSettings(NestedScrollWebView nestedScrollWebView, String url, boolean resetTab, boolean reloadWebsite) {
@@ -5801,20 +5851,6 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook
                     // Get the IP addresses for the host.
                     new GetHostIpAddresses(activity, getSupportFragmentManager(), nestedScrollWebView).execute(currentUri.getHost());
 
                     // Get the IP addresses for the host.
                     new GetHostIpAddresses(activity, getSupportFragmentManager(), nestedScrollWebView).execute(currentUri.getHost());
 
-                    // Apply any custom domain settings if the URL was loaded by navigating history.
-                    if (nestedScrollWebView.getNavigatingHistory()) {
-                        // Reset navigating history.
-                        nestedScrollWebView.setNavigatingHistory(false);
-
-                        // Apply the domain settings.
-                        boolean userAgentChanged = applyDomainSettings(nestedScrollWebView, url, true, false);
-
-                        // Manually load the URL if the user agent has changed, which will have caused the previous URL to be reloaded.
-                        if (userAgentChanged) {
-                            loadUrl(url);
-                        }
-                    }
-
                     // Replace Refresh with Stop if the options menu has been created.  (The first WebView typically begins loading before the menu items are instantiated.)
                     if (optionsMenu != null) {
                         // Get a handle for the refresh menu item.
                     // Replace Refresh with Stop if the options menu has been created.  (The first WebView typically begins loading before the menu items are instantiated.)
                     if (optionsMenu != null) {
                         // Get a handle for the refresh menu item.
index 72fc85aeeee2752e1968bbf638166449f9b81e27..9694c0ac4d9db578ee0e122eeb5775071339bc83 100644 (file)
@@ -59,7 +59,13 @@ import androidx.fragment.app.DialogFragment;  // The AndroidX dialog fragment mu
 import androidx.viewpager.widget.PagerAdapter;
 
 public class PinnedMismatchDialog extends DialogFragment {
 import androidx.viewpager.widget.PagerAdapter;
 
 public class PinnedMismatchDialog extends DialogFragment {
+    // The public interface is used to send information back to the parent activity.
+    public interface PinnedMismatchListener {
+        void pinnedErrorGoBack();
+    }
+
     // Declare the class variables.
     // Declare the class variables.
+    private PinnedMismatchListener pinnedMismatchListener;
     private NestedScrollWebView nestedScrollWebView;
     private String currentSslIssuedToCName;
     private String currentSslIssuedToOName;
     private NestedScrollWebView nestedScrollWebView;
     private String currentSslIssuedToCName;
     private String currentSslIssuedToOName;
@@ -70,6 +76,15 @@ public class PinnedMismatchDialog extends DialogFragment {
     private Date currentSslStartDate;
     private Date currentSslEndDate;
 
     private Date currentSslStartDate;
     private Date currentSslEndDate;
 
+    @Override
+    public void onAttach(Context context) {
+        // Run the default commands.
+        super.onAttach(context);
+
+        // Get a handle for the listener from the launching context.
+        pinnedMismatchListener = (PinnedMismatchListener) context;
+    }
+
     public static PinnedMismatchDialog displayDialog(long webViewFragmentId) {
         // Create an arguments bundle.
         Bundle argumentsBundle = new Bundle();
     public static PinnedMismatchDialog displayDialog(long webViewFragmentId) {
         // Create an arguments bundle.
         Bundle argumentsBundle = new Bundle();
@@ -211,14 +226,8 @@ public class PinnedMismatchDialog extends DialogFragment {
         // Setup the back button.
         dialogBuilder.setNegativeButton(R.string.back, (DialogInterface dialog, int which) -> {
             if (nestedScrollWebView.canGoBack()) {  // There is a back page in the history.
         // Setup the back button.
         dialogBuilder.setNegativeButton(R.string.back, (DialogInterface dialog, int which) -> {
             if (nestedScrollWebView.canGoBack()) {  // There is a back page in the history.
-                // Reset the current domain name so that navigation works if third-party requests are blocked.
-                nestedScrollWebView.resetCurrentDomainName();
-
-                // Set navigating history so that the domain settings are applied when the new URL is loaded.
-                nestedScrollWebView.setNavigatingHistory(true);
-
-                // Go back.
-                nestedScrollWebView.goBack();
+                // Invoke the navigate history listener in the calling activity.  These commands cannot be run here because they need access to `applyDomainSettings()`.
+                pinnedMismatchListener.pinnedErrorGoBack();
             } else {  // There are no pages to go back to.
                 // Load a blank page
                 nestedScrollWebView.loadUrl("");
             } else {  // There are no pages to go back to.
                 // Load a blank page
                 nestedScrollWebView.loadUrl("");
index 366566f76b9bd3d5392478735f4d3c424caf814f..8aba719bafbb3c71c6a6fef1b2c101fc73c9d60f 100644 (file)
@@ -22,6 +22,7 @@ package com.stoutner.privacybrowser.dialogs;
 import android.annotation.SuppressLint;
 import android.app.AlertDialog;
 import android.app.Dialog;
 import android.annotation.SuppressLint;
 import android.app.AlertDialog;
 import android.app.Dialog;
+import android.content.Context;
 import android.content.DialogInterface;
 import android.content.SharedPreferences;
 import android.graphics.Bitmap;
 import android.content.DialogInterface;
 import android.content.SharedPreferences;
 import android.graphics.Bitmap;
@@ -35,6 +36,7 @@ import android.view.WindowManager;
 import android.webkit.WebBackForwardList;
 import android.widget.AdapterView;
 import android.widget.ListView;
 import android.webkit.WebBackForwardList;
 import android.widget.AdapterView;
 import android.widget.ListView;
+import android.widget.TextView;
 
 import androidx.annotation.NonNull;
 import androidx.core.content.ContextCompat;
 
 import androidx.annotation.NonNull;
 import androidx.core.content.ContextCompat;
@@ -50,6 +52,23 @@ import com.stoutner.privacybrowser.views.NestedScrollWebView;
 import java.util.ArrayList;
 
 public class UrlHistoryDialog extends DialogFragment{
 import java.util.ArrayList;
 
 public class UrlHistoryDialog extends DialogFragment{
+    // The public interface is used to send information back to the parent activity.
+    public interface NavigateHistoryListener {
+        void navigateHistory(String url, int steps);
+    }
+
+    // The navigate history listener is used in `onAttach()` and `onCreateDialog()`.
+    private NavigateHistoryListener navigateHistoryListener;
+
+    @Override
+    public void onAttach(Context context) {
+        // Run the default commands.
+        super.onAttach(context);
+
+        // Get a handle for the listener from the launching context.
+        navigateHistoryListener = (NavigateHistoryListener) context;
+    }
+
     public static UrlHistoryDialog loadBackForwardList(long webViewFragmentId) {
         // Create an arguments bundle.
         Bundle argumentsBundle = new Bundle();
     public static UrlHistoryDialog loadBackForwardList(long webViewFragmentId) {
         // Create an arguments bundle.
         Bundle argumentsBundle = new Bundle();
@@ -126,7 +145,7 @@ public class UrlHistoryDialog extends DialogFragment{
         // Create a history array list.
         ArrayList<History> historyArrayList = new ArrayList<>();
 
         // Create a history array list.
         ArrayList<History> historyArrayList = new ArrayList<>();
 
-        // Populate the history array list, descending from `urlStringArrayList.size()` so that the newest entries are at the top.  `-1` is needed because the history array list is zero-based.
+        // Populate the history array list, descending from the end of the list so that the newest entries are at the top.  `-1` is needed because the history array list is zero-based.
         for (int i=webBackForwardList.getSize() -1; i >= 0; i--) {
             // Create a variable to store the favorite icon bitmap.
             Bitmap favoriteIconBitmap;
         for (int i=webBackForwardList.getSize() -1; i >= 0; i--) {
             // Create a variable to store the favorite icon bitmap.
             Bitmap favoriteIconBitmap;
@@ -214,14 +233,14 @@ public class UrlHistoryDialog extends DialogFragment{
 
             // Only consume the click if it is not on the `currentPageId`.
             if (itemId != currentPageId) {
 
             // Only consume the click if it is not on the `currentPageId`.
             if (itemId != currentPageId) {
-                // Reset the current domain name so that navigation works if third-party requests are blocked.
-                nestedScrollWebView.resetCurrentDomainName();
+                // Get a handle for the URL text view.
+                TextView urlTextView = view.findViewById(R.id.history_url_textview);
 
 
-                // Set navigating history so that the domain settings are applied when the new URL is loaded.
-                nestedScrollWebView.setNavigatingHistory(true);
+                // Get the URL.
+                String url = urlTextView.getText().toString();
 
 
-                // Load the history entry.
-                nestedScrollWebView.goBackOrForward(currentPageId - itemId);
+                // Invoke the navigate history listener in the calling activity.  These commands cannot be run here because they need access to `applyDomainSettings()`.
+                navigateHistoryListener.navigateHistory(url, currentPageId - itemId);
 
                 // Dismiss the alert dialog.
                 alertDialog.dismiss();
 
                 // Dismiss the alert dialog.
                 alertDialog.dismiss();
index c7122cb8c83c4c34cad3ff4ff5a7a549cc2dc059..f877745580097b4054484118f16db0eb54859ca3 100644 (file)
@@ -117,9 +117,6 @@ public class NestedScrollWebView extends WebView implements NestedScrollingChild
     // The ignore pinned domain information tracker.  This is set when a user proceeds past a pinned mismatch dialog to prevent the dialog from showing again until after the domain changes.
     private boolean ignorePinnedDomainInformation;
 
     // The ignore pinned domain information tracker.  This is set when a user proceeds past a pinned mismatch dialog to prevent the dialog from showing again until after the domain changes.
     private boolean ignorePinnedDomainInformation;
 
-    // Track navigation of history.
-    private boolean navigatingHistory;
-
     // The default or favorite icon.
     private Bitmap favoriteOrDefaultIcon;
 
     // The default or favorite icon.
     private Bitmap favoriteOrDefaultIcon;
 
@@ -607,18 +604,6 @@ public class NestedScrollWebView extends WebView implements NestedScrollingChild
     }
 
 
     }
 
 
-    // Navigating history.
-    public void setNavigatingHistory(boolean status) {
-        // Set the status of navigating history.
-        navigatingHistory = status;
-    }
-
-    public boolean getNavigatingHistory() {
-        // Return the status of navigating history.
-        return navigatingHistory;
-    }
-
-
     // Favorite or default icon.
     public void initializeFavoriteIcon() {
         // Get the default favorite icon drawable.  `ContextCompat` must be used until API >= 21.
     // Favorite or default icon.
     public void initializeFavoriteIcon() {
         // Get the default favorite icon drawable.  `ContextCompat` must be used until API >= 21.
index 13527b012a8e5cd453023e8110dad05a4f67d231..4b397c5d4e7f749c2b561c76099228e69f869412 100644 (file)
 
     <!-- Context Menus. -->
     <string name="open_in_new_tab">Yeni sekmede aç</string>
 
     <!-- Context Menus. -->
     <string name="open_in_new_tab">Yeni sekmede aç</string>
+    <string name="open_image_in_new_tab">Resmi Yeni Sekmede Aç</string>
     <string name="copy_url">URL\'yi kopyala</string>
     <string name="download_url">URL\'yi indir</string>
     <string name="email_address">E-posta adresi</string>
     <string name="copy_url">URL\'yi kopyala</string>
     <string name="download_url">URL\'yi indir</string>
     <string name="email_address">E-posta adresi</string>
         <string name="block_all_third_party_requests_summary">Tüm üçüncü taraf istekleri engellemek gizliliği arttırır, fakat çoğu web sitesinin çökmesine sebep olur.</string>
     <string name="url_modification">URL Modifikasyonu</string>
         <string name="google_analytics">Google Analytics</string>
         <string name="block_all_third_party_requests_summary">Tüm üçüncü taraf istekleri engellemek gizliliği arttırır, fakat çoğu web sitesinin çökmesine sebep olur.</string>
     <string name="url_modification">URL Modifikasyonu</string>
         <string name="google_analytics">Google Analytics</string>
-        <string name="google_analytics_summary">URL\'den sonra gelen “?utm_” or “&amp;utm_” ve diğer şeyleri kaldırır.</string>
+        <string name="google_analytics_summary">URL\'lerde “?utm_” ve “&amp;utm_” ve onlardan sonra gelen her şey kaldırıldı.</string>
         <string name="facebook_click_ids">Facebook Tık ID\'leri</string>
         <string name="facebook_click_ids">Facebook Tık ID\'leri</string>
-        <string name="facebook_click_ids_summary">URL\'den sonra gelen “?fbclid=” or “&amp;fbclid=” ve diğer şeyleri kaldırır.</string>
+        <string name="facebook_click_ids_summary">URL\'lerde “?fbclid=”, “&amp;fbclid=”, “?fbadid=”, ve “&amp;fbadid=” ve onlardan sonra gelen her şey kaldırıldı.</string>
         <string name="twitter_amp_redirects">Twitter AMP yönlendirmeleri</string>
         <string name="twitter_amp_redirects_summary">URL\'den sonra gelen “?amp=1” ve diğer şeyleri kaldırır.</string>
     <string name="tor">Tor</string>
         <string name="twitter_amp_redirects">Twitter AMP yönlendirmeleri</string>
         <string name="twitter_amp_redirects_summary">URL\'den sonra gelen “?amp=1” ve diğer şeyleri kaldırır.</string>
     <string name="tor">Tor</string>