Merge "fix close last page bug"
diff --git a/res/drawable-hdpi/ic_snapshot.png b/res/drawable-hdpi/ic_snapshot.png
new file mode 100644
index 0000000..a621cb4
--- /dev/null
+++ b/res/drawable-hdpi/ic_snapshot.png
Binary files differ
diff --git a/res/drawable-mdpi/ic_snapshot.png b/res/drawable-mdpi/ic_snapshot.png
new file mode 100644
index 0000000..6054acb
--- /dev/null
+++ b/res/drawable-mdpi/ic_snapshot.png
Binary files differ
diff --git a/res/drawable-mdpi/ic_ua_android.png b/res/drawable-mdpi/ic_ua_android.png
deleted file mode 100644
index 4f7aa45..0000000
--- a/res/drawable-mdpi/ic_ua_android.png
+++ /dev/null
Binary files differ
diff --git a/res/drawable-mdpi/ic_ua_desktop.png b/res/drawable-mdpi/ic_ua_desktop.png
deleted file mode 100644
index 4e2f5c2..0000000
--- a/res/drawable-mdpi/ic_ua_desktop.png
+++ /dev/null
Binary files differ
diff --git a/res/layout/help_dialog_useragent_switcher.xml b/res/layout/help_dialog_useragent_switcher.xml
deleted file mode 100644
index cc29a2d..0000000
--- a/res/layout/help_dialog_useragent_switcher.xml
+++ /dev/null
@@ -1,37 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2011 The Android Open Source Project
-
-     Licensed under the Apache License, Version 2.0 (the "License");
-     you may not use this file except in compliance with the License.
-     You may obtain a copy of the License at
-
-          http://www.apache.org/licenses/LICENSE-2.0
-
-     Unless required by applicable law or agreed to in writing, software
-     distributed under the License is distributed on an "AS IS" BASIS,
-     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-     See the License for the specific language governing permissions and
-     limitations under the License.
--->
-
-<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
-    android:layout_width="wrap_content"
-    android:layout_height="wrap_content"
-    android:orientation="vertical">
-
-    <TextView
-        android:layout_width="wrap_content"
-        android:layout_height="wrap_content"
-        android:text="@string/help_useragent_switcher" />
-
-    <ImageView
-        android:layout_width="wrap_content"
-        android:layout_height="wrap_content"
-        android:src="@drawable/help_useragent_tablet" />
-
-    <ImageView
-        android:layout_width="wrap_content"
-        android:layout_height="wrap_content"
-        android:src="@drawable/help_useragent_laptop" />
-
-</LinearLayout>
diff --git a/res/layout/tab_title.xml b/res/layout/tab_title.xml
index e2c6d0a..fcae2bc 100644
--- a/res/layout/tab_title.xml
+++ b/res/layout/tab_title.xml
@@ -31,6 +31,13 @@
         android:src="@drawable/ic_incognito_holo_dark"
         android:visibility="gone" />
     <ImageView
+        android:id="@+id/snapshot"
+        android:layout_width="wrap_content"
+        android:layout_height="match_parent"
+        android:gravity="center_vertical"
+        android:src="@drawable/ic_snapshot"
+        android:visibility="gone" />
+    <ImageView
         android:id="@+id/favicon"
         android:layout_width="20dip"
         android:layout_height="20dip"
diff --git a/res/menu/ua_switcher.xml b/res/menu/ua_switcher.xml
new file mode 100644
index 0000000..5076fb2
--- /dev/null
+++ b/res/menu/ua_switcher.xml
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2011 The Android Open Source Project
+
+     Licensed under the Apache License, Version 2.0 (the "License");
+     you may not use this file except in compliance with the License.
+     You may obtain a copy of the License at
+
+          http://www.apache.org/licenses/LICENSE-2.0
+
+     Unless required by applicable law or agreed to in writing, software
+     distributed under the License is distributed on an "AS IS" BASIS,
+     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+     See the License for the specific language governing permissions and
+     limitations under the License.
+-->
+
+<menu xmlns:android="http://schemas.android.com/apk/res/android">
+    <item
+        android:id="@+id/ua_mobile_menu_id"
+        android:checkable="true"
+        android:title="@string/ua_switcher_mobile" />
+    <item
+        android:id="@+id/ua_desktop_menu_id"
+        android:checkable="true"
+        android:title="@string/ua_switcher_desktop" />
+</menu>
+
diff --git a/res/values/strings.xml b/res/values/strings.xml
index e51538c..b86edb5 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -665,13 +665,6 @@
     <!-- Summary for the fullscreen lab feature [CHAR LIMIT=120] -->
     <string name="pref_lab_fullscreen_summary">
       Use fullscreen mode to hide the status bar.</string>
-    <!-- Title for the useragent switcher lab feature [CHAR LIMIT=40] -->
-    <string name="pref_enable_useragent_switcher">Useragent Switcher</string>
-    <!-- Summary for the useragent switcher lab feature [CHAR LIMIT=120] -->
-    <string name="pref_enable_useragent_switcher_summary">Toggle between the tablet and desktop versions of a site</string>
-    <!-- Text explaining how to use the useragent switcher lab feature [CHAR LIMIT=none] -->
-    <string name="help_useragent_switcher">Tap on the Android or laptop icon to toggle between the tablet and desktop versions of a site.</string>
-
     <!-- Title for a dialog displayed when the browser has a data connectivity
             problem -->
     <string name="browserFrameNetworkErrorLabel">Data connectivity problem</string>
@@ -1016,4 +1009,8 @@
     <string name="preview">Preview:</string>
     <!-- Name for the user's unsynced, local bookmarks [CHAR LIMIT=50] -->
     <string name="local_bookmarks">Local</string>
+    <!-- Popup menu option that allows the user to select the mobile version of a webpage [CHAR LIMIT=50] -->
+    <string name="ua_switcher_mobile">Mobile</string>
+    <!-- Popup menu option that allows the user to select the desktop version of a webpage [CHAR LIMIT=50] -->
+    <string name="ua_switcher_desktop">Desktop</string>
 </resources>
diff --git a/res/xml-sw600dp/lab_preferences.xml b/res/xml-sw600dp/lab_preferences.xml
index c858c38..705f740 100644
--- a/res/xml-sw600dp/lab_preferences.xml
+++ b/res/xml-sw600dp/lab_preferences.xml
@@ -35,9 +35,4 @@
         android:title="@string/pref_use_instant_search"
         android:summary="@string/pref_use_instant_search_summary" />
 
-    <CheckBoxPreference
-        android:key="enable_useragent_switcher"
-        android:defaultValue="false"
-        android:title="@string/pref_enable_useragent_switcher"
-        android:summary="@string/pref_enable_useragent_switcher_summary" />
 </PreferenceScreen>
diff --git a/src/com/android/browser/BrowserSettings.java b/src/com/android/browser/BrowserSettings.java
index 46d47b0..101effa 100644
--- a/src/com/android/browser/BrowserSettings.java
+++ b/src/com/android/browser/BrowserSettings.java
@@ -16,11 +16,6 @@
 
 package com.android.browser;
 
-import com.android.browser.homepages.HomeProvider;
-import com.android.browser.provider.BrowserProvider;
-import com.android.browser.search.SearchEngine;
-import com.android.browser.search.SearchEngines;
-
 import android.app.ActivityManager;
 import android.content.ContentResolver;
 import android.content.Context;
@@ -43,6 +38,11 @@
 import android.webkit.WebView;
 import android.webkit.WebViewDatabase;
 
+import com.android.browser.homepages.HomeProvider;
+import com.android.browser.provider.BrowserProvider;
+import com.android.browser.search.SearchEngine;
+import com.android.browser.search.SearchEngines;
+
 import java.lang.ref.WeakReference;
 import java.util.Iterator;
 import java.util.LinkedList;
@@ -165,7 +165,7 @@
         settings.setAutoFillProfile(getAutoFillProfile());
 
         String ua = mCustomUserAgents.get(settings);
-        if (enableUseragentSwitcher() && ua != null) {
+        if (ua != null) {
             settings.setUserAgentString(ua);
         } else {
             settings.setUserAgentString(USER_AGENTS[getUserAgent()]);
@@ -606,10 +606,6 @@
         return mPrefs.getBoolean(PREF_FULLSCREEN, false);
     }
 
-    public boolean enableUseragentSwitcher() {
-        return mPrefs.getBoolean(PREF_ENABLE_USERAGENT_SWITCHER, false);
-    }
-
     // -----------------------------
     // getter/setters for privacy_security_preferences.xml
     // -----------------------------
diff --git a/src/com/android/browser/Controller.java b/src/com/android/browser/Controller.java
index 6a951c2..986b617 100644
--- a/src/com/android/browser/Controller.java
+++ b/src/com/android/browser/Controller.java
@@ -1496,7 +1496,6 @@
                 final MenuItem counter = menu.findItem(R.id.dump_counters_menu_id);
                 counter.setVisible(showDebugSettings);
                 counter.setEnabled(showDebugSettings);
-                menu.findItem(R.id.freeze_tab_menu_id).setVisible(showDebugSettings);
 
                 final MenuItem newtab = menu.findItem(R.id.new_tab_menu_id);
                 newtab.setEnabled(getTabControl().canCreateNewTab());
@@ -1605,21 +1604,20 @@
 
             case R.id.freeze_tab_menu_id:
                 // TODO: Show error messages
-                WebView source = getCurrentTopWebView();
+                Tab source = getTabControl().getCurrentTab();
                 if (source == null) break;
-                Tab t = createNewTab(false, true, false);
-                if (t == null) break;
-                WebView pinned = t.getWebView();
-                if (pinned == null) break;
+                Tab snapshot = createNewTab(false, false, false);
+                if (snapshot == null) break;
                 try {
                     ByteArrayOutputStream bos = new ByteArrayOutputStream();
-                    source.saveViewState(bos);
+                    source.saveSnapshot(bos);
                     ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
-                    pinned.loadViewState(bis);
+                    snapshot.loadSnapshot(bis);
+                    mUi.onTabDataChanged(snapshot);
                     bis.close();
                     bos.close();
+                    setActiveTab(snapshot);
                 } catch (IOException e) {
-                    closeTab(t);
                 }
                 break;
 
diff --git a/src/com/android/browser/PreferenceKeys.java b/src/com/android/browser/PreferenceKeys.java
index cff9f70..f7230df 100644
--- a/src/com/android/browser/PreferenceKeys.java
+++ b/src/com/android/browser/PreferenceKeys.java
@@ -78,7 +78,6 @@
     static final String PREF_USE_MOST_VISITED_HOMEPAGE = "use_most_visited_homepage";
     static final String PREF_USE_INSTANT_SEARCH = "use_instant_search";
     static final String PREF_FULLSCREEN = "fullscreen";
-    static final String PREF_ENABLE_USERAGENT_SWITCHER = "enable_useragent_switcher";
 
     // ----------------------
     // Keys for privacy_security_preferences.xml
diff --git a/src/com/android/browser/Tab.java b/src/com/android/browser/Tab.java
index b0a991a..95c7850 100644
--- a/src/com/android/browser/Tab.java
+++ b/src/com/android/browser/Tab.java
@@ -16,9 +16,6 @@
 
 package com.android.browser;
 
-import com.android.browser.homepages.HomeProvider;
-import com.android.common.speech.LoggingEvents;
-
 import android.app.Activity;
 import android.app.AlertDialog;
 import android.app.SearchManager;
@@ -28,6 +25,7 @@
 import android.content.DialogInterface.OnCancelListener;
 import android.content.Intent;
 import android.graphics.Bitmap;
+import android.graphics.Bitmap.CompressFormat;
 import android.graphics.BitmapFactory;
 import android.net.Uri;
 import android.net.http.SslError;
@@ -60,6 +58,15 @@
 import android.widget.TextView;
 import android.widget.Toast;
 
+import com.android.browser.homepages.HomeProvider;
+import com.android.common.speech.LoggingEvents;
+
+import java.io.ByteArrayOutputStream;
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.Iterator;
@@ -135,6 +142,7 @@
     private DataController mDataController;
     // State of the auto-login request.
     private DeviceAccountLogin mDeviceAccountLogin;
+    private boolean mIsSnapshot = false;
 
     // AsyncTask for downloading touch icons
     DownloadTouchIcon mTouchIconLoader;
@@ -1475,6 +1483,10 @@
      * @param child the Tab that was created from this Tab
      */
     void addChildTab(Tab child) {
+        if (mIsSnapshot) {
+            throw new IllegalStateException(
+                    "Snapshot tabs cannot have child tabs!");
+        }
         if (mChildren == null) {
             mChildren = new Vector<Tab>();
         }
@@ -1739,10 +1751,7 @@
         }
 
         mSavedState = new Bundle();
-        final WebBackForwardList list = mMainView.saveState(mSavedState);
-
-        // Store some extra info for displaying the tab in the picker.
-        final WebHistoryItem item = list != null ? list.getCurrentItem() : null;
+        mMainView.saveState(mSavedState);
 
         mSavedState.putLong(ID, mId);
         mSavedState.putString(CURRURL, mCurrentState.mUrl);
@@ -1807,4 +1816,101 @@
         return mScreenshot;
     }
 
+    public boolean isSnapshot() {
+        return mIsSnapshot;
+    }
+
+    public boolean loadSnapshot(InputStream rstream) {
+        if (rstream == null) {
+            mIsSnapshot = false;
+            if (mMainView != null) {
+                mMainView.clearViewState();
+            }
+            return true;
+        }
+        DataInputStream stream = new DataInputStream(rstream);
+        if (!readTabInfo(stream)) {
+            return false;
+        }
+        if (!mMainView.loadViewState(stream)) {
+            return false;
+        }
+        mIsSnapshot = true;
+        return true;
+    }
+
+    public boolean saveSnapshot(OutputStream rstream) {
+        if (rstream == null) return false;
+        if (mMainView == null) return false;
+        DataOutputStream stream = new DataOutputStream(rstream);
+        if (saveTabInfo(stream)) {
+            return mMainView.saveViewState(stream);
+        }
+        return false;
+    }
+
+    private boolean readTabInfo(DataInputStream stream) {
+        try {
+            PageState state = new PageState(mActivity, false);
+            state.mTitle = stream.readUTF();
+            if (state.mTitle.length() == 0) {
+                state.mTitle = null;
+            }
+            state.mUrl = stream.readUTF();
+            int faviconLen = stream.readInt();
+            if (faviconLen > 0) {
+                byte[] data = new byte[faviconLen];
+                int read = stream.read(data);
+                if (read != faviconLen) {
+                    throw new IOException("Read didn't match expected len!"
+                            + " Expected: " + faviconLen
+                            + " Got: " + read);
+                }
+                state.mFavicon = BitmapFactory.decodeByteArray(data, 0, data.length);
+            }
+            mCurrentState = state;
+            return true;
+        } catch (IOException e) {
+            return false;
+        }
+    }
+
+    private boolean saveTabInfo(DataOutputStream stream) {
+        try {
+            // mTitle might be null, but writeUTF doesn't handle that
+            String title = mCurrentState.mTitle;
+            stream.writeUTF(title != null ? title : "");
+            // mUrl is never null
+            stream.writeUTF(mCurrentState.mUrl);
+            byte[] compressedPixels = compressFavicon();
+            if (compressedPixels == null) {
+                stream.writeInt(-1);
+            } else {
+                stream.writeInt(compressedPixels.length);
+                stream.write(compressedPixels);
+            }
+            return true;
+        } catch (Exception e) {
+            Log.w(LOGTAG, "Failed to saveTabInfo", e);
+            return false;
+        }
+    }
+
+    private byte[] compressFavicon() {
+        Bitmap favicon = mCurrentState.mFavicon;
+        if (favicon == null) {
+            return null;
+        }
+        ByteArrayOutputStream stream = new ByteArrayOutputStream();
+        byte[] data = null;
+        try {
+            favicon.compress(CompressFormat.PNG, 100, stream);
+            data = stream.toByteArray();
+            stream.close();
+        } catch (IOException e) {
+            // Will return null below then
+        }
+        return data;
+    }
+
 }
diff --git a/src/com/android/browser/TabBar.java b/src/com/android/browser/TabBar.java
index 6c3949a..6e84a40 100644
--- a/src/com/android/browser/TabBar.java
+++ b/src/com/android/browser/TabBar.java
@@ -238,7 +238,7 @@
 
     void showTitleBarIndicator(boolean show) {
         Tab tab = mTabControl.getCurrentTab();
-        if (tab != null) {
+        if (tab != null && !tab.isSnapshot()) {
             TabView tv = mTabMap.get(tab);
             if (tv != null) {
                 tv.showIndicator(show);
@@ -325,6 +325,7 @@
         TextView mTitle;
         View mIndicator;
         View mIncognito;
+        View mSnapshot;
         ImageView mIconView;
         ImageView mLock;
         ImageView mClose;
@@ -355,6 +356,7 @@
             mClose = (ImageView) mTabContent.findViewById(R.id.close);
             mClose.setOnClickListener(this);
             mIncognito = mTabContent.findViewById(R.id.incognito);
+            mSnapshot = mTabContent.findViewById(R.id.snapshot);
             mIndicator = mTabContent.findViewById(R.id.chevron);
             mSelected = false;
             mInLoad = false;
@@ -399,11 +401,15 @@
             if (mTab.getFavicon() != null) {
                 setFavicon(renderFavicon(mTab.getFavicon()));
             }
-            if (mTab != null) {
-                mIncognito.setVisibility(
-                        mTab.isPrivateBrowsingEnabled() ?
-                        View.VISIBLE : View.GONE);
-            }
+            updateTabIcons();
+        }
+
+        private void updateTabIcons() {
+            mIncognito.setVisibility(
+                    mTab.isPrivateBrowsingEnabled() ?
+                    View.VISIBLE : View.GONE);
+            mSnapshot.setVisibility(mTab.isSnapshot()
+                    ? View.VISIBLE : View.GONE);
         }
 
         @Override
@@ -666,6 +672,7 @@
             } else if (url != null) {
                 tv.setDisplayTitle(UrlUtils.stripUrl(url));
             }
+            tv.updateTabIcons();
         }
     }
 
diff --git a/src/com/android/browser/TitleBarBase.java b/src/com/android/browser/TitleBarBase.java
index 4dc960c..b95711e 100644
--- a/src/com/android/browser/TitleBarBase.java
+++ b/src/com/android/browser/TitleBarBase.java
@@ -35,6 +35,8 @@
 import android.view.Gravity;
 import android.view.KeyEvent;
 import android.view.LayoutInflater;
+import android.view.Menu;
+import android.view.MenuItem;
 import android.view.View;
 import android.view.View.OnClickListener;
 import android.view.View.OnFocusChangeListener;
@@ -48,6 +50,8 @@
 import android.widget.Button;
 import android.widget.FrameLayout;
 import android.widget.ImageView;
+import android.widget.PopupMenu;
+import android.widget.PopupMenu.OnMenuItemClickListener;
 import android.widget.ProgressBar;
 import android.widget.RelativeLayout;
 import android.widget.Spinner;
@@ -60,7 +64,8 @@
  */
 public class TitleBarBase extends RelativeLayout
         implements OnClickListener, OnFocusChangeListener, UrlInputListener,
-        TextChangeWatcher, DeviceAccountLogin.AutoLoginCallback {
+        TextChangeWatcher, DeviceAccountLogin.AutoLoginCallback,
+        OnMenuItemClickListener {
 
     protected static final int PROGRESS_MAX = 100;
 
@@ -75,7 +80,7 @@
     protected UrlInputView mUrlInput;
     protected boolean mInVoiceMode;
     protected View mContainer;
-
+    private View mUaSwitcher;
 
     // Auto-login UI
     protected View mAutoLogin;
@@ -385,6 +390,14 @@
         return mAutoLoginHandler != null;
     }
 
+    public void setUaSwitcher(View v) {
+        if (mUaSwitcher != null) {
+            mUaSwitcher.setOnClickListener(null);
+        }
+        mUaSwitcher = v;
+        mUaSwitcher.setOnClickListener(this);
+    }
+
     @Override
     public void onClick(View v) {
         if (mAutoLoginCancel == v) {
@@ -402,10 +415,45 @@
                 mAutoLoginHandler.login(
                         mAutoLoginAccount.getSelectedItemPosition(), this);
             }
+        } else if (mUaSwitcher == v) {
+            BrowserSettings settings = BrowserSettings.getInstance();
+            WebView web = getCurrentWebView();
+            if (web == null) return;
+            boolean desktop = settings.hasDesktopUseragent(web);
+            PopupMenu popup = new PopupMenu(mContext, mUaSwitcher);
+            Menu menu = popup.getMenu();
+            popup.getMenuInflater().inflate(R.menu.ua_switcher, menu);
+            menu.findItem(R.id.ua_mobile_menu_id).setChecked(!desktop);
+            menu.findItem(R.id.ua_desktop_menu_id).setChecked(desktop);
+            popup.setOnMenuItemClickListener(this);
+            popup.show();
         }
     }
 
     @Override
+    public boolean onMenuItemClick(MenuItem item) {
+        BrowserSettings settings = BrowserSettings.getInstance();
+        WebView web = getCurrentWebView();
+        if (web == null) return false;
+        boolean desktop = settings.hasDesktopUseragent(web);
+        switch (item.getItemId()) {
+        case R.id.ua_mobile_menu_id:
+            if (desktop) {
+                settings.toggleDesktopUseragent(web);
+                web.loadUrl(web.getOriginalUrl());
+            }
+            return true;
+        case R.id.ua_desktop_menu_id:
+            if (!desktop) {
+                settings.toggleDesktopUseragent(web);
+                web.loadUrl(web.getOriginalUrl());
+            }
+            return true;
+        }
+        return false;
+    }
+
+    @Override
     public void onFocusChange(View view, boolean hasFocus) {
         // if losing focus and not in touch mode, leave as is
         if (hasFocus || view.isInTouchMode() || mUrlInput.needsUpdate()) {
diff --git a/src/com/android/browser/TitleBarPhone.java b/src/com/android/browser/TitleBarPhone.java
index 97fe747..75b9fb7 100644
--- a/src/com/android/browser/TitleBarPhone.java
+++ b/src/com/android/browser/TitleBarPhone.java
@@ -71,6 +71,7 @@
         Resources res = context.getResources();
         mStopDrawable = res.getDrawable(R.drawable.ic_stop_holo_dark);
         mRefreshDrawable = res.getDrawable(R.drawable.ic_refresh_holo_dark);
+        setUaSwitcher(mFavicon);
     }
 
     @Override
diff --git a/src/com/android/browser/TitleBarXLarge.java b/src/com/android/browser/TitleBarXLarge.java
index 8c03e4c..91709cc 100644
--- a/src/com/android/browser/TitleBarXLarge.java
+++ b/src/com/android/browser/TitleBarXLarge.java
@@ -62,8 +62,6 @@
     private ImageView mVoiceSearch;
     private Drawable mFocusDrawable;
     private Drawable mUnfocusDrawable;
-    private boolean mHasFocus = false;
-    private BrowserSettings mSettings;
 
     public TitleBarXLarge(Activity activity, UiController controller,
             XLargeUi ui, FrameLayout parent) {
@@ -77,10 +75,7 @@
         mUnfocusDrawable = resources.getDrawable(
                 R.drawable.textfield_default_holo_dark);
         mInVoiceMode = false;
-        mSettings = BrowserSettings.getInstance();
         initLayout(activity, R.layout.url_bar);
-        PreferenceManager.getDefaultSharedPreferences(activity)
-                .registerOnSharedPreferenceChangeListener(mSharedPrefsListener);
     }
 
     @Override
@@ -109,7 +104,7 @@
         mGoButton.setOnClickListener(this);
         mClearButton.setOnClickListener(this);
         mVoiceSearch.setOnClickListener(this);
-        mUrlIcon.setOnClickListener(this);
+        setUaSwitcher(mUrlIcon);
         mUrlInput.setContainer(mUrlContainer);
         setFocusState(false);
     }
@@ -187,13 +182,6 @@
             clearOrClose();
         } else if (mVoiceSearch == v) {
             mUiController.startVoiceSearch();
-        } else if (mUrlIcon == v) {
-            WebView web = mUiController.getCurrentWebView();
-            if (mSettings.enableUseragentSwitcher() && web != null) {
-                mSettings.toggleDesktopUseragent(web);
-                web.loadUrl(web.getOriginalUrl());
-                updateUrlIcon();
-            }
         } else {
             super.onClick(v);
         }
@@ -213,38 +201,14 @@
     }
 
     void updateUrlIcon() {
-        if (mHasFocus) {
-            return;
-        }
-        if (!mInVoiceMode && mSettings.enableUseragentSwitcher()) {
-            WebView web = mUiController.getCurrentWebView();
-            if (mSettings.hasDesktopUseragent(web)) {
-                mUrlIcon.setImageResource(R.drawable.ic_ua_desktop);
-            } else {
-                mUrlIcon.setImageResource(R.drawable.ic_ua_android);
-            }
-        } else {
-            mUrlIcon.setImageResource(mInVoiceMode ?
-                    R.drawable.ic_search_holo_dark
-                    : R.drawable.ic_web_holo_dark);
-        }
+        mUrlIcon.setImageResource(mInVoiceMode ?
+                R.drawable.ic_search_holo_dark
+                : R.drawable.ic_web_holo_dark);
     }
 
-    private OnSharedPreferenceChangeListener mSharedPrefsListener =
-            new OnSharedPreferenceChangeListener() {
-
-        @Override
-        public void onSharedPreferenceChanged(
-                SharedPreferences sharedPreferences, String key) {
-            updateUrlIcon();
-        }
-
-    };
-
     @Override
     protected void setFocusState(boolean focus) {
         super.setFocusState(focus);
-        mHasFocus = focus;
         if (focus) {
             mSearchButton.setVisibility(View.GONE);
             mStar.setVisibility(View.GONE);
diff --git a/src/com/android/browser/XLargeUi.java b/src/com/android/browser/XLargeUi.java
index 1530ed3..25cdbd9 100644
--- a/src/com/android/browser/XLargeUi.java
+++ b/src/com/android/browser/XLargeUi.java
@@ -213,7 +213,7 @@
             mTabBar.showTitleBarIndicator(false);
         } else {
             // check if title bar is already attached by animation
-            if (mTitleBar.getParent() == null) {
+            if (mTitleBar.getParent() == null && !tab.isSnapshot()) {
                 view.setEmbeddedTitleBar(mTitleBar);
             }
             view.setScrollListener(this);
diff --git a/src/com/android/browser/preferences/LabPreferencesFragment.java b/src/com/android/browser/preferences/LabPreferencesFragment.java
index d9ef3df..0dd8805 100644
--- a/src/com/android/browser/preferences/LabPreferencesFragment.java
+++ b/src/com/android/browser/preferences/LabPreferencesFragment.java
@@ -45,7 +45,6 @@
         // Load the XML preferences file
         addPreferencesFromResource(R.xml.lab_preferences);
         registerChangeListener(PreferenceKeys.PREF_ENABLE_QUICK_CONTROLS);
-        registerChangeListener(PreferenceKeys.PREF_ENABLE_USERAGENT_SWITCHER);
         useInstantPref = findPreference(PreferenceKeys.PREF_USE_INSTANT_SEARCH);
     }
 
@@ -81,17 +80,6 @@
             startActivity(new Intent(BrowserActivity.ACTION_RESTART, null,
                     getActivity(), BrowserActivity.class));
         }
-        if (PreferenceKeys.PREF_ENABLE_USERAGENT_SWITCHER.equals(key)) {
-            if ((Boolean)newValue) {
-                // Show the help
-                LayoutInflater inflater = LayoutInflater.from(getActivity());
-                View content = inflater.inflate(R.layout.help_dialog_useragent_switcher, null);
-                new AlertDialog.Builder(getActivity())
-                        .setView(content)
-                        .setNeutralButton(android.R.string.ok, null)
-                        .show();
-            }
-        }
         return true;
     }
 }