Bumping manifests a=b2g-bump
[gecko.git] / caps / nsIPrincipal.idl
blob4f1476e85af534b71090da0400e3e948eec7f0f1
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 /* Defines the abstract interface for a principal. */
8 #include "nsISerializable.idl"
10 %{C++
11 struct JSPrincipals;
12 #include "nsCOMPtr.h"
13 #include "nsTArray.h"
16 interface nsIURI;
17 interface nsIContentSecurityPolicy;
19 [ptr] native JSContext(JSContext);
20 [ptr] native JSPrincipals(JSPrincipals);
21 [ptr] native PrincipalArray(nsTArray<nsCOMPtr<nsIPrincipal> >);
23 [scriptable, builtinclass, uuid(204555e7-04ad-4cc8-9f0e-840615cc43e8)]
24 interface nsIPrincipal : nsISerializable
26 /**
27 * Returns whether the other principal is equivalent to this principal.
28 * Principals are considered equal if they are the same principal, or
29 * they have the same origin.
31 boolean equals(in nsIPrincipal other);
33 /**
34 * Like equals, but takes document.domain changes into account.
36 boolean equalsConsideringDomain(in nsIPrincipal other);
38 %{C++
39 inline bool Equals(nsIPrincipal* aOther) {
40 bool equal = false;
41 return NS_SUCCEEDED(Equals(aOther, &equal)) && equal;
44 inline bool EqualsConsideringDomain(nsIPrincipal* aOther) {
45 bool equal = false;
46 return NS_SUCCEEDED(EqualsConsideringDomain(aOther, &equal)) && equal;
50 /**
51 * Returns a hash value for the principal.
53 [noscript] readonly attribute unsigned long hashValue;
55 /**
56 * The codebase URI to which this principal pertains. This is
57 * generally the document URI.
59 readonly attribute nsIURI URI;
61 /**
62 * The domain URI to which this principal pertains.
63 * This is congruent with HTMLDocument.domain, and may be null.
64 * Setting this has no effect on the URI.
66 [noscript] attribute nsIURI domain;
68 /**
69 * The origin of this principal's codebase URI.
70 * An origin is defined as: scheme + host + port.
72 // XXXcaa this should probably be turned into an nsIURI.
73 // The system principal's origin should be some caps namespace
74 // with a chrome URI. All of chrome should probably be the same.
75 readonly attribute string origin;
77 /**
78 * Returns whether the other principal is equal to or weaker than this
79 * principal. Principals are equal if they are the same object or they
80 * have the same origin.
82 * Thus a principal always subsumes itself.
84 * The system principal subsumes itself and all other principals.
86 * A null principal (corresponding to an unknown, hence assumed minimally
87 * privileged, security context) is not equal to any other principal
88 * (including other null principals), and therefore does not subsume
89 * anything but itself.
91 boolean subsumes(in nsIPrincipal other);
93 /**
94 * Same as the previous method, subsumes(), but takes document.domain into
95 * account.
97 boolean subsumesConsideringDomain(in nsIPrincipal other);
99 %{C++
100 inline bool Subsumes(nsIPrincipal* aOther) {
101 bool subsumes = false;
102 return NS_SUCCEEDED(Subsumes(aOther, &subsumes)) && subsumes;
105 inline bool SubsumesConsideringDomain(nsIPrincipal* aOther) {
106 bool subsumes = false;
107 return NS_SUCCEEDED(SubsumesConsideringDomain(aOther, &subsumes)) && subsumes;
112 * Checks whether this principal is allowed to load the network resource
113 * located at the given URI under the same-origin policy. This means that
114 * codebase principals are only allowed to load resources from the same
115 * domain, the system principal is allowed to load anything, and null
116 * principals can only load URIs where they are the principal. This is
117 * changed by the optional flag allowIfInheritsPrincipal (which defaults to
118 * false) which allows URIs that inherit their loader's principal.
120 * If the load is allowed this function does nothing. If the load is not
121 * allowed the function throws NS_ERROR_DOM_BAD_URI.
123 * NOTE: Other policies might override this, such as the Access-Control
124 * specification.
125 * NOTE: The 'domain' attribute has no effect on the behaviour of this
126 * function.
129 * @param uri The URI about to be loaded.
130 * @param report If true, will report a warning to the console service
131 * if the load is not allowed.
132 * @param allowIfInheritsPrincipal If true, the load is allowed if the
133 * loadee inherits the principal of the
134 * loader.
135 * @throws NS_ERROR_DOM_BAD_URI if the load is not allowed.
137 void checkMayLoad(in nsIURI uri, in boolean report,
138 in boolean allowIfInheritsPrincipal);
141 * A Content Security Policy associated with this principal.
143 [noscript] attribute nsIContentSecurityPolicy csp;
146 * Returns the jar prefix of the principal.
147 * The jar prefix is a string that can be used to isolate data or
148 * permissions between different principals while taking into account
149 * parameters like the app id or the fact that the principal is embedded in
150 * a mozbrowser.
151 * Some principals will return an empty string.
152 * Some principals will assert if you try to access the jarPrefix.
154 * The jarPrefix is intended to be an opaque identifier. It is currently
155 * "human-readable" but no callers should assume it will stay as is and
156 * it might be crypto-hashed at some point.
158 readonly attribute AUTF8String jarPrefix;
161 * The base domain of the codebase URI to which this principal pertains
162 * (generally the document URI), handling null principals and
163 * non-hierarchical schemes correctly.
165 readonly attribute ACString baseDomain;
167 const short APP_STATUS_NOT_INSTALLED = 0;
168 const short APP_STATUS_INSTALLED = 1;
169 const short APP_STATUS_PRIVILEGED = 2;
170 const short APP_STATUS_CERTIFIED = 3;
173 * Gets the principal's app status, which indicates whether the principal
174 * corresponds to "app code", and if it does, how privileged that code is.
175 * This method returns one of the APP_STATUS constants above.
177 * Note that a principal may have
179 * appId != nsIScriptSecurityManager::NO_APP_ID &&
180 * appId != nsIScriptSecurityManager::UNKNOWN_APP_ID
182 * and still have appStatus == APP_STATUS_NOT_INSTALLED. That's because
183 * appId identifies the app that contains this principal, but a window
184 * might be contained in an app and not be running code that the app has
185 * vouched for. For example, the window might be inside an <iframe
186 * mozbrowser>, or the window's origin might not match the app's origin.
188 * If you're doing a check to determine "does this principal correspond to
189 * app code?", you must check appStatus; checking appId != NO_APP_ID is not
190 * sufficient.
192 [infallible] readonly attribute unsigned short appStatus;
195 * Gets the id of the app this principal is inside. If this principal is
196 * not inside an app, returns nsIScriptSecurityManager::NO_APP_ID.
198 * Note that this principal does not necessarily have the permissions of
199 * the app identified by appId. For example, this principal might
200 * correspond to an iframe whose origin differs from that of the app frame
201 * containing it. In this case, the iframe will have the appId of its
202 * containing app frame, but the iframe must not run with the app's
203 * permissions.
205 * Similarly, this principal might correspond to an <iframe mozbrowser>
206 * inside an app frame; in this case, the content inside the iframe should
207 * not have any of the app's permissions, even if the iframe is at the same
208 * origin as the app.
210 * If you're doing a security check based on appId, you must check
211 * appStatus as well.
213 [infallible] readonly attribute unsigned long appId;
216 * Returns true iff the principal is inside a browser element. (<iframe
217 * mozbrowser mozapp> does not count as a browser element.)
219 [infallible] readonly attribute boolean isInBrowserElement;
222 * Returns true if this principal has an unknown appId. This shouldn't
223 * generally be used. We only expose it due to not providing the correct
224 * appId everywhere where we construct principals.
226 [infallible] readonly attribute boolean unknownAppId;
229 * Returns true iff this principal is a null principal (corresponding to an
230 * unknown, hence assumed minimally privileged, security context).
232 [infallible] readonly attribute boolean isNullPrincipal;
236 * If nsSystemPrincipal is too risky to use, but we want a principal to access
237 * more than one origin, nsExpandedPrincipals letting us define an array of
238 * principals it subsumes. So script with an nsExpandedPrincipals will gain
239 * same origin access when at least one of its principals it contains gained
240 * sameorigin acccess. An nsExpandedPrincipal will be subsumed by the system
241 * principal, and by another nsExpandedPrincipal that has all its principals.
242 * It is added for jetpack content-scripts to let them interact with the
243 * content and a well defined set of other domains, without the risk of
244 * leaking out a system principal to the content. See: Bug 734891
246 [uuid(f3e177Df-6a5e-489f-80a7-2dd1481471d8)]
247 interface nsIExpandedPrincipal : nsISupports
250 * An array of principals that the expanded principal subsumes.
251 * Note: this list is not reference counted, it is shared, so
252 * should not be changed and should only be used ephemerally.
254 [noscript] readonly attribute PrincipalArray whiteList;