1 /* -*- Mode: C++; tab-width: 2; 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 /* describes principals by their orginating uris*/
7 #ifndef nsJSPrincipals_h__
8 #define nsJSPrincipals_h__
10 #include "js/Principals.h"
11 #include "nsIPrincipal.h"
14 struct JSStructuredCloneReader
;
15 struct JSStructuredCloneWriter
;
21 } // namespace mozilla
23 class nsJSPrincipals
: public nsIPrincipal
, public JSPrincipals
{
25 /* SpiderMonkey security callbacks. */
26 static bool Subsume(JSPrincipals
* jsprin
, JSPrincipals
* other
);
27 static void Destroy(JSPrincipals
* jsprin
);
29 /* JSReadPrincipalsOp for nsJSPrincipals */
30 static bool ReadPrincipals(JSContext
* aCx
, JSStructuredCloneReader
* aReader
,
31 JSPrincipals
** aOutPrincipals
);
33 static bool ReadKnownPrincipalType(JSContext
* aCx
,
34 JSStructuredCloneReader
* aReader
,
36 JSPrincipals
** aOutPrincipals
);
38 static bool ReadPrincipalInfo(JSStructuredCloneReader
* aReader
,
39 mozilla::ipc::PrincipalInfo
& aInfo
);
41 /* For write() implementations of off-main-thread JSPrincipals. */
42 static bool WritePrincipalInfo(JSStructuredCloneWriter
* aWriter
,
43 const mozilla::ipc::PrincipalInfo
& aInfo
);
45 bool write(JSContext
* aCx
, JSStructuredCloneWriter
* aWriter
) final
;
47 bool isSystemOrAddonPrincipal() final
;
50 * Get a weak reference to nsIPrincipal associated with the given JS
51 * principal, and vice-versa.
53 static nsJSPrincipals
* get(JSPrincipals
* principals
) {
54 nsJSPrincipals
* self
= static_cast<nsJSPrincipals
*>(principals
);
55 MOZ_ASSERT_IF(self
, self
->debugToken
== DEBUG_TOKEN
);
58 static nsJSPrincipals
* get(nsIPrincipal
* principal
) {
59 nsJSPrincipals
* self
= static_cast<nsJSPrincipals
*>(principal
);
60 MOZ_ASSERT_IF(self
, self
->debugToken
== DEBUG_TOKEN
);
64 NS_IMETHOD_(MozExternalRefCountType
) AddRef(void) override
;
65 NS_IMETHOD_(MozExternalRefCountType
) Release(void) override
;
69 setDebugToken(DEBUG_TOKEN
);
73 * Return a string that can be used as JS script filename in error reports.
75 virtual nsresult
GetScriptLocation(nsACString
& aStr
) = 0;
76 static const uint32_t DEBUG_TOKEN
= 0x0bf41760;
79 virtual ~nsJSPrincipals() { setDebugToken(0); }
82 #endif /* nsJSPrincipals_h__ */