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
//! A web view's downloads: the files its page saves, where an app chooses
//! they go, and the transport every platform speaks.
//!
//! An app that listens for [`crate::EventKind::DownloadPending`]
//! ([`crate::element::WebView::on_download_pending`]) chooses every
//! download's destination itself: the platform holds the transfer and
//! reports it as a [`WebDownloadPending`], whose
//! [`accept`](WebDownloadPending::accept) and
//! [`cancel`](WebDownloadPending::cancel) decide it. An app that listens
//! for [`crate::EventKind::Download`] alone ([`crate::element::WebView::on_download`])
//! has its downloads written into the app's data directory
//! (`downloads/<id>/<filename>`). With neither listener the platform keeps
//! its own behavior.
//!
//! A destination is a [`DownloadDestination`]: an absolute path whose
//! parent directory exists. It refuses an existing file unless
//! [`DownloadDestination::overwrite`] says to replace it. The core writes a
//! private staging directory beside the destination (its leaf does not
//! exist until the engine creates it) and publishes the file atomically
//! only when the transfer finishes, so a failed, cancelled or interrupted
//! download never replaces or corrupts a file at the destination; only the
//! private directory is removed, and only after the platform said its
//! writer stopped.
//!
//! Platforms are transports: they report offers, progress and ends
//! ([`DownloadOffer`], [`DownloadProgress`], [`DownloadEnd`]) and carry out
//! [`WebViewOperation`]s ([`crate::Command::WebViewRequest`]), answering
//! each with [`crate::EventKind::WebViewReply`] and [`reply`]. The state
//! machine, the timeouts, the destination checks, the files and the
//! app-facing events live in [`downloads`], on the engine thread; the disk
//! work runs on a thread of its own.
//!
//! [`WebDownload`] reports an automatic or accepted download's life and
//! [`WebDownload::cancel`] cancels one that is under way. A download a
//! platform cannot own is reported as failed with
//! `ERR_NSH_DOWNLOAD_DISCARDED`.
use PathBuf;
use crate::;
pub use DownloadHandle;
pub use ;
pub use ;
/// What a web view is asked to do ([`crate::Command::WebViewRequest`]).
///
/// A platform answers each with [`crate::EventKind::WebViewReply`]:
/// `StartDownload` once it accepted the staging path and its transfer
/// continued, `CancelDownload` only after its writer stopped.
/// A request on a web view, carrying the core's request id so the
/// platform's reply names it ([`crate::EventKind::WebViewReply`]).
/// The event payload answering [`WebViewRequest`] `id` with `result`
/// ([`crate::EventKind::WebViewReply`]).