diff options
author | Josh Matthews <josh@joshmatthews.net> | 2025-02-17 23:13:43 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-02-18 04:13:43 +0000 |
commit | 1d606bb85cd34c6d37ae8d022b7cb32adadb9b08 (patch) | |
tree | 3c1c70468394f3cd722117f22d84cbcb069cebec | |
parent | 32f19c1eae3ead86987fa353f3f3e7e6fadb47eb (diff) | |
download | servo-1d606bb85cd34c6d37ae8d022b7cb32adadb9b08.tar.gz servo-1d606bb85cd34c6d37ae8d022b7cb32adadb9b08.zip |
Make WebBluetooth an optional feature. (#35479)
Signed-off-by: Josh Matthews <josh@joshmatthews.net>
42 files changed, 124 insertions, 37 deletions
diff --git a/components/constellation/Cargo.toml b/components/constellation/Cargo.toml index 3a22e73be45..d4f8c592bea 100644 --- a/components/constellation/Cargo.toml +++ b/components/constellation/Cargo.toml @@ -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 } diff --git a/components/constellation/constellation.rs b/components/constellation/constellation.rs index 2715534d098..0debfc8f18f 100644 --- a/components/constellation/constellation.rs +++ b/components/constellation/constellation.rs @@ -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."); diff --git a/components/constellation/pipeline.rs b/components/constellation/pipeline.rs index 9c46fa2a510..3e5327451a4 100644 --- a/components/constellation/pipeline.rs +++ b/components/constellation/pipeline.rs @@ -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(), diff --git a/components/constellation/tracing.rs b/components/constellation/tracing.rs index 78ac8ae8fd9..6009b07b984 100644 --- a/components/constellation/tracing.rs +++ b/components/constellation/tracing.rs @@ -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") }, diff --git a/components/script/Cargo.toml b/components/script/Cargo.toml index 5875edbccaa..186366eef72 100644 --- a/components/script/Cargo.toml +++ b/components/script/Cargo.toml @@ -13,6 +13,7 @@ name = "script" path = "lib.rs" [features] +bluetooth = ['bluetooth_traits', 'script_bindings/bluetooth'] crown = ['js/crown'] debugmozjs = ['js/debugmozjs'] jitspew = ['js/jitspew'] @@ -41,7 +42,7 @@ base = { workspace = true } base64 = { workspace = true } bincode = { workspace = true } bitflags = { workspace = true } -bluetooth_traits = { workspace = true } +bluetooth_traits = { workspace = true, optional = true } canvas_traits = { workspace = true } cbc = { workspace = true } cipher = { workspace = true } diff --git a/components/script/dom/bluetooth.rs b/components/script/dom/bluetooth/bluetooth.rs index 4e47c9664bf..4e47c9664bf 100644 --- a/components/script/dom/bluetooth.rs +++ b/components/script/dom/bluetooth/bluetooth.rs diff --git a/components/script/dom/bluetoothadvertisingevent.rs b/components/script/dom/bluetooth/bluetoothadvertisingevent.rs index b33f1e17323..b33f1e17323 100644 --- a/components/script/dom/bluetoothadvertisingevent.rs +++ b/components/script/dom/bluetooth/bluetoothadvertisingevent.rs diff --git a/components/script/dom/bluetoothcharacteristicproperties.rs b/components/script/dom/bluetooth/bluetoothcharacteristicproperties.rs index 992bdac6a9f..992bdac6a9f 100644 --- a/components/script/dom/bluetoothcharacteristicproperties.rs +++ b/components/script/dom/bluetooth/bluetoothcharacteristicproperties.rs diff --git a/components/script/dom/bluetoothdevice.rs b/components/script/dom/bluetooth/bluetoothdevice.rs index 4a7783be899..4a7783be899 100644 --- a/components/script/dom/bluetoothdevice.rs +++ b/components/script/dom/bluetooth/bluetoothdevice.rs diff --git a/components/script/dom/bluetoothpermissionresult.rs b/components/script/dom/bluetooth/bluetoothpermissionresult.rs index d5d0e521262..d5d0e521262 100644 --- a/components/script/dom/bluetoothpermissionresult.rs +++ b/components/script/dom/bluetooth/bluetoothpermissionresult.rs diff --git a/components/script/dom/bluetoothremotegattcharacteristic.rs b/components/script/dom/bluetooth/bluetoothremotegattcharacteristic.rs index f07355469f1..f07355469f1 100644 --- a/components/script/dom/bluetoothremotegattcharacteristic.rs +++ b/components/script/dom/bluetooth/bluetoothremotegattcharacteristic.rs diff --git a/components/script/dom/bluetoothremotegattdescriptor.rs b/components/script/dom/bluetooth/bluetoothremotegattdescriptor.rs index 3d714884860..3d714884860 100644 --- a/components/script/dom/bluetoothremotegattdescriptor.rs +++ b/components/script/dom/bluetooth/bluetoothremotegattdescriptor.rs diff --git a/components/script/dom/bluetoothremotegattserver.rs b/components/script/dom/bluetooth/bluetoothremotegattserver.rs index 1df7fc3bd4c..1df7fc3bd4c 100644 --- a/components/script/dom/bluetoothremotegattserver.rs +++ b/components/script/dom/bluetooth/bluetoothremotegattserver.rs diff --git a/components/script/dom/bluetoothremotegattservice.rs b/components/script/dom/bluetooth/bluetoothremotegattservice.rs index 014f78d2669..014f78d2669 100644 --- a/components/script/dom/bluetoothremotegattservice.rs +++ b/components/script/dom/bluetooth/bluetoothremotegattservice.rs diff --git a/components/script/dom/bluetoothuuid.rs b/components/script/dom/bluetooth/bluetoothuuid.rs index 719625eb659..719625eb659 100644 --- a/components/script/dom/bluetoothuuid.rs +++ b/components/script/dom/bluetooth/bluetoothuuid.rs diff --git a/components/script/dom/bluetooth/mod.rs b/components/script/dom/bluetooth/mod.rs new file mode 100644 index 00000000000..158e66073e4 --- /dev/null +++ b/components/script/dom/bluetooth/mod.rs @@ -0,0 +1,16 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ + +pub(crate) use self::bluetooth::*; +pub(crate) mod bluetooth; +pub(crate) mod bluetoothadvertisingevent; +pub(crate) mod bluetoothcharacteristicproperties; +pub(crate) mod bluetoothdevice; +pub(crate) mod bluetoothpermissionresult; +pub(crate) mod bluetoothremotegattcharacteristic; +pub(crate) mod bluetoothremotegattdescriptor; +pub(crate) mod bluetoothremotegattserver; +pub(crate) mod bluetoothremotegattservice; +pub(crate) mod bluetoothuuid; +pub(crate) mod testrunner; diff --git a/components/script/dom/testrunner.rs b/components/script/dom/bluetooth/testrunner.rs index d2d42131d08..d2d42131d08 100644 --- a/components/script/dom/testrunner.rs +++ b/components/script/dom/bluetooth/testrunner.rs diff --git a/components/script/dom/mod.rs b/components/script/dom/mod.rs index 0fd8c9c10ee..c2049aab55c 100644 --- a/components/script/dom/mod.rs +++ b/components/script/dom/mod.rs @@ -233,16 +233,11 @@ pub(crate) mod beforeunloadevent; pub(crate) mod bindings; pub(crate) mod biquadfilternode; pub(crate) mod blob; +#[cfg(feature = "bluetooth")] +#[allow(clippy::module_inception)] pub(crate) mod bluetooth; -pub(crate) mod bluetoothadvertisingevent; -pub(crate) mod bluetoothcharacteristicproperties; -pub(crate) mod bluetoothdevice; -pub(crate) mod bluetoothpermissionresult; -pub(crate) mod bluetoothremotegattcharacteristic; -pub(crate) mod bluetoothremotegattdescriptor; -pub(crate) mod bluetoothremotegattserver; -pub(crate) mod bluetoothremotegattservice; -pub(crate) mod bluetoothuuid; +#[cfg(feature = "bluetooth")] +pub(crate) use self::bluetooth::*; pub(crate) mod broadcastchannel; pub(crate) mod bytelengthqueuingstrategy; pub(crate) mod canvasgradient; @@ -552,7 +547,6 @@ pub(crate) mod testbindingpairiterable; pub(crate) mod testbindingproxy; pub(crate) mod testbindingsetlike; pub(crate) mod testns; -pub(crate) mod testrunner; pub(crate) mod testworklet; pub(crate) mod testworkletglobalscope; pub(crate) mod text; diff --git a/components/script/dom/navigator.rs b/components/script/dom/navigator.rs index 7aae62abe92..2751831224f 100644 --- a/components/script/dom/navigator.rs +++ b/components/script/dom/navigator.rs @@ -16,6 +16,7 @@ use crate::dom::bindings::reflector::{reflect_dom_object, DomGlobal, Reflector}; use crate::dom::bindings::root::{DomRoot, MutNullableDom}; use crate::dom::bindings::str::DOMString; use crate::dom::bindings::utils::to_frozen_array; +#[cfg(feature = "bluetooth")] use crate::dom::bluetooth::Bluetooth; use crate::dom::gamepad::Gamepad; use crate::dom::gamepadevent::GamepadEventType; @@ -42,6 +43,7 @@ pub(super) fn hardware_concurrency() -> u64 { #[dom_struct] pub(crate) struct Navigator { reflector_: Reflector, + #[cfg(feature = "bluetooth")] bluetooth: MutNullableDom<Bluetooth>, plugins: MutNullableDom<PluginArray>, mime_types: MutNullableDom<MimeTypeArray>, @@ -63,6 +65,7 @@ impl Navigator { fn new_inherited() -> Navigator { Navigator { reflector_: Reflector::new(), + #[cfg(feature = "bluetooth")] bluetooth: Default::default(), plugins: Default::default(), mime_types: Default::default(), @@ -195,6 +198,7 @@ impl NavigatorMethods<crate::DomTypeHolder> for Navigator { } // https://webbluetoothcg.github.io/web-bluetooth/#dom-navigator-bluetooth + #[cfg(feature = "bluetooth")] fn Bluetooth(&self) -> DomRoot<Bluetooth> { self.bluetooth.or_init(|| Bluetooth::new(&self.global())) } diff --git a/components/script/dom/permissions.rs b/components/script/dom/permissions.rs index 3e9573bacb4..4553a8dbe28 100644 --- a/components/script/dom/permissions.rs +++ b/components/script/dom/permissions.rs @@ -23,7 +23,9 @@ use crate::dom::bindings::codegen::Bindings::WindowBinding::Window_Binding::Wind use crate::dom::bindings::error::Error; use crate::dom::bindings::reflector::{reflect_dom_object, DomGlobal, Reflector}; use crate::dom::bindings::root::DomRoot; +#[cfg(feature = "bluetooth")] use crate::dom::bluetooth::Bluetooth; +#[cfg(feature = "bluetooth")] use crate::dom::bluetoothpermissionresult::BluetoothPermissionResult; use crate::dom::globalscope::GlobalScope; use crate::dom::permissionstatus::PermissionStatus; @@ -116,6 +118,7 @@ impl Permissions { // (Query, Request, Revoke) Step 2. match root_desc.name { + #[cfg(feature = "bluetooth")] PermissionName::Bluetooth => { let bluetooth_desc = match Bluetooth::create_descriptor(cx, permissionDesc) { Ok(descriptor) => descriptor, diff --git a/components/script/dom/window.rs b/components/script/dom/window.rs index 0e3bf71d269..375e6621992 100644 --- a/components/script/dom/window.rs +++ b/components/script/dom/window.rs @@ -18,6 +18,7 @@ use backtrace::Backtrace; use base::cross_process_instant::CrossProcessInstant; use base::id::{BrowsingContextId, PipelineId, WebViewId}; use base64::Engine; +#[cfg(feature = "bluetooth")] use bluetooth_traits::BluetoothRequest; use canvas_traits::webgl::WebGLChan; use crossbeam_channel::{unbounded, Sender}; @@ -113,6 +114,7 @@ use crate::dom::bindings::structuredclone; use crate::dom::bindings::trace::{CustomTraceable, JSTraceable, RootedTraceableBox}; use crate::dom::bindings::utils::GlobalStaticData; use crate::dom::bindings::weakref::DOMTracker; +#[cfg(feature = "bluetooth")] use crate::dom::bluetooth::BluetoothExtraPermissionData; use crate::dom::crypto::Crypto; use crate::dom::cssstyledeclaration::{CSSModificationAccess, CSSStyleDeclaration, CSSStyleOwner}; @@ -137,6 +139,7 @@ use crate::dom::promise::Promise; use crate::dom::screen::Screen; use crate::dom::selection::Selection; use crate::dom::storage::Storage; +#[cfg(feature = "bluetooth")] use crate::dom::testrunner::TestRunner; use crate::dom::types::UIEvent; use crate::dom::webglrenderingcontext::WebGLCommandSender; @@ -273,8 +276,10 @@ pub(crate) struct Window { /// A handle for communicating messages to the bluetooth thread. #[no_trace] + #[cfg(feature = "bluetooth")] bluetooth_thread: IpcSender<BluetoothRequest>, + #[cfg(feature = "bluetooth")] bluetooth_extra_permission_data: BluetoothExtraPermissionData, /// An enlarged rectangle around the page contents visible in the viewport, used @@ -307,6 +312,7 @@ pub(crate) struct Window { /// All the MediaQueryLists we need to update media_query_lists: DOMTracker<MediaQueryList>, + #[cfg(feature = "bluetooth")] test_runner: MutNullableDom<TestRunner>, /// A handle for communicating messages to the WebGL thread, if available. @@ -504,10 +510,12 @@ impl Window { }) } + #[cfg(feature = "bluetooth")] pub(crate) fn bluetooth_thread(&self) -> IpcSender<BluetoothRequest> { self.bluetooth_thread.clone() } + #[cfg(feature = "bluetooth")] pub(crate) fn bluetooth_extra_permission_data(&self) -> &BluetoothExtraPermissionData { &self.bluetooth_extra_permission_data } @@ -1425,6 +1433,7 @@ impl WindowMethods<crate::DomTypeHolder> for Window { fetch::Fetch(self.upcast(), input, init, comp, can_gc) } + #[cfg(feature = "bluetooth")] fn TestRunner(&self) -> DomRoot<TestRunner> { self.test_runner.or_init(|| TestRunner::new(self.upcast())) } @@ -2733,7 +2742,7 @@ impl Window { image_cache_sender: IpcSender<PendingImageResponse>, image_cache: Arc<dyn ImageCache>, resource_threads: ResourceThreads, - bluetooth_thread: IpcSender<BluetoothRequest>, + #[cfg(feature = "bluetooth")] bluetooth_thread: IpcSender<BluetoothRequest>, mem_profiler_chan: MemProfilerChan, time_profiler_chan: TimeProfilerChan, devtools_chan: Option<IpcSender<ScriptToDevtoolsControlMsg>>, @@ -2809,7 +2818,9 @@ impl Window { parent_info, dom_static: GlobalStaticData::new(), js_runtime: DomRefCell::new(Some(runtime.clone())), + #[cfg(feature = "bluetooth")] bluetooth_thread, + #[cfg(feature = "bluetooth")] bluetooth_extra_permission_data: BluetoothExtraPermissionData::new(), page_clip_rect: Cell::new(MaxRect::max_rect()), unhandled_resize_event: Default::default(), @@ -2823,6 +2834,7 @@ impl Window { error_reporter, scroll_offsets: Default::default(), media_query_lists: DOMTracker::new(), + #[cfg(feature = "bluetooth")] test_runner: Default::default(), webgl_chan, #[cfg(feature = "webxr")] diff --git a/components/script/messaging.rs b/components/script/messaging.rs index 41dd113c732..1aeaeb8456f 100644 --- a/components/script/messaging.rs +++ b/components/script/messaging.rs @@ -9,6 +9,7 @@ use std::option::Option; use std::result::Result; use base::id::PipelineId; +#[cfg(feature = "bluetooth")] use bluetooth_traits::BluetoothRequest; use crossbeam_channel::{select, Receiver, SendError, Sender}; use devtools_traits::{DevtoolScriptControlMsg, ScriptToDevtoolsControlMsg}; @@ -305,6 +306,7 @@ pub(crate) struct ScriptThreadSenders { /// A handle to the bluetooth thread. #[no_trace] + #[cfg(feature = "bluetooth")] pub(crate) bluetooth_sender: IpcSender<BluetoothRequest>, /// A [`Sender`] that sends messages to the `Constellation`. diff --git a/components/script/script_thread.rs b/components/script/script_thread.rs index 8992b457f0f..b0066c88768 100644 --- a/components/script/script_thread.rs +++ b/components/script/script_thread.rs @@ -900,6 +900,7 @@ impl ScriptThread { let senders = ScriptThreadSenders { self_sender, + #[cfg(feature = "bluetooth")] bluetooth_sender: state.bluetooth_sender, constellation_sender: state.constellation_sender, pipeline_to_constellation_sender: state.pipeline_to_constellation_sender.sender.clone(), @@ -3075,6 +3076,7 @@ impl ScriptThread { self.senders.image_cache_sender.clone(), self.image_cache.clone(), self.resource_threads.clone(), + #[cfg(feature = "bluetooth")] self.senders.bluetooth_sender.clone(), self.senders.memory_profiler_sender.clone(), self.senders.time_profiler_sender.clone(), diff --git a/components/script_bindings/Cargo.toml b/components/script_bindings/Cargo.toml index 4da26f81160..95da7193edc 100644 --- a/components/script_bindings/Cargo.toml +++ b/components/script_bindings/Cargo.toml @@ -37,6 +37,7 @@ servo_config = { path = "../config" } style = { workspace = true } [features] +bluetooth = [] webgpu = [] webxr = [] diff --git a/components/script_bindings/webidls/Bluetooth.webidl b/components/script_bindings/webidls/Bluetooth.webidl index 65ce8ea79b3..890d94b69c4 100644 --- a/components/script_bindings/webidls/Bluetooth.webidl +++ b/components/script_bindings/webidls/Bluetooth.webidl @@ -2,6 +2,8 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ +// skip-unless CARGO_FEATURE_BLUETOOTH + // https://webbluetoothcg.github.io/web-bluetooth/#bluetooth dictionary BluetoothDataFilterInit { @@ -40,3 +42,15 @@ interface Bluetooth : EventTarget { // Bluetooth includes BluetoothDeviceEventHandlers; // Bluetooth includes CharacteristicEventHandlers; // Bluetooth includes ServiceEventHandlers; + +// https://webbluetoothcg.github.io/web-bluetooth/#navigator-extensions +partial interface Navigator { + [SameObject, Pref="dom_bluetooth_enabled"] readonly attribute Bluetooth bluetooth; +}; + +// https://webbluetoothcg.github.io/web-bluetooth/tests#test-interfaces +partial interface Window { + [Pref="dom_bluetooth_testing_enabled", Exposed=Window] + readonly attribute TestRunner testRunner; + //readonly attribute EventSender eventSender; +}; diff --git a/components/script_bindings/webidls/BluetoothAdvertisingEvent.webidl b/components/script_bindings/webidls/BluetoothAdvertisingEvent.webidl index c6f3c6a8480..c205aa935cb 100644 --- a/components/script_bindings/webidls/BluetoothAdvertisingEvent.webidl +++ b/components/script_bindings/webidls/BluetoothAdvertisingEvent.webidl @@ -2,6 +2,8 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ +// skip-unless CARGO_FEATURE_BLUETOOTH + // https://webbluetoothcg.github.io/web-bluetooth/#advertising-events /*interface BluetoothManufacturerDataMap { diff --git a/components/script_bindings/webidls/BluetoothCharacteristicProperties.webidl b/components/script_bindings/webidls/BluetoothCharacteristicProperties.webidl index fb812ff7c46..db33bf2499b 100644 --- a/components/script_bindings/webidls/BluetoothCharacteristicProperties.webidl +++ b/components/script_bindings/webidls/BluetoothCharacteristicProperties.webidl @@ -2,6 +2,8 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ +// skip-unless CARGO_FEATURE_BLUETOOTH + // https://webbluetoothcg.github.io/web-bluetooth/#characteristicproperties [Exposed=Window, Pref="dom_bluetooth_enabled"] diff --git a/components/script_bindings/webidls/BluetoothDevice.webidl b/components/script_bindings/webidls/BluetoothDevice.webidl index f9cb44dda5a..afd34fcc80a 100644 --- a/components/script_bindings/webidls/BluetoothDevice.webidl +++ b/components/script_bindings/webidls/BluetoothDevice.webidl @@ -2,6 +2,8 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ +// skip-unless CARGO_FEATURE_BLUETOOTH + // https://webbluetoothcg.github.io/web-bluetooth/#bluetoothdevice [Exposed=Window, Pref="dom_bluetooth_enabled"] diff --git a/components/script_bindings/webidls/BluetoothPermissionResult.webidl b/components/script_bindings/webidls/BluetoothPermissionResult.webidl index 67822fc55cf..42ebb0dc19f 100644 --- a/components/script_bindings/webidls/BluetoothPermissionResult.webidl +++ b/components/script_bindings/webidls/BluetoothPermissionResult.webidl @@ -2,6 +2,8 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ +// skip-unless CARGO_FEATURE_BLUETOOTH + // https://webbluetoothcg.github.io/web-bluetooth/#bluetoothpermissionresult dictionary BluetoothPermissionDescriptor : PermissionDescriptor { diff --git a/components/script_bindings/webidls/BluetoothRemoteGATTCharacteristic.webidl b/components/script_bindings/webidls/BluetoothRemoteGATTCharacteristic.webidl index 9e0140d8129..e907d3e83b1 100644 --- a/components/script_bindings/webidls/BluetoothRemoteGATTCharacteristic.webidl +++ b/components/script_bindings/webidls/BluetoothRemoteGATTCharacteristic.webidl @@ -2,6 +2,8 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ +// skip-unless CARGO_FEATURE_BLUETOOTH + // https://webbluetoothcg.github.io/web-bluetooth/#bluetoothremotegattcharacteristic [Exposed=Window, Pref="dom_bluetooth_enabled"] diff --git a/components/script_bindings/webidls/BluetoothRemoteGATTDescriptor.webidl b/components/script_bindings/webidls/BluetoothRemoteGATTDescriptor.webidl index 31e19a850fc..c93429fd849 100644 --- a/components/script_bindings/webidls/BluetoothRemoteGATTDescriptor.webidl +++ b/components/script_bindings/webidls/BluetoothRemoteGATTDescriptor.webidl @@ -2,6 +2,8 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ +// skip-unless CARGO_FEATURE_BLUETOOTH + // http://webbluetoothcg.github.io/web-bluetooth/#bluetoothremotegattdescriptor [Exposed=Window, Pref="dom_bluetooth_enabled"] diff --git a/components/script_bindings/webidls/BluetoothRemoteGATTServer.webidl b/components/script_bindings/webidls/BluetoothRemoteGATTServer.webidl index 3d60ace070f..c1dbdf41678 100644 --- a/components/script_bindings/webidls/BluetoothRemoteGATTServer.webidl +++ b/components/script_bindings/webidls/BluetoothRemoteGATTServer.webidl @@ -2,6 +2,8 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ +// skip-unless CARGO_FEATURE_BLUETOOTH + //https://webbluetoothcg.github.io/web-bluetooth/#bluetoothremotegattserver [Exposed=Window, Pref="dom_bluetooth_enabled"] diff --git a/components/script_bindings/webidls/BluetoothRemoteGATTService.webidl b/components/script_bindings/webidls/BluetoothRemoteGATTService.webidl index e505ae3aabe..986d029b963 100644 --- a/components/script_bindings/webidls/BluetoothRemoteGATTService.webidl +++ b/components/script_bindings/webidls/BluetoothRemoteGATTService.webidl @@ -2,6 +2,8 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ +// skip-unless CARGO_FEATURE_BLUETOOTH + // https://webbluetoothcg.github.io/web-bluetooth/#bluetoothremotegattservice [Exposed=Window, Pref="dom_bluetooth_enabled"] diff --git a/components/script_bindings/webidls/BluetoothUUID.webidl b/components/script_bindings/webidls/BluetoothUUID.webidl index 5ee501bf6e6..86df76209fe 100644 --- a/components/script_bindings/webidls/BluetoothUUID.webidl +++ b/components/script_bindings/webidls/BluetoothUUID.webidl @@ -2,6 +2,8 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ +// skip-unless CARGO_FEATURE_BLUETOOTH + // https://webbluetoothcg.github.io/web-bluetooth/#bluetoothuuid [Exposed=Window, Pref="dom_bluetooth_enabled"] diff --git a/components/script_bindings/webidls/Navigator.webidl b/components/script_bindings/webidls/Navigator.webidl index 05fbdf62024..a612d42ae99 100644 --- a/components/script_bindings/webidls/Navigator.webidl +++ b/components/script_bindings/webidls/Navigator.webidl @@ -31,11 +31,6 @@ interface mixin NavigatorID { [Exposed=Window] readonly attribute DOMString vendorSub; // constant "" }; -// https://webbluetoothcg.github.io/web-bluetooth/#navigator-extensions -partial interface Navigator { - [SameObject, Pref="dom_bluetooth_enabled"] readonly attribute Bluetooth bluetooth; -}; - // https://w3c.github.io/ServiceWorker/#navigator-service-worker partial interface Navigator { [SameObject, Pref="dom_serviceworker_enabled"] readonly attribute ServiceWorkerContainer serviceWorker; diff --git a/components/script_bindings/webidls/TestRunner.webidl b/components/script_bindings/webidls/TestRunner.webidl index 4be17153247..2b847bd11bf 100644 --- a/components/script_bindings/webidls/TestRunner.webidl +++ b/components/script_bindings/webidls/TestRunner.webidl @@ -2,6 +2,8 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ +// skip-unless CARGO_FEATURE_BLUETOOTH + // https://webbluetoothcg.github.io/web-bluetooth/tests#test-runner // callback BluetoothManualChooserEventsCallback = void(sequence<DOMString> events); diff --git a/components/script_bindings/webidls/Window.webidl b/components/script_bindings/webidls/Window.webidl index 222fb592ba0..c7b6dde617d 100644 --- a/components/script_bindings/webidls/Window.webidl +++ b/components/script_bindings/webidls/Window.webidl @@ -166,13 +166,6 @@ Window includes WindowLocalStorage; // http://w3c.github.io/animation-timing/#framerequestcallback callback FrameRequestCallback = undefined (DOMHighResTimeStamp time); -// https://webbluetoothcg.github.io/web-bluetooth/tests#test-interfaces -partial interface Window { - [Pref="dom_bluetooth_testing_enabled", Exposed=Window] - readonly attribute TestRunner testRunner; - //readonly attribute EventSender eventSender; -}; - partial interface Window { [Pref="css_animations_testing_enabled"] readonly attribute unsigned long runningAnimationCount; diff --git a/components/servo/Cargo.toml b/components/servo/Cargo.toml index 3bce5b97934..f2b9b802307 100644 --- a/components/servo/Cargo.toml +++ b/components/servo/Cargo.toml @@ -13,6 +13,13 @@ path = "lib.rs" crate-type = ["rlib"] [features] +bluetooth = [ + "bluetooth_traits", + "dep:bluetooth", + "constellation/bluetooth", + "script/bluetooth", + "script_traits/bluetooth", +] default = ["clipboard"] clipboard = ["dep:arboard"] crown = ["script/crown"] @@ -51,8 +58,8 @@ webgpu = [ [dependencies] background_hang_monitor = { path = "../background_hang_monitor" } base = { workspace = true } -bluetooth = { path = "../bluetooth" } -bluetooth_traits = { workspace = true } +bluetooth = { path = "../bluetooth", optional = true } +bluetooth_traits = { workspace = true, optional = true } canvas = { path = "../canvas", default-features = false } canvas_traits = { workspace = true } cfg-if = { workspace = true } diff --git a/components/servo/lib.rs b/components/servo/lib.rs index b90ceb3a3d8..b2e5028c52e 100644 --- a/components/servo/lib.rs +++ b/components/servo/lib.rs @@ -34,7 +34,9 @@ use std::thread; pub use base::id::TopLevelBrowsingContextId; use base::id::{PipelineId, PipelineNamespace, PipelineNamespaceId, WebViewId}; +#[cfg(feature = "bluetooth")] use bluetooth::BluetoothThreadFactory; +#[cfg(feature = "bluetooth")] use bluetooth_traits::BluetoothRequest; use canvas::canvas_paint_thread::CanvasPaintThread; use canvas::WebGLComm; @@ -108,12 +110,13 @@ use webview::WebViewInner; #[cfg(feature = "webxr")] pub use webxr; pub use { - background_hang_monitor, base, bluetooth, bluetooth_traits, canvas, canvas_traits, compositing, - devtools, devtools_traits, euclid, fonts, ipc_channel, layout_thread_2020, media, net, - net_traits, profile, profile_traits, script, script_layout_interface, script_traits, - servo_config as config, servo_config, servo_geometry, servo_url, style, style_traits, - webrender_api, webrender_traits, + background_hang_monitor, base, canvas, canvas_traits, compositing, devtools, devtools_traits, + euclid, fonts, ipc_channel, layout_thread_2020, media, net, net_traits, profile, + profile_traits, script, script_layout_interface, script_traits, servo_config as config, + servo_config, servo_geometry, servo_url, style, style_traits, webrender_api, webrender_traits, }; +#[cfg(feature = "bluetooth")] +pub use {bluetooth, bluetooth_traits}; use crate::proxies::ConstellationProxy; pub use crate::servo_delegate::{ServoDelegate, ServoError}; @@ -1099,6 +1102,7 @@ fn create_constellation( // Global configuration options, parsed from the command line. let opts = opts::get(); + #[cfg(feature = "bluetooth")] let bluetooth_thread: IpcSender<BluetoothRequest> = BluetoothThreadFactory::new(embedder_proxy.clone()); @@ -1128,6 +1132,7 @@ fn create_constellation( compositor_proxy, embedder_proxy, devtools_sender, + #[cfg(feature = "bluetooth")] bluetooth_thread, system_font_service, public_resource_threads, diff --git a/components/shared/script/Cargo.toml b/components/shared/script/Cargo.toml index 9e11eb10e62..a1e71af824d 100644 --- a/components/shared/script/Cargo.toml +++ b/components/shared/script/Cargo.toml @@ -12,13 +12,14 @@ name = "script_traits" path = "lib.rs" [features] +bluetooth = ["bluetooth_traits"] webgpu = [] [dependencies] background_hang_monitor_api = { workspace = true } base = { workspace = true } bitflags = { workspace = true } -bluetooth_traits = { workspace = true } +bluetooth_traits = { workspace = true, optional = true } canvas_traits = { workspace = true } cookie = { workspace = true } crossbeam-channel = { workspace = true } diff --git a/components/shared/script/lib.rs b/components/shared/script/lib.rs index f76faaef79a..5c46dc01bef 100644 --- a/components/shared/script/lib.rs +++ b/components/shared/script/lib.rs @@ -27,6 +27,7 @@ use base::id::{ }; use base::Epoch; use bitflags::bitflags; +#[cfg(feature = "bluetooth")] use bluetooth_traits::BluetoothRequest; use canvas_traits::webgl::WebGLPipeline; use crossbeam_channel::{RecvTimeoutError, Sender}; @@ -517,6 +518,7 @@ pub struct InitialScriptState { /// A channel to the resource manager thread. pub resource_threads: ResourceThreads, /// A channel to the bluetooth thread. + #[cfg(feature = "bluetooth")] pub bluetooth_sender: IpcSender<BluetoothRequest>, /// The image cache for this script thread. pub image_cache: Arc<dyn ImageCache>, diff --git a/ports/servoshell/Cargo.toml b/ports/servoshell/Cargo.toml index dfc58f538bc..7a8061f9851 100644 --- a/ports/servoshell/Cargo.toml +++ b/ports/servoshell/Cargo.toml @@ -59,7 +59,7 @@ webgpu = ["libservo/webgpu"] [dependencies] euclid = { workspace = true } libc = { workspace = true } -libservo = { path = "../../components/servo", features = ["background_hang_monitor"] } +libservo = { path = "../../components/servo", features = ["background_hang_monitor", "bluetooth"] } cfg-if = { workspace = true } keyboard-types = { workspace = true } log = { workspace = true } |