Move Tab layout code to UI

Change-Id: Ic2d81345883bba22329b4f805c44a68b14e174e3
diff --git a/src/com/android/browser/BaseUi.java b/src/com/android/browser/BaseUi.java
index 5f8944f..2b3a9e5 100644
--- a/src/com/android/browser/BaseUi.java
+++ b/src/com/android/browser/BaseUi.java
@@ -427,6 +427,24 @@
         mainView.setEmbeddedTitleBar(null);
     }
 
+    @Override
+    public void onSetWebView(Tab tab, WebView webView) {
+        View container = tab.getViewContainer();
+        if (container == null) {
+            // The tab consists of a container view, which contains the main
+            // WebView, as well as any other UI elements associated with the tab.
+            container = mActivity.getLayoutInflater().inflate(R.layout.tab,
+                    null);
+            tab.setViewContainer(container);
+        }
+        if (tab.getWebView() != webView) {
+            // Just remove the old one.
+            FrameLayout wrapper =
+                    (FrameLayout) container.findViewById(R.id.webview_wrapper);
+            wrapper.removeView(tab.getWebView());
+        }
+    }
+
     /**
      * create a sub window container and webview for the tab
      * Note: this methods operates through side-effects for now
diff --git a/src/com/android/browser/Controller.java b/src/com/android/browser/Controller.java
index acd76dd..b9bd9d7 100644
--- a/src/com/android/browser/Controller.java
+++ b/src/com/android/browser/Controller.java
@@ -317,6 +317,11 @@
     }
 
     @Override
+    public void onSetWebView(Tab tab, WebView view) {
+        mUi.onSetWebView(tab, view);
+    }
+
+    @Override
     public void createSubWindow(Tab tab) {
         endActionMode();
         WebView mainView = tab.getWebView();
diff --git a/src/com/android/browser/Tab.java b/src/com/android/browser/Tab.java
index 3647a20..8a3bc27 100644
--- a/src/com/android/browser/Tab.java
+++ b/src/com/android/browser/Tab.java
@@ -85,7 +85,7 @@
     // The Geolocation permissions prompt
     private GeolocationPermissionsPrompt mGeolocationPermissionsPrompt;
     // Main WebView wrapper
-    private LinearLayout mContainer;
+    private View mContainer;
     // Main WebView
     private WebView mMainView;
     // Subwindow container
@@ -128,8 +128,6 @@
     // the lock icon type and previous lock icon type for the tab
     private int mLockIconType;
     private int mPrevLockIconType;
-    // Inflation service for making subwindows.
-    private final LayoutInflater mInflateService;
     // The listener that gets invoked when a download is started from the
     // mMainView
     private final DownloadListener mDownloadListener;
@@ -1205,11 +1203,6 @@
         mInPageLoad = false;
         mInForeground = false;
 
-        mInflateService = LayoutInflater.from(mActivity);
-
-        // The tab consists of a container view, which contains the main
-        // WebView, as well as any other UI elements associated with the tab.
-        mContainer = (LinearLayout) mInflateService.inflate(R.layout.tab, null);
 
         mDownloadListener = new DownloadListener() {
             public void onDownloadStart(String url, String userAgent,
@@ -1246,16 +1239,14 @@
         if (mMainView == w) {
             return;
         }
+
         // If the WebView is changing, the page will be reloaded, so any ongoing
         // Geolocation permission requests are void.
         if (mGeolocationPermissionsPrompt != null) {
             mGeolocationPermissionsPrompt.hide();
         }
 
-        // Just remove the old one.
-        FrameLayout wrapper =
-                (FrameLayout) mContainer.findViewById(R.id.webview_wrapper);
-        wrapper.removeView(mMainView);
+        mWebViewController.onSetWebView(this, w);
 
         // set the new one
         mMainView = w;
@@ -1451,6 +1442,10 @@
         return mMainView;
     }
 
+    void setViewContainer(View container) {
+        mContainer = container;
+    }
+
     View getViewContainer() {
         return mContainer;
     }
diff --git a/src/com/android/browser/UI.java b/src/com/android/browser/UI.java
index 3a8a5cd..e7f67f2 100644
--- a/src/com/android/browser/UI.java
+++ b/src/com/android/browser/UI.java
@@ -58,6 +58,8 @@
 
     public void attachTab(Tab tab);
 
+    public void onSetWebView(Tab tab, WebView view);
+
     public void createSubWindow(Tab tab, WebView subWebView);
 
     public void attachSubWindow(View subContainer);
diff --git a/src/com/android/browser/WebViewController.java b/src/com/android/browser/WebViewController.java
index eeeee18..11a6959 100644
--- a/src/com/android/browser/WebViewController.java
+++ b/src/com/android/browser/WebViewController.java
@@ -42,6 +42,8 @@
 
     WebViewFactory getWebViewFactory();
 
+    void onSetWebView(Tab tab, WebView view);
+
     void createSubWindow(Tab tab);
 
     void onPageStarted(Tab tab, WebView view, String url, Bitmap favicon);