|
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
|
2 /* vim: set ts=8 sts=4 et sw=4 tw=99: */ |
|
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 |
|
7 #ifndef _xpc_WRAPPERFACTORY_H |
|
8 #define _xpc_WRAPPERFACTORY_H |
|
9 |
|
10 #include "jswrapper.h" |
|
11 |
|
12 namespace xpc { |
|
13 |
|
14 class WrapperFactory { |
|
15 public: |
|
16 enum { WAIVE_XRAY_WRAPPER_FLAG = js::Wrapper::LAST_USED_FLAG << 1, |
|
17 IS_XRAY_WRAPPER_FLAG = WAIVE_XRAY_WRAPPER_FLAG << 1 }; |
|
18 |
|
19 // Return true if any of any of the nested wrappers have the flag set. |
|
20 static bool HasWrapperFlag(JSObject *wrapper, unsigned flag) { |
|
21 unsigned flags = 0; |
|
22 js::UncheckedUnwrap(wrapper, true, &flags); |
|
23 return !!(flags & flag); |
|
24 } |
|
25 |
|
26 static bool IsXrayWrapper(JSObject *wrapper) { |
|
27 return HasWrapperFlag(wrapper, IS_XRAY_WRAPPER_FLAG); |
|
28 } |
|
29 |
|
30 static bool HasWaiveXrayFlag(JSObject *wrapper) { |
|
31 return HasWrapperFlag(wrapper, WAIVE_XRAY_WRAPPER_FLAG); |
|
32 } |
|
33 |
|
34 static bool IsSecurityWrapper(JSObject *obj) { |
|
35 return !js::CheckedUnwrap(obj); |
|
36 } |
|
37 |
|
38 static bool IsCOW(JSObject *wrapper); |
|
39 |
|
40 static JSObject *GetXrayWaiver(JS::HandleObject obj); |
|
41 static JSObject *CreateXrayWaiver(JSContext *cx, JS::HandleObject obj); |
|
42 static JSObject *WaiveXray(JSContext *cx, JSObject *obj); |
|
43 |
|
44 static JSObject *DoubleWrap(JSContext *cx, JS::HandleObject obj, unsigned flags); |
|
45 |
|
46 // Prepare a given object for wrapping in a new compartment. |
|
47 static JSObject *PrepareForWrapping(JSContext *cx, |
|
48 JS::HandleObject scope, |
|
49 JS::HandleObject obj, |
|
50 unsigned flags); |
|
51 |
|
52 // Rewrap an object that is about to cross compartment boundaries. |
|
53 static JSObject *Rewrap(JSContext *cx, |
|
54 JS::HandleObject existing, |
|
55 JS::HandleObject obj, |
|
56 JS::HandleObject wrappedProto, |
|
57 JS::HandleObject parent, |
|
58 unsigned flags); |
|
59 |
|
60 // Wrap wrapped object into a waiver wrapper and then re-wrap it. |
|
61 static bool WaiveXrayAndWrap(JSContext *cx, JS::MutableHandleValue vp); |
|
62 static bool WaiveXrayAndWrap(JSContext *cx, JS::MutableHandleObject object); |
|
63 |
|
64 // Returns true if the wrapper is in not shadowing mode for the id. |
|
65 static bool XrayWrapperNotShadowing(JSObject *wrapper, jsid id); |
|
66 }; |
|
67 |
|
68 extern js::Wrapper XrayWaiver; |
|
69 |
|
70 } |
|
71 |
|
72 #endif /* _xpc_WRAPPERFACTORY_H */ |