mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 13:28:11 +00:00
LibWeb: Re-implement HTML::Navigator using IDL
Get rid of the bespoke NavigatorObject class and use the modern IDL strategies for creating platform objects to re-implement Navigator and its associcated mixin interfaces. While we're here, implement it in a way that brings WorkerNavigator up to spec :^)
This commit is contained in:
parent
14e1513077
commit
2d5bee256e
27 changed files with 343 additions and 208 deletions
53
Userland/Libraries/LibWeb/HTML/NavigatorID.cpp
Normal file
53
Userland/Libraries/LibWeb/HTML/NavigatorID.cpp
Normal file
|
@ -0,0 +1,53 @@
|
|||
/*
|
||||
* Copyright (c) 2022, Andrew Kaster <akaster@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <AK/String.h>
|
||||
#include <LibWeb/HTML/NavigatorID.h>
|
||||
#include <LibWeb/Loader/ResourceLoader.h>
|
||||
|
||||
namespace Web::HTML {
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/system-state.html#dom-navigator-appversion
|
||||
String NavigatorIDMixin::app_version() const
|
||||
{
|
||||
// Must return the appropriate string that starts with "5.0 (", as follows:
|
||||
|
||||
// Let trail be the substring of default `User-Agent` value that follows the "Mozilla/" prefix.
|
||||
auto user_agent_string = ResourceLoader::the().user_agent();
|
||||
|
||||
auto trail = user_agent_string.substring_view(strlen("Mozilla/"), user_agent_string.length() - strlen("Mozilla/"));
|
||||
|
||||
// If the navigator compatibility mode is Chrome or WebKit
|
||||
// NOTE: We are using Chrome for now. Make sure to update all APIs if you add a toggle for this.
|
||||
|
||||
// Return trail.
|
||||
return trail;
|
||||
|
||||
// If the navigator compatibility mode is Gecko
|
||||
// If trail starts with "5.0 (Windows", then return "5.0 (Windows)".
|
||||
// Otherwise, return the prefix of trail up to but not including the first U+003B (;), concatenated with the
|
||||
// character U+0029 RIGHT PARENTHESIS. For example, "5.0 (Macintosh)", "5.0 (Android 10)", or "5.0 (X11)".
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/system-state.html#dom-navigator-platform
|
||||
String NavigatorIDMixin::platform() const
|
||||
{
|
||||
// Must return a string representing the platform on which the browser is executing (e.g. "MacIntel", "Win32",
|
||||
// "Linux x86_64", "Linux armv81") or, for privacy and compatibility, a string that is commonly returned on another
|
||||
// platform.
|
||||
|
||||
// FIXME: Use some portion of the user agent string to make spoofing work 100%
|
||||
return "SerenityOS";
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/system-state.html#dom-navigator-useragent
|
||||
String NavigatorIDMixin::user_agent() const
|
||||
{
|
||||
// Must return the default `User-Agent` value.
|
||||
return ResourceLoader::the().user_agent();
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue