Truly independent web browser
/*
* Copyright (c) 2024, Tim Flynn <[email protected]>
* Copyright (c) 2024, Jamie Mansfield <[email protected]>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/Platform.h>
#include <AK/String.h>
#include <AK/StringView.h>
#include <AK/Vector.h>
#include <LibCore/BrowserVersion.h>
#include <LibWebCommon/Loader/NavigatorCompatibilityMode.h>
namespace Web {
#if ARCH(X86_64)
# define CPU_STRING "x86_64"
#elif ARCH(AARCH64)
# define CPU_STRING "AArch64"
#elif ARCH(I386)
# define CPU_STRING "x86"
#elif ARCH(RISCV64)
# define CPU_STRING "RISC-V 64"
#elif ARCH(PPC64) || ARCH(PPC64LE)
# define CPU_STRING "PowerPC 64"
#elif ARCH(PPC)
# define CPU_STRING "PowerPC"
#else
# error Unknown architecture
#endif
#if defined(AK_OS_SERENITY)
# define OS_STRING "SerenityOS"
#elif defined(AK_OS_ANDROID)
# define OS_STRING "Android 10"
#elif defined(AK_OS_LINUX)
# define OS_STRING "Linux"
#elif defined(AK_OS_MACOS)
# define OS_STRING "macOS"
#elif defined(AK_OS_IOS)
# define OS_STRING "iOS"
#elif defined(AK_OS_WINDOWS)
# define OS_STRING "Windows"
#elif defined(AK_OS_FREEBSD)
# define OS_STRING "FreeBSD"
#elif defined(AK_OS_OPENBSD)
# define OS_STRING "OpenBSD"
#elif defined(AK_OS_NETBSD)
# define OS_STRING "NetBSD"
#elif defined(AK_OS_DRAGONFLY)
# define OS_STRING "DragonFly"
#elif defined(AK_OS_SOLARIS)
# define OS_STRING "SunOS"
#elif defined(AK_OS_HAIKU)
# define OS_STRING "Haiku"
#elif defined(AK_OS_GNU_HURD)
# define OS_STRING "GNU/Hurd"
#else
# error Unknown OS
#endif
#define BROWSER_NAME "Ladybird"
// NB: Some web servers treat us very badly unless we pretend to be one of the major browsers.
// This token is appended to the User-Agent string to improve compatibility.
// We will need to update this periodically to match a somewhat recent version.
#define SAD_COMPATIBILITY_HACK "AppleWebKit/537.36 (KHTML, like Gecko) Chrome/153.0.0.0 Safari/537.36"
// NB: Servers sniff the parenthesized platform token of the User-Agent string and only recognize
// the frozen tokens sent by major browsers. Reporting the actual OS and CPU here gets us
// served degraded or broken content (e.g. the Instagram login page), so the platform token is
// frozen per OS and decoupled from the real platform.
#if defined(AK_OS_MACOS)
# define UA_PLATFORM_STRING "Macintosh; Intel Mac OS X 10_15_7"
#elif defined(AK_OS_IOS)
# define UA_PLATFORM_STRING "iPhone; CPU iPhone OS 27_2 like Mac OS X"
#elif defined(AK_OS_ANDROID)
# define UA_PLATFORM_STRING "Linux; Android 10; K"
#elif defined(AK_OS_WINDOWS)
# define UA_PLATFORM_STRING "Windows NT 10.0; Win64; x64"
#else
# define UA_PLATFORM_STRING "X11; Linux x86_64"
#endif
constexpr auto default_user_agent = "Mozilla/5.0 (" UA_PLATFORM_STRING ") " BROWSER_NAME "/" BROWSER_VERSION " " SAD_COMPATIBILITY_HACK ""sv;
// https://html.spec.whatwg.org/multipage/system-state.html#dom-navigator-platform
// "Must return either the empty string or a string representing the platform on which the browser is executing, e.g.
// "MacIntel", "Win32", "Linux x86_64", "Linux armv81"."
// Browsers on macOS report MacIntel whatever the CPU is, and browsers on Windows report Win32; elsewhere, the platform
// is what uname() reports as the system name and the machine, spelled the way the kernel spells them.
#if defined(AK_OS_MACOS)
# define NAVIGATOR_PLATFORM_STRING "MacIntel"
#elif defined(AK_OS_IOS)
# define NAVIGATOR_PLATFORM_STRING "iPhone"
#elif defined(AK_OS_WINDOWS)
# define NAVIGATOR_PLATFORM_STRING "Win32"
#else
# if defined(AK_OS_ANDROID) || defined(AK_OS_LINUX)
# define NAVIGATOR_PLATFORM_SYSTEM_NAME "Linux"
# else
# define NAVIGATOR_PLATFORM_SYSTEM_NAME OS_STRING
# endif
# if ARCH(X86_64)
# define NAVIGATOR_PLATFORM_MACHINE "x86_64"
# elif ARCH(AARCH64)
# define NAVIGATOR_PLATFORM_MACHINE "aarch64"
# elif ARCH(I386)
# define NAVIGATOR_PLATFORM_MACHINE "i686"
# elif ARCH(RISCV64)
# define NAVIGATOR_PLATFORM_MACHINE "riscv64"
# elif ARCH(PPC64LE)
# define NAVIGATOR_PLATFORM_MACHINE "ppc64le"
# elif ARCH(PPC64)
# define NAVIGATOR_PLATFORM_MACHINE "ppc64"
# elif ARCH(PPC)
# define NAVIGATOR_PLATFORM_MACHINE "ppc"
# else
# error Unknown architecture
# endif
# define NAVIGATOR_PLATFORM_STRING NAVIGATOR_PLATFORM_SYSTEM_NAME " " NAVIGATOR_PLATFORM_MACHINE
#endif
constexpr auto default_platform = NAVIGATOR_PLATFORM_STRING ""sv;
constexpr auto default_navigator_compatibility_mode = NavigatorCompatibilityMode::Chrome;
// The languages a navigator reports, and the Accept-Language header carries, until the user's own list arrives.
inline Vector<String> default_preferred_languages()
{
return { "en-US"_string, "en"_string };
}
}