michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "nsISerializable.idl" michael@0: michael@0: interface nsIURI; michael@0: interface nsIChannel; michael@0: interface nsIDocShell; michael@0: interface nsIPrincipal; michael@0: michael@0: /** michael@0: * nsIContentSecurityPolicy michael@0: * Describes an XPCOM component used to model and enforce CSPs. Instances of michael@0: * this class may have multiple policies within them, but there should only be michael@0: * one of these per document/principal. michael@0: */ michael@0: michael@0: [scriptable, uuid(8b91f829-b1bf-4327-8ece-4000aa823394)] michael@0: interface nsIContentSecurityPolicy : nsISerializable michael@0: { michael@0: michael@0: /** michael@0: * Set to true when the CSP has been read in and parsed and is ready to michael@0: * enforce. This is a barrier for the nsDocument so it doesn't load any michael@0: * sub-content until either it knows that a CSP is ready or will not be used. michael@0: */ michael@0: attribute boolean isInitialized; michael@0: michael@0: /** michael@0: * Accessor method for a read-only string version of the policy at a given michael@0: * index. michael@0: */ michael@0: AString getPolicy(in unsigned long index); michael@0: michael@0: /** michael@0: * Returns the number of policies attached to this CSP instance. Useful with michael@0: * getPolicy(). michael@0: */ michael@0: attribute long policyCount; michael@0: michael@0: /** michael@0: * Remove a policy associated with this CSP context. michael@0: * @throws NS_ERROR_FAILURE if the index is out of bounds or invalid. michael@0: */ michael@0: void removePolicy(in unsigned long index); michael@0: michael@0: /** michael@0: * Parse and install a CSP policy. michael@0: * @param aPolicy michael@0: * String representation of the policy (e.g., header value) michael@0: * @param selfURI michael@0: * the URI of the protected document/principal michael@0: * @param reportOnly michael@0: * Should this policy affect content, script and style processing or michael@0: * just send reports if it is violated? michael@0: * @param specCompliant michael@0: * Whether or not the policy conforms to the W3C specification. michael@0: * If this is false, that indicates this policy is from the older michael@0: * implementation with different semantics and directive names. michael@0: */ michael@0: void appendPolicy(in AString policyString, in nsIURI selfURI, michael@0: in boolean reportOnly, in boolean specCompliant); michael@0: michael@0: /** michael@0: * Whether this policy allows in-page script. michael@0: * @param shouldReportViolations michael@0: * Whether or not the use of inline script should be reported. michael@0: * This function always returns "true" for report-only policies, but when michael@0: * any policy (report-only or otherwise) is violated, michael@0: * shouldReportViolations is true as well. michael@0: * @return michael@0: * Whether or not the effects of the inline script should be allowed michael@0: * (block the compilation if false). michael@0: */ michael@0: boolean getAllowsInlineScript(out boolean shouldReportViolations); michael@0: michael@0: /** michael@0: * whether this policy allows eval and eval-like functions michael@0: * such as setTimeout("code string", time). michael@0: * @param shouldReportViolations michael@0: * Whether or not the use of eval should be reported. michael@0: * This function returns "true" when violating report-only policies, but michael@0: * when any policy (report-only or otherwise) is violated, michael@0: * shouldReportViolations is true as well. michael@0: * @return michael@0: * Whether or not the effects of the eval call should be allowed michael@0: * (block the call if false). michael@0: */ michael@0: boolean getAllowsEval(out boolean shouldReportViolations); michael@0: michael@0: /** michael@0: * Whether this policy allows in-page styles. michael@0: * This includes