2017-02-22 12:01:43 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* 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/. */
|
|
|
|
|
2017-03-22 13:38:17 +03:00
|
|
|
#ifndef ExpandedPrincipal_h
|
|
|
|
#define ExpandedPrincipal_h
|
2017-02-22 12:01:43 +03:00
|
|
|
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsJSPrincipals.h"
|
|
|
|
#include "nsTArray.h"
|
|
|
|
#include "nsNetUtil.h"
|
|
|
|
#include "mozilla/BasePrincipal.h"
|
|
|
|
|
2019-05-22 02:14:27 +03:00
|
|
|
class nsIContentSecurityPolicy;
|
|
|
|
|
2019-06-03 15:37:12 +03:00
|
|
|
namespace Json {
|
|
|
|
class Value;
|
|
|
|
}
|
|
|
|
|
2017-03-22 13:38:17 +03:00
|
|
|
class ExpandedPrincipal : public nsIExpandedPrincipal,
|
|
|
|
public mozilla::BasePrincipal {
|
2017-02-25 01:02:24 +03:00
|
|
|
public:
|
2017-03-22 13:38:17 +03:00
|
|
|
static already_AddRefed<ExpandedPrincipal> Create(
|
2018-10-31 20:56:43 +03:00
|
|
|
nsTArray<nsCOMPtr<nsIPrincipal>>& aAllowList,
|
2017-02-25 01:02:24 +03:00
|
|
|
const mozilla::OriginAttributes& aAttrs);
|
|
|
|
|
2017-04-16 23:32:42 +03:00
|
|
|
static PrincipalKind Kind() { return eExpandedPrincipal; }
|
|
|
|
|
2018-05-24 09:43:14 +03:00
|
|
|
// For use from the XPCOM factory constructor only. Do not ever use this
|
|
|
|
// constructor by hand!
|
|
|
|
ExpandedPrincipal();
|
|
|
|
|
2017-02-22 12:01:43 +03:00
|
|
|
NS_DECL_NSIEXPANDEDPRINCIPAL
|
|
|
|
NS_DECL_NSISERIALIZABLE
|
2017-03-22 13:38:17 +03:00
|
|
|
|
2017-02-22 12:01:43 +03:00
|
|
|
NS_IMETHOD_(MozExternalRefCountType) AddRef() override {
|
|
|
|
return nsJSPrincipals::AddRef();
|
|
|
|
};
|
|
|
|
NS_IMETHOD_(MozExternalRefCountType) Release() override {
|
|
|
|
return nsJSPrincipals::Release();
|
|
|
|
};
|
|
|
|
NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr) override;
|
2018-11-20 04:17:52 +03:00
|
|
|
uint32_t GetHashValue() override;
|
2017-02-22 12:01:43 +03:00
|
|
|
NS_IMETHOD GetURI(nsIURI** aURI) override;
|
|
|
|
NS_IMETHOD GetDomain(nsIURI** aDomain) override;
|
|
|
|
NS_IMETHOD SetDomain(nsIURI* aDomain) override;
|
|
|
|
NS_IMETHOD GetBaseDomain(nsACString& aBaseDomain) override;
|
2016-11-06 08:38:17 +03:00
|
|
|
NS_IMETHOD GetAddonId(nsAString& aAddonId) override;
|
2020-05-13 19:50:19 +03:00
|
|
|
NS_IMETHOD IsThirdPartyURI(nsIURI* uri, bool* aRes) override;
|
2017-10-03 01:05:19 +03:00
|
|
|
virtual bool AddonHasPermission(const nsAtom* aPerm) override;
|
2017-02-22 12:01:43 +03:00
|
|
|
virtual nsresult GetScriptLocation(nsACString& aStr) override;
|
|
|
|
|
2018-04-04 17:54:26 +03:00
|
|
|
bool AddonAllowsLoad(nsIURI* aURI, bool aExplicit = false);
|
|
|
|
|
2019-05-22 02:14:27 +03:00
|
|
|
void SetCsp(nsIContentSecurityPolicy* aCSP);
|
|
|
|
|
2017-11-03 05:56:27 +03:00
|
|
|
// Returns the principal to inherit when this principal requests the given
|
|
|
|
// URL. See BasePrincipal::PrincipalToInherit.
|
2017-11-23 01:20:26 +03:00
|
|
|
nsIPrincipal* PrincipalToInherit(nsIURI* aRequestedURI = nullptr);
|
2017-11-03 05:56:27 +03:00
|
|
|
|
2018-09-11 12:01:14 +03:00
|
|
|
nsresult GetSiteIdentifier(mozilla::SiteIdentifier& aSite) override;
|
|
|
|
|
2019-06-03 15:37:12 +03:00
|
|
|
virtual nsresult PopulateJSONObject(Json::Value& aObject) override;
|
|
|
|
// Serializable keys are the valid enum fields the serialization supports
|
2019-12-04 01:20:03 +03:00
|
|
|
enum SerializableKeys : uint8_t { eSpecs = 0, eSuffix, eMax = eSuffix };
|
2019-12-03 20:30:09 +03:00
|
|
|
typedef mozilla::BasePrincipal::KeyValT<SerializableKeys> KeyVal;
|
|
|
|
|
2019-06-03 15:37:12 +03:00
|
|
|
static already_AddRefed<BasePrincipal> FromProperties(
|
|
|
|
nsTArray<ExpandedPrincipal::KeyVal>& aFields);
|
|
|
|
|
2017-02-22 12:01:43 +03:00
|
|
|
protected:
|
2018-10-31 20:56:43 +03:00
|
|
|
explicit ExpandedPrincipal(nsTArray<nsCOMPtr<nsIPrincipal>>& aAllowList);
|
2017-03-29 09:21:03 +03:00
|
|
|
|
2017-03-22 13:38:17 +03:00
|
|
|
virtual ~ExpandedPrincipal();
|
|
|
|
|
|
|
|
bool SubsumesInternal(nsIPrincipal* aOther,
|
|
|
|
DocumentDomainConsideration aConsideration) override;
|
2017-02-22 12:01:43 +03:00
|
|
|
|
|
|
|
bool MayLoadInternal(nsIURI* aURI) override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
nsTArray<nsCOMPtr<nsIPrincipal>> mPrincipals;
|
2019-05-22 02:14:27 +03:00
|
|
|
nsCOMPtr<nsIContentSecurityPolicy> mCSP;
|
2017-02-22 12:01:43 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
#define NS_EXPANDEDPRINCIPAL_CONTRACTID "@mozilla.org/expandedprincipal;1"
|
|
|
|
#define NS_EXPANDEDPRINCIPAL_CID \
|
2018-11-30 13:46:48 +03:00
|
|
|
{ \
|
2017-02-22 12:01:43 +03:00
|
|
|
0xe8ee88b0, 0x5571, 0x4086, { \
|
|
|
|
0xa4, 0x5b, 0x39, 0xa7, 0x16, 0x90, 0x6b, 0xdb \
|
|
|
|
} \
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-03-22 13:38:17 +03:00
|
|
|
#endif // ExpandedPrincipal_h
|