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

@ -6,7 +6,7 @@ use std::sync::Arc;
use std::sync::atomic::AtomicBool;
use std::thread::{self, JoinHandle};
use base::id::{BrowsingContextId, PipelineId, TopLevelBrowsingContextId, WebViewId};
use base::id::{BrowsingContextId, PipelineId, WebViewId};
use crossbeam_channel::{Receiver, Sender, unbounded};
use devtools_traits::DevtoolScriptControlMsg;
use dom_struct::dom_struct;
@ -349,7 +349,7 @@ impl DedicatedWorkerGlobalScope {
insecure_requests_policy: InsecureRequestsPolicy,
) -> JoinHandle<()> {
let serialized_worker_url = worker_url.to_string();
let top_level_browsing_context_id = TopLevelBrowsingContextId::installed();
let webview_id = WebViewId::installed();
let current_global = GlobalScope::current().expect("No current global object");
let origin = current_global.origin().immutable().clone();
let referrer = current_global.get_referrer();
@ -361,8 +361,8 @@ impl DedicatedWorkerGlobalScope {
.spawn(move || {
thread_state::initialize(ThreadState::SCRIPT | ThreadState::IN_WORKER);
if let Some(top_level_browsing_context_id) = top_level_browsing_context_id {
TopLevelBrowsingContextId::install(top_level_browsing_context_id);
if let Some(webview_id) = webview_id {
WebViewId::install(webview_id);
}
let roots = RootCollection::new();
@ -376,21 +376,17 @@ impl DedicatedWorkerGlobalScope {
let referrer = referrer_url.map(Referrer::ReferrerUrl).unwrap_or(referrer);
let request = RequestBuilder::new(
top_level_browsing_context_id,
worker_url.clone(),
referrer,
)
.destination(Destination::Worker)
.mode(RequestMode::SameOrigin)
.credentials_mode(CredentialsMode::CredentialsSameOrigin)
.parser_metadata(ParserMetadata::NotParserInserted)
.use_url_credentials(true)
.pipeline_id(Some(pipeline_id))
.referrer_policy(referrer_policy)
.referrer_policy(referrer_policy)
.insecure_requests_policy(insecure_requests_policy)
.origin(origin);
let request = RequestBuilder::new(webview_id, worker_url.clone(), referrer)
.destination(Destination::Worker)
.mode(RequestMode::SameOrigin)
.credentials_mode(CredentialsMode::CredentialsSameOrigin)
.parser_metadata(ParserMetadata::NotParserInserted)
.use_url_credentials(true)
.pipeline_id(Some(pipeline_id))
.referrer_policy(referrer_policy)
.referrer_policy(referrer_policy)
.insecure_requests_policy(insecure_requests_policy)
.origin(origin);
let runtime = unsafe {
let task_source = SendableTaskSource {

View file

@ -4,7 +4,7 @@
use std::cell::Cell;
use base::id::{BrowsingContextId, PipelineId, TopLevelBrowsingContextId};
use base::id::{BrowsingContextId, PipelineId, WebViewId};
use bitflags::bitflags;
use dom_struct::dom_struct;
use html5ever::{LocalName, Prefix, local_name, namespace_url, ns};
@ -74,7 +74,7 @@ enum ProcessingMode {
pub(crate) struct HTMLIFrameElement {
htmlelement: HTMLElement,
#[no_trace]
top_level_browsing_context_id: Cell<Option<TopLevelBrowsingContextId>>,
webview_id: Cell<Option<WebViewId>>,
#[no_trace]
browsing_context_id: Cell<Option<BrowsingContextId>>,
#[no_trace]
@ -143,7 +143,7 @@ impl HTMLIFrameElement {
Some(id) => id,
};
let top_level_browsing_context_id = match self.top_level_browsing_context_id() {
let webview_id = match self.webview_id() {
None => return warn!("Attempted to start a new pipeline on an unattached iframe."),
Some(id) => id,
};
@ -188,7 +188,7 @@ impl HTMLIFrameElement {
let load_info = IFrameLoadInfo {
parent_pipeline_id: window.pipeline_id(),
browsing_context_id,
top_level_browsing_context_id,
webview_id,
new_pipeline_id,
is_private: false, // FIXME
inherited_secure_context: load_data.inherited_secure_context,
@ -223,7 +223,7 @@ impl HTMLIFrameElement {
parent_info: Some(window.pipeline_id()),
new_pipeline_id,
browsing_context_id,
top_level_browsing_context_id,
webview_id,
opener: None,
load_data,
window_size,
@ -406,11 +406,10 @@ impl HTMLIFrameElement {
Some(document.insecure_requests_policy()),
);
let browsing_context_id = BrowsingContextId::new();
let top_level_browsing_context_id = window.window_proxy().top_level_browsing_context_id();
let webview_id = window.window_proxy().webview_id();
self.pipeline_id.set(None);
self.pending_pipeline_id.set(None);
self.top_level_browsing_context_id
.set(Some(top_level_browsing_context_id));
self.webview_id.set(Some(webview_id));
self.browsing_context_id.set(Some(browsing_context_id));
self.start_new_pipeline(
load_data,
@ -424,7 +423,7 @@ impl HTMLIFrameElement {
self.pipeline_id.set(None);
self.pending_pipeline_id.set(None);
self.about_blank_pipeline_id.set(None);
self.top_level_browsing_context_id.set(None);
self.webview_id.set(None);
self.browsing_context_id.set(None);
}
@ -460,7 +459,7 @@ impl HTMLIFrameElement {
HTMLIFrameElement {
htmlelement: HTMLElement::new_inherited(local_name, prefix, document),
browsing_context_id: Cell::new(None),
top_level_browsing_context_id: Cell::new(None),
webview_id: Cell::new(None),
pipeline_id: Cell::new(None),
pending_pipeline_id: Cell::new(None),
about_blank_pipeline_id: Cell::new(None),
@ -500,8 +499,8 @@ impl HTMLIFrameElement {
}
#[inline]
pub(crate) fn top_level_browsing_context_id(&self) -> Option<TopLevelBrowsingContextId> {
self.top_level_browsing_context_id.get()
pub(crate) fn webview_id(&self) -> Option<WebViewId> {
self.webview_id.get()
}
pub(crate) fn set_throttled(&self, throttled: bool) {

View file

@ -5,7 +5,7 @@
use std::cell::Cell;
use std::ptr;
use base::id::{BrowsingContextId, PipelineId, TopLevelBrowsingContextId};
use base::id::{BrowsingContextId, PipelineId, WebViewId};
use dom_struct::dom_struct;
use html5ever::local_name;
use indexmap::map::IndexMap;
@ -81,7 +81,7 @@ pub(crate) struct WindowProxy {
/// The frame id of the top-level ancestor browsing context.
/// In the case that this is a top-level window, this is our id.
#[no_trace]
top_level_browsing_context_id: TopLevelBrowsingContextId,
webview_id: WebViewId,
/// The name of the browsing context (sometimes, but not always,
/// equal to the name of a container element)
@ -128,7 +128,7 @@ pub(crate) struct WindowProxy {
impl WindowProxy {
fn new_inherited(
browsing_context_id: BrowsingContextId,
top_level_browsing_context_id: TopLevelBrowsingContextId,
webview_id: WebViewId,
currently_active: Option<PipelineId>,
frame_element: Option<&Element>,
parent: Option<&WindowProxy>,
@ -141,7 +141,7 @@ impl WindowProxy {
WindowProxy {
reflector: Reflector::new(),
browsing_context_id,
top_level_browsing_context_id,
webview_id,
name: DomRefCell::new(name),
currently_active: Cell::new(currently_active),
discarded: Cell::new(false),
@ -161,7 +161,7 @@ impl WindowProxy {
pub(crate) fn new(
window: &Window,
browsing_context_id: BrowsingContextId,
top_level_browsing_context_id: TopLevelBrowsingContextId,
webview_id: WebViewId,
frame_element: Option<&Element>,
parent: Option<&WindowProxy>,
opener: Option<BrowsingContextId>,
@ -187,7 +187,7 @@ impl WindowProxy {
let current = Some(window.global().pipeline_id());
let window_proxy = Box::new(WindowProxy::new_inherited(
browsing_context_id,
top_level_browsing_context_id,
webview_id,
current,
frame_element,
parent,
@ -221,7 +221,7 @@ impl WindowProxy {
pub(crate) fn new_dissimilar_origin(
global_to_clone_from: &GlobalScope,
browsing_context_id: BrowsingContextId,
top_level_browsing_context_id: TopLevelBrowsingContextId,
webview_id: WebViewId,
parent: Option<&WindowProxy>,
opener: Option<BrowsingContextId>,
creator: CreatorBrowsingContextInfo,
@ -234,7 +234,7 @@ impl WindowProxy {
// Create a new browsing context.
let window_proxy = Box::new(WindowProxy::new_inherited(
browsing_context_id,
top_level_browsing_context_id,
webview_id,
None,
None,
parent,
@ -322,7 +322,7 @@ impl WindowProxy {
parent_info: None,
new_pipeline_id: response.new_pipeline_id,
browsing_context_id: new_browsing_context_id,
top_level_browsing_context_id: response.new_webview_id,
webview_id: response.new_webview_id,
opener: Some(self.browsing_context_id),
load_data,
window_size: window.window_size(),
@ -585,8 +585,8 @@ impl WindowProxy {
self.browsing_context_id
}
pub(crate) fn top_level_browsing_context_id(&self) -> TopLevelBrowsingContextId {
self.top_level_browsing_context_id
pub(crate) fn webview_id(&self) -> WebViewId {
self.webview_id
}
pub(crate) fn frame_element(&self) -> Option<&Element> {

View file

@ -9,7 +9,7 @@
use std::cell::Cell;
use base::cross_process_instant::CrossProcessInstant;
use base::id::{BrowsingContextId, PipelineId, TopLevelBrowsingContextId};
use base::id::{BrowsingContextId, PipelineId, WebViewId};
use content_security_policy::Destination;
use crossbeam_channel::Sender;
use http::header;
@ -128,7 +128,7 @@ pub(crate) struct InProgressLoad {
pub(crate) browsing_context_id: BrowsingContextId,
/// The top level ancestor browsing context.
#[no_trace]
pub(crate) top_level_browsing_context_id: TopLevelBrowsingContextId,
pub(crate) webview_id: WebViewId,
/// The parent pipeline and frame type associated with this load, if any.
#[no_trace]
pub(crate) parent_info: Option<PipelineId>,
@ -166,7 +166,7 @@ impl InProgressLoad {
pub(crate) fn new(
id: PipelineId,
browsing_context_id: BrowsingContextId,
top_level_browsing_context_id: TopLevelBrowsingContextId,
webview_id: WebViewId,
parent_info: Option<PipelineId>,
opener: Option<BrowsingContextId>,
window_size: WindowSizeData,
@ -177,7 +177,7 @@ impl InProgressLoad {
InProgressLoad {
pipeline_id: id,
browsing_context_id,
top_level_browsing_context_id,
webview_id,
parent_info,
opener,
window_size,
@ -193,9 +193,9 @@ impl InProgressLoad {
pub(crate) fn request_builder(&mut self) -> RequestBuilder {
let id = self.pipeline_id;
let top_level_browsing_context_id = self.top_level_browsing_context_id;
let webview_id = self.webview_id;
let mut request_builder = RequestBuilder::new(
Some(top_level_browsing_context_id),
Some(webview_id),
self.load_data.url.clone(),
self.load_data.referrer.clone(),
)

View file

@ -35,9 +35,7 @@ use background_hang_monitor_api::{
};
use base::Epoch;
use base::cross_process_instant::CrossProcessInstant;
use base::id::{
BrowsingContextId, HistoryStateId, PipelineId, PipelineNamespace, TopLevelBrowsingContextId,
};
use base::id::{BrowsingContextId, HistoryStateId, PipelineId, PipelineNamespace, WebViewId};
use canvas_traits::webgl::WebGLPipeline;
use chrono::{DateTime, Local};
use crossbeam_channel::unbounded;
@ -401,12 +399,12 @@ impl ScriptThreadFactory for ScriptThread {
.spawn(move || {
thread_state::initialize(ThreadState::SCRIPT | ThreadState::LAYOUT);
PipelineNamespace::install(state.pipeline_namespace_id);
TopLevelBrowsingContextId::install(state.top_level_browsing_context_id);
WebViewId::install(state.webview_id);
let roots = RootCollection::new();
let _stack_roots = ThreadLocalStackRoots::new(&roots);
let id = state.id;
let browsing_context_id = state.browsing_context_id;
let top_level_browsing_context_id = state.top_level_browsing_context_id;
let webview_id = state.webview_id;
let parent_info = state.parent_info;
let opener = state.opener;
let memory_profiler_sender = state.memory_profiler_sender.clone();
@ -425,7 +423,7 @@ impl ScriptThreadFactory for ScriptThread {
script_thread.pre_page_load(InProgressLoad::new(
id,
browsing_context_id,
top_level_browsing_context_id,
webview_id,
parent_info,
opener,
window_size,
@ -661,7 +659,7 @@ impl ScriptThread {
pub(crate) fn get_top_level_for_browsing_context(
sender_pipeline: PipelineId,
browsing_context_id: BrowsingContextId,
) -> Option<TopLevelBrowsingContextId> {
) -> Option<WebViewId> {
with_script_thread(|script_thread| {
script_thread.ask_constellation_for_top_level_info(sender_pipeline, browsing_context_id)
})
@ -1791,13 +1789,13 @@ impl ScriptThread {
ScriptThreadMessage::UpdatePipelineId(
parent_pipeline_id,
browsing_context_id,
top_level_browsing_context_id,
webview_id,
new_pipeline_id,
reason,
) => self.handle_update_pipeline_id(
parent_pipeline_id,
browsing_context_id,
top_level_browsing_context_id,
webview_id,
new_pipeline_id,
reason,
can_gc,
@ -2381,7 +2379,7 @@ impl ScriptThread {
parent_info,
new_pipeline_id,
browsing_context_id,
top_level_browsing_context_id,
webview_id,
opener,
load_data,
window_size,
@ -2392,7 +2390,7 @@ impl ScriptThread {
let new_load = InProgressLoad::new(
new_pipeline_id,
browsing_context_id,
top_level_browsing_context_id,
webview_id,
parent_info,
opener,
window_size,
@ -2518,7 +2516,7 @@ impl ScriptThread {
&self,
pipeline_id: PipelineId,
source_pipeline_id: PipelineId,
source_browsing_context: TopLevelBrowsingContextId,
source_browsing_context: WebViewId,
origin: Option<ImmutableOrigin>,
source_origin: ImmutableOrigin,
data: StructuredSerializedData,
@ -2573,7 +2571,7 @@ impl ScriptThread {
&self,
parent_pipeline_id: PipelineId,
browsing_context_id: BrowsingContextId,
top_level_browsing_context_id: TopLevelBrowsingContextId,
webview_id: WebViewId,
new_pipeline_id: PipelineId,
reason: UpdatePipelineIdReason,
can_gc: CanGc,
@ -2592,7 +2590,7 @@ impl ScriptThread {
let _ = self.local_window_proxy(
&window,
browsing_context_id,
top_level_browsing_context_id,
webview_id,
Some(parent_pipeline_id),
// Any local window proxy has already been created, so there
// is no need to pass along existing opener information that
@ -2899,7 +2897,7 @@ impl ScriptThread {
&self,
sender_pipeline: PipelineId,
browsing_context_id: BrowsingContextId,
) -> Option<TopLevelBrowsingContextId> {
) -> Option<WebViewId> {
let (result_sender, result_receiver) = ipc::channel().unwrap();
let msg = ScriptMsg::GetTopForBrowsingContext(browsing_context_id, result_sender);
self.senders
@ -2920,7 +2918,7 @@ impl ScriptThread {
fn remote_window_proxy(
&self,
global_to_clone: &GlobalScope,
top_level_browsing_context_id: TopLevelBrowsingContextId,
webview_id: WebViewId,
pipeline_id: PipelineId,
opener: Option<BrowsingContextId>,
) -> Option<DomRoot<WindowProxy>> {
@ -2931,12 +2929,7 @@ impl ScriptThread {
}
let parent_browsing_context = parent_pipeline_id.and_then(|parent_id| {
self.remote_window_proxy(
global_to_clone,
top_level_browsing_context_id,
parent_id,
opener,
)
self.remote_window_proxy(global_to_clone, webview_id, parent_id, opener)
});
let opener_browsing_context = opener.and_then(ScriptThread::find_window_proxy);
@ -2949,7 +2942,7 @@ impl ScriptThread {
let window_proxy = WindowProxy::new_dissimilar_origin(
global_to_clone,
browsing_context_id,
top_level_browsing_context_id,
webview_id,
parent_browsing_context.as_deref(),
opener,
creator,
@ -2970,7 +2963,7 @@ impl ScriptThread {
&self,
window: &Window,
browsing_context_id: BrowsingContextId,
top_level_browsing_context_id: TopLevelBrowsingContextId,
webview_id: WebViewId,
parent_info: Option<PipelineId>,
opener: Option<BrowsingContextId>,
) -> DomRoot<WindowProxy> {
@ -2986,12 +2979,9 @@ impl ScriptThread {
});
let parent_browsing_context = match (parent_info, iframe.as_ref()) {
(_, Some(iframe)) => Some(iframe.owner_window().window_proxy()),
(Some(parent_id), _) => self.remote_window_proxy(
window.upcast(),
top_level_browsing_context_id,
parent_id,
opener,
),
(Some(parent_id), _) => {
self.remote_window_proxy(window.upcast(), webview_id, parent_id, opener)
},
_ => None,
};
@ -3005,7 +2995,7 @@ impl ScriptThread {
let window_proxy = WindowProxy::new(
window,
browsing_context_id,
top_level_browsing_context_id,
webview_id,
iframe.as_deref().map(Castable::upcast),
parent_browsing_context.as_deref(),
opener,
@ -3053,7 +3043,7 @@ impl ScriptThread {
};
let paint_time_metrics = PaintTimeMetrics::new(
incomplete.top_level_browsing_context_id,
incomplete.webview_id,
incomplete.pipeline_id,
self.senders.time_profiler_sender.clone(),
self.senders.layout_to_constellation_ipc_sender.clone(),
@ -3070,7 +3060,7 @@ impl ScriptThread {
let layout_config = LayoutConfig {
id: incomplete.pipeline_id,
webview_id: incomplete.top_level_browsing_context_id,
webview_id: incomplete.webview_id,
url: final_url.clone(),
is_iframe: incomplete.parent_info.is_some(),
script_chan: self.senders.constellation_sender.clone(),
@ -3084,7 +3074,7 @@ impl ScriptThread {
// Create the window and document objects.
let window = Window::new(
incomplete.top_level_browsing_context_id,
incomplete.webview_id,
self.js_runtime.clone(),
self.senders.self_sender.clone(),
self.layout_factory.create(layout_config),
@ -3129,7 +3119,7 @@ impl ScriptThread {
let window_proxy = self.local_window_proxy(
&window,
incomplete.browsing_context_id,
incomplete.top_level_browsing_context_id,
incomplete.webview_id,
incomplete.parent_info,
incomplete.opener,
);
@ -3225,7 +3215,7 @@ impl ScriptThread {
self.handle_update_pipeline_id(
parent_pipeline,
window_proxy.browsing_context_id(),
window_proxy.top_level_browsing_context_id(),
window_proxy.webview_id(),
incomplete.pipeline_id,
UpdatePipelineIdReason::Navigation,
can_gc,
@ -3238,8 +3228,7 @@ impl ScriptThread {
.unwrap();
// Notify devtools that a new script global exists.
let is_top_level_global =
incomplete.top_level_browsing_context_id.0 == incomplete.browsing_context_id;
let is_top_level_global = incomplete.webview_id.0 == incomplete.browsing_context_id;
self.notify_devtools(
document.Title(),
final_url.clone(),

View file

@ -264,9 +264,7 @@ pub(crate) unsafe fn jsval_to_webdriver(
let window_proxy = window.window_proxy();
if window_proxy.is_browsing_context_discarded() {
Err(WebDriverJSError::StaleElementReference)
} else if window_proxy.browsing_context_id() ==
window_proxy.top_level_browsing_context_id()
{
} else if window_proxy.browsing_context_id() == window_proxy.webview_id() {
Ok(WebDriverJSValue::Window(WebWindow(
window.Document().upcast::<Node>().unique_id(),
)))