NotificationEvent.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. #ifndef mozilla_dom_workers_notificationevent_h__
  6. #define mozilla_dom_workers_notificationevent_h__
  7. #include "mozilla/dom/Event.h"
  8. #include "mozilla/dom/NotificationEventBinding.h"
  9. #include "mozilla/dom/ServiceWorkerEvents.h"
  10. #include "mozilla/dom/workers/Workers.h"
  11. BEGIN_WORKERS_NAMESPACE
  12. class ServiceWorker;
  13. class ServiceWorkerClient;
  14. class NotificationEvent final : public ExtendableEvent
  15. {
  16. protected:
  17. explicit NotificationEvent(EventTarget* aOwner);
  18. ~NotificationEvent()
  19. {}
  20. public:
  21. NS_DECL_ISUPPORTS_INHERITED
  22. NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(NotificationEvent, ExtendableEvent)
  23. NS_FORWARD_TO_EVENT
  24. virtual JSObject* WrapObjectInternal(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override
  25. {
  26. return NotificationEventBinding::Wrap(aCx, this, aGivenProto);
  27. }
  28. static already_AddRefed<NotificationEvent>
  29. Constructor(mozilla::dom::EventTarget* aOwner,
  30. const nsAString& aType,
  31. const NotificationEventInit& aOptions,
  32. ErrorResult& aRv)
  33. {
  34. RefPtr<NotificationEvent> e = new NotificationEvent(aOwner);
  35. bool trusted = e->Init(aOwner);
  36. e->InitEvent(aType, aOptions.mBubbles, aOptions.mCancelable);
  37. e->SetTrusted(trusted);
  38. e->SetComposed(aOptions.mComposed);
  39. e->mNotification = aOptions.mNotification;
  40. e->SetWantsPopupControlCheck(e->IsTrusted());
  41. return e.forget();
  42. }
  43. static already_AddRefed<NotificationEvent>
  44. Constructor(const GlobalObject& aGlobal,
  45. const nsAString& aType,
  46. const NotificationEventInit& aOptions,
  47. ErrorResult& aRv)
  48. {
  49. nsCOMPtr<EventTarget> owner = do_QueryInterface(aGlobal.GetAsSupports());
  50. return Constructor(owner, aType, aOptions, aRv);
  51. }
  52. already_AddRefed<Notification>
  53. Notification_()
  54. {
  55. RefPtr<Notification> n = mNotification;
  56. return n.forget();
  57. }
  58. private:
  59. RefPtr<Notification> mNotification;
  60. };
  61. END_WORKERS_NAMESPACE
  62. #endif /* mozilla_dom_workers_notificationevent_h__ */