NavigatorID.cpp 2.0 KB

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