Fix stop/refresh menu state

    Bug: 5469075 5640775

Reconcile page load status updates to only use tab state; update menus
accordingly

Change-Id: Id32f1e0486e8439d6729f3657eda1132c25dfc7e
diff --git a/src/com/android/browser/Controller.java b/src/com/android/browser/Controller.java
index 2a57edf..e8ae21d 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;
 
@@ -874,17 +872,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 +1420,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 +1435,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 +1486,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());
@@ -1572,7 +1570,7 @@
                 break;
 
             case R.id.stop_reload_menu_id:
-                if (mInLoad) {
+                if (isInLoad()) {
                     stopLoading();
                 } else {
                     getCurrentTopWebView().reload();
@@ -1791,7 +1789,7 @@
                     // Switching the menu back to icon view, so show the
                     // title bar once again.
                     mExtendedMenuOpen = false;
-                    mUi.onExtendedMenuClosed(mInLoad);
+                    mUi.onExtendedMenuClosed(isInLoad());
                 }
             }
         } else {
@@ -1806,11 +1804,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.
@@ -1873,12 +1871,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