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;
|
2019-06-03 12:37:12 +00:00
|
|
|
namespace Json {
|
|
|
|
class Value;
|
|
|
|
}
|
2006-04-02 20:58:26 +00:00
|
|
|
|
|
|
|
#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_CONTRACTID "@mozilla.org/nullprincipal;1"
|
|
|
|
|
|
|
|
#define NS_NULLPRINCIPAL_SCHEME "moz-nullprincipal"
|
|
|
|
|
2018-07-17 19:37:48 +00:00
|
|
|
namespace mozilla {
|
|
|
|
|
|
|
|
class NullPrincipal final : public BasePrincipal {
|
2006-04-02 20:58:26 +00:00
|
|
|
public:
|
2015-03-31 17:11:00 +00:00
|
|
|
// This should only be used by deserialization, and the factory constructor.
|
|
|
|
// Other consumers should use the Create and CreateWithInheritedAttributes
|
|
|
|
// methods.
|
2017-02-24 02:33:40 +00:00
|
|
|
NullPrincipal() : BasePrincipal(eNullPrincipal) {}
|
2015-02-24 20:54:40 +00:00
|
|
|
|
2017-04-16 20:32:42 +00:00
|
|
|
static PrincipalKind Kind() { return eNullPrincipal; }
|
|
|
|
|
2006-04-02 20:58:26 +00:00
|
|
|
NS_DECL_NSISERIALIZABLE
|
2015-05-11 21:36:56 +00:00
|
|
|
|
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;
|
2006-04-02 20:58:26 +00:00
|
|
|
|
2018-10-30 00:13:29 +00:00
|
|
|
static already_AddRefed<NullPrincipal> CreateWithInheritedAttributes(
|
|
|
|
nsIPrincipal* aInheritFrom);
|
2016-04-21 08:51:25 +00:00
|
|
|
|
2017-03-01 10:59:57 +00: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 10:45:36 +00:00
|
|
|
// to an unique value.
|
2017-03-22 10:38:40 +00:00
|
|
|
static already_AddRefed<NullPrincipal> CreateWithInheritedAttributes(
|
2018-10-30 00:13:29 +00:00
|
|
|
nsIDocShell* aDocShell, bool aIsFirstParty = false);
|
|
|
|
static already_AddRefed<NullPrincipal> CreateWithInheritedAttributes(
|
|
|
|
const OriginAttributes& aOriginAttributes, bool aIsFirstParty = false);
|
2014-07-29 15:47:52 +00:00
|
|
|
|
2017-03-22 10:38:40 +00:00
|
|
|
static already_AddRefed<NullPrincipal> Create(
|
2018-07-17 19:37:48 +00:00
|
|
|
const OriginAttributes& aOriginAttributes, nsIURI* aURI = nullptr);
|
2015-03-31 17:11:00 +00:00
|
|
|
|
2018-03-22 18:36:20 +00:00
|
|
|
static already_AddRefed<NullPrincipal> CreateWithoutOriginAttributes();
|
|
|
|
|
2018-07-17 19:37:48 +00:00
|
|
|
nsresult Init(const OriginAttributes& aOriginAttributes = OriginAttributes(),
|
2016-11-30 14:13:27 +00:00
|
|
|
nsIURI* aURI = nullptr);
|
2006-04-02 20:58:26 +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;
|
|
|
|
}
|
|
|
|
|
2019-06-03 12:37:12 +00:00
|
|
|
virtual nsresult PopulateJSONObject(Json::Value& aObject) override;
|
|
|
|
|
|
|
|
// 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
|
|
|
typedef mozilla::BasePrincipal::KeyValT<SerializableKeys> KeyVal;
|
|
|
|
|
2019-06-03 12:37:12 +00:00
|
|
|
static already_AddRefed<BasePrincipal> FromProperties(
|
|
|
|
nsTArray<NullPrincipal::KeyVal>& aFields);
|
|
|
|
|
2012-03-09 09:48:50 +00:00
|
|
|
protected:
|
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;
|
|
|
|
|
2006-04-02 20:58:26 +00:00
|
|
|
nsCOMPtr<nsIURI> mURI;
|
2017-04-10 10:45:36 +00:00
|
|
|
|
|
|
|
private:
|
2020-05-28 08:55:04 +00:00
|
|
|
FRIEND_TEST(OriginAttributes, NullPrincipal);
|
|
|
|
|
2019-11-27 20:17:46 +00:00
|
|
|
// If aIsFirstParty is true, this NullPrincipal will be initialized based on
|
|
|
|
// the aOriginAttributes with FirstPartyDomain set to a unique value.
|
|
|
|
// This value is generated from mURI.path, with ".mozilla" appended at the
|
2020-05-28 08:55:04 +00:00
|
|
|
// end. aURI is used for testing purpose to assign specific UUID rather than
|
|
|
|
// random generated one.
|
|
|
|
nsresult Init(const OriginAttributes& aOriginAttributes, bool aIsFirstParty,
|
|
|
|
nsIURI* aURI = nullptr);
|
2006-04-02 20:58:26 +00:00
|
|
|
};
|
|
|
|
|
2018-07-17 19:37:48 +00:00
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_NullPrincipal_h
|