// Copyright 2020 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/cross_origin_embedder_policy.mojom";
import "services/network/public/mojom/document_isolation_policy.mojom";
import "services/network/public/mojom/ip_address_space.mojom";

// How to treat local network access requests.
//
// Local network access requests are requests from a less-private IP address
// space to a more-private IP address space. Concretely:
//
//  - unknown to private
//  - unknown to local
//  - public to private
//  - public to local
//  - private to local
//
// See the Local Network Access (LNA) Spec at
// https://wicg.github.io/local-network-access/
// for more information.
enum LocalNetworkAccessRequestPolicy {
  // Allow the requests.
  kAllow,

  // Allow the requests, and display a warning in DevTools.
  kWarn,

  // Block the requests with a CORS error.
  kBlock,

  // Display a warning in devtools when a request will require user permission
  // in the future when LNA launches.
  kPermissionWarn,

  // Block requests unless the user explicitly grants permission for the
  // request to proceed.
  kPermissionBlock,
};

struct ClientSecurityState {
  // See: https://html.spec.whatwg.org/multipage/origin.html#coep
  CrossOriginEmbedderPolicy cross_origin_embedder_policy;

  // Whether the initiator of the requests is in a web secure context.
  // See: https://developer.mozilla.org/en-US/docs/Web/Security/Secure_Contexts
  bool is_web_secure_context = false;

  // The initiator's IP AddressSpace.
  IPAddressSpace ip_address_space = kUnknown;

  // The policy to apply to private network requests.
  LocalNetworkAccessRequestPolicy local_network_access_request_policy = kAllow;

  // See: https://github.com/explainers-by-googlers/document-isolation-policy
  DocumentIsolationPolicy document_isolation_policy;
};

