author Mozilla Releng Treescript <>
Wed, 08 Apr 2020 13:00:07 +0000
changeset 585457 4116857dfab244069ae1c4ca0785f9dc88f3405c
parent 557725 7c7ccb6e9ce55f60a540d993bb83854b7f735d36
permissions -rw-r--r--
no bug - Bumping Firefox l10n changesets r=release a=l10n-bump DONTBUILD hu -> 78684b95c459 kab -> 08cce54cefae kk -> 46f99f92cd11 ko -> b16a26a205db nl -> 6df2bf27455a oc -> 14aca8a8263a ro -> 1a02e66078fe

/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at */
/* describes principals by their orginating uris*/

#ifndef nsJSPrincipals_h__
#define nsJSPrincipals_h__
#include "jsapi.h"
#include "nsIPrincipal.h"

namespace mozilla {
namespace ipc {
class PrincipalInfo;
}  // namespace ipc
}  // namespace mozilla

class nsJSPrincipals : public nsIPrincipal, public JSPrincipals {
  /* SpiderMonkey security callbacks. */
  static bool Subsume(JSPrincipals* jsprin, JSPrincipals* other);
  static void Destroy(JSPrincipals* jsprin);

  /* JSReadPrincipalsOp for nsJSPrincipals */
  static bool ReadPrincipals(JSContext* aCx, JSStructuredCloneReader* aReader,
                             JSPrincipals** aOutPrincipals);

  static bool ReadKnownPrincipalType(JSContext* aCx,
                                     JSStructuredCloneReader* aReader,
                                     uint32_t aTag,
                                     JSPrincipals** aOutPrincipals);

  /* For write() implementations of off-main-thread JSPrincipals. */
  static bool WritePrincipalInfo(JSStructuredCloneWriter* aWriter,
                                 const mozilla::ipc::PrincipalInfo& aInfo);
  // This class is used on the main thread to specify which principal to use
  // when reading principals data that was set on a DOM worker thread.
  // DOM workers do not use principals from Gecko's point of view, and any
  // JSPrincipals used internally will be a shared singleton object. When that
  // singleton is written out and later read on the main thread, we substitute
  // the principal specified with this class.
  struct MOZ_RAII AutoSetActiveWorkerPrincipal {
    explicit AutoSetActiveWorkerPrincipal(nsIPrincipal* aPrincipal);

  bool write(JSContext* aCx, JSStructuredCloneWriter* aWriter) final;

  bool isSystemOrAddonPrincipal() final;

   * Get a weak reference to nsIPrincipal associated with the given JS
   * principal, and vice-versa.
  static nsJSPrincipals* get(JSPrincipals* principals) {
    nsJSPrincipals* self = static_cast<nsJSPrincipals*>(principals);
    MOZ_ASSERT_IF(self, self->debugToken == DEBUG_TOKEN);
    return self;
  static nsJSPrincipals* get(nsIPrincipal* principal) {
    nsJSPrincipals* self = static_cast<nsJSPrincipals*>(principal);
    MOZ_ASSERT_IF(self, self->debugToken == DEBUG_TOKEN);
    return self;

  NS_IMETHOD_(MozExternalRefCountType) AddRef(void) override;
  NS_IMETHOD_(MozExternalRefCountType) Release(void) override;

  nsJSPrincipals() {
    refcount = 0;

   * Return a string that can be used as JS script filename in error reports.
  virtual nsresult GetScriptLocation(nsACString& aStr) = 0;
  static const uint32_t DEBUG_TOKEN = 0x0bf41760;

  virtual ~nsJSPrincipals() { setDebugToken(0); }

#endif /* nsJSPrincipals_h__ */