use dom_struct::dom_struct;
use js::rust::MutableHandleValue;
use crate::dom::bindings::codegen::Bindings::WorkerNavigatorBinding::WorkerNavigatorMethods;
use crate::dom::bindings::reflector::{reflect_dom_object, DomObject, Reflector};
use crate::dom::bindings::root::{DomRoot, MutNullableDom};
use crate::dom::bindings::str::DOMString;
use crate::dom::bindings::utils::to_frozen_array;
use crate::dom::navigator::hardware_concurrency;
use crate::dom::navigatorinfo;
use crate::dom::permissions::Permissions;
#[cfg(feature = "webgpu")]
use crate::dom::webgpu::gpu::GPU;
use crate::dom::workerglobalscope::WorkerGlobalScope;
use crate::script_runtime::{CanGc, JSContext};
#[dom_struct]
pub struct WorkerNavigator {
reflector_: Reflector,
permissions: MutNullableDom<Permissions>,
#[cfg(feature = "webgpu")]
gpu: MutNullableDom<GPU>,
}
impl WorkerNavigator {
fn new_inherited() -> WorkerNavigator {
WorkerNavigator {
reflector_: Reflector::new(),
permissions: Default::default(),
#[cfg(feature = "webgpu")]
gpu: Default::default(),
}
}
pub fn new(global: &WorkerGlobalScope) -> DomRoot<WorkerNavigator> {
reflect_dom_object(
Box::new(WorkerNavigator::new_inherited()),
global,
CanGc::note(),
)
}
}
impl WorkerNavigatorMethods<crate::DomTypeHolder> for WorkerNavigator {
fn Product(&self) -> DOMString {
navigatorinfo::Product()
}
fn ProductSub(&self) -> DOMString {
navigatorinfo::ProductSub()
}
fn Vendor(&self) -> DOMString {
navigatorinfo::Vendor()
}
fn VendorSub(&self) -> DOMString {
navigatorinfo::VendorSub()
}
fn TaintEnabled(&self) -> bool {
navigatorinfo::TaintEnabled()
}
fn AppName(&self) -> DOMString {
navigatorinfo::AppName()
}
fn AppCodeName(&self) -> DOMString {
navigatorinfo::AppCodeName()
}
fn Platform(&self) -> DOMString {
navigatorinfo::Platform()
}
fn UserAgent(&self) -> DOMString {
navigatorinfo::UserAgent(self.global().get_user_agent())
}
fn AppVersion(&self) -> DOMString {
navigatorinfo::AppVersion()
}
fn Language(&self) -> DOMString {
navigatorinfo::Language()
}
#[allow(unsafe_code)]
fn Languages(&self, cx: JSContext, retval: MutableHandleValue) {
to_frozen_array(&[self.Language()], cx, retval)
}
fn Permissions(&self) -> DomRoot<Permissions> {
self.permissions
.or_init(|| Permissions::new(&self.global()))
}
#[cfg(feature = "webgpu")]
fn Gpu(&self) -> DomRoot<GPU> {
self.gpu.or_init(|| GPU::new(&self.global()))
}
fn HardwareConcurrency(&self) -> u64 {
hardware_concurrency()
}
}