2015-12-24 14:06:41 +00:00
|
|
|
// Copyright (c) 2015 GitHub, Inc.
|
|
|
|
// Use of this source code is governed by the MIT license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2017-05-18 22:05:25 +00:00
|
|
|
#ifndef BRIGHTRAY_BROWSER_NOTIFICATION_H_
|
|
|
|
#define BRIGHTRAY_BROWSER_NOTIFICATION_H_
|
2015-12-24 14:06:41 +00:00
|
|
|
|
2017-05-18 22:06:57 +00:00
|
|
|
#include <string>
|
2017-06-23 10:39:42 +00:00
|
|
|
#include <vector>
|
2017-05-18 22:06:57 +00:00
|
|
|
|
2015-12-24 14:06:41 +00:00
|
|
|
#include "base/memory/weak_ptr.h"
|
|
|
|
#include "base/strings/string16.h"
|
2017-06-24 11:03:27 +00:00
|
|
|
#include "third_party/skia/include/core/SkBitmap.h"
|
|
|
|
#include "url/gurl.h"
|
2015-12-24 14:06:41 +00:00
|
|
|
|
|
|
|
namespace brightray {
|
|
|
|
|
2015-12-25 02:16:07 +00:00
|
|
|
class NotificationDelegate;
|
|
|
|
class NotificationPresenter;
|
|
|
|
|
2017-06-23 10:39:42 +00:00
|
|
|
struct NotificationAction {
|
|
|
|
base::string16 type;
|
2017-06-23 11:04:39 +00:00
|
|
|
base::string16 text;
|
2017-06-23 10:39:42 +00:00
|
|
|
};
|
|
|
|
|
2017-06-24 11:03:27 +00:00
|
|
|
struct NotificationOptions {
|
|
|
|
base::string16 title;
|
|
|
|
base::string16 msg;
|
|
|
|
std::string tag;
|
|
|
|
GURL icon_url;
|
|
|
|
SkBitmap icon;
|
|
|
|
bool silent;
|
|
|
|
bool has_reply;
|
|
|
|
base::string16 reply_placeholder;
|
|
|
|
std::vector<NotificationAction> actions;
|
|
|
|
};
|
|
|
|
|
2015-12-24 14:06:41 +00:00
|
|
|
class Notification {
|
|
|
|
public:
|
2017-05-31 07:17:29 +00:00
|
|
|
virtual ~Notification();
|
|
|
|
|
2015-12-25 02:16:07 +00:00
|
|
|
// Shows the notification.
|
2017-06-24 11:03:27 +00:00
|
|
|
virtual void Show(const NotificationOptions& options) = 0;
|
2015-12-25 02:16:07 +00:00
|
|
|
// Closes the notification, this instance will be destroyed after the
|
|
|
|
// notification gets closed.
|
|
|
|
virtual void Dismiss() = 0;
|
2015-12-24 14:06:41 +00:00
|
|
|
|
2016-04-15 07:14:13 +00:00
|
|
|
// Should be called by derived classes.
|
|
|
|
void NotificationClicked();
|
|
|
|
void NotificationDismissed();
|
|
|
|
void NotificationFailed();
|
|
|
|
|
2016-10-25 13:32:06 +00:00
|
|
|
// delete this.
|
|
|
|
void Destroy();
|
|
|
|
|
2015-12-24 14:06:41 +00:00
|
|
|
base::WeakPtr<Notification> GetWeakPtr() {
|
|
|
|
return weak_factory_.GetWeakPtr();
|
|
|
|
}
|
|
|
|
|
2017-05-31 07:17:29 +00:00
|
|
|
void set_delegate(NotificationDelegate* delegate) { delegate_ = delegate; }
|
2015-12-25 02:16:07 +00:00
|
|
|
NotificationDelegate* delegate() const { return delegate_; }
|
|
|
|
NotificationPresenter* presenter() const { return presenter_; }
|
|
|
|
|
2015-12-24 14:06:41 +00:00
|
|
|
protected:
|
2015-12-25 02:16:07 +00:00
|
|
|
Notification(NotificationDelegate* delegate,
|
|
|
|
NotificationPresenter* presenter);
|
2017-04-05 11:27:46 +00:00
|
|
|
|
2015-12-24 14:06:41 +00:00
|
|
|
private:
|
2015-12-25 02:16:07 +00:00
|
|
|
NotificationDelegate* delegate_;
|
|
|
|
NotificationPresenter* presenter_;
|
|
|
|
|
2015-12-24 14:06:41 +00:00
|
|
|
base::WeakPtrFactory<Notification> weak_factory_;
|
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(Notification);
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace brightray
|
|
|
|
|
2017-05-18 22:05:25 +00:00
|
|
|
#endif // BRIGHTRAY_BROWSER_NOTIFICATION_H_
|