notification.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. // Copyright (c) 2015 GitHub, Inc.
  2. // Use of this source code is governed by the MIT license that can be
  3. // found in the LICENSE file.
  4. #ifndef BRIGHTRAY_BROWSER_NOTIFICATION_H_
  5. #define BRIGHTRAY_BROWSER_NOTIFICATION_H_
  6. #include <string>
  7. #include <vector>
  8. #include "base/memory/weak_ptr.h"
  9. #include "base/strings/string16.h"
  10. #include "third_party/skia/include/core/SkBitmap.h"
  11. #include "url/gurl.h"
  12. namespace brightray {
  13. class NotificationDelegate;
  14. class NotificationPresenter;
  15. struct NotificationAction {
  16. base::string16 type;
  17. base::string16 text;
  18. };
  19. struct NotificationOptions {
  20. base::string16 title;
  21. base::string16 subtitle;
  22. base::string16 msg;
  23. std::string tag;
  24. GURL icon_url;
  25. SkBitmap icon;
  26. bool silent;
  27. bool has_reply;
  28. base::string16 reply_placeholder;
  29. base::string16 sound;
  30. std::vector<NotificationAction> actions;
  31. };
  32. class Notification {
  33. public:
  34. virtual ~Notification();
  35. // Shows the notification.
  36. virtual void Show(const NotificationOptions& options) = 0;
  37. // Closes the notification, this instance will be destroyed after the
  38. // notification gets closed.
  39. virtual void Dismiss() = 0;
  40. // Should be called by derived classes.
  41. void NotificationClicked();
  42. void NotificationDismissed();
  43. void NotificationFailed();
  44. // delete this.
  45. void Destroy();
  46. base::WeakPtr<Notification> GetWeakPtr() {
  47. return weak_factory_.GetWeakPtr();
  48. }
  49. void set_delegate(NotificationDelegate* delegate) { delegate_ = delegate; }
  50. NotificationDelegate* delegate() const { return delegate_; }
  51. NotificationPresenter* presenter() const { return presenter_; }
  52. protected:
  53. Notification(NotificationDelegate* delegate,
  54. NotificationPresenter* presenter);
  55. private:
  56. NotificationDelegate* delegate_;
  57. NotificationPresenter* presenter_;
  58. base::WeakPtrFactory<Notification> weak_factory_;
  59. DISALLOW_COPY_AND_ASSIGN(Notification);
  60. };
  61. } // namespace brightray
  62. #endif // BRIGHTRAY_BROWSER_NOTIFICATION_H_