Skip to main content

browser_protocol/preload/
mod.rs

1use serde::{Serialize, Deserialize};
2use serde_json::Value as JsonValue;
3use std::borrow::Cow;
4
5/// Unique id
6
7pub type RuleSetId<'a> = Cow<'a, str>;
8
9/// Corresponds to SpeculationRuleSet
10
11#[derive(Debug, Clone, Serialize, Deserialize, Default)]
12#[serde(rename_all = "camelCase")]
13pub struct RuleSet<'a> {
14    id: RuleSetId<'a>,
15    /// Identifies a document which the rule set is associated with.
16    #[serde(rename = "loaderId")]
17    loader_id: crate::network::LoaderId<'a>,
18    /// Source text of JSON representing the rule set. If it comes from
19    /// '\<script\>' tag, it is the textContent of the node. Note that it is
20    /// a JSON for valid case.
21    /// 
22    /// See also:
23    /// - <https://wicg.github.io/nav-speculation/speculation-rules.html>
24    /// - <https://github.com/WICG/nav-speculation/blob/main/triggers.md>
25    #[serde(rename = "sourceText")]
26    source_text: Cow<'a, str>,
27    /// A speculation rule set is either added through an inline
28    /// '\<script\>' tag or through an external resource via the
29    /// 'Speculation-Rules' HTTP header. For the first case, we include
30    /// the BackendNodeId of the relevant '\<script\>' tag. For the second
31    /// case, we include the external URL where the rule set was loaded
32    /// from, and also RequestId if Network domain is enabled.
33    /// 
34    /// See also:
35    /// - <https://wicg.github.io/nav-speculation/speculation-rules.html#speculation-rules-script>
36    /// - <https://wicg.github.io/nav-speculation/speculation-rules.html#speculation-rules-header>
37    #[serde(skip_serializing_if = "Option::is_none", rename = "backendNodeId")]
38    backend_node_id: Option<crate::dom::BackendNodeId>,
39    #[serde(skip_serializing_if = "Option::is_none")]
40    url: Option<Cow<'a, str>>,
41    #[serde(skip_serializing_if = "Option::is_none", rename = "requestId")]
42    request_id: Option<crate::network::RequestId<'a>>,
43    /// Error information
44    /// 'errorMessage' is null iff 'errorType' is null.
45    #[serde(skip_serializing_if = "Option::is_none", rename = "errorType")]
46    error_type: Option<RuleSetErrorType>,
47    /// TODO(<https://crbug.com/1425354>): Replace this property with structured error.
48    #[serde(skip_serializing_if = "Option::is_none", rename = "errorMessage")]
49    error_message: Option<Cow<'a, str>>,
50    /// For more details, see:
51    /// <https://github.com/WICG/nav-speculation/blob/main/speculation-rules-tags.md>
52    #[serde(skip_serializing_if = "Option::is_none")]
53    tag: Option<Cow<'a, str>>,
54}
55
56impl<'a> RuleSet<'a> {
57    /// Creates a builder for this type with the required parameters:
58    /// * `id`: 
59    /// * `loader_id`: Identifies a document which the rule set is associated with.
60    /// * `source_text`: Source text of JSON representing the rule set. If it comes from `\<script\>` tag, it is the textContent of the node. Note that it is a JSON for valid case.  See also: - <https://wicg.github.io/nav-speculation/speculation-rules.html> - <https://github.com/WICG/nav-speculation/blob/main/triggers.md>
61    pub fn builder(id: impl Into<RuleSetId<'a>>, loader_id: crate::network::LoaderId<'a>, source_text: impl Into<Cow<'a, str>>) -> RuleSetBuilder<'a> {
62        RuleSetBuilder {
63            id: id.into(),
64            loader_id: loader_id,
65            source_text: source_text.into(),
66            backend_node_id: None,
67            url: None,
68            request_id: None,
69            error_type: None,
70            error_message: None,
71            tag: None,
72        }
73    }
74    pub fn id(&self) -> &RuleSetId<'a> { &self.id }
75    /// Identifies a document which the rule set is associated with.
76    pub fn loader_id(&self) -> &crate::network::LoaderId<'a> { &self.loader_id }
77    /// Source text of JSON representing the rule set. If it comes from
78    /// '\<script\>' tag, it is the textContent of the node. Note that it is
79    /// a JSON for valid case.
80    /// 
81    /// See also:
82    /// - <https://wicg.github.io/nav-speculation/speculation-rules.html>
83    /// - <https://github.com/WICG/nav-speculation/blob/main/triggers.md>
84    pub fn source_text(&self) -> &str { self.source_text.as_ref() }
85    /// A speculation rule set is either added through an inline
86    /// '\<script\>' tag or through an external resource via the
87    /// 'Speculation-Rules' HTTP header. For the first case, we include
88    /// the BackendNodeId of the relevant '\<script\>' tag. For the second
89    /// case, we include the external URL where the rule set was loaded
90    /// from, and also RequestId if Network domain is enabled.
91    /// 
92    /// See also:
93    /// - <https://wicg.github.io/nav-speculation/speculation-rules.html#speculation-rules-script>
94    /// - <https://wicg.github.io/nav-speculation/speculation-rules.html#speculation-rules-header>
95    pub fn backend_node_id(&self) -> Option<&crate::dom::BackendNodeId> { self.backend_node_id.as_ref() }
96    pub fn url(&self) -> Option<&str> { self.url.as_deref() }
97    pub fn request_id(&self) -> Option<&crate::network::RequestId<'a>> { self.request_id.as_ref() }
98    /// Error information
99    /// 'errorMessage' is null iff 'errorType' is null.
100    pub fn error_type(&self) -> Option<&RuleSetErrorType> { self.error_type.as_ref() }
101    /// TODO(<https://crbug.com/1425354>): Replace this property with structured error.
102    pub fn error_message(&self) -> Option<&str> { self.error_message.as_deref() }
103    /// For more details, see:
104    /// <https://github.com/WICG/nav-speculation/blob/main/speculation-rules-tags.md>
105    pub fn tag(&self) -> Option<&str> { self.tag.as_deref() }
106}
107
108
109pub struct RuleSetBuilder<'a> {
110    id: RuleSetId<'a>,
111    loader_id: crate::network::LoaderId<'a>,
112    source_text: Cow<'a, str>,
113    backend_node_id: Option<crate::dom::BackendNodeId>,
114    url: Option<Cow<'a, str>>,
115    request_id: Option<crate::network::RequestId<'a>>,
116    error_type: Option<RuleSetErrorType>,
117    error_message: Option<Cow<'a, str>>,
118    tag: Option<Cow<'a, str>>,
119}
120
121impl<'a> RuleSetBuilder<'a> {
122    /// A speculation rule set is either added through an inline
123    /// '\<script\>' tag or through an external resource via the
124    /// 'Speculation-Rules' HTTP header. For the first case, we include
125    /// the BackendNodeId of the relevant '\<script\>' tag. For the second
126    /// case, we include the external URL where the rule set was loaded
127    /// from, and also RequestId if Network domain is enabled.
128    /// 
129    /// See also:
130    /// - <https://wicg.github.io/nav-speculation/speculation-rules.html#speculation-rules-script>
131    /// - <https://wicg.github.io/nav-speculation/speculation-rules.html#speculation-rules-header>
132    pub fn backend_node_id(mut self, backend_node_id: crate::dom::BackendNodeId) -> Self { self.backend_node_id = Some(backend_node_id); self }
133    pub fn url(mut self, url: impl Into<Cow<'a, str>>) -> Self { self.url = Some(url.into()); self }
134    pub fn request_id(mut self, request_id: crate::network::RequestId<'a>) -> Self { self.request_id = Some(request_id); self }
135    /// Error information
136    /// 'errorMessage' is null iff 'errorType' is null.
137    pub fn error_type(mut self, error_type: impl Into<RuleSetErrorType>) -> Self { self.error_type = Some(error_type.into()); self }
138    /// TODO(<https://crbug.com/1425354>): Replace this property with structured error.
139    pub fn error_message(mut self, error_message: impl Into<Cow<'a, str>>) -> Self { self.error_message = Some(error_message.into()); self }
140    /// For more details, see:
141    /// <https://github.com/WICG/nav-speculation/blob/main/speculation-rules-tags.md>
142    pub fn tag(mut self, tag: impl Into<Cow<'a, str>>) -> Self { self.tag = Some(tag.into()); self }
143    pub fn build(self) -> RuleSet<'a> {
144        RuleSet {
145            id: self.id,
146            loader_id: self.loader_id,
147            source_text: self.source_text,
148            backend_node_id: self.backend_node_id,
149            url: self.url,
150            request_id: self.request_id,
151            error_type: self.error_type,
152            error_message: self.error_message,
153            tag: self.tag,
154        }
155    }
156}
157
158
159#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
160pub enum RuleSetErrorType {
161    #[default]
162    #[serde(rename = "SourceIsNotJsonObject")]
163    SourceIsNotJsonObject,
164    #[serde(rename = "InvalidRulesSkipped")]
165    InvalidRulesSkipped,
166    #[serde(rename = "InvalidRulesetLevelTag")]
167    InvalidRulesetLevelTag,
168}
169
170/// The type of preloading attempted. It corresponds to
171/// mojom::SpeculationAction (although PrefetchWithSubresources is omitted as it
172/// isn't being used by clients).
173
174#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
175pub enum SpeculationAction {
176    #[default]
177    #[serde(rename = "Prefetch")]
178    Prefetch,
179    #[serde(rename = "Prerender")]
180    Prerender,
181    #[serde(rename = "PrerenderUntilScript")]
182    PrerenderUntilScript,
183}
184
185/// Corresponds to mojom::SpeculationTargetHint.
186/// See <https://github.com/WICG/nav-speculation/blob/main/triggers.md#window-name-targeting-hints>
187
188#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
189pub enum SpeculationTargetHint {
190    #[default]
191    #[serde(rename = "Blank")]
192    Blank,
193    #[serde(rename = "Self")]
194    SelfValue,
195}
196
197/// A key that identifies a preloading attempt.
198/// 
199/// The url used is the url specified by the trigger (i.e. the initial URL), and
200/// not the final url that is navigated to. For example, prerendering allows
201/// same-origin main frame navigations during the attempt, but the attempt is
202/// still keyed with the initial URL.
203
204#[derive(Debug, Clone, Serialize, Deserialize, Default)]
205#[serde(rename_all = "camelCase")]
206pub struct PreloadingAttemptKey<'a> {
207    #[serde(rename = "loaderId")]
208    loader_id: crate::network::LoaderId<'a>,
209    action: SpeculationAction,
210    url: Cow<'a, str>,
211    #[serde(skip_serializing_if = "Option::is_none", rename = "formSubmission")]
212    form_submission: Option<bool>,
213    #[serde(skip_serializing_if = "Option::is_none", rename = "targetHint")]
214    target_hint: Option<SpeculationTargetHint>,
215}
216
217impl<'a> PreloadingAttemptKey<'a> {
218    /// Creates a builder for this type with the required parameters:
219    /// * `loader_id`: 
220    /// * `action`: 
221    /// * `url`: 
222    pub fn builder(loader_id: crate::network::LoaderId<'a>, action: impl Into<SpeculationAction>, url: impl Into<Cow<'a, str>>) -> PreloadingAttemptKeyBuilder<'a> {
223        PreloadingAttemptKeyBuilder {
224            loader_id: loader_id,
225            action: action.into(),
226            url: url.into(),
227            form_submission: None,
228            target_hint: None,
229        }
230    }
231    pub fn loader_id(&self) -> &crate::network::LoaderId<'a> { &self.loader_id }
232    pub fn action(&self) -> &SpeculationAction { &self.action }
233    pub fn url(&self) -> &str { self.url.as_ref() }
234    pub fn form_submission(&self) -> Option<bool> { self.form_submission }
235    pub fn target_hint(&self) -> Option<&SpeculationTargetHint> { self.target_hint.as_ref() }
236}
237
238
239pub struct PreloadingAttemptKeyBuilder<'a> {
240    loader_id: crate::network::LoaderId<'a>,
241    action: SpeculationAction,
242    url: Cow<'a, str>,
243    form_submission: Option<bool>,
244    target_hint: Option<SpeculationTargetHint>,
245}
246
247impl<'a> PreloadingAttemptKeyBuilder<'a> {
248    pub fn form_submission(mut self, form_submission: bool) -> Self { self.form_submission = Some(form_submission); self }
249    pub fn target_hint(mut self, target_hint: impl Into<SpeculationTargetHint>) -> Self { self.target_hint = Some(target_hint.into()); self }
250    pub fn build(self) -> PreloadingAttemptKey<'a> {
251        PreloadingAttemptKey {
252            loader_id: self.loader_id,
253            action: self.action,
254            url: self.url,
255            form_submission: self.form_submission,
256            target_hint: self.target_hint,
257        }
258    }
259}
260
261/// Lists sources for a preloading attempt, specifically the ids of rule sets
262/// that had a speculation rule that triggered the attempt, and the
263/// BackendNodeIds of \<a href\> or \<area href\> elements that triggered the
264/// attempt (in the case of attempts triggered by a document rule). It is
265/// possible for multiple rule sets and links to trigger a single attempt.
266
267#[derive(Debug, Clone, Serialize, Deserialize, Default)]
268#[serde(rename_all = "camelCase")]
269pub struct PreloadingAttemptSource<'a> {
270    key: PreloadingAttemptKey<'a>,
271    #[serde(rename = "ruleSetIds")]
272    rule_set_ids: Vec<RuleSetId<'a>>,
273    #[serde(rename = "nodeIds")]
274    node_ids: Vec<crate::dom::BackendNodeId>,
275}
276
277impl<'a> PreloadingAttemptSource<'a> {
278    /// Creates a builder for this type with the required parameters:
279    /// * `key`: 
280    /// * `rule_set_ids`: 
281    /// * `node_ids`: 
282    pub fn builder(key: PreloadingAttemptKey<'a>, rule_set_ids: Vec<RuleSetId<'a>>, node_ids: Vec<crate::dom::BackendNodeId>) -> PreloadingAttemptSourceBuilder<'a> {
283        PreloadingAttemptSourceBuilder {
284            key: key,
285            rule_set_ids: rule_set_ids,
286            node_ids: node_ids,
287        }
288    }
289    pub fn key(&self) -> &PreloadingAttemptKey<'a> { &self.key }
290    pub fn rule_set_ids(&self) -> &[RuleSetId<'a>] { &self.rule_set_ids }
291    pub fn node_ids(&self) -> &[crate::dom::BackendNodeId] { &self.node_ids }
292}
293
294
295pub struct PreloadingAttemptSourceBuilder<'a> {
296    key: PreloadingAttemptKey<'a>,
297    rule_set_ids: Vec<RuleSetId<'a>>,
298    node_ids: Vec<crate::dom::BackendNodeId>,
299}
300
301impl<'a> PreloadingAttemptSourceBuilder<'a> {
302    pub fn build(self) -> PreloadingAttemptSource<'a> {
303        PreloadingAttemptSource {
304            key: self.key,
305            rule_set_ids: self.rule_set_ids,
306            node_ids: self.node_ids,
307        }
308    }
309}
310
311/// Chrome manages different types of preloads together using a
312/// concept of preloading pipeline. For example, if a site uses a
313/// SpeculationRules for prerender, Chrome first starts a prefetch and
314/// then upgrades it to prerender.
315/// 
316/// CDP events for them are emitted separately but they share
317/// 'PreloadPipelineId'.
318
319pub type PreloadPipelineId<'a> = Cow<'a, str>;
320
321/// List of FinalStatus reasons for Prerender2.
322
323#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
324pub enum PrerenderFinalStatus {
325    #[default]
326    #[serde(rename = "Activated")]
327    Activated,
328    #[serde(rename = "Destroyed")]
329    Destroyed,
330    #[serde(rename = "LowEndDevice")]
331    LowEndDevice,
332    #[serde(rename = "InvalidSchemeRedirect")]
333    InvalidSchemeRedirect,
334    #[serde(rename = "InvalidSchemeNavigation")]
335    InvalidSchemeNavigation,
336    #[serde(rename = "NavigationRequestBlockedByCsp")]
337    NavigationRequestBlockedByCsp,
338    #[serde(rename = "MojoBinderPolicy")]
339    MojoBinderPolicy,
340    #[serde(rename = "RendererProcessCrashed")]
341    RendererProcessCrashed,
342    #[serde(rename = "RendererProcessKilled")]
343    RendererProcessKilled,
344    #[serde(rename = "Download")]
345    Download,
346    #[serde(rename = "TriggerDestroyed")]
347    TriggerDestroyed,
348    #[serde(rename = "NavigationNotCommitted")]
349    NavigationNotCommitted,
350    #[serde(rename = "NavigationBadHttpStatus")]
351    NavigationBadHttpStatus,
352    #[serde(rename = "ClientCertRequested")]
353    ClientCertRequested,
354    #[serde(rename = "NavigationRequestNetworkError")]
355    NavigationRequestNetworkError,
356    #[serde(rename = "CancelAllHostsForTesting")]
357    CancelAllHostsForTesting,
358    #[serde(rename = "DidFailLoad")]
359    DidFailLoad,
360    #[serde(rename = "Stop")]
361    Stop,
362    #[serde(rename = "SslCertificateError")]
363    SslCertificateError,
364    #[serde(rename = "LoginAuthRequested")]
365    LoginAuthRequested,
366    #[serde(rename = "UaChangeRequiresReload")]
367    UaChangeRequiresReload,
368    #[serde(rename = "BlockedByClient")]
369    BlockedByClient,
370    #[serde(rename = "AudioOutputDeviceRequested")]
371    AudioOutputDeviceRequested,
372    #[serde(rename = "MixedContent")]
373    MixedContent,
374    #[serde(rename = "TriggerBackgrounded")]
375    TriggerBackgrounded,
376    #[serde(rename = "MemoryLimitExceeded")]
377    MemoryLimitExceeded,
378    #[serde(rename = "DataSaverEnabled")]
379    DataSaverEnabled,
380    #[serde(rename = "TriggerUrlHasEffectiveUrl")]
381    TriggerUrlHasEffectiveUrl,
382    #[serde(rename = "ActivatedBeforeStarted")]
383    ActivatedBeforeStarted,
384    #[serde(rename = "InactivePageRestriction")]
385    InactivePageRestriction,
386    #[serde(rename = "StartFailed")]
387    StartFailed,
388    #[serde(rename = "TimeoutBackgrounded")]
389    TimeoutBackgrounded,
390    #[serde(rename = "CrossSiteRedirectInInitialNavigation")]
391    CrossSiteRedirectInInitialNavigation,
392    #[serde(rename = "CrossSiteNavigationInInitialNavigation")]
393    CrossSiteNavigationInInitialNavigation,
394    #[serde(rename = "SameSiteCrossOriginRedirectNotOptInInInitialNavigation")]
395    SameSiteCrossOriginRedirectNotOptInInInitialNavigation,
396    #[serde(rename = "SameSiteCrossOriginNavigationNotOptInInInitialNavigation")]
397    SameSiteCrossOriginNavigationNotOptInInInitialNavigation,
398    #[serde(rename = "ActivationNavigationParameterMismatch")]
399    ActivationNavigationParameterMismatch,
400    #[serde(rename = "ActivatedInBackground")]
401    ActivatedInBackground,
402    #[serde(rename = "EmbedderHostDisallowed")]
403    EmbedderHostDisallowed,
404    #[serde(rename = "ActivationNavigationDestroyedBeforeSuccess")]
405    ActivationNavigationDestroyedBeforeSuccess,
406    #[serde(rename = "TabClosedByUserGesture")]
407    TabClosedByUserGesture,
408    #[serde(rename = "TabClosedWithoutUserGesture")]
409    TabClosedWithoutUserGesture,
410    #[serde(rename = "PrimaryMainFrameRendererProcessCrashed")]
411    PrimaryMainFrameRendererProcessCrashed,
412    #[serde(rename = "PrimaryMainFrameRendererProcessKilled")]
413    PrimaryMainFrameRendererProcessKilled,
414    #[serde(rename = "ActivationFramePolicyNotCompatible")]
415    ActivationFramePolicyNotCompatible,
416    #[serde(rename = "PreloadingDisabled")]
417    PreloadingDisabled,
418    #[serde(rename = "BatterySaverEnabled")]
419    BatterySaverEnabled,
420    #[serde(rename = "ActivatedDuringMainFrameNavigation")]
421    ActivatedDuringMainFrameNavigation,
422    #[serde(rename = "PreloadingUnsupportedByWebContents")]
423    PreloadingUnsupportedByWebContents,
424    #[serde(rename = "CrossSiteRedirectInMainFrameNavigation")]
425    CrossSiteRedirectInMainFrameNavigation,
426    #[serde(rename = "CrossSiteNavigationInMainFrameNavigation")]
427    CrossSiteNavigationInMainFrameNavigation,
428    #[serde(rename = "SameSiteCrossOriginRedirectNotOptInInMainFrameNavigation")]
429    SameSiteCrossOriginRedirectNotOptInInMainFrameNavigation,
430    #[serde(rename = "SameSiteCrossOriginNavigationNotOptInInMainFrameNavigation")]
431    SameSiteCrossOriginNavigationNotOptInInMainFrameNavigation,
432    #[serde(rename = "MemoryPressureOnTrigger")]
433    MemoryPressureOnTrigger,
434    #[serde(rename = "MemoryPressureAfterTriggered")]
435    MemoryPressureAfterTriggered,
436    #[serde(rename = "PrerenderingDisabledByDevTools")]
437    PrerenderingDisabledByDevTools,
438    #[serde(rename = "SpeculationRuleRemoved")]
439    SpeculationRuleRemoved,
440    #[serde(rename = "ActivatedWithAuxiliaryBrowsingContexts")]
441    ActivatedWithAuxiliaryBrowsingContexts,
442    #[serde(rename = "MaxNumOfRunningEagerPrerendersExceeded")]
443    MaxNumOfRunningEagerPrerendersExceeded,
444    #[serde(rename = "MaxNumOfRunningNonEagerPrerendersExceeded")]
445    MaxNumOfRunningNonEagerPrerendersExceeded,
446    #[serde(rename = "MaxNumOfRunningEmbedderPrerendersExceeded")]
447    MaxNumOfRunningEmbedderPrerendersExceeded,
448    #[serde(rename = "PrerenderingUrlHasEffectiveUrl")]
449    PrerenderingUrlHasEffectiveUrl,
450    #[serde(rename = "RedirectedPrerenderingUrlHasEffectiveUrl")]
451    RedirectedPrerenderingUrlHasEffectiveUrl,
452    #[serde(rename = "ActivationUrlHasEffectiveUrl")]
453    ActivationUrlHasEffectiveUrl,
454    #[serde(rename = "JavaScriptInterfaceAdded")]
455    JavaScriptInterfaceAdded,
456    #[serde(rename = "JavaScriptInterfaceRemoved")]
457    JavaScriptInterfaceRemoved,
458    #[serde(rename = "AllPrerenderingCanceled")]
459    AllPrerenderingCanceled,
460    #[serde(rename = "WindowClosed")]
461    WindowClosed,
462    #[serde(rename = "SlowNetwork")]
463    SlowNetwork,
464    #[serde(rename = "OtherPrerenderedPageActivated")]
465    OtherPrerenderedPageActivated,
466    #[serde(rename = "V8OptimizerDisabled")]
467    V8OptimizerDisabled,
468    #[serde(rename = "PrerenderFailedDuringPrefetch")]
469    PrerenderFailedDuringPrefetch,
470    #[serde(rename = "BrowsingDataRemoved")]
471    BrowsingDataRemoved,
472    #[serde(rename = "PrerenderHostReused")]
473    PrerenderHostReused,
474    #[serde(rename = "FormSubmitWhenPrerendering")]
475    FormSubmitWhenPrerendering,
476    #[serde(rename = "CrossDocumentRestart")]
477    CrossDocumentRestart,
478}
479
480/// Preloading status values, see also PreloadingTriggeringOutcome. This
481/// status is shared by prefetchStatusUpdated and prerenderStatusUpdated.
482
483#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
484pub enum PreloadingStatus {
485    #[default]
486    #[serde(rename = "Pending")]
487    Pending,
488    #[serde(rename = "Running")]
489    Running,
490    #[serde(rename = "Ready")]
491    Ready,
492    #[serde(rename = "Success")]
493    Success,
494    #[serde(rename = "Failure")]
495    Failure,
496    #[serde(rename = "NotSupported")]
497    NotSupported,
498}
499
500/// TODO(<https://crbug.com/1384419>): revisit the list of PrefetchStatus and
501/// filter out the ones that aren't necessary to the developers.
502
503#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
504pub enum PrefetchStatus {
505    #[default]
506    #[serde(rename = "PrefetchAllowed")]
507    PrefetchAllowed,
508    #[serde(rename = "PrefetchFailedIneligibleRedirect")]
509    PrefetchFailedIneligibleRedirect,
510    #[serde(rename = "PrefetchFailedInvalidRedirect")]
511    PrefetchFailedInvalidRedirect,
512    #[serde(rename = "PrefetchFailedMIMENotSupported")]
513    PrefetchFailedMIMENotSupported,
514    #[serde(rename = "PrefetchFailedNetError")]
515    PrefetchFailedNetError,
516    #[serde(rename = "PrefetchFailedNon2XX")]
517    PrefetchFailedNon2XX,
518    #[serde(rename = "PrefetchEvictedAfterBrowsingDataRemoved")]
519    PrefetchEvictedAfterBrowsingDataRemoved,
520    #[serde(rename = "PrefetchEvictedAfterCandidateRemoved")]
521    PrefetchEvictedAfterCandidateRemoved,
522    #[serde(rename = "PrefetchEvictedForNewerPrefetch")]
523    PrefetchEvictedForNewerPrefetch,
524    #[serde(rename = "PrefetchHeldback")]
525    PrefetchHeldback,
526    #[serde(rename = "PrefetchIneligibleRetryAfter")]
527    PrefetchIneligibleRetryAfter,
528    #[serde(rename = "PrefetchIsPrivacyDecoy")]
529    PrefetchIsPrivacyDecoy,
530    #[serde(rename = "PrefetchIsStale")]
531    PrefetchIsStale,
532    #[serde(rename = "PrefetchNotEligibleBrowserContextOffTheRecord")]
533    PrefetchNotEligibleBrowserContextOffTheRecord,
534    #[serde(rename = "PrefetchNotEligibleDataSaverEnabled")]
535    PrefetchNotEligibleDataSaverEnabled,
536    #[serde(rename = "PrefetchNotEligibleExistingProxy")]
537    PrefetchNotEligibleExistingProxy,
538    #[serde(rename = "PrefetchNotEligibleHostIsNonUnique")]
539    PrefetchNotEligibleHostIsNonUnique,
540    #[serde(rename = "PrefetchNotEligibleNonDefaultStoragePartition")]
541    PrefetchNotEligibleNonDefaultStoragePartition,
542    #[serde(rename = "PrefetchNotEligibleSameSiteCrossOriginPrefetchRequiredProxy")]
543    PrefetchNotEligibleSameSiteCrossOriginPrefetchRequiredProxy,
544    #[serde(rename = "PrefetchNotEligibleSchemeIsNotHttps")]
545    PrefetchNotEligibleSchemeIsNotHttps,
546    #[serde(rename = "PrefetchNotEligibleUserHasCookies")]
547    PrefetchNotEligibleUserHasCookies,
548    #[serde(rename = "PrefetchNotEligibleUserHasServiceWorker")]
549    PrefetchNotEligibleUserHasServiceWorker,
550    #[serde(rename = "PrefetchNotEligibleUserHasServiceWorkerNoFetchHandler")]
551    PrefetchNotEligibleUserHasServiceWorkerNoFetchHandler,
552    #[serde(rename = "PrefetchNotEligibleRedirectFromServiceWorker")]
553    PrefetchNotEligibleRedirectFromServiceWorker,
554    #[serde(rename = "PrefetchNotEligibleRedirectToServiceWorker")]
555    PrefetchNotEligibleRedirectToServiceWorker,
556    #[serde(rename = "PrefetchNotEligibleBatterySaverEnabled")]
557    PrefetchNotEligibleBatterySaverEnabled,
558    #[serde(rename = "PrefetchNotEligiblePreloadingDisabled")]
559    PrefetchNotEligiblePreloadingDisabled,
560    #[serde(rename = "PrefetchNotFinishedInTime")]
561    PrefetchNotFinishedInTime,
562    #[serde(rename = "PrefetchNotStarted")]
563    PrefetchNotStarted,
564    #[serde(rename = "PrefetchNotUsedCookiesChanged")]
565    PrefetchNotUsedCookiesChanged,
566    #[serde(rename = "PrefetchProxyNotAvailable")]
567    PrefetchProxyNotAvailable,
568    #[serde(rename = "PrefetchResponseUsed")]
569    PrefetchResponseUsed,
570    #[serde(rename = "PrefetchSuccessfulButNotUsed")]
571    PrefetchSuccessfulButNotUsed,
572    #[serde(rename = "PrefetchNotUsedProbeFailed")]
573    PrefetchNotUsedProbeFailed,
574}
575
576/// Information of headers to be displayed when the header mismatch occurred.
577
578#[derive(Debug, Clone, Serialize, Deserialize, Default)]
579#[serde(rename_all = "camelCase")]
580pub struct PrerenderMismatchedHeaders<'a> {
581    #[serde(rename = "headerName")]
582    header_name: Cow<'a, str>,
583    #[serde(skip_serializing_if = "Option::is_none", rename = "initialValue")]
584    initial_value: Option<Cow<'a, str>>,
585    #[serde(skip_serializing_if = "Option::is_none", rename = "activationValue")]
586    activation_value: Option<Cow<'a, str>>,
587}
588
589impl<'a> PrerenderMismatchedHeaders<'a> {
590    /// Creates a builder for this type with the required parameters:
591    /// * `header_name`: 
592    pub fn builder(header_name: impl Into<Cow<'a, str>>) -> PrerenderMismatchedHeadersBuilder<'a> {
593        PrerenderMismatchedHeadersBuilder {
594            header_name: header_name.into(),
595            initial_value: None,
596            activation_value: None,
597        }
598    }
599    pub fn header_name(&self) -> &str { self.header_name.as_ref() }
600    pub fn initial_value(&self) -> Option<&str> { self.initial_value.as_deref() }
601    pub fn activation_value(&self) -> Option<&str> { self.activation_value.as_deref() }
602}
603
604
605pub struct PrerenderMismatchedHeadersBuilder<'a> {
606    header_name: Cow<'a, str>,
607    initial_value: Option<Cow<'a, str>>,
608    activation_value: Option<Cow<'a, str>>,
609}
610
611impl<'a> PrerenderMismatchedHeadersBuilder<'a> {
612    pub fn initial_value(mut self, initial_value: impl Into<Cow<'a, str>>) -> Self { self.initial_value = Some(initial_value.into()); self }
613    pub fn activation_value(mut self, activation_value: impl Into<Cow<'a, str>>) -> Self { self.activation_value = Some(activation_value.into()); self }
614    pub fn build(self) -> PrerenderMismatchedHeaders<'a> {
615        PrerenderMismatchedHeaders {
616            header_name: self.header_name,
617            initial_value: self.initial_value,
618            activation_value: self.activation_value,
619        }
620    }
621}
622
623#[derive(Debug, Clone, Serialize, Deserialize, Default)]
624pub struct EnableParams {}
625
626impl EnableParams { pub const METHOD: &'static str = "Preload.enable"; }
627
628impl<'a> crate::CdpCommand<'a> for EnableParams {
629    const METHOD: &'static str = "Preload.enable";
630    type Response = crate::EmptyReturns;
631}
632
633#[derive(Debug, Clone, Serialize, Deserialize, Default)]
634pub struct DisableParams {}
635
636impl DisableParams { pub const METHOD: &'static str = "Preload.disable"; }
637
638impl<'a> crate::CdpCommand<'a> for DisableParams {
639    const METHOD: &'static str = "Preload.disable";
640    type Response = crate::EmptyReturns;
641}