2006-04-02 20:58:26 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 11:12:37 +00:00
|
|
|
/* 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/. */
|
2006-04-02 20:58:26 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This is the principal that has no rights and can't be accessed by
|
|
|
|
* anything other than itself and chrome; null principals are not
|
|
|
|
* same-origin with anything but themselves.
|
|
|
|
*/
|
|
|
|
|
2018-07-17 19:37:48 +00:00
|
|
|
#ifndef mozilla_NullPrincipal_h
|
|
|
|
#define mozilla_NullPrincipal_h
|
2006-04-02 20:58:26 +00:00
|
|
|
|
|
|
|
#include "nsIPrincipal.h"
|
|
|
|
#include "nsJSPrincipals.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
|
2015-05-11 21:36:56 +00:00
|
|
|
#include "mozilla/BasePrincipal.h"
|
2020-05-28 08:55:04 +00:00
|
|
|
#include "gtest/MozGtestFriend.h"
|
2015-05-11 21:36:56 +00:00
|
|
|
|
2016-04-21 08:51:25 +00:00
|
|
|
class nsIDocShell;
|
2006-04-02 20:58:26 +00:00
|
|
|
class nsIURI;
|
|
|
|
|
|
|
|
#define NS_NULLPRINCIPAL_CID \
|
2018-11-30 10:46:48 +00:00
|
|
|
{ \
|
2015-07-28 21:32:00 +00:00
|
|
|
0xbd066e5f, 0x146f, 0x4472, { \
|
|
|
|
0x83, 0x31, 0x7b, 0xfd, 0x05, 0xb1, 0xed, 0x90 \
|
|
|
|
} \
|
|
|
|
}
|
2006-04-02 20:58:26 +00:00
|
|
|
|
|
|
|
#define NS_NULLPRINCIPAL_SCHEME "moz-nullprincipal"
|
|
|
|
|
2018-07-17 19:37:48 +00:00
|
|
|
namespace mozilla {
|
|
|
|
|
2024-01-26 15:39:38 +00:00
|
|
|
class JSONWriter;
|
|
|
|
|
2018-07-17 19:37:48 +00:00
|
|
|
class NullPrincipal final : public BasePrincipal {
|
2006-04-02 20:58:26 +00:00
|
|
|
public:
|
2017-04-16 20:32:42 +00:00
|
|
|
static PrincipalKind Kind() { return eNullPrincipal; }
|
|
|
|
|
2015-05-11 20:16:36 +00:00
|
|
|
NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr) override;
|
2018-11-20 01:17:52 +00:00
|
|
|
uint32_t GetHashValue() override;
|
2015-05-11 21:36:56 +00:00
|
|
|
NS_IMETHOD GetURI(nsIURI** aURI) override;
|
2019-12-05 16:04:53 +00:00
|
|
|
NS_IMETHOD GetIsOriginPotentiallyTrustworthy(bool* aResult) override;
|
2015-05-11 21:36:56 +00:00
|
|
|
NS_IMETHOD GetDomain(nsIURI** aDomain) override;
|
|
|
|
NS_IMETHOD SetDomain(nsIURI* aDomain) override;
|
|
|
|
NS_IMETHOD GetBaseDomain(nsACString& aBaseDomain) override;
|
2016-11-06 05:38:17 +00:00
|
|
|
NS_IMETHOD GetAddonId(nsAString& aAddonId) override;
|
2021-07-15 21:09:15 +00:00
|
|
|
NS_IMETHOD GetPrecursorPrincipal(nsIPrincipal** aPrecursor) override;
|
2006-04-02 20:58:26 +00:00
|
|
|
|
2022-09-20 23:29:08 +00:00
|
|
|
// Create a NullPrincipal, inheriting origin attributes from the given
|
|
|
|
// principal.
|
|
|
|
// If aInheritFrom is a content principal, or has a content principal
|
|
|
|
// precursor, it will be used as the precursor for this principal.
|
2018-10-30 00:13:29 +00:00
|
|
|
static already_AddRefed<NullPrincipal> CreateWithInheritedAttributes(
|
|
|
|
nsIPrincipal* aInheritFrom);
|
2016-04-21 08:51:25 +00:00
|
|
|
|
2022-09-20 23:29:08 +00:00
|
|
|
// Create a new NullPrincipal with the specified OriginAttributes.
|
|
|
|
//
|
|
|
|
// If `aNullPrincipalURI` is specified, it must be a NS_NULLPRINCIPAL_SCHEME
|
|
|
|
// URI previously created using `NullPrincipal::CreateURI`, and will be used
|
|
|
|
// as the origin URI for this principal.
|
2017-03-22 10:38:40 +00:00
|
|
|
static already_AddRefed<NullPrincipal> Create(
|
2022-09-20 23:29:08 +00:00
|
|
|
const OriginAttributes& aOriginAttributes,
|
|
|
|
nsIURI* aNullPrincipalURI = nullptr);
|
2015-03-31 17:11:00 +00:00
|
|
|
|
2018-03-22 18:36:20 +00:00
|
|
|
static already_AddRefed<NullPrincipal> CreateWithoutOriginAttributes();
|
|
|
|
|
2021-07-15 21:09:13 +00:00
|
|
|
// Generates a new unique `moz-nullprincipal:` URI. If `aPrecursor` is
|
|
|
|
// specified, it will be included in the generated URI as the null principal's
|
|
|
|
// precursor.
|
2021-07-15 21:09:15 +00:00
|
|
|
//
|
|
|
|
// The `aPrincipalID` attribute is used to force the creation of a
|
|
|
|
// deterministic NullPrincipal in situations where that is required. Avoid
|
|
|
|
// using this parameter unless absolutely necessary.
|
|
|
|
static already_AddRefed<nsIURI> CreateURI(nsIPrincipal* aPrecursor = nullptr,
|
|
|
|
const nsID* aPrincipalID = nullptr);
|
2021-07-06 08:23:11 +00:00
|
|
|
|
2016-08-30 04:22:04 +00:00
|
|
|
virtual nsresult GetScriptLocation(nsACString& aStr) override;
|
2012-03-09 09:48:50 +00:00
|
|
|
|
2018-09-11 09:01:14 +00:00
|
|
|
nsresult GetSiteIdentifier(SiteIdentifier& aSite) override {
|
|
|
|
aSite.Init(this);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2024-01-26 15:39:38 +00:00
|
|
|
virtual nsresult WriteJSONInnerProperties(JSONWriter& aWriter) override;
|
2019-06-03 12:37:12 +00:00
|
|
|
|
|
|
|
// Serializable keys are the valid enum fields the serialization supports
|
2019-12-03 22:20:03 +00:00
|
|
|
enum SerializableKeys : uint8_t { eSpec = 0, eSuffix, eMax = eSuffix };
|
2019-12-03 17:30:09 +00:00
|
|
|
|
2024-01-26 15:39:39 +00:00
|
|
|
static constexpr char SpecKey = '0';
|
|
|
|
static_assert(eSpec == 0);
|
|
|
|
static constexpr char SuffixKey = '1';
|
|
|
|
static_assert(eSuffix == 1);
|
2019-06-03 12:37:12 +00:00
|
|
|
|
2021-05-17 20:50:09 +00:00
|
|
|
class Deserializer : public BasePrincipal::Deserializer {
|
|
|
|
public:
|
|
|
|
NS_IMETHOD Read(nsIObjectInputStream* aStream) override;
|
|
|
|
};
|
|
|
|
|
2012-03-09 09:48:50 +00:00
|
|
|
protected:
|
2021-05-17 20:50:09 +00:00
|
|
|
NullPrincipal(nsIURI* aURI, const nsACString& aOriginNoSuffix,
|
|
|
|
const OriginAttributes& aOriginAttributes);
|
|
|
|
|
2017-03-22 10:38:40 +00:00
|
|
|
virtual ~NullPrincipal() = default;
|
2006-04-02 20:58:26 +00:00
|
|
|
|
2018-10-30 00:13:29 +00:00
|
|
|
bool SubsumesInternal(nsIPrincipal* aOther,
|
|
|
|
DocumentDomainConsideration aConsideration) override {
|
2019-02-11 18:03:12 +00:00
|
|
|
MOZ_ASSERT(aOther);
|
|
|
|
return FastEquals(aOther);
|
2015-05-14 18:15:56 +00:00
|
|
|
}
|
|
|
|
|
2015-10-01 03:03:36 +00:00
|
|
|
bool MayLoadInternal(nsIURI* aURI) override;
|
|
|
|
|
2021-05-17 20:50:09 +00:00
|
|
|
const nsCOMPtr<nsIURI> mURI;
|
2017-04-10 10:45:36 +00:00
|
|
|
|
|
|
|
private:
|
2022-03-28 15:12:36 +00:00
|
|
|
FRIEND_TEST(NullPrincipalPrecursor, EscapingRoundTrips);
|
|
|
|
|
|
|
|
static void EscapePrecursorQuery(nsACString& aPrecursorQuery);
|
|
|
|
static void UnescapePrecursorQuery(nsACString& aPrecursorQuery);
|
2006-04-02 20:58:26 +00:00
|
|
|
};
|
|
|
|
|
2018-07-17 19:37:48 +00:00
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_NullPrincipal_h
|