nsJSPrincipals.h 2.1 KB

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