summaryrefslogtreecommitdiff
path: root/chromium/third_party/blink/public/mojom/fetch/fetch_api_request.mojom
blob: 31cd8d67e6b0f1bf80ece6d0bdc961ee878787f8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
// Copyright 2017 The Chromium Authors. All rights reserved.
// 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/fetch_api.mojom";
import "services/network/public/mojom/request_context_frame_type.mojom";
import "services/network/public/mojom/url_loader.mojom";
import "third_party/blink/public/mojom/blob/serialized_blob.mojom";
import "third_party/blink/public/mojom/referrer.mojom";
import "url/mojom/url.mojom";


// Type of the context associated with a request.
// https://fetch.spec.whatwg.org/#concept-request-destination.
// TODO(crbug.com/889751): This is a deprecated spec concept, figure out
// how to refactor this to match the new spec concepts, 'destination' and
// 'initiator'.
enum RequestContextType {
  UNSPECIFIED,
  AUDIO,
  BEACON,
  CSP_REPORT,
  DOWNLOAD,
  EMBED,
  EVENT_SOURCE,
  FAVICON,
  FETCH,
  FONT,
  FORM,
  FRAME,
  HYPERLINK,
  IFRAME,
  IMAGE,
  IMAGE_SET,
  IMPORT,
  INTERNAL,
  LOCATION,
  MANIFEST,
  OBJECT,
  PING,
  PLUGIN,
  PREFETCH,
  SCRIPT,
  SERVICE_WORKER,
  SHARED_WORKER,
  SUBRESOURCE,
  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 "importance mode"
// Currently discussed at: https://github.com/WICG/priority-hints
// TODO(domfarolino): add a spec link to this once specified.
enum FetchImportanceMode {
  kImportanceLow,
  kImportanceAuto,
  kImportanceHigh
};

// 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 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.FetchRequestMode mode = network.mojom.FetchRequestMode.kNoCors;
  bool is_main_resource_load = false;
  RequestContextType request_context_type = RequestContextType.UNSPECIFIED;
  network.mojom.RequestContextFrameType frame_type =
    network.mojom.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;
  network.mojom.URLRequestBody? body;

  Referrer? referrer;
  network.mojom.FetchCredentialsMode credentials_mode =
    network.mojom.FetchCredentialsMode.kOmit;
  FetchCacheMode cache_mode = FetchCacheMode.kDefault;
  network.mojom.FetchRedirectMode redirect_mode =
    network.mojom.FetchRedirectMode.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;
};