notification.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. NotificationOptions();
  33. ~NotificationOptions();
  34. };
  35. class Notification {
  36. public:
  37. virtual ~Notification();
  38. // Shows the notification.
  39. virtual void Show(const NotificationOptions& options) = 0;
  40. // Closes the notification, this instance will be destroyed after the
  41. // notification gets closed.
  42. virtual void Dismiss() = 0;
  43. // Should be called by derived classes.
  44. void NotificationClicked();
  45. void NotificationDismissed();
  46. void NotificationFailed();
  47. // delete this.
  48. void Destroy();
  49. base::WeakPtr<Notification> GetWeakPtr() {
  50. return weak_factory_.GetWeakPtr();
  51. }
  52. void set_delegate(NotificationDelegate* delegate) { delegate_ = delegate; }
  53. NotificationDelegate* delegate() const { return delegate_; }
  54. NotificationPresenter* presenter() const { return presenter_; }
  55. protected:
  56. Notification(NotificationDelegate* delegate,
  57. NotificationPresenter* presenter);
  58. private:
  59. NotificationDelegate* delegate_;
  60. NotificationPresenter* presenter_;
  61. base::WeakPtrFactory<Notification> weak_factory_;
  62. DISALLOW_COPY_AND_ASSIGN(Notification);
  63. };
  64. } // namespace brightray
  65. #endif // BRIGHTRAY_BROWSER_NOTIFICATION_H_