Bug 1933479 - Add tab close button on hover to vertical tabs when sidebar is collapse...
[gecko.git] / toolkit / xre / GeckoArgs.h
blob5bb83ad51cfc4265957f2bedf6e3d58da4cdde89
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 #ifndef mozilla_GeckoArgs_h
6 #define mozilla_GeckoArgs_h
8 #include "mozilla/CmdLineAndEnvUtils.h"
9 #include "mozilla/Maybe.h"
10 #include "mozilla/UniquePtrExtensions.h"
11 #include "mozilla/ipc/SharedMemory.h"
13 #include <array>
14 #include <cctype>
15 #include <climits>
16 #include <string>
17 #include <vector>
19 namespace mozilla {
21 namespace geckoargs {
23 // Type used for passing arguments to a content process, including OS files.
24 struct ChildProcessArgs {
25 std::vector<std::string> mArgs;
26 std::vector<UniqueFileHandle> mFiles;
27 #ifdef XP_DARWIN
28 std::vector<UniqueMachSendRight> mSendRights;
29 #endif
32 #ifdef XP_UNIX
33 // On some unix platforms, file handles are passed down without using a fixed
34 // file descriptor. This method can be used to override the default mapping.
35 void SetPassedFileHandles(Span<int> aFiles);
36 void SetPassedFileHandles(std::vector<UniqueFileHandle>&& aFiles);
38 // Add the file handles from a ChildProcessArgs to a fdsToRemap table.
39 void AddToFdsToRemap(const ChildProcessArgs& aArgs,
40 std::vector<std::pair<int, int>>& aFdsToRemap);
41 #endif
43 #ifdef XP_DARWIN
44 // Size of the internal static array of mach send rights. This acts as a limit
45 // to the number of mach send rights which can be passed on the command line.
46 constexpr size_t kMaxPassedMachSendRights = 10;
48 // Fill the internal static array with the mach send rights which were passed
49 // from the parent process.
50 void SetPassedMachSendRights(std::vector<UniqueMachSendRight>&& aSendRights);
51 #endif
53 template <typename T>
54 struct CommandLineArg {
55 Maybe<T> Get(int& aArgc, char** aArgv,
56 const CheckArgFlag aFlags = CheckArgFlag::RemoveArg) {
57 return GetCommon(sMatch, aArgc, aArgv, aFlags);
59 static Maybe<T> GetCommon(const char* aMatch, int& aArgc, char** aArgv,
60 const CheckArgFlag aFlags);
62 const char* Name() { return sName; };
64 void Put(T aValue, ChildProcessArgs& aArgs) {
65 return PutCommon(sName, std::move(aValue), aArgs);
67 static void PutCommon(const char* aName, T aValue, ChildProcessArgs& aArgs);
69 const char* sName;
70 const char* sMatch;
73 /// Get()
75 template <>
76 inline Maybe<const char*> CommandLineArg<const char*>::GetCommon(
77 const char* aMatch, int& aArgc, char** aArgv, const CheckArgFlag aFlags) {
78 MOZ_ASSERT(aArgv, "aArgv must be initialized before CheckArg()");
79 const char* rv = nullptr;
80 if (ARG_FOUND == CheckArg(aArgc, aArgv, aMatch, &rv, aFlags)) {
81 return Some(rv);
83 return Nothing();
86 template <>
87 inline Maybe<bool> CommandLineArg<bool>::GetCommon(const char* aMatch,
88 int& aArgc, char** aArgv,
89 const CheckArgFlag aFlags) {
90 MOZ_ASSERT(aArgv, "aArgv must be initialized before CheckArg()");
91 if (ARG_FOUND ==
92 CheckArg(aArgc, aArgv, aMatch, (const char**)nullptr, aFlags)) {
93 return Some(true);
95 return Nothing();
98 template <>
99 inline Maybe<uint64_t> CommandLineArg<uint64_t>::GetCommon(
100 const char* aMatch, int& aArgc, char** aArgv, const CheckArgFlag aFlags) {
101 if (Maybe<const char*> arg = CommandLineArg<const char*>::GetCommon(
102 aMatch, aArgc, aArgv, aFlags)) {
103 errno = 0;
104 char* endptr = nullptr;
105 uint64_t conv = std::strtoull(*arg, &endptr, 10);
106 if (errno == 0 && endptr && *endptr == '\0') {
107 return Some(conv);
110 return Nothing();
113 template <>
114 inline Maybe<uint32_t> CommandLineArg<uint32_t>::GetCommon(
115 const char* aMatch, int& aArgc, char** aArgv, const CheckArgFlag aFlags) {
116 return CommandLineArg<uint64_t>::GetCommon(aMatch, aArgc, aArgv, aFlags);
119 template <>
120 Maybe<UniqueFileHandle> CommandLineArg<UniqueFileHandle>::GetCommon(
121 const char* aMatch, int& aArgc, char** aArgv, const CheckArgFlag aFlags);
123 #ifdef XP_DARWIN
124 template <>
125 Maybe<UniqueMachSendRight> CommandLineArg<UniqueMachSendRight>::GetCommon(
126 const char* aMatch, int& aArgc, char** aArgv, const CheckArgFlag aFlags);
127 #endif
129 /// Put()
131 template <>
132 inline void CommandLineArg<const char*>::PutCommon(const char* aName,
133 const char* aValue,
134 ChildProcessArgs& aArgs) {
135 aArgs.mArgs.push_back(aName);
136 aArgs.mArgs.push_back(aValue);
139 template <>
140 inline void CommandLineArg<bool>::PutCommon(const char* aName, bool aValue,
141 ChildProcessArgs& aArgs) {
142 if (aValue) {
143 aArgs.mArgs.push_back(aName);
147 template <>
148 inline void CommandLineArg<uint64_t>::PutCommon(const char* aName,
149 uint64_t aValue,
150 ChildProcessArgs& aArgs) {
151 aArgs.mArgs.push_back(aName);
152 aArgs.mArgs.push_back(std::to_string(aValue));
155 template <>
156 inline void CommandLineArg<uint32_t>::PutCommon(const char* aName,
157 uint32_t aValue,
158 ChildProcessArgs& aArgs) {
159 CommandLineArg<uint64_t>::PutCommon(aName, aValue, aArgs);
162 template <>
163 void CommandLineArg<UniqueFileHandle>::PutCommon(const char* aName,
164 UniqueFileHandle aValue,
165 ChildProcessArgs& aArgs);
167 #ifdef XP_DARWIN
168 template <>
169 void CommandLineArg<UniqueMachSendRight>::PutCommon(const char* aName,
170 UniqueMachSendRight aValue,
171 ChildProcessArgs& aArgs);
172 #endif
174 #if defined(__GNUC__)
175 # pragma GCC diagnostic push
176 # pragma GCC diagnostic ignored "-Wunused-variable"
177 #endif
179 static CommandLineArg<uint64_t> sParentPid{"-parentPid", "parentpid"};
180 static CommandLineArg<const char*> sInitialChannelID{"-initialChannelId",
181 "initialchannelid"};
182 static CommandLineArg<const char*> sParentBuildID{"-parentBuildID",
183 "parentbuildid"};
184 static CommandLineArg<const char*> sAppDir{"-appDir", "appdir"};
185 static CommandLineArg<const char*> sGREOmni{"-greomni", "greomni"};
186 static CommandLineArg<const char*> sAppOmni{"-appomni", "appomni"};
187 static CommandLineArg<const char*> sProfile{"-profile", "profile"};
189 static CommandLineArg<UniqueFileHandle> sIPCHandle{"-ipcHandle", "ipchandle"};
191 static CommandLineArg<mozilla::ipc::SharedMemoryHandle> sJsInitHandle{
192 "-jsInitHandle", "jsinithandle"};
193 static CommandLineArg<uint64_t> sJsInitLen{"-jsInitLen", "jsinitlen"};
194 static CommandLineArg<mozilla::ipc::SharedMemoryHandle> sPrefsHandle{
195 "-prefsHandle", "prefshandle"};
196 static CommandLineArg<uint64_t> sPrefsLen{"-prefsLen", "prefslen"};
197 static CommandLineArg<mozilla::ipc::SharedMemoryHandle> sPrefMapHandle{
198 "-prefMapHandle", "prefmaphandle"};
199 static CommandLineArg<uint64_t> sPrefMapSize{"-prefMapSize", "prefmapsize"};
201 static CommandLineArg<uint64_t> sSandboxingKind{"-sandboxingKind",
202 "sandboxingkind"};
204 static CommandLineArg<bool> sSafeMode{"-safeMode", "safemode"};
206 static CommandLineArg<bool> sIsForBrowser{"-isForBrowser", "isforbrowser"};
207 static CommandLineArg<bool> sNotForBrowser{"-notForBrowser", "notforbrowser"};
209 static CommandLineArg<const char*> sPluginPath{"-pluginPath", "pluginpath"};
210 static CommandLineArg<bool> sPluginNativeEvent{"-pluginNativeEvent",
211 "pluginnativeevent"};
213 #if defined(XP_WIN) || defined(MOZ_WIDGET_COCOA)
214 static CommandLineArg<const char*> sCrashReporter{"-crashReporter",
215 "crashreporter"};
216 #elif defined(XP_UNIX)
217 static CommandLineArg<UniqueFileHandle> sCrashReporter{"-crashReporter",
218 "crashreporter"};
219 #endif
221 #if defined(XP_WIN)
222 # if defined(MOZ_SANDBOX)
223 static CommandLineArg<bool> sWin32kLockedDown{"-win32kLockedDown",
224 "win32klockeddown"};
225 # endif // defined(MOZ_SANDBOX)
226 static CommandLineArg<bool> sDisableDynamicDllBlocklist{
227 "-disableDynamicBlocklist", "disabledynamicblocklist"};
228 #endif // defined(XP_WIN)
230 #if defined(XP_LINUX) && defined(MOZ_SANDBOX)
231 static CommandLineArg<UniqueFileHandle> sSandboxReporter{"-sandboxReporter",
232 "sandboxreporter"};
233 static CommandLineArg<UniqueFileHandle> sChrootClient{"-chrootClient",
234 "chrootclient"};
235 #endif
237 #if defined(__GNUC__)
238 # pragma GCC diagnostic pop
239 #endif
241 } // namespace geckoargs
243 } // namespace mozilla
245 #endif // mozilla_GeckoArgs_h