// Copyright 2021 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 "mojo/public/mojom/base/byte_size.mojom";
import "mojo/public/mojom/base/time.mojom";
import "services/network/public/mojom/blocked_by_response_reason.mojom";
import "services/network/public/mojom/cors.mojom";
import "services/network/public/mojom/network_param.mojom";
import "services/network/public/mojom/ssl_info.mojom";
import "services/network/public/mojom/trust_tokens.mojom";

// Unlike structs, enums are not nullable, so we wrap this enum in a struct.
struct BlockedByResponseReasonWrapper {
  // More detailed reason for failing the response with
  // net::ERR_BLOCKED_BY_RESPONSE |error_code|.
  BlockedByResponseReason reason;
};

struct URLLoaderCompletionStatus {
  // The error code. ERR_FAILED is set for CORS errors.
  int32 error_code = 0;

  // Extra detail on the error.
  int32 extended_error_code = 0;

  // A copy of the data requested exists in the disk cache and/or the in-memory
  // cache.
  // TODO(crbug.com/40230090): Rename this field to `exists_in_any_cache`
  // to represent what this field actually means.
  bool exists_in_cache = false;

  // Time the request completed.
  mojo_base.mojom.TimeTicks completion_time;

  // Total amount of data received from the network.
  mojo_base.mojom.ByteSize encoded_data_length;

  // The length of the response body before removing any content encodings.
  mojo_base.mojom.ByteSize encoded_body_length;

  // The length of the response body after decoding.
  mojo_base.mojom.ByteSize decoded_body_length;

  // Optional CORS error details.
  CorsErrorStatus? cors_error_status;

  // Optional Trust Tokens (https://github.com/wicg/trust-token-api) error
  // details.
  //
  // A non-kOk value denotes that the request failed because a Trust Tokens
  // operation was attempted and failed for the given reason.
  //
  // The status is set to kOk in all other cases. In particular, a value of kOk
  // does not imply that a Trust Tokens operation was executed successfully
  // alongside this request, or even that a Trust Tokens operation was
  // attempted.
  TrustTokenOperationStatus trust_token_operation_status =
      TrustTokenOperationStatus.kOk;

  // Optional SSL certificate info.
  SSLInfo? ssl_info;

  // Only set when |error_code| is |ERR_BLOCKED_BY_RESPONSE|.
  BlockedByResponseReasonWrapper? blocked_by_response_reason;

  // Set when response blocked by ORB needs to be reported to the DevTools
  // console.
  bool should_report_orb_blocking = false;

  // Host resolution error info for this request.
  ResolveErrorInfo resolve_error_info;

  // Whether the initiator of this request should be collapsed.
  bool should_collapse_initiator = false;
};
