tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

ExpandedPrincipal.h (3370B)


      1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* This Source Code Form is subject to the terms of the Mozilla Public
      3 * License, v. 2.0. If a copy of the MPL was not distributed with this
      4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      5 
      6 #ifndef ExpandedPrincipal_h
      7 #define ExpandedPrincipal_h
      8 
      9 #include "nsCOMPtr.h"
     10 #include "nsJSPrincipals.h"
     11 #include "nsProxyRelease.h"
     12 #include "nsTArray.h"
     13 #include "nsNetUtil.h"
     14 #include "mozilla/BasePrincipal.h"
     15 
     16 class nsIContentSecurityPolicy;
     17 
     18 namespace mozilla {
     19 class JSONWriter;
     20 }  // namespace mozilla
     21 
     22 class ExpandedPrincipal : public nsIExpandedPrincipal,
     23                          public mozilla::BasePrincipal {
     24 public:
     25  static already_AddRefed<ExpandedPrincipal> Create(
     26      const nsTArray<nsCOMPtr<nsIPrincipal>>& aAllowList,
     27      const mozilla::OriginAttributes& aAttrs);
     28 
     29  static PrincipalKind Kind() { return eExpandedPrincipal; }
     30 
     31  NS_DECL_NSIEXPANDEDPRINCIPAL
     32 
     33  NS_IMETHOD_(MozExternalRefCountType) AddRef() override {
     34    return nsJSPrincipals::AddRef();
     35  };
     36  NS_IMETHOD_(MozExternalRefCountType) Release() override {
     37    return nsJSPrincipals::Release();
     38  };
     39  NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr) override;
     40  NS_IMETHOD GetURI(nsIURI** aURI) override;
     41  NS_IMETHOD GetDomain(nsIURI** aDomain) override;
     42  NS_IMETHOD SetDomain(nsIURI* aDomain) override;
     43  NS_IMETHOD GetBaseDomain(nsACString& aBaseDomain) override;
     44  NS_IMETHOD GetAddonId(nsAString& aAddonId) override;
     45  NS_IMETHOD IsThirdPartyURI(nsIURI* uri, bool* aRes) override;
     46  virtual bool AddonHasPermission(const nsAtom* aPerm) override;
     47  virtual nsresult GetScriptLocation(nsACString& aStr) override;
     48 
     49  bool AddonAllowsLoad(nsIURI* aURI, bool aExplicit = false);
     50 
     51  void SetCsp(nsIContentSecurityPolicy* aCSP);
     52 
     53  // Returns the principal to inherit when this principal requests the given
     54  // URL. See BasePrincipal::PrincipalToInherit.
     55  nsIPrincipal* PrincipalToInherit(nsIURI* aRequestedURI = nullptr);
     56 
     57  nsresult GetSiteIdentifier(mozilla::SiteIdentifier& aSite) override;
     58 
     59  virtual nsresult WriteJSONInnerProperties(
     60      mozilla::JSONWriter& aWriter) override;
     61 
     62  // Serializable keys are the valid enum fields the serialization supports
     63  enum SerializableKeys : uint8_t { eSpecs = 0, eSuffix, eMax = eSuffix };
     64 
     65  static constexpr char SpecsKey = '0';
     66  static_assert(eSpecs == 0);
     67  static constexpr char SuffixKey = '1';
     68  static_assert(eSuffix == 1);
     69 
     70  class Deserializer : public BasePrincipal::Deserializer {
     71   public:
     72    NS_IMETHOD Read(nsIObjectInputStream* aStream) override;
     73  };
     74 
     75 protected:
     76  explicit ExpandedPrincipal(nsTArray<nsCOMPtr<nsIPrincipal>>&& aPrincipals,
     77                             const nsACString& aOriginNoSuffix,
     78                             const mozilla::OriginAttributes& aAttrs);
     79 
     80  virtual ~ExpandedPrincipal();
     81 
     82  bool SubsumesInternal(nsIPrincipal* aOther,
     83                        DocumentDomainConsideration aConsideration) override;
     84 
     85  bool MayLoadInternal(nsIURI* aURI) override;
     86 
     87 private:
     88  const nsTArray<nsCOMPtr<nsIPrincipal>> mPrincipals;
     89  nsMainThreadPtrHandle<nsIContentSecurityPolicy> mCSP
     90      MOZ_GUARDED_BY(mozilla::sMainThreadCapability);
     91 };
     92 
     93 #define NS_EXPANDEDPRINCIPAL_CID \
     94  {0xe8ee88b0, 0x5571, 0x4086, {0xa4, 0x5b, 0x39, 0xa7, 0x16, 0x90, 0x6b, 0xdb}}
     95 
     96 #endif  // ExpandedPrincipal_h