close external tabs on back

      Bug: 4466495
      close externally created tabs
      when the back button is used and no further
      back history is available

Change-Id: If605474d929fb759226a1e1f4125bfaab43e6653
diff --git a/src/com/android/browser/IntentHandler.java b/src/com/android/browser/IntentHandler.java
index 6ed5b72..c76197d 100644
--- a/src/com/android/browser/IntentHandler.java
+++ b/src/com/android/browser/IntentHandler.java
@@ -17,10 +17,6 @@
 
 package com.android.browser;
 
-import com.android.browser.search.SearchEngine;
-import com.android.common.Search;
-import com.android.common.speech.LoggingEvents;
-
 import android.app.Activity;
 import android.app.SearchManager;
 import android.content.ContentResolver;
@@ -36,6 +32,10 @@
 import android.text.TextUtils;
 import android.util.Patterns;
 
+import com.android.browser.search.SearchEngine;
+import com.android.common.Search;
+import com.android.common.speech.LoggingEvents;
+
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.Map;
@@ -187,6 +187,9 @@
                     Tab tab = mController.openTab(urlData);
                     if (tab != null) {
                         tab.setAppId(appId);
+                        if ((intent.getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT) != 0) {
+                            tab.setCloseOnBack(true);
+                        }
                     }
                 }
             } else {