Avoid showing previous tab when closing an app tab

      Bug: 5188145
      skip setActiveTab when closing a tab launched from an app
      set active tab in onResume

Change-Id: If602358a61690f15fe2e81a6b3d62d51ad15e16d
diff --git a/src/com/android/browser/Controller.java b/src/com/android/browser/Controller.java
index 84d7e36..e0bb6f2 100644
--- a/src/com/android/browser/Controller.java
+++ b/src/com/android/browser/Controller.java
@@ -2296,6 +2296,10 @@
 
     @Override
     public void closeCurrentTab() {
+        closeCurrentTab(false);
+    }
+
+    protected void closeCurrentTab(boolean andQuit) {
         if (mTabControl.getTabCount() == 1) {
             mCrashRecoveryHandler.clearState();
             mTabControl.removeTab(getCurrentTab());
@@ -2311,7 +2315,10 @@
                 newTab = mTabControl.getTab(pos - 1);
             }
         }
-        if (switchToTab(newTab)) {
+        if (andQuit) {
+            mTabControl.setCurrentTab(newTab);
+            closeTab(current);
+        } else if (switchToTab(newTab)) {
             // Close window
             closeTab(current);
         }
@@ -2411,7 +2418,7 @@
                 closeTab(current);
             } else {
                 if ((current.getAppId() != null) || current.closeOnBack()) {
-                    closeCurrentTab();
+                    closeCurrentTab(true);
                 }
                 /*
                  * Instead of finishing the activity, simply push this to the back