CrossProcessObjectWrappers.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  2. *
  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/. */
  6. #ifndef mozilla_jsipc_CrossProcessObjectWrappers_h__
  7. #define mozilla_jsipc_CrossProcessObjectWrappers_h__
  8. #include "js/TypeDecls.h"
  9. #include "mozilla/jsipc/CpowHolder.h"
  10. #include "mozilla/jsipc/JavaScriptTypes.h"
  11. #include "nsID.h"
  12. #include "nsString.h"
  13. #include "nsTArray.h"
  14. #ifdef XP_WIN
  15. #undef GetClassName
  16. #undef GetClassInfo
  17. #endif
  18. namespace mozilla {
  19. namespace dom {
  20. class CPOWManagerGetter;
  21. } // namespace dom
  22. namespace jsipc {
  23. class PJavaScriptParent;
  24. class PJavaScriptChild;
  25. class CPOWManager
  26. {
  27. public:
  28. virtual bool Unwrap(JSContext* cx,
  29. const InfallibleTArray<CpowEntry>& aCpows,
  30. JS::MutableHandleObject objp) = 0;
  31. virtual bool Wrap(JSContext* cx,
  32. JS::HandleObject aObj,
  33. InfallibleTArray<CpowEntry>* outCpows) = 0;
  34. };
  35. class CrossProcessCpowHolder : public CpowHolder
  36. {
  37. public:
  38. CrossProcessCpowHolder(dom::CPOWManagerGetter* managerGetter,
  39. const InfallibleTArray<CpowEntry>& cpows);
  40. ~CrossProcessCpowHolder();
  41. bool ToObject(JSContext* cx, JS::MutableHandleObject objp);
  42. private:
  43. CPOWManager* js_;
  44. const InfallibleTArray<CpowEntry>& cpows_;
  45. bool unwrapped_;
  46. };
  47. CPOWManager*
  48. CPOWManagerFor(PJavaScriptParent* aParent);
  49. CPOWManager*
  50. CPOWManagerFor(PJavaScriptChild* aChild);
  51. bool
  52. IsCPOW(JSObject* obj);
  53. bool
  54. IsWrappedCPOW(JSObject* obj);
  55. nsresult
  56. InstanceOf(JSObject* obj, const nsID* id, bool* bp);
  57. bool
  58. DOMInstanceOf(JSContext* cx, JSObject* obj, int prototypeID, int depth, bool* bp);
  59. void
  60. GetWrappedCPOWTag(JSObject* obj, nsACString& out);
  61. PJavaScriptParent*
  62. NewJavaScriptParent();
  63. void
  64. ReleaseJavaScriptParent(PJavaScriptParent* parent);
  65. PJavaScriptChild*
  66. NewJavaScriptChild();
  67. void
  68. ReleaseJavaScriptChild(PJavaScriptChild* child);
  69. void
  70. AfterProcessTask();
  71. } // namespace jsipc
  72. } // namespace mozilla
  73. #endif // mozilla_jsipc_CrossProcessObjectWrappers_h__