Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fetch cancellation #19274

Merged
merged 6 commits into from Nov 21, 2017

Fetch cancellation: Store cancel_chan in XHR

  • Loading branch information
Manishearth committed Nov 18, 2017
commit 87e4c15280ac29eb7efc7f7824b6647c6ee1b0e0
@@ -154,6 +154,8 @@ pub struct XMLHttpRequest {
response_status: Cell<Result<(), ()>>,
referrer_url: Option<ServoUrl>,
referrer_policy: Option<ReferrerPolicy>,
#[ignore_malloc_size_of = "channels are hard"]
cancellation_chan: DomRefCell<Option<ipc::IpcSender<()>>>,
}

impl XMLHttpRequest {
@@ -198,6 +200,7 @@ impl XMLHttpRequest {
response_status: Cell::new(Ok(())),
referrer_url: referrer_url,
referrer_policy: referrer_policy,
cancellation_chan: DomRefCell::new(None),
}
}
pub fn new(global: &GlobalScope) -> DomRoot<XMLHttpRequest> {
@@ -218,7 +221,8 @@ impl XMLHttpRequest {
fn initiate_async_xhr(context: Arc<Mutex<XHRContext>>,
task_source: NetworkingTaskSource,
global: &GlobalScope,
init: RequestInit) {
init: RequestInit,
cancellation_chan: ipc::IpcReceiver<()>) {
impl FetchResponseListener for XHRContext {
fn process_request_body(&mut self) {
// todo
@@ -255,6 +259,7 @@ impl XMLHttpRequest {
}

let (action_sender, action_receiver) = ipc::channel().unwrap();

let listener = NetworkListener {
context: context,
task_source: task_source,
@@ -264,7 +269,7 @@ impl XMLHttpRequest {
listener.notify_fetch(message.to().unwrap());
}));
global.core_resource_thread().send(
Fetch(init, FetchChannels::ResponseMsg(action_sender, None))).unwrap();
Fetch(init, FetchChannels::ResponseMsg(action_sender, Some(cancellation_chan)))).unwrap();
}
}

@@ -1311,8 +1316,11 @@ impl XMLHttpRequest {
(global.networking_task_source(), None)
};

let (cancel_sender, cancel_receiver) = ipc::channel().unwrap();
*self.cancellation_chan.borrow_mut() = Some(cancel_sender);

XMLHttpRequest::initiate_async_xhr(context.clone(), task_source,
global, init);
global, init, cancel_receiver);

if let Some(script_port) = script_port {
loop {
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.