Merge "Remove an init. workaround for Cookiemanager."
diff --git a/res/values/dimensions.xml b/res/values/dimensions.xml
index 8844f6b..d6ae6ba 100644
--- a/res/values/dimensions.xml
+++ b/res/values/dimensions.xml
@@ -27,7 +27,7 @@
     <dimen name="widgetItemMinHeight">48dip</dimen>
     <dimen name="favicon_size">16dip</dimen>
     <dimen name="favicon_padded_size">20dip</dimen>
-    <dimen name="qc_radius_start">45dip</dimen>
+    <dimen name="qc_radius_start">60dip</dimen>
     <dimen name="qc_radius_increment">70dip</dimen>
     <dimen name="qc_slop">10dip</dimen>
     <dimen name="qc_touch_offset">15dip</dimen>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 1daa43f..1438c1c 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -408,7 +408,7 @@
     <string name="autofill_profile_editor_delete_profile">Delete</string>
 
     <!-- Text on a dialog shown to the user when they are prompted to set up the autofill feature [CHAR-LIMIT=NONE] -->
-    <string name="autofill_setup_dialog_message">The browser can automatically complete web forms like this one. Would you like to set up your auto-fill text?</string>
+    <string name="autofill_setup_dialog_message">The browser can automatically complete web forms like this one. Do you want to set up your auto-fill text?</string>
     <!-- Toast message displayed when the user decides to not set up autofill at this time. We want to remind them that they can configure
          it through the Browser Settings menu. [CHAR-LIMIT=NONE] -->
     <string name="autofill_setup_dialog_negative_toast">You can always set up your auto-fill text from the Browser &gt; Settings &gt; General screen.</string>
diff --git a/src/com/android/browser/BaseUi.java b/src/com/android/browser/BaseUi.java
index e3b620a..88829cc 100644
--- a/src/com/android/browser/BaseUi.java
+++ b/src/com/android/browser/BaseUi.java
@@ -753,7 +753,12 @@
         if (enabled) {
             winParams.flags |=  bits;
             if (mCustomView != null) {
-                mCustomView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE);
+                // HTML5 Video can ask for the HIDE_NAVIGATION specifically,
+                // and we want to differentiate it from the flash.
+                if ((mCustomView.getSystemUiVisibility()
+                        & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0) {
+                    mCustomView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE);
+                }
             } else {
                 mContentView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE);
             }
diff --git a/src/com/android/browser/BrowserActivity.java b/src/com/android/browser/BrowserActivity.java
index 23aeed5..77fac4f 100644
--- a/src/com/android/browser/BrowserActivity.java
+++ b/src/com/android/browser/BrowserActivity.java
@@ -62,7 +62,7 @@
             finish();
             return;
         }
-        mController = new Controller(this, icicle == null);
+        mController = new Controller(this);
         boolean xlarge = isTablet(this);
         if (xlarge) {
             mUi = new XLargeUi(this, mController);
@@ -71,12 +71,8 @@
         }
         mController.setUi(mUi);
 
-        Bundle state = getIntent().getBundleExtra(EXTRA_STATE);
-        if (state != null && icicle == null) {
-            icicle = state;
-        }
-
-        mController.start(icicle, getIntent());
+        Intent intent = (icicle == null) ? getIntent() : null;
+        mController.start(intent);
     }
 
     public static boolean isTablet(Context context) {
diff --git a/src/com/android/browser/BrowserSettings.java b/src/com/android/browser/BrowserSettings.java
index 6d60591..dd7bb56 100644
--- a/src/com/android/browser/BrowserSettings.java
+++ b/src/com/android/browser/BrowserSettings.java
@@ -845,4 +845,47 @@
         return mPrefs.getString(PREF_DATA_PRELOAD, getDefaultPreloadSetting());
     }
 
+    // -----------------------------
+    // getter/setters for browser recovery
+    // -----------------------------
+    /**
+     * The last time browser was started.
+     * @return The last browser start time as System.currentTimeMillis. This
+     * can be 0 if this is the first time or the last tab was closed.
+     */
+    public long getLastRecovered() {
+        return mPrefs.getLong(KEY_LAST_RECOVERED, 0);
+    }
+
+    /**
+     * Sets the last browser start time.
+     * @param time The last time as System.currentTimeMillis that the browser
+     * was started. This should be set to 0 if the last tab is closed.
+     */
+    public void setLastRecovered(long time) {
+        mPrefs.edit()
+            .putLong(KEY_LAST_RECOVERED, time)
+            .apply();
+    }
+
+    /**
+     * Used to determine whether or not the previous browser run crashed. Once
+     * the previous state has been determined, the value will be set to false
+     * until a pause is received.
+     * @return true if the last browser run was paused or false if it crashed.
+     */
+    public boolean wasLastRunPaused() {
+        return mPrefs.getBoolean(KEY_LAST_RUN_PAUSED, false);
+    }
+
+    /**
+     * Sets whether or not the last run was a pause or crash.
+     * @param isPaused Set to true When a pause is received or false after
+     * resuming.
+     */
+    public void setLastRunPaused(boolean isPaused) {
+        mPrefs.edit()
+            .putBoolean(KEY_LAST_RUN_PAUSED, isPaused)
+            .apply();
+    }
 }
diff --git a/src/com/android/browser/Controller.java b/src/com/android/browser/Controller.java
index c9756da..7c73411 100644
--- a/src/com/android/browser/Controller.java
+++ b/src/com/android/browser/Controller.java
@@ -207,8 +207,6 @@
      */
     private boolean mExtendedMenuOpen;
 
-    private boolean mInLoad;
-
     private boolean mActivityPaused = true;
     private boolean mLoadStopped;
 
@@ -220,15 +218,13 @@
 
     private boolean mBlockEvents;
 
-    public Controller(Activity browser, boolean preloadCrashState) {
+    public Controller(Activity browser) {
         mActivity = browser;
         mSettings = BrowserSettings.getInstance();
         mTabControl = new TabControl(this);
         mSettings.setController(this);
         mCrashRecoveryHandler = CrashRecoveryHandler.initialize(this);
-        if (preloadCrashState) {
-            mCrashRecoveryHandler.preloadCrashState();
-        }
+        mCrashRecoveryHandler.preloadCrashState();
         mFactory = new BrowserWebViewFactory(browser);
 
         mUrlHandler = new UrlHandler(this);
@@ -258,16 +254,12 @@
         openIconDatabase();
     }
 
-    void start(final Bundle icicle, final Intent intent) {
-        boolean noCrashRecovery = intent.getBooleanExtra(NO_CRASH_RECOVERY, false);
-        if (icicle != null || noCrashRecovery) {
-            doStart(icicle, intent, false);
-        } else {
-            mCrashRecoveryHandler.startRecovery(intent);
-        }
+    void start(final Intent intent) {
+        // mCrashRecoverHandler has any previously saved state.
+        mCrashRecoveryHandler.startRecovery(intent);
     }
 
-    void doStart(final Bundle icicle, final Intent intent, final boolean fromCrash) {
+    void doStart(final Bundle icicle, final Intent intent) {
         // Unless the last browser usage was within 24 hours, destroy any
         // remaining incognito tabs.
 
@@ -295,36 +287,42 @@
         GoogleAccountLogin.startLoginIfNeeded(mActivity,
                 new Runnable() {
                     @Override public void run() {
-                        onPreloginFinished(icicle, intent, currentTabId, restoreIncognitoTabs,
-                                fromCrash);
+                        onPreloginFinished(icicle, intent, currentTabId,
+                                restoreIncognitoTabs);
                     }
                 });
     }
 
     private void onPreloginFinished(Bundle icicle, Intent intent, long currentTabId,
-            boolean restoreIncognitoTabs, boolean fromCrash) {
+            boolean restoreIncognitoTabs) {
         if (currentTabId == -1) {
             BackgroundHandler.execute(new PruneThumbnails(mActivity, null));
-            final Bundle extra = intent.getExtras();
-            // Create an initial tab.
-            // If the intent is ACTION_VIEW and data is not null, the Browser is
-            // invoked to view the content by another application. In this case,
-            // the tab will be close when exit.
-            UrlData urlData = IntentHandler.getUrlDataFromIntent(intent);
-            Tab t = null;
-            if (urlData.isEmpty()) {
-                t = openTabToHomePage();
+            if (intent == null) {
+                // This won't happen under common scenarios. The icicle is
+                // not null, but there aren't any tabs to restore.
+                openTabToHomePage();
             } else {
-                t = openTab(urlData);
-            }
-            if (t != null) {
-                t.setAppId(intent.getStringExtra(Browser.EXTRA_APPLICATION_ID));
-            }
-            WebView webView = t.getWebView();
-            if (extra != null) {
-                int scale = extra.getInt(Browser.INITIAL_ZOOM_LEVEL, 0);
-                if (scale > 0 && scale <= 1000) {
-                    webView.setInitialScale(scale);
+                final Bundle extra = intent.getExtras();
+                // Create an initial tab.
+                // If the intent is ACTION_VIEW and data is not null, the Browser is
+                // invoked to view the content by another application. In this case,
+                // the tab will be close when exit.
+                UrlData urlData = IntentHandler.getUrlDataFromIntent(intent);
+                Tab t = null;
+                if (urlData.isEmpty()) {
+                    t = openTabToHomePage();
+                } else {
+                    t = openTab(urlData);
+                }
+                if (t != null) {
+                    t.setAppId(intent.getStringExtra(Browser.EXTRA_APPLICATION_ID));
+                }
+                WebView webView = t.getWebView();
+                if (extra != null) {
+                    int scale = extra.getInt(Browser.INITIAL_ZOOM_LEVEL, 0);
+                    if (scale > 0 && scale <= 1000) {
+                        webView.setInitialScale(scale);
+                    }
                 }
             }
             mUi.updateTabs(mTabControl.getTabs());
@@ -344,9 +342,9 @@
             // TabControl.restoreState() will create a new tab even if
             // restoring the state fails.
             setActiveTab(mTabControl.getCurrentTab());
-            // Handle the intent if needed. If icicle != null, we are restoring
-            // and the intent will be stale - ignore it.
-            if (icicle == null || fromCrash) {
+            // Intent is non-null when framework thinks the browser should be
+            // launching with a new intent (icicle is null).
+            if (intent != null) {
                 mIntentHandler.onNewIntent(intent);
             }
         }
@@ -355,7 +353,8 @@
         if (jsFlags.trim().length() != 0) {
             getCurrentWebView().setJsFlags(jsFlags);
         }
-        if (BrowserActivity.ACTION_SHOW_BOOKMARKS.equals(intent.getAction())) {
+        if (intent != null
+                && BrowserActivity.ACTION_SHOW_BOOKMARKS.equals(intent.getAction())) {
             bookmarksOrHistoryPicker(ComboViews.Bookmarks);
         }
     }
@@ -653,18 +652,27 @@
     }
 
     void onSaveInstanceState(Bundle outState) {
-        // the default implementation requires each view to have an id. As the
-        // browser handles the state itself and it doesn't use id for the views,
-        // don't call the default implementation. Otherwise it will trigger the
-        // warning like this, "couldn't save which view has focus because the
-        // focused view XXX has no id".
-
         // Save all the tabs
-        mTabControl.saveState(outState);
-        if (!outState.isEmpty()) {
+        Bundle saveState = createSaveState();
+
+        // crash recovery manages all save & restore state
+        mCrashRecoveryHandler.writeState(saveState);
+        mSettings.setLastRunPaused(true);
+    }
+
+    /**
+     * Save the current state to outState. Does not write the state to
+     * disk.
+     * @return Bundle containing the current state of all tabs.
+     */
+    /* package */ Bundle createSaveState() {
+        Bundle saveState = new Bundle();
+        mTabControl.saveState(saveState);
+        if (!saveState.isEmpty()) {
             // Save time so that we know how old incognito tabs (if any) are.
-            outState.putSerializable("lastActiveDate", Calendar.getInstance());
+            saveState.putSerializable("lastActiveDate", Calendar.getInstance());
         }
+        return saveState;
     }
 
     void onResume() {
@@ -672,6 +680,7 @@
             Log.e(LOGTAG, "BrowserActivity is already resumed.");
             return;
         }
+        mSettings.setLastRunPaused(false);
         mActivityPaused = false;
         Tab current = mTabControl.getCurrentTab();
         if (current != null) {
@@ -874,17 +883,16 @@
             // when the main frame completes loading regardless of the state of
             // any sub frames so calls to onProgressChanges may continue after
             // onPageFinished has executed)
-            if (mInLoad) {
-                mInLoad = false;
-                updateInLoadMenuItems(mCachedMenu);
+            if (tab.inPageLoad()) {
+                updateInLoadMenuItems(mCachedMenu, tab);
             }
         } else {
-            if (!mInLoad) {
+            if (!tab.inPageLoad()) {
                 // onPageFinished may have already been called but a subframe is
-                // still loading and updating the progress. Reset mInLoad and
+                // still loading
+                // updating the progress and
                 // update the menu items.
-                mInLoad = true;
-                updateInLoadMenuItems(mCachedMenu);
+                updateInLoadMenuItems(mCachedMenu, tab);
             }
         }
         mUi.onProgressChanged(tab);
@@ -1423,12 +1431,12 @@
      * we must manually update the state of the stop/reload menu
      * item
      */
-    private void updateInLoadMenuItems(Menu menu) {
+    private void updateInLoadMenuItems(Menu menu, Tab tab) {
         if (menu == null) {
             return;
         }
         MenuItem dest = menu.findItem(R.id.stop_reload_menu_id);
-        MenuItem src = mInLoad ?
+        MenuItem src = tab.inPageLoad() ?
                 menu.findItem(R.id.stop_menu_id):
                 menu.findItem(R.id.reload_menu_id);
         if (src != null) {
@@ -1438,7 +1446,7 @@
     }
 
     boolean onPrepareOptionsMenu(Menu menu) {
-        updateInLoadMenuItems(menu);
+        updateInLoadMenuItems(menu, getCurrentTab());
         // hold on to the menu reference here; it is used by the page callbacks
         // to update the menu based on loading state
         mCachedMenu = menu;
@@ -1489,7 +1497,8 @@
         final MenuItem forward = menu.findItem(R.id.forward_menu_id);
         forward.setEnabled(canGoForward);
 
-        final MenuItem source = menu.findItem(mInLoad ? R.id.stop_menu_id : R.id.reload_menu_id);
+        final MenuItem source = menu.findItem(isInLoad() ? R.id.stop_menu_id
+                : R.id.reload_menu_id);
         final MenuItem dest = menu.findItem(R.id.stop_reload_menu_id);
         if (source != null && dest != null) {
             dest.setTitle(source.getTitle());
@@ -1569,7 +1578,7 @@
                 break;
 
             case R.id.stop_reload_menu_id:
-                if (mInLoad) {
+                if (isInLoad()) {
                     stopLoading();
                 } else {
                     getCurrentTopWebView().reload();
@@ -1784,7 +1793,7 @@
                     // Switching the menu back to icon view, so show the
                     // title bar once again.
                     mExtendedMenuOpen = false;
-                    mUi.onExtendedMenuClosed(mInLoad);
+                    mUi.onExtendedMenuClosed(isInLoad());
                 }
             }
         } else {
@@ -1799,11 +1808,11 @@
 
     public void onOptionsMenuClosed(Menu menu) {
         mOptionsMenuOpen = false;
-        mUi.onOptionsMenuClosed(mInLoad);
+        mUi.onOptionsMenuClosed(isInLoad());
     }
 
     public void onContextMenuClosed(Menu menu) {
-        mUi.onContextMenuClosed(menu, mInLoad);
+        mUi.onContextMenuClosed(menu, isInLoad());
     }
 
     // Helper method for getting the top window.
@@ -1866,12 +1875,12 @@
      */
     public void onActionModeFinished(ActionMode mode) {
         if (!isInCustomActionMode()) return;
-        mUi.onActionModeFinished(mInLoad);
+        mUi.onActionModeFinished(isInLoad());
         mActionMode = null;
     }
 
     boolean isInLoad() {
-        return mInLoad;
+        return getCurrentTab().inPageLoad();
     }
 
     // bookmark handling
@@ -2216,7 +2225,10 @@
         removeSubWindow(tab);
         // dismiss the subwindow. This will destroy the WebView.
         tab.dismissSubWindow();
-        getCurrentTopWebView().requestFocus();
+        WebView wv = getCurrentTopWebView();
+        if (wv != null) {
+            wv.requestFocus();
+        }
     }
 
     @Override
diff --git a/src/com/android/browser/CrashRecoveryHandler.java b/src/com/android/browser/CrashRecoveryHandler.java
index 3202016..822e82a 100644
--- a/src/com/android/browser/CrashRecoveryHandler.java
+++ b/src/com/android/browser/CrashRecoveryHandler.java
@@ -37,8 +37,6 @@
     private static final boolean LOGV_ENABLED = Browser.LOGV_ENABLED;
     private static final String LOGTAG = "BrowserCrashRecovery";
     private static final String STATE_FILE = "browser_state.parcel";
-    private static final String RECOVERY_PREFERENCES = "browser_recovery_prefs";
-    private static final String KEY_LAST_RECOVERED = "last_recovered";
     private static final int BUFFER_SIZE = 4096;
     private static final long BACKUP_DELAY = 500; // 500ms between writes
     /* This is the duration for which we will prompt to restore
@@ -85,31 +83,8 @@
             public void handleMessage(Message msg) {
                 switch (msg.what) {
                 case MSG_WRITE_STATE:
-                    if (LOGV_ENABLED) {
-                        Log.v(LOGTAG, "Saving crash recovery state");
-                    }
-                    Parcel p = Parcel.obtain();
-                    try {
-                        Bundle state = (Bundle) msg.obj;
-                        state.writeToParcel(p, 0);
-                        File stateJournal = new File(mContext.getCacheDir(),
-                                STATE_FILE + ".journal");
-                        FileOutputStream fout = new FileOutputStream(stateJournal);
-                        fout.write(p.marshall());
-                        fout.close();
-                        File stateFile = new File(mContext.getCacheDir(),
-                                STATE_FILE);
-                        if (!stateJournal.renameTo(stateFile)) {
-                            // Failed to rename, try deleting the existing
-                            // file and try again
-                            stateFile.delete();
-                            stateJournal.renameTo(stateFile);
-                        }
-                    } catch (Throwable e) {
-                        Log.i(LOGTAG, "Failed to save persistent state", e);
-                    } finally {
-                        p.recycle();
-                    }
+                    Bundle saveState = (Bundle) msg.obj;
+                    writeState(saveState);
                     break;
                 case MSG_CLEAR_STATE:
                     if (LOGV_ENABLED) {
@@ -142,8 +117,7 @@
         @Override
         public void run() {
             try {
-                final Bundle state = new Bundle();
-                mController.onSaveInstanceState(state);
+                final Bundle state = mController.createSaveState();
                 Message.obtain(mBackgroundHandler, MSG_WRITE_STATE, state)
                         .sendToTarget();
                 // Remove any queued up saves
@@ -162,28 +136,24 @@
     }
 
     private boolean shouldRestore() {
-        SharedPreferences prefs = mContext.getSharedPreferences(
-                RECOVERY_PREFERENCES, Context.MODE_PRIVATE);
-        long lastRecovered = prefs.getLong(KEY_LAST_RECOVERED, 0);
+        BrowserSettings browserSettings = BrowserSettings.getInstance();
+        long lastRecovered = browserSettings.getLastRecovered();
         long timeSinceLastRecover = System.currentTimeMillis() - lastRecovered;
-        if (timeSinceLastRecover > PROMPT_INTERVAL) {
-            return true;
-        }
-        return false;
+        return (timeSinceLastRecover > PROMPT_INTERVAL)
+                || browserSettings.wasLastRunPaused();
     }
 
     private void updateLastRecovered(long time) {
-        SharedPreferences prefs = mContext.getSharedPreferences(
-                RECOVERY_PREFERENCES, Context.MODE_PRIVATE);
-        prefs.edit()
-            .putLong(KEY_LAST_RECOVERED, time)
-            .apply();
+        BrowserSettings browserSettings = BrowserSettings.getInstance();
+        browserSettings.setLastRecovered(time);
     }
 
-    private Bundle loadCrashState() {
+    synchronized private Bundle loadCrashState() {
         if (!shouldRestore()) {
             return null;
         }
+        BrowserSettings browserSettings = BrowserSettings.getInstance();
+        browserSettings.setLastRunPaused(false);
         Bundle state = null;
         Parcel parcel = Parcel.obtain();
         FileInputStream fin = null;
@@ -231,7 +201,7 @@
         }
         updateLastRecovered(mRecoveryState != null
                 ? System.currentTimeMillis() : 0);
-        mController.doStart(mRecoveryState, intent, true);
+        mController.doStart(mRecoveryState, intent);
         mRecoveryState = null;
     }
 
@@ -245,4 +215,35 @@
         mBackgroundHandler.sendEmptyMessage(MSG_PRELOAD_STATE);
     }
 
-}
+    /**
+     * Writes the crash recovery state to a file synchronously.
+     * Errors are swallowed, but logged.
+     * @param state The state to write out
+     */
+    synchronized void writeState(Bundle state) {
+        if (LOGV_ENABLED) {
+            Log.v(LOGTAG, "Saving crash recovery state");
+        }
+        Parcel p = Parcel.obtain();
+        try {
+            state.writeToParcel(p, 0);
+            File stateJournal = new File(mContext.getCacheDir(),
+                    STATE_FILE + ".journal");
+            FileOutputStream fout = new FileOutputStream(stateJournal);
+            fout.write(p.marshall());
+            fout.close();
+            File stateFile = new File(mContext.getCacheDir(),
+                    STATE_FILE);
+            if (!stateJournal.renameTo(stateFile)) {
+                // Failed to rename, try deleting the existing
+                // file and try again
+                stateFile.delete();
+                stateJournal.renameTo(stateFile);
+            }
+        } catch (Throwable e) {
+            Log.i(LOGTAG, "Failed to save persistent state", e);
+        } finally {
+            p.recycle();
+        }
+    }
+}
\ No newline at end of file
diff --git a/src/com/android/browser/DownloadHandler.java b/src/com/android/browser/DownloadHandler.java
index 17ad320..6e2c786 100644
--- a/src/com/android/browser/DownloadHandler.java
+++ b/src/com/android/browser/DownloadHandler.java
@@ -67,6 +67,7 @@
             //     that matches.
             Intent intent = new Intent(Intent.ACTION_VIEW);
             intent.setDataAndType(Uri.parse(url), mimetype);
+            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
             ResolveInfo info = activity.getPackageManager().resolveActivity(intent,
                     PackageManager.MATCH_DEFAULT_ONLY);
             if (info != null) {
diff --git a/src/com/android/browser/NavigationBarPhone.java b/src/com/android/browser/NavigationBarPhone.java
index 2e206fb..60b228d 100644
--- a/src/com/android/browser/NavigationBarPhone.java
+++ b/src/com/android/browser/NavigationBarPhone.java
@@ -213,6 +213,7 @@
             if (hasFocus && !mUrlInput.getText().toString().equals(mUrlInput.getTag())) {
                 // only change text if different
                 mUrlInput.setText((String) mUrlInput.getTag(), false);
+                mUrlInput.selectAll();
             } else {
                 setDisplayTitle(mUrlInput.getText().toString());
             }
diff --git a/src/com/android/browser/PieControlPhone.java b/src/com/android/browser/PieControlPhone.java
index f12c49a..2b6a3c5 100644
--- a/src/com/android/browser/PieControlPhone.java
+++ b/src/com/android/browser/PieControlPhone.java
@@ -24,6 +24,7 @@
 import android.widget.PopupMenu;
 import android.widget.PopupMenu.OnMenuItemClickListener;
 
+import com.android.browser.UI.ComboViews;
 import com.android.browser.view.PieItem;
 import com.android.browser.view.PieMenu.PieView.OnLayoutListener;
 import com.android.browser.view.PieStackView;
@@ -40,6 +41,8 @@
     private PieItem mUrl;
     private PieItem mShowTabs;
     private PieItem mOptions;
+    private PieItem mNewTab;
+    private PieItem mBookmarks;
     private TabAdapter mTabAdapter;
     private PopupMenu mPopup;
 
@@ -67,10 +70,14 @@
                 1);
 
         // level 1
+        mNewTab = makeItem(R.drawable.ic_new_window_holo_dark, 1);
+        mBookmarks = makeItem(R.drawable.ic_bookmarks_holo_dark, 1);
+        mPie.addItem(mNewTab);
         mPie.addItem(mShowTabs);
         mPie.addItem(mUrl);
+        mPie.addItem(mBookmarks);
         mPie.addItem(mOptions);
-        setClickListener(this, mUrl, mShowTabs, mOptions);
+        setClickListener(this, mUrl, mShowTabs, mOptions, mNewTab, mBookmarks);
         mPopup = new PopupMenu(mActivity, mUi.getTitleBar());
         Menu menu = mPopup.getMenu();
         mPopup.getMenuInflater().inflate(R.menu.browser, menu);
@@ -105,6 +112,11 @@
             mUi.showNavScreen();
         } else if (mOptions.getView() == v) {
             showMenu();
+        } else if (mNewTab.getView() == v) {
+            mUiController.openTabToHomePage();
+            mUi.editUrl(false);
+        } else if (mBookmarks.getView() == v) {
+            mUiController.bookmarksOrHistoryPicker(ComboViews.Bookmarks);
         }
     }
 
diff --git a/src/com/android/browser/PreferenceKeys.java b/src/com/android/browser/PreferenceKeys.java
index ecab008..1a20495 100644
--- a/src/com/android/browser/PreferenceKeys.java
+++ b/src/com/android/browser/PreferenceKeys.java
@@ -104,4 +104,17 @@
     static final String PREF_DATA_PRELOAD = "preload_when";
     static final String PREF_LOAD_IMAGES = "load_images";
 
+    // ----------------------
+    // Keys for browser recovery
+    // ----------------------
+    /**
+     * The last time recovery was started as System.currentTimeMillis.
+     * 0 if not set.
+     */
+    static final String KEY_LAST_RECOVERED = "last_recovered";
+
+    /**
+     * Key for whether or not the last run was paused.
+     */
+    static final String KEY_LAST_RUN_PAUSED = "last_paused";
 }
diff --git a/src/com/android/browser/Tab.java b/src/com/android/browser/Tab.java
index dd97960..0abc86b 100644
--- a/src/com/android/browser/Tab.java
+++ b/src/com/android/browser/Tab.java
@@ -619,7 +619,6 @@
                 LogTag.logPageFinishedLoading(
                         url, SystemClock.uptimeMillis() - mLoadStartTime);
             }
-            mInPageLoad = false;
             syncCurrentState(view, url);
             mWebViewController.onPageFinished(Tab.this);
         }
@@ -1044,6 +1043,9 @@
         @Override
         public void onProgressChanged(WebView view, int newProgress) {
             mPageLoadProgress = newProgress;
+            if (newProgress == 100) {
+                mInPageLoad = false;
+            }
             mWebViewController.onProgressChanged(Tab.this);
         }