2015-05-11 14:25:59 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
|
|
/* 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/. */
|
|
|
|
|
|
|
|
#ifndef mozilla_BasePrincipal_h
|
|
|
|
#define mozilla_BasePrincipal_h
|
|
|
|
|
|
|
|
#include "nsIPrincipal.h"
|
2015-05-13 18:25:40 -07:00
|
|
|
#include "nsIScriptSecurityManager.h"
|
2015-05-11 14:25:59 -07:00
|
|
|
#include "nsJSPrincipals.h"
|
|
|
|
|
2015-06-02 23:35:09 -07:00
|
|
|
#include "mozilla/dom/ChromeUtilsBinding.h"
|
2015-05-14 16:24:25 -07:00
|
|
|
|
2015-06-04 11:51:57 -07:00
|
|
|
class nsIContentSecurityPolicy;
|
2015-05-14 13:56:37 -07:00
|
|
|
class nsIObjectOutputStream;
|
|
|
|
class nsIObjectInputStream;
|
|
|
|
|
2015-05-11 14:25:59 -07:00
|
|
|
namespace mozilla {
|
|
|
|
|
2015-05-15 13:43:11 -07:00
|
|
|
class OriginAttributes : public dom::OriginAttributesDictionary
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
OriginAttributes() {}
|
|
|
|
OriginAttributes(uint32_t aAppId, bool aInBrowser)
|
|
|
|
{
|
|
|
|
mAppId = aAppId;
|
|
|
|
mInBrowser = aInBrowser;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator==(const OriginAttributes& aOther) const
|
|
|
|
{
|
|
|
|
return mAppId == aOther.mAppId &&
|
|
|
|
mInBrowser == aOther.mInBrowser;
|
|
|
|
}
|
|
|
|
bool operator!=(const OriginAttributes& aOther) const
|
|
|
|
{
|
|
|
|
return !(*this == aOther);
|
|
|
|
}
|
|
|
|
|
2015-06-04 11:51:57 -07:00
|
|
|
// Serializes/Deserializes non-default values into the suffix format, i.e.
|
2015-05-15 13:43:11 -07:00
|
|
|
// |!key1=value1&key2=value2|. If there are no non-default attributes, this
|
|
|
|
// returns an empty string.
|
2015-06-03 01:43:43 -07:00
|
|
|
void CreateSuffix(nsACString& aStr) const;
|
2015-06-04 11:51:57 -07:00
|
|
|
bool PopulateFromSuffix(const nsACString& aStr);
|
2015-05-15 13:43:11 -07:00
|
|
|
};
|
|
|
|
|
2015-05-11 14:25:59 -07:00
|
|
|
/*
|
|
|
|
* Base class from which all nsIPrincipal implementations inherit. Use this for
|
|
|
|
* default implementations and other commonalities between principal
|
|
|
|
* implementations.
|
|
|
|
*
|
|
|
|
* We should merge nsJSPrincipals into this class at some point.
|
|
|
|
*/
|
|
|
|
class BasePrincipal : public nsJSPrincipals
|
|
|
|
{
|
|
|
|
public:
|
2015-06-04 11:51:57 -07:00
|
|
|
BasePrincipal();
|
2015-05-13 18:25:40 -07:00
|
|
|
|
2015-05-14 11:15:56 -07:00
|
|
|
enum DocumentDomainConsideration { DontConsiderDocumentDomain, ConsiderDocumentDomain};
|
|
|
|
bool Subsumes(nsIPrincipal* aOther, DocumentDomainConsideration aConsideration);
|
|
|
|
|
2015-05-14 16:50:44 -07:00
|
|
|
NS_IMETHOD GetOrigin(nsACString& aOrigin) final;
|
2015-05-14 16:55:52 -07:00
|
|
|
NS_IMETHOD GetOriginNoSuffix(nsACString& aOrigin) final;
|
2015-05-14 11:15:56 -07:00
|
|
|
NS_IMETHOD Equals(nsIPrincipal* other, bool* _retval) final;
|
|
|
|
NS_IMETHOD EqualsConsideringDomain(nsIPrincipal* other, bool* _retval) final;
|
|
|
|
NS_IMETHOD Subsumes(nsIPrincipal* other, bool* _retval) final;
|
|
|
|
NS_IMETHOD SubsumesConsideringDomain(nsIPrincipal* other, bool* _retval) final;
|
2015-05-15 14:54:21 -07:00
|
|
|
NS_IMETHOD GetCsp(nsIContentSecurityPolicy** aCsp) override;
|
|
|
|
NS_IMETHOD SetCsp(nsIContentSecurityPolicy* aCsp) override;
|
2015-05-21 11:16:04 -07:00
|
|
|
NS_IMETHOD GetCspJSON(nsAString& outCSPinJSON) override;
|
2015-05-11 14:36:56 -07:00
|
|
|
NS_IMETHOD GetIsNullPrincipal(bool* aIsNullPrincipal) override;
|
2015-05-13 18:25:40 -07:00
|
|
|
NS_IMETHOD GetJarPrefix(nsACString& aJarPrefix) final;
|
2015-05-14 16:24:25 -07:00
|
|
|
NS_IMETHOD GetOriginAttributes(JSContext* aCx, JS::MutableHandle<JS::Value> aVal) final;
|
|
|
|
NS_IMETHOD GetOriginSuffix(nsACString& aOriginSuffix) final;
|
2015-05-18 22:00:07 -07:00
|
|
|
NS_IMETHOD GetCookieJar(nsACString& aCookieJar) final;
|
2015-05-13 18:25:40 -07:00
|
|
|
NS_IMETHOD GetAppStatus(uint16_t* aAppStatus) final;
|
|
|
|
NS_IMETHOD GetAppId(uint32_t* aAppStatus) final;
|
|
|
|
NS_IMETHOD GetIsInBrowserElement(bool* aIsInBrowserElement) final;
|
|
|
|
NS_IMETHOD GetUnknownAppId(bool* aUnknownAppId) final;
|
2015-05-11 14:36:56 -07:00
|
|
|
|
|
|
|
virtual bool IsOnCSSUnprefixingWhitelist() override { return false; }
|
2015-05-11 14:25:59 -07:00
|
|
|
|
2015-06-03 13:40:46 -07:00
|
|
|
virtual bool IsCodebasePrincipal() const { return false; };
|
2015-06-03 01:43:43 -07:00
|
|
|
|
2015-05-14 11:15:56 -07:00
|
|
|
static BasePrincipal* Cast(nsIPrincipal* aPrin) { return static_cast<BasePrincipal*>(aPrin); }
|
2015-05-15 13:43:11 -07:00
|
|
|
static already_AddRefed<BasePrincipal> CreateCodebasePrincipal(nsIURI* aURI, OriginAttributes& aAttrs);
|
2015-05-14 12:24:03 -07:00
|
|
|
|
|
|
|
const OriginAttributes& OriginAttributesRef() { return mOriginAttributes; }
|
|
|
|
uint32_t AppId() const { return mOriginAttributes.mAppId; }
|
2015-05-14 16:24:25 -07:00
|
|
|
bool IsInBrowserElement() const { return mOriginAttributes.mInBrowser; }
|
2015-05-14 12:24:03 -07:00
|
|
|
|
2015-05-11 14:25:59 -07:00
|
|
|
protected:
|
2015-06-04 11:51:57 -07:00
|
|
|
virtual ~BasePrincipal();
|
2015-05-11 14:25:59 -07:00
|
|
|
|
2015-05-14 16:50:44 -07:00
|
|
|
virtual nsresult GetOriginInternal(nsACString& aOrigin) = 0;
|
2015-05-14 11:15:56 -07:00
|
|
|
virtual bool SubsumesInternal(nsIPrincipal* aOther, DocumentDomainConsideration aConsider) = 0;
|
|
|
|
|
2015-05-11 14:25:59 -07:00
|
|
|
nsCOMPtr<nsIContentSecurityPolicy> mCSP;
|
2015-05-14 12:24:03 -07:00
|
|
|
OriginAttributes mOriginAttributes;
|
2015-05-11 14:25:59 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif /* mozilla_BasePrincipal_h */
|