2018-11-30 22:52:05 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 4; 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/. */
|
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"
|
2022-12-02 03:53:51 +03:00
|
|
|
#include "mozilla/ClearOnShutdown.h"
|
1999-09-01 04:54:35 +04:00
|
|
|
#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"
|
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;
|
|
|
|
|
2023-02-02 00:45:44 +03:00
|
|
|
NS_IMPL_CLASSINFO(SystemPrincipal, nullptr, nsIClassInfo::SINGLETON,
|
2010-06-22 20:59:57 +04:00
|
|
|
NS_SYSTEMPRINCIPAL_CID)
|
2017-03-22 13:39:08 +03:00
|
|
|
NS_IMPL_QUERY_INTERFACE_CI(SystemPrincipal, nsIPrincipal, nsISerializable)
|
|
|
|
NS_IMPL_CI_INTERFACE_GETTER(SystemPrincipal, nsIPrincipal, nsISerializable)
|
1999-11-12 21:59:03 +03:00
|
|
|
|
2021-05-17 23:50:09 +03:00
|
|
|
static constexpr nsLiteralCString kSystemPrincipalSpec =
|
|
|
|
"[System Principal]"_ns;
|
|
|
|
|
|
|
|
SystemPrincipal::SystemPrincipal()
|
|
|
|
: BasePrincipal(eSystemPrincipal, kSystemPrincipalSpec,
|
|
|
|
OriginAttributes()) {}
|
2012-03-09 13:48:50 +04:00
|
|
|
|
2022-12-02 03:53:51 +03:00
|
|
|
static StaticMutex sSystemPrincipalMutex;
|
|
|
|
static StaticRefPtr<SystemPrincipal> sSystemPrincipal
|
|
|
|
MOZ_GUARDED_BY(sSystemPrincipalMutex);
|
|
|
|
|
|
|
|
already_AddRefed<SystemPrincipal> SystemPrincipal::Get() {
|
|
|
|
StaticMutexAutoLock lock(sSystemPrincipalMutex);
|
|
|
|
return do_AddRef(sSystemPrincipal);
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<SystemPrincipal> SystemPrincipal::Init() {
|
|
|
|
AssertIsOnMainThread();
|
|
|
|
StaticMutexAutoLock lock(sSystemPrincipalMutex);
|
|
|
|
if (MOZ_UNLIKELY(sSystemPrincipal)) {
|
|
|
|
MOZ_ASSERT_UNREACHABLE("SystemPrincipal::Init() may only be called once");
|
|
|
|
} else {
|
|
|
|
sSystemPrincipal = new SystemPrincipal();
|
|
|
|
}
|
|
|
|
return do_AddRef(sSystemPrincipal);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SystemPrincipal::Shutdown() {
|
|
|
|
AssertIsOnMainThread();
|
|
|
|
StaticMutexAutoLock lock(sSystemPrincipalMutex);
|
|
|
|
MOZ_ASSERT(sSystemPrincipal);
|
|
|
|
sSystemPrincipal = nullptr;
|
2017-02-25 01:02:24 +03:00
|
|
|
}
|
|
|
|
|
2017-03-22 13:39:08 +03:00
|
|
|
nsresult SystemPrincipal::GetScriptLocation(nsACString& aStr) {
|
2021-05-17 23:50:09 +03:00
|
|
|
aStr.Assign(kSystemPrincipalSpec);
|
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 //
|
|
|
|
///////////////////////////////////////
|
|
|
|
|
2018-11-20 04:17:52 +03:00
|
|
|
uint32_t SystemPrincipal::GetHashValue() { return NS_PTR_TO_INT32(this); }
|
1999-09-01 04:54:35 +04:00
|
|
|
|
2017-01-30 16:09:37 +03:00
|
|
|
NS_IMETHODIMP
|
2017-03-22 13:39:08 +03:00
|
|
|
SystemPrincipal::GetURI(nsIURI** aURI) {
|
2012-07-30 18:20:58 +04:00
|
|
|
*aURI = nullptr;
|
2003-10-22 02:11:49 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2019-12-05 19:04:53 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
SystemPrincipal::GetIsOriginPotentiallyTrustworthy(bool* aResult) {
|
|
|
|
*aResult = true;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2003-10-22 02:11:49 +04:00
|
|
|
NS_IMETHODIMP
|
2017-03-22 13:39:08 +03:00
|
|
|
SystemPrincipal::GetDomain(nsIURI** aDomain) {
|
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) { return NS_OK; }
|
2003-10-22 02:11:49 +04:00
|
|
|
|
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) {
|
2019-06-03 15:37:12 +03:00
|
|
|
// Read is used still for legacy principals
|
|
|
|
MOZ_RELEASE_ASSERT(false, "Old style serialization is removed");
|
2001-07-31 23:05:34 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|