nsNullPrincipal.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. * This is the principal that has no rights and can't be accessed by
  7. * anything other than itself and chrome; null principals are not
  8. * same-origin with anything but themselves.
  9. */
  10. #ifndef nsNullPrincipal_h__
  11. #define nsNullPrincipal_h__
  12. #include "nsIPrincipal.h"
  13. #include "nsJSPrincipals.h"
  14. #include "nsIScriptSecurityManager.h"
  15. #include "nsCOMPtr.h"
  16. #include "nsIContentSecurityPolicy.h"
  17. #include "mozilla/BasePrincipal.h"
  18. class nsIDocShell;
  19. class nsIURI;
  20. #define NS_NULLPRINCIPAL_CID \
  21. { 0xbd066e5f, 0x146f, 0x4472, \
  22. { 0x83, 0x31, 0x7b, 0xfd, 0x05, 0xb1, 0xed, 0x90 } }
  23. #define NS_NULLPRINCIPAL_CONTRACTID "@mozilla.org/nullprincipal;1"
  24. #define NS_NULLPRINCIPAL_SCHEME "moz-nullprincipal"
  25. class nsNullPrincipal final : public mozilla::BasePrincipal
  26. {
  27. public:
  28. // This should only be used by deserialization, and the factory constructor.
  29. // Other consumers should use the Create and CreateWithInheritedAttributes
  30. // methods.
  31. nsNullPrincipal() {}
  32. NS_DECL_NSISERIALIZABLE
  33. NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr) override;
  34. NS_IMETHOD GetHashValue(uint32_t* aHashValue) override;
  35. NS_IMETHOD SetCsp(nsIContentSecurityPolicy* aCsp) override;
  36. NS_IMETHOD GetURI(nsIURI** aURI) override;
  37. NS_IMETHOD GetDomain(nsIURI** aDomain) override;
  38. NS_IMETHOD SetDomain(nsIURI* aDomain) override;
  39. NS_IMETHOD GetBaseDomain(nsACString& aBaseDomain) override;
  40. nsresult GetOriginInternal(nsACString& aOrigin) override;
  41. static already_AddRefed<nsNullPrincipal> CreateWithInheritedAttributes(nsIPrincipal* aInheritFrom);
  42. static already_AddRefed<nsNullPrincipal> CreateWithInheritedAttributes(nsIDocShell* aDocShell);
  43. static already_AddRefed<nsNullPrincipal>
  44. Create(const mozilla::PrincipalOriginAttributes& aOriginAttributes = mozilla::PrincipalOriginAttributes());
  45. nsresult Init(const mozilla::PrincipalOriginAttributes& aOriginAttributes = mozilla::PrincipalOriginAttributes());
  46. virtual nsresult GetScriptLocation(nsACString &aStr) override;
  47. PrincipalKind Kind() override { return eNullPrincipal; }
  48. protected:
  49. virtual ~nsNullPrincipal() {}
  50. bool SubsumesInternal(nsIPrincipal* aOther, DocumentDomainConsideration aConsideration) override
  51. {
  52. return aOther == this;
  53. }
  54. bool MayLoadInternal(nsIURI* aURI) override;
  55. nsCOMPtr<nsIURI> mURI;
  56. };
  57. #endif // nsNullPrincipal_h__