1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 : * vim: set ts=4 sw=4 et tw=99 ft=cpp:
3 : *
4 : * ***** BEGIN LICENSE BLOCK *****
5 : * Version: MPL 1.1/GPL 2.0/LGPL 2.1
6 : *
7 : * The contents of this file are subject to the Mozilla Public License Version
8 : * 1.1 (the "License"); you may not use this file except in compliance with
9 : * the License. You may obtain a copy of the License at
10 : * http://www.mozilla.org/MPL/
11 : *
12 : * Software distributed under the License is distributed on an "AS IS" basis,
13 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
14 : * for the specific language governing rights and limitations under the
15 : * License.
16 : *
17 : * The Original Code is mozilla.org code, released
18 : * June 24, 2010.
19 : *
20 : * The Initial Developer of the Original Code is
21 : * The Mozilla Foundation
22 : *
23 : * Contributor(s):
24 : * Andreas Gal <gal@mozilla.com>
25 : *
26 : * Alternatively, the contents of this file may be used under the terms of
27 : * either of the GNU General Public License Version 2 or later (the "GPL"),
28 : * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29 : * in which case the provisions of the GPL or the LGPL are applicable instead
30 : * of those above. If you wish to allow use of your version of this file only
31 : * under the terms of either the GPL or the LGPL, and not to allow others to
32 : * use your version of this file under the terms of the MPL, indicate your
33 : * decision by deleting the provisions above and replace them with the notice
34 : * and other provisions required by the GPL or the LGPL. If you do not delete
35 : * the provisions above, a recipient may use your version of this file under
36 : * the terms of any one of the MPL, the GPL or the LGPL.
37 : *
38 : * ***** END LICENSE BLOCK ***** */
39 :
40 : #include "jsapi.h"
41 : #include "jswrapper.h"
42 :
43 : namespace xpc {
44 :
45 : class WrapperFactory {
46 : public:
47 : enum { WAIVE_XRAY_WRAPPER_FLAG = js::Wrapper::LAST_USED_FLAG << 1,
48 : IS_XRAY_WRAPPER_FLAG = WAIVE_XRAY_WRAPPER_FLAG << 1,
49 : SCRIPT_ACCESS_ONLY_FLAG = IS_XRAY_WRAPPER_FLAG << 1,
50 : PARTIALLY_TRANSPARENT = SCRIPT_ACCESS_ONLY_FLAG << 1,
51 : SOW_FLAG = PARTIALLY_TRANSPARENT << 1,
52 :
53 : // Prevent scripts from shadowing native properties.
54 : // NB: Applies only to Xray wrappers.
55 : // NB: This will prevent scriptable helpers from defining special
56 : // handlers for properties defined in IDL. Use with caution.
57 : SHADOWING_FORBIDDEN = SOW_FLAG << 1 };
58 :
59 : // Return true if any of any of the nested wrappers have the flag set.
60 1840428 : static bool HasWrapperFlag(JSObject *wrapper, unsigned flag) {
61 1840428 : unsigned flags = 0;
62 1840428 : js::UnwrapObject(wrapper, true, &flags);
63 1840428 : return !!(flags & flag);
64 : }
65 :
66 1840428 : static bool IsXrayWrapper(JSObject *wrapper) {
67 1840428 : return HasWrapperFlag(wrapper, IS_XRAY_WRAPPER_FLAG);
68 : }
69 :
70 0 : static bool IsPartiallyTransparent(JSObject *wrapper) {
71 0 : return HasWrapperFlag(wrapper, PARTIALLY_TRANSPARENT);
72 : }
73 :
74 0 : static bool HasWaiveXrayFlag(JSObject *wrapper) {
75 0 : return HasWrapperFlag(wrapper, WAIVE_XRAY_WRAPPER_FLAG);
76 : }
77 :
78 0 : static bool IsShadowingForbidden(JSObject *wrapper) {
79 0 : return HasWrapperFlag(wrapper, SHADOWING_FORBIDDEN);
80 : }
81 :
82 : static JSObject *WaiveXray(JSContext *cx, JSObject *obj);
83 :
84 : static JSObject *DoubleWrap(JSContext *cx, JSObject *obj, unsigned flags);
85 :
86 : // Prepare a given object for wrapping in a new compartment.
87 : static JSObject *PrepareForWrapping(JSContext *cx,
88 : JSObject *scope,
89 : JSObject *obj,
90 : unsigned flags);
91 :
92 : // Rewrap an object that is about to cross compartment boundaries.
93 : static JSObject *Rewrap(JSContext *cx,
94 : JSObject *obj,
95 : JSObject *wrappedProto,
96 : JSObject *parent,
97 : unsigned flags);
98 :
99 : // Return true if this is a location object.
100 : static bool IsLocationObject(JSObject *obj);
101 :
102 : // Wrap a location object.
103 : static JSObject *WrapLocationObject(JSContext *cx, JSObject *obj);
104 :
105 : // Wrap wrapped object into a waiver wrapper and then re-wrap it.
106 : static bool WaiveXrayAndWrap(JSContext *cx, jsval *vp);
107 :
108 : // Wrap a (same compartment) object in a SOW.
109 : static JSObject *WrapSOWObject(JSContext *cx, JSObject *obj);
110 : };
111 :
112 : extern js::Wrapper WaiveXrayWrapperWrapper;
113 :
114 : }
|