Skip to content
Permalink
Browse files

Make Window::scroll_offsets store keys as OpaqueNode values

This is the type that is supposed to signal that we will never ever
try to get back a Node from it in an unsafe way, unlike
UntrustedNodeAddress.
  • Loading branch information...
nox committed Jan 14, 2019
1 parent 887cc62 commit e57d09abb83b26f4471477653819f3a1637c04aa
Showing with 12 additions and 14 deletions.
  1. +2 −1 components/script/dom/bindings/trace.rs
  2. +8 −12 components/script/dom/window.rs
  3. +2 −1 components/script/script_thread.rs
@@ -115,6 +115,7 @@ use std::sync::{Arc, Mutex};
use std::time::{Instant, SystemTime};
use style::attr::{AttrIdentifier, AttrValue, LengthOrPercentageOrAuto};
use style::context::QuirksMode;
use style::dom::OpaqueNode;
use style::element_state::*;
use style::media_queries::MediaList;
use style::properties::PropertyDeclarationBlock;
@@ -418,7 +419,7 @@ unsafe_no_jsmanaged_fields!(BufferQueue, QuirksMode, StrTendril);
unsafe_no_jsmanaged_fields!(Runtime);
unsafe_no_jsmanaged_fields!(HeaderMap, Method);
unsafe_no_jsmanaged_fields!(WindowProxyHandler);
unsafe_no_jsmanaged_fields!(UntrustedNodeAddress);
unsafe_no_jsmanaged_fields!(UntrustedNodeAddress, OpaqueNode);
unsafe_no_jsmanaged_fields!(LengthOrPercentageOrAuto);
unsafe_no_jsmanaged_fields!(RGBA);
unsafe_no_jsmanaged_fields!(StorageType);
@@ -102,7 +102,7 @@ use script_layout_interface::{PendingImageState, TrustedNodeAddress};
use script_traits::webdriver_msg::{WebDriverJSError, WebDriverJSResult};
use script_traits::{ConstellationControlMsg, DocumentState, LoadData};
use script_traits::{ScriptMsg, ScriptToConstellationChan, ScrollState, TimerEvent, TimerEventId};
use script_traits::{TimerSchedulerMsg, UntrustedNodeAddress, WindowSizeData, WindowSizeType};
use script_traits::{TimerSchedulerMsg, WindowSizeData, WindowSizeType};
use selectors::attr::CaseSensitivity;
use servo_config::opts;
use servo_geometry::{f32_rect_to_au_rect, MaxRect};
@@ -119,6 +119,7 @@ use std::mem;
use std::rc::Rc;
use std::sync::atomic::Ordering;
use std::sync::{Arc, Mutex};
use style::dom::OpaqueNode;
use style::error_reporting::{ContextualParseError, ParseErrorReporter};
use style::media_queries;
use style::parser::ParserContext as CssParserContext;
@@ -247,7 +248,7 @@ pub struct Window {
error_reporter: CSSErrorReporter,

/// A list of scroll offsets for each scrollable element.
scroll_offsets: DomRefCell<HashMap<UntrustedNodeAddress, Vector2D<f32>>>,
scroll_offsets: DomRefCell<HashMap<OpaqueNode, Vector2D<f32>>>,

/// All the MediaQueryLists we need to update
media_query_lists: DOMTracker<MediaQueryList>,
@@ -389,7 +390,7 @@ impl Window {
/// Sets a new list of scroll offsets.
///
/// This is called when layout gives us new ones and WebRender is in use.
pub fn set_scroll_offsets(&self, offsets: HashMap<UntrustedNodeAddress, Vector2D<f32>>) {
pub fn set_scroll_offsets(&self, offsets: HashMap<OpaqueNode, Vector2D<f32>>) {
*self.scroll_offsets.borrow_mut() = offsets
}

@@ -1601,11 +1602,7 @@ impl Window {
}

pub fn scroll_offset_query(&self, node: &Node) -> Vector2D<f32> {
if let Some(scroll_offset) = self
.scroll_offsets
.borrow()
.get(&node.to_untrusted_node_address())
{
if let Some(scroll_offset) = self.scroll_offsets.borrow().get(&node.to_opaque()) {
return *scroll_offset;
}
Vector2D::new(0.0, 0.0)
@@ -1620,10 +1617,9 @@ impl Window {
// The scroll offsets are immediatly updated since later calls
// to topScroll and others may access the properties before
// webrender has a chance to update the offsets.
self.scroll_offsets.borrow_mut().insert(
node.to_untrusted_node_address(),
Vector2D::new(x_ as f32, y_ as f32),
);
self.scroll_offsets
.borrow_mut()
.insert(node.to_opaque(), Vector2D::new(x_ as f32, y_ as f32));

let NodeScrollIdResponse(scroll_id) = self.layout_rpc.node_scroll_id();

@@ -146,6 +146,7 @@ use std::result::Result;
use std::sync::Arc;
use std::thread;
use std::time::{Duration, SystemTime};
use style::dom::OpaqueNode;
use style::thread_state::{self, ThreadState};
use time::{at_utc, get_time, precise_time_ns, Timespec};
use url::percent_encoding::percent_decode;
@@ -1914,7 +1915,7 @@ impl ScriptThread {
if node_address == UntrustedNodeAddress(ptr::null()) {
window.update_viewport_for_scroll(-scroll_offset.x, -scroll_offset.y);
} else {
scroll_offsets.insert(node_address, -*scroll_offset);
scroll_offsets.insert(OpaqueNode(node_address.0 as usize), -*scroll_offset);
}
}
window.set_scroll_offsets(scroll_offsets)

0 comments on commit e57d09a

Please sign in to comment.
You can’t perform that action at this time.