Serenity Operating System
at master 53 lines 2.1 kB view raw
1/* 2 * Copyright (c) 2022, Andrew Kaster <akaster@serenityos.org> 3 * 4 * SPDX-License-Identifier: BSD-2-Clause 5 */ 6 7#include <AK/DeprecatedString.h> 8#include <LibWeb/HTML/NavigatorID.h> 9#include <LibWeb/Loader/ResourceLoader.h> 10 11namespace Web::HTML { 12 13// https://html.spec.whatwg.org/multipage/system-state.html#dom-navigator-appversion 14DeprecatedString NavigatorIDMixin::app_version() const 15{ 16 // Must return the appropriate string that starts with "5.0 (", as follows: 17 18 // Let trail be the substring of default `User-Agent` value that follows the "Mozilla/" prefix. 19 auto user_agent_string = ResourceLoader::the().user_agent(); 20 21 auto trail = user_agent_string.substring_view(strlen("Mozilla/"), user_agent_string.length() - strlen("Mozilla/")); 22 23 // If the navigator compatibility mode is Chrome or WebKit 24 // NOTE: We are using Chrome for now. Make sure to update all APIs if you add a toggle for this. 25 26 // Return trail. 27 return trail; 28 29 // If the navigator compatibility mode is Gecko 30 // If trail starts with "5.0 (Windows", then return "5.0 (Windows)". 31 // Otherwise, return the prefix of trail up to but not including the first U+003B (;), concatenated with the 32 // character U+0029 RIGHT PARENTHESIS. For example, "5.0 (Macintosh)", "5.0 (Android 10)", or "5.0 (X11)". 33} 34 35// https://html.spec.whatwg.org/multipage/system-state.html#dom-navigator-platform 36DeprecatedString NavigatorIDMixin::platform() const 37{ 38 // Must return a string representing the platform on which the browser is executing (e.g. "MacIntel", "Win32", 39 // "Linux x86_64", "Linux armv81") or, for privacy and compatibility, a string that is commonly returned on another 40 // platform. 41 42 // FIXME: Use some portion of the user agent string to make spoofing work 100% 43 return "SerenityOS"; 44} 45 46// https://html.spec.whatwg.org/multipage/system-state.html#dom-navigator-useragent 47DeprecatedString NavigatorIDMixin::user_agent() const 48{ 49 // Must return the default `User-Agent` value. 50 return ResourceLoader::the().user_agent(); 51} 52 53}