handle preload tab when max count is reached

       Bug: 5066968
       when opening the pre-load tab, check against max count
       if max count is already reached, replace the least
       used tab with the pre-loaded tab; it's back/forward
       history will be lost

Change-Id: I091b6b066a3e990f330be458d4aff72f62c8de38
diff --git a/src/com/android/browser/Controller.java b/src/com/android/browser/Controller.java
index 92682c1..b3be618 100644
--- a/src/com/android/browser/Controller.java
+++ b/src/com/android/browser/Controller.java
@@ -2159,6 +2159,13 @@
                 return null;
             }
         }
+        // check tab count and make room for new tab
+        if (!mTabControl.canCreateNewTab()) {
+            Tab leastUsed = mTabControl.getLeastUsedTab(getCurrentTab());
+            if (leastUsed != null) {
+                closeTab(leastUsed);
+            }
+        }
         Tab t = tabControl.getTab();
         mTabControl.addPreloadedTab(t);
         addTab(t);