mirror of
https://github.com/servo/servo.git
synced 2025-08-05 21:50:18 +01:00
implement window.stop, improve aborting document load
This commit is contained in:
parent
aab335e543
commit
ff62ca7c01
10 changed files with 49 additions and 18 deletions
|
@ -141,7 +141,7 @@ use style::shared_lock::{SharedRwLock as StyleSharedRwLock, SharedRwLockReadGuar
|
|||
use style::str::{split_html_space_chars, str_join};
|
||||
use style::stylesheet_set::DocumentStylesheetSet;
|
||||
use style::stylesheets::{CssRule, Stylesheet, Origin, OriginSet};
|
||||
use task_source::TaskSource;
|
||||
use task_source::{TaskSource, TaskSourceName};
|
||||
use time;
|
||||
use timers::OneshotTimerCallback;
|
||||
use url::Host;
|
||||
|
@ -2010,7 +2010,7 @@ impl Document {
|
|||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#abort-a-document
|
||||
fn abort(&self) {
|
||||
pub fn abort(&self) {
|
||||
// We need to inhibit the loader before anything else.
|
||||
self.loader.borrow_mut().inhibit_events();
|
||||
|
||||
|
@ -2029,14 +2029,21 @@ impl Document {
|
|||
*self.asap_scripts_set.borrow_mut() = vec![];
|
||||
self.asap_in_order_scripts_list.clear();
|
||||
self.deferred_scripts.clear();
|
||||
if self.loader.borrow_mut().cancel_all_loads() {
|
||||
// If any loads were canceled.
|
||||
self.salvageable.set(false);
|
||||
};
|
||||
|
||||
// TODO: https://github.com/servo/servo/issues/15236
|
||||
self.window.cancel_all_tasks();
|
||||
// Also Step 2.
|
||||
// Note: the spec says to discard any tasks queued for fetch.
|
||||
// This cancels all tasks on the networking task source, which might be too broad.
|
||||
// See https://github.com/whatwg/html/issues/3837
|
||||
self.window.cancel_all_tasks_from_source(TaskSourceName::Networking);
|
||||
|
||||
// Step 3.
|
||||
if let Some(parser) = self.get_current_parser() {
|
||||
parser.abort();
|
||||
// TODO: salvageable flag.
|
||||
self.salvageable.set(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -268,7 +268,7 @@ impl HTMLImageElement {
|
|||
|
||||
// This is a background load because the load blocker already fulfills the
|
||||
// purpose of delaying the document's load event.
|
||||
document.loader().fetch_async_background(request, action_sender);
|
||||
document.loader_mut().fetch_async_background(request, action_sender);
|
||||
}
|
||||
|
||||
/// Step 14 of https://html.spec.whatwg.org/multipage/#update-the-image-data
|
||||
|
|
|
@ -613,7 +613,7 @@ impl HTMLMediaElement {
|
|||
ROUTER.add_route(action_receiver.to_opaque(), Box::new(move |message| {
|
||||
listener.notify_fetch(message.to().unwrap());
|
||||
}));
|
||||
document.loader().fetch_async_background(request, action_sender);
|
||||
document.loader_mut().fetch_async_background(request, action_sender);
|
||||
},
|
||||
Resource::Object => {
|
||||
// FIXME(nox): Actually do something with the object.
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
attribute DOMString status;
|
||||
void close();
|
||||
readonly attribute boolean closed;
|
||||
//void stop();
|
||||
void stop();
|
||||
//void focus();
|
||||
//void blur();
|
||||
|
||||
|
|
|
@ -552,6 +552,13 @@ impl WindowMethods for Window {
|
|||
receiver.recv().unwrap();
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#dom-window-stop
|
||||
fn Stop(&self) {
|
||||
// TODO: Cancel ongoing navigation.
|
||||
let doc = self.Document();
|
||||
doc.abort();
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#dom-window-closed
|
||||
fn Closed(&self) -> bool {
|
||||
self.window_proxy.get()
|
||||
|
@ -1110,6 +1117,16 @@ impl Window {
|
|||
}
|
||||
}
|
||||
|
||||
/// Cancels all the tasks from a given task source.
|
||||
/// This sets the current sentinel value to
|
||||
/// `true` and replaces it with a brand new one for future tasks.
|
||||
pub fn cancel_all_tasks_from_source(&self, task_source_name: TaskSourceName) {
|
||||
let mut ignore_flags = self.ignore_further_async_events.borrow_mut();
|
||||
let flag = ignore_flags.entry(task_source_name).or_insert(Default::default());
|
||||
let cancelled = mem::replace(&mut *flag, Default::default());
|
||||
cancelled.store(true, Ordering::Relaxed);
|
||||
}
|
||||
|
||||
pub fn clear_js_runtime(&self) {
|
||||
// We tear down the active document, which causes all the attached
|
||||
// nodes to dispose of their layout data. This messages the layout
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue