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

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

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::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()))
}

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::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,

View file

@ -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")]