1 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* vim: set ts=2 sw=2 et tw=78: */
3 : /* ***** BEGIN LICENSE BLOCK *****
4 : * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 : *
6 : * The contents of this file are subject to the Mozilla Public License Version
7 : * 1.1 (the "License"); you may not use this file except in compliance with
8 : * the License. You may obtain a copy of the License at
9 : * http://www.mozilla.org/MPL/
10 : *
11 : * Software distributed under the License is distributed on an "AS IS" basis,
12 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 : * for the specific language governing rights and limitations under the
14 : * License.
15 : *
16 : * The Original Code is mozilla.org code.
17 : *
18 : * The Initial Developer of the Original Code is
19 : * The Mozilla Foundation.
20 : * Portions created by the Initial Developer are Copyright (C) 2005
21 : * the Initial Developer. All Rights Reserved.
22 : *
23 : * Contributor(s):
24 : * Johnny Stenback <jst@mozilla.org> (original author)
25 : * Brendan Eich <brendan@mozilla.org>
26 : * Boris Zbarsky <bzbarsky@mit.edu>
27 : * Blake Kaplan <mrbkap@gmail.com>
28 : *
29 : * Alternatively, the contents of this file may be used under the terms of
30 : * either the GNU General Public License Version 2 or later (the "GPL"), or
31 : * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
32 : * in which case the provisions of the GPL or the LGPL are applicable instead
33 : * of those above. If you wish to allow use of your version of this file only
34 : * under the terms of either the GPL or the LGPL, and not to allow others to
35 : * use your version of this file under the terms of the MPL, indicate your
36 : * decision by deleting the provisions above and replace them with the notice
37 : * and other provisions required by the GPL or the LGPL. If you do not delete
38 : * the provisions above, a recipient may use your version of this file under
39 : * the terms of any one of the MPL, the GPL or the LGPL.
40 : *
41 : * ***** END LICENSE BLOCK ***** */
42 :
43 : #ifndef XPC_WRAPPER_H
44 : #define XPC_WRAPPER_H 1
45 :
46 : #include "xpcprivate.h"
47 :
48 : namespace XPCNativeWrapper {
49 :
50 : // Given an XPCWrappedNative pointer and the name of the function on
51 : // XPCNativeScriptableFlags corresponding with a flag, returns 'true'
52 : // if the flag is set.
53 : // XXX Convert to using GetFlags() and not a macro.
54 : #define NATIVE_HAS_FLAG(_wn, _flag) \
55 : ((_wn)->GetScriptableInfo() && \
56 : (_wn)->GetScriptableInfo()->GetFlags()._flag())
57 :
58 : bool
59 : AttachNewConstructorObject(XPCCallContext &ccx, JSObject *aGlobalObject);
60 :
61 : } // namespace XPCNativeWrapper
62 :
63 : // This namespace wraps some common functionality between the three existing
64 : // wrappers. Its main purpose is to allow XPCCrossOriginWrapper to act both
65 : // as an XPCSafeJSObjectWrapper and as an XPCNativeWrapper when required to
66 : // do so (the decision is based on the principals of the wrapper and wrapped
67 : // objects).
68 : namespace XPCWrapper {
69 :
70 : /**
71 : * Returns the script security manager used by XPConnect.
72 : */
73 : inline nsIScriptSecurityManager *
74 1662851 : GetSecurityManager()
75 : {
76 1662851 : return nsXPConnect::gScriptSecurityManager;
77 : }
78 :
79 : inline JSBool
80 1195369 : IsSecurityWrapper(JSObject *wrapper)
81 : {
82 1195369 : return js::IsWrapper(wrapper);
83 : }
84 :
85 : /**
86 : * Given an arbitrary object, Unwrap will return the wrapped object if the
87 : * passed-in object is a wrapper that Unwrap knows about *and* the
88 : * currently running code has permission to access both the wrapper and
89 : * wrapped object.
90 : *
91 : * Since this is meant to be called from functions like
92 : * XPCWrappedNative::GetWrappedNativeOfJSObject, it does not set an
93 : * exception on |cx|.
94 : */
95 : JSObject *
96 : Unwrap(JSContext *cx, JSObject *wrapper, bool stopAtOuter = true);
97 :
98 : JSObject *
99 : UnsafeUnwrapSecurityWrapper(JSObject *obj);
100 :
101 : } // namespace XPCWrapper
102 :
103 :
104 : #endif
|