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=5f8d80754bbef87c1b19822b4c5855a5f47eeb16;hp=d13c4d27bb0ff149fffeb19064b2564f7a2f3f3c;hb=717553f0ca8a835fa8ade69e76b53e7c2a7fdea1;hpb=de4e15cd445f2659165676e524a99f3c0f42033c 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 d13c4d27..5f8d8075 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; @@ -4410,6 +4419,16 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook if (url.contains("&fbclid=")) { url = url.substring(0, url.indexOf("&fbclid=")); } + + // Remove `?fbadid=`. + if (url.contains("?fbadid=")) { + url = url.substring(0, url.indexOf("?fbadid=")); + } + + // Remove `&fbadid=`. + if (url.contains("&fbadid=")) { + url = url.substring(0, url.indexOf("&fbadid=")); + } } // Sanitize Twitter AMP redirects. @@ -4434,15 +4453,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); @@ -4466,7 +4485,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) { @@ -5923,11 +5942,17 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook tabTitleTextView.setText(R.string.new_tab); } } else { // The WebView has loaded a webpage. - // Display the final URL. Getting the URL from the WebView instead of using the one provided by `onPageFinished()` makes websites like YouTube function correctly. - urlEditText.setText(currentUrl); + // Update the URL edit text if it is not currently being edited. + if (!urlEditText.hasFocus()) { + // Sanitize the current URL. This removes unwanted URL elements that were added by redirects, so that they won't be included if the URL is shared. + String sanitizedUrl = sanitizeUrl(currentUrl); + + // Display the final URL. Getting the URL from the WebView instead of using the one provided by `onPageFinished()` makes websites like YouTube function correctly. + urlEditText.setText(sanitizedUrl); - // Apply text highlighting to the URL. - highlightUrlText(); + // Apply text highlighting to the URL. + highlightUrlText(); + } // Only populate the title text view if the tab has been fully created. if (tab != null) {