2001-09-25 05:03:58 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
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/. */
|
1999-09-01 04:54:35 +04:00
|
|
|
|
|
|
|
/* The privileged system principal. */
|
|
|
|
|
2001-08-14 11:59:59 +04:00
|
|
|
#include "nscore.h"
|
2017-03-22 13:39:08 +03:00
|
|
|
#include "SystemPrincipal.h"
|
1999-09-01 04:54:35 +04:00
|
|
|
#include "nsIComponentManager.h"
|
|
|
|
#include "nsIServiceManager.h"
|
|
|
|
#include "nsIURL.h"
|
|
|
|
#include "nsCOMPtr.h"
|
2001-09-29 12:28:41 +04:00
|
|
|
#include "nsReadableUtils.h"
|
2002-05-15 22:55:21 +04:00
|
|
|
#include "nsCRT.h"
|
2003-10-22 02:11:49 +04:00
|
|
|
#include "nsString.h"
|
2006-03-15 07:59:42 +03:00
|
|
|
#include "nsIClassInfoImpl.h"
|
2012-07-20 09:44:03 +04:00
|
|
|
#include "nsIScriptSecurityManager.h"
|
2013-07-12 00:21:45 +04:00
|
|
|
#include "pratom.h"
|
1999-09-01 04:54:35 +04:00
|
|
|
|
2018-07-17 22:38:19 +03:00
|
|
|
using namespace mozilla;
|
|
|
|
|
2017-03-22 13:39:08 +03:00
|
|
|
NS_IMPL_CLASSINFO(SystemPrincipal, nullptr,
|
2010-06-22 20:59:57 +04:00
|
|
|
nsIClassInfo::SINGLETON | nsIClassInfo::MAIN_THREAD_ONLY,
|
|
|
|
NS_SYSTEMPRINCIPAL_CID)
|
2017-03-22 13:39:08 +03:00
|
|
|
NS_IMPL_QUERY_INTERFACE_CI(SystemPrincipal,
|
2014-04-27 11:06:00 +04:00
|
|
|
nsIPrincipal,
|
|
|
|
nsISerializable)
|
2017-03-22 13:39:08 +03:00
|
|
|
NS_IMPL_CI_INTERFACE_GETTER(SystemPrincipal,
|
2003-10-22 02:11:49 +04:00
|
|
|
nsIPrincipal,
|
|
|
|
nsISerializable)
|
1999-11-12 21:59:03 +03:00
|
|
|
|
2015-05-16 11:07:10 +03:00
|
|
|
#define SYSTEM_PRINCIPAL_SPEC "[System Principal]"
|
2012-03-09 13:48:50 +04:00
|
|
|
|
2017-03-22 13:39:08 +03:00
|
|
|
already_AddRefed<SystemPrincipal>
|
|
|
|
SystemPrincipal::Create()
|
2017-02-25 01:02:24 +03:00
|
|
|
{
|
2017-03-22 13:39:08 +03:00
|
|
|
RefPtr<SystemPrincipal> sp = new SystemPrincipal();
|
2017-03-29 09:22:26 +03:00
|
|
|
sp->FinishInit(NS_LITERAL_CSTRING(SYSTEM_PRINCIPAL_SPEC),
|
|
|
|
OriginAttributes());
|
2017-02-25 01:02:24 +03:00
|
|
|
return sp.forget();
|
|
|
|
}
|
|
|
|
|
2016-08-30 07:22:04 +03:00
|
|
|
nsresult
|
2017-03-22 13:39:08 +03:00
|
|
|
SystemPrincipal::GetScriptLocation(nsACString &aStr)
|
2012-03-09 13:48:50 +04:00
|
|
|
{
|
2015-05-16 11:07:10 +03:00
|
|
|
aStr.AssignLiteral(SYSTEM_PRINCIPAL_SPEC);
|
2016-08-30 07:22:04 +03:00
|
|
|
return NS_OK;
|
2012-03-09 13:48:50 +04:00
|
|
|
}
|
|
|
|
|
2003-10-22 02:11:49 +04:00
|
|
|
///////////////////////////////////////
|
|
|
|
// Methods implementing nsIPrincipal //
|
|
|
|
///////////////////////////////////////
|
|
|
|
|
1999-09-01 04:54:35 +04:00
|
|
|
NS_IMETHODIMP
|
2017-03-22 13:39:08 +03:00
|
|
|
SystemPrincipal::GetHashValue(uint32_t *result)
|
1999-09-01 04:54:35 +04:00
|
|
|
{
|
2001-08-14 11:59:59 +04:00
|
|
|
*result = NS_PTR_TO_INT32(this);
|
1999-09-01 04:54:35 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2017-01-30 16:09:37 +03:00
|
|
|
NS_IMETHODIMP
|
2017-03-22 13:39:08 +03:00
|
|
|
SystemPrincipal::GetURI(nsIURI** aURI)
|
2003-10-22 02:11:49 +04:00
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
*aURI = nullptr;
|
2003-10-22 02:11:49 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-01-23 00:38:21 +03:00
|
|
|
NS_IMETHODIMP
|
2017-03-22 13:39:08 +03:00
|
|
|
SystemPrincipal::GetCsp(nsIContentSecurityPolicy** aCsp)
|
2010-01-23 00:38:21 +03:00
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
*aCsp = nullptr;
|
2010-01-23 00:38:21 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2017-01-30 16:09:37 +03:00
|
|
|
NS_IMETHODIMP
|
2017-03-22 13:39:08 +03:00
|
|
|
SystemPrincipal::SetCsp(nsIContentSecurityPolicy* aCsp)
|
2017-01-30 16:09:37 +03:00
|
|
|
{
|
|
|
|
// Never destroy an existing CSP on the principal.
|
|
|
|
// This method should only be called in rare cases.
|
|
|
|
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2010-01-23 00:38:21 +03:00
|
|
|
NS_IMETHODIMP
|
2018-05-11 20:46:15 +03:00
|
|
|
SystemPrincipal::EnsureCSP(nsIDocument* aDocument,
|
2017-03-22 13:39:08 +03:00
|
|
|
nsIContentSecurityPolicy** aCSP)
|
2010-01-23 00:38:21 +03:00
|
|
|
{
|
2015-11-15 06:28:23 +03:00
|
|
|
// CSP on a system principal makes no sense
|
2016-05-21 20:36:24 +03:00
|
|
|
return NS_ERROR_FAILURE;
|
2015-11-15 06:28:23 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2017-03-22 13:39:08 +03:00
|
|
|
SystemPrincipal::GetPreloadCsp(nsIContentSecurityPolicy** aPreloadCSP)
|
2015-11-15 06:28:23 +03:00
|
|
|
{
|
|
|
|
*aPreloadCSP = nullptr;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2018-05-11 20:46:15 +03:00
|
|
|
SystemPrincipal::EnsurePreloadCSP(nsIDocument* aDocument,
|
2017-03-22 13:39:08 +03:00
|
|
|
nsIContentSecurityPolicy** aPreloadCSP)
|
2015-11-15 06:28:23 +03:00
|
|
|
{
|
|
|
|
// CSP on a system principal makes no sense
|
2018-10-17 08:05:55 +03:00
|
|
|
return NS_ERROR_FAILURE;
|
2010-01-23 00:38:21 +03:00
|
|
|
}
|
|
|
|
|
2003-10-22 02:11:49 +04:00
|
|
|
NS_IMETHODIMP
|
2017-03-22 13:39:08 +03:00
|
|
|
SystemPrincipal::GetDomain(nsIURI** aDomain)
|
2003-10-22 02:11:49 +04:00
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
*aDomain = nullptr;
|
2003-10-22 02:11:49 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2017-03-22 13:39:08 +03:00
|
|
|
SystemPrincipal::SetDomain(nsIURI* aDomain)
|
2003-10-22 02:11:49 +04:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-01-09 01:53:32 +04:00
|
|
|
NS_IMETHODIMP
|
2017-03-22 13:39:08 +03:00
|
|
|
SystemPrincipal::GetBaseDomain(nsACString& aBaseDomain)
|
2013-01-09 01:53:32 +04:00
|
|
|
{
|
|
|
|
// No base domain for chrome.
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2016-11-06 08:38:17 +03:00
|
|
|
NS_IMETHODIMP
|
2017-03-22 13:39:08 +03:00
|
|
|
SystemPrincipal::GetAddonId(nsAString& aAddonId)
|
2016-11-06 08:38:17 +03:00
|
|
|
{
|
|
|
|
aAddonId.Truncate();
|
|
|
|
return NS_OK;
|
|
|
|
};
|
|
|
|
|
2001-07-31 23:05:34 +04:00
|
|
|
//////////////////////////////////////////
|
|
|
|
// Methods implementing nsISerializable //
|
|
|
|
//////////////////////////////////////////
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2017-03-22 13:39:08 +03:00
|
|
|
SystemPrincipal::Read(nsIObjectInputStream* aStream)
|
2001-07-31 23:05:34 +04:00
|
|
|
{
|
|
|
|
// no-op: CID is sufficient to identify the mSystemPrincipal singleton
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2017-03-22 13:39:08 +03:00
|
|
|
SystemPrincipal::Write(nsIObjectOutputStream* aStream)
|
2001-07-31 23:05:34 +04:00
|
|
|
{
|
|
|
|
// no-op: CID is sufficient to identify the mSystemPrincipal singleton
|
|
|
|
return NS_OK;
|
|
|
|
}
|