chromium/third_party/blink/public/mojom/fetch/fetch_api_request.mojom

// 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 blink.mojom;

import "mojo/public/mojom/base/unguessable_token.mojom";
import "services/network/public/mojom/attribution.mojom";
import "services/network/public/mojom/ip_address_space.mojom";
import "services/network/public/mojom/chunked_data_pipe_getter.mojom";
import "services/network/public/mojom/fetch_api.mojom";
import "services/network/public/mojom/request_priority.mojom";
import "services/network/public/mojom/trust_tokens.mojom";
import "services/network/public/mojom/url_request.mojom";
import "third_party/blink/public/mojom/blob/serialized_blob.mojom";
import "third_party/blink/public/mojom/loader/request_context_frame_type.mojom";
import "third_party/blink/public/mojom/loader/referrer.mojom";
import "url/mojom/origin.mojom";
import "url/mojom/url.mojom";


// Type of the context associated with a request.
// https://fetch.spec.whatwg.org/#concept-request-destination.
// TODO(https://crbug.com/889751): Fetch now defines this concept as a request's
// "destination", represented as the enum
// network::mojom::RequestDestination. We should use that enum rather
// than this one.
enum RequestContextType {
  UNSPECIFIED,
  ATTRIBUTION_SRC,
  AUDIO,
  BEACON,
  CSP_REPORT,
  DOWNLOAD,
  EMBED,
  EVENT_SOURCE,
  FAVICON,
  FETCH,
  FONT,
  FORM,
  FRAME,
  HYPERLINK,
  IFRAME,
  IMAGE,
  IMAGE_SET,
  INTERNAL,
  JSON,
  LOCATION,
  MANIFEST,
  OBJECT,
  PING,
  PLUGIN,
  PREFETCH,
  SCRIPT,
  SERVICE_WORKER,
  SHARED_WORKER,
  SPECULATION_RULES,
  SUBRESOURCE,
  SUBRESOURCE_WEBBUNDLE,
  STYLE,
  TRACK,
  VIDEO,
  WORKER,
  XML_HTTP_REQUEST,
  XSLT,
};

// https://fetch.spec.whatwg.org/#concept-request-cache-mode
enum FetchCacheMode {
  // "default": Fetch will inspect the HTTP cache on the way to the network. If
  // there is a fresh response it will be used. If there is a stale response a
  // conditional request will be created, and a normal request otherwise. It
  // then updates the HTTP cache with the response.
  kDefault,

  // "no-store": Fetch behaves as if there is no HTTP cache at all.
  kNoStore,

  // "reload": Fetch behaves as if there is no HTTP cache on the way to the
  // network. Ergo, it creates a normal request and updates the HTTP cache with
  // the response.
  kBypassCache,

  // "no-cache": Fetch creates a conditional request if there is a response in
  // the HTTP cache and a normal request otherwise. It then updates the HTTP
  // cache with the response.
  kValidateCache,

  // "force-cache": Fetch uses any response in the HTTP cache matching the
  // request, not paying attention to staleness. If there was no response, it
  // creates a normal request and updates the HTTP cache with the response.
  kForceCache,

  // "only-if-cached": Fetch uses any response in the HTTP cache matching the
  // request, not paying attention to staleness. If there was no response, it
  // returns a network error.
  kOnlyIfCached,

  // Unspecified ones
  // Similar to ONLY_IF_CACHED, but checks freshness strictly.
  kUnspecifiedOnlyIfCachedStrict,
  // Used by devtools to trigger a request which ends up in CACHE_MISS.
  kUnspecifiedForceCacheMiss,
};

// Corresponds to Fetch request's "priority"
// Spec: https://wicg.github.io/priority-hints/
enum FetchPriorityHint {
  kLow,
  kAuto,
  kHigh
};

// Request headers for FetchAPIRequest. This is typemapped to a container with a
// case insensitive compare or hash function.
struct FetchAPIRequestHeaders {
  map<string, string> headers;
};

// Struct representing a Body for a Request:
// https://fetch.spec.whatwg.org/#body
// This has the same members definition with network.mojom.URLRequestBody, which
// aims to pass around body for network.mojom.URLRequest. Both of them are
// typemapped to scoped_refptr<network::ResourceRequestBody> for the default
// variant, the only difference is for the Blink variant that
// network.mojom.URLRequestBody still is typemapped to
// scoped_refptr<network::ResourceRequestBody> but this is typemapped to
// scoped_refptr<blink::EncodedFormData>.
struct FetchAPIRequestBody {
  // The body contents. DataElementChunkedDataPipe can be used in `elements`
  // only if `elements` consists of one element.
  array<network.mojom.DataElement> elements;

  // Identifies a particular upload instance, which is used by the cache to
  // formulate a cache key.
  uint64 identifier;

  // Indicates whether the post data contains sensitive information like
  // passwords.
  bool contains_sensitive_info;
};

// Struct representing a Request:
// https://fetch.spec.whatwg.org/#request-class
// Compared to network.mojom.URLRequest which is kind of internal data in the
// loading stack, FetchAPIRequest acts as a direct representation of the JS
// Request object in all API implementations like Background Fetch, Cache
// Storage and Service Worker, with no need to care how the loading logic
// happens.
// Note: When updating this struct, also update
// content/common/fetch/fetch_request_type_converters.cc.
struct FetchAPIRequest {
  network.mojom.RequestMode mode = network.mojom.RequestMode.kNoCors;
  bool is_main_resource_load = false;
  network.mojom.RequestDestination destination = network.mojom.RequestDestination.kEmpty;
  RequestContextFrameType frame_type = RequestContextFrameType.kNone;
  url.mojom.Url url;
  string method;
  FetchAPIRequestHeaders headers;

  // Note: |blob| and |body| are mutually exclusive.
  // |blob| is used in implementing Background Fetch APIs.
  // |body| is used to represent the FetchEvent#request#body dispatched to
  // service workers.
  // TODO(crbug.com/911930): Remove |blob| and use |body| instead everywhere.
  SerializedBlob? blob;
  FetchAPIRequestBody? body;

  // `request_initiator` indicates the origin that initiated the request.  See
  // also `network::ResourceRequest::request_initiator`, and the doc comment
  // for `request_initiator` in services/network/public/mojom/url_request.mojom.
  //
  // Note that the origin may be missing for browser-initiated navigations
  // (e.g. ones initiated from the Omnibox).
  url.mojom.Origin? request_initiator;

  // The chain of URLs seen during navigation redirects.  This should only
  // contain values if the mode is `RedirectMode::kNavigate`.  This list
  // will contain the initial network request URL, but not URLs from previous
  // state in the DOM.  For example, if a frame has URL A and sets its location
  // to URL B, then the redirect chain will begin with URL B.  The chain also
  // includes the current request URL, however, it will not reflect any changes
  // made by throttles.
  array<url.mojom.Url> navigation_redirect_chain;

  Referrer? referrer;
  network.mojom.CredentialsMode credentials_mode =
    network.mojom.CredentialsMode.kOmit;
  FetchCacheMode cache_mode = FetchCacheMode.kDefault;
  network.mojom.RedirectMode redirect_mode =
    network.mojom.RedirectMode.kFollow;
  string? integrity;
  network.mojom.RequestPriority priority = network.mojom.RequestPriority.kIdle;

  // Id of the original requestor window.
  // See network::ResourceRequest::fetch_window_id.
  mojo_base.mojom.UnguessableToken? fetch_window_id;

  bool keepalive = false;
  bool is_reload = false;
  bool is_history_navigation = false;

  // A V8 stack id string describing where the request was initiated.
  // DevTools can use this to display the initiator call stack when debugging
  // a process that later intercepts the request, e.g., in a service worker
  // fetch event handler.
  string? devtools_stack_id;

  // Specifies a Trust Token protocol operation if the request has one.
  network.mojom.TrustTokenParams? trust_token_params;

  network.mojom.IPAddressSpace target_address_space = network.mojom.IPAddressSpace.kUnknown;

  network.mojom.AttributionReportingEligibility attribution_reporting_eligibility =
    network.mojom.AttributionReportingEligibility.kUnset;

  network.mojom.AttributionSupport attribution_reporting_support =
    network.mojom.AttributionSupport.kUnset;

  // Used for BestEffortServiceWorker(crbug.com/1420517). Specifies the ID of
  // the RaceNetworkRequest if the RaceNetworkRequest is triggered. This value
  // is referred by the fetch process in blink, in order to detect and dedupe
  // the corresponding fetch event in ServiceWorker.
  mojo_base.mojom.UnguessableToken? service_worker_race_network_request_token;
};