introduce tab IDs

    Tabs are identified by IDs now, instead of their position
    Refactored the save/restore code

Change-Id: I7133d55831201d097dc19ec938a85e7085f36749
diff --git a/src/com/android/browser/TabBar.java b/src/com/android/browser/TabBar.java
index 31c0740..a574d26 100644
--- a/src/com/android/browser/TabBar.java
+++ b/src/com/android/browser/TabBar.java
@@ -155,7 +155,7 @@
             TabView tv = buildTabView(tab);
             mTabs.addTab(tv);
         }
-        mTabs.setSelectedTab(mTabControl.getCurrentIndex());
+        mTabs.setSelectedTab(mTabControl.getCurrentPosition());
     }
 
     @Override
@@ -210,11 +210,12 @@
             } else {
                 showUrlBar();
             }
-        } else {
+        } else if (view instanceof TabView) {
+            final Tab tab = ((TabView) view).mTab;
             int ix = mTabs.getChildIndex(view);
             if (ix >= 0) {
                 mTabs.setSelectedTab(ix);
-                mUiController.switchToTab(ix);
+                mUiController.switchToTab(tab);
             }
         }
     }
@@ -601,7 +602,7 @@
     // TabChangeListener implementation
 
     public void onSetActiveTab(Tab tab) {
-        mTabs.setSelectedTab(mTabControl.getTabIndex(tab));
+        mTabs.setSelectedTab(mTabControl.getTabPosition(tab));
         TabView tv = mTabMap.get(tab);
         if (tv != null) {
             tv.setProgress(tv.mTab.getLoadProgress());