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"
|
2014-07-29 19:47:52 +04:00
|
|
|
#include "nsIScriptSecurityManager.h"
|
2006-04-03 00:58:26 +04:00
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
|
2015-05-12 00:36:56 +03:00
|
|
|
#include "mozilla/BasePrincipal.h"
|
|
|
|
|
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_CONTRACTID "@mozilla.org/nullprincipal;1"
|
|
|
|
|
|
|
|
#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:
|
2015-03-31 20:11:00 +03:00
|
|
|
// This should only be used by deserialization, and the factory constructor.
|
|
|
|
// Other consumers should use the Create and CreateWithInheritedAttributes
|
|
|
|
// methods.
|
2017-02-24 05:33:40 +03:00
|
|
|
NullPrincipal() : BasePrincipal(eNullPrincipal) {}
|
2015-02-24 23:54:40 +03:00
|
|
|
|
2017-04-16 23:32:42 +03:00
|
|
|
static PrincipalKind Kind() { return eNullPrincipal; }
|
|
|
|
|
2006-04-03 00:58:26 +04:00
|
|
|
NS_DECL_NSISERIALIZABLE
|
2015-05-12 00:36:56 +03:00
|
|
|
|
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;
|
|
|
|
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();
|
|
|
|
|
2018-07-17 22:37:48 +03:00
|
|
|
nsresult Init(const OriginAttributes& aOriginAttributes = OriginAttributes(),
|
2016-11-30 17:13:27 +03:00
|
|
|
nsIURI* aURI = nullptr);
|
2006-04-03 00:58:26 +04: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
|
|
|
|
enum SerializableKeys { eSpec = 0, eSuffix, eMax = eSuffix };
|
|
|
|
// KeyVal is a lightweight storage that passes
|
|
|
|
// SerializableKeys and values after JSON parsing in the BasePrincipal to
|
|
|
|
// FromProperties
|
|
|
|
struct KeyVal {
|
|
|
|
bool valueWasSerialized;
|
|
|
|
nsCString value;
|
|
|
|
SerializableKeys key;
|
|
|
|
};
|
|
|
|
static already_AddRefed<BasePrincipal> FromProperties(
|
|
|
|
nsTArray<NullPrincipal::KeyVal>& aFields);
|
|
|
|
|
2012-03-09 13:48:50 +04:00
|
|
|
protected:
|
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;
|
|
|
|
|
2006-04-03 00:58:26 +04:00
|
|
|
nsCOMPtr<nsIURI> mURI;
|
2017-04-10 13:45:36 +03:00
|
|
|
|
|
|
|
private:
|
|
|
|
// If aIsFirstParty is true, this NullPrincipal will be initialized base on
|
|
|
|
// the aOriginAttributes with FirstPartyDomain set to an unique value, and
|
|
|
|
// this value is generated from mURI.path, with ".mozilla" appending at the
|
|
|
|
// end.
|
2018-07-17 22:37:48 +03:00
|
|
|
nsresult Init(const OriginAttributes& aOriginAttributes, bool aIsFirstParty);
|
2006-04-03 00:58:26 +04:00
|
|
|
};
|
|
|
|
|
2018-07-17 22:37:48 +03:00
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_NullPrincipal_h
|