notification.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. bool silent;
  25. GURL icon_url;
  26. SkBitmap icon;
  27. bool has_reply;
  28. base::string16 reply_placeholder;
  29. base::string16 sound;
  30. std::vector<NotificationAction> actions;
  31. base::string16 close_button_text;
  32. };
  33. class Notification {
  34. public:
  35. virtual ~Notification();
  36. // Shows the notification.
  37. virtual void Show(const NotificationOptions& options) = 0;
  38. // Closes the notification, this instance will be destroyed after the
  39. // notification gets closed.
  40. virtual void Dismiss() = 0;
  41. // Should be called by derived classes.
  42. void NotificationClicked();
  43. void NotificationDismissed();
  44. void NotificationFailed();
  45. // delete this.
  46. void Destroy();
  47. base::WeakPtr<Notification> GetWeakPtr() {
  48. return weak_factory_.GetWeakPtr();
  49. }
  50. void set_delegate(NotificationDelegate* delegate) { delegate_ = delegate; }
  51. NotificationDelegate* delegate() const { return delegate_; }
  52. NotificationPresenter* presenter() const { return presenter_; }
  53. protected:
  54. Notification(NotificationDelegate* delegate,
  55. NotificationPresenter* presenter);
  56. private:
  57. NotificationDelegate* delegate_;
  58. NotificationPresenter* presenter_;
  59. base::WeakPtrFactory<Notification> weak_factory_;
  60. DISALLOW_COPY_AND_ASSIGN(Notification);
  61. };
  62. } // namespace brightray
  63. #endif // BRIGHTRAY_BROWSER_NOTIFICATION_H_