Bug 1704628 Part 1: Make selectContextMenuItem use .activateItem() semantics. r=ochameau
[gecko.git] / caps / nsJSPrincipals.h
blob3ec4390ef927a4a63dd27199849938029c5fdc92
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 /* For write() implementations of off-main-thread JSPrincipals. */
39 static bool WritePrincipalInfo(JSStructuredCloneWriter* aWriter,
40 const mozilla::ipc::PrincipalInfo& aInfo);
41 // This class is used on the main thread to specify which principal to use
42 // when reading principals data that was set on a DOM worker thread.
43 // DOM workers do not use principals from Gecko's point of view, and any
44 // JSPrincipals used internally will be a shared singleton object. When that
45 // singleton is written out and later read on the main thread, we substitute
46 // the principal specified with this class.
47 struct MOZ_RAII AutoSetActiveWorkerPrincipal {
48 explicit AutoSetActiveWorkerPrincipal(nsIPrincipal* aPrincipal);
49 ~AutoSetActiveWorkerPrincipal();
52 bool write(JSContext* aCx, JSStructuredCloneWriter* aWriter) final;
54 bool isSystemOrAddonPrincipal() final;
57 * Get a weak reference to nsIPrincipal associated with the given JS
58 * principal, and vice-versa.
60 static nsJSPrincipals* get(JSPrincipals* principals) {
61 nsJSPrincipals* self = static_cast<nsJSPrincipals*>(principals);
62 MOZ_ASSERT_IF(self, self->debugToken == DEBUG_TOKEN);
63 return self;
65 static nsJSPrincipals* get(nsIPrincipal* principal) {
66 nsJSPrincipals* self = static_cast<nsJSPrincipals*>(principal);
67 MOZ_ASSERT_IF(self, self->debugToken == DEBUG_TOKEN);
68 return self;
71 NS_IMETHOD_(MozExternalRefCountType) AddRef(void) override;
72 NS_IMETHOD_(MozExternalRefCountType) Release(void) override;
74 nsJSPrincipals() {
75 refcount = 0;
76 setDebugToken(DEBUG_TOKEN);
79 /**
80 * Return a string that can be used as JS script filename in error reports.
82 virtual nsresult GetScriptLocation(nsACString& aStr) = 0;
83 static const uint32_t DEBUG_TOKEN = 0x0bf41760;
85 protected:
86 virtual ~nsJSPrincipals() { setDebugToken(0); }
89 #endif /* nsJSPrincipals_h__ */