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() {
return nullptr;
}
bool PermissionPromptAndroid::ShouldDestroyOnTabSwitching() {
PermissionPrompt::TabSwitchingBehavior
PermissionPromptAndroid::GetTabSwitchingBehavior() {
if (permission_request_notification_)
return true;
return false;
return permission_request_notification_->GetTabSwitchingBehavior();
return TabSwitchingBehavior::kKeepPromptAlive;
}
void PermissionPromptAndroid::Closing() {
......
......@@ -28,7 +28,7 @@ class PermissionPromptAndroid : public PermissionPrompt {
// PermissionPrompt:
void UpdateAnchorPosition() override;
gfx::NativeWindow GetNativeWindow() override;
bool ShouldDestroyOnTabSwitching() override;
TabSwitchingBehavior GetTabSwitchingBehavior() override;
void Closing();
void Accept();
......
......@@ -239,8 +239,21 @@ void PermissionRequestManager::OnVisibilityChanged(
return;
if (tab_is_hidden_) {
if (view_ && view_->ShouldDestroyOnTabSwitching())
DeleteBubble();
if (view_) {
switch (view_->GetTabSwitchingBehavior()) {
case PermissionPrompt::TabSwitchingBehavior::
kDestroyPromptButKeepRequestPending:
DeleteBubble();
break;
case PermissionPrompt::TabSwitchingBehavior::
kDestroyPromptAndIgnoreRequest:
FinalizeBubble(PermissionAction::IGNORED);
break;
case PermissionPrompt::TabSwitchingBehavior::kKeepPromptAlive:
break;
}
}
return;
}
......@@ -254,7 +267,8 @@ void PermissionRequestManager::OnVisibilityChanged(
if (view_) {
// We switched tabs away and back while a prompt was active.
DCHECK(!view_->ShouldDestroyOnTabSwitching());
DCHECK_EQ(view_->GetTabSwitchingBehavior(),
PermissionPrompt::TabSwitchingBehavior::kKeepPromptAlive);
} else {
ShowBubble(/*is_reshow=*/true);
}
......
......@@ -71,6 +71,23 @@ std::string PermissionRequestNotificationAndroid::NotificationIdForOrigin(
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() {
delegate_->Closing();
}
......
......@@ -40,6 +40,9 @@ class PermissionRequestNotificationAndroid final
// Converts an origin string into a notification id.
static std::string NotificationIdForOrigin(const std::string& origin);
// The behavior that this notification should have after tab switching.
static PermissionPrompt::TabSwitchingBehavior GetTabSwitchingBehavior();
private:
// PermissionRequestNotificationHandler::Delegate
void Close() override;
......
......@@ -27,11 +27,12 @@ gfx::NativeWindow MockPermissionPrompt::GetNativeWindow() {
return nullptr;
}
bool MockPermissionPrompt::ShouldDestroyOnTabSwitching() {
PermissionPrompt::TabSwitchingBehavior
MockPermissionPrompt::GetTabSwitchingBehavior() {
#if defined(OS_ANDROID)
return false;
return TabSwitchingBehavior::kKeepPromptAlive;
#else
return true;
return TabSwitchingBehavior::kDestroyPromptButKeepRequestPending;
#endif
}
......
......@@ -20,7 +20,7 @@ class MockPermissionPrompt : public PermissionPrompt {
// PermissionPrompt:
void UpdateAnchorPosition() override;
gfx::NativeWindow GetNativeWindow() override;
bool ShouldDestroyOnTabSwitching() override;
TabSwitchingBehavior GetTabSwitchingBehavior() override;
bool IsVisible();
......
......@@ -31,6 +31,20 @@ class PermissionPrompt {
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
// be persisted in the per-tab UI state.
class Delegate {
......@@ -67,8 +81,9 @@ class PermissionPrompt {
// TODO(hcarmona): Remove this as part of the bubble API work.
virtual gfx::NativeWindow GetNativeWindow() = 0;
// Whether the prompt should be destroyed on tab switching
virtual bool ShouldDestroyOnTabSwitching() = 0;
// Get the behavior of this prompt when the user switches away from the
// associated tab.
virtual TabSwitchingBehavior GetTabSwitchingBehavior() = 0;
};
#endif // CHROME_BROWSER_UI_PERMISSION_BUBBLE_PERMISSION_PROMPT_H_
......@@ -260,8 +260,10 @@ gfx::NativeWindow PermissionPromptImpl::GetNativeWindow() {
return nullptr;
}
bool PermissionPromptImpl::ShouldDestroyOnTabSwitching() {
return true;
PermissionPrompt::TabSwitchingBehavior
PermissionPromptImpl::GetTabSwitchingBehavior() {
return PermissionPrompt::TabSwitchingBehavior::
kDestroyPromptButKeepRequestPending;
}
void PermissionPromptImpl::Closing() {
......
......@@ -24,7 +24,7 @@ class PermissionPromptImpl : public PermissionPrompt {
// PermissionPrompt:
void UpdateAnchorPosition() override;
gfx::NativeWindow GetNativeWindow() override;
bool ShouldDestroyOnTabSwitching() override;
TabSwitchingBehavior GetTabSwitchingBehavior() override;
void Closing();
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