Make WebBluetooth an optional feature. (#35479)

Signed-off-by: Josh Matthews <josh@joshmatthews.net>
This commit is contained in:
Josh Matthews 2025-02-17 23:13:43 -05:00 committed by GitHub
parent 32f19c1eae
commit 1d606bb85c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
42 changed files with 124 additions and 37 deletions

View file

@ -12,6 +12,7 @@ name = "constellation"
path = "lib.rs"
[features]
bluetooth = ["bluetooth_traits"]
default = []
multiview = []
tracing = ["dep:tracing"]
@ -22,7 +23,7 @@ background_hang_monitor_api = { workspace = true }
background_hang_monitor = { path = "../background_hang_monitor" }
backtrace = { workspace = true }
base = { workspace = true }
bluetooth_traits = { workspace = true }
bluetooth_traits = { workspace = true, optional = true }
canvas_traits = { workspace = true }
compositing_traits = { workspace = true }
crossbeam-channel = { workspace = true }

View file

@ -103,6 +103,7 @@ use base::id::{
PipelineNamespaceRequest, TopLevelBrowsingContextId, WebViewId,
};
use base::Epoch;
#[cfg(feature = "bluetooth")]
use bluetooth_traits::BluetoothRequest;
use canvas_traits::canvas::{CanvasId, CanvasMsg};
use canvas_traits::webgl::WebGLThreads;
@ -351,6 +352,7 @@ pub struct Constellation<STF, SWF> {
/// An IPC channel for the constellation to send messages to the
/// bluetooth thread.
#[cfg(feature = "bluetooth")]
bluetooth_ipc_sender: IpcSender<BluetoothRequest>,
/// A map of origin to sender to a Service worker manager.
@ -493,6 +495,7 @@ pub struct InitialConstellationState {
pub devtools_sender: Option<Sender<DevtoolsControlMsg>>,
/// A channel to the bluetooth thread.
#[cfg(feature = "bluetooth")]
pub bluetooth_thread: IpcSender<BluetoothRequest>,
/// A proxy to the `SystemFontService` which manages the list of system fonts.
@ -711,6 +714,7 @@ where
compositor_proxy: state.compositor_proxy,
webviews: WebViewManager::default(),
devtools_sender: state.devtools_sender,
#[cfg(feature = "bluetooth")]
bluetooth_ipc_sender: state.bluetooth_thread,
public_resource_threads: state.public_resource_threads,
private_resource_threads: state.private_resource_threads,
@ -987,6 +991,7 @@ where
layout_factory: self.layout_factory.clone(),
compositor_proxy: self.compositor_proxy.clone(),
devtools_sender: self.devtools_sender.clone(),
#[cfg(feature = "bluetooth")]
bluetooth_thread: self.bluetooth_ipc_sender.clone(),
swmanager_thread: self.swmanager_ipc_sender.clone(),
system_font_service: self.system_font_service.clone(),
@ -2629,9 +2634,12 @@ where
warn!("Exit storage thread failed ({})", e);
}
debug!("Exiting bluetooth thread.");
if let Err(e) = self.bluetooth_ipc_sender.send(BluetoothRequest::Exit) {
warn!("Exit bluetooth thread failed ({})", e);
#[cfg(feature = "bluetooth")]
{
debug!("Exiting bluetooth thread.");
if let Err(e) = self.bluetooth_ipc_sender.send(BluetoothRequest::Exit) {
warn!("Exit bluetooth thread failed ({})", e);
}
}
debug!("Exiting service worker manager thread.");

View file

@ -16,6 +16,7 @@ use base::id::{
PipelineNamespaceRequest, TopLevelBrowsingContextId,
};
use base::Epoch;
#[cfg(feature = "bluetooth")]
use bluetooth_traits::BluetoothRequest;
use canvas_traits::webgl::WebGLPipeline;
use compositing_traits::{CompositionPipeline, CompositorMsg, CompositorProxy};
@ -145,6 +146,7 @@ pub struct InitialPipelineState {
pub devtools_sender: Option<Sender<DevtoolsControlMsg>>,
/// A channel to the bluetooth thread.
#[cfg(feature = "bluetooth")]
pub bluetooth_thread: IpcSender<BluetoothRequest>,
/// A channel to the service worker manager thread
@ -269,6 +271,7 @@ impl Pipeline {
.clone(),
bhm_control_port: None,
devtools_ipc_sender: script_to_devtools_ipc_sender,
#[cfg(feature = "bluetooth")]
bluetooth_thread: state.bluetooth_thread,
swmanager_thread: state.swmanager_thread,
system_font_service: state.system_font_service.to_sender(),
@ -477,6 +480,7 @@ pub struct UnprivilegedPipelineContent {
bhm_control_port: Option<IpcReceiver<BackgroundHangMonitorControlMsg>>,
layout_to_constellation_chan: IpcSender<LayoutMsg>,
devtools_ipc_sender: Option<IpcSender<ScriptToDevtoolsControlMsg>>,
#[cfg(feature = "bluetooth")]
bluetooth_thread: IpcSender<BluetoothRequest>,
swmanager_thread: IpcSender<SWManagerMsg>,
system_font_service: SystemFontServiceProxySender,
@ -527,6 +531,7 @@ impl UnprivilegedPipelineContent {
pipeline_to_constellation_sender: self.script_to_constellation_chan.clone(),
background_hang_monitor_register: background_hang_monitor_register.clone(),
layout_to_constellation_ipc_sender: self.layout_to_constellation_chan.clone(),
#[cfg(feature = "bluetooth")]
bluetooth_sender: self.bluetooth_thread,
resource_threads: self.resource_threads,
image_cache: image_cache.clone(),

View file

@ -233,6 +233,7 @@ mod from_script {
target_variant!("NotifyLoadStatusChanged(LoadStatus::Complete")
},
Self::Panic(..) => target_variant!("Panic"),
#[cfg(feature = "bluetooth")]
Self::GetSelectedBluetoothDevice(..) => {
target_variant!("GetSelectedBluetoothDevice")
},