/src/mozilla-central/caps/nsJSPrincipals.h
Line | Count | Source |
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 | 4.87M | static nsJSPrincipals* get(JSPrincipals *principals) { |
35 | 4.87M | nsJSPrincipals *self = static_cast<nsJSPrincipals *>(principals); |
36 | 4.87M | MOZ_ASSERT_IF(self, self->debugToken == DEBUG_TOKEN); |
37 | 4.87M | return self; |
38 | 4.87M | } |
39 | 6 | static nsJSPrincipals* get(nsIPrincipal *principal) { |
40 | 6 | nsJSPrincipals *self = static_cast<nsJSPrincipals *>(principal); |
41 | 6 | MOZ_ASSERT_IF(self, self->debugToken == DEBUG_TOKEN); |
42 | 6 | return self; |
43 | 6 | } |
44 | | |
45 | | NS_IMETHOD_(MozExternalRefCountType) AddRef(void) override; |
46 | | NS_IMETHOD_(MozExternalRefCountType) Release(void) override; |
47 | | |
48 | 5.78k | nsJSPrincipals() { |
49 | 5.78k | refcount = 0; |
50 | 5.78k | setDebugToken(DEBUG_TOKEN); |
51 | 5.78k | } |
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 | 5.77k | virtual ~nsJSPrincipals() { |
61 | 5.77k | setDebugToken(0); |
62 | 5.77k | } |
63 | | |
64 | | }; |
65 | | |
66 | | #endif /* nsJSPrincipals_h__ */ |