Commit 9eb4ca3d authored by Mohammad Refaat's avatar Mohammad Refaat Committed by Commit Bot

Remove didReplaceTab TabModelObserver's method

Replace by didReplaceWebState
Move logic from didChangeTab to updateTabViewForWebState
and use it inside didChangeTab & didReplaceWebState.

Bug: 911350
Change-Id: I198b7f39192fa52f5b0e79b72eb9949da27bc0a5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1620707
Commit-Queue: Mohammad Refaat <mrefaat@chromium.org>
Reviewed-by: default avatarMark Cogan <marq@chromium.org>
Cr-Commit-Position: refs/heads/master@{#662585}
parent d1fac4be
...@@ -15,12 +15,6 @@ ...@@ -15,12 +15,6 @@
@protocol TabModelObserver<NSObject> @protocol TabModelObserver<NSObject>
@optional @optional
// A Tab was replaced in the model, at the given index.
- (void)tabModel:(TabModel*)model
didReplaceTab:(Tab*)oldTab
withTab:(Tab*)newTab
atIndex:(NSUInteger)index;
// Some properties about the given tab changed, such as the URL or title. // Some properties about the given tab changed, such as the URL or title.
- (void)tabModel:(TabModel*)model didChangeTab:(Tab*)tab; - (void)tabModel:(TabModel*)model didChangeTab:(Tab*)tab;
......
...@@ -32,17 +32,4 @@ ...@@ -32,17 +32,4 @@
return self; return self;
} }
#pragma mark WebStateListObserving
- (void)webStateList:(WebStateList*)webStateList
didReplaceWebState:(web::WebState*)oldWebState
withWebState:(web::WebState*)newWebState
atIndex:(int)atIndex {
DCHECK_GE(atIndex, 0);
[_tabModelObservers tabModel:_tabModel
didReplaceTab:LegacyTabHelper::GetTabForWebState(oldWebState)
withTab:LegacyTabHelper::GetTabForWebState(newWebState)
atIndex:static_cast<NSUInteger>(atIndex)];
}
@end @end
...@@ -4412,6 +4412,22 @@ NSString* const kBrowserViewControllerSnackbarCategory = ...@@ -4412,6 +4412,22 @@ NSString* const kBrowserViewControllerSnackbarCategory =
} }
} }
// Observer method, WebState replaced in |webStateList|.
- (void)webStateList:(WebStateList*)webStateList
didReplaceWebState:(web::WebState*)oldWebState
withWebState:(web::WebState*)newWebState
atIndex:(int)atIndex {
[self uninstallDelegatesForWebState:oldWebState];
[self installDelegatesForWebState:newWebState];
// Add |newTab|'s view to the hierarchy if it's the current Tab.
if (self.active && self.currentWebState == newWebState)
[self displayWebState:newWebState];
if (newWebState)
[_paymentRequestManager setActiveWebState:newWebState];
}
// Observer method, |webState| inserted in |webStateList|. // Observer method, |webState| inserted in |webStateList|.
- (void)webStateList:(WebStateList*)webStateList - (void)webStateList:(WebStateList*)webStateList
didInsertWebState:(web::WebState*)webState didInsertWebState:(web::WebState*)webState
...@@ -4465,22 +4481,6 @@ NSString* const kBrowserViewControllerSnackbarCategory = ...@@ -4465,22 +4481,6 @@ NSString* const kBrowserViewControllerSnackbarCategory =
} }
} }
// Observer method, tab replaced.
- (void)tabModel:(TabModel*)model
didReplaceTab:(Tab*)oldTab
withTab:(Tab*)newTab
atIndex:(NSUInteger)index {
[self uninstallDelegatesForWebState:oldTab.webState];
[self installDelegatesForWebState:newTab.webState];
// Add |newTab|'s view to the hierarchy if it's the current Tab.
if (self.active && model.currentTab == newTab)
[self displayWebState:newTab.webState];
if (newTab)
[_paymentRequestManager setActiveWebState:newTab.webState];
}
#pragma mark - WebStateListObserver helpers (new tab animations) #pragma mark - WebStateListObserver helpers (new tab animations)
- (void)initiateNewTabAnimationForWebState:(web::WebState*)webState - (void)initiateNewTabAnimationForWebState:(web::WebState*)webState
......
...@@ -371,6 +371,9 @@ UIColor* BackgroundColor() { ...@@ -371,6 +371,9 @@ UIColor* BackgroundColor() {
// Updates the tab switcher button with the current tab count. // Updates the tab switcher button with the current tab count.
- (void)updateTabCount; - (void)updateTabCount;
// Updates the tab view fav icon & progress spinner based on the |webState|.
- (void)updateTabViewForWebState:(web::WebState*)webState;
@end @end
@implementation TabStripController @implementation TabStripController
...@@ -950,6 +953,33 @@ UIColor* BackgroundColor() { ...@@ -950,6 +953,33 @@ UIColor* BackgroundColor() {
_autoscrollDistance = -offset.x; _autoscrollDistance = -offset.x;
} }
- (void)updateTabViewForWebState:(web::WebState*)webState {
int modelIndex = _tabModel.webStateList->GetIndexOfWebState(webState);
if (modelIndex == WebStateList::kInvalidIndex) {
DCHECK(false) << "Received notification for a Webstate that is not "
<< "contained in the WebStateList";
return;
}
NSUInteger index = [self indexForModelIndex:modelIndex];
TabView* view = [_tabArray objectAtIndex:index];
[view setTitle:tab_util::GetTabTitle(webState)];
[view setFavicon:nil];
favicon::FaviconDriver* faviconDriver =
favicon::WebFaviconDriver::FromWebState(webState);
if (faviconDriver && faviconDriver->FaviconIsValid()) {
gfx::Image favicon = faviconDriver->GetFavicon();
if (!favicon.IsEmpty())
[view setFavicon:favicon.ToUIImage()];
}
if (webState->IsLoading() && !IsVisibleURLNewTabPage(webState))
[view startProgressSpinner];
else
[view stopProgressSpinner];
[view setNeedsDisplay];
}
#pragma mark - #pragma mark -
#pragma mark WebStateObserving methods #pragma mark WebStateObserving methods
...@@ -1046,6 +1076,16 @@ UIColor* BackgroundColor() { ...@@ -1046,6 +1076,16 @@ UIColor* BackgroundColor() {
[self updateTabCount]; [self updateTabCount];
} }
// Observer method, WebState replaced in |webStateList|.
- (void)webStateList:(WebStateList*)webStateList
didReplaceWebState:(web::WebState*)oldWebState
withWebState:(web::WebState*)newWebState
atIndex:(int)atIndex {
// TabViews do not hold references to their parent Tabs, so it's safe to treat
// this as a tab change rather than a tab replace.
[self updateTabViewForWebState:newWebState];
}
#pragma mark - #pragma mark -
#pragma mark TabModelObserver methods #pragma mark TabModelObserver methods
...@@ -1056,41 +1096,7 @@ UIColor* BackgroundColor() { ...@@ -1056,41 +1096,7 @@ UIColor* BackgroundColor() {
// there is no view to update yet. // there is no view to update yet.
if (_tabModel.count > _tabArray.count - _closingTabs.count) if (_tabModel.count > _tabArray.count - _closingTabs.count)
return; return;
[self updateTabViewForWebState:tab.webState];
NSUInteger modelIndex = [_tabModel indexOfTab:tab];
if (modelIndex == NSNotFound) {
DCHECK(false) << "Received notification for a Tab that is not contained in "
<< "the TabModel";
return;
}
NSUInteger index = [self indexForModelIndex:modelIndex];
TabView* view = [_tabArray objectAtIndex:index];
[view setTitle:tab_util::GetTabTitle(tab.webState)];
[view setFavicon:nil];
favicon::FaviconDriver* faviconDriver =
favicon::WebFaviconDriver::FromWebState(tab.webState);
if (faviconDriver && faviconDriver->FaviconIsValid()) {
gfx::Image favicon = faviconDriver->GetFavicon();
if (!favicon.IsEmpty())
[view setFavicon:favicon.ToUIImage()];
}
if (tab.webState->IsLoading() && !IsVisibleURLNewTabPage(tab.webState))
[view startProgressSpinner];
else
[view stopProgressSpinner];
[view setNeedsDisplay];
}
// Observer method.
- (void)tabModel:(TabModel*)model
didReplaceTab:(Tab*)oldTab
withTab:(Tab*)newTab
atIndex:(NSUInteger)index {
// TabViews do not hold references to their parent Tabs, so it's safe to treat
// this as a tab change rather than a tab replace.
[self tabModel:model didChangeTab:newTab];
} }
#pragma mark - #pragma mark -
......
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