/src/mozilla-central/js/xpconnect/wrappers/WrapperFactory.h
Line | Count | Source (jump to first uncovered line) |
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 "js/Wrapper.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 | 0 | static bool HasWrapperFlag(JSObject* wrapper, unsigned flag) { |
21 | 0 | unsigned flags = 0; |
22 | 0 | js::UncheckedUnwrap(wrapper, true, &flags); |
23 | 0 | return !!(flags & flag); |
24 | 0 | } |
25 | | |
26 | 0 | static bool IsXrayWrapper(JSObject* wrapper) { |
27 | 0 | return HasWrapperFlag(wrapper, IS_XRAY_WRAPPER_FLAG); |
28 | 0 | } |
29 | | |
30 | 0 | static bool HasWaiveXrayFlag(JSObject* wrapper) { |
31 | 0 | return HasWrapperFlag(wrapper, WAIVE_XRAY_WRAPPER_FLAG); |
32 | 0 | } |
33 | | |
34 | | static bool IsCOW(JSObject* wrapper); |
35 | | |
36 | | static JSObject* GetXrayWaiver(JS::HandleObject obj); |
37 | | static JSObject* CreateXrayWaiver(JSContext* cx, JS::HandleObject obj); |
38 | | static JSObject* WaiveXray(JSContext* cx, JSObject* obj); |
39 | | |
40 | | // Computes whether we should allow the creation of an Xray waiver from |
41 | | // |target| to |origin|. |
42 | | static bool AllowWaiver(JS::Compartment* target, JS::Compartment* origin); |
43 | | |
44 | | // Convenience method for the above, operating on a wrapper. |
45 | | static bool AllowWaiver(JSObject* wrapper); |
46 | | |
47 | | // Prepare a given object for wrapping in a new compartment. |
48 | | static void PrepareForWrapping(JSContext* cx, |
49 | | JS::HandleObject scope, |
50 | | JS::HandleObject obj, |
51 | | JS::HandleObject objectPassedToWrap, |
52 | | JS::MutableHandleObject retObj); |
53 | | |
54 | | // Rewrap an object that is about to cross compartment boundaries. |
55 | | static JSObject* Rewrap(JSContext* cx, |
56 | | JS::HandleObject existing, |
57 | | JS::HandleObject obj); |
58 | | |
59 | | // Wrap wrapped object into a waiver wrapper and then re-wrap it. |
60 | | static bool WaiveXrayAndWrap(JSContext* cx, JS::MutableHandleValue vp); |
61 | | static bool WaiveXrayAndWrap(JSContext* cx, JS::MutableHandleObject object); |
62 | | }; |
63 | | |
64 | | extern const js::Wrapper XrayWaiver; |
65 | | |
66 | | } // namespace xpc |
67 | | |
68 | | #endif /* _xpc_WRAPPERFACTORY_H */ |