Bug 1440355 [wpt PR 9634] - Updating test_element to correctly test for 'checked...
[gecko.git] / caps / SystemPrincipal.cpp
blob47e81afb75228f761d5261c0520d807327f7de4d
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 "nsIComponentManager.h"
11 #include "nsIServiceManager.h"
12 #include "nsIURL.h"
13 #include "nsCOMPtr.h"
14 #include "nsReadableUtils.h"
15 #include "nsCRT.h"
16 #include "nsString.h"
17 #include "nsIClassInfoImpl.h"
18 #include "nsIScriptSecurityManager.h"
19 #include "pratom.h"
21 NS_IMPL_CLASSINFO(SystemPrincipal, nullptr,
22 nsIClassInfo::SINGLETON | nsIClassInfo::MAIN_THREAD_ONLY,
23 NS_SYSTEMPRINCIPAL_CID)
24 NS_IMPL_QUERY_INTERFACE_CI(SystemPrincipal,
25 nsIPrincipal,
26 nsISerializable)
27 NS_IMPL_CI_INTERFACE_GETTER(SystemPrincipal,
28 nsIPrincipal,
29 nsISerializable)
31 #define SYSTEM_PRINCIPAL_SPEC "[System Principal]"
33 already_AddRefed<SystemPrincipal>
34 SystemPrincipal::Create()
36 RefPtr<SystemPrincipal> sp = new SystemPrincipal();
37 sp->FinishInit(NS_LITERAL_CSTRING(SYSTEM_PRINCIPAL_SPEC),
38 OriginAttributes());
39 return sp.forget();
42 nsresult
43 SystemPrincipal::GetScriptLocation(nsACString &aStr)
45 aStr.AssignLiteral(SYSTEM_PRINCIPAL_SPEC);
46 return NS_OK;
49 ///////////////////////////////////////
50 // Methods implementing nsIPrincipal //
51 ///////////////////////////////////////
53 NS_IMETHODIMP
54 SystemPrincipal::GetHashValue(uint32_t *result)
56 *result = NS_PTR_TO_INT32(this);
57 return NS_OK;
60 NS_IMETHODIMP
61 SystemPrincipal::GetURI(nsIURI** aURI)
63 *aURI = nullptr;
64 return NS_OK;
67 NS_IMETHODIMP
68 SystemPrincipal::GetCsp(nsIContentSecurityPolicy** aCsp)
70 *aCsp = nullptr;
71 return NS_OK;
74 NS_IMETHODIMP
75 SystemPrincipal::SetCsp(nsIContentSecurityPolicy* aCsp)
77 // Never destroy an existing CSP on the principal.
78 // This method should only be called in rare cases.
80 return NS_ERROR_FAILURE;
83 NS_IMETHODIMP
84 SystemPrincipal::EnsureCSP(nsIDOMDocument* aDocument,
85 nsIContentSecurityPolicy** aCSP)
87 // CSP on a system principal makes no sense
88 return NS_ERROR_FAILURE;
91 NS_IMETHODIMP
92 SystemPrincipal::GetPreloadCsp(nsIContentSecurityPolicy** aPreloadCSP)
94 *aPreloadCSP = nullptr;
95 return NS_OK;
98 NS_IMETHODIMP
99 SystemPrincipal::EnsurePreloadCSP(nsIDOMDocument* aDocument,
100 nsIContentSecurityPolicy** aPreloadCSP)
102 // CSP on a system principal makes no sense
103 return NS_OK;
106 NS_IMETHODIMP
107 SystemPrincipal::GetDomain(nsIURI** aDomain)
109 *aDomain = nullptr;
110 return NS_OK;
113 NS_IMETHODIMP
114 SystemPrincipal::SetDomain(nsIURI* aDomain)
116 return NS_OK;
119 NS_IMETHODIMP
120 SystemPrincipal::GetBaseDomain(nsACString& aBaseDomain)
122 // No base domain for chrome.
123 return NS_OK;
126 NS_IMETHODIMP
127 SystemPrincipal::GetAddonId(nsAString& aAddonId)
129 aAddonId.Truncate();
130 return NS_OK;
133 //////////////////////////////////////////
134 // Methods implementing nsISerializable //
135 //////////////////////////////////////////
137 NS_IMETHODIMP
138 SystemPrincipal::Read(nsIObjectInputStream* aStream)
140 // no-op: CID is sufficient to identify the mSystemPrincipal singleton
141 return NS_OK;
144 NS_IMETHODIMP
145 SystemPrincipal::Write(nsIObjectOutputStream* aStream)
147 // no-op: CID is sufficient to identify the mSystemPrincipal singleton
148 return NS_OK;