From 7dcfe46842e801486a3696bea379602350e6891a Mon Sep 17 00:00:00 2001 From: Soren Stoutner Date: Wed, 8 May 2019 12:35:01 -0700 Subject: [PATCH] Fix periodic problems adding tabs from intents. https://redmine.stoutner.com/issues/412 --- .../activities/MainWebViewActivity.java | 67 ++++++++++--------- .../adapters/WebViewPagerAdapter.java | 4 +- .../fragments/WebViewTabFragment.java | 10 +-- app/src/main/res/values-de/strings.xml | 3 +- app/src/main/res/values-es/strings.xml | 3 +- app/src/main/res/values-it/strings.xml | 3 +- app/src/main/res/values-ru/strings.xml | 3 +- app/src/main/res/values-tr/strings.xml | 1 - .../android/de-DE/full_description.txt | 4 +- 9 files changed, 55 insertions(+), 43 deletions(-) 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 5764b9d9..df7cef48 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/activities/MainWebViewActivity.java +++ b/app/src/main/java/com/stoutner/privacybrowser/activities/MainWebViewActivity.java @@ -816,15 +816,6 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook // Get the shared preferences. SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); - // Add a new tab if specified in the preferences. - if (sharedPreferences.getBoolean("open_intents_in_new_tab", true)) { - // Set the loading new intent flag. - loadingNewIntent = true; - - // Add a new tab. - addTab(null); - } - // Create a URL string. String url; @@ -847,8 +838,17 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook url = intentUriData.toString(); } - // Load the URL. - loadUrl(url); + // Add a new tab if specified in the preferences. + if (sharedPreferences.getBoolean("open_intents_in_new_tab", true)) { // Load the URL in a new tab. + // Set the loading new intent flag. + loadingNewIntent = true; + + // Add a new tab. + addNewTab(url); + } else { // Load the URL in the current tab. + // Make it so. + loadUrl(url); + } // Get a handle for the drawer layout. DrawerLayout drawerLayout = findViewById(R.id.drawerlayout); @@ -862,9 +862,6 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook if (drawerLayout.isDrawerVisible(GravityCompat.END)) { drawerLayout.closeDrawer(GravityCompat.END); } - - // Clear the keyboard if displayed and remove the focus on the urlTextBar if it has it. - currentWebView.requestFocus(); } } @@ -2314,11 +2311,8 @@ 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) -> { - // Add a new tab. - addTab(null); - - // Load the URL. - loadUrl(linkUrl); + // Load the link URL in a new tab. + addNewTab(linkUrl); return false; }); @@ -2431,11 +2425,8 @@ 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) -> { - // Add a new tab. - addTab(null); - - // Load the URL. - loadUrl(imageUrl); + // Load the image URL in a new tab. + addNewTab(imageUrl); return false; }); @@ -3969,6 +3960,11 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook } public void addTab(View view) { + // Add a new tab with a blank URL. + addNewTab(""); + } + + private void addNewTab(String url) { // Get a handle for the tab layout and the view pager. TabLayout tabLayout = findViewById(R.id.tablayout); ViewPager webViewPager = findViewById(R.id.webviewpager); @@ -3989,7 +3985,7 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook newTab.setCustomView(R.layout.tab_custom_view); // Add the new WebView page. - webViewPagerAdapter.addPage(newTabNumber, webViewPager); + webViewPagerAdapter.addPage(newTabNumber, webViewPager, url); } public void closeTab(View view) { @@ -4305,7 +4301,7 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook } @Override - public void initializeWebView(NestedScrollWebView nestedScrollWebView, int pageNumber, ProgressBar progressBar) { + public void initializeWebView(NestedScrollWebView nestedScrollWebView, int pageNumber, ProgressBar progressBar, String url) { // Get handles for the activity views. FrameLayout rootFrameLayout = findViewById(R.id.root_framelayout); DrawerLayout drawerLayout = findViewById(R.id.drawerlayout); @@ -4458,14 +4454,14 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook registerForContextMenu(nestedScrollWebView); // Allow the downloading of files. - nestedScrollWebView.setDownloadListener((String url, String userAgent, String contentDisposition, String mimetype, long contentLength) -> { + nestedScrollWebView.setDownloadListener((String downloadUrl, String userAgent, String contentDisposition, String mimetype, long contentLength) -> { // Check if the download should be processed by an external app. if (downloadWithExternalApp) { // Download with an external app. // Create a download intent. Not specifying the action type will display the maximum number of options. Intent downloadIntent = new Intent(); // Set the URI and the MIME type. Specifying `text/html` displays a good number of options. - downloadIntent.setDataAndType(Uri.parse(url), "text/html"); + downloadIntent.setDataAndType(Uri.parse(downloadUrl), "text/html"); // Flag the intent to open in a new task. downloadIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); @@ -4478,7 +4474,7 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook // The WRITE_EXTERNAL_STORAGE permission needs to be requested. // Store the variables for future use by `onRequestPermissionsResult()`. - downloadUrl = url; + this.downloadUrl = downloadUrl; downloadContentDisposition = contentDisposition; downloadContentLength = contentLength; @@ -4495,7 +4491,7 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook } } else { // The storage permission has already been granted. // Get a handle for the download file alert dialog. - DialogFragment downloadFileDialogFragment = DownloadFileDialog.fromUrl(url, contentDisposition, contentLength); + DialogFragment downloadFileDialogFragment = DownloadFileDialog.fromUrl(downloadUrl, contentDisposition, contentLength); // Show the download file alert dialog. downloadFileDialogFragment.show(getSupportFragmentManager(), getString(R.string.download)); @@ -5472,6 +5468,17 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook } } } + } else { // This is not the first tab. + // Apply the domain settings. + applyDomainSettings(nestedScrollWebView, url, false, false); + + // Load the URL. + nestedScrollWebView.loadUrl(url, customHeaders); + + // Display the keyboard if the URL is blank. + if (url.equals("")) { + inputMethodManager.showSoftInput(urlEditText, 0); + } } } } \ No newline at end of file diff --git a/app/src/main/java/com/stoutner/privacybrowser/adapters/WebViewPagerAdapter.java b/app/src/main/java/com/stoutner/privacybrowser/adapters/WebViewPagerAdapter.java index 0a5aff1f..256e6542 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/adapters/WebViewPagerAdapter.java +++ b/app/src/main/java/com/stoutner/privacybrowser/adapters/WebViewPagerAdapter.java @@ -93,9 +93,9 @@ public class WebViewPagerAdapter extends FragmentPagerAdapter { return position; } - public void addPage(int pageNumber, ViewPager webViewPager) { + public void addPage(int pageNumber, ViewPager webViewPager, String url) { // Add a new page. - webViewFragmentsList.add(WebViewTabFragment.createPage(pageNumber)); + webViewFragmentsList.add(WebViewTabFragment.createPage(pageNumber, url)); // Update the view pager. notifyDataSetChanged(); diff --git a/app/src/main/java/com/stoutner/privacybrowser/fragments/WebViewTabFragment.java b/app/src/main/java/com/stoutner/privacybrowser/fragments/WebViewTabFragment.java index 3ffa8aa4..413910dc 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/fragments/WebViewTabFragment.java +++ b/app/src/main/java/com/stoutner/privacybrowser/fragments/WebViewTabFragment.java @@ -40,7 +40,7 @@ public class WebViewTabFragment extends Fragment { // The public interface is used to send information back to the parent activity. public interface NewTabListener { - void initializeWebView(NestedScrollWebView nestedScrollWebView, int pageNumber, ProgressBar progressBar); + void initializeWebView(NestedScrollWebView nestedScrollWebView, int pageNumber, ProgressBar progressBar, String url); } // The new tab listener is used in `onAttach()` and `onCreateView()`. @@ -55,12 +55,13 @@ public class WebViewTabFragment extends Fragment { newTabListener = (NewTabListener) context; } - public static WebViewTabFragment createPage(int pageNumber) { + public static WebViewTabFragment createPage(int pageNumber, String url) { // Create a bundle. Bundle bundle = new Bundle(); - // Store the page number in the bundle. + // Store the page number and URL in the bundle. bundle.putInt("page_number", pageNumber); + bundle.putString("url", url); // Create a new instance of the WebView tab fragment. WebViewTabFragment webViewTabFragment = new WebViewTabFragment(); @@ -82,6 +83,7 @@ public class WebViewTabFragment extends Fragment { // Get the variables from the arguments int pageNumber = arguments.getInt("page_number"); + String url = arguments.getString("url"); // Inflate the tab's WebView. Setting false at the end of inflater.inflate does not attach the inflated layout as a child of container. The fragment will take care of attaching the root automatically. View newPageView = layoutInflater.inflate(R.layout.webview_framelayout, container, false); @@ -94,7 +96,7 @@ public class WebViewTabFragment extends Fragment { nestedScrollWebView.setWebViewFragmentId(fragmentId); // Request the main activity initialize the WebView. - newTabListener.initializeWebView(nestedScrollWebView, pageNumber, progressBar); + newTabListener.initializeWebView(nestedScrollWebView, pageNumber, progressBar, url); // Return the new page view. return newPageView; diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index f99913cd..981c912a 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -394,7 +394,8 @@ API Build: Sicherheits-Patch: - WebView: + WebView-Anbieter: + WebView-Version: Orbot: OpenKeychain: EasyList: diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml index 8997986a..c86f2cba 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -394,7 +394,8 @@ API Versión de compilación: Parche de seguridad: - WebView: + Proveedor de WebView: + Versión de WebView: Orbot: OpenKeychain: EasyList: diff --git a/app/src/main/res/values-it/strings.xml b/app/src/main/res/values-it/strings.xml index d7ff9e72..5b48a7cd 100644 --- a/app/src/main/res/values-it/strings.xml +++ b/app/src/main/res/values-it/strings.xml @@ -393,7 +393,8 @@ API Build: Patch si sicurezza: - WebView: + Provider di WebView: + Versione di WebView: Orbot: OpenKeychain: EasyList: diff --git a/app/src/main/res/values-ru/strings.xml b/app/src/main/res/values-ru/strings.xml index 3ff1b976..adec9671 100644 --- a/app/src/main/res/values-ru/strings.xml +++ b/app/src/main/res/values-ru/strings.xml @@ -388,7 +388,8 @@ API Сборка: Патч безопасности: - WebView: + Провайдер WebView: + Версия WebView: Orbot: OpenKeychain: EasyList: diff --git a/app/src/main/res/values-tr/strings.xml b/app/src/main/res/values-tr/strings.xml index 942b03f6..9e320807 100644 --- a/app/src/main/res/values-tr/strings.xml +++ b/app/src/main/res/values-tr/strings.xml @@ -387,7 +387,6 @@ API Derleme: Güvenlik Yaması: - Web Görünümü: Orbot: OpenKeychain: EasyList: diff --git a/fastlane/metadata/android/de-DE/full_description.txt b/fastlane/metadata/android/de-DE/full_description.txt index 762c83ba..b9b9f3c2 100644 --- a/fastlane/metadata/android/de-DE/full_description.txt +++ b/fastlane/metadata/android/de-DE/full_description.txt @@ -6,7 +6,7 @@ Privacy Browser verfolgt zwei grundsätzliche Ziele: Die meisten Browser plaudern still und heimlich jede Menge Informationen an Websiten aus, welche genutzt werden können, um deren Benutzer zu verfolgen und deren Privatsphäre zu kompromittieren. Webseiten und Werbenetzwerke nutzen Technologien wie JavaScript, Cookies, DOM-Speicher, User-Agents und andere, um jeden einzelnen Browser-Benutzer eindeutig zu identifizieren und ihn zwischen seinen Besuchen und sogar quer durch das Internet zu verfolgen. -In contrast, privacy sensitive features are disabled by default in Privacy Browser. Wenn Webseiten jedoch spezielle Funktionen benötigen, um zu funktionieren, können diese beim Besuch der betreffenden Seite bewusst einmalig aktiviert werden. Darüber hinaus können spezielle Einstellungen für bestimmte Domains auch abgespeichert werden, damit sie bei jedem Besuch der betreffenden Seite automatisch aktiviert und danach wieder deaktiviert werden. +In Privacy Browser hingegen sind Funktionen, welche die Privatsphäre gefährden, grundsätzlich deaktiviert. Wenn Webseiten jedoch spezielle Funktionen benötigen, um zu funktionieren, können diese beim Besuch der betreffenden Seite bewusst einmalig aktiviert werden. Darüber hinaus können spezielle Einstellungen für bestimmte Domains auch abgespeichert werden, damit sie bei jedem Besuch der betreffenden Seite automatisch aktiviert und danach wieder deaktiviert werden. Privacy Browser nutzt aktuell Android's eingebaute WebView-Komponente, um Webseiten anzuzeigen. Er funktioniert daher am Besten, wenn die letzte Version von WebView installiert ist (siehe https://www.stoutner.com/privacy-browser/common-settings/webview/). Ab Version 4.x wird Privacy Browser eine abgeleitete Version von Android's WebView - Privacy WebView genannt - verwenden, um erweiterte Privatsphäre-Funktionen zu bieten. @@ -16,4 +16,4 @@ Features: • Integrierter EasyList-Werbeblocker • TOR-Proxy-Unterstützung mittels Orbot • Verankerung von SSL-Zertifikaten (Pinning) -• Import/Export von Einstellungen und Lesezeichen \ No newline at end of file +• Import/export von Einstellungen und Lesezeichen \ No newline at end of file -- 2.43.0