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.
|
|
|
|
*/
|
|
|
|
|
2017-03-22 13:38:40 +03:00
|
|
|
#ifndef NullPrincipal_h
|
|
|
|
#define 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"
|
2013-11-23 03:12:00 +04:00
|
|
|
#include "nsIContentSecurityPolicy.h"
|
2006-04-03 00:58:26 +04:00
|
|
|
|
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;
|
|
|
|
|
|
|
|
#define NS_NULLPRINCIPAL_CID \
|
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"
|
|
|
|
|
2017-03-22 13:38:40 +03:00
|
|
|
class NullPrincipal final : public mozilla::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-03-22 13:38:40 +03:00
|
|
|
NullPrincipal()
|
2017-02-24 05:33:40 +03:00
|
|
|
: 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;
|
2015-05-12 00:36:56 +03:00
|
|
|
NS_IMETHOD GetHashValue(uint32_t* aHashValue) override;
|
2017-01-30 16:09:37 +03:00
|
|
|
NS_IMETHOD SetCsp(nsIContentSecurityPolicy* aCsp) 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
|
|
|
|
2017-03-22 13:38:40 +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(nsIDocShell* aDocShell, bool aIsFirstParty = false);
|
2014-07-29 19:47:52 +04:00
|
|
|
|
2017-03-22 13:38:40 +03:00
|
|
|
static already_AddRefed<NullPrincipal>
|
2018-03-22 21:36:20 +03:00
|
|
|
Create(const mozilla::OriginAttributes& aOriginAttributes,
|
2016-11-30 17:13:27 +03:00
|
|
|
nsIURI* aURI = nullptr);
|
2015-03-31 20:11:00 +03:00
|
|
|
|
2018-03-22 21:36:20 +03:00
|
|
|
static already_AddRefed<NullPrincipal>
|
|
|
|
CreateWithoutOriginAttributes();
|
|
|
|
|
2017-01-12 19:38:48 +03:00
|
|
|
nsresult Init(const mozilla::OriginAttributes& aOriginAttributes = mozilla::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
|
|
|
|
|
|
|
protected:
|
2017-03-22 13:38:40 +03:00
|
|
|
virtual ~NullPrincipal() = default;
|
2006-04-03 00:58:26 +04:00
|
|
|
|
2015-05-14 21:15:56 +03:00
|
|
|
bool SubsumesInternal(nsIPrincipal* aOther, DocumentDomainConsideration aConsideration) override
|
|
|
|
{
|
|
|
|
return aOther == this;
|
|
|
|
}
|
|
|
|
|
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.
|
|
|
|
nsresult Init(const mozilla::OriginAttributes& aOriginAttributes, bool aIsFirstParty);
|
2006-04-03 00:58:26 +04:00
|
|
|
};
|
|
|
|
|
2017-03-22 13:38:40 +03:00
|
|
|
#endif // NullPrincipal_h__
|