Commit d0d3a891 authored by Mohammad Refaat's avatar Mohammad Refaat Committed by Commit Bot

Use Browser in TabSwitcher/Delegate Protocol instead of TabModel

Also update users to call the new methods.

Bug: 1042277, 783777
Change-Id: Ie318b3828f9a1e00c86e5e731c9ff758a9283931
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2008071
Commit-Queue: Mohammad Refaat <mrefaat@chromium.org>
Reviewed-by: default avatarMark Cogan <marq@chromium.org>
Cr-Commit-Position: refs/heads/master@{#734092}
parent e6d6f2ef
......@@ -1208,9 +1208,9 @@ void MainControllerAuthenticationServiceDelegate::ClearBrowsingData(
_tabSwitcher = self.mainCoordinator.tabSwitcher;
// Call -restoreInternalState so that the grid shows the correct panel.
[_tabSwitcher restoreInternalStateWithMainTabModel:self.mainTabModel
otrTabModel:self.otrTabModel
activeTabModel:self.currentTabModel];
[_tabSwitcher restoreInternalStateWithMainBrowser:self.mainBrowser
otrBrowser:self.otrBrowser
activeBrowser:self.currentBrowser];
// Decide if the First Run UI needs to run.
BOOL firstRun = (FirstRun::IsChromeFirstRun() ||
......@@ -1444,6 +1444,10 @@ void MainControllerAuthenticationServiceDelegate::ClearBrowsingData(
return self.currentBVC.tabModel;
}
- (Browser*)currentBrowser {
return self.interfaceProvider.currentInterface.browser;
}
- (ios::ChromeBrowserState*)currentBrowserState {
return self.currentBVC.browserState;
}
......
......@@ -619,9 +619,9 @@ enum class EnterTabSwitcherSnapshotResult {
#pragma mark - TabSwitcherDelegate
- (void)tabSwitcher:(id<TabSwitcher>)tabSwitcher
shouldFinishWithActiveModel:(TabModel*)tabModel
focusOmnibox:(BOOL)focusOmnibox {
[self beginDismissingTabSwitcherWithCurrentModel:tabModel
shouldFinishWithBrowser:(Browser*)browser
focusOmnibox:(BOOL)focusOmnibox {
[self beginDismissingTabSwitcherWithCurrentModel:browser->GetTabModel()
focusOmnibox:focusOmnibox];
}
......@@ -1282,9 +1282,9 @@ enum class EnterTabSwitcherSnapshotResult {
// Tab switcher implementations may need to rebuild state before being
// displayed.
[self.mainController.tabSwitcher
restoreInternalStateWithMainTabModel:self.mainInterface.tabModel
otrTabModel:self.incognitoInterface.tabModel
activeTabModel:self.currentTabModel];
restoreInternalStateWithMainBrowser:self.mainInterface.browser
otrBrowser:self.incognitoInterface.browser
activeBrowser:self.currentInterface.browser];
self.mainController.tabSwitcherIsActive = YES;
[self.mainController.tabSwitcher setDelegate:self];
......
......@@ -7,7 +7,6 @@
#include "base/logging.h"
#import "ios/chrome/browser/main/browser.h"
#include "ios/chrome/browser/main/browser.h"
#import "ios/chrome/browser/tabs/tab_model.h"
#import "ios/chrome/browser/ui/tab_grid/tab_grid_paging.h"
#import "ios/chrome/browser/ui/tab_grid/tab_grid_view_controller.h"
#import "ios/chrome/browser/ui/tab_grid/view_controller_swapping.h"
......@@ -26,12 +25,12 @@
#pragma mark - TabSwitcher
- (void)restoreInternalStateWithMainTabModel:(TabModel*)mainModel
otrTabModel:(TabModel*)otrModel
activeTabModel:(TabModel*)activeModel {
- (void)restoreInternalStateWithMainBrowser:(Browser*)mainBrowser
otrBrowser:(Browser*)otrBrowser
activeBrowser:(Browser*)activeBrowser {
// The only action here is to signal to the tab grid which panel should be
// active.
if (activeModel == otrModel) {
if (activeBrowser == otrBrowser) {
self.tabGridViewController.activePage = TabGridPageIncognitoTabs;
} else {
self.tabGridViewController.activePage = TabGridPageRegularTabs;
......@@ -53,8 +52,8 @@
// Tell the delegate to display the tab.
DCHECK(self.delegate);
[self.delegate tabSwitcher:self
shouldFinishWithActiveModel:browser->GetTabModel()
focusOmnibox:NO];
shouldFinishWithBrowser:browser
focusOmnibox:NO];
}
- (void)setOtrBrowser:(Browser*)browser {
......
......@@ -11,7 +11,6 @@
#include "ios/chrome/browser/chrome_url_constants.h"
#include "ios/chrome/browser/main/browser.h"
#include "ios/chrome/browser/sessions/ios_chrome_tab_restore_service_factory.h"
#import "ios/chrome/browser/tabs/tab_model.h"
#import "ios/chrome/browser/ui/commands/browser_commands.h"
#import "ios/chrome/browser/ui/commands/browsing_data_commands.h"
#import "ios/chrome/browser/ui/commands/command_dispatcher.h"
......@@ -361,15 +360,15 @@
- (void)showActiveTabInPage:(TabGridPage)page focusOmnibox:(BOOL)focusOmnibox {
DCHECK(self.regularBrowser && self.incognitoBrowser);
TabModel* activeTabModel;
Browser* activeBrowser = nullptr;
switch (page) {
case TabGridPageIncognitoTabs:
DCHECK_GT(self.incognitoBrowser->GetWebStateList()->count(), 0);
activeTabModel = self.incognitoBrowser->GetTabModel();
activeBrowser = self.incognitoBrowser;
break;
case TabGridPageRegularTabs:
DCHECK_GT(self.regularBrowser->GetWebStateList()->count(), 0);
activeTabModel = self.regularBrowser->GetTabModel();
activeBrowser = self.regularBrowser;
break;
case TabGridPageRemoteTabs:
NOTREACHED() << "It is invalid to have an active tab in remote tabs.";
......@@ -378,7 +377,7 @@
// Trigger the transition through the TabSwitcher delegate. This will in turn
// call back into this coordinator via the ViewControllerSwapping protocol.
[self.tabSwitcher.delegate tabSwitcher:self.tabSwitcher
shouldFinishWithActiveModel:activeTabModel
shouldFinishWithBrowser:activeBrowser
focusOmnibox:focusOmnibox];
}
......@@ -407,7 +406,7 @@
- (void)showActiveRegularTabFromRecentTabs {
[self.tabSwitcher.delegate tabSwitcher:self.tabSwitcher
shouldFinishWithActiveModel:self.regularBrowser->GetTabModel()
shouldFinishWithBrowser:self.regularBrowser
focusOmnibox:NO];
}
......@@ -415,13 +414,13 @@
- (void)showActiveRegularTabFromHistory {
[self.tabSwitcher.delegate tabSwitcher:self.tabSwitcher
shouldFinishWithActiveModel:self.regularBrowser->GetTabModel()
shouldFinishWithBrowser:self.regularBrowser
focusOmnibox:NO];
}
- (void)showActiveIncognitoTabFromHistory {
[self.tabSwitcher.delegate tabSwitcher:self.tabSwitcher
shouldFinishWithActiveModel:self.incognitoBrowser->GetTabModel()
shouldFinishWithBrowser:self.incognitoBrowser
focusOmnibox:NO];
}
......
......@@ -24,8 +24,8 @@
@implementation TestTabSwitcherDelegate
@synthesize didEndCalled = _didEndCalled;
- (void)tabSwitcher:(id<TabSwitcher>)tabSwitcher
shouldFinishWithActiveModel:(TabModel*)tabModel
focusOmnibox:(BOOL)focusOmnibox {
shouldFinishWithBrowser:(Browser*)browser
focusOmnibox:(BOOL)focusOmnibox {
// No-op.
}
......
......@@ -12,7 +12,6 @@
#include "url/gurl.h"
class Browser;
@class TabModel;
@protocol TabSwitcher;
struct UrlLoadParams;
......@@ -22,10 +21,10 @@ struct UrlLoadParams;
@protocol TabSwitcherDelegate <NSObject>
// Informs the delegate the tab switcher should be dismissed with the given
// active model.
// active browser.
- (void)tabSwitcher:(id<TabSwitcher>)tabSwitcher
shouldFinishWithActiveModel:(TabModel*)tabModel
focusOmnibox:(BOOL)focusOmnibox;
shouldFinishWithBrowser:(Browser*)browser
focusOmnibox:(BOOL)focusOmnibox;
// Informs the delegate that the tab switcher is done and should be
// dismissed.
......@@ -42,22 +41,22 @@ struct UrlLoadParams;
// switcher.
@property(nonatomic, weak) id<TabSwitcherDelegate> delegate;
// Restores the internal state of the tab switcher with the given tab models,
// which must not be nil. |activeTabModel| is the model which starts active,
// and must be one of the other two models. Should only be called when the
// Restores the internal state of the tab switcher with the given browser,
// which must not be nil. |activeBrowser| is the browser which starts active,
// and must be one of the other two browsers. Should only be called when the
// object is not being shown.
- (void)restoreInternalStateWithMainTabModel:(TabModel*)mainModel
otrTabModel:(TabModel*)otrModel
activeTabModel:(TabModel*)activeModel;
- (void)restoreInternalStateWithMainBrowser:(Browser*)mainBrowser
otrBrowser:(Browser*)otrBrowser
activeBrowser:(Browser*)activeBrowser;
// Returns the view controller that displays the tab switcher.
- (UIViewController*)viewController;
// Create a new tab in |targetModel|. Implementors are expected to also perform
// an animation from the selected tab in the tab switcher to the newly created
// tab in the content area. Objects adopting this protocol should call the
// following delegate methods:
// |-tabSwitcher:shouldFinishWithActiveModel:|
// Create a new tab in |browser|. Implementors are expected to also perform an
// animation from the selected tab in the tab switcher to the newly created tab
// in the content area. Objects adopting this protocol should call the following
// delegate methods:
// |-tabSwitcher:shouldFinishWithBrowser:|
// |-tabSwitcherDismissTransitionDidEnd:|
// to inform the delegate when this animation begins and ends.
- (void)dismissWithNewTabAnimationToBrowser:(Browser*)browser
......@@ -66,8 +65,8 @@ struct UrlLoadParams;
// Updates the OTR (Off The Record) browser. Should only be called when both
// the current OTR browser and the new OTR browser are either nil or contain no
// tabs. This must be called after the otr tab model has been deleted because
// the incognito browser state is deleted.
// tabs. This must be called after the otr browser has been deleted because the
// incognito browser state is deleted.
- (void)setOtrBrowser:(Browser*)otrBrowser;
@end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment