michael@0: /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ michael@0: /* vim: set ts=8 sts=4 et sw=4 tw=99: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef _xpc_WRAPPERFACTORY_H michael@0: #define _xpc_WRAPPERFACTORY_H michael@0: michael@0: #include "jswrapper.h" michael@0: michael@0: namespace xpc { michael@0: michael@0: class WrapperFactory { michael@0: public: michael@0: enum { WAIVE_XRAY_WRAPPER_FLAG = js::Wrapper::LAST_USED_FLAG << 1, michael@0: IS_XRAY_WRAPPER_FLAG = WAIVE_XRAY_WRAPPER_FLAG << 1 }; michael@0: michael@0: // Return true if any of any of the nested wrappers have the flag set. michael@0: static bool HasWrapperFlag(JSObject *wrapper, unsigned flag) { michael@0: unsigned flags = 0; michael@0: js::UncheckedUnwrap(wrapper, true, &flags); michael@0: return !!(flags & flag); michael@0: } michael@0: michael@0: static bool IsXrayWrapper(JSObject *wrapper) { michael@0: return HasWrapperFlag(wrapper, IS_XRAY_WRAPPER_FLAG); michael@0: } michael@0: michael@0: static bool HasWaiveXrayFlag(JSObject *wrapper) { michael@0: return HasWrapperFlag(wrapper, WAIVE_XRAY_WRAPPER_FLAG); michael@0: } michael@0: michael@0: static bool IsSecurityWrapper(JSObject *obj) { michael@0: return !js::CheckedUnwrap(obj); michael@0: } michael@0: michael@0: static bool IsCOW(JSObject *wrapper); michael@0: michael@0: static JSObject *GetXrayWaiver(JS::HandleObject obj); michael@0: static JSObject *CreateXrayWaiver(JSContext *cx, JS::HandleObject obj); michael@0: static JSObject *WaiveXray(JSContext *cx, JSObject *obj); michael@0: michael@0: static JSObject *DoubleWrap(JSContext *cx, JS::HandleObject obj, unsigned flags); michael@0: michael@0: // Prepare a given object for wrapping in a new compartment. michael@0: static JSObject *PrepareForWrapping(JSContext *cx, michael@0: JS::HandleObject scope, michael@0: JS::HandleObject obj, michael@0: unsigned flags); michael@0: michael@0: // Rewrap an object that is about to cross compartment boundaries. michael@0: static JSObject *Rewrap(JSContext *cx, michael@0: JS::HandleObject existing, michael@0: JS::HandleObject obj, michael@0: JS::HandleObject wrappedProto, michael@0: JS::HandleObject parent, michael@0: unsigned flags); michael@0: michael@0: // Wrap wrapped object into a waiver wrapper and then re-wrap it. michael@0: static bool WaiveXrayAndWrap(JSContext *cx, JS::MutableHandleValue vp); michael@0: static bool WaiveXrayAndWrap(JSContext *cx, JS::MutableHandleObject object); michael@0: michael@0: // Returns true if the wrapper is in not shadowing mode for the id. michael@0: static bool XrayWrapperNotShadowing(JSObject *wrapper, jsid id); michael@0: }; michael@0: michael@0: extern js::Wrapper XrayWaiver; michael@0: michael@0: } michael@0: michael@0: #endif /* _xpc_WRAPPERFACTORY_H */