Bug 1867925 - Mark some storage-access-api tests as intermittent after wpt-sync....
[gecko.git] / caps / nsJSPrincipals.h
blob54cf5f44c03d95d90c973e50ddb79997adbca06e
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"
13 struct JSContext;
14 struct JSStructuredCloneReader;
15 struct JSStructuredCloneWriter;
17 namespace mozilla {
18 namespace ipc {
19 class PrincipalInfo;
20 } // namespace ipc
21 } // namespace mozilla
23 class nsJSPrincipals : public nsIPrincipal, public JSPrincipals {
24 public:
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,
35 uint32_t aTag,
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);
56 return self;
58 static nsJSPrincipals* get(nsIPrincipal* principal) {
59 nsJSPrincipals* self = static_cast<nsJSPrincipals*>(principal);
60 MOZ_ASSERT_IF(self, self->debugToken == DEBUG_TOKEN);
61 return self;
64 NS_IMETHOD_(MozExternalRefCountType) AddRef(void) override;
65 NS_IMETHOD_(MozExternalRefCountType) Release(void) override;
67 nsJSPrincipals() {
68 refcount = 0;
69 setDebugToken(DEBUG_TOKEN);
72 /**
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;
78 protected:
79 virtual ~nsJSPrincipals() { setDebugToken(0); }
82 #endif /* nsJSPrincipals_h__ */