NotificationParent.h (2397B)
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */ 3 /* This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this file, 5 * You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 #ifndef DOM_NOTIFICATION_NOTIFICATIONPARENT_H_ 8 #define DOM_NOTIFICATION_NOTIFICATIONPARENT_H_ 9 10 #include "mozilla/dom/DOMTypes.h" 11 #include "mozilla/dom/notification/PNotificationParent.h" 12 #include "mozilla/ipc/PBackgroundParent.h" 13 14 namespace mozilla::dom::notification { 15 16 enum class CloseMode; 17 18 enum class AlertTopic : uint8_t { 19 Disable, 20 Settings, 21 Click, 22 Show, 23 // Either closed or error. 24 // See ToAlertTopic about why we have both Finished and Closed. 25 Finished, 26 Closed, 27 }; 28 29 struct NotificationParentArgs { 30 NotNull<nsCOMPtr<nsIPrincipal>> mPrincipal; 31 NotNull<nsCOMPtr<nsIPrincipal>> mEffectiveStoragePrincipal; 32 bool mIsSecureContext; 33 nsString mScope; 34 IPCNotification mNotification; 35 }; 36 37 class NotificationParent final : public PNotificationParent, 38 public nsISupports, 39 public SupportsWeakPtr { 40 using IPCResult = mozilla::ipc::IPCResult; 41 42 public: 43 NS_DECL_ISUPPORTS 44 45 nsresult HandleAlertTopic(AlertTopic aTopic); 46 IPCResult RecvShow(ShowResolver&& aResolver); 47 IPCResult RecvClose(); 48 49 static nsresult CreateOnMainThread( 50 NotificationParentArgs&& mArgs, 51 Endpoint<PNotificationParent>&& aParentEndpoint, 52 PBackgroundParent::CreateNotificationParentResolver&& aResolver); 53 54 private: 55 explicit NotificationParent(NotificationParentArgs&& aArgs) 56 : mId(aArgs.mNotification.id()), mArgs(std::move(aArgs)) {}; 57 ~NotificationParent() = default; 58 59 nsresult Show(); 60 nsresult FireClickEvent(); 61 62 void Unregister(); 63 64 Maybe<NotificationParent::ShowResolver> mResolver; 65 66 // The ID generated by nsIAlertNotification during Show() function. It may 67 // stay empty if the function fails. 68 nsString mId; 69 const NotificationParentArgs mArgs; 70 71 // Whether it's now a dangling actor without corresponding OS notification, 72 // either because it's closed or denied permission. We don't have to call 73 // CloseAlert if this is the case. 74 bool mDangling = false; 75 }; 76 77 } // namespace mozilla::dom::notification 78 79 #endif // DOM_NOTIFICATION_NOTIFICATIONPARENT_H_