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
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_dom_workers_notificationevent_h__
8 #define mozilla_dom_workers_notificationevent_h__
10 #include "mozilla/dom/Event.h"
11 #include "mozilla/dom/NotificationEventBinding.h"
12 #include "mozilla/dom/ServiceWorkerEvents.h"
13 #include "mozilla/dom/WorkerCommon.h"
15 namespace mozilla::dom
{
18 class ServiceWorkerClient
;
20 class NotificationEvent final
: public ExtendableEvent
{
22 explicit NotificationEvent(EventTarget
* aOwner
);
23 ~NotificationEvent() = default;
26 NS_DECL_ISUPPORTS_INHERITED
27 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(NotificationEvent
, ExtendableEvent
)
29 virtual JSObject
* WrapObjectInternal(
30 JSContext
* aCx
, JS::Handle
<JSObject
*> aGivenProto
) override
{
31 return NotificationEvent_Binding::Wrap(aCx
, this, aGivenProto
);
34 static already_AddRefed
<NotificationEvent
> Constructor(
35 mozilla::dom::EventTarget
* aOwner
, const nsAString
& aType
,
36 const NotificationEventInit
& aOptions
) {
37 RefPtr
<NotificationEvent
> e
= new NotificationEvent(aOwner
);
38 bool trusted
= e
->Init(aOwner
);
39 e
->InitEvent(aType
, aOptions
.mBubbles
, aOptions
.mCancelable
);
40 e
->SetTrusted(trusted
);
41 e
->SetComposed(aOptions
.mComposed
);
42 e
->mNotification
= aOptions
.mNotification
;
43 e
->SetWantsPopupControlCheck(e
->IsTrusted());
47 static already_AddRefed
<NotificationEvent
> Constructor(
48 const GlobalObject
& aGlobal
, const nsAString
& aType
,
49 const NotificationEventInit
& aOptions
) {
50 nsCOMPtr
<EventTarget
> owner
= do_QueryInterface(aGlobal
.GetAsSupports());
51 return Constructor(owner
, aType
, aOptions
);
54 already_AddRefed
<Notification
> Notification_() {
55 RefPtr
<Notification
> n
= mNotification
;
60 RefPtr
<Notification
> mNotification
;
63 } // namespace mozilla::dom
65 #endif /* mozilla_dom_workers_notificationevent_h__ */