WrapperOwner.h 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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_WrapperOwner_h__
  7. #define mozilla_jsipc_WrapperOwner_h__
  8. #include "JavaScriptShared.h"
  9. #include "mozilla/ipc/ProtocolUtils.h"
  10. #include "mozilla/jsipc/CrossProcessObjectWrappers.h"
  11. #include "js/Class.h"
  12. #include "js/Proxy.h"
  13. namespace mozilla {
  14. namespace jsipc {
  15. class WrapperOwner : public virtual JavaScriptShared
  16. {
  17. public:
  18. typedef mozilla::ipc::IProtocol::ActorDestroyReason
  19. ActorDestroyReason;
  20. WrapperOwner();
  21. bool init();
  22. // Standard internal methods.
  23. // (The traps should be in the same order like js/Proxy.h)
  24. bool getOwnPropertyDescriptor(JSContext* cx, JS::HandleObject proxy, JS::HandleId id,
  25. JS::MutableHandle<JS::PropertyDescriptor> desc);
  26. bool defineProperty(JSContext* cx, JS::HandleObject proxy, JS::HandleId id,
  27. JS::Handle<JS::PropertyDescriptor> desc,
  28. JS::ObjectOpResult& result);
  29. bool ownPropertyKeys(JSContext* cx, JS::HandleObject proxy, JS::AutoIdVector& props);
  30. bool delete_(JSContext* cx, JS::HandleObject proxy, JS::HandleId id,
  31. JS::ObjectOpResult& result);
  32. bool preventExtensions(JSContext* cx, JS::HandleObject proxy, JS::ObjectOpResult& result);
  33. bool isExtensible(JSContext* cx, JS::HandleObject proxy, bool* extensible);
  34. bool has(JSContext* cx, JS::HandleObject proxy, JS::HandleId id, bool* bp);
  35. bool get(JSContext* cx, JS::HandleObject proxy, JS::HandleValue receiver,
  36. JS::HandleId id, JS::MutableHandleValue vp);
  37. bool set(JSContext* cx, JS::HandleObject proxy, JS::HandleId id, JS::HandleValue v,
  38. JS::HandleValue receiver, JS::ObjectOpResult& result);
  39. bool callOrConstruct(JSContext* cx, JS::HandleObject proxy, const JS::CallArgs& args,
  40. bool construct);
  41. // SpiderMonkey extensions.
  42. bool getPropertyDescriptor(JSContext* cx, JS::HandleObject proxy, JS::HandleId id,
  43. JS::MutableHandle<JS::PropertyDescriptor> desc);
  44. bool hasOwn(JSContext* cx, JS::HandleObject proxy, JS::HandleId id, bool* bp);
  45. bool getOwnEnumerablePropertyKeys(JSContext* cx, JS::HandleObject proxy,
  46. JS::AutoIdVector& props);
  47. bool hasInstance(JSContext* cx, JS::HandleObject proxy, JS::MutableHandleValue v, bool* bp);
  48. bool getBuiltinClass(JSContext* cx, JS::HandleObject proxy, js::ESClass* cls);
  49. bool isArray(JSContext* cx, JS::HandleObject proxy, JS::IsArrayAnswer* answer);
  50. const char* className(JSContext* cx, JS::HandleObject proxy);
  51. bool getPrototype(JSContext* cx, JS::HandleObject proxy, JS::MutableHandleObject protop);
  52. bool getPrototypeIfOrdinary(JSContext* cx, JS::HandleObject proxy, bool* isOrdinary,
  53. JS::MutableHandleObject protop);
  54. bool regexp_toShared(JSContext* cx, JS::HandleObject proxy, js::RegExpGuard* g);
  55. nsresult instanceOf(JSObject* obj, const nsID* id, bool* bp);
  56. bool toString(JSContext* cx, JS::HandleObject callee, JS::CallArgs& args);
  57. bool DOMQI(JSContext* cx, JS::HandleObject callee, JS::CallArgs& args);
  58. /*
  59. * Check that |obj| is a DOM wrapper whose prototype chain contains
  60. * |prototypeID| at depth |depth|.
  61. */
  62. bool domInstanceOf(JSContext* cx, JSObject* obj, int prototypeID, int depth, bool* bp);
  63. bool active() { return !inactive_; }
  64. virtual bool allowMessage(JSContext* cx) = 0;
  65. void drop(JSObject* obj);
  66. void updatePointer(JSObject* obj, const JSObject* old);
  67. virtual void ActorDestroy(ActorDestroyReason why);
  68. virtual bool toObjectVariant(JSContext* cx, JSObject* obj, ObjectVariant* objVarp);
  69. virtual JSObject* fromObjectVariant(JSContext* cx, const ObjectVariant& objVar);
  70. JSObject* fromRemoteObjectVariant(JSContext* cx, const RemoteObject& objVar);
  71. JSObject* fromLocalObjectVariant(JSContext* cx, const LocalObject& objVar);
  72. protected:
  73. ObjectId idOf(JSObject* obj);
  74. private:
  75. ObjectId idOfUnchecked(JSObject* obj);
  76. bool getPropertyKeys(JSContext* cx, JS::HandleObject proxy, uint32_t flags,
  77. JS::AutoIdVector& props);
  78. // Catastrophic IPC failure.
  79. bool ipcfail(JSContext* cx);
  80. // Check whether a return status is okay, and if not, propagate its error.
  81. //
  82. // If 'status' might be a ReturnObjectOpResult, which is only possible for
  83. // a subset of the operations below, 'result' must be passed.
  84. bool ok(JSContext* cx, const ReturnStatus& status, JS::ObjectOpResult& result);
  85. bool ok(JSContext* cx, const ReturnStatus& status);
  86. bool inactive_;
  87. /*** Dummy call handlers ***/
  88. public:
  89. virtual bool SendDropObject(const ObjectId& objId) = 0;
  90. virtual bool SendPreventExtensions(const ObjectId& objId, ReturnStatus* rs) = 0;
  91. virtual bool SendGetPropertyDescriptor(const ObjectId& objId, const JSIDVariant& id,
  92. ReturnStatus* rs,
  93. PPropertyDescriptor* out) = 0;
  94. virtual bool SendGetOwnPropertyDescriptor(const ObjectId& objId,
  95. const JSIDVariant& id,
  96. ReturnStatus* rs,
  97. PPropertyDescriptor* out) = 0;
  98. virtual bool SendDefineProperty(const ObjectId& objId, const JSIDVariant& id,
  99. const PPropertyDescriptor& flags,
  100. ReturnStatus* rs) = 0;
  101. virtual bool SendDelete(const ObjectId& objId, const JSIDVariant& id,
  102. ReturnStatus* rs) = 0;
  103. virtual bool SendHas(const ObjectId& objId, const JSIDVariant& id,
  104. ReturnStatus* rs, bool* bp) = 0;
  105. virtual bool SendHasOwn(const ObjectId& objId, const JSIDVariant& id,
  106. ReturnStatus* rs, bool* bp) = 0;
  107. virtual bool SendGet(const ObjectId& objId, const JSVariant& receiverVar,
  108. const JSIDVariant& id,
  109. ReturnStatus* rs, JSVariant* result) = 0;
  110. virtual bool SendSet(const ObjectId& objId, const JSIDVariant& id, const JSVariant& value,
  111. const JSVariant& receiverVar, ReturnStatus* rs) = 0;
  112. virtual bool SendIsExtensible(const ObjectId& objId, ReturnStatus* rs,
  113. bool* result) = 0;
  114. virtual bool SendCallOrConstruct(const ObjectId& objId, const nsTArray<JSParam>& argv,
  115. const bool& construct, ReturnStatus* rs, JSVariant* result,
  116. nsTArray<JSParam>* outparams) = 0;
  117. virtual bool SendHasInstance(const ObjectId& objId, const JSVariant& v,
  118. ReturnStatus* rs, bool* bp) = 0;
  119. virtual bool SendGetBuiltinClass(const ObjectId& objId, ReturnStatus* rs,
  120. uint32_t* classValue) = 0;
  121. virtual bool SendIsArray(const ObjectId& objId, ReturnStatus* rs,
  122. uint32_t* answer) = 0;
  123. virtual bool SendClassName(const ObjectId& objId, nsCString* result) = 0;
  124. virtual bool SendGetPrototype(const ObjectId& objId, ReturnStatus* rs, ObjectOrNullVariant* result) = 0;
  125. virtual bool SendGetPrototypeIfOrdinary(const ObjectId& objId, ReturnStatus* rs, bool* isOrdinary,
  126. ObjectOrNullVariant* result) = 0;
  127. virtual bool SendRegExpToShared(const ObjectId& objId, ReturnStatus* rs, nsString* source,
  128. uint32_t* flags) = 0;
  129. virtual bool SendGetPropertyKeys(const ObjectId& objId, const uint32_t& flags,
  130. ReturnStatus* rs, nsTArray<JSIDVariant>* ids) = 0;
  131. virtual bool SendInstanceOf(const ObjectId& objId, const JSIID& iid,
  132. ReturnStatus* rs, bool* instanceof) = 0;
  133. virtual bool SendDOMInstanceOf(const ObjectId& objId, const int& prototypeID, const int& depth,
  134. ReturnStatus* rs, bool* instanceof) = 0;
  135. };
  136. } // namespace jsipc
  137. } // namespace mozilla
  138. #endif // mozilla_jsipc_WrapperOwner_h__