base: Finish rename of TopLevelBrowsingContextId to WebViewId (#35896)

The `WebViewId` name is a lot more descriptive these days to the casual
reader, so I think we can go ahead and finish the rename.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
This commit is contained in:
Martin Robinson 2025-03-11 11:56:10 +01:00 committed by GitHub
parent 81fe4bbb1e
commit 2464d0937f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
22 changed files with 416 additions and 570 deletions

View file

@ -4,7 +4,7 @@
use std::collections::{HashMap, HashSet};
use base::id::{BrowsingContextGroupId, BrowsingContextId, PipelineId, TopLevelBrowsingContextId};
use base::id::{BrowsingContextGroupId, BrowsingContextId, PipelineId, WebViewId};
use euclid::Size2D;
use log::warn;
use style_traits::CSSPixel;
@ -48,7 +48,7 @@ pub struct BrowsingContext {
pub id: BrowsingContextId,
/// The top-level browsing context ancestor
pub top_level_id: TopLevelBrowsingContextId,
pub top_level_id: WebViewId,
/// The size of the frame.
pub size: Size2D<f32, CSSPixel>,
@ -82,7 +82,7 @@ impl BrowsingContext {
pub fn new(
bc_group_id: BrowsingContextGroupId,
id: BrowsingContextId,
top_level_id: TopLevelBrowsingContextId,
top_level_id: WebViewId,
pipeline_id: PipelineId,
parent_pipeline_id: Option<PipelineId>,
size: Size2D<f32, CSSPixel>,

File diff suppressed because it is too large Load diff

View file

@ -11,7 +11,7 @@ use std::sync::Arc;
use std::thread;
use backtrace::Backtrace;
use base::id::TopLevelBrowsingContextId;
use base::id::WebViewId;
use compositing_traits::ConstellationMsg as FromCompositorMsg;
use crossbeam_channel::Sender;
use log::{Level, LevelFilter, Log, Metadata, Record};
@ -87,7 +87,7 @@ impl Log for FromCompositorLogger {
fn log(&self, record: &Record) {
if let Some(entry) = log_entry(record) {
let top_level_id = TopLevelBrowsingContextId::installed();
let top_level_id = WebViewId::installed();
let thread_name = thread::current().name().map(ToOwned::to_owned);
let msg = FromCompositorMsg::LogEntry(top_level_id, thread_name, entry);
let chan = self.constellation_chan.lock();

View file

@ -14,7 +14,7 @@ use background_hang_monitor_api::{
use base::Epoch;
use base::id::{
BrowsingContextId, HistoryStateId, PipelineId, PipelineNamespace, PipelineNamespaceId,
PipelineNamespaceRequest, TopLevelBrowsingContextId,
PipelineNamespaceRequest, WebViewId,
};
#[cfg(feature = "bluetooth")]
use bluetooth_traits::BluetoothRequest;
@ -58,7 +58,7 @@ pub struct Pipeline {
pub browsing_context_id: BrowsingContextId,
/// The ID of the top-level browsing context that contains this Pipeline.
pub top_level_browsing_context_id: TopLevelBrowsingContextId,
pub webview_id: WebViewId,
pub opener: Option<BrowsingContextId>,
@ -112,7 +112,7 @@ pub struct InitialPipelineState {
pub browsing_context_id: BrowsingContextId,
/// The ID of the top-level browsing context that contains this Pipeline.
pub top_level_browsing_context_id: TopLevelBrowsingContextId,
pub webview_id: WebViewId,
/// The ID of the parent pipeline and frame type, if any.
/// If `None`, this is the root.
@ -219,7 +219,7 @@ impl Pipeline {
parent_info: state.parent_pipeline_id,
new_pipeline_id: state.id,
browsing_context_id: state.browsing_context_id,
top_level_browsing_context_id: state.top_level_browsing_context_id,
webview_id: state.webview_id,
opener: state.opener,
load_data: state.load_data.clone(),
window_size: state.window_size,
@ -261,7 +261,7 @@ impl Pipeline {
let mut unprivileged_pipeline_content = UnprivilegedPipelineContent {
id: state.id,
browsing_context_id: state.browsing_context_id,
top_level_browsing_context_id: state.top_level_browsing_context_id,
webview_id: state.webview_id,
parent_pipeline_id: state.parent_pipeline_id,
opener: state.opener,
script_to_constellation_chan: state.script_to_constellation_chan.clone(),
@ -327,7 +327,7 @@ impl Pipeline {
let pipeline = Pipeline::new(
state.id,
state.browsing_context_id,
state.top_level_browsing_context_id,
state.webview_id,
state.opener,
script_chan,
state.compositor_proxy,
@ -345,7 +345,7 @@ impl Pipeline {
pub fn new(
id: PipelineId,
browsing_context_id: BrowsingContextId,
top_level_browsing_context_id: TopLevelBrowsingContextId,
webview_id: WebViewId,
opener: Option<BrowsingContextId>,
event_loop: Rc<EventLoop>,
compositor_proxy: CompositorProxy,
@ -355,7 +355,7 @@ impl Pipeline {
let pipeline = Pipeline {
id,
browsing_context_id,
top_level_browsing_context_id,
webview_id,
opener,
event_loop,
compositor_proxy,
@ -387,7 +387,7 @@ impl Pipeline {
// since the compositor never blocks on the constellation.
if let Ok((sender, receiver)) = ipc::channel() {
self.compositor_proxy.send(CompositorMsg::PipelineExited(
self.top_level_browsing_context_id,
self.webview_id,
self.id,
sender,
));
@ -425,7 +425,7 @@ impl Pipeline {
pub fn to_sendable(&self) -> CompositionPipeline {
CompositionPipeline {
id: self.id,
top_level_browsing_context_id: self.top_level_browsing_context_id,
webview_id: self.webview_id,
script_chan: self.event_loop.sender(),
}
}
@ -458,8 +458,7 @@ impl Pipeline {
/// running timers at a heavily limited rate.
pub fn set_throttled(&self, throttled: bool) {
let script_msg = ScriptThreadMessage::SetThrottled(self.id, throttled);
let compositor_msg =
CompositorMsg::SetThrottled(self.top_level_browsing_context_id, self.id, throttled);
let compositor_msg = CompositorMsg::SetThrottled(self.webview_id, self.id, throttled);
let err = self.event_loop.send(script_msg);
if let Err(e) = err {
warn!("Sending SetThrottled to script failed ({}).", e);
@ -474,7 +473,7 @@ impl Pipeline {
#[derive(Deserialize, Serialize)]
pub struct UnprivilegedPipelineContent {
id: PipelineId,
top_level_browsing_context_id: TopLevelBrowsingContextId,
webview_id: WebViewId,
browsing_context_id: BrowsingContextId,
parent_pipeline_id: Option<PipelineId>,
opener: Option<BrowsingContextId>,
@ -527,7 +526,7 @@ impl UnprivilegedPipelineContent {
InitialScriptState {
id: self.id,
browsing_context_id: self.browsing_context_id,
top_level_browsing_context_id: self.top_level_browsing_context_id,
webview_id: self.webview_id,
parent_info: self.parent_pipeline_id,
opener: self.opener,
constellation_sender: self.script_chan.clone(),

View file

@ -5,7 +5,7 @@
use std::cmp::PartialEq;
use std::fmt;
use base::id::{BrowsingContextId, HistoryStateId, PipelineId, TopLevelBrowsingContextId};
use base::id::{BrowsingContextId, HistoryStateId, PipelineId, WebViewId};
use euclid::Size2D;
use log::debug;
use script_traits::LoadData;
@ -115,7 +115,7 @@ pub struct SessionHistoryChange {
pub browsing_context_id: BrowsingContextId,
/// The top-level browsing context ancestor.
pub top_level_browsing_context_id: TopLevelBrowsingContextId,
pub webview_id: WebViewId,
/// The pipeline for the document being loaded.
pub new_pipeline_id: PipelineId,

View file

@ -4,16 +4,16 @@
use std::collections::HashMap;
use base::id::TopLevelBrowsingContextId;
use base::id::WebViewId;
#[derive(Debug)]
pub struct WebViewManager<WebView> {
/// Our top-level browsing contexts. In the WebRender scene, their pipelines are the children of
/// a single root pipeline that also applies any pinch zoom transformation.
webviews: HashMap<TopLevelBrowsingContextId, WebView>,
webviews: HashMap<WebViewId, WebView>,
/// The order in which they were focused, latest last.
focus_order: Vec<TopLevelBrowsingContextId>,
focus_order: Vec<WebViewId>,
/// Whether the latest webview in focus order is currently focused.
is_focused: bool,
@ -30,63 +30,47 @@ impl<WebView> Default for WebViewManager<WebView> {
}
impl<WebView> WebViewManager<WebView> {
pub fn add(
&mut self,
top_level_browsing_context_id: TopLevelBrowsingContextId,
webview: WebView,
) {
self.webviews.insert(top_level_browsing_context_id, webview);
pub fn add(&mut self, webview_id: WebViewId, webview: WebView) {
self.webviews.insert(webview_id, webview);
}
pub fn remove(
&mut self,
top_level_browsing_context_id: TopLevelBrowsingContextId,
) -> Option<WebView> {
if self.focus_order.last() == Some(&top_level_browsing_context_id) {
pub fn remove(&mut self, webview_id: WebViewId) -> Option<WebView> {
if self.focus_order.last() == Some(&webview_id) {
self.is_focused = false;
}
self.focus_order
.retain(|b| *b != top_level_browsing_context_id);
self.webviews.remove(&top_level_browsing_context_id)
self.focus_order.retain(|b| *b != webview_id);
self.webviews.remove(&webview_id)
}
pub fn get(
&self,
top_level_browsing_context_id: TopLevelBrowsingContextId,
) -> Option<&WebView> {
self.webviews.get(&top_level_browsing_context_id)
pub fn get(&self, webview_id: WebViewId) -> Option<&WebView> {
self.webviews.get(&webview_id)
}
pub fn get_mut(
&mut self,
top_level_browsing_context_id: TopLevelBrowsingContextId,
) -> Option<&mut WebView> {
self.webviews.get_mut(&top_level_browsing_context_id)
pub fn get_mut(&mut self, webview_id: WebViewId) -> Option<&mut WebView> {
self.webviews.get_mut(&webview_id)
}
pub fn focused_webview(&self) -> Option<(TopLevelBrowsingContextId, &WebView)> {
pub fn focused_webview(&self) -> Option<(WebViewId, &WebView)> {
if !self.is_focused {
return None;
}
if let Some(top_level_browsing_context_id) = self.focus_order.last().cloned() {
if let Some(webview_id) = self.focus_order.last().cloned() {
debug_assert!(
self.webviews.contains_key(&top_level_browsing_context_id),
self.webviews.contains_key(&webview_id),
"BUG: webview in .focus_order not in .webviews!",
);
self.get(top_level_browsing_context_id)
.map(|webview| (top_level_browsing_context_id, webview))
self.get(webview_id).map(|webview| (webview_id, webview))
} else {
debug_assert!(false, "BUG: .is_focused but no webviews in .focus_order!");
None
}
}
pub fn focus(&mut self, top_level_browsing_context_id: TopLevelBrowsingContextId) {
debug_assert!(self.webviews.contains_key(&top_level_browsing_context_id));
self.focus_order
.retain(|b| *b != top_level_browsing_context_id);
self.focus_order.push(top_level_browsing_context_id);
pub fn focus(&mut self, webview_id: WebViewId) {
debug_assert!(self.webviews.contains_key(&webview_id));
self.focus_order.retain(|b| *b != webview_id);
self.focus_order.push(webview_id);
self.is_focused = true;
}
@ -100,14 +84,13 @@ mod test {
use std::num::NonZeroU32;
use base::id::{
BrowsingContextId, BrowsingContextIndex, PipelineNamespace, PipelineNamespaceId,
TopLevelBrowsingContextId, WebViewId,
BrowsingContextId, BrowsingContextIndex, PipelineNamespace, PipelineNamespaceId, WebViewId,
};
use crate::webview::WebViewManager;
fn id(namespace_id: u32, index: u32) -> WebViewId {
TopLevelBrowsingContextId(BrowsingContextId {
WebViewId(BrowsingContextId {
namespace_id: PipelineNamespaceId(namespace_id),
index: BrowsingContextIndex(NonZeroU32::new(index).expect("Incorrect test case")),
})