Commit 03b05d64 authored by mrefaat's avatar mrefaat Committed by Commit Bot

[IOSTabRefactoring] Inline -view from Tab in BVC

-view used by the BVC - so instead move the functionality to viewForTab

Bug: 899832
Change-Id: I9958174df2468a7be4d1ab13c4f29cff3f81b2fb
Reviewed-on: https://chromium-review.googlesource.com/c/1313282
Commit-Queue: Mohammad Refaat <mrefaat@chromium.org>
Reviewed-by: default avatarEugene But <eugenebut@chromium.org>
Reviewed-by: default avataredchin <edchin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#608114}
parent 3e61409a
...@@ -108,10 +108,6 @@ extern NSString* const kProxyPassthroughHeaderValue; ...@@ -108,10 +108,6 @@ extern NSString* const kProxyPassthroughHeaderValue;
// TODO(crbug.com/228575): Create a delegate interface and remove this. // TODO(crbug.com/228575): Create a delegate interface and remove this.
- (void)setParentTabModel:(TabModel*)model; - (void)setParentTabModel:(TabModel*)model;
// The view to display in the view hierarchy based on the current URL. Won't be
// nil. It is up to the caller to size the view and confirm |webUsageEnabled|.
- (UIView*)view;
// The view that generates print data when printing. It can be nil when printing // The view that generates print data when printing. It can be nil when printing
// is not supported with this tab. It can be different from |Tab view|. // is not supported with this tab. It can be different from |Tab view|.
- (UIView*)viewForPrinting; - (UIView*)viewForPrinting;
......
...@@ -267,22 +267,6 @@ NSString* const kTabUrlKey = @"url"; ...@@ -267,22 +267,6 @@ NSString* const kTabUrlKey = @"url";
_parentTabModel = model; _parentTabModel = model;
} }
- (UIView*)view {
if (!self.webState)
return nil;
// Record reload of previously-evicted tab.
if (self.webState->IsEvicted() && [_parentTabModel tabUsageRecorder])
[_parentTabModel tabUsageRecorder]->RecordPageLoadStart(self.webState);
// Do not trigger the load if the tab has crashed. SadTabTabHelper is
// responsible for handing reload logic for crashed tabs.
if (!self.webState->IsCrashed()) {
self.webState->GetNavigationManager()->LoadIfNecessary();
}
return self.webState->GetView();
}
- (UIView*)viewForPrinting { - (UIView*)viewForPrinting {
return self.webController.viewForPrinting; return self.webController.viewForPrinting;
} }
...@@ -420,8 +404,7 @@ NSString* const kTabUrlKey = @"url"; ...@@ -420,8 +404,7 @@ NSString* const kTabUrlKey = @"url";
_openInController = [[OpenInController alloc] _openInController = [[OpenInController alloc]
initWithURLLoaderFactory:_browserState->GetSharedURLLoaderFactory() initWithURLLoaderFactory:_browserState->GetSharedURLLoaderFactory()
webController:self.webController]; webController:self.webController];
// If the tab was evicted before, It should have been loaded already before // Previously evicted tabs should be reloaded before this method is called.
// starting the open-in controller.
DCHECK(!self.webState->IsEvicted()); DCHECK(!self.webState->IsEvicted());
self.webState->GetNavigationManager()->LoadIfNecessary(); self.webState->GetNavigationManager()->LoadIfNecessary();
_openInController.baseView = self.webState->GetView(); _openInController.baseView = self.webState->GetView();
......
...@@ -2564,7 +2564,8 @@ applicationCommandEndpoint:(id<ApplicationCommands>)applicationCommandEndpoint { ...@@ -2564,7 +2564,8 @@ applicationCommandEndpoint:(id<ApplicationCommands>)applicationCommandEndpoint {
_browserContainerCoordinator.viewController.contentViewController = _browserContainerCoordinator.viewController.contentViewController =
viewController; viewController;
} else { } else {
_browserContainerCoordinator.viewController.contentView = tab.view; _browserContainerCoordinator.viewController.contentView =
[self viewForTab:tab];
} }
} }
[self updateToolbar]; [self updateToolbar];
...@@ -2713,14 +2714,22 @@ applicationCommandEndpoint:(id<ApplicationCommands>)applicationCommandEndpoint { ...@@ -2713,14 +2714,22 @@ applicationCommandEndpoint:(id<ApplicationCommands>)applicationCommandEndpoint {
- (UIView*)viewForTab:(Tab*)tab { - (UIView*)viewForTab:(Tab*)tab {
DCHECK(tab); DCHECK(tab);
if (tab.webState) { if (!tab.webState)
NewTabPageTabHelper* NTPHelper = return nil;
NewTabPageTabHelper::FromWebState(tab.webState); web::WebState* webState = tab.webState;
if (NTPHelper && NTPHelper->IsActive()) { NewTabPageTabHelper* NTPHelper = NewTabPageTabHelper::FromWebState(webState);
return _ntpCoordinatorsForWebStates[tab.webState].viewController.view; if (NTPHelper && NTPHelper->IsActive()) {
} return _ntpCoordinatorsForWebStates[webState].viewController.view;
}
// TODO(crbug.com/904588): Move |RecordPageLoadStart| to TabUsageRecorder.
if (webState->IsEvicted() && [tab.parentTabModel tabUsageRecorder]) {
[tab.parentTabModel tabUsageRecorder]->RecordPageLoadStart(webState);
}
if (!webState->IsCrashed()) {
// Load the page if it was evicted by browsing data clearing logic.
webState->GetNavigationManager()->LoadIfNecessary();
} }
return tab.view; return webState->GetView();
} }
#pragma mark - Private Methods: Find Bar UI #pragma mark - Private Methods: Find Bar UI
......
...@@ -194,10 +194,6 @@ class BrowserViewControllerTest : public BlockCleanupTest { ...@@ -194,10 +194,6 @@ class BrowserViewControllerTest : public BlockCleanupTest {
[[tabModel stub] setCurrentTab:[OCMArg any]]; [[tabModel stub] setCurrentTab:[OCMArg any]];
[[tabModel stub] closeAllTabs]; [[tabModel stub] closeAllTabs];
// Stub methods for Tab.
UIView* dummyView = [[UIView alloc] initWithFrame:CGRectZero];
[[[currentTab stub] andReturn:dummyView] view];
web::WebState::CreateParams params(chrome_browser_state_.get()); web::WebState::CreateParams params(chrome_browser_state_.get());
std::unique_ptr<web::WebState> webState = web::WebState::Create(params); std::unique_ptr<web::WebState> webState = web::WebState::Create(params);
webStateImpl_.reset(static_cast<web::WebStateImpl*>(webState.release())); webStateImpl_.reset(static_cast<web::WebStateImpl*>(webState.release()));
...@@ -302,7 +298,7 @@ TEST_F(BrowserViewControllerTest, TestSwitchToTab) { ...@@ -302,7 +298,7 @@ TEST_F(BrowserViewControllerTest, TestSwitchToTab) {
TEST_F(BrowserViewControllerTest, TestTabSelected) { TEST_F(BrowserViewControllerTest, TestTabSelected) {
[bvc_ tabSelected:tab_ notifyToolbar:YES]; [bvc_ tabSelected:tab_ notifyToolbar:YES];
EXPECT_EQ([[tab_ view] superview], [bvc_ contentArea]); EXPECT_EQ([tab_.webState->GetView() superview], [bvc_ contentArea]);
EXPECT_TRUE(webStateImpl_->IsVisible()); EXPECT_TRUE(webStateImpl_->IsVisible());
} }
...@@ -313,7 +309,7 @@ TEST_F(BrowserViewControllerTest, TestTabSelectedIsNewTab) { ...@@ -313,7 +309,7 @@ TEST_F(BrowserViewControllerTest, TestTabSelectedIsNewTab) {
id tabMock = (id)tab_; id tabMock = (id)tab_;
[tabMock onSelector:@selector(url) callBlockExpectation:block]; [tabMock onSelector:@selector(url) callBlockExpectation:block];
[bvc_ tabSelected:tab_ notifyToolbar:YES]; [bvc_ tabSelected:tab_ notifyToolbar:YES];
EXPECT_EQ([[tab_ view] superview], [bvc_ contentArea]); EXPECT_EQ([tab_.webState->GetView() superview], [bvc_ contentArea]);
EXPECT_TRUE(webStateImpl_->IsVisible()); EXPECT_TRUE(webStateImpl_->IsVisible());
} }
......
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