| Index: ios/clean/chrome/browser/ui/tab_grid/tab_grid_coordinator.mm
|
| diff --git a/ios/clean/chrome/browser/ui/tab_grid/tab_grid_coordinator.mm b/ios/clean/chrome/browser/ui/tab_grid/tab_grid_coordinator.mm
|
| index 1b620951c1f70b2fac738686876e148534d96095..9362a1478e51b040675be78acb9f08263eb321f6 100644
|
| --- a/ios/clean/chrome/browser/ui/tab_grid/tab_grid_coordinator.mm
|
| +++ b/ios/clean/chrome/browser/ui/tab_grid/tab_grid_coordinator.mm
|
| @@ -21,6 +21,7 @@
|
| #import "ios/clean/chrome/browser/ui/tab/tab_coordinator.h"
|
| #import "ios/clean/chrome/browser/ui/tab_grid/tab_grid_view_controller.h"
|
| #import "ios/shared/chrome/browser/coordinator_context/coordinator_context.h"
|
| +#import "ios/shared/chrome/browser/tabs/web_state_list.h"
|
| #import "ios/web/public/navigation_manager.h"
|
| #include "ios/web/public/web_state/web_state.h"
|
| #import "net/base/mac/url_conversions.h"
|
| @@ -33,13 +34,10 @@
|
| @interface TabGridCoordinator ()<TabGridDataSource,
|
| SettingsCommands,
|
| TabCommands,
|
| - TabGridCommands> {
|
| - std::vector<std::unique_ptr<web::WebState>> _webStates;
|
| - size_t _activeWebStateIndex;
|
| -}
|
| -
|
| + TabGridCommands>
|
| @property(nonatomic, strong) TabGridViewController* viewController;
|
| @property(nonatomic, weak) SettingsCoordinator* settingsCoordinator;
|
| +@property(nonatomic, readonly) WebStateList& webStateList;
|
| @end
|
|
|
| @implementation TabGridCoordinator
|
| @@ -55,9 +53,13 @@
|
| web::WebState::CreateParams webStateCreateParams(browser->browser_state());
|
| std::unique_ptr<web::WebState> webState =
|
| web::WebState::Create(webStateCreateParams);
|
| - _webStates.push_back(std::move(webState));
|
| + self.webStateList.InsertWebState(0, webState.release(), nullptr);
|
| }
|
| - _activeWebStateIndex = 0;
|
| + self.webStateList.ActivateWebStateAt(0);
|
| +}
|
| +
|
| +- (WebStateList&)webStateList {
|
| + return self.browser->web_state_list();
|
| }
|
|
|
| #pragma mark - BrowserCoordinator
|
| @@ -80,15 +82,12 @@
|
|
|
| #pragma mark - TabGridDataSource
|
|
|
| -- (NSUInteger)numberOfTabsInTabGrid {
|
| - return static_cast<NSUInteger>(_webStates.size());
|
| +- (int)numberOfTabsInTabGrid {
|
| + return self.webStateList.count();
|
| }
|
|
|
| -- (NSString*)titleAtIndex:(NSInteger)index {
|
| - size_t i = static_cast<size_t>(index);
|
| - DCHECK(i < _webStates.size());
|
| - web::WebState* webState = _webStates[i].get();
|
| - GURL url = webState->GetVisibleURL();
|
| +- (NSString*)titleAtIndex:(int)index {
|
| + GURL url = self.webStateList.GetWebStateAt(index)->GetVisibleURL();
|
| NSString* urlText = @"<New Tab>";
|
| if (url.is_valid()) {
|
| urlText = base::SysUTF8ToNSString(url.spec());
|
| @@ -96,27 +95,30 @@
|
| return urlText;
|
| }
|
|
|
| -- (NSInteger)indexOfActiveTab {
|
| - return static_cast<NSInteger>(_activeWebStateIndex);
|
| +- (int)indexOfActiveTab {
|
| + return self.webStateList.active_index();
|
| }
|
|
|
| #pragma mark - TabCommands
|
|
|
| - (void)showTabAtIndexPath:(NSIndexPath*)indexPath {
|
| TabCoordinator* tabCoordinator = [[TabCoordinator alloc] init];
|
| - size_t index = static_cast<size_t>(indexPath.item);
|
| - DCHECK(index < _webStates.size());
|
| - tabCoordinator.webState = _webStates[index].get();
|
| + DCHECK_LE(indexPath.item, INT_MAX);
|
| + int index = static_cast<int>(indexPath.item);
|
| + self.webStateList.ActivateWebStateAt(index);
|
| + // PLACEHOLDER: The tab coordinator should be able to get the active webState
|
| + // on its own.
|
| + tabCoordinator.webState = self.webStateList.GetWebStateAt(index);
|
| tabCoordinator.presentationKey = indexPath;
|
| [self addChildCoordinator:tabCoordinator];
|
| [tabCoordinator start];
|
| - _activeWebStateIndex = index;
|
| }
|
|
|
| - (void)closeTabAtIndexPath:(NSIndexPath*)indexPath {
|
| - size_t index = static_cast<size_t>(indexPath.item);
|
| - DCHECK(index < _webStates.size());
|
| - _webStates.erase(_webStates.begin() + index);
|
| + DCHECK_LE(indexPath.item, INT_MAX);
|
| + int index = static_cast<int>(indexPath.item);
|
| + std::unique_ptr<web::WebState> closedWebState(
|
| + self.webStateList.DetachWebStateAt(index));
|
| }
|
|
|
| - (void)createNewTabAtIndexPath:(NSIndexPath*)indexPath {
|
| @@ -124,7 +126,8 @@
|
| self.browser->browser_state());
|
| std::unique_ptr<web::WebState> webState =
|
| web::WebState::Create(webStateCreateParams);
|
| - _webStates.push_back(std::move(webState));
|
| + self.webStateList.InsertWebState(self.webStateList.count(),
|
| + webState.release(), nullptr);
|
| }
|
|
|
| #pragma mark - TabGridCommands
|
| @@ -157,17 +160,19 @@
|
| #pragma mark - URLOpening
|
|
|
| - (void)openURL:(NSURL*)URL {
|
| + if (self.webStateList.active_index() == WebStateList::kInvalidIndex) {
|
| + return;
|
| + }
|
| [self.overlayCoordinator stop];
|
| [self removeOverlayCoordinator];
|
| - web::WebState* activeWebState = _webStates[_activeWebStateIndex].get();
|
| + web::WebState* activeWebState = self.webStateList.GetActiveWebState();
|
| web::NavigationManager::WebLoadParams params(net::GURLWithNSURL(URL));
|
| params.transition_type = ui::PAGE_TRANSITION_LINK;
|
| activeWebState->GetNavigationManager()->LoadURLWithParams(params);
|
| if (!self.children.count) {
|
| - [self showTabAtIndexPath:[NSIndexPath
|
| - indexPathForItem:static_cast<NSUInteger>(
|
| - _activeWebStateIndex)
|
| - inSection:0]];
|
| + [self
|
| + showTabAtIndexPath:[NSIndexPath indexPathForItem:[self indexOfActiveTab]
|
| + inSection:0]];
|
| }
|
| }
|
|
|
|
|