Dismiss ephemeral tab scoped toasts on tab change or navigation
Most toasts shown are relevant to the active tab when the toast was
triggered so these toasts should be dismissed when the user switches to
another tab or navigates to another page.
This CL implements logic so that ephemeral tab scoped toasts will
dismiss when the tab changes or navigates to another page.
Persistent toast logic by default are globally scoped since callers
should explicitly call ToastController::CloseToast() when they want the
toast to disappear.
Fixed: 365995637
Change-Id: Ifd4f80458656ef8918144895d30fb2e85006c279
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5861479
Reviewed-by: Alison Gale <[email protected]>
Code-Coverage: [email protected] <[email protected]>
Commit-Queue: Steven Luong <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1356159}
diff --git a/chrome/browser/ui/toasts/api/toast_specification.cc b/chrome/browser/ui/toasts/api/toast_specification.cc
index 5747e60b..73a28dd 100644
--- a/chrome/browser/ui/toasts/api/toast_specification.cc
+++ b/chrome/browser/ui/toasts/api/toast_specification.cc
@@ -44,12 +44,23 @@
return *this;
}
+ToastSpecification::Builder& ToastSpecification::Builder::AddGlobalScoped() {
+ toast_specification_->AddGlobalScope();
+ return *this;
+}
+
ToastSpecification::Builder& ToastSpecification::Builder::AddPersistance() {
toast_specification_->AddPersistance();
return *this;
}
std::unique_ptr<ToastSpecification> ToastSpecification::Builder::Build() {
+ // Persistent toast is global scoped by default since it should only be
+ // dismissed when explicitly told to do so.
+ if (toast_specification_->is_persistent_toast()) {
+ AddGlobalScoped();
+ }
+
ValidateSpecification();
return std::move(toast_specification_);
}
@@ -86,6 +97,10 @@
menu_model_ = std::move(menu_model);
}
+void ToastSpecification::AddGlobalScope() {
+ is_global_scope_ = true;
+}
+
void ToastSpecification::AddPersistance() {
is_persistent_toast_ = true;
}