2015-05-12 00:25:59 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#ifndef mozilla_BasePrincipal_h
|
|
|
|
#define mozilla_BasePrincipal_h
|
|
|
|
|
|
|
|
#include "nsJSPrincipals.h"
|
|
|
|
|
2016-08-15 13:22:44 +03:00
|
|
|
#include "mozilla/Attributes.h"
|
2017-03-22 20:45:40 +03:00
|
|
|
#include "mozilla/OriginAttributes.h"
|
2015-05-15 02:24:25 +03:00
|
|
|
|
2017-10-03 01:05:19 +03:00
|
|
|
class nsAtom;
|
2015-06-04 21:51:57 +03:00
|
|
|
class nsIContentSecurityPolicy;
|
2015-05-14 23:56:37 +03:00
|
|
|
class nsIObjectOutputStream;
|
|
|
|
class nsIObjectInputStream;
|
2015-11-03 04:50:54 +03:00
|
|
|
class nsIURI;
|
2015-05-14 23:56:37 +03:00
|
|
|
|
2017-03-22 13:38:17 +03:00
|
|
|
class ExpandedPrincipal;
|
2015-10-01 06:03:36 +03:00
|
|
|
|
2019-06-03 15:37:12 +03:00
|
|
|
namespace Json {
|
|
|
|
class Value;
|
|
|
|
}
|
2015-05-12 00:25:59 +03:00
|
|
|
namespace mozilla {
|
2019-01-02 16:05:23 +03:00
|
|
|
namespace dom {
|
|
|
|
class Document;
|
|
|
|
}
|
2017-09-05 21:04:43 +03:00
|
|
|
namespace extensions {
|
|
|
|
class WebExtensionPolicy;
|
|
|
|
}
|
2015-05-12 00:25:59 +03:00
|
|
|
|
2018-09-11 12:01:14 +03:00
|
|
|
class BasePrincipal;
|
|
|
|
|
2019-07-08 19:37:45 +03:00
|
|
|
// Content principals (and content principals embedded within expanded
|
2018-09-11 12:01:14 +03:00
|
|
|
// principals) stored in SiteIdentifier are guaranteed to contain only the
|
|
|
|
// eTLD+1 part of the original domain. This is used to determine whether two
|
|
|
|
// origins are same-site: if it's possible for two origins to access each other
|
|
|
|
// (maybe after mutating document.domain), then they must have the same site
|
|
|
|
// identifier.
|
|
|
|
class SiteIdentifier {
|
|
|
|
public:
|
|
|
|
void Init(BasePrincipal* aPrincipal) {
|
|
|
|
MOZ_ASSERT(aPrincipal);
|
|
|
|
mPrincipal = aPrincipal;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IsInitialized() const { return !!mPrincipal; }
|
|
|
|
|
|
|
|
bool Equals(const SiteIdentifier& aOther) const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
friend class ::ExpandedPrincipal;
|
|
|
|
|
|
|
|
BasePrincipal* GetPrincipal() const {
|
|
|
|
MOZ_ASSERT(IsInitialized());
|
|
|
|
return mPrincipal;
|
|
|
|
}
|
|
|
|
|
|
|
|
RefPtr<BasePrincipal> mPrincipal;
|
|
|
|
};
|
|
|
|
|
2015-05-12 00:25:59 +03:00
|
|
|
/*
|
|
|
|
* Base class from which all nsIPrincipal implementations inherit. Use this for
|
|
|
|
* default implementations and other commonalities between principal
|
|
|
|
* implementations.
|
|
|
|
*
|
|
|
|
* We should merge nsJSPrincipals into this class at some point.
|
|
|
|
*/
|
|
|
|
class BasePrincipal : public nsJSPrincipals {
|
|
|
|
public:
|
2019-06-03 15:37:12 +03:00
|
|
|
// Warning: this enum impacts Principal serialization into JSON format.
|
|
|
|
// Only update if you know exactly what you are doing
|
2017-02-24 05:33:40 +03:00
|
|
|
enum PrincipalKind {
|
2019-06-03 15:37:12 +03:00
|
|
|
eNullPrincipal = 0,
|
2019-07-08 19:37:45 +03:00
|
|
|
eContentPrincipal,
|
2017-02-24 05:33:40 +03:00
|
|
|
eExpandedPrincipal,
|
2019-06-03 15:37:12 +03:00
|
|
|
eSystemPrincipal,
|
|
|
|
eKindMax = eSystemPrincipal
|
2017-02-24 05:33:40 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
explicit BasePrincipal(PrincipalKind aKind);
|
2015-05-14 04:25:40 +03:00
|
|
|
|
2017-04-16 23:32:42 +03:00
|
|
|
template <typename T>
|
|
|
|
bool Is() const {
|
|
|
|
return mKind == T::Kind();
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
T* As() {
|
|
|
|
MOZ_ASSERT(Is<T>());
|
|
|
|
return static_cast<T*>(this);
|
|
|
|
}
|
|
|
|
|
2015-05-14 21:15:56 +03:00
|
|
|
enum DocumentDomainConsideration {
|
|
|
|
DontConsiderDocumentDomain,
|
|
|
|
ConsiderDocumentDomain
|
|
|
|
};
|
|
|
|
bool Subsumes(nsIPrincipal* aOther,
|
|
|
|
DocumentDomainConsideration aConsideration);
|
|
|
|
|
2018-02-06 09:46:57 +03:00
|
|
|
NS_IMETHOD GetOrigin(nsACString& aOrigin) final;
|
2019-11-28 12:22:17 +03:00
|
|
|
NS_IMETHOD GetAsciiOrigin(nsACString& aOrigin) override;
|
2018-02-06 09:46:57 +03:00
|
|
|
NS_IMETHOD GetOriginNoSuffix(nsACString& aOrigin) final;
|
|
|
|
NS_IMETHOD Equals(nsIPrincipal* other, bool* _retval) final;
|
|
|
|
NS_IMETHOD EqualsConsideringDomain(nsIPrincipal* other, bool* _retval) final;
|
2020-01-22 20:14:08 +03:00
|
|
|
NS_IMETHOD EqualsURI(nsIURI* aOtherURI, bool* _retval) override;
|
2020-04-23 16:11:56 +03:00
|
|
|
NS_IMETHOD EqualsForPermission(nsIPrincipal* other, bool aExactHost,
|
|
|
|
bool* _retval) final;
|
2018-02-06 09:46:57 +03:00
|
|
|
NS_IMETHOD Subsumes(nsIPrincipal* other, bool* _retval) final;
|
|
|
|
NS_IMETHOD SubsumesConsideringDomain(nsIPrincipal* other,
|
|
|
|
bool* _retval) final;
|
|
|
|
NS_IMETHOD SubsumesConsideringDomainIgnoringFPD(nsIPrincipal* other,
|
|
|
|
bool* _retval) final;
|
2019-12-13 09:24:12 +03:00
|
|
|
NS_IMETHOD CheckMayLoad(nsIURI* uri, bool allowIfInheritsPrincipal) final;
|
|
|
|
NS_IMETHOD CheckMayLoadWithReporting(nsIURI* uri,
|
|
|
|
bool allowIfInheritsPrincipal,
|
|
|
|
uint64_t innerWindowID) final;
|
2018-02-06 09:46:57 +03:00
|
|
|
NS_IMETHOD GetAddonPolicy(nsISupports** aResult) final;
|
2015-10-24 03:58:21 +03:00
|
|
|
NS_IMETHOD GetIsNullPrincipal(bool* aResult) override;
|
2019-07-08 19:37:45 +03:00
|
|
|
NS_IMETHOD GetIsContentPrincipal(bool* aResult) override;
|
2015-10-24 03:58:21 +03:00
|
|
|
NS_IMETHOD GetIsExpandedPrincipal(bool* aResult) override;
|
|
|
|
NS_IMETHOD GetIsSystemPrincipal(bool* aResult) override;
|
2020-06-02 16:50:12 +03:00
|
|
|
NS_IMETHOD GetScheme(nsACString& aScheme) override;
|
2019-09-26 13:47:03 +03:00
|
|
|
NS_IMETHOD SchemeIs(const char* aScheme, bool* aResult) override;
|
2019-11-07 16:42:37 +03:00
|
|
|
NS_IMETHOD IsURIInPrefList(const char* aPref, bool* aResult) override;
|
2020-03-26 16:18:40 +03:00
|
|
|
NS_IMETHOD IsL10nAllowed(nsIURI* aURI, bool* aResult) override;
|
2019-10-17 16:54:41 +03:00
|
|
|
NS_IMETHOD GetAboutModuleFlags(uint32_t* flags) override;
|
2018-07-14 05:26:15 +03:00
|
|
|
NS_IMETHOD GetIsAddonOrExpandedAddonPrincipal(bool* aResult) override;
|
2018-02-06 09:46:57 +03:00
|
|
|
NS_IMETHOD GetOriginAttributes(JSContext* aCx,
|
|
|
|
JS::MutableHandle<JS::Value> aVal) final;
|
2019-10-22 19:03:27 +03:00
|
|
|
NS_IMETHOD GetAsciiSpec(nsACString& aSpec) override;
|
2020-08-04 14:10:41 +03:00
|
|
|
NS_IMETHOD GetSpec(nsACString& aSpec) override;
|
2020-01-22 20:14:08 +03:00
|
|
|
NS_IMETHOD GetExposablePrePath(nsACString& aResult) override;
|
2020-04-15 00:48:38 +03:00
|
|
|
NS_IMETHOD GetExposableSpec(nsACString& aSpec) override;
|
2020-02-10 18:10:52 +03:00
|
|
|
NS_IMETHOD GetHostPort(nsACString& aRes) override;
|
2020-02-24 19:57:40 +03:00
|
|
|
NS_IMETHOD GetHost(nsACString& aRes) override;
|
2020-02-12 19:13:19 +03:00
|
|
|
NS_IMETHOD GetPrepath(nsACString& aResult) override;
|
2020-04-20 13:01:54 +03:00
|
|
|
NS_IMETHOD GetFilePath(nsACString& aResult) override;
|
2018-02-06 09:46:57 +03:00
|
|
|
NS_IMETHOD GetOriginSuffix(nsACString& aOriginSuffix) final;
|
2020-02-27 02:15:43 +03:00
|
|
|
NS_IMETHOD GetIsIpAddress(bool* aIsIpAddress) override;
|
2020-08-24 19:28:26 +03:00
|
|
|
NS_IMETHOD GetIsLocalIpAddress(bool* aIsIpAddress) override;
|
2019-11-28 12:22:17 +03:00
|
|
|
NS_IMETHOD GetIsOnion(bool* aIsOnion) override;
|
2018-02-06 09:46:57 +03:00
|
|
|
NS_IMETHOD GetIsInIsolatedMozBrowserElement(
|
|
|
|
bool* aIsInIsolatedMozBrowserElement) final;
|
|
|
|
NS_IMETHOD GetUserContextId(uint32_t* aUserContextId) final;
|
|
|
|
NS_IMETHOD GetPrivateBrowsingId(uint32_t* aPrivateBrowsingId) final;
|
2018-09-05 06:22:16 +03:00
|
|
|
NS_IMETHOD GetSiteOrigin(nsACString& aOrigin) override;
|
2019-10-02 18:10:40 +03:00
|
|
|
NS_IMETHOD IsThirdPartyURI(nsIURI* uri, bool* aRes) override;
|
|
|
|
NS_IMETHOD IsThirdPartyPrincipal(nsIPrincipal* uri, bool* aRes) override;
|
2020-04-27 13:54:47 +03:00
|
|
|
NS_IMETHOD IsThirdPartyChannel(nsIChannel* aChannel, bool* aRes) override;
|
2019-12-05 19:04:53 +03:00
|
|
|
NS_IMETHOD GetIsOriginPotentiallyTrustworthy(bool* aResult) override;
|
2019-12-06 15:32:27 +03:00
|
|
|
NS_IMETHOD IsSameOrigin(nsIURI* aURI, bool aIsPrivateWin,
|
|
|
|
bool* aRes) override;
|
2020-02-17 16:57:41 +03:00
|
|
|
NS_IMETHOD GetPrefLightCacheKey(nsIURI* aURI, bool aWithCredentials,
|
|
|
|
nsACString& _retval) override;
|
2020-05-19 17:51:40 +03:00
|
|
|
NS_IMETHOD HasFirstpartyStorageAccess(mozIDOMWindow* aCheckWindow,
|
|
|
|
uint32_t* aRejectedReason,
|
|
|
|
bool* aOutAllowed) override;
|
2020-02-17 16:57:41 +03:00
|
|
|
NS_IMETHOD GetAsciiHost(nsACString& aAsciiHost) override;
|
2020-02-27 03:22:27 +03:00
|
|
|
NS_IMETHOD GetLocalStorageQuotaKey(nsACString& aRes) override;
|
2020-03-03 15:58:38 +03:00
|
|
|
NS_IMETHOD AllowsRelaxStrictFileOriginPolicy(nsIURI* aURI,
|
|
|
|
bool* aRes) override;
|
2020-03-05 16:42:13 +03:00
|
|
|
NS_IMETHOD CreateReferrerInfo(mozilla::dom::ReferrerPolicy aReferrerPolicy,
|
2020-03-09 16:28:03 +03:00
|
|
|
nsIReferrerInfo** _retval) override;
|
|
|
|
NS_IMETHOD GetIsScriptAllowedByPolicy(
|
|
|
|
bool* aIsScriptAllowedByPolicy) override;
|
2020-03-29 18:31:24 +03:00
|
|
|
NS_IMETHOD GetStorageOriginKey(nsACString& aOriginKey) override;
|
2020-04-20 12:53:40 +03:00
|
|
|
|
|
|
|
NS_IMETHOD GetNextSubDomainPrincipal(
|
|
|
|
nsIPrincipal** aNextSubDomainPrincipal) override;
|
2019-06-03 15:37:12 +03:00
|
|
|
nsresult ToJSON(nsACString& aJSON);
|
|
|
|
static already_AddRefed<BasePrincipal> FromJSON(const nsACString& aJSON);
|
|
|
|
// Method populates a passed Json::Value with serializable fields
|
|
|
|
// which represent all of the fields to deserialize the principal
|
|
|
|
virtual nsresult PopulateJSONObject(Json::Value& aObject);
|
|
|
|
|
2017-10-03 01:05:19 +03:00
|
|
|
virtual bool AddonHasPermission(const nsAtom* aPerm);
|
2016-07-09 03:19:17 +03:00
|
|
|
|
2019-07-08 19:37:45 +03:00
|
|
|
virtual bool IsContentPrincipal() const { return false; };
|
2015-06-03 11:43:43 +03:00
|
|
|
|
2015-05-14 21:15:56 +03:00
|
|
|
static BasePrincipal* Cast(nsIPrincipal* aPrin) {
|
|
|
|
return static_cast<BasePrincipal*>(aPrin);
|
|
|
|
}
|
2017-03-29 09:24:01 +03:00
|
|
|
|
2019-12-09 18:10:32 +03:00
|
|
|
static BasePrincipal& Cast(nsIPrincipal& aPrin) {
|
|
|
|
return *static_cast<BasePrincipal*>(&aPrin);
|
|
|
|
}
|
|
|
|
|
2019-01-03 23:08:55 +03:00
|
|
|
static const BasePrincipal* Cast(const nsIPrincipal* aPrin) {
|
|
|
|
return static_cast<const BasePrincipal*>(aPrin);
|
|
|
|
}
|
|
|
|
|
2019-12-09 18:10:32 +03:00
|
|
|
static const BasePrincipal& Cast(const nsIPrincipal& aPrin) {
|
|
|
|
return *static_cast<const BasePrincipal*>(&aPrin);
|
|
|
|
}
|
|
|
|
|
2019-07-08 19:37:45 +03:00
|
|
|
static already_AddRefed<BasePrincipal> CreateContentPrincipal(
|
2017-03-29 09:24:01 +03:00
|
|
|
const nsACString& aOrigin);
|
|
|
|
|
2019-07-08 19:37:45 +03:00
|
|
|
// These following method may not create a content principal in case it's
|
2017-03-29 09:24:01 +03:00
|
|
|
// not possible to generate a correct origin from the passed URI. If this
|
|
|
|
// happens, a NullPrincipal is returned.
|
|
|
|
|
2019-07-08 19:37:45 +03:00
|
|
|
static already_AddRefed<BasePrincipal> CreateContentPrincipal(
|
2017-01-12 19:38:48 +03:00
|
|
|
nsIURI* aURI, const OriginAttributes& aAttrs);
|
2015-05-14 22:24:03 +03:00
|
|
|
|
2018-02-06 09:46:57 +03:00
|
|
|
const OriginAttributes& OriginAttributesRef() final {
|
|
|
|
return mOriginAttributes;
|
|
|
|
}
|
2017-09-05 21:04:43 +03:00
|
|
|
extensions::WebExtensionPolicy* AddonPolicy();
|
2015-07-30 21:15:00 +03:00
|
|
|
uint32_t UserContextId() const { return mOriginAttributes.mUserContextId; }
|
2016-06-29 15:01:00 +03:00
|
|
|
uint32_t PrivateBrowsingId() const {
|
|
|
|
return mOriginAttributes.mPrivateBrowsingId;
|
|
|
|
}
|
2016-02-05 04:42:44 +03:00
|
|
|
bool IsInIsolatedMozBrowserElement() const {
|
|
|
|
return mOriginAttributes.mInIsolatedMozBrowser;
|
|
|
|
}
|
2015-05-14 22:24:03 +03:00
|
|
|
|
2017-02-24 05:33:40 +03:00
|
|
|
PrincipalKind Kind() const { return mKind; }
|
2015-10-24 03:58:21 +03:00
|
|
|
|
2019-04-12 08:30:19 +03:00
|
|
|
already_AddRefed<BasePrincipal> CloneForcingOriginAttributes(
|
|
|
|
const OriginAttributes& aOriginAttributes);
|
|
|
|
|
2018-05-14 21:49:32 +03:00
|
|
|
// If this is an add-on content script principal, returns its AddonPolicy.
|
|
|
|
// Otherwise returns null.
|
|
|
|
extensions::WebExtensionPolicy* ContentScriptAddonPolicy();
|
|
|
|
|
2017-02-10 08:08:06 +03:00
|
|
|
// Helper to check whether this principal is associated with an addon that
|
|
|
|
// allows unprivileged code to load aURI. aExplicit == true will prevent
|
|
|
|
// use of all_urls permission, requiring the domain in its permissions.
|
|
|
|
bool AddonAllowsLoad(nsIURI* aURI, bool aExplicit = false);
|
|
|
|
|
2017-03-07 06:50:10 +03:00
|
|
|
// Call these to avoid the cost of virtual dispatch.
|
2017-03-07 07:04:50 +03:00
|
|
|
inline bool FastEquals(nsIPrincipal* aOther);
|
|
|
|
inline bool FastEqualsConsideringDomain(nsIPrincipal* aOther);
|
|
|
|
inline bool FastSubsumes(nsIPrincipal* aOther);
|
|
|
|
inline bool FastSubsumesConsideringDomain(nsIPrincipal* aOther);
|
2018-09-21 10:13:15 +03:00
|
|
|
inline bool FastSubsumesIgnoringFPD(nsIPrincipal* aOther);
|
2017-03-07 07:04:50 +03:00
|
|
|
inline bool FastSubsumesConsideringDomainIgnoringFPD(nsIPrincipal* aOther);
|
2017-02-25 02:05:44 +03:00
|
|
|
|
2019-01-03 23:08:55 +03:00
|
|
|
// Fast way to check whether we have a system principal.
|
|
|
|
inline bool IsSystemPrincipal() const;
|
|
|
|
|
2017-11-03 05:56:27 +03:00
|
|
|
// Returns the principal to inherit when a caller with this principal loads
|
|
|
|
// the given URI.
|
|
|
|
//
|
|
|
|
// For most principal types, this returns the principal itself. For expanded
|
|
|
|
// principals, it returns the first sub-principal which subsumes the given URI
|
2018-10-31 20:56:43 +03:00
|
|
|
// (or, if no URI is given, the last allowlist principal).
|
2017-11-23 01:20:26 +03:00
|
|
|
nsIPrincipal* PrincipalToInherit(nsIURI* aRequestedURI = nullptr);
|
2017-11-03 05:56:27 +03:00
|
|
|
|
2019-06-03 09:04:25 +03:00
|
|
|
/* Returns true if this principal's CSP should override a document's CSP for
|
|
|
|
* loads that it triggers. Currently true for expanded principals which
|
2019-07-08 19:37:45 +03:00
|
|
|
* subsume the document principal, and add-on content principals regardless
|
2019-06-03 09:04:25 +03:00
|
|
|
* of whether they subsume the document principal.
|
2017-10-08 00:53:30 +03:00
|
|
|
*/
|
|
|
|
bool OverridesCSP(nsIPrincipal* aDocumentPrincipal) {
|
2019-09-09 19:45:29 +03:00
|
|
|
MOZ_ASSERT(aDocumentPrincipal);
|
|
|
|
|
2017-11-08 01:25:59 +03:00
|
|
|
// Expanded principals override CSP if and only if they subsume the document
|
|
|
|
// principal.
|
|
|
|
if (mKind == eExpandedPrincipal) {
|
|
|
|
return FastSubsumes(aDocumentPrincipal);
|
|
|
|
}
|
|
|
|
// Extension principals always override the CSP non-extension principals.
|
|
|
|
// This is primarily for the sake of their stylesheets, which are usually
|
|
|
|
// loaded from channels and cannot have expanded principals.
|
|
|
|
return (AddonPolicy() &&
|
|
|
|
!BasePrincipal::Cast(aDocumentPrincipal)->AddonPolicy());
|
2017-10-08 00:53:30 +03:00
|
|
|
}
|
|
|
|
|
2018-06-27 21:34:07 +03:00
|
|
|
uint32_t GetOriginNoSuffixHash() const { return mOriginNoSuffix->hash(); }
|
2019-08-09 01:00:44 +03:00
|
|
|
uint32_t GetOriginSuffixHash() const { return mOriginSuffix->hash(); }
|
2018-06-27 21:34:07 +03:00
|
|
|
|
2018-09-11 12:01:14 +03:00
|
|
|
virtual nsresult GetSiteIdentifier(SiteIdentifier& aSite) = 0;
|
|
|
|
|
2015-05-12 00:25:59 +03:00
|
|
|
protected:
|
2015-06-04 21:51:57 +03:00
|
|
|
virtual ~BasePrincipal();
|
2015-05-12 00:25:59 +03:00
|
|
|
|
2016-11-02 20:04:13 +03:00
|
|
|
// Note that this does not check OriginAttributes. Callers that depend on
|
|
|
|
// those must call Subsumes instead.
|
2015-05-14 21:15:56 +03:00
|
|
|
virtual bool SubsumesInternal(nsIPrincipal* aOther,
|
|
|
|
DocumentDomainConsideration aConsider) = 0;
|
|
|
|
|
2015-10-01 06:03:36 +03:00
|
|
|
// Internal, side-effect-free check to determine whether the concrete
|
|
|
|
// principal would allow the load ignoring any common behavior implemented in
|
|
|
|
// BasePrincipal::CheckMayLoad.
|
|
|
|
virtual bool MayLoadInternal(nsIURI* aURI) = 0;
|
2017-03-22 13:38:17 +03:00
|
|
|
friend class ::ExpandedPrincipal;
|
2015-10-01 06:03:36 +03:00
|
|
|
|
2019-12-13 09:24:12 +03:00
|
|
|
// Helper for implementing CheckMayLoad and CheckMayLoadWithReporting.
|
|
|
|
nsresult CheckMayLoadHelper(nsIURI* aURI, bool aAllowIfInheritsPrincipal,
|
|
|
|
bool aReport, uint64_t aInnerWindowID);
|
|
|
|
|
2017-03-29 09:21:03 +03:00
|
|
|
void SetHasExplicitDomain() { mHasExplicitDomain = true; }
|
|
|
|
|
2018-12-21 14:56:47 +03:00
|
|
|
// Either of these functions should be called as the last step of the
|
|
|
|
// initialization of the principal objects. It's typically called as the
|
|
|
|
// last step from the Init() method of the child classes.
|
2017-03-29 09:22:26 +03:00
|
|
|
void FinishInit(const nsACString& aOriginNoSuffix,
|
|
|
|
const OriginAttributes& aOriginAttributes);
|
2018-12-21 14:56:47 +03:00
|
|
|
void FinishInit(BasePrincipal* aOther,
|
|
|
|
const OriginAttributes& aOriginAttributes);
|
2017-02-25 01:02:24 +03:00
|
|
|
|
2019-12-03 20:30:09 +03:00
|
|
|
// KeyValT holds a principal subtype-specific key value and the associated
|
|
|
|
// parsed value after JSON parsing.
|
2019-12-06 15:32:27 +03:00
|
|
|
template <typename SerializedKey>
|
|
|
|
struct KeyValT {
|
|
|
|
static_assert(sizeof(SerializedKey) == 1,
|
|
|
|
"SerializedKey should be a uint8_t");
|
2019-12-04 01:20:03 +03:00
|
|
|
SerializedKey key;
|
2019-12-03 20:30:09 +03:00
|
|
|
bool valueWasSerialized;
|
|
|
|
nsCString value;
|
|
|
|
};
|
|
|
|
|
2017-03-29 09:22:26 +03:00
|
|
|
private:
|
2019-07-08 19:37:45 +03:00
|
|
|
static already_AddRefed<BasePrincipal> CreateContentPrincipal(
|
2017-03-29 09:24:01 +03:00
|
|
|
nsIURI* aURI, const OriginAttributes& aAttrs,
|
|
|
|
const nsACString& aOriginNoSuffix);
|
|
|
|
|
2018-09-21 10:13:15 +03:00
|
|
|
inline bool FastSubsumesIgnoringFPD(
|
|
|
|
nsIPrincipal* aOther, DocumentDomainConsideration aConsideration);
|
|
|
|
|
2017-10-03 01:05:19 +03:00
|
|
|
RefPtr<nsAtom> mOriginNoSuffix;
|
|
|
|
RefPtr<nsAtom> mOriginSuffix;
|
2017-03-29 09:21:03 +03:00
|
|
|
|
2017-01-12 19:38:48 +03:00
|
|
|
OriginAttributes mOriginAttributes;
|
2017-02-24 05:33:40 +03:00
|
|
|
PrincipalKind mKind;
|
2017-03-29 09:21:03 +03:00
|
|
|
bool mHasExplicitDomain;
|
|
|
|
bool mInitialized;
|
2015-05-12 00:25:59 +03:00
|
|
|
};
|
|
|
|
|
2017-03-07 07:04:50 +03:00
|
|
|
inline bool BasePrincipal::FastEquals(nsIPrincipal* aOther) {
|
2019-09-09 19:45:29 +03:00
|
|
|
MOZ_ASSERT(aOther);
|
|
|
|
|
2017-03-07 07:04:50 +03:00
|
|
|
auto other = Cast(aOther);
|
|
|
|
if (Kind() != other->Kind()) {
|
|
|
|
// Principals of different kinds can't be equal.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Two principals are considered to be equal if their origins are the same.
|
2019-07-08 19:37:45 +03:00
|
|
|
// If the two principals are content principals, their origin attributes
|
2017-03-07 07:04:50 +03:00
|
|
|
// (aka the origin suffix) must also match.
|
2019-02-11 21:03:12 +03:00
|
|
|
if (Kind() == eSystemPrincipal) {
|
2017-03-07 07:04:50 +03:00
|
|
|
return this == other;
|
|
|
|
}
|
|
|
|
|
2019-07-08 19:37:45 +03:00
|
|
|
if (Kind() == eContentPrincipal || Kind() == eNullPrincipal) {
|
2017-03-29 09:24:01 +03:00
|
|
|
return mOriginNoSuffix == other->mOriginNoSuffix &&
|
|
|
|
mOriginSuffix == other->mOriginSuffix;
|
2017-03-07 07:04:50 +03:00
|
|
|
}
|
|
|
|
|
2017-03-29 09:24:01 +03:00
|
|
|
MOZ_ASSERT(Kind() == eExpandedPrincipal);
|
|
|
|
return mOriginNoSuffix == other->mOriginNoSuffix;
|
2017-03-07 07:04:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
inline bool BasePrincipal::FastEqualsConsideringDomain(nsIPrincipal* aOther) {
|
2019-09-09 19:45:29 +03:00
|
|
|
MOZ_ASSERT(aOther);
|
|
|
|
|
2017-03-07 07:04:50 +03:00
|
|
|
// If neither of the principals have document.domain set, we use the fast path
|
|
|
|
// in Equals(). Otherwise, we fall back to the slow path below.
|
|
|
|
auto other = Cast(aOther);
|
2017-03-29 09:21:03 +03:00
|
|
|
if (!mHasExplicitDomain && !other->mHasExplicitDomain) {
|
2017-03-07 07:04:50 +03:00
|
|
|
return FastEquals(aOther);
|
|
|
|
}
|
|
|
|
|
|
|
|
return Subsumes(aOther, ConsiderDocumentDomain) &&
|
|
|
|
other->Subsumes(this, ConsiderDocumentDomain);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool BasePrincipal::FastSubsumes(nsIPrincipal* aOther) {
|
2019-09-09 19:45:29 +03:00
|
|
|
MOZ_ASSERT(aOther);
|
|
|
|
|
2017-03-07 07:04:50 +03:00
|
|
|
// If two principals are equal, then they both subsume each other.
|
2017-03-29 09:24:01 +03:00
|
|
|
if (FastEquals(aOther)) {
|
2017-03-07 07:04:50 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Otherwise, fall back to the slow path.
|
|
|
|
return Subsumes(aOther, DontConsiderDocumentDomain);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool BasePrincipal::FastSubsumesConsideringDomain(nsIPrincipal* aOther) {
|
2019-09-09 19:45:29 +03:00
|
|
|
MOZ_ASSERT(aOther);
|
|
|
|
|
2017-03-07 07:04:50 +03:00
|
|
|
// If neither of the principals have document.domain set, we hand off to
|
|
|
|
// FastSubsumes() which has fast paths for some special cases. Otherwise, we
|
|
|
|
// fall back to the slow path below.
|
2017-03-29 09:21:03 +03:00
|
|
|
if (!mHasExplicitDomain && !Cast(aOther)->mHasExplicitDomain) {
|
2017-03-07 07:04:50 +03:00
|
|
|
return FastSubsumes(aOther);
|
|
|
|
}
|
|
|
|
|
|
|
|
return Subsumes(aOther, ConsiderDocumentDomain);
|
|
|
|
}
|
|
|
|
|
2018-09-21 10:13:15 +03:00
|
|
|
inline bool BasePrincipal::FastSubsumesIgnoringFPD(
|
|
|
|
nsIPrincipal* aOther, DocumentDomainConsideration aConsideration) {
|
2019-09-09 19:45:29 +03:00
|
|
|
MOZ_ASSERT(aOther);
|
|
|
|
|
2019-07-08 19:37:45 +03:00
|
|
|
if (Kind() == eContentPrincipal &&
|
2017-03-07 07:04:50 +03:00
|
|
|
!dom::ChromeUtils::IsOriginAttributesEqualIgnoringFPD(
|
|
|
|
mOriginAttributes, Cast(aOther)->mOriginAttributes)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-09-21 10:13:15 +03:00
|
|
|
return SubsumesInternal(aOther, aConsideration);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool BasePrincipal::FastSubsumesIgnoringFPD(nsIPrincipal* aOther) {
|
|
|
|
return FastSubsumesIgnoringFPD(aOther, DontConsiderDocumentDomain);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool BasePrincipal::FastSubsumesConsideringDomainIgnoringFPD(
|
|
|
|
nsIPrincipal* aOther) {
|
|
|
|
return FastSubsumesIgnoringFPD(aOther, ConsiderDocumentDomain);
|
2017-03-07 07:04:50 +03:00
|
|
|
}
|
|
|
|
|
2019-01-03 23:08:55 +03:00
|
|
|
inline bool BasePrincipal::IsSystemPrincipal() const {
|
|
|
|
return Kind() == eSystemPrincipal;
|
|
|
|
}
|
|
|
|
|
2015-05-12 00:25:59 +03:00
|
|
|
} // namespace mozilla
|
|
|
|
|
2019-01-03 23:08:55 +03:00
|
|
|
inline bool nsIPrincipal::IsSystemPrincipal() const {
|
|
|
|
return mozilla::BasePrincipal::Cast(this)->IsSystemPrincipal();
|
|
|
|
}
|
|
|
|
|
2015-05-12 00:25:59 +03:00
|
|
|
#endif /* mozilla_BasePrincipal_h */
|