michael@0: /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 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 "nsISupports.idl" michael@0: #include "nsIPrincipal.idl" michael@0: #include "nsIXPCSecurityManager.idl" michael@0: interface nsIURI; michael@0: interface nsIChannel; michael@0: interface nsIDocShell; michael@0: interface nsIDomainPolicy; michael@0: michael@0: [scriptable, uuid(4c087cc3-e0cc-4ec3-88df-8d68f3023b45)] michael@0: interface nsIScriptSecurityManager : nsIXPCSecurityManager michael@0: { michael@0: /** michael@0: * Check that the script currently running in context "cx" can load "uri". michael@0: * michael@0: * Will return error code NS_ERROR_DOM_BAD_URI if the load request michael@0: * should be denied. michael@0: * michael@0: * @param cx the JSContext of the script causing the load michael@0: * @param uri the URI that is being loaded michael@0: */ michael@0: [noscript] void checkLoadURIFromScript(in JSContextPtr cx, in nsIURI uri); michael@0: michael@0: /** michael@0: * Default CheckLoadURI permissions michael@0: */ michael@0: // Default permissions michael@0: const unsigned long STANDARD = 0; michael@0: michael@0: // Indicate that the load is a load of a new document that is not michael@0: // user-triggered. Here "user-triggered" could be broadly interpreted -- michael@0: // for example, scripted sets of window.location.href might be treated as michael@0: // "user-triggered" in some circumstances. A typical example of a load michael@0: // that is not user-triggered is a refresh load. If this flag is michael@0: // set, the load will be denied if the originating principal's URI has the michael@0: // nsIProtocolHandler::URI_FORBIDS_AUTOMATIC_DOCUMENT_REPLACEMENT flag set. michael@0: const unsigned long LOAD_IS_AUTOMATIC_DOCUMENT_REPLACEMENT = 1 << 0; michael@0: michael@0: // Allow the loading of chrome URLs by non-chrome URLs. Use with great michael@0: // care! This will actually allow the loading of any URI which has the michael@0: // nsIProtocolHandler::URI_IS_UI_RESOURCE protocol handler flag set. Ths michael@0: // probably means at least chrome: and resource:. michael@0: const unsigned long ALLOW_CHROME = 1 << 1; michael@0: michael@0: // Don't allow URLs which would inherit the caller's principal (such as michael@0: // javascript: or data:) to load. See michael@0: // nsIProtocolHandler::URI_INHERITS_SECURITY_CONTEXT. michael@0: const unsigned long DISALLOW_INHERIT_PRINCIPAL = 1 << 2; michael@0: michael@0: // Alias for DISALLOW_INHERIT_PRINCIPAL for backwards compat with michael@0: // JS-implemented extensions. michael@0: const unsigned long DISALLOW_SCRIPT_OR_DATA = DISALLOW_INHERIT_PRINCIPAL; michael@0: michael@0: // Don't allow javascript: URLs to load michael@0: // WARNING: Support for this value was added in Mozilla 1.7.8 and michael@0: // Firefox 1.0.4. Use in prior versions WILL BE IGNORED. michael@0: // When using this, make sure that you actually want DISALLOW_SCRIPT, not michael@0: // DISALLOW_INHERIT_PRINCIPAL michael@0: const unsigned long DISALLOW_SCRIPT = 1 << 3; michael@0: michael@0: // Do not report errors if we just want to check if a principal can load michael@0: // a URI to not unnecessarily spam the error console. michael@0: const unsigned long DONT_REPORT_ERRORS = 1 << 4; michael@0: michael@0: /** michael@0: * Check that content with principal aPrincipal can load "uri". michael@0: * michael@0: * Will return error code NS_ERROR_DOM_BAD_URI if the load request michael@0: * should be denied. michael@0: * michael@0: * @param aPrincipal the principal identifying the actor causing the load michael@0: * @param uri the URI that is being loaded michael@0: * @param flags the permission set, see above michael@0: */ michael@0: void checkLoadURIWithPrincipal(in nsIPrincipal aPrincipal, michael@0: in nsIURI uri, michael@0: in unsigned long flags); michael@0: michael@0: /** michael@0: * Similar to checkLoadURIWithPrincipal but there are two differences: michael@0: * michael@0: * 1) The URI is a string, not a URI object. michael@0: * 2) This function assumes that the URI may still be subject to fixup (and michael@0: * hence will check whether fixed-up versions of the URI are allowed to michael@0: * load as well); if any of the versions of this URI is not allowed, this michael@0: * function will return error code NS_ERROR_DOM_BAD_URI. michael@0: */ michael@0: void checkLoadURIStrWithPrincipal(in nsIPrincipal aPrincipal, michael@0: in AUTF8String uri, michael@0: in unsigned long flags); michael@0: michael@0: /** michael@0: * Return true if scripts may be executed in the scope of the given global. michael@0: */ michael@0: [noscript,notxpcom] boolean scriptAllowed(in JSObjectPtr aGlobal); michael@0: michael@0: ///////////////// Principals /////////////////////// michael@0: /** michael@0: * Return the principal of the innermost frame of the currently michael@0: * executing script. Will return null if there is no script michael@0: * currently executing. michael@0: */ michael@0: [noscript] nsIPrincipal getSubjectPrincipal(); michael@0: michael@0: /** michael@0: * Return the all-powerful system principal. michael@0: */ michael@0: nsIPrincipal getSystemPrincipal(); michael@0: michael@0: /** michael@0: * Return a principal that has the same origin as aURI. michael@0: * This principals should not be used for any data/permission check, it will michael@0: * have appId = UNKNOWN_APP_ID. michael@0: */ michael@0: nsIPrincipal getSimpleCodebasePrincipal(in nsIURI aURI); michael@0: michael@0: /** michael@0: * Returns a principal that has the given information. michael@0: * @param appId is the app id of the principal. It can't be UNKNOWN_APP_ID. michael@0: * @param inMozBrowser is true if the principal has to be considered as michael@0: * inside a mozbrowser frame. michael@0: */ michael@0: nsIPrincipal getAppCodebasePrincipal(in nsIURI uri, michael@0: in unsigned long appId, michael@0: in boolean inMozBrowser); michael@0: michael@0: /** michael@0: * Returns a principal that has the appId and inMozBrowser of the docshell michael@0: * inside a mozbrowser frame. michael@0: * @param docShell to get appId/inMozBrowser from. michael@0: */ michael@0: nsIPrincipal getDocShellCodebasePrincipal(in nsIURI uri, michael@0: in nsIDocShell docShell); michael@0: michael@0: /** michael@0: * Returns a principal with that has the same origin as uri and is not part michael@0: * of an appliction. michael@0: * The returned principal will have appId = NO_APP_ID. michael@0: */ michael@0: nsIPrincipal getNoAppCodebasePrincipal(in nsIURI uri); michael@0: michael@0: /** michael@0: * Legacy name for getNoAppCodebasePrincipal. michael@0: * michael@0: * @deprecated use getNoAppCodebasePrincipal instead. michael@0: */ michael@0: [deprecated] nsIPrincipal getCodebasePrincipal(in nsIURI uri); michael@0: michael@0: /** michael@0: * Returns true if the principal of the currently running script is the michael@0: * system principal, false otherwise. michael@0: */ michael@0: [noscript] boolean subjectPrincipalIsSystem(); michael@0: michael@0: /** michael@0: * Returns OK if aJSContext and target have the same "origin" michael@0: * (scheme, host, and port). michael@0: */ michael@0: [noscript] void checkSameOrigin(in JSContextPtr aJSContext, michael@0: in nsIURI aTargetURI); michael@0: michael@0: /** michael@0: * Returns OK if aSourceURI and target have the same "origin" michael@0: * (scheme, host, and port). michael@0: * ReportError flag suppresses error reports for functions that michael@0: * don't need reporting. michael@0: */ michael@0: void checkSameOriginURI(in nsIURI aSourceURI, michael@0: in nsIURI aTargetURI, michael@0: in boolean reportError); michael@0: /** michael@0: * Get the principal for the given channel. This will typically be the michael@0: * channel owner if there is one, and the codebase principal for the michael@0: * channel's URI otherwise. aChannel must not be null. michael@0: */ michael@0: nsIPrincipal getChannelPrincipal(in nsIChannel aChannel); michael@0: michael@0: /** michael@0: * Check whether a given principal is a system principal. This allows us michael@0: * to avoid handing back the system principal to script while allowing michael@0: * script to check whether a given principal is system. michael@0: */ michael@0: boolean isSystemPrincipal(in nsIPrincipal aPrincipal); michael@0: %{C++ michael@0: bool IsSystemPrincipal(nsIPrincipal* aPrincipal) { michael@0: bool isSystem = false; michael@0: IsSystemPrincipal(aPrincipal, &isSystem); michael@0: return isSystem; michael@0: } michael@0: %} michael@0: michael@0: /** michael@0: * Same as getSubjectPrincipal(), only faster. cx must *never* be michael@0: * passed null, and it must be the context on the top of the michael@0: * context stack. Does *not* reference count the returned michael@0: * principal. michael@0: */ michael@0: [noscript,notxpcom] nsIPrincipal getCxSubjectPrincipal(in JSContextPtr cx); michael@0: michael@0: const unsigned long NO_APP_ID = 0; michael@0: const unsigned long UNKNOWN_APP_ID = 4294967295; // UINT32_MAX michael@0: const unsigned long SAFEBROWSING_APP_ID = 4294967294; // UINT32_MAX - 1 michael@0: michael@0: /** michael@0: * Returns the jar prefix for the app. michael@0: * appId can be NO_APP_ID or a valid app id. appId should not be michael@0: * UNKNOWN_APP_ID. michael@0: * inMozBrowser has to be true if the app is inside a mozbrowser iframe. michael@0: */ michael@0: AUTF8String getJarPrefix(in unsigned long appId, in boolean inMozBrowser); michael@0: michael@0: /** michael@0: * Per-domain controls to enable and disable script. This system is designed michael@0: * to be used by at most one consumer, and enforces this with its semantics. michael@0: * michael@0: * Initially, domainPolicyActive is false. When activateDomainPolicy() is michael@0: * invoked, domainPolicyActive becomes true, and subsequent calls to michael@0: * activateDomainPolicy() will fail until deactivate() is invoked on the michael@0: * nsIDomainPolicy returned from activateDomainPolicy(). At this point, michael@0: * domainPolicyActive becomes false again, and a new consumer may acquire michael@0: * control of the system by invoking activateDomainPolicy(). michael@0: */ michael@0: nsIDomainPolicy activateDomainPolicy(); michael@0: readonly attribute boolean domainPolicyActive; michael@0: michael@0: /** michael@0: * Query mechanism for the above policy. michael@0: * michael@0: * If domainPolicyEnabled is false, this simply returns the current value michael@0: * of javascript.enabled. Otherwise, it returns the same value, but taking michael@0: * the various blacklist/whitelist exceptions into account. michael@0: */ michael@0: bool policyAllowsScript(in nsIURI aDomain); michael@0: }; michael@0: michael@0: %{C++ michael@0: #define NS_SCRIPTSECURITYMANAGER_CONTRACTID "@mozilla.org/scriptsecuritymanager;1" michael@0: %}