aboutsummaryrefslogtreecommitdiffstats
path: root/components/net/fetch/methods.rs
diff options
context:
space:
mode:
Diffstat (limited to 'components/net/fetch/methods.rs')
-rw-r--r--components/net/fetch/methods.rs32
1 files changed, 30 insertions, 2 deletions
diff --git a/components/net/fetch/methods.rs b/components/net/fetch/methods.rs
index 789501fa322..f65c6c196f2 100644
--- a/components/net/fetch/methods.rs
+++ b/components/net/fetch/methods.rs
@@ -28,7 +28,7 @@ use std::fs::File;
use std::io::Read;
use std::mem;
use std::str;
-use std::sync::Arc;
+use std::sync::{Arc, Mutex};
use std::sync::mpsc::{Sender, Receiver};
use subresource_integrity::is_response_integrity_valid;
@@ -44,9 +44,37 @@ pub struct FetchContext {
pub user_agent: Cow<'static, str>,
pub devtools_chan: Option<Sender<DevtoolsControlMsg>>,
pub filemanager: FileManager,
- pub cancel_chan: Option<IpcReceiver<()>>,
+ pub cancellation_listener: Arc<Mutex<CancellationListener>>,
}
+pub struct CancellationListener {
+ cancel_chan: Option<IpcReceiver<()>>,
+ cancelled: bool,
+}
+
+impl CancellationListener {
+ pub fn new(cancel_chan: Option<IpcReceiver<()>>) -> Self {
+ Self {
+ cancel_chan: cancel_chan,
+ cancelled: false,
+ }
+ }
+
+ pub fn cancelled(&mut self) -> bool {
+ if let Some(ref cancel_chan) = self.cancel_chan {
+ if self.cancelled {
+ true
+ } else if cancel_chan.try_recv().is_ok() {
+ self.cancelled = true;
+ true
+ } else {
+ false
+ }
+ } else {
+ false
+ }
+ }
+}
pub type DoneChannel = Option<(Sender<Data>, Receiver<Data>)>;
/// [Fetch](https://fetch.spec.whatwg.org#concept-fetch)