]> gitweb.stoutner.com Git - PrivacyBrowserAndroid.git/blobdiff - app/src/main/java/com/stoutner/privacybrowser/adapters/WebViewPagerAdapter.java
Make the context menu Open in New Tab load the new tab in the background. https...
[PrivacyBrowserAndroid.git] / app / src / main / java / com / stoutner / privacybrowser / adapters / WebViewPagerAdapter.java
index 256e654236d7fe5b0ed7fdb0e7680c9882d0b0bb..5947df4466ec147802ec0762f8b66ec9eba52bcc 100644 (file)
@@ -89,11 +89,18 @@ public class WebViewPagerAdapter extends FragmentPagerAdapter {
             i++;
         }
 
+        // Set the position to be the last tab if it is not found.
+        // Sometimes there is a race condition in populating the webView fragments list when resuming Privacy Browser and displaying an SSL certificate error while loading a new intent.
+        // In that case, the last tab should be the one it is looking for.
+        if (position == -1) {
+            position = webViewFragmentsList.size() - 1;
+        }
+
         // Return the position.
         return position;
     }
 
-    public void addPage(int pageNumber, ViewPager webViewPager, String url) {
+    public void addPage(int pageNumber, ViewPager webViewPager, String url, boolean moveToTab) {
         // Add a new page.
         webViewFragmentsList.add(WebViewTabFragment.createPage(pageNumber, url));
 
@@ -101,7 +108,7 @@ public class WebViewPagerAdapter extends FragmentPagerAdapter {
         notifyDataSetChanged();
 
         // Move to the new page if it isn't the first one.
-        if (pageNumber > 0) {
+        if (pageNumber > 0 && moveToTab) {
             webViewPager.setCurrentItem(pageNumber);
         }
     }