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;
// TODO(crbug.com/228575): Create a delegate interface and remove this.
- (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
// is not supported with this tab. It can be different from |Tab view|.
- (UIView*)viewForPrinting;
......
......@@ -267,22 +267,6 @@ NSString* const kTabUrlKey = @"url";
_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 {
return self.webController.viewForPrinting;
}
......@@ -420,8 +404,7 @@ NSString* const kTabUrlKey = @"url";
_openInController = [[OpenInController alloc]
initWithURLLoaderFactory:_browserState->GetSharedURLLoaderFactory()
webController:self.webController];
// If the tab was evicted before, It should have been loaded already before
// starting the open-in controller.
// Previously evicted tabs should be reloaded before this method is called.
DCHECK(!self.webState->IsEvicted());
self.webState->GetNavigationManager()->LoadIfNecessary();
_openInController.baseView = self.webState->GetView();
......
......@@ -2564,7 +2564,8 @@ applicationCommandEndpoint:(id<ApplicationCommands>)applicationCommandEndpoint {
_browserContainerCoordinator.viewController.contentViewController =
viewController;
} else {
_browserContainerCoordinator.viewController.contentView = tab.view;
_browserContainerCoordinator.viewController.contentView =
[self viewForTab:tab];
}
}
[self updateToolbar];
......@@ -2713,14 +2714,22 @@ applicationCommandEndpoint:(id<ApplicationCommands>)applicationCommandEndpoint {
- (UIView*)viewForTab:(Tab*)tab {
DCHECK(tab);
if (tab.webState) {
NewTabPageTabHelper* NTPHelper =
NewTabPageTabHelper::FromWebState(tab.webState);
if (NTPHelper && NTPHelper->IsActive()) {
return _ntpCoordinatorsForWebStates[tab.webState].viewController.view;
}
if (!tab.webState)
return nil;
web::WebState* webState = tab.webState;
NewTabPageTabHelper* NTPHelper = NewTabPageTabHelper::FromWebState(webState);
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
......
......@@ -194,10 +194,6 @@ class BrowserViewControllerTest : public BlockCleanupTest {
[[tabModel stub] setCurrentTab:[OCMArg any]];
[[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());
std::unique_ptr<web::WebState> webState = web::WebState::Create(params);
webStateImpl_.reset(static_cast<web::WebStateImpl*>(webState.release()));
......@@ -302,7 +298,7 @@ TEST_F(BrowserViewControllerTest, TestSwitchToTab) {
TEST_F(BrowserViewControllerTest, TestTabSelected) {
[bvc_ tabSelected:tab_ notifyToolbar:YES];
EXPECT_EQ([[tab_ view] superview], [bvc_ contentArea]);
EXPECT_EQ([tab_.webState->GetView() superview], [bvc_ contentArea]);
EXPECT_TRUE(webStateImpl_->IsVisible());
}
......@@ -313,7 +309,7 @@ TEST_F(BrowserViewControllerTest, TestTabSelectedIsNewTab) {
id tabMock = (id)tab_;
[tabMock onSelector:@selector(url) callBlockExpectation:block];
[bvc_ tabSelected:tab_ notifyToolbar:YES];
EXPECT_EQ([[tab_ view] superview], [bvc_ contentArea]);
EXPECT_EQ([tab_.webState->GetView() superview], [bvc_ contentArea]);
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