Truly independent web browser
LibWeb: Remove Rust FFI exports that nothing calls
Andreas Klingc38a8fa6c084
diff --git a/Libraries/LibWeb/HTML/Parser/Rust/src/lib.rs b/Libraries/LibWeb/HTML/Parser/Rust/src/lib.rsindex 79b84b05d28..3d7076ff4ac 100644--- a/Libraries/LibWeb/HTML/Parser/Rust/src/lib.rs+++ b/Libraries/LibWeb/HTML/Parser/Rust/src/lib.rs@@ -164,27 +164,6 @@ pub unsafe extern "C" fn rust_html_tokenizer_create_from_ascii(make_handle(HtmlTokenizer::new(code_units))}-/// Create a new Rust HTML tokenizer directly from a UTF-8 byte buffer.-/// Rust converts the bytes directly to the tokenizer's UTF-16 storage.-///-/// # Safety-/// `bytes` must point to `len` valid UTF-8 bytes.-#[unsafe(no_mangle)]-pub unsafe extern "C" fn rust_html_tokenizer_create_from_utf8(- bytes: *const u8,- len: usize,-) -> *mut RustFfiTokenizerHandle {- let code_units = if bytes.is_null() || len == 0 {- Vec::new()- } else {- let slice = unsafe { std::slice::from_raw_parts(bytes, len) };- // SAFETY: The caller guarantees valid UTF-8.- unsafe { std::str::from_utf8_unchecked(slice) }.encode_utf16().collect()- };-- make_handle(HtmlTokenizer::new(code_units))-}-fn make_handle(tokenizer: HtmlTokenizer) -> *mut RustFfiTokenizerHandle {let handle = Box::new(RustFfiTokenizerHandle {tokenizer,diff --git a/Libraries/LibWeb/HTML/Parser/Rust/src/parser.rs b/Libraries/LibWeb/HTML/Parser/Rust/src/parser.rsindex d42c25a2ba9..62f0be26840 100644--- a/Libraries/LibWeb/HTML/Parser/Rust/src/parser.rs+++ b/Libraries/LibWeb/HTML/Parser/Rust/src/parser.rs@@ -172,7 +172,6 @@ unsafe extern "C" {/// Opaque handle for the Rust HTML parser, passed across the FFI boundary.pub struct RustFfiHtmlParserHandle {- run_count: u64,state: ParserState,}@@ -5577,7 +5576,6 @@ impl Token {#[unsafe(no_mangle)]pub extern "C" fn rust_html_parser_create() -> *mut RustFfiHtmlParserHandle {Box::into_raw(Box::new(RustFfiHtmlParserHandle {- run_count: 0,state: ParserState::new(),}))}@@ -5654,7 +5652,6 @@ pub unsafe extern "C" fn rust_html_parser_run_document(// synchronously execute script, and script can re-enter this function through document.write() or document.close().// TreeBuilder uses raw pointers internally so those nested parser runs do not alias an outer Rust `&mut` borrow.unsafe {- (*handle).run_count = (*handle).run_count.wrapping_add(1);(*handle).state.scripting_enabled = scripting_enabled;(*handle).state.allow_declarative_shadow_roots = allow_declarative_shadow_roots;(*handle).state.parser_pause_requested = false;@@ -5728,19 +5725,6 @@ pub unsafe extern "C" fn rust_html_parser_take_pending_svg_script(handle: *mut Rhandle.state.pending_svg_script.take().unwrap_or(0)}-/// Return how many times this parser handle has been asked to run.-///-/// # Safety-/// `handle` must be a valid pointer from `rust_html_parser_create`.-#[unsafe(no_mangle)]-pub unsafe extern "C" fn rust_html_parser_run_count(handle: *const RustFfiHtmlParserHandle) -> u64 {- if handle.is_null() {- return 0;- }- let handle = unsafe { &*handle };- handle.run_count-}-/// Destroy a Rust HTML parser.////// # Safetydiff --git a/Libraries/LibWeb/Rust/src/css/computed_longhand_table.rs b/Libraries/LibWeb/Rust/src/css/computed_longhand_table.rsindex 8321070d523..cae8369c7ce 100644--- a/Libraries/LibWeb/Rust/src/css/computed_longhand_table.rs+++ b/Libraries/LibWeb/Rust/src/css/computed_longhand_table.rs@@ -1510,53 +1510,6 @@ pub unsafe extern "C" fn rust_computed_longhand_table_freeze(table: *mut Computeunsafe { &mut *table }.freeze();}-/// Returns the retained raw cascaded font-size data, or null when none won.-///-/// # Safety-/// `table` must be a valid table.-#[unsafe(no_mangle)]-pub unsafe extern "C" fn rust_computed_longhand_table_raw_cascaded_font_size(- table: *const ComputedLonghandTable,-) -> *const c_void {- unsafe { &*table }.raw_cascaded_font_size()-}--/// Marks a longhand's stored value `!important` (or not).-///-/// # Safety-/// `table` must be a valid, unfrozen, uniquely owned table.-#[unsafe(no_mangle)]-pub unsafe extern "C" fn rust_computed_longhand_table_set_important(- table: *mut ComputedLonghandTable,- property_id: u16,- important: bool,-) {- unsafe { &mut *table }.set_important(property_id, important);-}--/// Marks a longhand's computed value as taken by inheritance (or not).-///-/// # Safety-/// `table` must be a valid, unfrozen, uniquely owned table.-#[unsafe(no_mangle)]-pub unsafe extern "C" fn rust_computed_longhand_table_set_inherited(- table: *mut ComputedLonghandTable,- property_id: u16,- inherited: bool,-) {- unsafe { &mut *table }.set_inherited(property_id, inherited);-}--/// # Safety-/// `table` must be a valid table.-#[unsafe(no_mangle)]-pub unsafe extern "C" fn rust_computed_longhand_table_is_important(- table: *const ComputedLonghandTable,- property_id: u16,-) -> bool {- unsafe { &*table }.is_important(property_id)-}-/// The importance bitmap, in the C++ `FixedBitmap` byte layout. The pointer/// stays valid while the caller's table reference is live.///diff --git a/Libraries/LibWeb/Rust/src/css/style/engine_calls.rs b/Libraries/LibWeb/Rust/src/css/style/engine_calls.rsindex db0307894ce..76788850ea6 100644--- a/Libraries/LibWeb/Rust/src/css/style/engine_calls.rs+++ b/Libraries/LibWeb/Rust/src/css/style/engine_calls.rs@@ -850,28 +850,6 @@ pub unsafe extern "C" fn style_engine_style_record_custom_property_environment(environment}-/// The style record the engine assigns the element `node` names, or 0.-///-/// # Safety-///-/// `host` must be a live document host, on its document's thread.-#[unsafe(no_mangle)]-pub unsafe extern "C" fn style_engine_assigned_style_record(- host: &DocumentHost,- read: &crate::render_state::BegunRead,- node: u32,-) -> u64 {- let Some(node) = super::StyleNodeID::from_raw(node) else {- return 0;- };- with_engine(read, host, |engine| {- engine- .computed_group_sets- .assigned_style_record(node)- .map_or(0, |record| record.raw())- })-}-/// What the host knows of its document's style engine, which answers the host's reads without asking the render owner.pub(crate) struct EngineMemo {/// The view of each style record the host asked about, the custom-property environment it was computed in, anddiff --git a/Libraries/LibWeb/Rust/src/layout/layout_changes.rs b/Libraries/LibWeb/Rust/src/layout/layout_changes.rsindex 3786c04a3e6..b5350313940 100644--- a/Libraries/LibWeb/Rust/src/layout/layout_changes.rs+++ b/Libraries/LibWeb/Rust/src/layout/layout_changes.rs@@ -338,8 +338,6 @@ pub(crate) enum LayoutWrite<'a> {DetachRemainingRowsForRemoval(&'a [u32]),/// The row takes the derived style record `record` its layout node made.AdoptDerivedNodeStyle { node: NodeSlotId, record: u64 },- /// The row's layout style takes the display `display`.- SetLayoutDisplay { node: NodeSlotId, display: u32 },/// The anonymous rows below the row inherit its style again.ReinheritAnonymousDescendants { node: NodeSlotId },/// The viewport and the boxes of the root element and its body take the styles viewport propagation gives them.@@ -391,12 +389,6 @@ impl LayoutWrite<'_> {arena.apply_reinherited_style_record(host_calls, node, derived);false}- Self::SetLayoutDisplay { node, display } => {- arena.update_layout_style(host_calls, node, |style| {- style.set_display(crate::css::display::FfiDisplay::from_raw(display));- });- false- }Self::ReinheritAnonymousDescendants { node } => {arena.reinherit_anonymous_descendants(host_calls, node);falsediff --git a/Libraries/LibWeb/Rust/src/layout/layout_node_arena/main_thread_entries.rs b/Libraries/LibWeb/Rust/src/layout/layout_node_arena/main_thread_entries.rsindex d02089b0a3d..08a2916ca3b 100644--- a/Libraries/LibWeb/Rust/src/layout/layout_node_arena/main_thread_entries.rs+++ b/Libraries/LibWeb/Rust/src/layout/layout_node_arena/main_thread_entries.rs@@ -124,17 +124,6 @@ pub unsafe extern "C" fn render_state_adopt_derived_node_style(host: &DocumentHounsafe { write_and_pay(host, node_read(), LayoutWrite::AdoptDerivedNodeStyle { node, record }) };}-/// The row's layout style takes the display `display`.-///-/// # Safety-///-/// `host` must be a live document host, on its document's thread.-#[unsafe(no_mangle)]-pub unsafe extern "C" fn render_state_set_layout_display(host: &DocumentHost, node: NodeSlotId, display: u32) {- // SAFETY: Guaranteed by the caller.- unsafe { write_and_pay(host, node_read(), LayoutWrite::SetLayoutDisplay { node, display }) };-}-/// The anonymous rows below the row inherit its style again, which their layout nodes hear of once the host has its next/// job back. A table box, which `is_table_box` says the row's style makes it, may itself take a record the arena derives/// as its wrapper inherits its style again, which its layout node hears of before it reads its style again.diff --git a/Libraries/LibWeb/Rust/src/render_state/clock/resize.rs b/Libraries/LibWeb/Rust/src/render_state/clock/resize.rsdeleted file mode 100644index 40cc20158e4..00000000000--- a/Libraries/LibWeb/Rust/src/render_state/clock/resize.rs+++ /dev/null@@ -1,201 +0,0 @@-/*- * Copyright (c) 2026-present, the Ladybird developers.- *- * SPDX-License-Identifier: BSD-2-Clause- */--//! Viewport input that reaches the render owner without passing through the host's event loop.--use super::{ClockTicks, Lane, Park};-use crate::css::css_pixels::{CssPixelRect, CssPixels};-use crate::css::media_list::MediaListData;-use crate::css::parser::query_parser::{FfiMediaEnvironment, FfiMediaFeatureValue, MEDIA_FEATURES};-use crate::css::style::style_job::SealedStyleInputs;-use crate::css::style_compute::FfiLengthResolutionContext;-use crate::css::style_sheet::NativeStyleSheet;-use crate::render_state::{DocumentHost, RenderState};-use libgfx_rust::{IntRect, IntSize};-use std::sync::Arc;-use std::sync::atomic::Ordering;--#[repr(u8)]-#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]-pub enum FfiResizeBlocker {- None,- #[default]- Unpublished,- ResizeListener,- AnimationFrameCallback,- ResizeObserver,- MediaQueryListener,- IntersectionObserver,- ViewTransition,- ContentVisibility,- ScrollState,- Animation,- Focus,- EmbeddedFrame,- ViewportStyle,- MediaChange,- NeedsHost,-}--#[derive(Clone, Copy, Default, PartialEq, Eq)]-pub(super) struct ViewportSize {- pub(super) width: i32,- pub(super) height: i32,-}--#[derive(Default)]-pub(super) struct ResizeMailbox {- pub(super) latest: Option<ViewportSize>,- pub(super) pending: bool,- pub(super) presented: u64,-}--pub(super) struct ResizePlan {- pub(super) size: ViewportSize,- scale: f64,- media: Vec<(Arc<MediaListData>, bool)>,- values: Box<[FfiMediaFeatureValue]>,- lengths: FfiLengthResolutionContext,-}--impl ResizePlan {- /// Seals media conditions as immutable parsed queries. A breakpoint requiring host-owned stylesheet- /// processing declines before changing the fork.- pub(super) fn new(inputs: &SealedStyleInputs, sheets: &[*const NativeStyleSheet]) -> Self {- let inputs = inputs.inputs();- // SAFETY: The caller holds the sealed inputs and lends live sheets on the host's thread.- let mut media = Vec::new();- for &sheet in sheets {- if let Some(sheet) = unsafe { sheet.as_ref() } {- sheet.collect_resize_media(&mut media);- }- }- let values = unsafe {- std::slice::from_raw_parts(inputs.media_feature_values.as_pointer().cast(), inputs.media_feature_value_count)- }.to_vec().into_boxed_slice();- let lengths = unsafe {- *inputs.media_length_resolution_context.as_pointer().cast::<FfiLengthResolutionContext>()- };- Self {- size: ViewportSize {- width: (inputs.viewport_width * inputs.device_pixels_per_css_pixel).round() as i32,- height: (inputs.viewport_height * inputs.device_pixels_per_css_pixel).round() as i32,- },- scale: inputs.device_pixels_per_css_pixel,- media,- values,- lengths,- }- }-- fn accepts(&self, size: ViewportSize) -> bool {- let width = size.width as f64 / self.scale;- let height = size.height as f64 / self.scale;- let mut values = self.values.clone();- for (feature, value) in MEDIA_FEATURES.iter().zip(values.iter_mut()) {- match feature.name {- "width" => value.value = width,- "height" => value.value = height,- "aspect-ratio" => { value.value = width; value.second_value = height; }- "orientation" => value.keyword = if width > height {- crate::css::css_enums::keyword::LANDSCAPE- } else {- crate::css::css_enums::keyword::PORTRAIT- },- _ => {}- }- }- let lengths = FfiLengthResolutionContext { viewport_width: width, viewport_height: height, ..self.lengths };- let environment = FfiMediaEnvironment {- values: values.as_ptr(), value_count: values.len(),- length_resolution_context: std::ptr::from_ref(&lengths).cast(),- };- // SAFETY: The local values and context outlive every query evaluation.- let environment = unsafe { environment.borrow() };- self.media.iter().all(|(list, matched)| {- (list.queries.is_empty() || list.queries.iter().any(|query| query.matches_media(environment))) == *matched- })- }-}--impl ClockTicks {- pub(super) fn viewport_changed(&self, size: ViewportSize) -> bool {- if size.width <= 0 || size.height <= 0 { return false; }- let mut mailbox = self.resize.lock().expect("resize mailbox");- if mailbox.latest == Some(size) { return false; }- mailbox.latest = Some(size);- mailbox.pending = true;- self.resize_blocker.load(Ordering::Acquire) == FfiResizeBlocker::None as u8- }-- pub(super) fn resize_waits(&self) -> bool {- self.resize_blocker.load(Ordering::Acquire) == FfiResizeBlocker::None as u8- && self.resize.lock().expect("resize mailbox").pending- }-}--impl Lane {- pub(super) fn resize(&mut self, state: &mut RenderState, size: ViewportSize) -> Result<(), Park> {- let plan = self.plan.resize.as_mut().ok_or(Park("no resize plan"))?;- if !plan.accepts(size) { return Err(Park("media conditions changed")); }- let width = CssPixels::nearest_value_for(size.width as f64 / plan.scale);- let height = CssPixels::nearest_value_for(size.height as f64 / plan.scale);- self.plan.round.set_viewport_size(width, height);- let arena = state.arena.arena();- arena.set_needs_layout_update(arena.layout_root(), true);- plan.size = size;- let mut recorder = self.recording.0.take(super::WaitsForTickRecording(()));- if let Some(inputs) = &mut recorder.recorder.published_inputs {- inputs.css_viewport_rect.width = width;- inputs.css_viewport_rect.height = height;- inputs.uncaptured.device_viewport_size = IntSize { width: size.width, height: size.height };- inputs.bitmap_rect = IntRect { x: 0, y: 0, width: size.width, height: size.height };- }- self.recording = super::TickRecording(crate::stage_thread::Riding::landed(recorder));- Ok(())- }-}--/// # Safety-/// `ticks` must be a retained clock handle.-#[unsafe(no_mangle)]-pub unsafe extern "C" fn clock_ticks_viewport_changed(ticks: &ClockTicks, width: i32, height: i32) -> bool {- ticks.viewport_changed(ViewportSize { width, height })-}--/// Invalidates eligibility synchronously when script installs a rendering hook.-/// # Safety-/// `host` must be live on its document's thread.-#[unsafe(no_mangle)]-pub unsafe extern "C" fn document_host_block_resize(host: &DocumentHost) {- host.clock_ticks().resize_blocker.store(FfiResizeBlocker::Unpublished as u8, Ordering::Release);-}--/// The compositor's latest viewport remains authoritative across host transactions.-/// # Safety-/// `host` must be live and `width` and `height` writable.-#[unsafe(no_mangle)]-pub unsafe extern "C" fn document_host_latest_viewport(host: &DocumentHost, width: &mut i32, height: &mut i32) -> bool {- let mailbox = host.clock_ticks().resize.lock().expect("resize mailbox");- let Some(size) = mailbox.latest else { return false; };- *width = size.width;- *height = size.height;- true-}--/// # Safety-/// `host` must be live on its document's thread.-#[unsafe(no_mangle)]-pub unsafe extern "C" fn document_host_resize_frame_count(host: &DocumentHost) -> u64 {- host.clock_ticks().resize.lock().expect("resize mailbox").presented-}--/// # Safety-/// `host` must be live on its document's thread.-#[unsafe(no_mangle)]-pub unsafe extern "C" fn document_host_resize_blocker(host: &DocumentHost) -> u8 {- host.clock_ticks().resize_blocker.load(Ordering::Acquire)-}