Revert "Android: Remove some methods from Tab"

This reverts commit 989bd3d98e3283115280ea71dc2762026eac7326.

Reason for revert: Internal build breakage  https://ci.chromium.org/p/chrome/builders/luci.chrome.ci/android-internal-chromium-tot/13140

Original change's description:
> Android: Remove some methods from Tab
> 
> This CL removes a test-only method (isLoadingAndRenderingDone),
> moves one that has only a few call sites
> (shouldStall/{set|get}UseDekstopUserAgent) over to the caller class.
> 
> Bug: 925242
> Change-Id: I174dfd3bff8eefcd94df8a0a3808e89a94be7569
> Reviewed-on: https://chromium-review.googlesource.com/c/1433634
> Commit-Queue: Jinsuk Kim <jinsukkim@chromium.org>
> Reviewed-by: Ted Choc <tedchoc@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#631436}

TBR=tedchoc@chromium.org,jinsukkim@chromium.org

Change-Id: I5bc79d0a2cdfc623c9fe78ba544de55c5d0bb239
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: 925242
Reviewed-on: https://chromium-review.googlesource.com/c/1469184
Reviewed-by: Jinsuk Kim <jinsukkim@chromium.org>
Commit-Queue: Jinsuk Kim <jinsukkim@chromium.org>
Cr-Commit-Position: refs/heads/master@{#631512}
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/ChromeActivity.java b/chrome/android/java/src/org/chromium/chrome/browser/ChromeActivity.java
index 1045c60..0089194 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/ChromeActivity.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/ChromeActivity.java
@@ -2245,10 +2245,8 @@
             }
         } else if (id == R.id.request_desktop_site_id || id == R.id.request_desktop_site_check_id) {
             final boolean reloadOnChange = !currentTab.isNativePage();
-            final boolean usingDesktopUserAgent =
-                    currentTab.getWebContents().getNavigationController().getUseDesktopUserAgent();
-            currentTab.getWebContents().getNavigationController().setUseDesktopUserAgent(
-                    !usingDesktopUserAgent, reloadOnChange);
+            final boolean usingDesktopUserAgent = currentTab.getUseDesktopUserAgent();
+            currentTab.setUseDesktopUserAgent(!usingDesktopUserAgent, reloadOnChange);
             RecordUserAction.record("MobileMenuRequestDesktopSite");
         } else if (id == R.id.reader_mode_prefs_id) {
             DomDistillerUIUtils.openSettings(currentTab.getWebContents());
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/appmenu/AppMenuPropertiesDelegate.java b/chrome/android/java/src/org/chromium/chrome/browser/appmenu/AppMenuPropertiesDelegate.java
index 36c49a5..a190cdd 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/appmenu/AppMenuPropertiesDelegate.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/appmenu/AppMenuPropertiesDelegate.java
@@ -438,8 +438,7 @@
         requestMenuRow.setVisible(itemVisible);
         if (!itemVisible) return;
 
-        boolean isRds =
-                currentTab.getWebContents().getNavigationController().getUseDesktopUserAgent();
+        boolean isRds = currentTab.getUseDesktopUserAgent();
         // Mark the checkbox if RDS is activated on this page.
         requestMenuCheck.setChecked(isRds);
 
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/compositor/layouts/LayoutManager.java b/chrome/android/java/src/org/chromium/chrome/browser/compositor/layouts/LayoutManager.java
index f507480e..fd3954e 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/compositor/layouts/LayoutManager.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/compositor/layouts/LayoutManager.java
@@ -36,7 +36,6 @@
 import org.chromium.chrome.browser.contextualsearch.ContextualSearchManagementDelegate;
 import org.chromium.chrome.browser.fullscreen.ChromeFullscreenManager;
 import org.chromium.chrome.browser.fullscreen.FullscreenManager;
-import org.chromium.chrome.browser.native_page.NativePageFactory;
 import org.chromium.chrome.browser.ntp.NewTabPage;
 import org.chromium.chrome.browser.tab.SadTab;
 import org.chromium.chrome.browser.tab.Tab;
@@ -646,7 +645,7 @@
         boolean isNtp = tab.getNativePage() instanceof NewTabPage;
         boolean isLocationBarShownInNtp =
                 isNtp ? ((NewTabPage) tab.getNativePage()).isLocationBarShownInNTP() : false;
-        boolean needsUpdate = layoutTab.initFromHost(tab.getBackgroundColor(), shouldStall(tab),
+        boolean needsUpdate = layoutTab.initFromHost(tab.getBackgroundColor(), tab.shouldStall(),
                 canUseLiveTexture, themeColor,
                 ColorUtils.getTextBoxColorForToolbarBackground(
                         mContext.getResources(), isLocationBarShownInNtp, themeColor),
@@ -656,12 +655,6 @@
         mHost.requestRender();
     }
 
-    // Whether the tab is ready to display or it should be faded in as it loads.
-    private static boolean shouldStall(Tab tab) {
-        return (tab.isFrozen() || tab.needsReload())
-                && !NativePageFactory.isNativePageUrl(tab.getUrl(), tab.isIncognito());
-    }
-
     @Override
     public LayoutTab createLayoutTab(int id, boolean incognito, boolean showCloseButton,
             boolean isTitleNeeded, float maxContentWidth, float maxContentHeight) {
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/tab/Tab.java b/chrome/android/java/src/org/chromium/chrome/browser/tab/Tab.java
index 0423b49..2c0e7cb9 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/tab/Tab.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/tab/Tab.java
@@ -866,6 +866,14 @@
         }
     }
 
+    /**
+     * @return Whether or not the loading and rendering of the page is done.
+     */
+    @VisibleForTesting
+    public boolean isLoadingAndRenderingDone() {
+        return isReady() && getProgress() >= CONSIDERED_READY_LOAD_PERCENTAGE;
+    }
+
     /** Stop the current navigation. */
     public void stopLoading() {
         if (isLoading()) {
@@ -974,6 +982,27 @@
     }
 
     /**
+     * Set whether or not the content layer should be using a desktop user agent for the
+     * currently loaded page.
+     * @param useDesktop     If {@code true}, use a desktop user agent.  Otherwise use a mobile one.
+     * @param reloadOnChange Reload the page if the user agent has changed.
+     */
+    public void setUseDesktopUserAgent(boolean useDesktop, boolean reloadOnChange) {
+        if (getWebContents() != null) {
+            getWebContents().getNavigationController().setUseDesktopUserAgent(
+                    useDesktop, reloadOnChange);
+        }
+    }
+
+    /**
+     * @return Whether or not the content layer is using a desktop user agent.
+     */
+    public boolean getUseDesktopUserAgent() {
+        return getWebContents() != null
+                && getWebContents().getNavigationController().getUseDesktopUserAgent();
+    }
+
+    /**
      * @return The current {@link ConnectionSecurityLevel} for the tab.
      */
     // TODO(tedchoc): Remove this and transition all clients to use LocationBarModel directly.
@@ -1018,6 +1047,14 @@
     }
 
     /**
+     * @return Whether the tab is ready to display or it should be faded in as it loads.
+     */
+    public boolean shouldStall() {
+        return (isFrozen() || needsReload())
+                && !NativePageFactory.isNativePageUrl(getUrl(), isIncognito());
+    }
+
+    /**
      * Prepares the tab to be shown. This method is supposed to be called before the tab is
      * displayed. It restores the ContentView if it is not available after the cold start and
      * reloads the tab if its renderer has crashed.
diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/NavigateTest.java b/chrome/android/javatests/src/org/chromium/chrome/browser/NavigateTest.java
index 5655733..cb618ce4 100644
--- a/chrome/android/javatests/src/org/chromium/chrome/browser/NavigateTest.java
+++ b/chrome/android/javatests/src/org/chromium/chrome/browser/NavigateTest.java
@@ -260,18 +260,13 @@
 
         final Tab tab = mActivityTestRule.getActivity().getActivityTab();
         ThreadUtils.runOnUiThreadBlocking(
-                () -> tab.getWebContents().getNavigationController().setUseDesktopUserAgent(
-                        true /* useDesktop */, true /* reloadOnChange */));
+                () -> tab.setUseDesktopUserAgent(true /* useDesktop */, true /* reloadOnChange */));
         ChromeTabUtils.waitForTabPageLoaded(tab, url1);
 
         DOMUtils.clickNode(tab.getWebContents(), "aboutLink");
         ChromeTabUtils.waitForTabPageLoaded(tab, url2);
         Assert.assertEquals("Request Desktop site setting should stay turned on", true,
-                mActivityTestRule.getActivity()
-                        .getActivityTab()
-                        .getWebContents()
-                        .getNavigationController()
-                        .getUseDesktopUserAgent());
+                mActivityTestRule.getActivity().getActivityTab().getUseDesktopUserAgent());
     }
 
     /**
diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/customtabs/CustomTabActivityTest.java b/chrome/android/javatests/src/org/chromium/chrome/browser/customtabs/CustomTabActivityTest.java
index 2ec1d79..f25bc7f 100644
--- a/chrome/android/javatests/src/org/chromium/chrome/browser/customtabs/CustomTabActivityTest.java
+++ b/chrome/android/javatests/src/org/chromium/chrome/browser/customtabs/CustomTabActivityTest.java
@@ -1475,7 +1475,7 @@
             @Override
             public boolean isSatisfied() {
                 final Tab currentTab = mCustomTabActivityTestRule.getActivity().getActivityTab();
-                return ChromeTabUtils.isLoadingAndRenderingDone(currentTab);
+                return currentTab.isLoadingAndRenderingDone();
             }
         });
         Assert.assertTrue(connection.postMessage(token, "Message", null)
diff --git a/chrome/test/android/javatests/src/org/chromium/chrome/test/MultiActivityTestRule.java b/chrome/test/android/javatests/src/org/chromium/chrome/test/MultiActivityTestRule.java
index 9c5328a..f0aa4164 100644
--- a/chrome/test/android/javatests/src/org/chromium/chrome/test/MultiActivityTestRule.java
+++ b/chrome/test/android/javatests/src/org/chromium/chrome/test/MultiActivityTestRule.java
@@ -19,7 +19,6 @@
 import org.chromium.chrome.browser.tabmodel.EmptyTabModelSelectorObserver;
 import org.chromium.chrome.browser.tabmodel.document.DocumentTabModelSelector;
 import org.chromium.chrome.test.util.ApplicationTestUtils;
-import org.chromium.chrome.test.util.ChromeTabUtils;
 import org.chromium.chrome.test.util.browser.tabmodel.document.MockStorageDelegate;
 import org.chromium.content_public.browser.test.util.Criteria;
 import org.chromium.content_public.browser.test.util.CriteriaHelper;
@@ -52,7 +51,7 @@
         CriteriaHelper.pollUiThread(new Criteria() {
             @Override
             public boolean isSatisfied() {
-                if (!ChromeTabUtils.isLoadingAndRenderingDone(tab)) return false;
+                if (!tab.isLoadingAndRenderingDone()) return false;
                 if (!TextUtils.equals(expectedTitle, tab.getTitle())) return false;
                 return true;
             }
diff --git a/chrome/test/android/javatests/src/org/chromium/chrome/test/util/ChromeTabUtils.java b/chrome/test/android/javatests/src/org/chromium/chrome/test/util/ChromeTabUtils.java
index 52d5f0e..c418102e 100644
--- a/chrome/test/android/javatests/src/org/chromium/chrome/test/util/ChromeTabUtils.java
+++ b/chrome/test/android/javatests/src/org/chromium/chrome/test/util/ChromeTabUtils.java
@@ -53,13 +53,6 @@
 public class ChromeTabUtils {
     private static final String TAG = "cr_ChromeTabUtils";
     public static final int TITLE_UPDATE_TIMEOUT_MS = 3000;
-
-    /**
-     * The required page load percentage for the page to be considered ready assuming the
-     * TextureView is also ready.
-     */
-    private static final int CONSIDERED_READY_LOAD_PERCENTAGE = 100;
-
     /**
      * An observer that waits for a Tab to load a page.
      *
@@ -766,11 +759,4 @@
                     "Tab title didn't update to %s in time.", newTitle));
         }
     }
-
-    /**
-     * @return Whether or not the loading and rendering of the page is done.
-     */
-    public static boolean isLoadingAndRenderingDone(Tab tab) {
-        return tab.isReady() && tab.getProgress() >= CONSIDERED_READY_LOAD_PERCENTAGE;
-    }
 }
diff --git a/chrome/test/android/javatests/src/org/chromium/chrome/test/util/browser/TabLoadObserver.java b/chrome/test/android/javatests/src/org/chromium/chrome/test/util/browser/TabLoadObserver.java
index 509fa3f..c47b6d2 100644
--- a/chrome/test/android/javatests/src/org/chromium/chrome/test/util/browser/TabLoadObserver.java
+++ b/chrome/test/android/javatests/src/org/chromium/chrome/test/util/browser/TabLoadObserver.java
@@ -12,7 +12,6 @@
 import org.chromium.base.test.util.CallbackHelper;
 import org.chromium.chrome.browser.tab.EmptyTabObserver;
 import org.chromium.chrome.browser.tab.Tab;
-import org.chromium.chrome.test.util.ChromeTabUtils;
 import org.chromium.content_public.browser.LoadUrlParams;
 import org.chromium.content_public.browser.test.util.Coordinates;
 import org.chromium.content_public.browser.test.util.Criteria;
@@ -96,7 +95,7 @@
         CriteriaHelper.pollUiThread(new Criteria() {
             @Override
             public boolean isSatisfied() {
-                if (!ChromeTabUtils.isLoadingAndRenderingDone(mTab)) {
+                if (!mTab.isLoadingAndRenderingDone()) {
                     updateFailureReason("load and rendering never completed");
                     return false;
                 }