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

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