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/Tab.java b/src/com/android/browser/Tab.java
index a251212..39bf49c 100644
--- a/src/com/android/browser/Tab.java
+++ b/src/com/android/browser/Tab.java
@@ -145,6 +145,8 @@
     // Application identifier used to find tabs that another application wants
     // to reuse.
     private String mAppId;
+    // flag to indicate if tab should be closed on back
+    private boolean mCloseOnBack;
     // Keep the original url around to avoid killing the old WebView if the url
     // has not changed.
     // Error console for the tab
@@ -225,6 +227,7 @@
     static final String APPID = "appid";
     static final String INCOGNITO = "privateBrowsingEnabled";
     static final String USERAGENT = "useragent";
+    static final String CLOSEFLAG = "closeOnBack";
 
     // -------------------------------------------------------------------------
 
@@ -1785,6 +1788,14 @@
         mAppId = id;
     }
 
+    boolean closeOnBack() {
+        return mCloseOnBack;
+    }
+
+    void setCloseOnBack(boolean close) {
+        mCloseOnBack = close;
+    }
+
     String getUrl() {
         return UrlUtils.filteredUrl(mCurrentState.mUrl);
     }
@@ -1895,6 +1906,7 @@
         if (mAppId != null) {
             mSavedState.putString(APPID, mAppId);
         }
+        mSavedState.putBoolean(CLOSEFLAG, mCloseOnBack);
         // Remember the parent tab so the relationship can be restored.
         if (mParent != null) {
             mSavedState.putLong(PARENTTAB, mParent.mId);
@@ -1916,6 +1928,7 @@
         // This will maintain the app id, original url and close-on-exit values.
         mId = b.getLong(ID);
         mAppId = b.getString(APPID);
+        mCloseOnBack = b.getBoolean(CLOSEFLAG);
         if (b.getBoolean(USERAGENT)
                 != mSettings.hasDesktopUseragent(getWebView())) {
             mSettings.toggleDesktopUseragent(getWebView());