ServiceWorkerClient.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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 file,
  4. * You can obtain one at http://mozilla.org/MPL/2.0/.
  5. */
  6. #ifndef mozilla_dom_workers_serviceworkerclient_h
  7. #define mozilla_dom_workers_serviceworkerclient_h
  8. #include "nsCOMPtr.h"
  9. #include "nsWrapperCache.h"
  10. #include "mozilla/ErrorResult.h"
  11. #include "mozilla/dom/BindingDeclarations.h"
  12. #include "mozilla/dom/ClientBinding.h"
  13. class nsIDocument;
  14. namespace mozilla {
  15. namespace dom {
  16. namespace workers {
  17. class ServiceWorkerClient;
  18. class ServiceWorkerWindowClient;
  19. // Used as a container object for information needed to create
  20. // client objects.
  21. class ServiceWorkerClientInfo final
  22. {
  23. friend class ServiceWorkerClient;
  24. friend class ServiceWorkerWindowClient;
  25. public:
  26. explicit ServiceWorkerClientInfo(nsIDocument* aDoc);
  27. const nsString& ClientId() const
  28. {
  29. return mClientId;
  30. }
  31. private:
  32. nsString mClientId;
  33. uint64_t mWindowId;
  34. nsString mUrl;
  35. // Window Clients
  36. VisibilityState mVisibilityState;
  37. bool mFocused;
  38. FrameType mFrameType;
  39. };
  40. class ServiceWorkerClient : public nsISupports,
  41. public nsWrapperCache
  42. {
  43. public:
  44. NS_DECL_CYCLE_COLLECTING_ISUPPORTS
  45. NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(ServiceWorkerClient)
  46. ServiceWorkerClient(nsISupports* aOwner,
  47. const ServiceWorkerClientInfo& aClientInfo)
  48. : mOwner(aOwner)
  49. , mId(aClientInfo.mClientId)
  50. , mUrl(aClientInfo.mUrl)
  51. , mWindowId(aClientInfo.mWindowId)
  52. , mFrameType(aClientInfo.mFrameType)
  53. {
  54. MOZ_ASSERT(aOwner);
  55. }
  56. nsISupports*
  57. GetParentObject() const
  58. {
  59. return mOwner;
  60. }
  61. void GetId(nsString& aRetval) const
  62. {
  63. aRetval = mId;
  64. }
  65. void
  66. GetUrl(nsAString& aUrl) const
  67. {
  68. aUrl.Assign(mUrl);
  69. }
  70. mozilla::dom::FrameType
  71. FrameType() const
  72. {
  73. return mFrameType;
  74. }
  75. void
  76. PostMessage(JSContext* aCx, JS::Handle<JS::Value> aMessage,
  77. const Optional<Sequence<JS::Value>>& aTransferable,
  78. ErrorResult& aRv);
  79. JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
  80. protected:
  81. virtual ~ServiceWorkerClient()
  82. { }
  83. private:
  84. nsCOMPtr<nsISupports> mOwner;
  85. nsString mId;
  86. nsString mUrl;
  87. protected:
  88. uint64_t mWindowId;
  89. mozilla::dom::FrameType mFrameType;
  90. };
  91. } // namespace workers
  92. } // namespace dom
  93. } // namespace mozilla
  94. #endif // mozilla_dom_workers_serviceworkerclient_h