Commit bf1d1c9f authored by Finnur Thorarinsson's avatar Finnur Thorarinsson Committed by Commit Bot

Win Native Notifications: Experiment with shorter timeouts for requireInteraction.

Bug: 1005572
Change-Id: Ic9979148323f55835e00fa85066d2b996ad81943
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1821899
Commit-Queue: Finnur Thorarinsson <finnur@chromium.org>
Reviewed-by: default avatarPeter Beverloo <peter@chromium.org>
Cr-Commit-Position: refs/heads/master@{#699850}
parent 80790bc6
......@@ -19,6 +19,7 @@
#include "base/time/time.h"
#include "chrome/browser/notifications/win/notification_image_retainer.h"
#include "chrome/browser/notifications/win/notification_launch_id.h"
#include "chrome/common/chrome_features.h"
#include "chrome/grit/chromium_strings.h"
#include "chrome/grit/generated_resources.h"
#include "components/url_formatter/elide_url.h"
......@@ -48,6 +49,8 @@ const char kBindingElement[] = "binding";
const char kBindingElementTemplateAttribute[] = "template";
const char kContent[] = "content";
const char kContextMenu[] = "contextMenu";
const char kDuration[] = "duration";
const char kDurationLong[] = "long";
const char kForeground[] = "foreground";
const char kHero[] = "hero";
const char kHintCrop[] = "hint-crop";
......@@ -98,10 +101,16 @@ void StartToastElement(XmlWriter* xml_writer,
xml_writer->StartElement(kNotificationToastElement);
xml_writer->AddAttribute(kNotificationLaunchAttribute, launch_id.Serialize());
// Note: If the notification doesn't include a button, then Windows will
// ignore the Reminder flag.
if (notification.never_timeout())
xml_writer->AddAttribute(kScenario, kReminder);
if (notification.never_timeout()) {
if (base::FeatureList::IsEnabled(
features::kNotificationDurationLongForRequireInteraction)) {
xml_writer->AddAttribute(kDuration, kDurationLong);
} else {
// Note: If the notification doesn't include a button, then Windows will
// ignore the Reminder flag. See EnsureReminderHasButton below.
xml_writer->AddAttribute(kScenario, kReminder);
}
}
if (notification.timestamp().is_null())
return;
......@@ -315,8 +324,11 @@ void AddContextMenu(XmlWriter* xml_writer,
void EnsureReminderHasButton(XmlWriter* xml_writer,
const message_center::Notification& notification,
NotificationLaunchId copied_launch_id) {
if (!notification.never_timeout() || !notification.buttons().empty())
if (!notification.never_timeout() || !notification.buttons().empty() ||
base::FeatureList::IsEnabled(
features::kNotificationDurationLongForRequireInteraction)) {
return;
}
xml_writer->StartElement(kActionElement);
xml_writer->AddAttribute(kActivationType, kBackground);
......
......@@ -13,9 +13,11 @@
#include "base/strings/string_number_conversions.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/task_environment.h"
#include "chrome/browser/notifications/win/fake_notification_image_retainer.h"
#include "chrome/browser/notifications/win/notification_launch_id.h"
#include "chrome/common/chrome_features.h"
#include "chrome/grit/chromium_strings.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/base/l10n/l10n_util.h"
......@@ -286,6 +288,32 @@ TEST_F(NotificationTemplateBuilderTest, RequireInteraction) {
ASSERT_NO_FATAL_FAILURE(VerifyXml(notification, kExpectedXml));
}
TEST_F(NotificationTemplateBuilderTest, RequireInteractionSuppressed) {
base::test::ScopedFeatureList scoped_feature_list;
scoped_feature_list.InitAndEnableFeature(
features::kNotificationDurationLongForRequireInteraction);
message_center::Notification notification = BuildNotification();
notification.set_never_timeout(true);
const wchar_t kExpectedXml[] =
LR"(<toast launch="0|0|Default|0|https://example.com/|notification_id" duration="long" displayTimestamp="1998-09-04T01:02:03Z">
<visual>
<binding template="ToastGeneric">
<text>My Title</text>
<text>My Message</text>
<text placement="attribution">example.com</text>
</binding>
</visual>
<actions>
<action content="settings" placement="contextMenu" activationType="foreground" arguments="2|0|Default|0|https://example.com/|notification_id"/>
</actions>
</toast>
)";
ASSERT_NO_FATAL_FAILURE(VerifyXml(notification, kExpectedXml));
}
TEST_F(NotificationTemplateBuilderTest, NullTimestamp) {
message_center::Notification notification = BuildNotification();
notification.set_timestamp(base::Time());
......
......@@ -518,6 +518,14 @@ const base::Feature kNewNetErrorPageUI{"NewNetErrorPageUI",
const base::Feature kNoReferrers{"NoReferrers",
base::FEATURE_DISABLED_BY_DEFAULT};
#if defined(OS_WIN)
// Changes behavior of requireInteraction for notifications. Instead of staying
// on-screen until dismissed, they are instead shown for a very long time.
const base::Feature kNotificationDurationLongForRequireInteraction{
"NotificationDurationLongForRequireInteraction",
base::FEATURE_DISABLED_BY_DEFAULT};
#endif // OS_WIN
#if defined(OS_POSIX)
// Enables NTLMv2, which implicitly disables NTLMv1.
const base::Feature kNtlmV2Enabled{"NtlmV2Enabled",
......
......@@ -333,6 +333,11 @@ COMPONENT_EXPORT(CHROME_FEATURES) extern const base::Feature kNewNetErrorPageUI;
COMPONENT_EXPORT(CHROME_FEATURES) extern const base::Feature kNoReferrers;
#if defined(OS_WIN)
COMPONENT_EXPORT(CHROME_FEATURES)
extern const base::Feature kNotificationDurationLongForRequireInteraction;
#endif
#if defined(OS_POSIX)
COMPONENT_EXPORT(CHROME_FEATURES) extern const base::Feature kNtlmV2Enabled;
#endif
......
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