LibWeb: Implement emulated Geolocation position retrieval

This implements enough of the Geolocation spec that it is now possible
for websites to retrieve the current geo position or try to watch for
updates (which currently never happen).

As it stands now, it only returns a single emulated position that points
to San Francisco.
This commit is contained in:
Jelle Raaijmakers
2025-06-22 20:26:03 +02:00
committed by Jelle Raaijmakers
parent 53c35c5d3b
commit 71f03cb785
Notes: github-actions[bot] 2025-06-24 09:35:05 +00:00
11 changed files with 477 additions and 48 deletions

View File

@@ -12,10 +12,9 @@ namespace Web::Geolocation {
GC_DEFINE_ALLOCATOR(GeolocationPositionError);
GeolocationPositionError::GeolocationPositionError(JS::Realm& realm, ErrorCode code, String message)
GeolocationPositionError::GeolocationPositionError(JS::Realm& realm, ErrorCode code)
: PlatformObject(realm)
, m_code(code)
, m_message(move(message))
{
}
@@ -25,4 +24,19 @@ void GeolocationPositionError::initialize(JS::Realm& realm)
Base::initialize(realm);
}
// https://w3c.github.io/geolocation/#message-attribute
String GeolocationPositionError::message() const
{
// The message attribute is a developer-friendly textual description of the code attribute.
switch (m_code) {
case ErrorCode::PositionUnavailable:
return "Position unavailable"_string;
case ErrorCode::PermissionDenied:
return "Permission denied"_string;
case ErrorCode::Timeout:
return "Timeout"_string;
}
VERIFY_NOT_REACHED();
}
}