1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- 2 * vim: set ts=8 sw=4 et tw=80: 3 * 4 * This Source Code Form is subject to the terms of the Mozilla Public 5 * License, v. 2.0. If a copy of the MPL was not distributed with this 6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 7 8 #ifndef mozilla_jsipc_CrossProcessObjectWrappers_h__ 9 #define mozilla_jsipc_CrossProcessObjectWrappers_h__ 10 11 #include "js/TypeDecls.h" 12 #include "mozilla/jsipc/CpowHolder.h" 13 #include "mozilla/jsipc/JavaScriptTypes.h" 14 #include "nsID.h" 15 #include "nsString.h" 16 #include "nsTArray.h" 17 18 #ifdef XP_WIN 19 #undef GetClassName 20 #undef GetClassInfo 21 #endif 22 23 namespace mozilla { 24 25 namespace dom { 26 class CPOWManagerGetter; 27 } // namespace dom 28 29 namespace jsipc { 30 31 class PJavaScriptParent; 32 class PJavaScriptChild; 33 34 class CPOWManager 35 { 36 public: 37 virtual bool Unwrap(JSContext* cx, 38 const InfallibleTArray<CpowEntry>& aCpows, 39 JS::MutableHandleObject objp) = 0; 40 41 virtual bool Wrap(JSContext* cx, 42 JS::HandleObject aObj, 43 InfallibleTArray<CpowEntry>* outCpows) = 0; 44 }; 45 46 class CrossProcessCpowHolder : public CpowHolder 47 { 48 public: 49 CrossProcessCpowHolder(dom::CPOWManagerGetter* managerGetter, 50 const InfallibleTArray<CpowEntry>& cpows); 51 52 ~CrossProcessCpowHolder(); 53 54 bool ToObject(JSContext* cx, JS::MutableHandleObject objp); 55 56 private: 57 CPOWManager* js_; 58 const InfallibleTArray<CpowEntry>& cpows_; 59 bool unwrapped_; 60 }; 61 62 CPOWManager* 63 CPOWManagerFor(PJavaScriptParent* aParent); 64 65 CPOWManager* 66 CPOWManagerFor(PJavaScriptChild* aChild); 67 68 bool 69 IsCPOW(JSObject* obj); 70 71 bool 72 IsWrappedCPOW(JSObject* obj); 73 74 nsresult 75 InstanceOf(JSObject* obj, const nsID* id, bool* bp); 76 77 bool 78 DOMInstanceOf(JSContext* cx, JSObject* obj, int prototypeID, int depth, bool* bp); 79 80 void 81 GetWrappedCPOWTag(JSObject* obj, nsACString& out); 82 83 PJavaScriptParent* 84 NewJavaScriptParent(); 85 86 void 87 ReleaseJavaScriptParent(PJavaScriptParent* parent); 88 89 PJavaScriptChild* 90 NewJavaScriptChild(); 91 92 void 93 ReleaseJavaScriptChild(PJavaScriptChild* child); 94 95 void 96 AfterProcessTask(); 97 98 } // namespace jsipc 99 } // namespace mozilla 100 101 #endif // mozilla_jsipc_CrossProcessObjectWrappers_h__ 102