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" path = "lib.rs"
[features] [features]
bluetooth = ["bluetooth_traits"]
default = [] default = []
multiview = [] multiview = []
tracing = ["dep:tracing"] tracing = ["dep:tracing"]
@ -22,7 +23,7 @@ background_hang_monitor_api = { workspace = true }
background_hang_monitor = { path = "../background_hang_monitor" } background_hang_monitor = { path = "../background_hang_monitor" }
backtrace = { workspace = true } backtrace = { workspace = true }
base = { workspace = true } base = { workspace = true }
bluetooth_traits = { workspace = true } bluetooth_traits = { workspace = true, optional = true }
canvas_traits = { workspace = true } canvas_traits = { workspace = true }
compositing_traits = { workspace = true } compositing_traits = { workspace = true }
crossbeam-channel = { workspace = true } crossbeam-channel = { workspace = true }

View file

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

View file

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

View file

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

View file

@ -13,6 +13,7 @@ name = "script"
path = "lib.rs" path = "lib.rs"
[features] [features]
bluetooth = ['bluetooth_traits', 'script_bindings/bluetooth']
crown = ['js/crown'] crown = ['js/crown']
debugmozjs = ['js/debugmozjs'] debugmozjs = ['js/debugmozjs']
jitspew = ['js/jitspew'] jitspew = ['js/jitspew']
@ -41,7 +42,7 @@ base = { workspace = true }
base64 = { workspace = true } base64 = { workspace = true }
bincode = { workspace = true } bincode = { workspace = true }
bitflags = { workspace = true } bitflags = { workspace = true }
bluetooth_traits = { workspace = true } bluetooth_traits = { workspace = true, optional = true }
canvas_traits = { workspace = true } canvas_traits = { workspace = true }
cbc = { workspace = true } cbc = { workspace = true }
cipher = { workspace = true } cipher = { workspace = true }

View file

@ -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;

View file

@ -233,16 +233,11 @@ pub(crate) mod beforeunloadevent;
pub(crate) mod bindings; pub(crate) mod bindings;
pub(crate) mod biquadfilternode; pub(crate) mod biquadfilternode;
pub(crate) mod blob; pub(crate) mod blob;
#[cfg(feature = "bluetooth")]
#[allow(clippy::module_inception)]
pub(crate) mod bluetooth; pub(crate) mod bluetooth;
pub(crate) mod bluetoothadvertisingevent; #[cfg(feature = "bluetooth")]
pub(crate) mod bluetoothcharacteristicproperties; pub(crate) use self::bluetooth::*;
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 broadcastchannel; pub(crate) mod broadcastchannel;
pub(crate) mod bytelengthqueuingstrategy; pub(crate) mod bytelengthqueuingstrategy;
pub(crate) mod canvasgradient; pub(crate) mod canvasgradient;
@ -552,7 +547,6 @@ pub(crate) mod testbindingpairiterable;
pub(crate) mod testbindingproxy; pub(crate) mod testbindingproxy;
pub(crate) mod testbindingsetlike; pub(crate) mod testbindingsetlike;
pub(crate) mod testns; pub(crate) mod testns;
pub(crate) mod testrunner;
pub(crate) mod testworklet; pub(crate) mod testworklet;
pub(crate) mod testworkletglobalscope; pub(crate) mod testworkletglobalscope;
pub(crate) mod text; pub(crate) mod text;

View file

@ -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::root::{DomRoot, MutNullableDom};
use crate::dom::bindings::str::DOMString; use crate::dom::bindings::str::DOMString;
use crate::dom::bindings::utils::to_frozen_array; use crate::dom::bindings::utils::to_frozen_array;
#[cfg(feature = "bluetooth")]
use crate::dom::bluetooth::Bluetooth; use crate::dom::bluetooth::Bluetooth;
use crate::dom::gamepad::Gamepad; use crate::dom::gamepad::Gamepad;
use crate::dom::gamepadevent::GamepadEventType; use crate::dom::gamepadevent::GamepadEventType;
@ -42,6 +43,7 @@ pub(super) fn hardware_concurrency() -> u64 {
#[dom_struct] #[dom_struct]
pub(crate) struct Navigator { pub(crate) struct Navigator {
reflector_: Reflector, reflector_: Reflector,
#[cfg(feature = "bluetooth")]
bluetooth: MutNullableDom<Bluetooth>, bluetooth: MutNullableDom<Bluetooth>,
plugins: MutNullableDom<PluginArray>, plugins: MutNullableDom<PluginArray>,
mime_types: MutNullableDom<MimeTypeArray>, mime_types: MutNullableDom<MimeTypeArray>,
@ -63,6 +65,7 @@ impl Navigator {
fn new_inherited() -> Navigator { fn new_inherited() -> Navigator {
Navigator { Navigator {
reflector_: Reflector::new(), reflector_: Reflector::new(),
#[cfg(feature = "bluetooth")]
bluetooth: Default::default(), bluetooth: Default::default(),
plugins: Default::default(), plugins: Default::default(),
mime_types: 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 // https://webbluetoothcg.github.io/web-bluetooth/#dom-navigator-bluetooth
#[cfg(feature = "bluetooth")]
fn Bluetooth(&self) -> DomRoot<Bluetooth> { fn Bluetooth(&self) -> DomRoot<Bluetooth> {
self.bluetooth.or_init(|| Bluetooth::new(&self.global())) self.bluetooth.or_init(|| Bluetooth::new(&self.global()))
} }

View file

@ -23,7 +23,9 @@ use crate::dom::bindings::codegen::Bindings::WindowBinding::Window_Binding::Wind
use crate::dom::bindings::error::Error; use crate::dom::bindings::error::Error;
use crate::dom::bindings::reflector::{reflect_dom_object, DomGlobal, Reflector}; use crate::dom::bindings::reflector::{reflect_dom_object, DomGlobal, Reflector};
use crate::dom::bindings::root::DomRoot; use crate::dom::bindings::root::DomRoot;
#[cfg(feature = "bluetooth")]
use crate::dom::bluetooth::Bluetooth; use crate::dom::bluetooth::Bluetooth;
#[cfg(feature = "bluetooth")]
use crate::dom::bluetoothpermissionresult::BluetoothPermissionResult; use crate::dom::bluetoothpermissionresult::BluetoothPermissionResult;
use crate::dom::globalscope::GlobalScope; use crate::dom::globalscope::GlobalScope;
use crate::dom::permissionstatus::PermissionStatus; use crate::dom::permissionstatus::PermissionStatus;
@ -116,6 +118,7 @@ impl Permissions {
// (Query, Request, Revoke) Step 2. // (Query, Request, Revoke) Step 2.
match root_desc.name { match root_desc.name {
#[cfg(feature = "bluetooth")]
PermissionName::Bluetooth => { PermissionName::Bluetooth => {
let bluetooth_desc = match Bluetooth::create_descriptor(cx, permissionDesc) { let bluetooth_desc = match Bluetooth::create_descriptor(cx, permissionDesc) {
Ok(descriptor) => descriptor, Ok(descriptor) => descriptor,

View file

@ -18,6 +18,7 @@ use backtrace::Backtrace;
use base::cross_process_instant::CrossProcessInstant; use base::cross_process_instant::CrossProcessInstant;
use base::id::{BrowsingContextId, PipelineId, WebViewId}; use base::id::{BrowsingContextId, PipelineId, WebViewId};
use base64::Engine; use base64::Engine;
#[cfg(feature = "bluetooth")]
use bluetooth_traits::BluetoothRequest; use bluetooth_traits::BluetoothRequest;
use canvas_traits::webgl::WebGLChan; use canvas_traits::webgl::WebGLChan;
use crossbeam_channel::{unbounded, Sender}; 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::trace::{CustomTraceable, JSTraceable, RootedTraceableBox};
use crate::dom::bindings::utils::GlobalStaticData; use crate::dom::bindings::utils::GlobalStaticData;
use crate::dom::bindings::weakref::DOMTracker; use crate::dom::bindings::weakref::DOMTracker;
#[cfg(feature = "bluetooth")]
use crate::dom::bluetooth::BluetoothExtraPermissionData; use crate::dom::bluetooth::BluetoothExtraPermissionData;
use crate::dom::crypto::Crypto; use crate::dom::crypto::Crypto;
use crate::dom::cssstyledeclaration::{CSSModificationAccess, CSSStyleDeclaration, CSSStyleOwner}; use crate::dom::cssstyledeclaration::{CSSModificationAccess, CSSStyleDeclaration, CSSStyleOwner};
@ -137,6 +139,7 @@ use crate::dom::promise::Promise;
use crate::dom::screen::Screen; use crate::dom::screen::Screen;
use crate::dom::selection::Selection; use crate::dom::selection::Selection;
use crate::dom::storage::Storage; use crate::dom::storage::Storage;
#[cfg(feature = "bluetooth")]
use crate::dom::testrunner::TestRunner; use crate::dom::testrunner::TestRunner;
use crate::dom::types::UIEvent; use crate::dom::types::UIEvent;
use crate::dom::webglrenderingcontext::WebGLCommandSender; use crate::dom::webglrenderingcontext::WebGLCommandSender;
@ -273,8 +276,10 @@ pub(crate) struct Window {
/// A handle for communicating messages to the bluetooth thread. /// A handle for communicating messages to the bluetooth thread.
#[no_trace] #[no_trace]
#[cfg(feature = "bluetooth")]
bluetooth_thread: IpcSender<BluetoothRequest>, bluetooth_thread: IpcSender<BluetoothRequest>,
#[cfg(feature = "bluetooth")]
bluetooth_extra_permission_data: BluetoothExtraPermissionData, bluetooth_extra_permission_data: BluetoothExtraPermissionData,
/// An enlarged rectangle around the page contents visible in the viewport, used /// 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 /// All the MediaQueryLists we need to update
media_query_lists: DOMTracker<MediaQueryList>, media_query_lists: DOMTracker<MediaQueryList>,
#[cfg(feature = "bluetooth")]
test_runner: MutNullableDom<TestRunner>, test_runner: MutNullableDom<TestRunner>,
/// A handle for communicating messages to the WebGL thread, if available. /// 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> { pub(crate) fn bluetooth_thread(&self) -> IpcSender<BluetoothRequest> {
self.bluetooth_thread.clone() self.bluetooth_thread.clone()
} }
#[cfg(feature = "bluetooth")]
pub(crate) fn bluetooth_extra_permission_data(&self) -> &BluetoothExtraPermissionData { pub(crate) fn bluetooth_extra_permission_data(&self) -> &BluetoothExtraPermissionData {
&self.bluetooth_extra_permission_data &self.bluetooth_extra_permission_data
} }
@ -1425,6 +1433,7 @@ impl WindowMethods<crate::DomTypeHolder> for Window {
fetch::Fetch(self.upcast(), input, init, comp, can_gc) fetch::Fetch(self.upcast(), input, init, comp, can_gc)
} }
#[cfg(feature = "bluetooth")]
fn TestRunner(&self) -> DomRoot<TestRunner> { fn TestRunner(&self) -> DomRoot<TestRunner> {
self.test_runner.or_init(|| TestRunner::new(self.upcast())) self.test_runner.or_init(|| TestRunner::new(self.upcast()))
} }
@ -2733,7 +2742,7 @@ impl Window {
image_cache_sender: IpcSender<PendingImageResponse>, image_cache_sender: IpcSender<PendingImageResponse>,
image_cache: Arc<dyn ImageCache>, image_cache: Arc<dyn ImageCache>,
resource_threads: ResourceThreads, resource_threads: ResourceThreads,
bluetooth_thread: IpcSender<BluetoothRequest>, #[cfg(feature = "bluetooth")] bluetooth_thread: IpcSender<BluetoothRequest>,
mem_profiler_chan: MemProfilerChan, mem_profiler_chan: MemProfilerChan,
time_profiler_chan: TimeProfilerChan, time_profiler_chan: TimeProfilerChan,
devtools_chan: Option<IpcSender<ScriptToDevtoolsControlMsg>>, devtools_chan: Option<IpcSender<ScriptToDevtoolsControlMsg>>,
@ -2809,7 +2818,9 @@ impl Window {
parent_info, parent_info,
dom_static: GlobalStaticData::new(), dom_static: GlobalStaticData::new(),
js_runtime: DomRefCell::new(Some(runtime.clone())), js_runtime: DomRefCell::new(Some(runtime.clone())),
#[cfg(feature = "bluetooth")]
bluetooth_thread, bluetooth_thread,
#[cfg(feature = "bluetooth")]
bluetooth_extra_permission_data: BluetoothExtraPermissionData::new(), bluetooth_extra_permission_data: BluetoothExtraPermissionData::new(),
page_clip_rect: Cell::new(MaxRect::max_rect()), page_clip_rect: Cell::new(MaxRect::max_rect()),
unhandled_resize_event: Default::default(), unhandled_resize_event: Default::default(),
@ -2823,6 +2834,7 @@ impl Window {
error_reporter, error_reporter,
scroll_offsets: Default::default(), scroll_offsets: Default::default(),
media_query_lists: DOMTracker::new(), media_query_lists: DOMTracker::new(),
#[cfg(feature = "bluetooth")]
test_runner: Default::default(), test_runner: Default::default(),
webgl_chan, webgl_chan,
#[cfg(feature = "webxr")] #[cfg(feature = "webxr")]

View file

@ -9,6 +9,7 @@ use std::option::Option;
use std::result::Result; use std::result::Result;
use base::id::PipelineId; use base::id::PipelineId;
#[cfg(feature = "bluetooth")]
use bluetooth_traits::BluetoothRequest; use bluetooth_traits::BluetoothRequest;
use crossbeam_channel::{select, Receiver, SendError, Sender}; use crossbeam_channel::{select, Receiver, SendError, Sender};
use devtools_traits::{DevtoolScriptControlMsg, ScriptToDevtoolsControlMsg}; use devtools_traits::{DevtoolScriptControlMsg, ScriptToDevtoolsControlMsg};
@ -305,6 +306,7 @@ pub(crate) struct ScriptThreadSenders {
/// A handle to the bluetooth thread. /// A handle to the bluetooth thread.
#[no_trace] #[no_trace]
#[cfg(feature = "bluetooth")]
pub(crate) bluetooth_sender: IpcSender<BluetoothRequest>, pub(crate) bluetooth_sender: IpcSender<BluetoothRequest>,
/// A [`Sender`] that sends messages to the `Constellation`. /// A [`Sender`] that sends messages to the `Constellation`.

View file

@ -900,6 +900,7 @@ impl ScriptThread {
let senders = ScriptThreadSenders { let senders = ScriptThreadSenders {
self_sender, self_sender,
#[cfg(feature = "bluetooth")]
bluetooth_sender: state.bluetooth_sender, bluetooth_sender: state.bluetooth_sender,
constellation_sender: state.constellation_sender, constellation_sender: state.constellation_sender,
pipeline_to_constellation_sender: state.pipeline_to_constellation_sender.sender.clone(), pipeline_to_constellation_sender: state.pipeline_to_constellation_sender.sender.clone(),
@ -3075,6 +3076,7 @@ impl ScriptThread {
self.senders.image_cache_sender.clone(), self.senders.image_cache_sender.clone(),
self.image_cache.clone(), self.image_cache.clone(),
self.resource_threads.clone(), self.resource_threads.clone(),
#[cfg(feature = "bluetooth")]
self.senders.bluetooth_sender.clone(), self.senders.bluetooth_sender.clone(),
self.senders.memory_profiler_sender.clone(), self.senders.memory_profiler_sender.clone(),
self.senders.time_profiler_sender.clone(), self.senders.time_profiler_sender.clone(),

View file

@ -37,6 +37,7 @@ servo_config = { path = "../config" }
style = { workspace = true } style = { workspace = true }
[features] [features]
bluetooth = []
webgpu = [] webgpu = []
webxr = [] webxr = []

View file

@ -2,6 +2,8 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * 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/. */ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
// skip-unless CARGO_FEATURE_BLUETOOTH
// https://webbluetoothcg.github.io/web-bluetooth/#bluetooth // https://webbluetoothcg.github.io/web-bluetooth/#bluetooth
dictionary BluetoothDataFilterInit { dictionary BluetoothDataFilterInit {
@ -40,3 +42,15 @@ interface Bluetooth : EventTarget {
// Bluetooth includes BluetoothDeviceEventHandlers; // Bluetooth includes BluetoothDeviceEventHandlers;
// Bluetooth includes CharacteristicEventHandlers; // Bluetooth includes CharacteristicEventHandlers;
// Bluetooth includes ServiceEventHandlers; // 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;
};

View file

@ -2,6 +2,8 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * 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/. */ * 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 // https://webbluetoothcg.github.io/web-bluetooth/#advertising-events
/*interface BluetoothManufacturerDataMap { /*interface BluetoothManufacturerDataMap {

View file

@ -2,6 +2,8 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * 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/. */ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
// skip-unless CARGO_FEATURE_BLUETOOTH
// https://webbluetoothcg.github.io/web-bluetooth/#characteristicproperties // https://webbluetoothcg.github.io/web-bluetooth/#characteristicproperties
[Exposed=Window, Pref="dom_bluetooth_enabled"] [Exposed=Window, Pref="dom_bluetooth_enabled"]

View file

@ -2,6 +2,8 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * 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/. */ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
// skip-unless CARGO_FEATURE_BLUETOOTH
// https://webbluetoothcg.github.io/web-bluetooth/#bluetoothdevice // https://webbluetoothcg.github.io/web-bluetooth/#bluetoothdevice
[Exposed=Window, Pref="dom_bluetooth_enabled"] [Exposed=Window, Pref="dom_bluetooth_enabled"]

View file

@ -2,6 +2,8 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * 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/. */ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
// skip-unless CARGO_FEATURE_BLUETOOTH
// https://webbluetoothcg.github.io/web-bluetooth/#bluetoothpermissionresult // https://webbluetoothcg.github.io/web-bluetooth/#bluetoothpermissionresult
dictionary BluetoothPermissionDescriptor : PermissionDescriptor { dictionary BluetoothPermissionDescriptor : PermissionDescriptor {

View file

@ -2,6 +2,8 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * 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/. */ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
// skip-unless CARGO_FEATURE_BLUETOOTH
// https://webbluetoothcg.github.io/web-bluetooth/#bluetoothremotegattcharacteristic // https://webbluetoothcg.github.io/web-bluetooth/#bluetoothremotegattcharacteristic
[Exposed=Window, Pref="dom_bluetooth_enabled"] [Exposed=Window, Pref="dom_bluetooth_enabled"]

View file

@ -2,6 +2,8 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * 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/. */ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
// skip-unless CARGO_FEATURE_BLUETOOTH
// http://webbluetoothcg.github.io/web-bluetooth/#bluetoothremotegattdescriptor // http://webbluetoothcg.github.io/web-bluetooth/#bluetoothremotegattdescriptor
[Exposed=Window, Pref="dom_bluetooth_enabled"] [Exposed=Window, Pref="dom_bluetooth_enabled"]

View file

@ -2,6 +2,8 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * 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/. */ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
// skip-unless CARGO_FEATURE_BLUETOOTH
//https://webbluetoothcg.github.io/web-bluetooth/#bluetoothremotegattserver //https://webbluetoothcg.github.io/web-bluetooth/#bluetoothremotegattserver
[Exposed=Window, Pref="dom_bluetooth_enabled"] [Exposed=Window, Pref="dom_bluetooth_enabled"]

View file

@ -2,6 +2,8 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * 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/. */ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
// skip-unless CARGO_FEATURE_BLUETOOTH
// https://webbluetoothcg.github.io/web-bluetooth/#bluetoothremotegattservice // https://webbluetoothcg.github.io/web-bluetooth/#bluetoothremotegattservice
[Exposed=Window, Pref="dom_bluetooth_enabled"] [Exposed=Window, Pref="dom_bluetooth_enabled"]

View file

@ -2,6 +2,8 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * 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/. */ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
// skip-unless CARGO_FEATURE_BLUETOOTH
// https://webbluetoothcg.github.io/web-bluetooth/#bluetoothuuid // https://webbluetoothcg.github.io/web-bluetooth/#bluetoothuuid
[Exposed=Window, Pref="dom_bluetooth_enabled"] [Exposed=Window, Pref="dom_bluetooth_enabled"]

View file

@ -31,11 +31,6 @@ interface mixin NavigatorID {
[Exposed=Window] readonly attribute DOMString vendorSub; // constant "" [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 // https://w3c.github.io/ServiceWorker/#navigator-service-worker
partial interface Navigator { partial interface Navigator {
[SameObject, Pref="dom_serviceworker_enabled"] readonly attribute ServiceWorkerContainer serviceWorker; [SameObject, Pref="dom_serviceworker_enabled"] readonly attribute ServiceWorkerContainer serviceWorker;

View file

@ -2,6 +2,8 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * 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/. */ * 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 // https://webbluetoothcg.github.io/web-bluetooth/tests#test-runner
// callback BluetoothManualChooserEventsCallback = void(sequence<DOMString> events); // callback BluetoothManualChooserEventsCallback = void(sequence<DOMString> events);

View file

@ -166,13 +166,6 @@ Window includes WindowLocalStorage;
// http://w3c.github.io/animation-timing/#framerequestcallback // http://w3c.github.io/animation-timing/#framerequestcallback
callback FrameRequestCallback = undefined (DOMHighResTimeStamp time); 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 { partial interface Window {
[Pref="css_animations_testing_enabled"] [Pref="css_animations_testing_enabled"]
readonly attribute unsigned long runningAnimationCount; readonly attribute unsigned long runningAnimationCount;

View file

@ -13,6 +13,13 @@ path = "lib.rs"
crate-type = ["rlib"] crate-type = ["rlib"]
[features] [features]
bluetooth = [
"bluetooth_traits",
"dep:bluetooth",
"constellation/bluetooth",
"script/bluetooth",
"script_traits/bluetooth",
]
default = ["clipboard"] default = ["clipboard"]
clipboard = ["dep:arboard"] clipboard = ["dep:arboard"]
crown = ["script/crown"] crown = ["script/crown"]
@ -51,8 +58,8 @@ webgpu = [
[dependencies] [dependencies]
background_hang_monitor = { path = "../background_hang_monitor" } background_hang_monitor = { path = "../background_hang_monitor" }
base = { workspace = true } base = { workspace = true }
bluetooth = { path = "../bluetooth" } bluetooth = { path = "../bluetooth", optional = true }
bluetooth_traits = { workspace = true } bluetooth_traits = { workspace = true, optional = true }
canvas = { path = "../canvas", default-features = false } canvas = { path = "../canvas", default-features = false }
canvas_traits = { workspace = true } canvas_traits = { workspace = true }
cfg-if = { workspace = true } cfg-if = { workspace = true }

View file

@ -34,7 +34,9 @@ use std::thread;
pub use base::id::TopLevelBrowsingContextId; pub use base::id::TopLevelBrowsingContextId;
use base::id::{PipelineId, PipelineNamespace, PipelineNamespaceId, WebViewId}; use base::id::{PipelineId, PipelineNamespace, PipelineNamespaceId, WebViewId};
#[cfg(feature = "bluetooth")]
use bluetooth::BluetoothThreadFactory; use bluetooth::BluetoothThreadFactory;
#[cfg(feature = "bluetooth")]
use bluetooth_traits::BluetoothRequest; use bluetooth_traits::BluetoothRequest;
use canvas::canvas_paint_thread::CanvasPaintThread; use canvas::canvas_paint_thread::CanvasPaintThread;
use canvas::WebGLComm; use canvas::WebGLComm;
@ -108,12 +110,13 @@ use webview::WebViewInner;
#[cfg(feature = "webxr")] #[cfg(feature = "webxr")]
pub use webxr; pub use webxr;
pub use { pub use {
background_hang_monitor, base, bluetooth, bluetooth_traits, canvas, canvas_traits, compositing, background_hang_monitor, base, canvas, canvas_traits, compositing, devtools, devtools_traits,
devtools, devtools_traits, euclid, fonts, ipc_channel, layout_thread_2020, media, net, euclid, fonts, ipc_channel, layout_thread_2020, media, net, net_traits, profile,
net_traits, profile, profile_traits, script, script_layout_interface, script_traits, profile_traits, script, script_layout_interface, script_traits, servo_config as config,
servo_config as config, servo_config, servo_geometry, servo_url, style, style_traits, servo_config, servo_geometry, servo_url, style, style_traits, webrender_api, webrender_traits,
webrender_api, webrender_traits,
}; };
#[cfg(feature = "bluetooth")]
pub use {bluetooth, bluetooth_traits};
use crate::proxies::ConstellationProxy; use crate::proxies::ConstellationProxy;
pub use crate::servo_delegate::{ServoDelegate, ServoError}; pub use crate::servo_delegate::{ServoDelegate, ServoError};
@ -1099,6 +1102,7 @@ fn create_constellation(
// Global configuration options, parsed from the command line. // Global configuration options, parsed from the command line.
let opts = opts::get(); let opts = opts::get();
#[cfg(feature = "bluetooth")]
let bluetooth_thread: IpcSender<BluetoothRequest> = let bluetooth_thread: IpcSender<BluetoothRequest> =
BluetoothThreadFactory::new(embedder_proxy.clone()); BluetoothThreadFactory::new(embedder_proxy.clone());
@ -1128,6 +1132,7 @@ fn create_constellation(
compositor_proxy, compositor_proxy,
embedder_proxy, embedder_proxy,
devtools_sender, devtools_sender,
#[cfg(feature = "bluetooth")]
bluetooth_thread, bluetooth_thread,
system_font_service, system_font_service,
public_resource_threads, public_resource_threads,

View file

@ -12,13 +12,14 @@ name = "script_traits"
path = "lib.rs" path = "lib.rs"
[features] [features]
bluetooth = ["bluetooth_traits"]
webgpu = [] webgpu = []
[dependencies] [dependencies]
background_hang_monitor_api = { workspace = true } background_hang_monitor_api = { workspace = true }
base = { workspace = true } base = { workspace = true }
bitflags = { workspace = true } bitflags = { workspace = true }
bluetooth_traits = { workspace = true } bluetooth_traits = { workspace = true, optional = true }
canvas_traits = { workspace = true } canvas_traits = { workspace = true }
cookie = { workspace = true } cookie = { workspace = true }
crossbeam-channel = { workspace = true } crossbeam-channel = { workspace = true }

View file

@ -27,6 +27,7 @@ use base::id::{
}; };
use base::Epoch; use base::Epoch;
use bitflags::bitflags; use bitflags::bitflags;
#[cfg(feature = "bluetooth")]
use bluetooth_traits::BluetoothRequest; use bluetooth_traits::BluetoothRequest;
use canvas_traits::webgl::WebGLPipeline; use canvas_traits::webgl::WebGLPipeline;
use crossbeam_channel::{RecvTimeoutError, Sender}; use crossbeam_channel::{RecvTimeoutError, Sender};
@ -517,6 +518,7 @@ pub struct InitialScriptState {
/// A channel to the resource manager thread. /// A channel to the resource manager thread.
pub resource_threads: ResourceThreads, pub resource_threads: ResourceThreads,
/// A channel to the bluetooth thread. /// A channel to the bluetooth thread.
#[cfg(feature = "bluetooth")]
pub bluetooth_sender: IpcSender<BluetoothRequest>, pub bluetooth_sender: IpcSender<BluetoothRequest>,
/// The image cache for this script thread. /// The image cache for this script thread.
pub image_cache: Arc<dyn ImageCache>, pub image_cache: Arc<dyn ImageCache>,

View file

@ -59,7 +59,7 @@ webgpu = ["libservo/webgpu"]
[dependencies] [dependencies]
euclid = { workspace = true } euclid = { workspace = true }
libc = { 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 } cfg-if = { workspace = true }
keyboard-types = { workspace = true } keyboard-types = { workspace = true }
log = { workspace = true } log = { workspace = true }