From 6bf0a5cb5034a7e684dcc3500e841785237ce2dd Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 19:32:43 +0200 Subject: Adding upstream version 1:115.7.0. Signed-off-by: Daniel Baumann --- toolkit/xre/GeckoArgs.h | 149 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 149 insertions(+) create mode 100644 toolkit/xre/GeckoArgs.h (limited to 'toolkit/xre/GeckoArgs.h') diff --git a/toolkit/xre/GeckoArgs.h b/toolkit/xre/GeckoArgs.h new file mode 100644 index 0000000000..667ddb4ba4 --- /dev/null +++ b/toolkit/xre/GeckoArgs.h @@ -0,0 +1,149 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef mozilla_GeckoArgs_h +#define mozilla_GeckoArgs_h + +#include "mozilla/CmdLineAndEnvUtils.h" +#include "mozilla/Maybe.h" + +#include +#include +#include +#include +#include + +namespace mozilla { + +namespace geckoargs { + +template +struct CommandLineArg { + Maybe Get(int& aArgc, char** aArgv, + const CheckArgFlag aFlags = CheckArgFlag::RemoveArg); + + const char* Name() { return sName; }; + + void Put(std::vector& aArgs); + void Put(T aValue, std::vector& aArgs); + + const char* sName; + const char* sMatch; +}; + +/// Get() + +template <> +inline Maybe CommandLineArg::Get( + int& aArgc, char** aArgv, const CheckArgFlag aFlags) { + MOZ_ASSERT(aArgv, "aArgv must be initialized before CheckArg()"); + const char* rv = nullptr; + if (ARG_FOUND == CheckArg(aArgc, aArgv, sMatch, &rv, aFlags)) { + return Some(rv); + } + return Nothing(); +} + +template <> +inline Maybe CommandLineArg::Get(int& aArgc, char** aArgv, + const CheckArgFlag aFlags) { + MOZ_ASSERT(aArgv, "aArgv must be initialized before CheckArg()"); + if (ARG_FOUND == + CheckArg(aArgc, aArgv, sMatch, (const char**)nullptr, aFlags)) { + return Some(true); + } + return Nothing(); +} + +template <> +inline Maybe CommandLineArg::Get( + int& aArgc, char** aArgv, const CheckArgFlag aFlags) { + MOZ_ASSERT(aArgv, "aArgv must be initialized before CheckArg()"); + const char* rv = nullptr; + if (ARG_FOUND == CheckArg(aArgc, aArgv, sMatch, &rv, aFlags)) { + errno = 0; + char* endptr = nullptr; + uint64_t conv = std::strtoull(rv, &endptr, 10); + if (errno == 0 && endptr && *endptr == '\0') { + return Some(conv); + } + } + return Nothing(); +} + +/// Put() + +template <> +inline void CommandLineArg::Put(const char* aValue, + std::vector& aArgs) { + aArgs.push_back(Name()); + aArgs.push_back(aValue); +} + +template <> +inline void CommandLineArg::Put(bool aValue, + std::vector& aArgs) { + if (aValue) { + aArgs.push_back(Name()); + } +} + +template <> +inline void CommandLineArg::Put(std::vector& aArgs) { + Put(true, aArgs); +} + +template <> +inline void CommandLineArg::Put(uint64_t aValue, + std::vector& aArgs) { + aArgs.push_back(Name()); + aArgs.push_back(std::to_string(aValue)); +} + +#if defined(__GNUC__) +# pragma GCC diagnostic push +# pragma GCC diagnostic ignored "-Wunused-variable" +#endif + +static CommandLineArg sParentBuildID{"-parentBuildID", + "parentbuildid"}; +static CommandLineArg sAppDir{"-appDir", "appdir"}; +static CommandLineArg sProfile{"-profile", "profile"}; + +static CommandLineArg sJsInitHandle{"-jsInitHandle", "jsinithandle"}; +static CommandLineArg sJsInitLen{"-jsInitLen", "jsinitlen"}; +static CommandLineArg sPrefsHandle{"-prefsHandle", "prefshandle"}; +static CommandLineArg sPrefsLen{"-prefsLen", "prefslen"}; +static CommandLineArg sPrefMapHandle{"-prefMapHandle", + "prefmaphandle"}; +static CommandLineArg sPrefMapSize{"-prefMapSize", "prefmapsize"}; + +static CommandLineArg sChildID{"-childID", "childid"}; + +static CommandLineArg sSandboxingKind{"-sandboxingKind", + "sandboxingkind"}; + +static CommandLineArg sSafeMode{"-safeMode", "safemode"}; + +static CommandLineArg sIsForBrowser{"-isForBrowser", "isforbrowser"}; +static CommandLineArg sNotForBrowser{"-notForBrowser", "notforbrowser"}; + +#if defined(XP_WIN) +# if defined(MOZ_SANDBOX) +static CommandLineArg sWin32kLockedDown{"-win32kLockedDown", + "win32klockeddown"}; +# endif // defined(MOZ_SANDBOX) +static CommandLineArg sDisableDynamicDllBlocklist{ + "-disableDynamicBlocklist", "disabledynamicblocklist"}; +#endif // defined(XP_WIN) + +#if defined(__GNUC__) +# pragma GCC diagnostic pop +#endif + +} // namespace geckoargs + +} // namespace mozilla + +#endif // mozilla_GeckoArgs_h -- cgit v1.2.3