1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/xpconnect/wrappers/WrapperFactory.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,72 @@ 1.4 +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 1.5 +/* vim: set ts=8 sts=4 et sw=4 tw=99: */ 1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 + 1.10 +#ifndef _xpc_WRAPPERFACTORY_H 1.11 +#define _xpc_WRAPPERFACTORY_H 1.12 + 1.13 +#include "jswrapper.h" 1.14 + 1.15 +namespace xpc { 1.16 + 1.17 +class WrapperFactory { 1.18 + public: 1.19 + enum { WAIVE_XRAY_WRAPPER_FLAG = js::Wrapper::LAST_USED_FLAG << 1, 1.20 + IS_XRAY_WRAPPER_FLAG = WAIVE_XRAY_WRAPPER_FLAG << 1 }; 1.21 + 1.22 + // Return true if any of any of the nested wrappers have the flag set. 1.23 + static bool HasWrapperFlag(JSObject *wrapper, unsigned flag) { 1.24 + unsigned flags = 0; 1.25 + js::UncheckedUnwrap(wrapper, true, &flags); 1.26 + return !!(flags & flag); 1.27 + } 1.28 + 1.29 + static bool IsXrayWrapper(JSObject *wrapper) { 1.30 + return HasWrapperFlag(wrapper, IS_XRAY_WRAPPER_FLAG); 1.31 + } 1.32 + 1.33 + static bool HasWaiveXrayFlag(JSObject *wrapper) { 1.34 + return HasWrapperFlag(wrapper, WAIVE_XRAY_WRAPPER_FLAG); 1.35 + } 1.36 + 1.37 + static bool IsSecurityWrapper(JSObject *obj) { 1.38 + return !js::CheckedUnwrap(obj); 1.39 + } 1.40 + 1.41 + static bool IsCOW(JSObject *wrapper); 1.42 + 1.43 + static JSObject *GetXrayWaiver(JS::HandleObject obj); 1.44 + static JSObject *CreateXrayWaiver(JSContext *cx, JS::HandleObject obj); 1.45 + static JSObject *WaiveXray(JSContext *cx, JSObject *obj); 1.46 + 1.47 + static JSObject *DoubleWrap(JSContext *cx, JS::HandleObject obj, unsigned flags); 1.48 + 1.49 + // Prepare a given object for wrapping in a new compartment. 1.50 + static JSObject *PrepareForWrapping(JSContext *cx, 1.51 + JS::HandleObject scope, 1.52 + JS::HandleObject obj, 1.53 + unsigned flags); 1.54 + 1.55 + // Rewrap an object that is about to cross compartment boundaries. 1.56 + static JSObject *Rewrap(JSContext *cx, 1.57 + JS::HandleObject existing, 1.58 + JS::HandleObject obj, 1.59 + JS::HandleObject wrappedProto, 1.60 + JS::HandleObject parent, 1.61 + unsigned flags); 1.62 + 1.63 + // Wrap wrapped object into a waiver wrapper and then re-wrap it. 1.64 + static bool WaiveXrayAndWrap(JSContext *cx, JS::MutableHandleValue vp); 1.65 + static bool WaiveXrayAndWrap(JSContext *cx, JS::MutableHandleObject object); 1.66 + 1.67 + // Returns true if the wrapper is in not shadowing mode for the id. 1.68 + static bool XrayWrapperNotShadowing(JSObject *wrapper, jsid id); 1.69 +}; 1.70 + 1.71 +extern js::Wrapper XrayWaiver; 1.72 + 1.73 +} 1.74 + 1.75 +#endif /* _xpc_WRAPPERFACTORY_H */