michael@0: /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 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: /* Defines the abstract interface for a principal. */ michael@0: michael@0: #include "nsISerializable.idl" michael@0: michael@0: %{C++ michael@0: struct JSPrincipals; michael@0: #include "nsCOMPtr.h" michael@0: #include "nsTArray.h" michael@0: %} michael@0: michael@0: interface nsIURI; michael@0: interface nsIContentSecurityPolicy; michael@0: michael@0: [ptr] native JSContext(JSContext); michael@0: [ptr] native JSPrincipals(JSPrincipals); michael@0: [ptr] native PrincipalArray(nsTArray >); michael@0: michael@0: [scriptable, builtinclass, uuid(204555e7-04ad-4cc8-9f0e-840615cc43e8)] michael@0: interface nsIPrincipal : nsISerializable michael@0: { michael@0: /** michael@0: * Returns whether the other principal is equivalent to this principal. michael@0: * Principals are considered equal if they are the same principal, or michael@0: * they have the same origin. michael@0: */ michael@0: boolean equals(in nsIPrincipal other); michael@0: michael@0: /** michael@0: * Like equals, but takes document.domain changes into account. michael@0: */ michael@0: boolean equalsConsideringDomain(in nsIPrincipal other); michael@0: michael@0: %{C++ michael@0: inline bool Equals(nsIPrincipal* aOther) { michael@0: bool equal = false; michael@0: return NS_SUCCEEDED(Equals(aOther, &equal)) && equal; michael@0: } michael@0: michael@0: inline bool EqualsConsideringDomain(nsIPrincipal* aOther) { michael@0: bool equal = false; michael@0: return NS_SUCCEEDED(EqualsConsideringDomain(aOther, &equal)) && equal; michael@0: } michael@0: %} michael@0: michael@0: /** michael@0: * Returns a hash value for the principal. michael@0: */ michael@0: [noscript] readonly attribute unsigned long hashValue; michael@0: michael@0: /** michael@0: * The codebase URI to which this principal pertains. This is michael@0: * generally the document URI. michael@0: */ michael@0: readonly attribute nsIURI URI; michael@0: michael@0: /** michael@0: * The domain URI to which this principal pertains. michael@0: * This is congruent with HTMLDocument.domain, and may be null. michael@0: * Setting this has no effect on the URI. michael@0: */ michael@0: [noscript] attribute nsIURI domain; michael@0: michael@0: /** michael@0: * The origin of this principal's codebase URI. michael@0: * An origin is defined as: scheme + host + port. michael@0: */ michael@0: // XXXcaa this should probably be turned into an nsIURI. michael@0: // The system principal's origin should be some caps namespace michael@0: // with a chrome URI. All of chrome should probably be the same. michael@0: readonly attribute string origin; michael@0: michael@0: /** michael@0: * Returns whether the other principal is equal to or weaker than this michael@0: * principal. Principals are equal if they are the same object or they michael@0: * have the same origin. michael@0: * michael@0: * Thus a principal always subsumes itself. michael@0: * michael@0: * The system principal subsumes itself and all other principals. michael@0: * michael@0: * A null principal (corresponding to an unknown, hence assumed minimally michael@0: * privileged, security context) is not equal to any other principal michael@0: * (including other null principals), and therefore does not subsume michael@0: * anything but itself. michael@0: */ michael@0: boolean subsumes(in nsIPrincipal other); michael@0: michael@0: /** michael@0: * Same as the previous method, subsumes(), but takes document.domain into michael@0: * account. michael@0: */ michael@0: boolean subsumesConsideringDomain(in nsIPrincipal other); michael@0: michael@0: %{C++ michael@0: inline bool Subsumes(nsIPrincipal* aOther) { michael@0: bool subsumes = false; michael@0: return NS_SUCCEEDED(Subsumes(aOther, &subsumes)) && subsumes; michael@0: } michael@0: michael@0: inline bool SubsumesConsideringDomain(nsIPrincipal* aOther) { michael@0: bool subsumes = false; michael@0: return NS_SUCCEEDED(SubsumesConsideringDomain(aOther, &subsumes)) && subsumes; michael@0: } michael@0: %} michael@0: michael@0: /** michael@0: * Checks whether this principal is allowed to load the network resource michael@0: * located at the given URI under the same-origin policy. This means that michael@0: * codebase principals are only allowed to load resources from the same michael@0: * domain, the system principal is allowed to load anything, and null michael@0: * principals are not allowed to load anything. This is changed slightly michael@0: * by the optional flag allowIfInheritsPrincipal (which defaults to false) michael@0: * which allows the load of a data: URI (which inherits the principal of michael@0: * its loader) or a URI with the same principal as its loader (eg. a michael@0: * Blob URI). michael@0: * In these cases, with allowIfInheritsPrincipal set to true, the URI can michael@0: * be loaded by a null principal. michael@0: * michael@0: * If the load is allowed this function does nothing. If the load is not michael@0: * allowed the function throws NS_ERROR_DOM_BAD_URI. michael@0: * michael@0: * NOTE: Other policies might override this, such as the Access-Control michael@0: * specification. michael@0: * NOTE: The 'domain' attribute has no effect on the behaviour of this michael@0: * function. michael@0: * michael@0: * michael@0: * @param uri The URI about to be loaded. michael@0: * @param report If true, will report a warning to the console service michael@0: * if the load is not allowed. michael@0: * @param allowIfInheritsPrincipal If true, the load is allowed if the michael@0: * loadee inherits the principal of the michael@0: * loader. michael@0: * @throws NS_ERROR_DOM_BAD_URI if the load is not allowed. michael@0: */ michael@0: void checkMayLoad(in nsIURI uri, in boolean report, michael@0: in boolean allowIfInheritsPrincipal); michael@0: michael@0: /** michael@0: * A Content Security Policy associated with this principal. michael@0: */ michael@0: [noscript] attribute nsIContentSecurityPolicy csp; michael@0: michael@0: /** michael@0: * Returns the jar prefix of the principal. michael@0: * The jar prefix is a string that can be used to isolate data or michael@0: * permissions between different principals while taking into account michael@0: * parameters like the app id or the fact that the principal is embedded in michael@0: * a mozbrowser. michael@0: * Some principals will return an empty string. michael@0: * Some principals will assert if you try to access the jarPrefix. michael@0: * michael@0: * The jarPrefix is intended to be an opaque identifier. It is currently michael@0: * "human-readable" but no callers should assume it will stay as is and michael@0: * it might be crypto-hashed at some point. michael@0: */ michael@0: readonly attribute AUTF8String jarPrefix; michael@0: michael@0: /** michael@0: * The base domain of the codebase URI to which this principal pertains michael@0: * (generally the document URI), handling null principals and michael@0: * non-hierarchical schemes correctly. michael@0: */ michael@0: readonly attribute ACString baseDomain; michael@0: michael@0: const short APP_STATUS_NOT_INSTALLED = 0; michael@0: const short APP_STATUS_INSTALLED = 1; michael@0: const short APP_STATUS_PRIVILEGED = 2; michael@0: const short APP_STATUS_CERTIFIED = 3; michael@0: michael@0: /** michael@0: * Gets the principal's app status, which indicates whether the principal michael@0: * corresponds to "app code", and if it does, how privileged that code is. michael@0: * This method returns one of the APP_STATUS constants above. michael@0: * michael@0: * Note that a principal may have michael@0: * michael@0: * appId != nsIScriptSecurityManager::NO_APP_ID && michael@0: * appId != nsIScriptSecurityManager::UNKNOWN_APP_ID michael@0: * michael@0: * and still have appStatus == APP_STATUS_NOT_INSTALLED. That's because michael@0: * appId identifies the app that contains this principal, but a window michael@0: * might be contained in an app and not be running code that the app has michael@0: * vouched for. For example, the window might be inside an