electron/shell/browser/notifications/notification.h

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

104 lines
2.9 KiB
C
Raw Normal View History

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.
#ifndef ELECTRON_SHELL_BROWSER_NOTIFICATIONS_NOTIFICATION_H_
#define ELECTRON_SHELL_BROWSER_NOTIFICATIONS_NOTIFICATION_H_
2015-12-24 14:06:41 +00:00
#include <string>
#include <vector>
#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
namespace electron {
2015-12-24 14:06:41 +00:00
class NotificationDelegate;
class NotificationPresenter;
struct NotificationAction {
std::u16string type;
std::u16string text;
};
2017-06-24 11:03:27 +00:00
struct NotificationOptions {
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;
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;
std::u16string close_button_text;
std::u16string toast_xml;
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();
// Shows the notification.
2017-06-24 11:03:27 +00:00
virtual void Show(const NotificationOptions& options) = 0;
// 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.
virtual void Dismiss() = 0;
2015-12-24 14:06:41 +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() {}
// Should be called by derived classes.
void NotificationClicked();
void NotificationDismissed(bool should_destroy = true);
void NotificationFailed(const std::string& error = "");
// 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; }
void set_notification_id(const std::string& id) { notification_id_ = id; }
void set_is_dismissed(bool dismissed) { is_dismissed_ = dismissed; }
NotificationDelegate* delegate() const { return delegate_; }
NotificationPresenter* presenter() const { return presenter_; }
const std::string& notification_id() const { return notification_id_; }
bool is_dismissed() const { return is_dismissed_; }
// disable copy
Notification(const Notification&) = delete;
Notification& operator=(const Notification&) = delete;
2015-12-24 14:06:41 +00:00
protected:
Notification(NotificationDelegate* delegate,
NotificationPresenter* presenter);
2015-12-24 14:06:41 +00:00
private:
raw_ptr<NotificationDelegate> delegate_;
raw_ptr<NotificationPresenter> presenter_;
std::string notification_id_;
bool is_dismissed_ = false;
base::WeakPtrFactory<Notification> weak_factory_{this};
2015-12-24 14:06:41 +00:00
};
} // namespace electron
2015-12-24 14:06:41 +00:00
#endif // ELECTRON_SHELL_BROWSER_NOTIFICATIONS_NOTIFICATION_H_