New tab flow through Bookmarks/History screen

Change-Id: I0f21279fea33582229f16f37bf813ad1fca15fc2
diff --git a/src/com/android/browser/BrowserActivity.java b/src/com/android/browser/BrowserActivity.java
index 40ada94..d6f7177 100644
--- a/src/com/android/browser/BrowserActivity.java
+++ b/src/com/android/browser/BrowserActivity.java
@@ -1367,7 +1367,7 @@
                 break;
 
             case R.id.bookmarks_menu_id:
-                bookmarksOrHistoryPicker(false);
+                bookmarksOrHistoryPicker(false, false);
                 break;
 
             case R.id.active_tabs_menu_id:
@@ -1451,7 +1451,7 @@
                 break;
 
             case R.id.classic_history_menu_id:
-                bookmarksOrHistoryPicker(true);
+                bookmarksOrHistoryPicker(true, false);
                 break;
 
             case R.id.title_bar_share_page_url:
@@ -1752,7 +1752,7 @@
                             new MenuItem.OnMenuItemClickListener() {
                                 public boolean onMenuItemClick(MenuItem item) {
                                     final Tab parent = mTabControl.getCurrentTab();
-                                    final Tab newTab = openTab(extra);
+                                    final Tab newTab = openTab(extra, false);
                                     if (newTab != parent) {
                                         parent.addChildTab(newTab);
                                     }
@@ -1895,8 +1895,8 @@
         }
     }
 
-    private Tab openTab(String url) {
-        if (mSettings.openInBackground()) {
+    private Tab openTab(String url, boolean forceForeground) {
+        if (mSettings.openInBackground() && !forceForeground) {
             Tab t = mTabControl.createNewTab();
             if (t != null) {
                 WebView view = t.getWebView();
@@ -2239,7 +2239,7 @@
                     return true;
                 } else if (mCustomView == null && mActiveTabsPage == null
                         && event.isLongPress()) {
-                    bookmarksOrHistoryPicker(true);
+                    bookmarksOrHistoryPicker(true, false);
                     return true;
                 }
                 break;
@@ -2789,7 +2789,7 @@
         }
 
         if (mMenuIsDown) {
-            openTab(url);
+            openTab(url, false);
             closeOptionsMenu();
             return true;
         }
@@ -3732,10 +3732,12 @@
                     String data = intent.getAction();
                     Bundle extras = intent.getExtras();
                     if (extras != null && extras.getBoolean("new_window", false)) {
-                        openTab(data);
+                        openTab(data, false);
+                    } else if ((extras != null) &&
+                            extras.getBoolean(CombinedBookmarkHistoryActivity.NEWTAB_MODE)) {
+                        openTab(data, true);
                     } else {
-                        final Tab currentTab =
-                                mTabControl.getCurrentTab();
+                        final Tab currentTab = mTabControl.getCurrentTab();
                         dismissSubWindow(currentTab);
                         if (data != null && data.length() != 0) {
                             loadUrl(getTopWindow(), data);
@@ -3842,7 +3844,7 @@
      * @param startWithHistory If true, open starting on the history tab.
      *                         Otherwise, start with the bookmarks tab.
      */
-    /* package */ void bookmarksOrHistoryPicker(boolean startWithHistory) {
+    /* package */ void bookmarksOrHistoryPicker(boolean startWithHistory, boolean newTabMode) {
         WebView current = mTabControl.getCurrentWebView();
         if (current == null) {
             return;
@@ -3877,6 +3879,9 @@
             intent.putExtra(CombinedBookmarkHistoryActivity.STARTING_TAB,
                     CombinedBookmarkHistoryActivity.HISTORY_TAB);
         }
+        if (newTabMode) {
+            intent.putExtra(CombinedBookmarkHistoryActivity.NEWTAB_MODE, true);
+        }
         startActivityForResult(intent, COMBO_PAGE);
     }