notification_utils.cc 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. // Copyright 2018 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "ash/public/cpp/notification_utils.h"
  5. #include "ui/gfx/vector_icon_types.h"
  6. #include "ui/message_center/public/cpp/notification_delegate.h"
  7. namespace ash {
  8. std::unique_ptr<message_center::Notification> CreateSystemNotification(
  9. message_center::NotificationType type,
  10. const std::string& id,
  11. const std::u16string& title,
  12. const std::u16string& message,
  13. const std::u16string& display_source,
  14. const GURL& origin_url,
  15. const message_center::NotifierId& notifier_id,
  16. const message_center::RichNotificationData& optional_fields,
  17. scoped_refptr<message_center::NotificationDelegate> delegate,
  18. const gfx::VectorIcon& small_image,
  19. message_center::SystemNotificationWarningLevel warning_level) {
  20. DCHECK_EQ(message_center::NotifierType::SYSTEM_COMPONENT, notifier_id.type);
  21. SkColor color = kSystemNotificationColorNormal;
  22. switch (warning_level) {
  23. case message_center::SystemNotificationWarningLevel::NORMAL:
  24. color = kSystemNotificationColorNormal;
  25. break;
  26. case message_center::SystemNotificationWarningLevel::WARNING:
  27. color = kSystemNotificationColorWarning;
  28. break;
  29. case message_center::SystemNotificationWarningLevel::CRITICAL_WARNING:
  30. color = kSystemNotificationColorCriticalWarning;
  31. break;
  32. }
  33. auto notification = std::make_unique<message_center::Notification>(
  34. type, id, title, message, ui::ImageModel(), display_source, origin_url,
  35. notifier_id, optional_fields, delegate);
  36. notification->set_accent_color(color);
  37. notification->set_system_notification_warning_level(warning_level);
  38. if (!small_image.is_empty())
  39. notification->set_vector_small_image(small_image);
  40. return notification;
  41. }
  42. } // namespace ash