chromium/services/network/public/mojom/fetch_api.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 network.mojom;

// Corresponds to Fetch request's "mode" and "use-CORS-preflight flag":
// https://fetch.spec.whatwg.org/#concept-request-mode
//
// These values are persisted to logs. Entries should not be renumbered and
// numeric values should never be reused.
enum RequestMode {
  kSameOrigin = 0,
  kNoCors = 1,
  kCors = 2,
  kCorsWithForcedPreflight = 3,
  kNavigate = 4,
  // Add a new type here, then update "FetchRequestMode" in enums.xml.
};

// Corresponds to Fetch request's "destination":
// https://fetch.spec.whatwg.org/#concept-request-destination
//
// These values are persisted to logs. Entries should not be renumbered and
// numeric values should never be reused.
enum RequestDestination {
  kEmpty = 0,
  kAudio = 1,
  kAudioWorklet = 2,
  // kDocument is for a main resource request in a main frame.
  kDocument = 3,
  kEmbed = 4,
  kFont = 5,
  kFrame = 6,
  kIframe = 7,
  kImage = 8,
  kManifest = 9,
  kObject = 10,
  kPaintWorklet = 11,
  kReport = 12,
  kScript = 13,
  kServiceWorker = 14,
  kSharedWorker = 15,
  kStyle = 16,
  kTrack = 17,
  kVideo = 18,
  // kWebBundle represents a request for a WebBundle. A <script> element whose
  // type is "webbundle" uses this destination.
  //
  // e.g. <script type=webbundle> { "source": "foo.wbn", ... } </script>
  //
  // Fetch specifiction does not define this destination yet.
  // Tracking issue: https://github.com/whatwg/fetch/issues/1120
  kWebBundle = 19,
  kWorker = 20,
  kXslt = 21,
  // kFencedframe represents a main resource request in a fenced frame. A
  // <fencedframe> element uses this destination.
  //
  // e.g. <fencedframe src="example.com"></fencedframe>
  //
  // Fenced Frame is not standardized yet. See
  // https://github.com/shivanigithub/fenced-frame for the explainer and
  // crbug.com/1123606 for the implementation.
  kFencedframe = 22,
  // Requests from the federated credential management API,
  // https://fedidcg.github.io/FedCM/
  kWebIdentity = 23,
  // Requests for compression dictionary
  kDictionary = 24,
  // Requests for speculation rules.
  // https://wicg.github.io/nav-speculation/speculation-rules.html
  kSpeculationRules = 25,
  // Requests for JSON modules
  kJson = 26,
  // Requests for shared storage worklet.
  kSharedStorageWorklet = 27,
};

// Corresponds to Fetch request's "redirect mode":
// https://fetch.spec.whatwg.org/#concept-request-redirect-mode
enum RedirectMode {
  kFollow,
  kError,
  kManual,
};

// Corresponds to Fetch request's "credentials mode":
// https://fetch.spec.whatwg.org/#concept-request-credentials-mode
enum CredentialsMode {
  // TODO(crbug.com/40089326): Due to a bug, this does not properly
  // correspond to Fetch's "credentials mode", in that client certificates will
  // be sent is available, or the handshake will be aborted in order to allow
  // selecting a client cert. The correct behavior is to omit all client certs
  // and continue the handshake without sending one if requested.
  kOmit,

  kSameOrigin,
  kInclude,

  // TODO(crbug.com/40089326): This works around kOmit not doing the
  // spec-defined behavior. This is a temporary workaround that explicitly
  // indicates the caller wants the spec-defined behavior. It's named as such
  // because this should be only temporary, until kOmit is fixed.
  kOmitBug_775438_Workaround
};

// Corresponds to response types from the Fetch spec:
// https://fetch.spec.whatwg.org/#concept-response-type
//
// These values are persisted to logs. Entries should not be renumbered and
// numeric values should never be reused.
enum FetchResponseType {
  kBasic = 0,
  kCors = 1,
  kDefault = 2,
  kError = 3,
  kOpaque = 4,
  kOpaqueRedirect = 5,
  // Add a new type here, then update "FetchResponseType" in enums.xml.
};

// Indicates the source of a response.
// This represents the source of the outmost response of a request.
// This is used only for histograms and isn't web-exposed.
enum FetchResponseSource {
  // The source is unspecified: e.g. "new Response('hi')" or a response from
  // a service worker.
  kUnspecified,
  // The response came from network: e.g. "fetch(req)".
  kNetwork,
  // The response came from HttpCache: e.g. "fetch(req)" and there is an entry
  // in HttpCache.
  kHttpCache,
  // The response came from CacheStorage: e.g. "cache.match(req)" in a fetch
  // event handler.
  kCacheStorage,
};