Commit fb03cc27 authored by Nohemi Fernandez's avatar Nohemi Fernandez Committed by Commit Bot

[iOS] Trigger the sign-in notification infobar after the web page loads.

Existing logic currently dismisses all infobars that are presented
before the page is loaded for a navigation request. This means that in
some cases the sign-in infobar may be removed before it is presented to
the user.

Move the logic to display the sign-in infobar after the page is loaded.

Bug: 1145592
Change-Id: I2404009417aa66e8b1c9836571ef88f9eb5e6f4b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2527147Reviewed-by: default avatarEugene But <eugenebut@chromium.org>
Commit-Queue: Nohemi Fernandez <fernandex@chromium.org>
Cr-Commit-Position: refs/heads/master@{#825976}
parent 7f2e74c2
...@@ -113,10 +113,15 @@ class AccountConsistencyHandler : public web::WebStatePolicyDecider, ...@@ -113,10 +113,15 @@ class AccountConsistencyHandler : public web::WebStatePolicyDecider,
base::OnceCallback<void(PolicyDecision)> callback) override; base::OnceCallback<void(PolicyDecision)> callback) override;
void WebStateDestroyed() override; void WebStateDestroyed() override;
// Marks that GAIA cookies have been restored.
void MarkGaiaCookiesRestored();
bool show_consistency_promo_ = false; bool show_consistency_promo_ = false;
bool gaia_cookies_restored_ = false;
AccountConsistencyService* account_consistency_service_; // Weak. AccountConsistencyService* account_consistency_service_; // Weak.
AccountReconcilor* account_reconcilor_; // Weak. AccountReconcilor* account_reconcilor_; // Weak.
__weak id<ManageAccountsDelegate> delegate_; __weak id<ManageAccountsDelegate> delegate_;
base::WeakPtrFactory<AccountConsistencyHandler> weak_ptr_factory_;
}; };
} // namespace } // namespace
...@@ -128,7 +133,8 @@ AccountConsistencyHandler::AccountConsistencyHandler( ...@@ -128,7 +133,8 @@ AccountConsistencyHandler::AccountConsistencyHandler(
: web::WebStatePolicyDecider(web_state), : web::WebStatePolicyDecider(web_state),
account_consistency_service_(service), account_consistency_service_(service),
account_reconcilor_(account_reconcilor), account_reconcilor_(account_reconcilor),
delegate_(delegate) { delegate_(delegate),
weak_ptr_factory_(this) {
web_state->AddObserver(this); web_state->AddObserver(this);
} }
...@@ -159,11 +165,13 @@ void AccountConsistencyHandler::ShouldAllowResponse( ...@@ -159,11 +165,13 @@ void AccountConsistencyHandler::ShouldAllowResponse(
if (google_util::IsGoogleDomainUrl( if (google_util::IsGoogleDomainUrl(
url, google_util::ALLOW_SUBDOMAIN, url, google_util::ALLOW_SUBDOMAIN,
google_util::DISALLOW_NON_STANDARD_PORTS)) { google_util::DISALLOW_NON_STANDARD_PORTS)) {
account_consistency_service_->SetGaiaCookiesIfDeleted(base::BindOnce( // Reset boolean that tracks displaying the sign-in notification infobar.
[](id<ManageAccountsDelegate> delegate) { // This ensures that only the most recent navigation will trigger an
[delegate onRestoreGaiaCookies]; // infobar.
}, gaia_cookies_restored_ = false;
delegate_)); account_consistency_service_->SetGaiaCookiesIfDeleted(
base::BindOnce(&AccountConsistencyHandler::MarkGaiaCookiesRestored,
weak_ptr_factory_.GetWeakPtr()));
} }
if (!gaia::IsGaiaSignonRealm(url.GetOrigin())) { if (!gaia::IsGaiaSignonRealm(url.GetOrigin())) {
...@@ -227,22 +235,40 @@ void AccountConsistencyHandler::ShouldAllowResponse( ...@@ -227,22 +235,40 @@ void AccountConsistencyHandler::ShouldAllowResponse(
std::move(callback).Run(PolicyDecision::Cancel()); std::move(callback).Run(PolicyDecision::Cancel());
} }
void AccountConsistencyHandler::MarkGaiaCookiesRestored() {
gaia_cookies_restored_ = true;
}
void AccountConsistencyHandler::PageLoaded( void AccountConsistencyHandler::PageLoaded(
web::WebState* web_state, web::WebState* web_state,
web::PageLoadCompletionStatus load_completion_status) { web::PageLoadCompletionStatus load_completion_status) {
if (!show_consistency_promo_ || const GURL& url = web_state->GetLastCommittedURL();
!gaia::IsGaiaSignonRealm(web_state->GetLastCommittedURL().GetOrigin()) || if (load_completion_status == web::PageLoadCompletionStatus::FAILURE ||
load_completion_status == web::PageLoadCompletionStatus::FAILURE) { !google_util::IsGoogleDomainUrl(
url, google_util::ALLOW_SUBDOMAIN,
google_util::DISALLOW_NON_STANDARD_PORTS)) {
return; return;
} }
[delegate_ onShowConsistencyPromo];
show_consistency_promo_ = false;
// Chrome uses the CHROME_CONNECTED cookie to determine whether the // Displays the sign-in notification infobar if GAIA cookies have been
// eligibility promo should be shown. Once it is shown we should remove the // restored. This occurs once the URL has been loaded to avoid a race
// cookie, since it should otherwise not be used unless the user is signed in. // condition in which the infobar is dismissed prior to the page load.
account_consistency_service_->RemoveAllChromeConnectedCookies( if (gaia_cookies_restored_) {
base::OnceClosure()); [delegate_ onRestoreGaiaCookies];
gaia_cookies_restored_ = false;
}
if (show_consistency_promo_ && gaia::IsGaiaSignonRealm(url.GetOrigin())) {
[delegate_ onShowConsistencyPromo];
show_consistency_promo_ = false;
// Chrome uses the CHROME_CONNECTED cookie to determine whether the
// eligibility promo should be shown. Once it is shown we should remove the
// cookie, since it should otherwise not be used unless the user is signed
// in.
account_consistency_service_->RemoveAllChromeConnectedCookies(
base::OnceClosure());
}
} }
void AccountConsistencyHandler::WebStateDestroyed(web::WebState* web_state) {} void AccountConsistencyHandler::WebStateDestroyed(web::WebState* web_state) {}
......
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