MessageChannel.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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_MessageChannel_h
  6. #define mozilla_dom_MessageChannel_h
  7. #include "mozilla/Attributes.h"
  8. #include "mozilla/ErrorResult.h"
  9. #include "mozilla/dom/BindingDeclarations.h"
  10. #include "nsCycleCollectionParticipant.h"
  11. #include "nsWrapperCache.h"
  12. #include "nsCOMPtr.h"
  13. class nsIGlobalObject;
  14. namespace mozilla {
  15. namespace dom {
  16. class MessagePort;
  17. class MessageChannel final : public nsISupports
  18. , public nsWrapperCache
  19. {
  20. public:
  21. NS_DECL_CYCLE_COLLECTING_ISUPPORTS
  22. NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(MessageChannel)
  23. nsIGlobalObject*
  24. GetParentObject() const
  25. {
  26. return mGlobal;
  27. }
  28. virtual JSObject*
  29. WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
  30. static already_AddRefed<MessageChannel>
  31. Constructor(const GlobalObject& aGlobal, ErrorResult& aRv);
  32. static already_AddRefed<MessageChannel>
  33. Constructor(nsIGlobalObject* aGlobal, ErrorResult& aRv);
  34. MessagePort*
  35. Port1() const
  36. {
  37. return mPort1;
  38. }
  39. MessagePort*
  40. Port2() const
  41. {
  42. return mPort2;
  43. }
  44. private:
  45. explicit MessageChannel(nsIGlobalObject* aGlobal);
  46. ~MessageChannel();
  47. nsCOMPtr<nsIGlobalObject> mGlobal;
  48. RefPtr<MessagePort> mPort1;
  49. RefPtr<MessagePort> mPort2;
  50. };
  51. } // namespace dom
  52. } // namespace mozilla
  53. #endif // mozilla_dom_MessageChannel_h