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.
|
|
|
|
|
2021-11-22 07:34:31 +00:00
|
|
|
#ifndef ELECTRON_SHELL_BROWSER_NOTIFICATIONS_NOTIFICATION_H_
|
|
|
|
#define ELECTRON_SHELL_BROWSER_NOTIFICATIONS_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
|
|
|
|
2023-05-11 20:07:39 +00:00
|
|
|
#include "base/memory/raw_ptr.h"
|
2015-12-24 14:06:41 +00:00
|
|
|
#include "base/memory/weak_ptr.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
|
|
|
|
2018-10-17 18:01:11 +00:00
|
|
|
namespace electron {
|
2015-12-24 14:06:41 +00:00
|
|
|
|
2015-12-25 02:16:07 +00:00
|
|
|
class NotificationDelegate;
|
|
|
|
class NotificationPresenter;
|
|
|
|
|
2017-06-23 10:39:42 +00:00
|
|
|
struct NotificationAction {
|
2021-03-16 16:18:45 +00:00
|
|
|
std::u16string type;
|
|
|
|
std::u16string text;
|
2017-06-23 10:39:42 +00:00
|
|
|
};
|
|
|
|
|
2017-06-24 11:03:27 +00:00
|
|
|
struct NotificationOptions {
|
2021-03-16 16:18:45 +00:00
|
|
|
std::u16string title;
|
|
|
|
std::u16string subtitle;
|
|
|
|
std::u16string msg;
|
2017-06-24 11:03:27 +00:00
|
|
|
std::string tag;
|
2018-01-22 18:48:12 +00:00
|
|
|
bool silent;
|
2017-06-24 11:03:27 +00:00
|
|
|
GURL icon_url;
|
|
|
|
SkBitmap icon;
|
|
|
|
bool has_reply;
|
2021-03-16 16:18:45 +00:00
|
|
|
std::u16string timeout_type;
|
|
|
|
std::u16string reply_placeholder;
|
|
|
|
std::u16string sound;
|
|
|
|
std::u16string urgency; // Linux
|
2017-06-24 11:03:27 +00:00
|
|
|
std::vector<NotificationAction> actions;
|
2021-03-16 16:18:45 +00:00
|
|
|
std::u16string close_button_text;
|
|
|
|
std::u16string toast_xml;
|
2018-04-17 23:37:22 +00:00
|
|
|
|
|
|
|
NotificationOptions();
|
|
|
|
~NotificationOptions();
|
2017-06-24 11:03:27 +00:00
|
|
|
};
|
|
|
|
|
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;
|
2023-10-17 23:33:00 +00:00
|
|
|
|
|
|
|
// Dismisses the notification. On some platforms this will result in full
|
|
|
|
// removal and destruction of the notification, but if the initial dismissal
|
|
|
|
// does not fully get rid of the notification it will be destroyed in Remove.
|
2015-12-25 02:16:07 +00:00
|
|
|
virtual void Dismiss() = 0;
|
2015-12-24 14:06:41 +00:00
|
|
|
|
2023-10-17 23:33:00 +00:00
|
|
|
// Removes the notification if it was not fully removed during dismissal,
|
|
|
|
// as can happen on some platforms including Windows.
|
refactor: put empty virtual function definitions in header (#43285)
* refactor: in FramelessView, move empty function decls to header
* refactor: in electron::api::WebContents, move empty function decls to header
* refactor: in electron::api::NativeWindow, move empty function decls to header
* refactor: in electron::OffScreenWebContentsView, move empty function decls to header
* refactor: in electron::OffScreenRenderWidgetHostView, move empty function decls to header
* refactor: in auto_updater::AutoUpdater, move empty function decls to header
* refactor: in electorn::api::FrameSubscriber, move empty function decls to header
* refactor: in electorn::api::SimpleURLLoaderWrapper, move empty function decls to header
* refactor: in electorn::InspectableWebContents, move empty function decls to header
* refactor: in electorn::OffScreenVideoConsumer, move empty function decls to header
* refactor: in electron::OffScreenWebContentsView, move empty function decls to header
* refactor: in electron::TrayIcon, move empty function decls to header
* refactor: in electron::ViewsDelegate, move empty function decls to header
* refactor: in electron::MediaCaptureDevicesDispatcher, move empty function decls to header
* refactor: in electron::UsbChooserContext::DeviceObserver, move empty function decls to header
* refactor: in electron::ProxyingWebSocket, move empty function decls to header
* refactor: in electron::Notification, move empty function decls to header
* refactor: in electron::PlatformNotificationService, move empty function decls to header
* Revert "refactor: in electron::PlatformNotificationService, move empty function decls to header"
This reverts commit 9103750d03b9ba1ceccba43d11dfdc2404ff6191.
* refactor: in electron::ElectronPDFDocumentHelperClient, move empty function decls to header
* refactor: in electron::api::SpellCheckClient, move empty function decls to header
* refactor: in electron::ElectronExtensionHostDelegate, move empty function decls to header
* refactor: in electron::PlatformNotificationService, move empty function decls to header
* refactor: in electron::NativeWindowViews, move empty function decls to header
* chore: move SetTouchBar() back to cc
* Revert "refactor: in auto_updater::AutoUpdater, move empty function decls to header"
This reverts commit c43d6862d32c74f63f82700a7546a732ac05ecb8.
2024-08-12 07:56:51 +00:00
|
|
|
virtual void Remove() {}
|
2023-10-17 23:33:00 +00:00
|
|
|
|
2016-04-15 07:14:13 +00:00
|
|
|
// Should be called by derived classes.
|
2020-09-02 01:02:47 +00:00
|
|
|
void NotificationClicked();
|
2023-10-17 23:33:00 +00:00
|
|
|
void NotificationDismissed(bool should_destroy = true);
|
2020-09-29 19:20:10 +00:00
|
|
|
void NotificationFailed(const std::string& error = "");
|
2016-04-15 07:14:13 +00:00
|
|
|
|
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; }
|
2018-04-08 19:24:08 +00:00
|
|
|
void set_notification_id(const std::string& id) { notification_id_ = id; }
|
2023-10-17 23:33:00 +00:00
|
|
|
void set_is_dismissed(bool dismissed) { is_dismissed_ = dismissed; }
|
2018-04-08 19:24:08 +00:00
|
|
|
|
2015-12-25 02:16:07 +00:00
|
|
|
NotificationDelegate* delegate() const { return delegate_; }
|
|
|
|
NotificationPresenter* presenter() const { return presenter_; }
|
2018-04-08 19:24:08 +00:00
|
|
|
const std::string& notification_id() const { return notification_id_; }
|
2023-10-17 23:33:00 +00:00
|
|
|
bool is_dismissed() const { return is_dismissed_; }
|
2015-12-25 02:16:07 +00:00
|
|
|
|
2021-11-03 11:41:45 +00:00
|
|
|
// disable copy
|
|
|
|
Notification(const Notification&) = delete;
|
|
|
|
Notification& operator=(const Notification&) = delete;
|
|
|
|
|
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:
|
2023-05-11 20:07:39 +00:00
|
|
|
raw_ptr<NotificationDelegate> delegate_;
|
|
|
|
raw_ptr<NotificationPresenter> presenter_;
|
2018-04-08 19:24:08 +00:00
|
|
|
std::string notification_id_;
|
2023-10-17 23:33:00 +00:00
|
|
|
bool is_dismissed_ = false;
|
2015-12-25 02:16:07 +00:00
|
|
|
|
2021-01-26 18:16:21 +00:00
|
|
|
base::WeakPtrFactory<Notification> weak_factory_{this};
|
2015-12-24 14:06:41 +00:00
|
|
|
};
|
|
|
|
|
2018-10-17 18:01:11 +00:00
|
|
|
} // namespace electron
|
2015-12-24 14:06:41 +00:00
|
|
|
|
2021-11-22 07:34:31 +00:00
|
|
|
#endif // ELECTRON_SHELL_BROWSER_NOTIFICATIONS_NOTIFICATION_H_
|