// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

module network.mojom;

import "services/network/public/mojom/permissions_policy/permissions_policy_feature.mojom";
import "url/mojom/origin.mojom";

// This struct mirrors network.mojom.CSPSource, but excludes members not used
// in permissions policies like `path`.
// Typemapped to `network::OriginWithPossibleWildcards`.
// TODO(crbug.com/40126948): Consider merging this with CSPSource as discussed
// under https://crrev.com/c/6226434/comment/28d23146_b9c83f46/
struct OriginWithPossibleWildcards {
  string scheme;
  string host;
  int32 port = -1;
  bool is_host_wildcard = false;
  bool is_port_wildcard = false;
};

// This struct holds permissions policy allowlist data that needs to be replicated
// between a RenderFrame and any of its associated RenderFrameProxies. A list of
// these form a ParsedPermissionsPolicy.
// Typemapped to `network::ParsedPermissionsPolicyDeclaration`.
// NOTE: These types are used for replication of frame state between processes.
struct ParsedPermissionsPolicyDeclaration {
  PermissionsPolicyFeature feature;
  array<OriginWithPossibleWildcards> allowed_origins;
  url.mojom.Origin? self_if_matches;
  bool matches_all_origins;
  bool matches_opaque_src;
  string? reporting_endpoint;
};

// Represents a Permissions Policy.
// Typemapped to `network::PermissionsPolicy`.
struct PermissionsPolicy {
  url.mojom.Origin origin;
  bool headerless;
  array<ParsedPermissionsPolicyDeclaration> declarations;
  // Converted to `network::PermissionsPolicyFeaturesBitset`.
  string inherited_policies;
  // `feature_list` is left out since it's an internal pointer.
};
