Line data Source code
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*/
6 :
7 : #ifndef nsJSPrincipals_h__
8 : #define nsJSPrincipals_h__
9 : #include "jsapi.h"
10 : #include "nsIPrincipal.h"
11 :
12 : class nsJSPrincipals : public nsIPrincipal, public JSPrincipals
13 : {
14 : public:
15 : /* SpiderMonkey security callbacks. */
16 : static bool Subsume(JSPrincipals *jsprin, JSPrincipals *other);
17 : static void Destroy(JSPrincipals *jsprin);
18 :
19 : /* JSReadPrincipalsOp for nsJSPrincipals */
20 : static bool ReadPrincipals(JSContext* aCx, JSStructuredCloneReader* aReader,
21 : JSPrincipals** aOutPrincipals);
22 :
23 : static bool ReadKnownPrincipalType(JSContext* aCx,
24 : JSStructuredCloneReader* aReader,
25 : uint32_t aTag,
26 : JSPrincipals** aOutPrincipals);
27 :
28 : bool write(JSContext* aCx, JSStructuredCloneWriter* aWriter) final;
29 :
30 : /*
31 : * Get a weak reference to nsIPrincipal associated with the given JS
32 : * principal, and vice-versa.
33 : */
34 83310 : static nsJSPrincipals* get(JSPrincipals *principals) {
35 83310 : nsJSPrincipals *self = static_cast<nsJSPrincipals *>(principals);
36 83310 : MOZ_ASSERT_IF(self, self->debugToken == DEBUG_TOKEN);
37 83310 : return self;
38 : }
39 298 : static nsJSPrincipals* get(nsIPrincipal *principal) {
40 298 : nsJSPrincipals *self = static_cast<nsJSPrincipals *>(principal);
41 298 : MOZ_ASSERT_IF(self, self->debugToken == DEBUG_TOKEN);
42 298 : return self;
43 : }
44 :
45 : NS_IMETHOD_(MozExternalRefCountType) AddRef(void) override;
46 : NS_IMETHOD_(MozExternalRefCountType) Release(void) override;
47 :
48 343 : nsJSPrincipals() {
49 343 : refcount = 0;
50 343 : setDebugToken(DEBUG_TOKEN);
51 343 : }
52 :
53 : /**
54 : * Return a string that can be used as JS script filename in error reports.
55 : */
56 : virtual nsresult GetScriptLocation(nsACString &aStr) = 0;
57 : static const uint32_t DEBUG_TOKEN = 0x0bf41760;
58 :
59 : protected:
60 354 : virtual ~nsJSPrincipals() {
61 177 : setDebugToken(0);
62 177 : }
63 :
64 : };
65 :
66 : #endif /* nsJSPrincipals_h__ */
|