From 086ddd481dcd6d9518def4b117586a896ab8411e Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Sun, 26 May 2024 11:12:49 -0400 Subject: [PATCH] Ladybird+LibWeb: Move User-Agent definitions to their own file This is to avoid including any LibProtocol header in Objective-C source files, which will cause a conflict between the Protocol namespace and a @Protocol interface. See Ladybird/AppKit/Application/ApplicationBridge.cpp for why this conflict unfortunately cannot be worked around. --- Ladybird/AppKit/UI/TabController.mm | 4 +- Ladybird/Qt/BrowserWindow.cpp | 2 +- .../Applications/Browser/BrowserWindow.cpp | 2 +- .../LibWeb/Loader/GeneratedPagesLoader.cpp | 2 +- .../LibWeb/Loader/ResourceLoader.cpp | 1 + .../Libraries/LibWeb/Loader/ResourceLoader.h | 48 -------------- Userland/Libraries/LibWeb/Loader/UserAgent.h | 62 +++++++++++++++++++ .../LibWeb/WebDriver/Capabilities.cpp | 2 +- 8 files changed, 69 insertions(+), 54 deletions(-) create mode 100644 Userland/Libraries/LibWeb/Loader/UserAgent.h diff --git a/Ladybird/AppKit/UI/TabController.mm b/Ladybird/AppKit/UI/TabController.mm index 9056cfa8821..93eb93a0c00 100644 --- a/Ladybird/AppKit/UI/TabController.mm +++ b/Ladybird/AppKit/UI/TabController.mm @@ -4,12 +4,12 @@ * SPDX-License-Identifier: BSD-2-Clause */ +#include #include #include +#include #import -#import -#import #import #import #import diff --git a/Ladybird/Qt/BrowserWindow.cpp b/Ladybird/Qt/BrowserWindow.cpp index 630589b4332..d5084a69f87 100644 --- a/Ladybird/Qt/BrowserWindow.cpp +++ b/Ladybird/Qt/BrowserWindow.cpp @@ -19,7 +19,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/Userland/Applications/Browser/BrowserWindow.cpp b/Userland/Applications/Browser/BrowserWindow.cpp index 3c561ac0967..6f18c0fb996 100644 --- a/Userland/Applications/Browser/BrowserWindow.cpp +++ b/Userland/Applications/Browser/BrowserWindow.cpp @@ -35,7 +35,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/Userland/Libraries/LibWeb/Loader/GeneratedPagesLoader.cpp b/Userland/Libraries/LibWeb/Loader/GeneratedPagesLoader.cpp index 7391fed7b1e..6cd5a1b11b5 100644 --- a/Userland/Libraries/LibWeb/Loader/GeneratedPagesLoader.cpp +++ b/Userland/Libraries/LibWeb/Loader/GeneratedPagesLoader.cpp @@ -12,7 +12,7 @@ #include #include #include -#include +#include namespace Web { diff --git a/Userland/Libraries/LibWeb/Loader/ResourceLoader.cpp b/Userland/Libraries/LibWeb/Loader/ResourceLoader.cpp index d0addca4c60..696eff6c76a 100644 --- a/Userland/Libraries/LibWeb/Loader/ResourceLoader.cpp +++ b/Userland/Libraries/LibWeb/Loader/ResourceLoader.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include #include diff --git a/Userland/Libraries/LibWeb/Loader/ResourceLoader.h b/Userland/Libraries/LibWeb/Loader/ResourceLoader.h index 47c8a2c1012..88b0746a326 100644 --- a/Userland/Libraries/LibWeb/Loader/ResourceLoader.h +++ b/Userland/Libraries/LibWeb/Loader/ResourceLoader.h @@ -19,54 +19,6 @@ 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" -#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" -#define BROWSER_VERSION "1.0" - -constexpr auto default_user_agent = "Mozilla/5.0 (" OS_STRING "; " CPU_STRING ") " BROWSER_NAME "/" BROWSER_VERSION ""sv; -constexpr auto default_platform = OS_STRING " " CPU_STRING ""sv; - namespace WebSockets { class WebSocketClientSocket; } diff --git a/Userland/Libraries/LibWeb/Loader/UserAgent.h b/Userland/Libraries/LibWeb/Loader/UserAgent.h new file mode 100644 index 00000000000..ad75fd8928f --- /dev/null +++ b/Userland/Libraries/LibWeb/Loader/UserAgent.h @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2024, Tim Flynn + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include +#include + +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" +#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" +#define BROWSER_VERSION "1.0" + +constexpr auto default_user_agent = "Mozilla/5.0 (" OS_STRING "; " CPU_STRING ") " BROWSER_NAME "/" BROWSER_VERSION ""sv; +constexpr auto default_platform = OS_STRING " " CPU_STRING ""sv; + +} diff --git a/Userland/Libraries/LibWeb/WebDriver/Capabilities.cpp b/Userland/Libraries/LibWeb/WebDriver/Capabilities.cpp index c1bdf83cb5b..d0d19c22a14 100644 --- a/Userland/Libraries/LibWeb/WebDriver/Capabilities.cpp +++ b/Userland/Libraries/LibWeb/WebDriver/Capabilities.cpp @@ -9,7 +9,7 @@ #include #include #include -#include +#include #include #include