Use task! for form planned navigations.

This commit is contained in:
Anthony Ramine 2017-09-17 21:35:21 +02:00
parent aa67ff30db
commit 3592108759

View file

@ -48,16 +48,13 @@ use encoding::label::encoding_from_whatwg_label;
use html5ever::{LocalName, Prefix}; use html5ever::{LocalName, Prefix};
use hyper::header::{Charset, ContentDisposition, ContentType, DispositionParam, DispositionType}; use hyper::header::{Charset, ContentDisposition, ContentType, DispositionParam, DispositionType};
use hyper::method::Method; use hyper::method::Method;
use msg::constellation_msg::PipelineId;
use script_thread::MainThreadScriptMsg; use script_thread::MainThreadScriptMsg;
use script_traits::LoadData; use script_traits::LoadData;
use servo_rand::random; use servo_rand::random;
use std::borrow::ToOwned; use std::borrow::ToOwned;
use std::cell::Cell; use std::cell::Cell;
use std::sync::mpsc::Sender;
use style::attr::AttrValue; use style::attr::AttrValue;
use style::str::split_html_space_chars; use style::str::split_html_space_chars;
use task::Task;
use task_source::TaskSource; use task_source::TaskSource;
#[derive(Clone, Copy, HeapSizeOf, JSTraceable, PartialEq)] #[derive(Clone, Copy, HeapSizeOf, JSTraceable, PartialEq)]
@ -436,20 +433,26 @@ impl HTMLFormElement {
// Each planned navigation task is tagged with a generation ID, and // Each planned navigation task is tagged with a generation ID, and
// before the task is handled, it first checks whether the HTMLFormElement's // before the task is handled, it first checks whether the HTMLFormElement's
// generation ID is the same as its own generation ID. // generation ID is the same as its own generation ID.
let GenerationId(prev_id) = self.generation_id.get(); let generation_id = GenerationId(self.generation_id.get().0 + 1);
self.generation_id.set(GenerationId(prev_id + 1)); self.generation_id.set(generation_id);
// Step 2 // Step 2.
let nav = box PlannedNavigation { let pipeline_id = window.upcast::<GlobalScope>().pipeline_id();
load_data: load_data, let script_chan = window.main_thread_script_chan().clone();
pipeline_id: window.upcast::<GlobalScope>().pipeline_id(), let this = Trusted::new(self);
script_chan: window.main_thread_script_chan().clone(), let task = box task!(navigate_to_form_planned_navigation: move || {
generation_id: self.generation_id.get(), if generation_id != this.root().generation_id.get() {
form: Trusted::new(self) return;
}; }
script_chan.send(MainThreadScriptMsg::Navigate(
pipeline_id,
load_data,
false,
)).unwrap();
});
// Step 3 // Step 3.
window.dom_manipulation_task_source().queue(nav, window.upcast()).unwrap(); window.dom_manipulation_task_source().queue(task, window.upcast()).unwrap();
} }
/// Interactively validate the constraints of form elements /// Interactively validate the constraints of form elements
@ -1108,24 +1111,6 @@ impl FormControlElementHelpers for Element {
} }
} }
struct PlannedNavigation {
load_data: LoadData,
pipeline_id: PipelineId,
script_chan: Sender<MainThreadScriptMsg>,
generation_id: GenerationId,
form: Trusted<HTMLFormElement>
}
impl Task for PlannedNavigation {
fn run(self: Box<Self>) {
if self.generation_id == self.form.root().generation_id.get() {
let script_chan = self.script_chan.clone();
script_chan.send(MainThreadScriptMsg::Navigate(self.pipeline_id, self.load_data, false)).unwrap();
}
}
}
// https://html.spec.whatwg.org/multipage/#multipart/form-data-encoding-algorithm // https://html.spec.whatwg.org/multipage/#multipart/form-data-encoding-algorithm
pub fn encode_multipart_form_data(form_data: &mut Vec<FormDatum>, pub fn encode_multipart_form_data(form_data: &mut Vec<FormDatum>,
boundary: String, encoding: EncodingRef) -> Vec<u8> { boundary: String, encoding: EncodingRef) -> Vec<u8> {