js/xpconnect/wrappers/XrayWrapper.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
michael@0 2 /* vim: set ts=8 sts=4 et sw=4 tw=99: */
michael@0 3 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 4 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 6
michael@0 7 #ifndef XrayWrapper_h
michael@0 8 #define XrayWrapper_h
michael@0 9
michael@0 10 #include "mozilla/Attributes.h"
michael@0 11
michael@0 12 #include "jswrapper.h"
michael@0 13
michael@0 14 // Xray wrappers re-resolve the original native properties on the native
michael@0 15 // object and always directly access to those properties.
michael@0 16 // Because they work so differently from the rest of the wrapper hierarchy,
michael@0 17 // we pull them out of the Wrapper inheritance hierarchy and create a
michael@0 18 // little world around them.
michael@0 19
michael@0 20 namespace xpc {
michael@0 21
michael@0 22 bool
michael@0 23 holder_get(JSContext *cx, JS::HandleObject holder, JS::HandleId id, JS::MutableHandleValue vp);
michael@0 24 bool
michael@0 25 holder_set(JSContext *cx, JS::HandleObject holder, JS::HandleId id, bool strict,
michael@0 26 JS::MutableHandleValue vp);
michael@0 27
michael@0 28 namespace XrayUtils {
michael@0 29
michael@0 30 bool IsXPCWNHolderClass(const JSClass *clasp);
michael@0 31
michael@0 32 bool CloneExpandoChain(JSContext *cx, JSObject *src, JSObject *dst);
michael@0 33
michael@0 34 bool
michael@0 35 IsTransparent(JSContext *cx, JS::HandleObject wrapper, JS::HandleId id);
michael@0 36
michael@0 37 JSObject *
michael@0 38 GetNativePropertiesObject(JSContext *cx, JSObject *wrapper);
michael@0 39
michael@0 40 bool
michael@0 41 IsXrayResolving(JSContext *cx, JS::HandleObject wrapper, JS::HandleId id);
michael@0 42
michael@0 43 bool
michael@0 44 HasNativeProperty(JSContext *cx, JS::HandleObject wrapper, JS::HandleId id,
michael@0 45 bool *hasProp);
michael@0 46 }
michael@0 47
michael@0 48 class XrayTraits;
michael@0 49 class XPCWrappedNativeXrayTraits;
michael@0 50 class DOMXrayTraits;
michael@0 51 class JSXrayTraits;
michael@0 52
michael@0 53
michael@0 54 enum XrayType {
michael@0 55 XrayForDOMObject,
michael@0 56 XrayForWrappedNative,
michael@0 57 XrayForJSObject,
michael@0 58 NotXray
michael@0 59 };
michael@0 60
michael@0 61 XrayType GetXrayType(JSObject *obj);
michael@0 62 XrayTraits* GetXrayTraits(JSObject *obj);
michael@0 63
michael@0 64 // NB: Base *must* derive from JSProxyHandler
michael@0 65 template <typename Base, typename Traits = XPCWrappedNativeXrayTraits >
michael@0 66 class XrayWrapper : public Base {
michael@0 67 public:
michael@0 68 XrayWrapper(unsigned flags);
michael@0 69 virtual ~XrayWrapper();
michael@0 70
michael@0 71 /* Fundamental proxy traps. */
michael@0 72 virtual bool isExtensible(JSContext *cx, JS::Handle<JSObject*> wrapper, bool *extensible) MOZ_OVERRIDE;
michael@0 73 virtual bool preventExtensions(JSContext *cx, JS::Handle<JSObject*> wrapper) MOZ_OVERRIDE;
michael@0 74 virtual bool getPropertyDescriptor(JSContext *cx, JS::Handle<JSObject*> wrapper, JS::Handle<jsid> id,
michael@0 75 JS::MutableHandle<JSPropertyDescriptor> desc);
michael@0 76 virtual bool getOwnPropertyDescriptor(JSContext *cx, JS::Handle<JSObject*> wrapper, JS::Handle<jsid> id,
michael@0 77 JS::MutableHandle<JSPropertyDescriptor> desc);
michael@0 78 virtual bool defineProperty(JSContext *cx, JS::Handle<JSObject*> wrapper, JS::Handle<jsid> id,
michael@0 79 JS::MutableHandle<JSPropertyDescriptor> desc);
michael@0 80 virtual bool getOwnPropertyNames(JSContext *cx, JS::Handle<JSObject*> wrapper,
michael@0 81 JS::AutoIdVector &props);
michael@0 82 virtual bool delete_(JSContext *cx, JS::Handle<JSObject*> wrapper,
michael@0 83 JS::Handle<jsid> id, bool *bp);
michael@0 84 virtual bool enumerate(JSContext *cx, JS::Handle<JSObject*> wrapper, JS::AutoIdVector &props);
michael@0 85
michael@0 86 /* Derived proxy traps. */
michael@0 87 virtual bool get(JSContext *cx, JS::Handle<JSObject*> wrapper, JS::Handle<JSObject*> receiver,
michael@0 88 JS::Handle<jsid> id, JS::MutableHandle<JS::Value> vp);
michael@0 89 virtual bool set(JSContext *cx, JS::Handle<JSObject*> wrapper, JS::Handle<JSObject*> receiver,
michael@0 90 JS::Handle<jsid> id, bool strict, JS::MutableHandle<JS::Value> vp);
michael@0 91 virtual bool has(JSContext *cx, JS::Handle<JSObject*> wrapper, JS::Handle<jsid> id,
michael@0 92 bool *bp);
michael@0 93 virtual bool hasOwn(JSContext *cx, JS::Handle<JSObject*> wrapper, JS::Handle<jsid> id,
michael@0 94 bool *bp);
michael@0 95 virtual bool keys(JSContext *cx, JS::Handle<JSObject*> wrapper,
michael@0 96 JS::AutoIdVector &props);
michael@0 97 virtual bool iterate(JSContext *cx, JS::Handle<JSObject*> wrapper, unsigned flags,
michael@0 98 JS::MutableHandle<JS::Value> vp);
michael@0 99
michael@0 100 virtual bool call(JSContext *cx, JS::Handle<JSObject*> wrapper,
michael@0 101 const JS::CallArgs &args) MOZ_OVERRIDE;
michael@0 102 virtual bool construct(JSContext *cx, JS::Handle<JSObject*> wrapper,
michael@0 103 const JS::CallArgs &args) MOZ_OVERRIDE;
michael@0 104
michael@0 105 virtual bool defaultValue(JSContext *cx, JS::HandleObject wrapper,
michael@0 106 JSType hint, JS::MutableHandleValue vp)
michael@0 107 MOZ_OVERRIDE;
michael@0 108
michael@0 109 virtual bool getPrototypeOf(JSContext *cx, JS::HandleObject wrapper,
michael@0 110 JS::MutableHandleObject protop) MOZ_OVERRIDE;
michael@0 111 virtual bool setPrototypeOf(JSContext *cx, JS::HandleObject wrapper,
michael@0 112 JS::HandleObject proto, bool *bp) MOZ_OVERRIDE;
michael@0 113
michael@0 114 static XrayWrapper singleton;
michael@0 115
michael@0 116 private:
michael@0 117 template <bool HasPrototype>
michael@0 118 typename mozilla::EnableIf<HasPrototype, bool>::Type
michael@0 119 getPrototypeOfHelper(JSContext *cx, JS::HandleObject wrapper,
michael@0 120 JS::HandleObject target, JS::MutableHandleObject protop)
michael@0 121 {
michael@0 122 return Traits::singleton.getPrototypeOf(cx, wrapper, target, protop);
michael@0 123 }
michael@0 124 template <bool HasPrototype>
michael@0 125 typename mozilla::EnableIf<!HasPrototype, bool>::Type
michael@0 126 getPrototypeOfHelper(JSContext *cx, JS::HandleObject wrapper,
michael@0 127 JS::HandleObject target, JS::MutableHandleObject protop)
michael@0 128 {
michael@0 129 return Base::getPrototypeOf(cx, wrapper, protop);
michael@0 130 }
michael@0 131 bool getPrototypeOfHelper(JSContext *cx, JS::HandleObject wrapper,
michael@0 132 JS::HandleObject target, JS::MutableHandleObject protop)
michael@0 133 {
michael@0 134 return getPrototypeOfHelper<Traits::HasPrototype>(cx, wrapper, target,
michael@0 135 protop);
michael@0 136 }
michael@0 137
michael@0 138 bool enumerate(JSContext *cx, JS::Handle<JSObject*> wrapper, unsigned flags,
michael@0 139 JS::AutoIdVector &props);
michael@0 140 };
michael@0 141
michael@0 142 #define PermissiveXrayXPCWN xpc::XrayWrapper<js::CrossCompartmentWrapper, xpc::XPCWrappedNativeXrayTraits>
michael@0 143 #define SecurityXrayXPCWN xpc::XrayWrapper<js::CrossCompartmentSecurityWrapper, xpc::XPCWrappedNativeXrayTraits>
michael@0 144 #define PermissiveXrayDOM xpc::XrayWrapper<js::CrossCompartmentWrapper, xpc::DOMXrayTraits>
michael@0 145 #define SecurityXrayDOM xpc::XrayWrapper<js::CrossCompartmentSecurityWrapper, xpc::DOMXrayTraits>
michael@0 146 #define PermissiveXrayJS xpc::XrayWrapper<js::CrossCompartmentWrapper, xpc::JSXrayTraits>
michael@0 147 #define SCSecurityXrayXPCWN xpc::XrayWrapper<js::SameCompartmentSecurityWrapper, xpc::XPCWrappedNativeXrayTraits>
michael@0 148
michael@0 149 class SandboxProxyHandler : public js::Wrapper {
michael@0 150 public:
michael@0 151 SandboxProxyHandler() : js::Wrapper(0)
michael@0 152 {
michael@0 153 }
michael@0 154
michael@0 155 virtual bool getPropertyDescriptor(JSContext *cx, JS::Handle<JSObject*> proxy,
michael@0 156 JS::Handle<jsid> id,
michael@0 157 JS::MutableHandle<JSPropertyDescriptor> desc) MOZ_OVERRIDE;
michael@0 158 virtual bool getOwnPropertyDescriptor(JSContext *cx, JS::Handle<JSObject*> proxy,
michael@0 159 JS::Handle<jsid> id,
michael@0 160 JS::MutableHandle<JSPropertyDescriptor> desc) MOZ_OVERRIDE;
michael@0 161
michael@0 162 // We just forward the derived traps to the BaseProxyHandler versions which
michael@0 163 // implement them in terms of the fundamental traps.
michael@0 164 virtual bool has(JSContext *cx, JS::Handle<JSObject*> proxy, JS::Handle<jsid> id,
michael@0 165 bool *bp) MOZ_OVERRIDE;
michael@0 166 virtual bool hasOwn(JSContext *cx, JS::Handle<JSObject*> proxy, JS::Handle<jsid> id,
michael@0 167 bool *bp) MOZ_OVERRIDE;
michael@0 168 virtual bool get(JSContext *cx, JS::Handle<JSObject*> proxy, JS::Handle<JSObject*> receiver,
michael@0 169 JS::Handle<jsid> id, JS::MutableHandle<JS::Value> vp) MOZ_OVERRIDE;
michael@0 170 virtual bool set(JSContext *cx, JS::Handle<JSObject*> proxy, JS::Handle<JSObject*> receiver,
michael@0 171 JS::Handle<jsid> id, bool strict, JS::MutableHandle<JS::Value> vp) MOZ_OVERRIDE;
michael@0 172 virtual bool keys(JSContext *cx, JS::Handle<JSObject*> proxy,
michael@0 173 JS::AutoIdVector &props) MOZ_OVERRIDE;
michael@0 174 virtual bool iterate(JSContext *cx, JS::Handle<JSObject*> proxy, unsigned flags,
michael@0 175 JS::MutableHandle<JS::Value> vp) MOZ_OVERRIDE;
michael@0 176 };
michael@0 177
michael@0 178 extern SandboxProxyHandler sandboxProxyHandler;
michael@0 179
michael@0 180 // A proxy handler that lets us wrap callables and invoke them with
michael@0 181 // the correct this object, while forwarding all other operations down
michael@0 182 // to them directly.
michael@0 183 class SandboxCallableProxyHandler : public js::Wrapper {
michael@0 184 public:
michael@0 185 SandboxCallableProxyHandler() : js::Wrapper(0)
michael@0 186 {
michael@0 187 }
michael@0 188
michael@0 189 virtual bool call(JSContext *cx, JS::Handle<JSObject*> proxy,
michael@0 190 const JS::CallArgs &args) MOZ_OVERRIDE;
michael@0 191 };
michael@0 192
michael@0 193 extern SandboxCallableProxyHandler sandboxCallableProxyHandler;
michael@0 194
michael@0 195 class AutoSetWrapperNotShadowing;
michael@0 196 class XPCWrappedNativeXrayTraits;
michael@0 197
michael@0 198 class MOZ_STACK_CLASS ResolvingId {
michael@0 199 public:
michael@0 200 ResolvingId(JSContext *cx, JS::HandleObject wrapper, JS::HandleId id);
michael@0 201 ~ResolvingId();
michael@0 202
michael@0 203 bool isXrayShadowing(jsid id);
michael@0 204 bool isResolving(jsid id);
michael@0 205 static ResolvingId* getResolvingId(JSObject *holder);
michael@0 206 static JSObject* getHolderObject(JSObject *wrapper);
michael@0 207 static ResolvingId *getResolvingIdFromWrapper(JSObject *wrapper);
michael@0 208
michael@0 209 private:
michael@0 210 friend class AutoSetWrapperNotShadowing;
michael@0 211 friend class XPCWrappedNativeXrayTraits;
michael@0 212
michael@0 213 JS::HandleId mId;
michael@0 214 JS::RootedObject mHolder;
michael@0 215 ResolvingId *mPrev;
michael@0 216 bool mXrayShadowing;
michael@0 217 };
michael@0 218
michael@0 219 }
michael@0 220
michael@0 221 #endif

mercurial