Commit 511e7cfe authored by Andy Paicu's avatar Andy Paicu Committed by Commit Bot

Treat heads-up notification requests as ignored on tab switching

Bug: 1014085
Change-Id: Ibc831829014e235b964c62417d9b7c8d8467b7fe
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1860030
Commit-Queue: Andy Paicu <andypaicu@chromium.org>
Reviewed-by: default avatarEmily Stark <estark@chromium.org>
Reviewed-by: default avatarBalazs Engedy <engedy@chromium.org>
Cr-Commit-Position: refs/heads/master@{#706376}
parent 3ba68b08
...@@ -57,10 +57,11 @@ gfx::NativeWindow PermissionPromptAndroid::GetNativeWindow() { ...@@ -57,10 +57,11 @@ gfx::NativeWindow PermissionPromptAndroid::GetNativeWindow() {
return nullptr; return nullptr;
} }
bool PermissionPromptAndroid::ShouldDestroyOnTabSwitching() { PermissionPrompt::TabSwitchingBehavior
PermissionPromptAndroid::GetTabSwitchingBehavior() {
if (permission_request_notification_) if (permission_request_notification_)
return true; return permission_request_notification_->GetTabSwitchingBehavior();
return false; return TabSwitchingBehavior::kKeepPromptAlive;
} }
void PermissionPromptAndroid::Closing() { void PermissionPromptAndroid::Closing() {
......
...@@ -28,7 +28,7 @@ class PermissionPromptAndroid : public PermissionPrompt { ...@@ -28,7 +28,7 @@ class PermissionPromptAndroid : public PermissionPrompt {
// PermissionPrompt: // PermissionPrompt:
void UpdateAnchorPosition() override; void UpdateAnchorPosition() override;
gfx::NativeWindow GetNativeWindow() override; gfx::NativeWindow GetNativeWindow() override;
bool ShouldDestroyOnTabSwitching() override; TabSwitchingBehavior GetTabSwitchingBehavior() override;
void Closing(); void Closing();
void Accept(); void Accept();
......
...@@ -239,8 +239,21 @@ void PermissionRequestManager::OnVisibilityChanged( ...@@ -239,8 +239,21 @@ void PermissionRequestManager::OnVisibilityChanged(
return; return;
if (tab_is_hidden_) { if (tab_is_hidden_) {
if (view_ && view_->ShouldDestroyOnTabSwitching()) if (view_) {
switch (view_->GetTabSwitchingBehavior()) {
case PermissionPrompt::TabSwitchingBehavior::
kDestroyPromptButKeepRequestPending:
DeleteBubble(); DeleteBubble();
break;
case PermissionPrompt::TabSwitchingBehavior::
kDestroyPromptAndIgnoreRequest:
FinalizeBubble(PermissionAction::IGNORED);
break;
case PermissionPrompt::TabSwitchingBehavior::kKeepPromptAlive:
break;
}
}
return; return;
} }
...@@ -254,7 +267,8 @@ void PermissionRequestManager::OnVisibilityChanged( ...@@ -254,7 +267,8 @@ void PermissionRequestManager::OnVisibilityChanged(
if (view_) { if (view_) {
// We switched tabs away and back while a prompt was active. // We switched tabs away and back while a prompt was active.
DCHECK(!view_->ShouldDestroyOnTabSwitching()); DCHECK_EQ(view_->GetTabSwitchingBehavior(),
PermissionPrompt::TabSwitchingBehavior::kKeepPromptAlive);
} else { } else {
ShowBubble(/*is_reshow=*/true); ShowBubble(/*is_reshow=*/true);
} }
......
...@@ -71,6 +71,23 @@ std::string PermissionRequestNotificationAndroid::NotificationIdForOrigin( ...@@ -71,6 +71,23 @@ std::string PermissionRequestNotificationAndroid::NotificationIdForOrigin(
return kNotificationIdPrefix + origin; return kNotificationIdPrefix + origin;
} }
// static
PermissionPrompt::TabSwitchingBehavior
PermissionRequestNotificationAndroid::GetTabSwitchingBehavior() {
if (QuietNotificationsPromptConfig::UIFlavorToUse() ==
QuietNotificationsPromptConfig::UIFlavor::QUIET_NOTIFICATION) {
return PermissionPrompt::TabSwitchingBehavior::
kDestroyPromptButKeepRequestPending;
} else {
// For heads-up notifications finalize the request as "ignored" on tab
// switching.
DCHECK_EQ(QuietNotificationsPromptConfig::UIFlavor::HEADS_UP_NOTIFICATION,
QuietNotificationsPromptConfig::UIFlavorToUse());
return PermissionPrompt::TabSwitchingBehavior::
kDestroyPromptAndIgnoreRequest;
}
}
void PermissionRequestNotificationAndroid::Close() { void PermissionRequestNotificationAndroid::Close() {
delegate_->Closing(); delegate_->Closing();
} }
......
...@@ -40,6 +40,9 @@ class PermissionRequestNotificationAndroid final ...@@ -40,6 +40,9 @@ class PermissionRequestNotificationAndroid final
// Converts an origin string into a notification id. // Converts an origin string into a notification id.
static std::string NotificationIdForOrigin(const std::string& origin); static std::string NotificationIdForOrigin(const std::string& origin);
// The behavior that this notification should have after tab switching.
static PermissionPrompt::TabSwitchingBehavior GetTabSwitchingBehavior();
private: private:
// PermissionRequestNotificationHandler::Delegate // PermissionRequestNotificationHandler::Delegate
void Close() override; void Close() override;
......
...@@ -27,11 +27,12 @@ gfx::NativeWindow MockPermissionPrompt::GetNativeWindow() { ...@@ -27,11 +27,12 @@ gfx::NativeWindow MockPermissionPrompt::GetNativeWindow() {
return nullptr; return nullptr;
} }
bool MockPermissionPrompt::ShouldDestroyOnTabSwitching() { PermissionPrompt::TabSwitchingBehavior
MockPermissionPrompt::GetTabSwitchingBehavior() {
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
return false; return TabSwitchingBehavior::kKeepPromptAlive;
#else #else
return true; return TabSwitchingBehavior::kDestroyPromptButKeepRequestPending;
#endif #endif
} }
......
...@@ -20,7 +20,7 @@ class MockPermissionPrompt : public PermissionPrompt { ...@@ -20,7 +20,7 @@ class MockPermissionPrompt : public PermissionPrompt {
// PermissionPrompt: // PermissionPrompt:
void UpdateAnchorPosition() override; void UpdateAnchorPosition() override;
gfx::NativeWindow GetNativeWindow() override; gfx::NativeWindow GetNativeWindow() override;
bool ShouldDestroyOnTabSwitching() override; TabSwitchingBehavior GetTabSwitchingBehavior() override;
bool IsVisible(); bool IsVisible();
......
...@@ -31,6 +31,20 @@ class PermissionPrompt { ...@@ -31,6 +31,20 @@ class PermissionPrompt {
bool is_origin; bool is_origin;
}; };
// Permission prompt behavior on tab switching.
enum TabSwitchingBehavior {
// The prompt should be kept as-is on tab switching (usually because it's
// part of the containing tab so it will be hidden automatically when
// switching from said tab)
kKeepPromptAlive,
// Destroy the prompt but keep the permission request pending. When the user
// revisits the tab, the permission prompt is re-displayed.
kDestroyPromptButKeepRequestPending,
// Destroy the prompt and treat the permission request as being resolved
// with the PermissionAction::IGNORED result.
kDestroyPromptAndIgnoreRequest,
};
// The delegate will receive events caused by user action which need to // The delegate will receive events caused by user action which need to
// be persisted in the per-tab UI state. // be persisted in the per-tab UI state.
class Delegate { class Delegate {
...@@ -67,8 +81,9 @@ class PermissionPrompt { ...@@ -67,8 +81,9 @@ class PermissionPrompt {
// TODO(hcarmona): Remove this as part of the bubble API work. // TODO(hcarmona): Remove this as part of the bubble API work.
virtual gfx::NativeWindow GetNativeWindow() = 0; virtual gfx::NativeWindow GetNativeWindow() = 0;
// Whether the prompt should be destroyed on tab switching // Get the behavior of this prompt when the user switches away from the
virtual bool ShouldDestroyOnTabSwitching() = 0; // associated tab.
virtual TabSwitchingBehavior GetTabSwitchingBehavior() = 0;
}; };
#endif // CHROME_BROWSER_UI_PERMISSION_BUBBLE_PERMISSION_PROMPT_H_ #endif // CHROME_BROWSER_UI_PERMISSION_BUBBLE_PERMISSION_PROMPT_H_
...@@ -260,8 +260,10 @@ gfx::NativeWindow PermissionPromptImpl::GetNativeWindow() { ...@@ -260,8 +260,10 @@ gfx::NativeWindow PermissionPromptImpl::GetNativeWindow() {
return nullptr; return nullptr;
} }
bool PermissionPromptImpl::ShouldDestroyOnTabSwitching() { PermissionPrompt::TabSwitchingBehavior
return true; PermissionPromptImpl::GetTabSwitchingBehavior() {
return PermissionPrompt::TabSwitchingBehavior::
kDestroyPromptButKeepRequestPending;
} }
void PermissionPromptImpl::Closing() { void PermissionPromptImpl::Closing() {
......
...@@ -24,7 +24,7 @@ class PermissionPromptImpl : public PermissionPrompt { ...@@ -24,7 +24,7 @@ class PermissionPromptImpl : public PermissionPrompt {
// PermissionPrompt: // PermissionPrompt:
void UpdateAnchorPosition() override; void UpdateAnchorPosition() override;
gfx::NativeWindow GetNativeWindow() override; gfx::NativeWindow GetNativeWindow() override;
bool ShouldDestroyOnTabSwitching() override; TabSwitchingBehavior GetTabSwitchingBehavior() override;
void Closing(); void Closing();
void Accept(); void Accept();
......
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