Bug 1700051: part 32) Move `InvalidateWords` to `SoftText`. r=smaug
[gecko.git] / js / xpconnect / wrappers / AccessCheck.h
blobc42e56ea02878b3670620c1210a6434f707c0cf9
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
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/. */
7 #ifndef __AccessCheck_h__
8 #define __AccessCheck_h__
10 #include "js/Id.h"
11 #include "js/Wrapper.h"
12 #include "nsString.h"
14 #ifdef XP_MACOSX
15 // AssertMacros.h defines 'check' which conflicts with the method declarations
16 // in this file.
17 # undef check
18 #endif
20 namespace xpc {
22 class AccessCheck {
23 public:
24 static bool subsumes(JSObject* a, JSObject* b);
25 static bool wrapperSubsumes(JSObject* wrapper);
26 static bool subsumesConsideringDomain(JS::Realm* a, JS::Realm* b);
27 static bool subsumesConsideringDomainIgnoringFPD(JS::Realm* a, JS::Realm* b);
28 static bool isChrome(JS::Compartment* compartment);
29 static bool isChrome(JS::Realm* realm);
30 static bool isChrome(JSObject* obj);
31 static bool checkPassToPrivilegedCode(JSContext* cx, JS::HandleObject wrapper,
32 JS::HandleValue value);
33 static bool checkPassToPrivilegedCode(JSContext* cx, JS::HandleObject wrapper,
34 const JS::CallArgs& args);
35 // Called to report the correct sort of exception when our policy denies and
36 // should throw. The accessType argument should be one of "access",
37 // "define", "delete", depending on which operation is being denied.
38 static void reportCrossOriginDenial(JSContext* cx, JS::HandleId id,
39 const nsACString& accessType);
42 /**
43 * Returns true if the given object (which is expected to be stripped of
44 * cross-compartment wrappers in practice, but this function doesn't assume
45 * that) is a WindowProxy or Location object, which need special wrapping
46 * behavior due to being usable cross-origin in limited ways.
48 bool IsCrossOriginAccessibleObject(JSObject* obj);
50 struct Policy {
51 static bool checkCall(JSContext* cx, JS::HandleObject wrapper,
52 const JS::CallArgs& args) {
53 MOZ_CRASH("As a rule, filtering wrappers are non-callable");
57 // This policy allows no interaction with the underlying callable. Everything
58 // throws.
59 struct Opaque : public Policy {
60 static bool check(JSContext* cx, JSObject* wrapper, jsid id,
61 js::Wrapper::Action act) {
62 return false;
64 static bool deny(JSContext* cx, js::Wrapper::Action act, JS::HandleId id,
65 bool mayThrow) {
66 return false;
68 static bool allowNativeCall(JSContext* cx, JS::IsAcceptableThis test,
69 JS::NativeImpl impl) {
70 return false;
74 // Like the above, but allows CALL.
75 struct OpaqueWithCall : public Policy {
76 static bool check(JSContext* cx, JSObject* wrapper, jsid id,
77 js::Wrapper::Action act) {
78 return act == js::Wrapper::CALL;
80 static bool deny(JSContext* cx, js::Wrapper::Action act, JS::HandleId id,
81 bool mayThrow) {
82 return false;
84 static bool allowNativeCall(JSContext* cx, JS::IsAcceptableThis test,
85 JS::NativeImpl impl) {
86 return false;
88 static bool checkCall(JSContext* cx, JS::HandleObject wrapper,
89 const JS::CallArgs& args) {
90 return AccessCheck::checkPassToPrivilegedCode(cx, wrapper, args);
94 // This class used to support permitting access to properties if they
95 // appeared in an access list on the object, but now it acts like an
96 // Opaque wrapper, with the exception that it fails silently for GET,
97 // ENUMERATE, and GET_PROPERTY_DESCRIPTOR. This is done for backwards
98 // compatibility. See bug 1397513.
99 struct OpaqueWithSilentFailing : public Policy {
100 static bool check(JSContext* cx, JS::HandleObject wrapper, JS::HandleId id,
101 js::Wrapper::Action act) {
102 return false;
105 static bool deny(JSContext* cx, js::Wrapper::Action act, JS::HandleId id,
106 bool mayThrow);
107 static bool allowNativeCall(JSContext* cx, JS::IsAcceptableThis test,
108 JS::NativeImpl impl) {
109 return false;
113 } // namespace xpc
115 #endif /* __AccessCheck_h__ */