dom/clients/manager/ClientPrincipalUtils.cpp
author L10n Bumper Bot <release+l10nbumper@mozilla.com>
Sun, 15 Sep 2019 07:00:38 +0000
changeset 551773 046074b8dd770cf62961623e2ca73de03de04678
parent 527065 662b776a02e6d046b0358cb89b53c19477a4bc67
permissions -rw-r--r--
no bug - Bumping Firefox l10n changesets r=release a=l10n-bump DONTBUILD de -> c2c729a2d0f4 el -> d7b09a1e1174 ia -> edec39db2cfe it -> 07aafea57eac pt-BR -> 7c2ad2d3be07 ro -> 1036dd1d1a16

/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* 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 http://mozilla.org/MPL/2.0/. */

#include "ClientPrincipalUtils.h"

namespace mozilla {
namespace dom {

using mozilla::ipc::ContentPrincipalInfo;
using mozilla::ipc::PrincipalInfo;

bool ClientMatchPrincipalInfo(const PrincipalInfo& aLeft,
                              const PrincipalInfo& aRight) {
  if (aLeft.type() != aRight.type()) {
    return false;
  }

  switch (aLeft.type()) {
    case PrincipalInfo::TContentPrincipalInfo: {
      const ContentPrincipalInfo& leftContent =
          aLeft.get_ContentPrincipalInfo();
      const ContentPrincipalInfo& rightContent =
          aRight.get_ContentPrincipalInfo();
      return leftContent.attrs() == rightContent.attrs() &&
             leftContent.originNoSuffix() == rightContent.originNoSuffix();
    }
    case PrincipalInfo::TSystemPrincipalInfo: {
      // system principal always matches
      return true;
    }
    case PrincipalInfo::TNullPrincipalInfo: {
      // null principal never matches
      return false;
    }
    default: {
      break;
    }
  }

  // Clients (windows/workers) should never have an expanded principal type.
  MOZ_CRASH("unexpected principal type!");
}

}  // namespace dom
}  // namespace mozilla