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 "nsJSPrincipals.h"
41 :
42 : #include "XPCWrapper.h"
43 :
44 : #include "CrossOriginWrapper.h"
45 : #include "AccessCheck.h"
46 : #include "WrapperFactory.h"
47 :
48 : namespace xpc {
49 :
50 2928 : NoWaiverWrapper::NoWaiverWrapper(unsigned flags) : js::CrossCompartmentWrapper(flags)
51 : {
52 2928 : }
53 :
54 2974 : NoWaiverWrapper::~NoWaiverWrapper()
55 : {
56 5948 : }
57 :
58 1464 : CrossOriginWrapper::CrossOriginWrapper(unsigned flags) : NoWaiverWrapper(flags)
59 : {
60 1464 : }
61 :
62 1487 : CrossOriginWrapper::~CrossOriginWrapper()
63 : {
64 2974 : }
65 :
66 : bool
67 0 : CrossOriginWrapper::getPropertyDescriptor(JSContext *cx, JSObject *wrapper, jsid id,
68 : bool set, js::PropertyDescriptor *desc)
69 : {
70 0 : return CrossCompartmentWrapper::getPropertyDescriptor(cx, wrapper, id, set, desc) &&
71 0 : WrapperFactory::WaiveXrayAndWrap(cx, &desc->value);
72 : }
73 :
74 : bool
75 0 : CrossOriginWrapper::getOwnPropertyDescriptor(JSContext *cx, JSObject *wrapper, jsid id,
76 : bool set, js::PropertyDescriptor *desc)
77 : {
78 0 : return CrossCompartmentWrapper::getOwnPropertyDescriptor(cx, wrapper, id, set, desc) &&
79 0 : WrapperFactory::WaiveXrayAndWrap(cx, &desc->value);
80 : }
81 :
82 : bool
83 0 : CrossOriginWrapper::get(JSContext *cx, JSObject *wrapper, JSObject *receiver, jsid id,
84 : js::Value *vp)
85 : {
86 0 : return CrossCompartmentWrapper::get(cx, wrapper, receiver, id, vp) &&
87 0 : WrapperFactory::WaiveXrayAndWrap(cx, vp);
88 : }
89 :
90 : bool
91 0 : CrossOriginWrapper::call(JSContext *cx, JSObject *wrapper, unsigned argc, js::Value *vp)
92 : {
93 0 : return CrossCompartmentWrapper::call(cx, wrapper, argc, vp) &&
94 0 : WrapperFactory::WaiveXrayAndWrap(cx, vp);
95 : }
96 :
97 : bool
98 0 : CrossOriginWrapper::construct(JSContext *cx, JSObject *wrapper,
99 : unsigned argc, js::Value *argv, js::Value *rval)
100 : {
101 0 : return CrossCompartmentWrapper::construct(cx, wrapper, argc, argv, rval) &&
102 0 : WrapperFactory::WaiveXrayAndWrap(cx, rval);
103 : }
104 :
105 : bool
106 345 : NoWaiverWrapper::enter(JSContext *cx, JSObject *wrapper, jsid id, Action act, bool *bp)
107 : {
108 345 : *bp = true; // always allowed
109 345 : nsIScriptSecurityManager *ssm = XPCWrapper::GetSecurityManager();
110 345 : if (!ssm) {
111 0 : return true;
112 : }
113 :
114 : // Note: By the time enter is called here, CrossCompartmentWrapper has
115 : // already pushed the fake stack frame onto cx. Because of this, the frame
116 : // that we're clamping is the one that we want (the one in our compartment).
117 345 : JSStackFrame *fp = NULL;
118 345 : nsIPrincipal *principal = GetCompartmentPrincipal(js::GetObjectCompartment(wrappedObject(wrapper)));
119 345 : nsresult rv = ssm->PushContextPrincipal(cx, JS_FrameIterator(cx, &fp), principal);
120 345 : if (NS_FAILED(rv)) {
121 0 : NS_WARNING("Not allowing call because we're out of memory");
122 0 : JS_ReportOutOfMemory(cx);
123 0 : return false;
124 : }
125 345 : return true;
126 : }
127 :
128 : void
129 345 : NoWaiverWrapper::leave(JSContext *cx, JSObject *wrapper)
130 : {
131 345 : nsIScriptSecurityManager *ssm = XPCWrapper::GetSecurityManager();
132 345 : if (ssm) {
133 345 : ssm->PopContextPrincipal(cx);
134 : }
135 345 : }
136 :
137 : }
|