From 65588cd5dfcc1a25dd6e16ca1e5fcb9bea3ef444 Mon Sep 17 00:00:00 2001 From: Ashwin Naren Date: Wed, 1 Oct 2025 21:17:36 -0700 Subject: [PATCH] script: Stubs for geolocation interfaces (#39584) Needed for #39526; stubs out all the necessary interface from https://www.w3.org/TR/geolocation/. Testing: WPT Signed-off-by: Ashwin Naren --- components/config/prefs.rs | 2 + .../script/dom/geolocation/geolocation.rs | 91 +++++++++++++++ .../dom/geolocation/geolocationcoordinates.rs | 105 ++++++++++++++++++ .../dom/geolocation/geolocationposition.rs | 55 +++++++++ .../geolocation/geolocationpositionerror.rs | 51 +++++++++ components/script/dom/geolocation/mod.rs | 10 ++ components/script/dom/mod.rs | 2 + components/script/dom/navigator.rs | 6 + components/script/script_runtime.rs | 3 + components/script/script_thread.rs | 8 ++ components/script/task_manager.rs | 2 + components/script/task_source.rs | 3 + .../webidls/Geolocation.webidl | 47 ++++++++ .../webidls/GeolocationCoordinates.webidl | 20 ++++ .../webidls/GeolocationPosition.webidl | 15 +++ .../webidls/GeolocationPositionError.webidl | 18 +++ .../shared/background_hang_monitor/lib.rs | 1 + components/shared/profile/time.rs | 12 +- python/tidy/tidy.py | 1 + tests/wpt/include.ini | 2 + tests/wpt/meta/geolocation/__dir__.ini | 3 + ...etCurrentPosition_TypeError.https.html.ini | 6 + .../idlharness.https.window.js.ini | 6 + .../non-secure-contexts.http.html.ini | 13 +++ .../geolocation/permission.https.html.ini | 3 + .../geolocation/tojson.https.window.js.ini | 4 + .../watchPosition_TypeError.https.html.ini | 6 + .../watchposition-timeout.https.window.js.ini | 4 + 28 files changed, 494 insertions(+), 5 deletions(-) create mode 100644 components/script/dom/geolocation/geolocation.rs create mode 100644 components/script/dom/geolocation/geolocationcoordinates.rs create mode 100644 components/script/dom/geolocation/geolocationposition.rs create mode 100644 components/script/dom/geolocation/geolocationpositionerror.rs create mode 100644 components/script/dom/geolocation/mod.rs create mode 100644 components/script_bindings/webidls/Geolocation.webidl create mode 100644 components/script_bindings/webidls/GeolocationCoordinates.webidl create mode 100644 components/script_bindings/webidls/GeolocationPosition.webidl create mode 100644 components/script_bindings/webidls/GeolocationPositionError.webidl create mode 100644 tests/wpt/meta/geolocation/__dir__.ini create mode 100644 tests/wpt/meta/geolocation/getCurrentPosition_TypeError.https.html.ini create mode 100644 tests/wpt/meta/geolocation/idlharness.https.window.js.ini create mode 100644 tests/wpt/meta/geolocation/non-secure-contexts.http.html.ini create mode 100644 tests/wpt/meta/geolocation/permission.https.html.ini create mode 100644 tests/wpt/meta/geolocation/tojson.https.window.js.ini create mode 100644 tests/wpt/meta/geolocation/watchPosition_TypeError.https.html.ini create mode 100644 tests/wpt/meta/geolocation/watchposition-timeout.https.window.js.ini diff --git a/components/config/prefs.rs b/components/config/prefs.rs index f10346361fe..f6f51f0ccac 100644 --- a/components/config/prefs.rs +++ b/components/config/prefs.rs @@ -114,6 +114,7 @@ pub struct Preferences { pub dom_fontface_enabled: bool, pub dom_fullscreen_test: bool, pub dom_gamepad_enabled: bool, + pub dom_geolocation_enabled: bool, pub dom_indexeddb_enabled: bool, pub dom_intersection_observer_enabled: bool, pub dom_microdata_testing_enabled: bool, @@ -294,6 +295,7 @@ impl Preferences { dom_fontface_enabled: false, dom_fullscreen_test: false, dom_gamepad_enabled: true, + dom_geolocation_enabled: false, dom_indexeddb_enabled: false, dom_intersection_observer_enabled: false, dom_microdata_testing_enabled: false, diff --git a/components/script/dom/geolocation/geolocation.rs b/components/script/dom/geolocation/geolocation.rs new file mode 100644 index 00000000000..f4b8d5d8474 --- /dev/null +++ b/components/script/dom/geolocation/geolocation.rs @@ -0,0 +1,91 @@ +/* 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/. */ +use std::cell::{Cell, RefCell}; +use std::rc::Rc; + +use dom_struct::dom_struct; +use rustc_hash::FxHashSet; +use script_bindings::codegen::GenericBindings::GeolocationBinding::Geolocation_Binding::GeolocationMethods; +use script_bindings::codegen::GenericBindings::GeolocationBinding::{ + PositionCallback, PositionOptions, +}; +use script_bindings::codegen::GenericBindings::WindowBinding::WindowMethods; +use script_bindings::reflector::Reflector; +use script_bindings::root::DomRoot; +use script_bindings::script_runtime::CanGc; + +use crate::dom::bindings::codegen::DomTypeHolder::DomTypeHolder; +use crate::dom::bindings::reflector::{DomGlobal, reflect_dom_object}; +use crate::dom::globalscope::GlobalScope; + +#[dom_struct] +pub struct Geolocation { + reflector_: Reflector, + /// + watch_ids: RefCell>, + next_watch_id: Cell, +} + +impl Geolocation { + fn new_inherited() -> Self { + Geolocation { + reflector_: Reflector::new(), + watch_ids: RefCell::new(FxHashSet::default()), + next_watch_id: Cell::new(1), + } + } + + pub(crate) fn new(global: &GlobalScope, can_gc: CanGc) -> DomRoot { + reflect_dom_object(Box::new(Self::new_inherited()), global, can_gc) + } +} + +impl GeolocationMethods for Geolocation { + /// + fn GetCurrentPosition( + &self, + _success_callback: Rc>, + _options: &PositionOptions, + ) { + // Step 1. If this's relevant global object's associated Document is not fully active: + // if !self.global().as_window().Document().is_active() { + // Step 1.1 Call back with error errorCallback and POSITION_UNAVAILABLE. + // Step 1.2 Terminate this algorithm. + // return; + // } + // Step 2. Request a position passing this, successCallback, errorCallback, and options. + // FIXME(arihant2math) + } + + /// + fn WatchPosition( + &self, + _success_callback: Rc>, + _options: &PositionOptions, + ) -> i32 { + // Step 1. If this's relevant global object's associated Document is not fully active: + if !self.global().as_window().Document().is_active() { + // Step 1.1 Call back with error errorCallback and POSITION_UNAVAILABLE. + // Step 1.2 Return 0. + return 0; + } + // Step 2. Let watchId be an implementation-defined unsigned long that is greater than zero. + let watch_id = self.next_watch_id.get(); + self.next_watch_id.set(watch_id + 1); + // Step 3. Append watchId to this's [[watchIDs]]. + self.watch_ids.borrow_mut().insert(watch_id); + // Step 4. Request a position passing this, successCallback, errorCallback, options, and watchId. + // FIXME(arihant2math) + // Step 5. Return watchId. + watch_id as i32 + } + + /// + fn ClearWatch(&self, watch_id: i32) { + let watch_id = u32::try_from(watch_id).ok(); + if let Some(id) = watch_id { + self.watch_ids.borrow_mut().remove(&id); + } + } +} diff --git a/components/script/dom/geolocation/geolocationcoordinates.rs b/components/script/dom/geolocation/geolocationcoordinates.rs new file mode 100644 index 00000000000..52f866ecb70 --- /dev/null +++ b/components/script/dom/geolocation/geolocationcoordinates.rs @@ -0,0 +1,105 @@ +/* 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/. */ + +use dom_struct::dom_struct; +use script_bindings::codegen::GenericBindings::GeolocationCoordinatesBinding::GeolocationCoordinatesMethods; +use script_bindings::num::Finite; +use script_bindings::reflector::Reflector; +use script_bindings::root::DomRoot; +use script_bindings::script_runtime::CanGc; + +use crate::dom::bindings::reflector::reflect_dom_object; +use crate::dom::globalscope::GlobalScope; + +#[dom_struct] +pub struct GeolocationCoordinates { + reflector_: Reflector, + accuracy: Finite, + latitude: Finite, + longitude: Finite, + altitude: Option>, + altitude_accuracy: Option>, + heading: Option>, + speed: Option>, +} + +impl GeolocationCoordinates { + fn new_inherited( + accuracy: Finite, + latitude: Finite, + longitude: Finite, + altitude: Option>, + altitude_accuracy: Option>, + heading: Option>, + speed: Option>, + ) -> Self { + GeolocationCoordinates { + reflector_: Reflector::new(), + accuracy, + latitude, + longitude, + altitude, + altitude_accuracy, + heading, + speed, + } + } + + #[expect(unused, clippy::too_many_arguments)] + pub(crate) fn new( + global: &GlobalScope, + accuracy: Finite, + latitude: Finite, + longitude: Finite, + altitude: Option>, + altitude_accuracy: Option>, + heading: Option>, + speed: Option>, + can_gc: CanGc, + ) -> DomRoot { + reflect_dom_object( + Box::new(Self::new_inherited( + accuracy, + latitude, + longitude, + altitude, + altitude_accuracy, + heading, + speed, + )), + global, + can_gc, + ) + } +} + +impl GeolocationCoordinatesMethods for GeolocationCoordinates { + fn Accuracy(&self) -> Finite { + self.accuracy + } + + fn Latitude(&self) -> Finite { + self.latitude + } + + fn Longitude(&self) -> Finite { + self.longitude + } + + fn GetAltitude(&self) -> Option> { + self.altitude + } + + fn GetAltitudeAccuracy(&self) -> Option> { + self.altitude_accuracy + } + + fn GetHeading(&self) -> Option> { + self.heading + } + + fn GetSpeed(&self) -> Option> { + self.speed + } +} diff --git a/components/script/dom/geolocation/geolocationposition.rs b/components/script/dom/geolocation/geolocationposition.rs new file mode 100644 index 00000000000..f1a35feac29 --- /dev/null +++ b/components/script/dom/geolocation/geolocationposition.rs @@ -0,0 +1,55 @@ +/* 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/. */ + +use dom_struct::dom_struct; +use script_bindings::codegen::GenericBindings::GeolocationPositionBinding::GeolocationPositionMethods; +use script_bindings::reflector::Reflector; +use script_bindings::root::{Dom, DomRoot}; +use script_bindings::script_runtime::CanGc; + +use crate::dom::bindings::codegen::DomTypeHolder::DomTypeHolder; +use crate::dom::bindings::reflector::reflect_dom_object; +use crate::dom::geolocationcoordinates::GeolocationCoordinates; +use crate::dom::globalscope::GlobalScope; + +#[dom_struct] +pub struct GeolocationPosition { + reflector_: Reflector, + coords: Dom, + timestamp: u64, +} + +impl GeolocationPosition { + fn new_inherited(coords: &GeolocationCoordinates, timestamp: u64) -> Self { + GeolocationPosition { + reflector_: Reflector::new(), + coords: Dom::from_ref(coords), + timestamp, + } + } + + #[expect(unused)] + pub(crate) fn new( + global: &GlobalScope, + coords: &GeolocationCoordinates, + timestamp: u64, + can_gc: CanGc, + ) -> DomRoot { + reflect_dom_object( + Box::new(Self::new_inherited(coords, timestamp)), + global, + can_gc, + ) + } +} + +impl GeolocationPositionMethods for GeolocationPosition { + fn Coords(&self) -> DomRoot { + DomRoot::from_ref(&*self.coords.clone()) + } + + fn Timestamp(&self) -> u64 { + self.timestamp + } +} diff --git a/components/script/dom/geolocation/geolocationpositionerror.rs b/components/script/dom/geolocation/geolocationpositionerror.rs new file mode 100644 index 00000000000..300f8fa0b5b --- /dev/null +++ b/components/script/dom/geolocation/geolocationpositionerror.rs @@ -0,0 +1,51 @@ +/* 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/. */ + +use dom_struct::dom_struct; +use script_bindings::codegen::GenericBindings::GeolocationPositionErrorBinding::GeolocationPositionErrorMethods; +use script_bindings::reflector::Reflector; +use script_bindings::root::DomRoot; +use script_bindings::script_runtime::CanGc; +use script_bindings::str::DOMString; + +use crate::dom::bindings::codegen::DomTypeHolder::DomTypeHolder; +use crate::dom::bindings::reflector::reflect_dom_object; +use crate::dom::globalscope::GlobalScope; + +#[dom_struct] +pub struct GeolocationPositionError { + reflector_: Reflector, + code: u16, + message: DOMString, +} + +impl GeolocationPositionError { + fn new_inherited(code: u16, message: DOMString) -> Self { + GeolocationPositionError { + reflector_: Reflector::new(), + code, + message, + } + } + + #[expect(unused)] + pub(crate) fn new( + global: &GlobalScope, + code: u16, + message: DOMString, + can_gc: CanGc, + ) -> DomRoot { + reflect_dom_object(Box::new(Self::new_inherited(code, message)), global, can_gc) + } +} + +impl GeolocationPositionErrorMethods for GeolocationPositionError { + fn Code(&self) -> u16 { + self.code + } + + fn Message(&self) -> DOMString { + self.message.clone() + } +} diff --git a/components/script/dom/geolocation/mod.rs b/components/script/dom/geolocation/mod.rs new file mode 100644 index 00000000000..223a4a8321c --- /dev/null +++ b/components/script/dom/geolocation/mod.rs @@ -0,0 +1,10 @@ +/* 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/. */ + +#[expect(clippy::module_inception, reason = "The interface name is Geolocation")] +pub(crate) mod geolocation; +pub(crate) use geolocation::Geolocation; +pub(crate) mod geolocationcoordinates; +pub(crate) mod geolocationposition; +pub(crate) mod geolocationpositionerror; diff --git a/components/script/dom/mod.rs b/components/script/dom/mod.rs index b7d0a228e20..5be03ba6d69 100644 --- a/components/script/dom/mod.rs +++ b/components/script/dom/mod.rs @@ -325,6 +325,8 @@ pub(crate) mod formdata; pub(crate) mod formdataevent; pub(crate) mod gamepad; pub(crate) use self::gamepad::*; +pub(crate) mod geolocation; +pub(crate) use self::geolocation::*; #[allow(dead_code)] pub(crate) mod globalscope; pub(crate) mod hashchangeevent; diff --git a/components/script/dom/navigator.rs b/components/script/dom/navigator.rs index 9127eba3de4..a15bd7b33e4 100644 --- a/components/script/dom/navigator.rs +++ b/components/script/dom/navigator.rs @@ -38,6 +38,7 @@ use crate::dom::credentialmanagement::credentialscontainer::CredentialsContainer use crate::dom::csp::{GlobalCspReporting, Violation}; use crate::dom::gamepad::Gamepad; use crate::dom::gamepad::gamepadevent::GamepadEventType; +use crate::dom::geolocation::Geolocation; use crate::dom::globalscope::GlobalScope; use crate::dom::mediadevices::MediaDevices; use crate::dom::mediasession::MediaSession; @@ -238,6 +239,11 @@ impl NavigatorMethods for Navigator { .or_init(|| CredentialsContainer::new(&self.global(), CanGc::note())) } + // https://www.w3.org/TR/geolocation/#navigator_interface + fn Geolocation(&self) -> DomRoot { + Geolocation::new(&self.global(), CanGc::note()) + } + // https://html.spec.whatwg.org/multipage/#navigatorlanguage fn Language(&self) -> DOMString { navigatorinfo::Language() diff --git a/components/script/script_runtime.rs b/components/script/script_runtime.rs index 18e20881088..6253001c024 100644 --- a/components/script/script_runtime.rs +++ b/components/script/script_runtime.rs @@ -116,6 +116,7 @@ pub(crate) enum ScriptThreadEventCategory { FileRead, FontLoading, FormPlannedNavigation, + GeolocationEvent, HistoryEvent, ImageCacheMsg, InputEvent, @@ -157,6 +158,7 @@ impl From for ProfilerCategory { ScriptThreadEventCategory::FormPlannedNavigation => { ProfilerCategory::ScriptPlannedNavigation }, + ScriptThreadEventCategory::GeolocationEvent => ProfilerCategory::ScriptGeolocationEvent, ScriptThreadEventCategory::HistoryEvent => ProfilerCategory::ScriptHistoryEvent, ScriptThreadEventCategory::ImageCacheMsg => ProfilerCategory::ScriptImageCacheMsg, ScriptThreadEventCategory::InputEvent => ProfilerCategory::ScriptInputEvent, @@ -203,6 +205,7 @@ impl From for ScriptHangAnnotation { ScriptThreadEventCategory::FormPlannedNavigation => { ScriptHangAnnotation::FormPlannedNavigation }, + ScriptThreadEventCategory::GeolocationEvent => ScriptHangAnnotation::GeolocationEvent, ScriptThreadEventCategory::HistoryEvent => ScriptHangAnnotation::HistoryEvent, ScriptThreadEventCategory::ImageCacheMsg => ScriptHangAnnotation::ImageCacheMsg, ScriptThreadEventCategory::NetworkEvent => ScriptHangAnnotation::NetworkEvent, diff --git a/components/script/script_thread.rs b/components/script/script_thread.rs index 9abf725909f..21156ef9eef 100644 --- a/components/script/script_thread.rs +++ b/components/script/script_thread.rs @@ -1616,6 +1616,14 @@ impl ScriptThread { profiler_chan, f ), + ScriptThreadEventCategory::GeolocationEvent => { + time_profile!( + ProfilerCategory::ScriptGeolocationEvent, + None, + profiler_chan, + f + ) + }, ScriptThreadEventCategory::HistoryEvent => { time_profile!(ProfilerCategory::ScriptHistoryEvent, None, profiler_chan, f) }, diff --git a/components/script/task_manager.rs b/components/script/task_manager.rs index 9524f850968..b963082c869 100644 --- a/components/script/task_manager.rs +++ b/components/script/task_manager.rs @@ -141,6 +141,8 @@ impl TaskManager { task_source_functions!(self, file_reading_task_source, FileReading); task_source_functions!(self, font_loading_task_source, FontLoading); task_source_functions!(self, gamepad_task_source, Gamepad); + // FIXME(arihant2math): uncomment when geolocation is implemented. + // task_source_functions!(self, geolocation_task_source, Geolocation); task_source_functions!(self, media_element_task_source, MediaElement); task_source_functions!(self, networking_task_source, Networking); task_source_functions!(self, performance_timeline_task_source, PerformanceTimeline); diff --git a/components/script/task_source.rs b/components/script/task_source.rs index c887f73cc87..af133f5484e 100644 --- a/components/script/task_source.rs +++ b/components/script/task_source.rs @@ -46,6 +46,8 @@ pub(crate) enum TaskSourceName { Timer, /// Gamepad, + /// + Geolocation, /// IntersectionObserver, /// @@ -63,6 +65,7 @@ impl From for ScriptThreadEventCategory { TaskSourceName::DOMManipulation => ScriptThreadEventCategory::ScriptEvent, TaskSourceName::FileReading => ScriptThreadEventCategory::FileRead, TaskSourceName::FontLoading => ScriptThreadEventCategory::FontLoading, + TaskSourceName::Geolocation => ScriptThreadEventCategory::GeolocationEvent, TaskSourceName::HistoryTraversal => ScriptThreadEventCategory::HistoryEvent, TaskSourceName::Networking => ScriptThreadEventCategory::NetworkEvent, TaskSourceName::PerformanceTimeline => { diff --git a/components/script_bindings/webidls/Geolocation.webidl b/components/script_bindings/webidls/Geolocation.webidl new file mode 100644 index 00000000000..733fb061927 --- /dev/null +++ b/components/script_bindings/webidls/Geolocation.webidl @@ -0,0 +1,47 @@ +/* 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/. */ + +/* + * The origin of this IDL file is + * https://www.w3.org/TR/geolocation/#geolocation_interface + */ + +partial interface Navigator { + [SameObject, Pref="dom_geolocation_enabled"] readonly attribute Geolocation geolocation; +}; + +// FIXME: The errorCallback parameters are currently commented out because they are not yet supported by the codegen, +// further debugging is needed. +// https://www.w3.org/TR/geolocation/#geolocation_interface +[Pref="dom_geolocation_enabled", Exposed=Window] +interface Geolocation { + undefined getCurrentPosition ( + PositionCallback successCallback, +// optional PositionErrorCallback? errorCallback = null, + optional PositionOptions options = {} + ); + + long watchPosition ( + PositionCallback successCallback, +// optional PositionErrorCallback? errorCallback = null, + optional PositionOptions options = {} + ); + + undefined clearWatch (long watchId); +}; + +callback PositionCallback = undefined ( + GeolocationPosition position +); + +callback PositionErrorCallback = undefined ( + GeolocationPositionError positionError +); + +// https://www.w3.org/TR/geolocation/#position_options_interface +dictionary PositionOptions { + boolean enableHighAccuracy = false; + [Clamp] unsigned long timeout = 0xFFFFFFFF; + [Clamp] unsigned long maximumAge = 0; +}; diff --git a/components/script_bindings/webidls/GeolocationCoordinates.webidl b/components/script_bindings/webidls/GeolocationCoordinates.webidl new file mode 100644 index 00000000000..cd58552e840 --- /dev/null +++ b/components/script_bindings/webidls/GeolocationCoordinates.webidl @@ -0,0 +1,20 @@ +/* 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/. */ + +/* + * The origin of this IDL file is + * https://www.w3.org/TR/geolocation/#coordinates_interface + */ + +// https://www.w3.org/TR/geolocation/#coordinates_interface +[Pref="dom_geolocation_enabled", Exposed=Window, SecureContext] +interface GeolocationCoordinates { + readonly attribute double accuracy; + readonly attribute double latitude; + readonly attribute double longitude; + readonly attribute double? altitude; + readonly attribute double? altitudeAccuracy; + readonly attribute double? heading; + readonly attribute double? speed; +}; diff --git a/components/script_bindings/webidls/GeolocationPosition.webidl b/components/script_bindings/webidls/GeolocationPosition.webidl new file mode 100644 index 00000000000..9706e1975e8 --- /dev/null +++ b/components/script_bindings/webidls/GeolocationPosition.webidl @@ -0,0 +1,15 @@ +/* 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/. */ + +/* + * The origin of this IDL file is + * https://www.w3.org/TR/geolocation/#position_interface + */ + +// https://www.w3.org/TR/geolocation/#position_interface +[Pref="dom_geolocation_enabled", Exposed=Window, SecureContext] +interface GeolocationPosition { + readonly attribute GeolocationCoordinates coords; + readonly attribute EpochTimeStamp timestamp; +}; diff --git a/components/script_bindings/webidls/GeolocationPositionError.webidl b/components/script_bindings/webidls/GeolocationPositionError.webidl new file mode 100644 index 00000000000..b637a225359 --- /dev/null +++ b/components/script_bindings/webidls/GeolocationPositionError.webidl @@ -0,0 +1,18 @@ +/* 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/. */ + +/* + * The origin of this IDL file is + * https://www.w3.org/TR/geolocation/#position_error_interface + */ + +// https://www.w3.org/TR/geolocation/#position_error_interface +[Pref="dom_geolocation_enabled", Exposed=Window] +interface GeolocationPositionError { + const unsigned short PERMISSION_DENIED = 1; + const unsigned short POSITION_UNAVAILABLE = 2; + const unsigned short TIMEOUT = 3; + readonly attribute unsigned short code; + readonly attribute DOMString message; +}; diff --git a/components/shared/background_hang_monitor/lib.rs b/components/shared/background_hang_monitor/lib.rs index f2f2c84c6cc..f7c6acaddac 100644 --- a/components/shared/background_hang_monitor/lib.rs +++ b/components/shared/background_hang_monitor/lib.rs @@ -23,6 +23,7 @@ pub enum ScriptHangAnnotation { FileRead, FontLoading, FormPlannedNavigation, + GeolocationEvent, ImageCacheMsg, InputEvent, HistoryEvent, diff --git a/components/shared/profile/time.rs b/components/shared/profile/time.rs index b2dee281eab..626470b65e4 100644 --- a/components/shared/profile/time.rs +++ b/components/shared/profile/time.rs @@ -105,12 +105,13 @@ pub enum ProfilerCategory { ScriptEnterFullscreen = 0x79, ScriptExitFullscreen = 0x7a, ScriptWorkletEvent = 0x7b, - ScriptPerformanceEvent = 0x7c, - ScriptHistoryEvent = 0x7d, - ScriptPortMessage = 0x7e, - ScriptWebGPUMsg = 0x7f, + ScriptGeolocationEvent = 0x7c, + ScriptPerformanceEvent = 0x7d, + ScriptHistoryEvent = 0x7e, + ScriptPortMessage = 0x7f, + ScriptWebGPUMsg = 0x80, - ScriptDatabaseAccessEvent = 0x80, + ScriptDatabaseAccessEvent = 0x81, /// Web performance metrics. TimeToFirstPaint = 0x90, @@ -136,6 +137,7 @@ impl ProfilerCategory { ProfilerCategory::ScriptEvent => "ScriptEvent", ProfilerCategory::ScriptFileRead => "ScriptFileRead", ProfilerCategory::ScriptFontLoading => "ScriptFontLoading", + ProfilerCategory::ScriptGeolocationEvent => "ScriptGeolocationEvent", ProfilerCategory::ScriptImageCacheMsg => "ScriptImageCacheMsg", ProfilerCategory::ScriptInputEvent => "ScriptInputEvent", ProfilerCategory::ScriptNetworkEvent => "ScriptNetworkEvent", diff --git a/python/tidy/tidy.py b/python/tidy/tidy.py index 17f5bf08b8f..86aacdae712 100644 --- a/python/tidy/tidy.py +++ b/python/tidy/tidy.py @@ -115,6 +115,7 @@ WEBIDL_STANDARDS = [ b"//dvcs.w3.org/hg", b"//www.w3.org/TR/trusted-types/", b"//www.w3.org/TR/credential-management", + b"//www.w3.org/TR/geolocation", b"//dom.spec.whatwg.org", b"//drafts.csswg.org", b"//drafts.css-houdini.org", diff --git a/tests/wpt/include.ini b/tests/wpt/include.ini index 436cc59d51b..4c76805a2cd 100644 --- a/tests/wpt/include.ini +++ b/tests/wpt/include.ini @@ -148,6 +148,8 @@ skip: true skip: false [gamepad] skip: false +[geolocation] + skip: false [hr-time] skip: false [html] diff --git a/tests/wpt/meta/geolocation/__dir__.ini b/tests/wpt/meta/geolocation/__dir__.ini new file mode 100644 index 00000000000..60e0b3984c3 --- /dev/null +++ b/tests/wpt/meta/geolocation/__dir__.ini @@ -0,0 +1,3 @@ +prefs: [ + "dom_geolocation_enabled:true", +] diff --git a/tests/wpt/meta/geolocation/getCurrentPosition_TypeError.https.html.ini b/tests/wpt/meta/geolocation/getCurrentPosition_TypeError.https.html.ini new file mode 100644 index 00000000000..1e6ea8ac8a4 --- /dev/null +++ b/tests/wpt/meta/geolocation/getCurrentPosition_TypeError.https.html.ini @@ -0,0 +1,6 @@ +[getCurrentPosition_TypeError.https.html] + [Call getCurrentPosition() with wrong type for third argument. Exception expected.] + expected: FAIL + + [Calling getCurrentPosition() with a legacy event handler objects.] + expected: FAIL diff --git a/tests/wpt/meta/geolocation/idlharness.https.window.js.ini b/tests/wpt/meta/geolocation/idlharness.https.window.js.ini new file mode 100644 index 00000000000..782e2025cf8 --- /dev/null +++ b/tests/wpt/meta/geolocation/idlharness.https.window.js.ini @@ -0,0 +1,6 @@ +[idlharness.https.window.html] + [GeolocationPosition interface: operation toJSON()] + expected: FAIL + + [GeolocationCoordinates interface: operation toJSON()] + expected: FAIL diff --git a/tests/wpt/meta/geolocation/non-secure-contexts.http.html.ini b/tests/wpt/meta/geolocation/non-secure-contexts.http.html.ini new file mode 100644 index 00000000000..d1b04191438 --- /dev/null +++ b/tests/wpt/meta/geolocation/non-secure-contexts.http.html.ini @@ -0,0 +1,13 @@ +[non-secure-contexts.http.html] + expected: TIMEOUT + [When in a non-secure context, getCurrentPosition()'s errorCallback is asynchronously called.] + expected: TIMEOUT + + [When in a non-secure context, watchPosition()'s errorCallback is asynchronously called.] + expected: NOTRUN + + [When in a non-secure context, the getCurrentPosition() errorCallBack gets a GeolocationPositionError with the correct error code.] + expected: NOTRUN + + [When in a non-secure context, the watchPosition() errorCallBack gets a GeolocationPositionError with the correct error code.] + expected: NOTRUN diff --git a/tests/wpt/meta/geolocation/permission.https.html.ini b/tests/wpt/meta/geolocation/permission.https.html.ini new file mode 100644 index 00000000000..96262009f84 --- /dev/null +++ b/tests/wpt/meta/geolocation/permission.https.html.ini @@ -0,0 +1,3 @@ +[permission.https.html] + [Query "geolocation" powerful feature] + expected: FAIL diff --git a/tests/wpt/meta/geolocation/tojson.https.window.js.ini b/tests/wpt/meta/geolocation/tojson.https.window.js.ini new file mode 100644 index 00000000000..c9b577f80f3 --- /dev/null +++ b/tests/wpt/meta/geolocation/tojson.https.window.js.ini @@ -0,0 +1,4 @@ +[tojson.https.window.html] + expected: ERROR + [Test toJSON() in GeolocationPosition and GeolocationCoordinates.] + expected: NOTRUN diff --git a/tests/wpt/meta/geolocation/watchPosition_TypeError.https.html.ini b/tests/wpt/meta/geolocation/watchPosition_TypeError.https.html.ini new file mode 100644 index 00000000000..c0f8ddedd36 --- /dev/null +++ b/tests/wpt/meta/geolocation/watchPosition_TypeError.https.html.ini @@ -0,0 +1,6 @@ +[watchPosition_TypeError.https.html] + [Call watchPosition() with wrong type for third argument. Exception expected.] + expected: FAIL + + [Calling watchPosition() with a legacy event handler object.] + expected: FAIL diff --git a/tests/wpt/meta/geolocation/watchposition-timeout.https.window.js.ini b/tests/wpt/meta/geolocation/watchposition-timeout.https.window.js.ini new file mode 100644 index 00000000000..616d80c4f64 --- /dev/null +++ b/tests/wpt/meta/geolocation/watchposition-timeout.https.window.js.ini @@ -0,0 +1,4 @@ +[watchposition-timeout.https.window.html] + expected: ERROR + [Passing timeout=1 should not cause multiple timeout errors] + expected: NOTRUN