Bug 1700051: part 30) Narrow scope of `newOffset`. r=smaug
[gecko.git] / caps / SystemPrincipal.cpp
blobddfb5c52393aa8528112ae7d4fedca144abc2a89
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 /* The privileged system principal. */
8 #include "nscore.h"
9 #include "SystemPrincipal.h"
10 #include "nsCOMPtr.h"
11 #include "nsReadableUtils.h"
12 #include "nsCRT.h"
13 #include "nsString.h"
14 #include "nsIClassInfoImpl.h"
15 #include "pratom.h"
17 using namespace mozilla;
19 NS_IMPL_CLASSINFO(SystemPrincipal, nullptr,
20 nsIClassInfo::SINGLETON | nsIClassInfo::MAIN_THREAD_ONLY,
21 NS_SYSTEMPRINCIPAL_CID)
22 NS_IMPL_QUERY_INTERFACE_CI(SystemPrincipal, nsIPrincipal, nsISerializable)
23 NS_IMPL_CI_INTERFACE_GETTER(SystemPrincipal, nsIPrincipal, nsISerializable)
25 #define SYSTEM_PRINCIPAL_SPEC "[System Principal]"
27 already_AddRefed<SystemPrincipal> SystemPrincipal::Create() {
28 RefPtr<SystemPrincipal> sp = new SystemPrincipal();
29 sp->FinishInit(nsLiteralCString(SYSTEM_PRINCIPAL_SPEC), OriginAttributes());
30 return sp.forget();
33 nsresult SystemPrincipal::GetScriptLocation(nsACString& aStr) {
34 aStr.AssignLiteral(SYSTEM_PRINCIPAL_SPEC);
35 return NS_OK;
38 ///////////////////////////////////////
39 // Methods implementing nsIPrincipal //
40 ///////////////////////////////////////
42 uint32_t SystemPrincipal::GetHashValue() { return NS_PTR_TO_INT32(this); }
44 NS_IMETHODIMP
45 SystemPrincipal::GetURI(nsIURI** aURI) {
46 *aURI = nullptr;
47 return NS_OK;
50 NS_IMETHODIMP
51 SystemPrincipal::GetIsOriginPotentiallyTrustworthy(bool* aResult) {
52 *aResult = true;
53 return NS_OK;
56 NS_IMETHODIMP
57 SystemPrincipal::GetDomain(nsIURI** aDomain) {
58 *aDomain = nullptr;
59 return NS_OK;
62 NS_IMETHODIMP
63 SystemPrincipal::SetDomain(nsIURI* aDomain) { return NS_OK; }
65 NS_IMETHODIMP
66 SystemPrincipal::GetBaseDomain(nsACString& aBaseDomain) {
67 // No base domain for chrome.
68 return NS_OK;
71 NS_IMETHODIMP
72 SystemPrincipal::GetAddonId(nsAString& aAddonId) {
73 aAddonId.Truncate();
74 return NS_OK;
77 //////////////////////////////////////////
78 // Methods implementing nsISerializable //
79 //////////////////////////////////////////
81 NS_IMETHODIMP
82 SystemPrincipal::Read(nsIObjectInputStream* aStream) {
83 // no-op: CID is sufficient to identify the mSystemPrincipal singleton
84 return NS_OK;
87 NS_IMETHODIMP
88 SystemPrincipal::Write(nsIObjectOutputStream* aStream) {
89 // Read is used still for legacy principals
90 MOZ_RELEASE_ASSERT(false, "Old style serialization is removed");
91 return NS_OK;