Cleanup menus

 Bug: 5290513

Change-Id: I2ca1de40fe362b74d941056504fc4e3249de03a3
diff --git a/src/com/android/browser/Controller.java b/src/com/android/browser/Controller.java
index 4809f13..f6feb4a 100644
--- a/src/com/android/browser/Controller.java
+++ b/src/com/android/browser/Controller.java
@@ -1248,10 +1248,6 @@
         }
         MenuInflater inflater = mActivity.getMenuInflater();
         inflater.inflate(R.menu.browser, menu);
-        updateInLoadMenuItems(menu);
-        // hold on to the menu reference here; it is used by the page callbacks
-        // to update the menu based on loading state
-        mCachedMenu = menu;
         return true;
     }
 
@@ -1435,6 +1431,10 @@
     }
 
     boolean onPrepareOptionsMenu(Menu menu) {
+        updateInLoadMenuItems(menu);
+        // hold on to the menu reference here; it is used by the page callbacks
+        // to update the menu based on loading state
+        mCachedMenu = menu;
         // Note: setVisible will decide whether an item is visible; while
         // setEnabled() will decide whether an item is enabled, which also means
         // whether the matching shortcut key will function.
@@ -1465,11 +1465,13 @@
         boolean canGoForward = false;
         boolean isHome = false;
         boolean isDesktopUa = false;
+        boolean isLive = false;
         if (tab != null) {
             canGoBack = tab.canGoBack();
             canGoForward = tab.canGoForward();
             isHome = mSettings.getHomePage().equals(tab.getUrl());
             isDesktopUa = mSettings.hasDesktopUseragent(tab.getWebView());
+            isLive = !tab.isSnapshot();
         }
         final MenuItem back = menu.findItem(R.id.back_menu_id);
         back.setEnabled(canGoBack);
@@ -1486,6 +1488,7 @@
             dest.setTitle(source.getTitle());
             dest.setIcon(source.getIcon());
         }
+        menu.setGroupVisible(R.id.NAV_MENU, isLive);
 
         // decide whether to show the share link option
         PackageManager pm = mActivity.getPackageManager();
@@ -1506,6 +1509,8 @@
         counter.setEnabled(showDebugSettings);
         final MenuItem uaSwitcher = menu.findItem(R.id.ua_desktop_menu_id);
         uaSwitcher.setChecked(isDesktopUa);
+        menu.setGroupVisible(R.id.LIVE_MENU, isLive);
+        menu.setGroupVisible(R.id.SNAPSHOT_MENU, !isLive);
 
         mUi.updateMenuState(tab, menu);
     }
@@ -1623,6 +1628,10 @@
                 mPageDialogsHandler.showPageInfo(mTabControl.getCurrentTab(), false, null);
                 break;
 
+            case R.id.snapshot_go_live:
+                goLive();
+                return true;
+
             case R.id.classic_history_menu_id:
                 bookmarksOrHistoryPicker(true);
                 break;
@@ -1690,6 +1699,11 @@
         return true;
     }
 
+    private void goLive() {
+        Tab t = getCurrentTab();
+        t.loadUrl(t.getUrl(), null);
+    }
+
     public boolean onContextItemSelected(MenuItem item) {
         // Let the History and Bookmark fragments handle menus they created.
         if (item.getGroupId() == R.id.CONTEXT_MENU) {