diff options
Diffstat (limited to 'chromium/ui/message_center')
14 files changed, 71 insertions, 36 deletions
diff --git a/chromium/ui/message_center/BUILD.gn b/chromium/ui/message_center/BUILD.gn index eb0016c49bf..ce4ea2bf80b 100644 --- a/chromium/ui/message_center/BUILD.gn +++ b/chromium/ui/message_center/BUILD.gn @@ -129,6 +129,9 @@ jumbo_component("message_center") { "//ui/events", "//ui/views", ] + if (is_mac) { + libs = [ "Foundation.framework" ] + } } } else { # Notification service disabled. diff --git a/chromium/ui/message_center/OWNERS b/chromium/ui/message_center/OWNERS index 0bd96e9e557..c03aa04db85 100644 --- a/chromium/ui/message_center/OWNERS +++ b/chromium/ui/message_center/OWNERS @@ -6,3 +6,4 @@ yoshiki@chromium.org tengs@chromium.org # COMPONENT: UI>Notifications +# TEAM: platform-capabilities@chromium.org diff --git a/chromium/ui/message_center/message_center_impl.cc b/chromium/ui/message_center/message_center_impl.cc index ae9c59615b1..6d71ab26ad9 100644 --- a/chromium/ui/message_center/message_center_impl.cc +++ b/chromium/ui/message_center/message_center_impl.cc @@ -37,7 +37,7 @@ MessageCenterImpl::MessageCenterImpl( lock_screen_controller_(std::move(lock_screen_controller)), popup_timers_controller_(std::make_unique<PopupTimersController>(this)), stats_collector_(this) { - notification_list_.reset(new NotificationList(this)); + notification_list_ = std::make_unique<NotificationList>(this); } MessageCenterImpl::~MessageCenterImpl() { @@ -186,15 +186,16 @@ void MessageCenterImpl::AddNotification( // |notification_list| will replace the notification instead of adding new. // This is essentially an update rather than addition. bool already_exists = (notification_list_->GetNotificationById(id) != NULL); + if (already_exists) { + UpdateNotification(id, std::move(notification)); + return; + } + notification_list_->AddNotification(std::move(notification)); visible_notifications_ = notification_list_->GetVisibleNotifications(blockers_); - for (auto& observer : observer_list_) { - if (already_exists) - observer.OnNotificationUpdated(id); - else - observer.OnNotificationAdded(id); + observer.OnNotificationAdded(id); } } @@ -458,7 +459,7 @@ void MessageCenterImpl::EnterQuietModeWithExpire( for (auto& observer : observer_list_) observer.OnQuietModeChanged(true); - quiet_mode_timer_.reset(new base::OneShotTimer); + quiet_mode_timer_ = std::make_unique<base::OneShotTimer>(); quiet_mode_timer_->Start( FROM_HERE, expires_in, diff --git a/chromium/ui/message_center/message_center_impl_unittest.cc b/chromium/ui/message_center/message_center_impl_unittest.cc index 6b05dc598bb..f9bfc75a2f7 100644 --- a/chromium/ui/message_center/message_center_impl_unittest.cc +++ b/chromium/ui/message_center/message_center_impl_unittest.cc @@ -148,8 +148,8 @@ class MessageCenterImplTest : public testing::Test { void SetUp() override { MessageCenter::Initialize(std::make_unique<FakeLockScreenController>()); message_center_ = MessageCenter::Get(); - loop_.reset(new base::MessageLoop); - run_loop_.reset(new base::RunLoop()); + loop_ = std::make_unique<base::MessageLoop>(); + run_loop_ = std::make_unique<base::RunLoop>(); closure_ = run_loop_->QuitClosure(); } @@ -457,6 +457,35 @@ TEST_F(MessageCenterImplTest, PopupTimersControllerRestartOnUpdate) { base::MessageLoopCurrent::Get()->SetTaskRunner(old_task_runner); } +TEST_F(MessageCenterImplTest, Renotify) { + message_center()->SetHasMessageCenterView(true); + const std::string id("id"); + + // Add notification initially. + std::unique_ptr<Notification> notification = CreateSimpleNotification(id); + message_center()->AddNotification(std::move(notification)); + auto popups = message_center()->GetPopupNotifications(); + EXPECT_EQ(1u, popups.size()); + EXPECT_TRUE(PopupNotificationsContain(popups, id)); + + // Mark notification as shown. + message_center()->MarkSinglePopupAsShown(id, true); + EXPECT_EQ(0u, message_center()->GetPopupNotifications().size()); + + // Add notification again without |renotify| flag. It should not pop-up again. + notification = CreateSimpleNotification(id); + message_center()->AddNotification(std::move(notification)); + EXPECT_EQ(0u, message_center()->GetPopupNotifications().size()); + + // Add notification again with |renotify| flag. It should pop-up again. + notification = CreateSimpleNotification(id); + notification->set_renotify(true); + message_center()->AddNotification(std::move(notification)); + popups = message_center()->GetPopupNotifications(); + EXPECT_EQ(1u, popups.size()); + EXPECT_TRUE(PopupNotificationsContain(popups, id)); +} + TEST_F(MessageCenterImplTest, NotificationBlocker) { NotifierId notifier_id(NotifierType::APPLICATION, "app1"); // Multiple blockers to verify the case that one blocker blocks but another diff --git a/chromium/ui/message_center/popup_timers_controller.cc b/chromium/ui/message_center/popup_timers_controller.cc index 88ab8edb742..0c3668cc97d 100644 --- a/chromium/ui/message_center/popup_timers_controller.cc +++ b/chromium/ui/message_center/popup_timers_controller.cc @@ -54,7 +54,7 @@ void PopupTimersController::StartTimer(const std::string& id, std::unique_ptr<PopupTimer> timer(new PopupTimer(id, timeout, AsWeakPtr())); timer->Start(); - popup_timers_.insert(std::make_pair(id, std::move(timer))); + popup_timers_.emplace(id, std::move(timer)); } void PopupTimersController::StartAll() { diff --git a/chromium/ui/message_center/public/cpp/notification.h b/chromium/ui/message_center/public/cpp/notification.h index 0448014b8ee..63e0c0f9549 100644 --- a/chromium/ui/message_center/public/cpp/notification.h +++ b/chromium/ui/message_center/public/cpp/notification.h @@ -40,9 +40,10 @@ struct MESSAGE_CENTER_PUBLIC_EXPORT NotificationItem { }; enum class SettingsButtonHandler { - NONE = 0, // No button. This is the default. - INLINE = 1, // Button shown, settings inline. - DELEGATE = 2 // Button shown, notification's delegate handles action. + NONE = 0, // No button. This is the default. Does not affect native + // settings button (like on Android). + INLINE = 1, // Button shown, settings inline. + DELEGATE = 2, // Button shown, notification's delegate handles action. }; enum class SystemNotificationWarningLevel { NORMAL, WARNING, CRITICAL_WARNING }; diff --git a/chromium/ui/message_center/views/message_popup_collection.cc b/chromium/ui/message_center/views/message_popup_collection.cc index 67b55fd8a38..7f13f873595 100644 --- a/chromium/ui/message_center/views/message_popup_collection.cc +++ b/chromium/ui/message_center/views/message_popup_collection.cc @@ -6,6 +6,7 @@ #include "base/bind.h" #include "base/stl_util.h" +#include "base/threading/thread_task_runner_handle.h" #include "ui/gfx/animation/linear_animation.h" #include "ui/gfx/animation/tween.h" #include "ui/message_center/message_center.h" diff --git a/chromium/ui/message_center/views/message_popup_view.cc b/chromium/ui/message_center/views/message_popup_view.cc index 075164712f5..9626c08e03c 100644 --- a/chromium/ui/message_center/views/message_popup_view.cc +++ b/chromium/ui/message_center/views/message_popup_view.cc @@ -128,7 +128,7 @@ void MessagePopupView::Show() { params.native_widget = new views::DesktopNativeWidgetAura(widget); #endif - widget->Init(params); + widget->Init(std::move(params)); #if defined(OS_CHROMEOS) // On Chrome OS, this widget is shown in the shelf container. It means this diff --git a/chromium/ui/message_center/views/notification_header_view.cc b/chromium/ui/message_center/views/notification_header_view.cc index dc04686ee07..6bd33b7daf6 100644 --- a/chromium/ui/message_center/views/notification_header_view.cc +++ b/chromium/ui/message_center/views/notification_header_view.cc @@ -404,6 +404,9 @@ void NotificationHeaderView::UpdateSummaryTextVisibility() { const bool timestamp_visible = !has_progress_ && timestamp_; timestamp_divider_->SetVisible(timestamp_visible); timestamp_view_->SetVisible(timestamp_visible); + + // TODO(crbug.com/991492): this should not be necessary. + detail_views_->InvalidateLayout(); } } // namespace message_center diff --git a/chromium/ui/message_center/views/notification_header_view_unittest.cc b/chromium/ui/message_center/views/notification_header_view_unittest.cc index 42b6fa14211..b5ec7af47c0 100644 --- a/chromium/ui/message_center/views/notification_header_view_unittest.cc +++ b/chromium/ui/message_center/views/notification_header_view_unittest.cc @@ -4,7 +4,7 @@ #include "ui/message_center/views/notification_header_view.h" -#include "base/test/scoped_task_environment.h" +#include "base/test/task_environment.h" #include "base/time/time.h" #include "testing/gtest/include/gtest/gtest.h" #include "ui/base/l10n/l10n_util.h" @@ -15,24 +15,20 @@ namespace message_center { class NotificationHeaderViewTest : public views::ViewsTestBase { public: - NotificationHeaderViewTest() = default; + NotificationHeaderViewTest() + : views::ViewsTestBase( + base::test::TaskEnvironment::TimeSource::MOCK_TIME) {} ~NotificationHeaderViewTest() override = default; // ViewsTestBase: void SetUp() override { - // Setup a mocked time environment. - scoped_task_environment_ = new ScopedTaskEnvironment( - ScopedTaskEnvironment::MainThreadType::UI, - ScopedTaskEnvironment::TimeSource::MOCK_TIME_AND_NOW); - set_scoped_task_environment(base::WrapUnique(scoped_task_environment_)); - ViewsTestBase::SetUp(); views::Widget::InitParams params = CreateParams(views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); params.bounds = gfx::Rect(200, 200); params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; - widget_.Init(params); + widget_.Init(std::move(params)); views::View* container = new views::View(); widget_.SetContentsView(container); @@ -49,7 +45,6 @@ class NotificationHeaderViewTest : public views::ViewsTestBase { protected: NotificationHeaderView* notification_header_view_ = nullptr; - ScopedTaskEnvironment* scoped_task_environment_ = nullptr; private: views::Widget widget_; @@ -65,22 +60,22 @@ TEST_F(NotificationHeaderViewTest, UpdatesTimestampOverTime) { IDS_MESSAGE_NOTIFICATION_DURATION_HOURS_SHORTEST_FUTURE, 3), notification_header_view_->timestamp_for_testing()); - scoped_task_environment_->FastForwardBy(base::TimeDelta::FromHours(3)); - scoped_task_environment_->RunUntilIdle(); + task_environment_->FastForwardBy(base::TimeDelta::FromHours(3)); + task_environment_->RunUntilIdle(); EXPECT_EQ(l10n_util::GetPluralStringFUTF16( IDS_MESSAGE_NOTIFICATION_DURATION_MINUTES_SHORTEST_FUTURE, 30), notification_header_view_->timestamp_for_testing()); - scoped_task_environment_->FastForwardBy(base::TimeDelta::FromMinutes(30)); - scoped_task_environment_->RunUntilIdle(); + task_environment_->FastForwardBy(base::TimeDelta::FromMinutes(30)); + task_environment_->RunUntilIdle(); EXPECT_EQ( l10n_util::GetStringUTF16(IDS_MESSAGE_NOTIFICATION_NOW_STRING_SHORTEST), notification_header_view_->timestamp_for_testing()); - scoped_task_environment_->FastForwardBy(base::TimeDelta::FromDays(2)); - scoped_task_environment_->RunUntilIdle(); + task_environment_->FastForwardBy(base::TimeDelta::FromDays(2)); + task_environment_->RunUntilIdle(); EXPECT_EQ(l10n_util::GetPluralStringFUTF16( IDS_MESSAGE_NOTIFICATION_DURATION_DAYS_SHORTEST, 2), diff --git a/chromium/ui/message_center/views/notification_view_md.cc b/chromium/ui/message_center/views/notification_view_md.cc index 245e70246c3..42ca2635e42 100644 --- a/chromium/ui/message_center/views/notification_view_md.cc +++ b/chromium/ui/message_center/views/notification_view_md.cc @@ -453,7 +453,7 @@ bool NotificationInputContainerMD::HandleKeyEvent(views::Textfield* sender, if (event.type() == ui::ET_KEY_PRESSED && event.key_code() == ui::VKEY_RETURN) { delegate_->OnNotificationInputSubmit( - textfield_->GetProperty(kTextfieldIndexKey), textfield_->text()); + textfield_->GetProperty(kTextfieldIndexKey), textfield_->GetText()); textfield_->SetText(base::string16()); return true; } @@ -465,7 +465,7 @@ void NotificationInputContainerMD::OnAfterUserAction(views::Textfield* sender) { button_->SetImage( views::Button::STATE_NORMAL, gfx::CreateVectorIcon(kNotificationInlineReplyIcon, kInputReplyButtonSize, - textfield_->text().empty() + textfield_->GetText().empty() ? kTextfieldPlaceholderIconColorMD : SK_ColorWHITE)); } @@ -474,7 +474,7 @@ void NotificationInputContainerMD::ButtonPressed(views::Button* sender, const ui::Event& event) { if (sender == button_) { delegate_->OnNotificationInputSubmit( - textfield_->GetProperty(kTextfieldIndexKey), textfield_->text()); + textfield_->GetProperty(kTextfieldIndexKey), textfield_->GetText()); } } @@ -765,7 +765,7 @@ void NotificationViewMD::ButtonPressed(views::Button* sender, if (placeholder) { inline_reply_->textfield()->SetProperty(kTextfieldIndexKey, static_cast<int>(i)); - inline_reply_->textfield()->set_placeholder_text( + inline_reply_->textfield()->SetPlaceholderText( placeholder->empty() ? l10n_util::GetStringUTF16( IDS_MESSAGE_CENTER_NOTIFICATION_INLINE_REPLY_PLACEHOLDER) diff --git a/chromium/ui/message_center/views/notification_view_md_unittest.cc b/chromium/ui/message_center/views/notification_view_md_unittest.cc index 271de35c7bb..da337194661 100644 --- a/chromium/ui/message_center/views/notification_view_md_unittest.cc +++ b/chromium/ui/message_center/views/notification_view_md_unittest.cc @@ -321,7 +321,7 @@ void NotificationViewMDTest::UpdateNotificationViews( views::Widget::InitParams init_params( CreateParams(views::Widget::InitParams::TYPE_POPUP)); widget_ = new views::Widget(); - widget_->Init(init_params); + widget_->Init(std::move(init_params)); widget_->SetContentsView(notification_view_.get()); widget_->SetSize(notification_view_->GetPreferredSize()); widget_->Show(); diff --git a/chromium/ui/message_center/views/slide_out_controller.cc b/chromium/ui/message_center/views/slide_out_controller.cc index 14355c31ce7..fad2063d7ca 100644 --- a/chromium/ui/message_center/views/slide_out_controller.cc +++ b/chromium/ui/message_center/views/slide_out_controller.cc @@ -5,6 +5,7 @@ #include "ui/message_center/views/slide_out_controller.h" #include "base/bind.h" +#include "base/threading/thread_task_runner_handle.h" #include "ui/compositor/layer.h" #include "ui/compositor/scoped_layer_animation_settings.h" #include "ui/gfx/transform.h" diff --git a/chromium/ui/message_center/views/slide_out_controller_unittest.cc b/chromium/ui/message_center/views/slide_out_controller_unittest.cc index ebd677353bb..16ea6074302 100644 --- a/chromium/ui/message_center/views/slide_out_controller_unittest.cc +++ b/chromium/ui/message_center/views/slide_out_controller_unittest.cc @@ -62,7 +62,7 @@ class SlideOutControllerTest : public views::ViewsTestBase { CreateParams(views::Widget::InitParams::TYPE_POPUP); params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; params.bounds = gfx::Rect(50, 50, 650, 650); - widget_->Init(params); + widget_->Init(std::move(params)); views::View* root = widget_->GetRootView(); views::View* target_ = new views::View(); |