ServiceWorkerRegistration.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  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_ServiceWorkerRegistration_h
  6. #define mozilla_dom_ServiceWorkerRegistration_h
  7. #include "mozilla/DOMEventTargetHelper.h"
  8. #include "mozilla/dom/ServiceWorkerBinding.h"
  9. #include "mozilla/dom/ServiceWorkerCommon.h"
  10. #include "mozilla/dom/workers/bindings/WorkerHolder.h"
  11. #include "nsContentUtils.h" // Required for nsContentUtils::PushEnabled
  12. // Support for Notification API extension.
  13. #include "mozilla/dom/NotificationBinding.h"
  14. class nsPIDOMWindowInner;
  15. namespace mozilla {
  16. namespace dom {
  17. class Promise;
  18. class PushManager;
  19. class WorkerListener;
  20. namespace workers {
  21. class ServiceWorker;
  22. class WorkerPrivate;
  23. } // namespace workers
  24. // Used by ServiceWorkerManager to notify ServiceWorkerRegistrations of
  25. // updatefound event and invalidating ServiceWorker instances.
  26. class ServiceWorkerRegistrationListener
  27. {
  28. public:
  29. NS_IMETHOD_(MozExternalRefCountType) AddRef() = 0;
  30. NS_IMETHOD_(MozExternalRefCountType) Release() = 0;
  31. virtual void
  32. UpdateFound() = 0;
  33. virtual void
  34. InvalidateWorkers(WhichServiceWorker aWhichOnes) = 0;
  35. virtual void
  36. RegistrationRemoved() = 0;
  37. virtual void
  38. GetScope(nsAString& aScope) const = 0;
  39. };
  40. class ServiceWorkerRegistration : public DOMEventTargetHelper
  41. {
  42. public:
  43. NS_DECL_ISUPPORTS_INHERITED
  44. IMPL_EVENT_HANDLER(updatefound)
  45. static bool
  46. Visible(JSContext* aCx, JSObject* aObj);
  47. static bool
  48. NotificationAPIVisible(JSContext* aCx, JSObject* aObj);
  49. static already_AddRefed<ServiceWorkerRegistration>
  50. CreateForMainThread(nsPIDOMWindowInner* aWindow,
  51. const nsAString& aScope);
  52. static already_AddRefed<ServiceWorkerRegistration>
  53. CreateForWorker(workers::WorkerPrivate* aWorkerPrivate,
  54. const nsAString& aScope);
  55. JSObject*
  56. WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
  57. virtual already_AddRefed<workers::ServiceWorker>
  58. GetInstalling() = 0;
  59. virtual already_AddRefed<workers::ServiceWorker>
  60. GetWaiting() = 0;
  61. virtual already_AddRefed<workers::ServiceWorker>
  62. GetActive() = 0;
  63. virtual void
  64. GetScope(nsAString& aScope) const = 0;
  65. virtual already_AddRefed<Promise>
  66. Update(ErrorResult& aRv) = 0;
  67. virtual already_AddRefed<Promise>
  68. Unregister(ErrorResult& aRv) = 0;
  69. virtual already_AddRefed<PushManager>
  70. GetPushManager(JSContext* aCx, ErrorResult& aRv) = 0;
  71. virtual already_AddRefed<Promise>
  72. ShowNotification(JSContext* aCx,
  73. const nsAString& aTitle,
  74. const NotificationOptions& aOptions,
  75. ErrorResult& aRv) = 0;
  76. virtual already_AddRefed<Promise>
  77. GetNotifications(const GetNotificationOptions& aOptions,
  78. ErrorResult& aRv) = 0;
  79. protected:
  80. ServiceWorkerRegistration(nsPIDOMWindowInner* aWindow,
  81. const nsAString& aScope);
  82. virtual ~ServiceWorkerRegistration()
  83. { }
  84. const nsString mScope;
  85. };
  86. } // namespace dom
  87. } // namespace mozilla
  88. #endif /* mozilla_dom_ServiceWorkerRegistration_h */