[iOS] Remove TabGridPaging protocol

Implement the properties directly in the classes as it was never used
as a protocol elsewhere in the app.

Also make sure to set the TabGridMode and the ActivePage through
mediators.

Bug: None
Change-Id: I5dbb67f6cf3425a220169d8ed35db6594f58d4db
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5743502
Reviewed-by: Aliona Dangla <alionadangla@chromium.org>
Commit-Queue: Gauthier Ambard <gambard@chromium.org>
Code-Coverage: findit-for-me@appspot.gserviceaccount.com <findit-for-me@appspot.gserviceaccount.com>
Auto-Submit: Gauthier Ambard <gambard@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1334280}
diff --git a/ios/chrome/browser/ui/recent_tabs/recent_tabs_mediator.mm b/ios/chrome/browser/ui/recent_tabs/recent_tabs_mediator.mm
index dbdf6a1..8b9c20b 100644
--- a/ios/chrome/browser/ui/recent_tabs/recent_tabs_mediator.mm
+++ b/ios/chrome/browser/ui/recent_tabs/recent_tabs_mediator.mm
@@ -405,6 +405,10 @@
   self.currentMode = mode;
 }
 
+- (void)setPageAsActive {
+  NOTREACHED_NORETURN() << "Should not be called in remote tabs.";
+}
+
 #pragma mark - TabGridToolbarsGridDelegate
 
 - (void)closeAllButtonTapped:(id)sender {
diff --git a/ios/chrome/browser/ui/tab_switcher/tab_grid/grid/base_grid_mediator.mm b/ios/chrome/browser/ui/tab_switcher/tab_grid/grid/base_grid_mediator.mm
index 933b5d54..116159f 100644
--- a/ios/chrome/browser/ui/tab_switcher/tab_grid/grid/base_grid_mediator.mm
+++ b/ios/chrome/browser/ui/tab_switcher/tab_grid/grid/base_grid_mediator.mm
@@ -1654,6 +1654,10 @@
   self.currentMode = mode;
 }
 
+- (void)setPageAsActive {
+  NOTREACHED_NORETURN() << "Should be implemented in a subclass.";
+}
+
 #pragma mark - TabGridToolbarsGridDelegate
 
 - (void)closeAllButtonTapped:(id)sender {
diff --git a/ios/chrome/browser/ui/tab_switcher/tab_grid/grid/grid_empty_view.h b/ios/chrome/browser/ui/tab_switcher/tab_grid/grid/grid_empty_view.h
index f00bbee..7fd0cdb 100644
--- a/ios/chrome/browser/ui/tab_switcher/tab_grid/grid/grid_empty_view.h
+++ b/ios/chrome/browser/ui/tab_switcher/tab_grid/grid/grid_empty_view.h
@@ -10,10 +10,15 @@
 #import "ios/chrome/browser/ui/tab_switcher/tab_grid/tab_grid_paging.h"
 
 // Protocol defining the interface of the view displayed when the grid is empty.
-@protocol GridEmptyView <TabGridPaging>
+@protocol GridEmptyView
 
 // Insets of the inner ScrollView.
 @property(nonatomic, assign) UIEdgeInsets scrollViewContentInsets;
+// Active page of the tab grid. The active page is the page that
+// contains the most recent active tab.
+@property(nonatomic, assign) TabGridPage activePage;
+// The current mode of the empty grid.
+@property(nonatomic, assign) TabGridMode tabGridMode;
 
 @end
 
diff --git a/ios/chrome/browser/ui/tab_switcher/tab_grid/grid/incognito/incognito_grid_mediator.mm b/ios/chrome/browser/ui/tab_switcher/tab_grid/grid/incognito/incognito_grid_mediator.mm
index 20f06b4cb..63d9854 100644
--- a/ios/chrome/browser/ui/tab_switcher/tab_grid/grid/incognito/incognito_grid_mediator.mm
+++ b/ios/chrome/browser/ui/tab_switcher/tab_grid/grid/incognito/incognito_grid_mediator.mm
@@ -109,6 +109,10 @@
   }
 }
 
+- (void)setPageAsActive {
+  [self.gridConsumer setActivePageFromPage:TabGridPageIncognitoTabs];
+}
+
 #pragma mark - TabGridToolbarsGridDelegate
 
 - (void)closeAllButtonTapped:(id)sender {
diff --git a/ios/chrome/browser/ui/tab_switcher/tab_grid/grid/regular/regular_grid_mediator.mm b/ios/chrome/browser/ui/tab_switcher/tab_grid/grid/regular/regular_grid_mediator.mm
index 21b4f5ea..4f369bb 100644
--- a/ios/chrome/browser/ui/tab_switcher/tab_grid/grid/regular/regular_grid_mediator.mm
+++ b/ios/chrome/browser/ui/tab_switcher/tab_grid/grid/regular/regular_grid_mediator.mm
@@ -90,6 +90,10 @@
   }
 }
 
+- (void)setPageAsActive {
+  [self.gridConsumer setActivePageFromPage:TabGridPageRegularTabs];
+}
+
 #pragma mark - TabGridToolbarsGridDelegate
 
 - (void)closeAllButtonTapped:(id)sender {
diff --git a/ios/chrome/browser/ui/tab_switcher/tab_grid/tab_grid_coordinator.mm b/ios/chrome/browser/ui/tab_switcher/tab_grid/tab_grid_coordinator.mm
index 09faa4c8..56fa139 100644
--- a/ios/chrome/browser/ui/tab_switcher/tab_grid/tab_grid_coordinator.mm
+++ b/ios/chrome/browser/ui/tab_switcher/tab_grid/tab_grid_coordinator.mm
@@ -372,8 +372,7 @@
 
 - (void)setActivePage:(TabGridPage)page {
   DCHECK(page != TabGridPageRemoteTabs);
-  [_mediator setPage:page];
-  self.baseViewController.activePage = page;
+  [_mediator setActivePage:page];
 }
 
 - (void)setActiveMode:(TabGridMode)mode {
@@ -557,12 +556,10 @@
   // Finally, the launch mask view should be removed.
   ProceduralBlock extendedCompletion = ^{
     [self.delegate tabGridDismissTransitionDidEnd:self];
-    if (self.baseViewController.tabGridMode == TabGridModeSearch) {
-      // In search mode, the tabgrid mode is not reset before the animation so
-      // the animation can start from the correct cell. Once the animation is
-      // complete, reset the tab grid mode.
-      [self setActiveMode:TabGridModeNormal];
-    }
+    // In search mode, the tabgrid mode is not reset before the animation so
+    // the animation can start from the correct cell. Once the animation is
+    // complete, reset the tab grid mode.
+    [self setActiveMode:TabGridModeNormal];
     Browser* browser = self.bvcContainer.incognito ? self.incognitoBrowser
                                                    : self.regularBrowser;
     if (!GetFirstResponderInWindowScene(
diff --git a/ios/chrome/browser/ui/tab_switcher/tab_grid/tab_grid_mediator.h b/ios/chrome/browser/ui/tab_switcher/tab_grid/tab_grid_mediator.h
index a33a502c..0b1d717 100644
--- a/ios/chrome/browser/ui/tab_switcher/tab_grid/tab_grid_mediator.h
+++ b/ios/chrome/browser/ui/tab_switcher/tab_grid/tab_grid_mediator.h
@@ -48,8 +48,9 @@
     NS_DESIGNATED_INITIALIZER;
 
 - (instancetype)init NS_UNAVAILABLE;
-// Set the current displayed page (incognito, regular or remote).
-- (void)setPage:(TabGridPage)page;
+
+// Set the active page (incognito, regular or remote).
+- (void)setActivePage:(TabGridPage)page;
 // Set the current mode (normal/selection/search/inactive) on the currently
 // displayed page.
 - (void)setModeOnCurrentPage:(TabGridMode)mode;
diff --git a/ios/chrome/browser/ui/tab_switcher/tab_grid/tab_grid_mediator.mm b/ios/chrome/browser/ui/tab_switcher/tab_grid/tab_grid_mediator.mm
index 538a31e..fe64be6 100644
--- a/ios/chrome/browser/ui/tab_switcher/tab_grid/tab_grid_mediator.mm
+++ b/ios/chrome/browser/ui/tab_switcher/tab_grid/tab_grid_mediator.mm
@@ -89,8 +89,9 @@
 
 #pragma mark - Public
 
-- (void)setPage:(TabGridPage)page {
+- (void)setActivePage:(TabGridPage)page {
   [self notifyPageMutatorAboutPage:page];
+  [_currentPageMutator setPageAsActive];
 }
 
 - (void)setModeOnCurrentPage:(TabGridMode)mode {
diff --git a/ios/chrome/browser/ui/tab_switcher/tab_grid/tab_grid_page_mutator.h b/ios/chrome/browser/ui/tab_switcher/tab_grid/tab_grid_page_mutator.h
index 75aa291..32bd60b 100644
--- a/ios/chrome/browser/ui/tab_switcher/tab_grid/tab_grid_page_mutator.h
+++ b/ios/chrome/browser/ui/tab_switcher/tab_grid/tab_grid_page_mutator.h
@@ -19,6 +19,9 @@
 // Notifies the model that the mode the grid should switch to `mode`.
 - (void)switchToMode:(TabGridMode)mode;
 
+// Notifies the model that the current page is the active one.
+- (void)setPageAsActive;
+
 @end
 
 #endif  // IOS_CHROME_BROWSER_UI_TAB_SWITCHER_TAB_GRID_TAB_GRID_PAGE_MUTATOR_H_
diff --git a/ios/chrome/browser/ui/tab_switcher/tab_grid/tab_grid_paging.h b/ios/chrome/browser/ui/tab_switcher/tab_grid/tab_grid_paging.h
index b28d61a5..06c4ce2 100644
--- a/ios/chrome/browser/ui/tab_switcher/tab_grid/tab_grid_paging.h
+++ b/ios/chrome/browser/ui/tab_switcher/tab_grid/tab_grid_paging.h
@@ -22,13 +22,4 @@
   TabGridModeGroup = 4,
 };
 
-// An object implementing this protocol can change the active "page" or the mode
-// of the tab grid.
-@protocol TabGridPaging <NSObject>
-// Active page of the tab grid. The active page is the page that
-// contains the most recent active tab.
-@property(nonatomic, assign) TabGridPage activePage;
-@property(nonatomic, assign) TabGridMode tabGridMode;
-@end
-
 #endif  // IOS_CHROME_BROWSER_UI_TAB_SWITCHER_TAB_GRID_TAB_GRID_PAGING_H_
diff --git a/ios/chrome/browser/ui/tab_switcher/tab_grid/tab_grid_view_controller.h b/ios/chrome/browser/ui/tab_switcher/tab_grid/tab_grid_view_controller.h
index 32cfb7a..1b596472 100644
--- a/ios/chrome/browser/ui/tab_switcher/tab_grid/tab_grid_view_controller.h
+++ b/ios/chrome/browser/ui/tab_switcher/tab_grid/tab_grid_view_controller.h
@@ -103,7 +103,6 @@
                         KeyCommandActions,
                         TabGridConsumer,
                         TabGridIdleStatusHandler,
-                        TabGridPaging,
                         TabGridToolbarsMainTabGridDelegate,
                         TabGridTransitionLayoutProviding,
                         UISearchBarDelegate>
@@ -179,6 +178,9 @@
 @property(nonatomic, weak)
     GridContainerViewController* remoteGridContainerViewController;
 
+// Active page of the tab grid. The active page is the page that
+// contains the most recent active tab.
+@property(nonatomic, assign, readonly) TabGridPage activePage;
 // The currently visible page.
 @property(nonatomic, assign, readonly) TabGridPage currentPage;
 
diff --git a/ios/chrome/browser/ui/tab_switcher/tab_grid/tab_grid_view_controller.mm b/ios/chrome/browser/ui/tab_switcher/tab_grid/tab_grid_view_controller.mm
index d3919d7..c43d13b8 100644
--- a/ios/chrome/browser/ui/tab_switcher/tab_grid/tab_grid_view_controller.mm
+++ b/ios/chrome/browser/ui/tab_switcher/tab_grid/tab_grid_view_controller.mm
@@ -129,15 +129,21 @@
 @property(nonatomic, strong)
     DisabledGridViewController* remoteDisabledViewController;
 
+// Redefined as readwrite
+@property(nonatomic, assign, readwrite) TabGridPage activePage;
+// Setting the current page doesn't scroll the scroll view; use
+// -scrollToPage:animated: for that. Redefined as readwrite.
+@property(nonatomic, assign, readwrite) TabGridPage currentPage;
+
+// Current mode of the tab grid.
+@property(nonatomic, assign) TabGridMode tabGridMode;
+
 // Other UI components.
 @property(nonatomic, weak) UIScrollView* scrollView;
 @property(nonatomic, weak) UIView* scrollContentView;
 // Scrim view to be presented when the search box in focused with no text.
 @property(nonatomic, strong) UIControl* scrimView;
 @property(nonatomic, assign) TabGridConfiguration configuration;
-// Setting the current page doesn't scroll the scroll view; use
-// -scrollToPage:animated: for that. Redefined as readwrite.
-@property(nonatomic, assign, readwrite) TabGridPage currentPage;
 // The UIViewController corresponding with `currentPage`.
 @property(nonatomic, readonly) UIViewController* currentPageViewController;
 // Whether the scroll view is animating its content offset to the current page.
@@ -184,10 +190,6 @@
   BOOL _backgroundedSinceEntering;
 }
 
-// TabGridPaging property.
-@synthesize activePage = _activePage;
-@synthesize tabGridMode = _tabGridMode;
-
 - (instancetype)initWithPageConfiguration:
     (TabGridPageConfiguration)tabGridPageConfiguration {
   self = [super initWithNibName:nil bundle:nil];
@@ -571,19 +573,6 @@
   return self.remoteTabsViewController;
 }
 
-#pragma mark - TabGridPaging
-
-- (void)setActivePage:(TabGridPage)activePage {
-  [self scrollToPage:activePage animated:YES];
-  [self.activityObserver updateLastActiveTabPage:activePage];
-  if (activePage != _activePage) {
-    // Usually, an active page change is a result of an in-page action happening
-    // on a previously non-active page.
-    [self tabGridDidPerformAction:TabGridActionType::kInPageAction];
-  }
-  _activePage = activePage;
-}
-
 #pragma mark - TabGridMode
 
 - (void)setTabGridMode:(TabGridMode)mode {
@@ -734,6 +723,17 @@
   }
 }
 
+- (void)setActivePage:(TabGridPage)activePage {
+  [self scrollToPage:activePage animated:YES];
+  [self.activityObserver updateLastActiveTabPage:activePage];
+  if (activePage != _activePage) {
+    // Usually, an active page change is a result of an in-page action happening
+    // on a previously non-active page.
+    [self tabGridDidPerformAction:TabGridActionType::kInPageAction];
+  }
+  _activePage = activePage;
+}
+
 - (void)setCurrentPage:(TabGridPage)currentPage {
   // Record the idle metric if the previous page was the third panel.
   if (_currentPage != currentPage) {
diff --git a/ios/chrome/browser/ui/tab_switcher/tab_grid/tab_groups/tab_groups_panel_mediator.mm b/ios/chrome/browser/ui/tab_switcher/tab_grid/tab_groups/tab_groups_panel_mediator.mm
index ceb19e7..6b06917f 100644
--- a/ios/chrome/browser/ui/tab_switcher/tab_grid/tab_groups/tab_groups_panel_mediator.mm
+++ b/ios/chrome/browser/ui/tab_switcher/tab_grid/tab_groups/tab_groups_panel_mediator.mm
@@ -130,6 +130,10 @@
       << "Tab Groups panel should only support Normal mode.";
 }
 
+- (void)setPageAsActive {
+  NOTREACHED_NORETURN() << "Should not be called in Tab Groups.";
+}
+
 #pragma mark TabGridToolbarsGridDelegate
 
 - (void)closeAllButtonTapped:(id)sender {