tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

nsJSPrincipals.h (2778B)


      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 
     10 #include "js/Principals.h"
     11 #include "nsIPrincipal.h"
     12 
     13 struct JSContext;
     14 struct JSStructuredCloneReader;
     15 struct JSStructuredCloneWriter;
     16 
     17 namespace mozilla {
     18 namespace ipc {
     19 class PrincipalInfo;
     20 }  // namespace ipc
     21 }  // namespace mozilla
     22 
     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);
     28 
     29  /* JSReadPrincipalsOp for nsJSPrincipals */
     30  static bool ReadPrincipals(JSContext* aCx, JSStructuredCloneReader* aReader,
     31                             JSPrincipals** aOutPrincipals);
     32 
     33  static bool ReadKnownPrincipalType(JSContext* aCx,
     34                                     JSStructuredCloneReader* aReader,
     35                                     uint32_t aTag,
     36                                     JSPrincipals** aOutPrincipals);
     37 
     38  static bool ReadPrincipalInfo(JSStructuredCloneReader* aReader,
     39                                mozilla::ipc::PrincipalInfo& aInfo);
     40 
     41  /* For write() implementations of off-main-thread JSPrincipals. */
     42  static bool WritePrincipalInfo(JSStructuredCloneWriter* aWriter,
     43                                 const mozilla::ipc::PrincipalInfo& aInfo);
     44 
     45  bool write(JSContext* aCx, JSStructuredCloneWriter* aWriter) final;
     46 
     47  bool isSystemOrAddonPrincipal() final;
     48 
     49  /*
     50   * Get a weak reference to nsIPrincipal associated with the given JS
     51   * principal, and vice-versa.
     52   */
     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;
     57  }
     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;
     62  }
     63 
     64  NS_IMETHOD_(MozExternalRefCountType) AddRef(void) override;
     65  NS_IMETHOD_(MozExternalRefCountType) Release(void) override;
     66 
     67  nsJSPrincipals() {
     68    refcount = 0;
     69    setDebugToken(DEBUG_TOKEN);
     70  }
     71 
     72  /**
     73   * Return a string that can be used as JS script filename in error reports.
     74   */
     75  virtual nsresult GetScriptLocation(nsACString& aStr) = 0;
     76  static const uint32_t DEBUG_TOKEN = 0x0bf41760;
     77 
     78 protected:
     79  virtual ~nsJSPrincipals() { setDebugToken(0); }
     80 };
     81 
     82 #endif /* nsJSPrincipals_h__ */