Source code

Revision control

Other Tools

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/. */
5
6
/* The privileged system principal. */
7
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"
16
17
using namespace mozilla;
18
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)
24
25
#define SYSTEM_PRINCIPAL_SPEC "[System Principal]"
26
27
already_AddRefed<SystemPrincipal> SystemPrincipal::Create() {
28
RefPtr<SystemPrincipal> sp = new SystemPrincipal();
29
sp->FinishInit(NS_LITERAL_CSTRING(SYSTEM_PRINCIPAL_SPEC), OriginAttributes());
30
return sp.forget();
31
}
32
33
nsresult SystemPrincipal::GetScriptLocation(nsACString& aStr) {
34
aStr.AssignLiteral(SYSTEM_PRINCIPAL_SPEC);
35
return NS_OK;
36
}
37
38
///////////////////////////////////////
39
// Methods implementing nsIPrincipal //
40
///////////////////////////////////////
41
42
uint32_t SystemPrincipal::GetHashValue() { return NS_PTR_TO_INT32(this); }
43
44
NS_IMETHODIMP
45
SystemPrincipal::GetURI(nsIURI** aURI) {
46
*aURI = nullptr;
47
return NS_OK;
48
}
49
50
NS_IMETHODIMP
51
SystemPrincipal::GetIsOriginPotentiallyTrustworthy(bool* aResult) {
52
*aResult = true;
53
return NS_OK;
54
}
55
56
NS_IMETHODIMP
57
SystemPrincipal::GetDomain(nsIURI** aDomain) {
58
*aDomain = nullptr;
59
return NS_OK;
60
}
61
62
NS_IMETHODIMP
63
SystemPrincipal::SetDomain(nsIURI* aDomain) { return NS_OK; }
64
65
NS_IMETHODIMP
66
SystemPrincipal::GetBaseDomain(nsACString& aBaseDomain) {
67
// No base domain for chrome.
68
return NS_OK;
69
}
70
71
NS_IMETHODIMP
72
SystemPrincipal::GetAddonId(nsAString& aAddonId) {
73
aAddonId.Truncate();
74
return NS_OK;
75
};
76
77
//////////////////////////////////////////
78
// Methods implementing nsISerializable //
79
//////////////////////////////////////////
80
81
NS_IMETHODIMP
82
SystemPrincipal::Read(nsIObjectInputStream* aStream) {
83
// no-op: CID is sufficient to identify the mSystemPrincipal singleton
84
return NS_OK;
85
}
86
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;
92
}