X-Git-Url: https://gitweb.stoutner.com/?p=PrivacyBrowserAndroid.git;a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fcom%2Fstoutner%2Fprivacybrowser%2Factivities%2FMainWebViewActivity.java;h=ce5ccc126cabdb61ea0a8e8f97f9887a137d000a;hp=097c8af9b883b443710a0fd3375af767829ece81;hb=ff1bf786c6cc0a55e20af4e99697ca221f2c11c8;hpb=ffdec8106ad23f62ca529749ade99f51e336ce55 diff --git a/app/src/main/java/com/stoutner/privacybrowser/activities/MainWebViewActivity.java b/app/src/main/java/com/stoutner/privacybrowser/activities/MainWebViewActivity.java index 097c8af9..ce5ccc12 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/activities/MainWebViewActivity.java +++ b/app/src/main/java/com/stoutner/privacybrowser/activities/MainWebViewActivity.java @@ -433,7 +433,7 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook loadingNewIntent = true; // Add a new tab. - addNewTab(url); + addNewTab(url, true); } else { // Load the URL in the current tab. // Make it so. loadUrl(url); @@ -2026,7 +2026,7 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook // Add an Open in New Tab entry. menu.add(R.string.open_in_new_tab).setOnMenuItemClickListener((MenuItem item) -> { // Load the link URL in a new tab. - addNewTab(linkUrl); + addNewTab(linkUrl, false); // Consume the event. return true; @@ -2151,9 +2151,9 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook menu.setHeaderTitle(imageUrl); // Add an Open in New Tab entry. - menu.add(R.string.open_in_new_tab).setOnMenuItemClickListener((MenuItem item) -> { - // Load the image URL in a new tab. - addNewTab(imageUrl); + menu.add(R.string.open_image_in_new_tab).setOnMenuItemClickListener((MenuItem item) -> { + // Load the image in a new tab. + addNewTab(imageUrl, false); // Consume the event. return true; @@ -2260,7 +2260,16 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook // Add an Open in New Tab entry. menu.add(R.string.open_in_new_tab).setOnMenuItemClickListener((MenuItem item) -> { // Load the link URL in a new tab. - addNewTab(linkUrl); + addNewTab(linkUrl, false); + + // Consume the event. + return true; + }); + + // Add an Open Image in New Tab entry. + menu.add(R.string.open_image_in_new_tab).setOnMenuItemClickListener((MenuItem item) -> { + // Load the image in a new tab. + addNewTab(imageUrl, false); // Consume the event. return true; @@ -3591,6 +3600,9 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook // Store a copy of the current user agent to track changes for the return boolean. String initialUserAgent = nestedScrollWebView.getSettings().getUserAgentString(); + // Store the current URL. + nestedScrollWebView.setCurrentUrl(url); + // Parse the URL into a URI. Uri uri = Uri.parse(url); @@ -4431,15 +4443,15 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook ultraPrivacy = combinedBlocklists.get(5); // Add the first tab. - addNewTab(""); + addNewTab("", true); } public void addTab(View view) { // Add a new tab with a blank URL. - addNewTab(""); + addNewTab("", true); } - private void addNewTab(String url) { + private void addNewTab(String url, boolean moveToTab) { // Sanitize the URL. url = sanitizeUrl(url); @@ -4463,7 +4475,7 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook newTab.setCustomView(R.layout.tab_custom_view); // Add the new WebView page. - webViewPagerAdapter.addPage(newTabNumber, webViewPager, url); + webViewPagerAdapter.addPage(newTabNumber, webViewPager, url, moveToTab); } public void closeTab(View view) { @@ -5344,6 +5356,12 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook // Check requests against the block lists. The deprecated `shouldInterceptRequest()` must be used until minimum API >= 21. @Override public WebResourceResponse shouldInterceptRequest(WebView view, String url) { + // Check to see if the resource request is for the main URL. + if (url.equals(nestedScrollWebView.getCurrentUrl())) { + // `return null` loads the resource request, which should never be blocked if it is the main URL. + return null; + } + // Wait until the blocklists have been populated. When Privacy Browser is being resumed after having the process killed in the background it will try to load the URLs immediately. while (ultraPrivacy == null) { // The wait must be synchronized, which only lets one thread run on it at a time, or `java.lang.IllegalMonitorStateException` is thrown.