script: Implement <meta http-equiv="refresh"> (#31468)

* script: Implement <meta http-equiv="refresh">

* Address review comments
This commit is contained in:
Smitty 2024-03-01 02:42:18 -05:00 committed by GitHub
parent ee122acdf4
commit 0beec63c86
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
19 changed files with 227 additions and 396 deletions

View file

@ -140,6 +140,7 @@ use crate::dom::htmlhtmlelement::HTMLHtmlElement;
use crate::dom::htmliframeelement::HTMLIFrameElement;
use crate::dom::htmlimageelement::HTMLImageElement;
use crate::dom::htmlinputelement::HTMLInputElement;
use crate::dom::htmlmetaelement::RefreshRedirectDue;
use crate::dom::htmlscriptelement::{HTMLScriptElement, ScriptResult};
use crate::dom::htmltextareaelement::HTMLTextAreaElement;
use crate::dom::htmltitleelement::HTMLTitleElement;
@ -233,6 +234,17 @@ enum FocusTransaction {
InTransaction(Option<Dom<Element>>),
}
/// Information about a declarative refresh
#[derive(JSTraceable, MallocSizeOf)]
pub enum DeclarativeRefresh {
PendingLoad {
#[no_trace]
url: ServoUrl,
time: u64,
},
CreatedAfterLoad,
}
/// <https://dom.spec.whatwg.org/#document>
#[dom_struct]
pub struct Document {
@ -435,6 +447,8 @@ pub struct Document {
animations: DomRefCell<Animations>,
/// The nearest inclusive ancestors to all the nodes that require a restyle.
dirty_root: MutNullableDom<Element>,
/// <https://html.spec.whatwg.org/multipage/#will-declaratively-refresh>
declarative_refresh: DomRefCell<Option<DeclarativeRefresh>>,
}
#[derive(JSTraceable, MallocSizeOf)]
@ -2399,6 +2413,19 @@ impl Document {
task!(completely_loaded: move || {
let document = document.root();
document.completely_loaded.set(true);
if let Some(DeclarativeRefresh::PendingLoad {
url,
time
}) = &*document.declarative_refresh.borrow() {
// https://html.spec.whatwg.org/multipage/#shared-declarative-refresh-steps
document.window.upcast::<GlobalScope>().schedule_callback(
OneshotTimerCallback::RefreshRedirectDue(RefreshRedirectDue {
window: window_from_node(&*document),
url: url.clone(),
}),
MsDuration::new(time.saturating_mul(1000)),
);
}
// Note: this will, among others, result in the "iframe-load-event-steps" being run.
// https://html.spec.whatwg.org/multipage/#iframe-load-event-steps
document.notify_constellation_load();
@ -2409,6 +2436,10 @@ impl Document {
}
}
pub fn completely_loaded(&self) -> bool {
self.completely_loaded.get()
}
// https://html.spec.whatwg.org/multipage/#pending-parsing-blocking-script
pub fn set_pending_parsing_blocking_script(
&self,
@ -3195,6 +3226,7 @@ impl Document {
},
animations: DomRefCell::new(Animations::new()),
dirty_root: Default::default(),
declarative_refresh: Default::default(),
}
}
@ -3940,6 +3972,13 @@ impl Document {
pub(crate) fn cancel_animations_for_node(&self, node: &Node) {
self.animations.borrow().cancel_animations_for_node(node);
}
pub(crate) fn will_declaratively_refresh(&self) -> bool {
self.declarative_refresh.borrow().is_some()
}
pub(crate) fn set_declarative_refresh(&self, refresh: DeclarativeRefresh) {
*self.declarative_refresh.borrow_mut() = Some(refresh);
}
}
impl Element {