Bug 1528736 [wpt PR 15405] - Update interfaces/font-metrics-api.idl, a=testonly
[gecko.git] / caps / nsIScriptSecurityManager.idl
blob116fcd782b151cc5f76043b04decd11f635e61fe
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
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 #include "nsISupports.idl"
7 #include "nsIPrincipal.idl"
8 interface nsIURI;
9 interface nsIChannel;
10 interface nsIClassInfo;
11 interface nsIDocShell;
12 interface nsIDomainPolicy;
13 interface nsILoadContext;
15 %{ C++
16 #include "jspubtd.h"
18 namespace mozilla {
19 namespace dom {
20 class DomainPolicyClone;
25 [ptr] native JSContextPtr(JSContext);
26 [ptr] native JSObjectPtr(JSObject);
27 [ptr] native DomainPolicyClonePtr(mozilla::dom::DomainPolicyClone);
29 [scriptable, uuid(51daad87-3a0c-44cc-b620-7356801c9022)]
30 interface nsIScriptSecurityManager : nsISupports
32 /**
33 * For each of these hooks returning NS_OK means 'let the action continue'.
34 * Returning an error code means 'veto the action'. XPConnect will return
35 * false to the js engine if the action is vetoed. The implementor of this
36 * interface is responsible for setting a JS exception into the JSContext
37 * if that is appropriate.
39 [noscript] void canCreateWrapper(in JSContextPtr aJSContext,
40 in nsIIDRef aIID,
41 in nsISupports aObj,
42 in nsIClassInfo aClassInfo);
44 [noscript] void canCreateInstance(in JSContextPtr aJSContext,
45 in nsCIDRef aCID);
47 [noscript] void canGetService(in JSContextPtr aJSContext,
48 in nsCIDRef aCID);
50 /**
51 * Check that the script currently running in context "cx" can load "uri".
53 * Will return error code NS_ERROR_DOM_BAD_URI if the load request
54 * should be denied.
56 * @param cx the JSContext of the script causing the load
57 * @param uri the URI that is being loaded
59 [noscript] void checkLoadURIFromScript(in JSContextPtr cx, in nsIURI uri);
61 /**
62 * Default CheckLoadURI permissions
64 // Default permissions
65 const unsigned long STANDARD = 0;
67 // Indicate that the load is a load of a new document that is not
68 // user-triggered. Here "user-triggered" could be broadly interpreted --
69 // for example, scripted sets of window.location.href might be treated as
70 // "user-triggered" in some circumstances. A typical example of a load
71 // that is not user-triggered is a <meta> refresh load. If this flag is
72 // set, the load will be denied if the originating principal's URI has the
73 // nsIProtocolHandler::URI_FORBIDS_AUTOMATIC_DOCUMENT_REPLACEMENT flag set.
74 const unsigned long LOAD_IS_AUTOMATIC_DOCUMENT_REPLACEMENT = 1 << 0;
76 // Allow the loading of chrome URLs by non-chrome URLs. Use with great
77 // care! This will actually allow the loading of any URI which has the
78 // nsIProtocolHandler::URI_IS_UI_RESOURCE protocol handler flag set. Ths
79 // probably means at least chrome: and resource:.
80 const unsigned long ALLOW_CHROME = 1 << 1;
82 // Don't allow URLs which would inherit the caller's principal (such as
83 // javascript: or data:) to load. See
84 // nsIProtocolHandler::URI_INHERITS_SECURITY_CONTEXT.
85 const unsigned long DISALLOW_INHERIT_PRINCIPAL = 1 << 2;
87 // Alias for DISALLOW_INHERIT_PRINCIPAL for backwards compat with
88 // JS-implemented extensions.
89 const unsigned long DISALLOW_SCRIPT_OR_DATA = DISALLOW_INHERIT_PRINCIPAL;
91 // Don't allow javascript: URLs to load
92 // WARNING: Support for this value was added in Mozilla 1.7.8 and
93 // Firefox 1.0.4. Use in prior versions WILL BE IGNORED.
94 // When using this, make sure that you actually want DISALLOW_SCRIPT, not
95 // DISALLOW_INHERIT_PRINCIPAL
96 const unsigned long DISALLOW_SCRIPT = 1 << 3;
98 // Do not report errors if we just want to check if a principal can load
99 // a URI to not unnecessarily spam the error console.
100 const unsigned long DONT_REPORT_ERRORS = 1 << 4;
103 * Check that content with principal aPrincipal can load "uri".
105 * Will return error code NS_ERROR_DOM_BAD_URI if the load request
106 * should be denied.
108 * @param aPrincipal the principal identifying the actor causing the load
109 * @param uri the URI that is being loaded
110 * @param flags the permission set, see above
112 void checkLoadURIWithPrincipal(in nsIPrincipal aPrincipal,
113 in nsIURI uri,
114 in unsigned long flags);
117 * Similar to checkLoadURIWithPrincipal but there are two differences:
119 * 1) The URI is a string, not a URI object.
120 * 2) This function assumes that the URI may still be subject to fixup (and
121 * hence will check whether fixed-up versions of the URI are allowed to
122 * load as well); if any of the versions of this URI is not allowed, this
123 * function will return error code NS_ERROR_DOM_BAD_URI.
125 void checkLoadURIStrWithPrincipal(in nsIPrincipal aPrincipal,
126 in AUTF8String uri,
127 in unsigned long flags);
130 * Returns true if the URI is from a domain that is allow-listed through
131 * prefs to be allowed to use file:// URIs.
132 * @param aUri the URI to be tested
134 bool inFileURIAllowlist(in nsIURI aUri);
136 ///////////////// Principals ///////////////////////
139 * Return the all-powerful system principal.
141 nsIPrincipal getSystemPrincipal();
144 * Returns a principal that has the OriginAttributes of the load context.
145 * @param loadContext to get the OriginAttributes from.
147 nsIPrincipal getLoadContextCodebasePrincipal(in nsIURI uri,
148 in nsILoadContext loadContext);
151 * Returns a principal that has the OriginAttributes of the docshell.
152 * @param docShell to get the OriginAttributes from.
154 nsIPrincipal getDocShellCodebasePrincipal(in nsIURI uri,
155 in nsIDocShell docShell);
158 * If this is a codebase principal, return a copy with different
159 * origin attributes.
161 [implicit_jscontext]
162 nsIPrincipal principalWithOA(in nsIPrincipal principal,
163 in jsval originAttributes);
166 * Returns a principal whose origin is composed of |uri| and |originAttributes|.
167 * See nsIPrincipal.idl for a description of origin attributes, and
168 * ChromeUtils.webidl for a list of origin attributes and their defaults.
170 [implicit_jscontext]
171 nsIPrincipal createCodebasePrincipal(in nsIURI uri, in jsval originAttributes);
174 * Returns a principal whose origin is the one we pass in.
175 * See nsIPrincipal.idl for a description of origin attributes, and
176 * ChromeUtils.webidl for a list of origin attributes and their defaults.
178 nsIPrincipal createCodebasePrincipalFromOrigin(in ACString origin);
181 * Returns a unique nonce principal with |originAttributes|.
182 * See nsIPrincipal.idl for a description of origin attributes, and
183 * ChromeUtils.webidl for a list of origin attributes and their defaults.
185 [implicit_jscontext]
186 nsIPrincipal createNullPrincipal(in jsval originAttributes);
189 * Returns OK if aSourceURI and target have the same "origin"
190 * (scheme, host, and port).
191 * ReportError flag suppresses error reports for functions that
192 * don't need reporting.
193 * FromPrivateWindow indicates whether the error occurs in a private
194 * window or not.
196 void checkSameOriginURI(in nsIURI aSourceURI,
197 in nsIURI aTargetURI,
198 in boolean reportError,
199 in boolean fromPrivateWindow);
201 * Get the principal for the given channel. This will typically be the
202 * channel owner if there is one, and the codebase principal for the
203 * channel's URI otherwise. aChannel must not be null.
205 nsIPrincipal getChannelResultPrincipal(in nsIChannel aChannel);
208 * Temporary API until bug 1220687 is fixed.
210 * Returns the same value as getChannelResultPrincipal, but ignoring
211 * sandboxing. Specifically, if sandboxing would have prevented the
212 * channel's triggering principal from being returned by
213 * getChannelResultPrincipal, the triggering principal will be returned
214 * by this method.
216 * Note that this method only ignores sandboxing of the channel in
217 * question, it does not ignore sandboxing of any channels further up a
218 * document chain. The triggering principal itself may still be the null
219 * principal due to sandboxing further up a document chain. In that regard
220 * the ignoring of sandboxing is limited.
222 [noscript, nostdcall]
223 nsIPrincipal getChannelResultPrincipalIfNotSandboxed(in nsIChannel aChannel);
226 * Get the codebase principal for the channel's URI.
227 * aChannel must not be null.
229 nsIPrincipal getChannelURIPrincipal(in nsIChannel aChannel);
232 * Check whether a given principal is a system principal. This allows us
233 * to avoid handing back the system principal to script while allowing
234 * script to check whether a given principal is system.
236 * @deprecated use nsIPrincipal's accessors for this boolean.
237 * https://bugzilla.mozilla.org/show_bug.cgi?id=1517483 tracks removing
238 * this.
240 boolean isSystemPrincipal(in nsIPrincipal aPrincipal);
241 %{C++
242 bool IsSystemPrincipal(nsIPrincipal* aPrincipal) {
243 bool isSystem = false;
244 IsSystemPrincipal(aPrincipal, &isSystem);
245 return isSystem;
249 const unsigned long NO_APP_ID = 0;
250 const unsigned long UNKNOWN_APP_ID = 4294967295; // UINT32_MAX
252 const unsigned long DEFAULT_USER_CONTEXT_ID = 0;
255 * Per-domain controls to enable and disable script. This system is designed
256 * to be used by at most one consumer, and enforces this with its semantics.
258 * Initially, domainPolicyActive is false. When activateDomainPolicy() is
259 * invoked, domainPolicyActive becomes true, and subsequent calls to
260 * activateDomainPolicy() will fail until deactivate() is invoked on the
261 * nsIDomainPolicy returned from activateDomainPolicy(). At this point,
262 * domainPolicyActive becomes false again, and a new consumer may acquire
263 * control of the system by invoking activateDomainPolicy().
265 nsIDomainPolicy activateDomainPolicy();
266 readonly attribute boolean domainPolicyActive;
269 * Only the parent process can directly access domain policies, child
270 * processes only have a read-only mirror to the one in the parent.
271 * For child processes the mirror is updated via messages
272 * and ContentChild will hold the DomainPolicy by calling
273 * ActivateDomainPolicyInternal directly. New consumer to this
274 * function should not be addded.
276 [noscript] nsIDomainPolicy activateDomainPolicyInternal();
279 * This function is for internal use only. Every time a child process is spawned, we
280 * must clone any active domain policies in the parent to the new child.
282 [noscript, notxpcom] void cloneDomainPolicy(in DomainPolicyClonePtr aClone);
285 * Query mechanism for the above policy.
287 * If domainPolicyEnabled is false, this simply returns the current value
288 * of javascript.enabled. Otherwise, it returns the same value, but taking
289 * the various blocklist/allowlist exceptions into account.
291 bool policyAllowsScript(in nsIURI aDomain);
294 %{C++
295 #define NS_SCRIPTSECURITYMANAGER_CONTRACTID "@mozilla.org/scriptsecuritymanager;1"