viewpoint_cdp/protocol/page_download/
mod.rs

1//! Page download types.
2//!
3//! Types for Page.downloadWillBegin, Page.downloadProgress, and related events.
4
5use serde::{Deserialize, Serialize};
6
7/// Event: Page.downloadWillBegin
8///
9/// Fired when page is about to start a download.
10#[derive(Debug, Clone, Deserialize)]
11#[serde(rename_all = "camelCase")]
12pub struct DownloadWillBeginEvent {
13    /// Id of the frame that caused download to begin.
14    pub frame_id: String,
15    /// Global unique identifier of the download.
16    pub guid: String,
17    /// URL of the resource being downloaded.
18    pub url: String,
19    /// Suggested file name of the resource (the actual name of the file saved on disk may differ).
20    pub suggested_filename: String,
21}
22
23/// Download progress state.
24#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize)]
25#[serde(rename_all = "camelCase")]
26pub enum DownloadProgressState {
27    /// Download is in progress.
28    InProgress,
29    /// Download completed.
30    Completed,
31    /// Download was canceled.
32    Canceled,
33}
34
35/// Event: Page.downloadProgress
36///
37/// Fired when download makes progress.
38#[derive(Debug, Clone, Deserialize)]
39#[serde(rename_all = "camelCase")]
40pub struct DownloadProgressEvent {
41    /// Global unique identifier of the download.
42    pub guid: String,
43    /// Total expected bytes to download.
44    pub total_bytes: f64,
45    /// Total bytes received.
46    pub received_bytes: f64,
47    /// Download status.
48    pub state: DownloadProgressState,
49}
50
51/// Parameters for Page.setDownloadBehavior.
52#[derive(Debug, Clone, Serialize)]
53#[serde(rename_all = "camelCase")]
54pub struct SetDownloadBehaviorParams {
55    /// Whether to allow all or deny all download requests, or use default Chrome behavior if
56    /// available (otherwise deny).
57    pub behavior: DownloadBehavior,
58    /// The default path to save downloaded files to. This is required if behavior is set to 'allow'.
59    #[serde(skip_serializing_if = "Option::is_none")]
60    pub download_path: Option<String>,
61}
62
63/// Download behavior.
64#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize)]
65#[serde(rename_all = "camelCase")]
66pub enum DownloadBehavior {
67    /// Deny all downloads.
68    Deny,
69    /// Allow all downloads.
70    Allow,
71    /// Use default behavior.
72    Default,
73}