2006-04-03 00:58:26 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 15:12:37 +04: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-03 00:58:26 +04: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 22:37:48 +03:00
|
|
|
#ifndef mozilla_NullPrincipal_h
|
|
|
|
#define mozilla_NullPrincipal_h
|
2006-04-03 00:58:26 +04:00
|
|
|
|
|
|
|
#include "nsIPrincipal.h"
|
|
|
|
#include "nsJSPrincipals.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
|
2015-05-12 00:36:56 +03:00
|
|
|
#include "mozilla/BasePrincipal.h"
|
2020-05-28 11:55:04 +03:00
|
|
|
#include "gtest/MozGtestFriend.h"
|
2015-05-12 00:36:56 +03:00
|
|
|
|
2016-04-21 11:51:25 +03:00
|
|
|
class nsIDocShell;
|
2006-04-03 00:58:26 +04:00
|
|
|
class nsIURI;
|
2019-06-03 15:37:12 +03:00
|
|
|
namespace Json {
|
|
|
|
class Value;
|
|
|
|
}
|
2006-04-03 00:58:26 +04:00
|
|
|
|
|
|
|
#define NS_NULLPRINCIPAL_CID \
|
2018-11-30 13:46:48 +03:00
|
|
|
{ \
|
2015-07-29 00:32:00 +03:00
|
|
|
0xbd066e5f, 0x146f, 0x4472, { \
|
|
|
|
0x83, 0x31, 0x7b, 0xfd, 0x05, 0xb1, 0xed, 0x90 \
|
|
|
|
} \
|
|
|
|
}
|
2006-04-03 00:58:26 +04:00
|
|
|
|
|
|
|
#define NS_NULLPRINCIPAL_SCHEME "moz-nullprincipal"
|
|
|
|
|
2018-07-17 22:37:48 +03:00
|
|
|
namespace mozilla {
|
|
|
|
|
|
|
|
class NullPrincipal final : public BasePrincipal {
|
2006-04-03 00:58:26 +04:00
|
|
|
public:
|
2017-04-16 23:32:42 +03:00
|
|
|
static PrincipalKind Kind() { return eNullPrincipal; }
|
|
|
|
|
2015-05-11 23:16:36 +03:00
|
|
|
NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr) override;
|
2018-11-20 04:17:52 +03:00
|
|
|
uint32_t GetHashValue() override;
|
2015-05-12 00:36:56 +03:00
|
|
|
NS_IMETHOD GetURI(nsIURI** aURI) override;
|
2019-12-05 19:04:53 +03:00
|
|
|
NS_IMETHOD GetIsOriginPotentiallyTrustworthy(bool* aResult) override;
|
2015-05-12 00:36:56 +03:00
|
|
|
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;
|
2006-04-03 00:58:26 +04:00
|
|
|
|
2018-10-30 03:13:29 +03:00
|
|
|
static already_AddRefed<NullPrincipal> CreateWithInheritedAttributes(
|
|
|
|
nsIPrincipal* aInheritFrom);
|
2016-04-21 11:51:25 +03:00
|
|
|
|
2017-03-01 13:59:57 +03:00
|
|
|
// Create NullPrincipal with origin attributes from docshell.
|
|
|
|
// If aIsFirstParty is true, and the pref 'privacy.firstparty.isolate' is also
|
|
|
|
// enabled, the mFirstPartyDomain value of the origin attributes will be set
|
2017-04-10 13:45:36 +03:00
|
|
|
// to an unique value.
|
2017-03-22 13:38:40 +03:00
|
|
|
static already_AddRefed<NullPrincipal> CreateWithInheritedAttributes(
|
2018-10-30 03:13:29 +03:00
|
|
|
nsIDocShell* aDocShell, bool aIsFirstParty = false);
|
|
|
|
static already_AddRefed<NullPrincipal> CreateWithInheritedAttributes(
|
|
|
|
const OriginAttributes& aOriginAttributes, bool aIsFirstParty = false);
|
2014-07-29 19:47:52 +04:00
|
|
|
|
2017-03-22 13:38:40 +03:00
|
|
|
static already_AddRefed<NullPrincipal> Create(
|
2018-07-17 22:37:48 +03:00
|
|
|
const OriginAttributes& aOriginAttributes, nsIURI* aURI = nullptr);
|
2015-03-31 20:11:00 +03:00
|
|
|
|
2018-03-22 21:36:20 +03:00
|
|
|
static already_AddRefed<NullPrincipal> CreateWithoutOriginAttributes();
|
|
|
|
|
2021-07-16 00:09:13 +03: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.
|
|
|
|
static already_AddRefed<nsIURI> CreateURI(nsIPrincipal* aPrecursor = nullptr);
|
2021-07-06 11:23:11 +03:00
|
|
|
|
2016-08-30 07:22:04 +03:00
|
|
|
virtual nsresult GetScriptLocation(nsACString& aStr) override;
|
2012-03-09 13:48:50 +04:00
|
|
|
|
2018-09-11 12:01:14 +03:00
|
|
|
nsresult GetSiteIdentifier(SiteIdentifier& aSite) override {
|
|
|
|
aSite.Init(this);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
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 { eSpec = 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<NullPrincipal::KeyVal>& aFields);
|
|
|
|
|
2021-05-17 23:50:09 +03:00
|
|
|
class Deserializer : public BasePrincipal::Deserializer {
|
|
|
|
public:
|
|
|
|
NS_IMETHOD Read(nsIObjectInputStream* aStream) override;
|
|
|
|
};
|
|
|
|
|
2012-03-09 13:48:50 +04:00
|
|
|
protected:
|
2021-05-17 23:50:09 +03:00
|
|
|
NullPrincipal(nsIURI* aURI, const nsACString& aOriginNoSuffix,
|
|
|
|
const OriginAttributes& aOriginAttributes);
|
|
|
|
|
2017-03-22 13:38:40 +03:00
|
|
|
virtual ~NullPrincipal() = default;
|
2006-04-03 00:58:26 +04:00
|
|
|
|
2018-10-30 03:13:29 +03:00
|
|
|
bool SubsumesInternal(nsIPrincipal* aOther,
|
|
|
|
DocumentDomainConsideration aConsideration) override {
|
2019-02-11 21:03:12 +03:00
|
|
|
MOZ_ASSERT(aOther);
|
|
|
|
return FastEquals(aOther);
|
2015-05-14 21:15:56 +03:00
|
|
|
}
|
|
|
|
|
2015-10-01 06:03:36 +03:00
|
|
|
bool MayLoadInternal(nsIURI* aURI) override;
|
|
|
|
|
2021-05-17 23:50:09 +03:00
|
|
|
const nsCOMPtr<nsIURI> mURI;
|
2017-04-10 13:45:36 +03:00
|
|
|
|
|
|
|
private:
|
2020-05-28 11:55:04 +03:00
|
|
|
FRIEND_TEST(OriginAttributes, NullPrincipal);
|
|
|
|
|
2019-11-27 23:17:46 +03:00
|
|
|
// If aIsFirstParty is true, this NullPrincipal will be initialized based on
|
2021-07-16 00:09:13 +03:00
|
|
|
// the aOriginAttributes with FirstPartyDomain set to a unique value. This
|
|
|
|
// value is generated from mURI.filePath, with ".mozilla" appended at the end.
|
|
|
|
// aURI is used for testing purpose to assign a specific UUID rather than a
|
|
|
|
// randomly generated one.
|
2021-05-17 23:50:09 +03:00
|
|
|
static already_AddRefed<NullPrincipal> CreateInternal(
|
|
|
|
const OriginAttributes& aOriginAttributes, bool aIsFirstParty,
|
2021-07-16 00:09:13 +03:00
|
|
|
nsIURI* aURI = nullptr, nsIPrincipal* aPrecursor = nullptr);
|
2006-04-03 00:58:26 +04:00
|
|
|
};
|
|
|
|
|
2018-07-17 22:37:48 +03:00
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_NullPrincipal_h
|