tor-browser

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

ClientPrincipalUtils.cpp (1514B)


      1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
      3 /* This Source Code Form is subject to the terms of the Mozilla Public
      4 * License, v. 2.0. If a copy of the MPL was not distributed with this
      5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      6 
      7 #include "ClientPrincipalUtils.h"
      8 
      9 #include "mozilla/ipc/PBackgroundSharedTypes.h"
     10 
     11 namespace mozilla::dom {
     12 
     13 using mozilla::ipc::ContentPrincipalInfo;
     14 using mozilla::ipc::PrincipalInfo;
     15 
     16 bool ClientMatchPrincipalInfo(const PrincipalInfo& aLeft,
     17                              const PrincipalInfo& aRight) {
     18  if (aLeft.type() != aRight.type()) {
     19    return false;
     20  }
     21 
     22  switch (aLeft.type()) {
     23    case PrincipalInfo::TContentPrincipalInfo: {
     24      const ContentPrincipalInfo& leftContent =
     25          aLeft.get_ContentPrincipalInfo();
     26      const ContentPrincipalInfo& rightContent =
     27          aRight.get_ContentPrincipalInfo();
     28      return leftContent.attrs() == rightContent.attrs() &&
     29             leftContent.originNoSuffix() == rightContent.originNoSuffix();
     30    }
     31    case PrincipalInfo::TSystemPrincipalInfo: {
     32      // system principal always matches
     33      return true;
     34    }
     35    case PrincipalInfo::TNullPrincipalInfo: {
     36      // null principal never matches
     37      return false;
     38    }
     39    default: {
     40      break;
     41    }
     42  }
     43 
     44  // Clients (windows/workers) should never have an expanded principal type.
     45  MOZ_CRASH("unexpected principal type!");
     46 }
     47 
     48 }  // namespace mozilla::dom