chromium/services/network/public/mojom/devtools_observer.mojom

// 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/time.mojom";
import "mojo/public/mojom/base/unguessable_token.mojom";
import "mojo/public/mojom/base/time.mojom";
import "services/network/public/mojom/alternate_protocol_usage.mojom";
import "services/network/public/mojom/client_security_state.mojom";
import "services/network/public/mojom/cookie_manager.mojom";
import "services/network/public/mojom/cookie_partition_key.mojom";
import "services/network/public/mojom/cors.mojom";
import "services/network/public/mojom/fetch_api.mojom";
import "services/network/public/mojom/http_raw_headers.mojom";
import "services/network/public/mojom/http_request_headers.mojom";
import "services/network/public/mojom/ip_address_space.mojom";
import "services/network/public/mojom/referrer_policy.mojom";
import "services/network/public/mojom/request_priority.mojom";
import "services/network/public/mojom/service_worker_router_info.mojom";
import "services/network/public/mojom/shared_dictionary_error.mojom";
import "services/network/public/mojom/trust_tokens.mojom";
import "services/network/public/mojom/ip_endpoint.mojom";
import "services/network/public/mojom/url_loader_completion_status.mojom";
import "services/network/public/mojom/network_param.mojom";
import "services/network/public/mojom/load_timing_info.mojom";
import "url/mojom/origin.mojom";
import "url/mojom/url.mojom";

// A struct with information about a URLRequest that is reported to DevTools.
// See URLRequest definition for a description of the fields.
struct URLRequestDevToolsInfo {
  string method;
  url.mojom.Url url;
  RequestPriority priority;
  URLRequestReferrerPolicy referrer_policy;
  TrustTokenParams? trust_token_params;
  bool has_user_gesture;
  uint32 resource_type;
};

// A struct with info about a URLResponseHead that is reported to DevTools.
// We don't use URLResponseHead directly to avoid circular dependencies between
// (includees of) URLResponseHead and DevToolsObserver.
// See URLResponseHead definition for a description of the fields.
struct URLResponseHeadDevToolsInfo {
  mojo_base.mojom.Time response_time;
  HttpResponseHeaders headers;
  string mime_type;
  string charset;
  LoadTimingInfo load_timing;
  uint32 cert_status;
  int64 encoded_data_length;
  bool was_in_prefetch_cache;
  bool was_fetched_via_service_worker;
  string cache_storage_cache_name;
  string alpn_negotiated_protocol;
  AlternateProtocolUsage alternate_protocol_usage;
  bool was_fetched_via_spdy;
  FetchResponseSource service_worker_response_source;
  ServiceWorkerRouterInfo? service_worker_router_info;
  SSLInfo? ssl_info;
  IPEndPoint remote_endpoint;
  bool emitted_extra_info;
};

// This is sent with OnRawRequest to indicate if the site has any partitioned
// cookies in a partition different than the current one. The event populates
// this on a best-effort basis, and sometimes will be null to indicate the
// network service cannot accurately populate the bit.
struct OtherPartitionInfo {
  bool site_has_cookie_in_other_partition;
};

// Interface for devtools receiving information about individual request
// state.
interface DevToolsObserver {
  // Called to send raw header information and information about excluded
  // cookies. Only called when |devtool_request_id| is available to the
  // URLLoader.
  OnRawRequest(
    string devtool_request_id,
    array<CookieWithAccessResult> cookies_with_access_result,
    array<HttpRawHeaderPair> headers,
    mojo_base.mojom.TimeTicks timestamp,
    ClientSecurityState? client_security_state,
    OtherPartitionInfo? other_partition_info);

  // Called to send information about the cookies blocked from storage from a
  // received response. Only called when |devtool_request_id| is available to
  // the URLLoader.
  OnRawResponse(
    string devtool_request_id,
    array<CookieAndLineWithAccessResult> cookies_with_access_result,
    array<HttpRawHeaderPair> headers,
    string? raw_response_headers,
    IPAddressSpace resource_address_space,
    int32 http_status_code,
    CookiePartitionKey? cookie_partition_key);

  // Called to send information about the 103 Early hints headers.
  // Only called when `devtool_request_id` is available to the URLLoader.
  OnEarlyHintsResponse(
    string devtool_request_id,
    array<HttpRawHeaderPair> headers);

  // Called to send information about a private network request that was blocked
  // (then |is_warning| is false), or will be blocked in the future (then
  // |is_warning| is true). It is possible to share sensitive information with
  // DevTools as this is handled in the browser process. Called even when
  // |devtool_request_id| is not available to the URLLoader to ensure the
  // information can be recorded even when DevTools is closed.
  OnPrivateNetworkRequest(
    string? devtool_request_id,
    url.mojom.Url url,
    bool is_warning,
    IPAddressSpace resource_address_space,
    ClientSecurityState client_security_state);

  // Called to send the CORS preflight request information. Only called when
  // |devtool_request_id| is available on the original request.
  OnCorsPreflightRequest(
    mojo_base.mojom.UnguessableToken devtool_request_id,
    HttpRequestHeaders request_headers,
    URLRequestDevToolsInfo request_info,
    url.mojom.Url initiator_url,
    string initiator_devtool_request_id);

  // Called to send the CORS preflight response information. Only called when
  // |devtool_request_id| is available on the original request.
  OnCorsPreflightResponse(
    mojo_base.mojom.UnguessableToken devtool_request_id,
    url.mojom.Url url,
    URLResponseHeadDevToolsInfo head);

  // Called to send the CORS preflight completion status. Only called when
  // |devtool_request_id| is available on the original request.
  OnCorsPreflightRequestCompleted(
    mojo_base.mojom.UnguessableToken devtool_request_id,
    URLLoaderCompletionStatus status);

  // Called to send the result of a successful or failed Trust Token
  // operation. Only called when |devtools_request_id| is available on the
  // original request.
  OnTrustTokenOperationDone(
    string devtool_request_id,
    TrustTokenOperationResult result);

  // Called to send information about a CORS problem. This callback is intended
  // to share sensitive information with DevTools, and is handled in the browser
  // process. Called even when |devtool_request_id| is not available to the
  // URLLoader to ensure CORS issues are recorded even if DevTools is closed.
  //
  // |is_warning| being true indicates that the error was suppressed and treated
  // as a simple warning, as opposed to having caused the request to fail.
  OnCorsError(
    string? devtool_request_id,
    url.mojom.Origin? initiator_origin,
    ClientSecurityState? client_security_state,
    url.mojom.Url url,
    CorsErrorStatus status,
    bool is_warning);

  // Called to report an ORB error. This callback is intended to deliver a
  // DevTools issue.
  //
  // |devtools_request_id| id of the affected request.
  // |url| is the URL that was blocked by ORB.
  OnOrbError(
    string? devtools_request_id,
    url.mojom.Url url);

  // Called when parsing the .wbn file has succeeded. The event
  // contains the information about the web bundle contents.
  OnSubresourceWebBundleMetadata(
    string devtool_request_id,
    array<url.mojom.Url> urls);

  // Called when parsing the .wbn file has failed.
  OnSubresourceWebBundleMetadataError(
    string devtool_request_id,
    string error_message);

  // Called when handling requests for resources within a .wbn file.
  // Note: this will only be fired for resources that are requested by the
  // webpage.
  OnSubresourceWebBundleInnerResponse(
    string inner_request_devtools_id,
    url.mojom.Url url,
    string? bundle_request_devtools_id);

  // Called when an error occurs while handling a request within a .wbn file.
  OnSubresourceWebBundleInnerResponseError(
    string inner_request_devtools_id,
    url.mojom.Url url,
    string error_message,
    string? bundle_request_devtools_id);

  // Called when an error occurs while handling a response with
  // "Use-As-Dictionary" header, or fetching request with a registered
  // dictionary.
  OnSharedDictionaryError(
    string devtool_request_id,
    url.mojom.Url url,
    SharedDictionaryError error);

  // Used by the NetworkService to create a copy of this observer.
  // (e.g. when creating an observer for URLLoader from URLLoaderFactory's
  // observer).
  Clone(pending_receiver<DevToolsObserver> listener);
};