mirror of
https://github.com/servo/servo.git
synced 2025-08-05 21:50:18 +01:00
script: Stop using legacy time
for Document::reflow_timeout
(#33258)
Use `std::time` from the Rust standard library instead. This is one step toward removing our use of the legacy `time` crate which has security issues. Signed-off-by: Martin Robinson <mrobinson@igalia.com>
This commit is contained in:
parent
cd8b803368
commit
83a40c5180
2 changed files with 27 additions and 21 deletions
|
@ -327,7 +327,7 @@ pub struct Document {
|
||||||
/// The current active HTML parser, to allow resuming after interruptions.
|
/// The current active HTML parser, to allow resuming after interruptions.
|
||||||
current_parser: MutNullableDom<ServoParser>,
|
current_parser: MutNullableDom<ServoParser>,
|
||||||
/// When we should kick off a reflow. This happens during parsing.
|
/// When we should kick off a reflow. This happens during parsing.
|
||||||
reflow_timeout: Cell<Option<u64>>,
|
reflow_timeout: Cell<Option<Instant>>,
|
||||||
/// The cached first `base` element with an `href` attribute.
|
/// The cached first `base` element with an `href` attribute.
|
||||||
base_element: MutNullableDom<HTMLBaseElement>,
|
base_element: MutNullableDom<HTMLBaseElement>,
|
||||||
/// This field is set to the document itself for inert documents.
|
/// This field is set to the document itself for inert documents.
|
||||||
|
@ -898,27 +898,32 @@ impl Document {
|
||||||
|
|
||||||
/// Reflows and disarms the timer if the reflow timer has expired.
|
/// Reflows and disarms the timer if the reflow timer has expired.
|
||||||
pub fn reflow_if_reflow_timer_expired(&self) {
|
pub fn reflow_if_reflow_timer_expired(&self) {
|
||||||
if let Some(reflow_timeout) = self.reflow_timeout.get() {
|
let Some(reflow_timeout) = self.reflow_timeout.get() else {
|
||||||
if time::precise_time_ns() < reflow_timeout {
|
return;
|
||||||
return;
|
};
|
||||||
}
|
|
||||||
|
|
||||||
self.reflow_timeout.set(None);
|
if Instant::now() < reflow_timeout {
|
||||||
self.window
|
return;
|
||||||
.reflow(ReflowGoal::Full, ReflowReason::RefreshTick);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self.reflow_timeout.set(None);
|
||||||
|
self.window
|
||||||
|
.reflow(ReflowGoal::Full, ReflowReason::RefreshTick);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Schedules a reflow to be kicked off at the given `timeout` (in `time::precise_time_ns()`
|
/// Schedules a reflow to be kicked off at the given [`Duration`] in the future. This reflow
|
||||||
/// units). This reflow happens even if the event loop is busy. This is used to display initial
|
/// happens even if the event loop is busy. This is used to display initial page content during
|
||||||
/// page content during parsing.
|
/// parsing.
|
||||||
pub fn set_reflow_timeout(&self, timeout: u64) {
|
pub fn set_reflow_timeout(&self, duration: Duration) {
|
||||||
if let Some(existing_timeout) = self.reflow_timeout.get() {
|
let new_reflow_time = Instant::now() + duration;
|
||||||
if existing_timeout < timeout {
|
|
||||||
return;
|
// Do not schedule a timeout that is longer than the one that is currently queued.
|
||||||
}
|
if matches!(self.reflow_timeout.get(), Some(existing_timeout) if existing_timeout < new_reflow_time)
|
||||||
|
{
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
self.reflow_timeout.set(Some(timeout))
|
|
||||||
|
self.reflow_timeout.set(Some(new_reflow_time))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Remove any existing association between the provided id and any elements in this document.
|
/// Remove any existing association between the provided id and any elements in this document.
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
use dom_struct::dom_struct;
|
use dom_struct::dom_struct;
|
||||||
use embedder_traits::EmbedderMsg;
|
use embedder_traits::EmbedderMsg;
|
||||||
use html5ever::{local_name, namespace_url, ns, LocalName, Prefix};
|
use html5ever::{local_name, namespace_url, ns, LocalName, Prefix};
|
||||||
|
@ -23,9 +25,8 @@ use crate::dom::htmlelement::HTMLElement;
|
||||||
use crate::dom::node::{document_from_node, window_from_node, BindContext, Node};
|
use crate::dom::node::{document_from_node, window_from_node, BindContext, Node};
|
||||||
use crate::dom::virtualmethods::VirtualMethods;
|
use crate::dom::virtualmethods::VirtualMethods;
|
||||||
|
|
||||||
/// How long we should wait before performing the initial reflow after `<body>` is parsed, in
|
/// How long we should wait before performing the initial reflow after `<body>` is parsed.
|
||||||
/// nanoseconds.
|
const INITIAL_REFLOW_DELAY: Duration = Duration::from_millis(200);
|
||||||
const INITIAL_REFLOW_DELAY: u64 = 200_000_000;
|
|
||||||
|
|
||||||
#[dom_struct]
|
#[dom_struct]
|
||||||
pub struct HTMLBodyElement {
|
pub struct HTMLBodyElement {
|
||||||
|
@ -155,7 +156,7 @@ impl VirtualMethods for HTMLBodyElement {
|
||||||
|
|
||||||
let window = window_from_node(self);
|
let window = window_from_node(self);
|
||||||
let document = window.Document();
|
let document = window.Document();
|
||||||
document.set_reflow_timeout(time::precise_time_ns() + INITIAL_REFLOW_DELAY);
|
document.set_reflow_timeout(INITIAL_REFLOW_DELAY);
|
||||||
if window.is_top_level() {
|
if window.is_top_level() {
|
||||||
let msg = EmbedderMsg::HeadParsed;
|
let msg = EmbedderMsg::HeadParsed;
|
||||||
window.send_to_embedder(msg);
|
window.send_to_embedder(msg);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue