Commit d2b45c87 authored by Kurt Horimoto's avatar Kurt Horimoto Committed by Commit Bot

[iOS] Use one FullscreenController for both BrowserStates.

Only one browser UI is shown at a time, so a single FullscreenController
is needed for both the normal and incognito BrowserStates.

Bug: none
Cq-Include-Trybots: luci.chromium.try:ios-simulator-full-configs;master.tryserver.chromium.mac:ios-simulator-cronet
Change-Id: Ic08edb4a6c622a8dbeefc4ce02afbb35dbca9f0d
Reviewed-on: https://chromium-review.googlesource.com/1184163
Commit-Queue: Kurt Horimoto <kkhorimoto@chromium.org>
Reviewed-by: default avatarEugene But <eugenebut@chromium.org>
Cr-Commit-Position: refs/heads/master@{#586141}
parent cbd228ca
......@@ -1239,6 +1239,8 @@ applicationCommandEndpoint:(id<ApplicationCommands>)applicationCommandEndpoint {
_browserState);
ChromeBroadcaster* broadcaster = fullscreenController->broadcaster();
if (_broadcasting) {
fullscreenController->SetWebStateList(_model.webStateList);
_toolbarUIUpdater = [[LegacyToolbarUIUpdater alloc]
initWithToolbarUI:[[ToolbarUIState alloc] init]
toolbarOwner:self
......@@ -1253,6 +1255,7 @@ applicationCommandEndpoint:(id<ApplicationCommands>)applicationCommandEndpoint {
webStateList:[_model webStateList]];
StartBroadcastingMainContentUI(self, broadcaster);
_fullscreenUIUpdater = std::make_unique<FullscreenUIUpdater>(self);
fullscreenController->AddObserver(_fullscreenUIUpdater.get());
[self updateForFullscreenProgress:fullscreenController->GetProgress()];
} else {
......@@ -1265,6 +1268,9 @@ applicationCommandEndpoint:(id<ApplicationCommands>)applicationCommandEndpoint {
_webMainContentUIForwarder = nil;
fullscreenController->RemoveObserver(_fullscreenUIUpdater.get());
_fullscreenUIUpdater = nullptr;
fullscreenController->SetWebStateList(nullptr);
}
}
......@@ -1414,13 +1420,6 @@ applicationCommandEndpoint:(id<ApplicationCommands>)applicationCommandEndpoint {
_paymentRequestManager = nil;
[_model browserStateDestroyed];
FullscreenController* fullscreenController =
FullscreenControllerFactory::GetInstance()->GetForBrowserState(
_browserState);
fullscreenController->RemoveObserver(_fullscreenUIUpdater.get());
_fullscreenUIUpdater = nullptr;
fullscreenController->SetWebStateList(nullptr);
TextToSpeechPlaybackControllerFactory::GetInstance()
->GetForBrowserState(_browserState)
->SetWebStateList(nullptr);
......@@ -2109,14 +2108,6 @@ applicationCommandEndpoint:(id<ApplicationCommands>)applicationCommandEndpoint {
// during testing, so explicitly support this).
_bookmarkModel = ios::BookmarkModelFactory::GetForBrowserState(_browserState);
// Add a FullscreenUIUpdater for self.
FullscreenController* controller =
FullscreenControllerFactory::GetInstance()->GetForBrowserState(
_browserState);
_fullscreenUIUpdater = std::make_unique<FullscreenUIUpdater>(self);
// Set the FullscreenController's WebStateList.
controller->SetWebStateList(_model.webStateList);
// Set the TTS playback controller's WebStateList.
TextToSpeechPlaybackControllerFactory::GetInstance()
->GetForBrowserState(_browserState)
......
......@@ -41,5 +41,5 @@ FullscreenControllerFactory::BuildServiceInstanceFor(
web::BrowserState* FullscreenControllerFactory::GetBrowserStateToUse(
web::BrowserState* context) const {
return GetBrowserStateOwnInstanceInIncognito(context);
return GetBrowserStateRedirectedInIncognito(context);
}
......@@ -55,6 +55,8 @@ ChromeBroadcaster* FullscreenControllerImpl::broadcaster() {
}
void FullscreenControllerImpl::SetWebStateList(WebStateList* web_state_list) {
if (web_state_list_ == web_state_list)
return;
if (web_state_list_observer_)
web_state_list_observer_->Disconnect();
web_state_list_ = web_state_list;
......
......@@ -59,6 +59,7 @@ class SadTabTabHelperTest : public PlatformTest {
navigation_manager->SetBrowserState(browser_state_.get());
navigation_manager_ = navigation_manager.get();
web_state_.SetNavigationManager(std::move(navigation_manager));
web_state_.SetBrowserState(browser_state_.get());
}
~SadTabTabHelperTest() override { [application_ stopMocking]; }
......@@ -188,7 +189,10 @@ TEST_F(SadTabTabHelperTest, FailureInterval) {
// N.B. The test fixture web_state_ is not used for this test as a custom
// |repeat_failure_interval| is required.
std::unique_ptr<ios::ChromeBrowserState> browser_state =
TestChromeBrowserState::Builder().Build();
web::TestWebState web_state;
web_state.SetBrowserState(browser_state.get());
SadTabTabHelper::CreateForWebState(&web_state, 0.0f, sad_tab_delegate_);
PagePlaceholderTabHelper::CreateForWebState(&web_state);
web_state.WasShown();
......
......@@ -131,18 +131,18 @@ id<GREYMatcher> PopupBlocker() {
// Tests a link with target="_blank" multiple times.
- (void)testLinkWithBlankTargetMultipleTimes {
const char ID[] = "webScenarioWindowOpenRegularLinkMultipleTimes";
[[EarlGrey selectElementWithMatcher:WebViewInWebState(GetCurrentWebState())]
performAction:web::WebViewTapElement(
GetCurrentWebState(),
ElementSelector::ElementSelectorId(ID))];
web::WebState* test_page_web_state = GetCurrentWebState();
id<GREYMatcher> test_page_matcher = WebViewInWebState(test_page_web_state);
id<GREYAction> link_tap = web::WebViewTapElement(
test_page_web_state, ElementSelector::ElementSelectorId(ID));
[[EarlGrey selectElementWithMatcher:test_page_matcher]
performAction:link_tap];
[ChromeEarlGrey waitForMainTabCount:2];
chrome_test_util::OpenNewTab();
[ChromeEarlGrey waitForMainTabCount:3];
chrome_test_util::SelectTabAtIndexInCurrentMode(0);
[[EarlGrey selectElementWithMatcher:WebViewInWebState(GetCurrentWebState())]
performAction:web::WebViewTapElement(
GetCurrentWebState(),
ElementSelector::ElementSelectorId(ID))];
[[EarlGrey selectElementWithMatcher:test_page_matcher]
performAction:link_tap];
[ChromeEarlGrey waitForMainTabCount:4];
}
......
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