2022-10-08 20:53:08 -06:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2022, Andrew Kaster <akaster@serenityos.org>
|
2022-10-12 23:52:58 +02:00
|
|
|
* Copyright (c) 2022, Linus Groh <linusg@serenityos.org>
|
2024-09-04 23:52:56 +01:00
|
|
|
* Copyright (c) 2024, Jamie Mansfield <jmansfield@cadixdev.org>
|
2025-06-19 15:28:02 +02:00
|
|
|
* Copyright (c) 2025, Jelle Raaijmakers <jelle@ladybird.org>
|
2022-10-08 20:53:08 -06:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
2024-11-15 04:01:23 +13:00
|
|
|
#include <LibGC/Heap.h>
|
2022-10-08 20:53:08 -06:00
|
|
|
#include <LibJS/Runtime/Realm.h>
|
|
|
|
#include <LibWeb/Bindings/Intrinsics.h>
|
2024-04-27 12:09:58 +12:00
|
|
|
#include <LibWeb/Bindings/NavigatorPrototype.h>
|
2023-11-10 13:29:20 -05:00
|
|
|
#include <LibWeb/Clipboard/Clipboard.h>
|
2025-01-30 22:29:26 +01:00
|
|
|
#include <LibWeb/CredentialManagement/CredentialsContainer.h>
|
2025-06-19 15:28:02 +02:00
|
|
|
#include <LibWeb/Geolocation/Geolocation.h>
|
2022-10-08 20:53:08 -06:00
|
|
|
#include <LibWeb/HTML/Navigator.h>
|
2022-10-12 23:52:58 +02:00
|
|
|
#include <LibWeb/HTML/Scripting/Environments.h>
|
|
|
|
#include <LibWeb/HTML/Window.h>
|
2024-07-02 20:55:21 +01:00
|
|
|
#include <LibWeb/Loader/ResourceLoader.h>
|
2022-10-12 23:52:58 +02:00
|
|
|
#include <LibWeb/Page/Page.h>
|
2024-11-30 18:01:40 +13:00
|
|
|
#include <LibWeb/ServiceWorker/ServiceWorkerContainer.h>
|
2022-10-08 20:53:08 -06:00
|
|
|
|
|
|
|
namespace Web::HTML {
|
|
|
|
|
2024-11-15 04:01:23 +13:00
|
|
|
GC_DEFINE_ALLOCATOR(Navigator);
|
2023-11-19 19:47:52 +01:00
|
|
|
|
2024-11-15 04:01:23 +13:00
|
|
|
GC::Ref<Navigator> Navigator::create(JS::Realm& realm)
|
2022-10-08 20:53:08 -06:00
|
|
|
{
|
2024-11-14 05:50:17 +13:00
|
|
|
return realm.create<Navigator>(realm);
|
2022-10-08 20:53:08 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
Navigator::Navigator(JS::Realm& realm)
|
|
|
|
: PlatformObject(realm)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
Navigator::~Navigator() = default;
|
|
|
|
|
2023-08-07 08:41:28 +02:00
|
|
|
void Navigator::initialize(JS::Realm& realm)
|
2023-01-10 06:28:20 -05:00
|
|
|
{
|
2024-03-16 13:13:08 +01:00
|
|
|
WEB_SET_PROTOTYPE_FOR_INTERFACE(Navigator);
|
2025-04-20 16:22:57 +02:00
|
|
|
Base::initialize(realm);
|
2025-08-18 17:27:00 +01:00
|
|
|
NavigatorGamepadPartial::check_for_connected_gamepads();
|
2023-01-10 06:28:20 -05:00
|
|
|
}
|
|
|
|
|
2023-02-28 00:20:09 +00:00
|
|
|
// https://html.spec.whatwg.org/multipage/system-state.html#dom-navigator-pdfviewerenabled
|
|
|
|
bool Navigator::pdf_viewer_enabled() const
|
|
|
|
{
|
|
|
|
// The NavigatorPlugins mixin's pdfViewerEnabled getter steps are to return the user agent's PDF viewer supported.
|
2023-02-28 00:23:53 +00:00
|
|
|
// NOTE: The NavigatorPlugins mixin should only be exposed on the Window object.
|
2025-01-21 09:12:05 -05:00
|
|
|
auto const& window = as<HTML::Window>(HTML::current_principal_global_object());
|
2023-12-15 20:33:16 +01:00
|
|
|
return window.page().pdf_viewer_supported();
|
2023-02-28 00:20:09 +00:00
|
|
|
}
|
|
|
|
|
2022-10-12 23:52:58 +02:00
|
|
|
// https://w3c.github.io/webdriver/#dfn-webdriver
|
|
|
|
bool Navigator::webdriver() const
|
|
|
|
{
|
|
|
|
// Returns true if webdriver-active flag is set, false otherwise.
|
|
|
|
|
|
|
|
// NOTE: The NavigatorAutomationInformation interface should not be exposed on WorkerNavigator.
|
2025-01-21 09:12:05 -05:00
|
|
|
auto const& window = as<HTML::Window>(HTML::current_principal_global_object());
|
2023-12-15 20:33:16 +01:00
|
|
|
return window.page().is_webdriver_active();
|
2022-10-12 23:52:58 +02:00
|
|
|
}
|
|
|
|
|
2023-02-28 00:23:53 +00:00
|
|
|
void Navigator::visit_edges(Cell::Visitor& visitor)
|
|
|
|
{
|
|
|
|
Base::visit_edges(visitor);
|
2025-08-18 17:27:00 +01:00
|
|
|
NavigatorGamepadPartial::visit_edges(visitor);
|
2023-02-28 00:23:53 +00:00
|
|
|
visitor.visit(m_mime_type_array);
|
|
|
|
visitor.visit(m_plugin_array);
|
2023-11-10 13:29:20 -05:00
|
|
|
visitor.visit(m_clipboard);
|
2025-06-19 15:28:02 +02:00
|
|
|
visitor.visit(m_geolocation);
|
2025-08-06 09:07:40 +02:00
|
|
|
visitor.visit(m_serial);
|
2024-05-25 12:40:44 +01:00
|
|
|
visitor.visit(m_user_activation);
|
2024-08-22 18:09:35 +01:00
|
|
|
visitor.visit(m_service_worker_container);
|
2024-09-04 23:52:56 +01:00
|
|
|
visitor.visit(m_media_capabilities);
|
2025-01-30 22:29:26 +01:00
|
|
|
visitor.visit(m_credentials);
|
2023-02-28 00:23:53 +00:00
|
|
|
}
|
|
|
|
|
2024-11-15 04:01:23 +13:00
|
|
|
GC::Ref<MimeTypeArray> Navigator::mime_types()
|
2023-02-28 00:23:53 +00:00
|
|
|
{
|
|
|
|
if (!m_mime_type_array)
|
2024-11-14 05:50:17 +13:00
|
|
|
m_mime_type_array = realm().create<MimeTypeArray>(realm());
|
2023-02-28 00:23:53 +00:00
|
|
|
return *m_mime_type_array;
|
|
|
|
}
|
|
|
|
|
2024-11-15 04:01:23 +13:00
|
|
|
GC::Ref<PluginArray> Navigator::plugins()
|
2023-02-28 00:23:53 +00:00
|
|
|
{
|
|
|
|
if (!m_plugin_array)
|
2024-11-14 05:50:17 +13:00
|
|
|
m_plugin_array = realm().create<PluginArray>(realm());
|
2023-02-28 00:23:53 +00:00
|
|
|
return *m_plugin_array;
|
|
|
|
}
|
|
|
|
|
2024-11-15 04:01:23 +13:00
|
|
|
GC::Ref<Clipboard::Clipboard> Navigator::clipboard()
|
2023-11-10 13:29:20 -05:00
|
|
|
{
|
|
|
|
if (!m_clipboard)
|
2024-11-14 05:50:17 +13:00
|
|
|
m_clipboard = realm().create<Clipboard::Clipboard>(realm());
|
2023-11-10 13:29:20 -05:00
|
|
|
return *m_clipboard;
|
|
|
|
}
|
|
|
|
|
2025-06-19 15:28:02 +02:00
|
|
|
GC::Ref<Geolocation::Geolocation> Navigator::geolocation()
|
|
|
|
{
|
|
|
|
if (!m_geolocation)
|
|
|
|
m_geolocation = realm().create<Geolocation::Geolocation>(realm());
|
|
|
|
return *m_geolocation;
|
|
|
|
}
|
|
|
|
|
2025-08-06 09:07:40 +02:00
|
|
|
GC::Ref<Serial::Serial> Navigator::serial()
|
|
|
|
{
|
|
|
|
if (!m_serial)
|
|
|
|
m_serial = realm().create<Serial::Serial>(realm());
|
|
|
|
return *m_serial;
|
|
|
|
}
|
|
|
|
|
2024-11-15 04:01:23 +13:00
|
|
|
GC::Ref<UserActivation> Navigator::user_activation()
|
2024-05-25 12:40:44 +01:00
|
|
|
{
|
|
|
|
if (!m_user_activation)
|
2024-11-14 05:50:17 +13:00
|
|
|
m_user_activation = realm().create<UserActivation>(realm());
|
2024-05-25 12:40:44 +01:00
|
|
|
return *m_user_activation;
|
|
|
|
}
|
|
|
|
|
2025-01-30 22:29:26 +01:00
|
|
|
GC::Ref<CredentialManagement::CredentialsContainer> Navigator::credentials()
|
|
|
|
{
|
|
|
|
if (!m_credentials)
|
|
|
|
m_credentials = realm().create<CredentialManagement::CredentialsContainer>(realm());
|
|
|
|
return *m_credentials;
|
|
|
|
}
|
|
|
|
|
2024-04-11 21:28:30 +02:00
|
|
|
// https://w3c.github.io/pointerevents/#dom-navigator-maxtouchpoints
|
|
|
|
WebIDL::Long Navigator::max_touch_points()
|
|
|
|
{
|
|
|
|
dbgln("FIXME: Unimplemented Navigator.maxTouchPoints");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2024-11-30 18:01:40 +13:00
|
|
|
GC::Ref<ServiceWorker::ServiceWorkerContainer> Navigator::service_worker()
|
2024-08-22 18:09:35 +01:00
|
|
|
{
|
|
|
|
if (!m_service_worker_container)
|
2024-11-30 18:01:40 +13:00
|
|
|
m_service_worker_container = realm().create<ServiceWorker::ServiceWorkerContainer>(realm());
|
2024-08-22 18:09:35 +01:00
|
|
|
return *m_service_worker_container;
|
|
|
|
}
|
|
|
|
|
2024-11-15 04:01:23 +13:00
|
|
|
GC::Ref<MediaCapabilitiesAPI::MediaCapabilities> Navigator::media_capabilities()
|
2024-09-04 23:52:56 +01:00
|
|
|
{
|
|
|
|
if (!m_media_capabilities)
|
2024-11-14 05:50:17 +13:00
|
|
|
m_media_capabilities = realm().create<MediaCapabilitiesAPI::MediaCapabilities>(realm());
|
2024-09-04 23:52:56 +01:00
|
|
|
return *m_media_capabilities;
|
|
|
|
}
|
|
|
|
|
2022-10-08 20:53:08 -06:00
|
|
|
}
|