author Mike Hommey <>
Fri, 11 Jan 2019 16:01:15 +0000
changeset 453570 daf50f25895db073e44d50fecf2e4f6fe873865d
parent 448947 6f3709b3878117466168c40affa7bca0b60cf75b
child 458525 ef4325327e46517ba3cfd72a9b4e02c6ccbf9080
permissions -rw-r--r--
Bug 1519307 - Add a new project to build useful parts of breakpad independently. r=froydnj With `ac_add_options --enable-project=tools/crashreporter` in a mozconfig, `./mach build` builds minidump_stackwalk, dump_syms and fileid. One caveat is that due to limitation in how the build system works currently, it's cumbersome to keep dump_syms as a host program for Gecko, and to make it a target program for this project. For now, keep it as a host program. We're not going to use it on automation, but it's still convenient to have for quick local builds (I've had to resort to awful hacks downstream). Differential Revision:

/* -*- 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 */

 * This is the principal that has no rights and can't be accessed by
 * anything other than itself and chrome; null principals are not
 * same-origin with anything but themselves.

#ifndef mozilla_NullPrincipal_h
#define mozilla_NullPrincipal_h

#include "nsIPrincipal.h"
#include "nsJSPrincipals.h"
#include "nsIScriptSecurityManager.h"
#include "nsCOMPtr.h"
#include "nsIContentSecurityPolicy.h"

#include "mozilla/BasePrincipal.h"

class nsIDocShell;
class nsIURI;

#define NS_NULLPRINCIPAL_CID                         \
  {                                                  \
    0xbd066e5f, 0x146f, 0x4472, {                    \
      0x83, 0x31, 0x7b, 0xfd, 0x05, 0xb1, 0xed, 0x90 \
    }                                                \

#define NS_NULLPRINCIPAL_SCHEME "moz-nullprincipal"

namespace mozilla {

class NullPrincipal final : public BasePrincipal {
  // This should only be used by deserialization, and the factory constructor.
  // Other consumers should use the Create and CreateWithInheritedAttributes
  // methods.
  NullPrincipal() : BasePrincipal(eNullPrincipal) {}

  static PrincipalKind Kind() { return eNullPrincipal; }


  NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr) override;
  uint32_t GetHashValue() override;
  NS_IMETHOD SetCsp(nsIContentSecurityPolicy* aCsp) override;
  NS_IMETHOD GetURI(nsIURI** aURI) override;
  NS_IMETHOD GetDomain(nsIURI** aDomain) override;
  NS_IMETHOD SetDomain(nsIURI* aDomain) override;
  NS_IMETHOD GetBaseDomain(nsACString& aBaseDomain) override;
  NS_IMETHOD GetAddonId(nsAString& aAddonId) override;

  static already_AddRefed<NullPrincipal> CreateWithInheritedAttributes(
      nsIPrincipal* aInheritFrom);

  // Create NullPrincipal with origin attributes from docshell.
  // If aIsFirstParty is true, and the pref 'privacy.firstparty.isolate' is also
  // enabled, the mFirstPartyDomain value of the origin attributes will be set
  // to an unique value.
  static already_AddRefed<NullPrincipal> CreateWithInheritedAttributes(
      nsIDocShell* aDocShell, bool aIsFirstParty = false);
  static already_AddRefed<NullPrincipal> CreateWithInheritedAttributes(
      const OriginAttributes& aOriginAttributes, bool aIsFirstParty = false);

  static already_AddRefed<NullPrincipal> Create(
      const OriginAttributes& aOriginAttributes, nsIURI* aURI = nullptr);

  static already_AddRefed<NullPrincipal> CreateWithoutOriginAttributes();

  nsresult Init(const OriginAttributes& aOriginAttributes = OriginAttributes(),
                nsIURI* aURI = nullptr);

  virtual nsresult GetScriptLocation(nsACString& aStr) override;

  nsresult GetSiteIdentifier(SiteIdentifier& aSite) override {
    return NS_OK;

  virtual ~NullPrincipal() = default;

  bool SubsumesInternal(nsIPrincipal* aOther,
                        DocumentDomainConsideration aConsideration) override {
    return aOther == this;

  bool MayLoadInternal(nsIURI* aURI) override;

  nsCOMPtr<nsIURI> mURI;

  // If aIsFirstParty is true, this NullPrincipal will be initialized base on
  // the aOriginAttributes with FirstPartyDomain set to an unique value, and
  // this value is generated from mURI.path, with ".mozilla" appending at the
  // end.
  nsresult Init(const OriginAttributes& aOriginAttributes, bool aIsFirstParty);

}  // namespace mozilla

#endif  // mozilla_NullPrincipal_h