Merge mozilla-central to autoland. CLOSED TREE
[gecko.git] / toolkit / xre / GeckoArgs.h
blob4604e1910a903622c1453f1b18578feadafe92a7
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"
11 #include <array>
12 #include <cctype>
13 #include <climits>
14 #include <string>
15 #include <vector>
17 namespace mozilla {
19 namespace geckoargs {
21 template <typename T>
22 struct CommandLineArg {
23 Maybe<T> Get(int& aArgc, char** aArgv,
24 const CheckArgFlag aFlags = CheckArgFlag::RemoveArg);
26 const char* Name() { return sName; };
28 void Put(std::vector<std::string>& aArgs);
29 void Put(T aValue, std::vector<std::string>& aArgs);
31 const char* sName;
32 const char* sMatch;
35 /// Get()
37 template <>
38 inline Maybe<const char*> CommandLineArg<const char*>::Get(
39 int& aArgc, char** aArgv, const CheckArgFlag aFlags) {
40 MOZ_ASSERT(aArgv, "aArgv must be initialized before CheckArg()");
41 const char* rv = nullptr;
42 if (ARG_FOUND == CheckArg(aArgc, aArgv, sMatch, &rv, aFlags)) {
43 return Some(rv);
45 return Nothing();
48 template <>
49 inline Maybe<bool> CommandLineArg<bool>::Get(int& aArgc, char** aArgv,
50 const CheckArgFlag aFlags) {
51 MOZ_ASSERT(aArgv, "aArgv must be initialized before CheckArg()");
52 if (ARG_FOUND ==
53 CheckArg(aArgc, aArgv, sMatch, (const char**)nullptr, aFlags)) {
54 return Some(true);
56 return Nothing();
59 template <>
60 inline Maybe<uint64_t> CommandLineArg<uint64_t>::Get(
61 int& aArgc, char** aArgv, const CheckArgFlag aFlags) {
62 MOZ_ASSERT(aArgv, "aArgv must be initialized before CheckArg()");
63 const char* rv = nullptr;
64 if (ARG_FOUND == CheckArg(aArgc, aArgv, sMatch, &rv, aFlags)) {
65 errno = 0;
66 char* endptr = nullptr;
67 uint64_t conv = std::strtoull(rv, &endptr, 10);
68 if (errno == 0 && endptr && *endptr == '\0') {
69 return Some(conv);
72 return Nothing();
75 /// Put()
77 template <>
78 inline void CommandLineArg<const char*>::Put(const char* aValue,
79 std::vector<std::string>& aArgs) {
80 aArgs.push_back(Name());
81 aArgs.push_back(aValue);
84 template <>
85 inline void CommandLineArg<bool>::Put(bool aValue,
86 std::vector<std::string>& aArgs) {
87 if (aValue) {
88 aArgs.push_back(Name());
92 template <>
93 inline void CommandLineArg<bool>::Put(std::vector<std::string>& aArgs) {
94 Put(true, aArgs);
97 template <>
98 inline void CommandLineArg<uint64_t>::Put(uint64_t aValue,
99 std::vector<std::string>& aArgs) {
100 aArgs.push_back(Name());
101 aArgs.push_back(std::to_string(aValue));
104 #if defined(__GNUC__)
105 # pragma GCC diagnostic push
106 # pragma GCC diagnostic ignored "-Wunused-variable"
107 #endif
109 static CommandLineArg<const char*> sParentBuildID{"-parentBuildID",
110 "parentbuildid"};
111 static CommandLineArg<const char*> sAppDir{"-appDir", "appdir"};
112 static CommandLineArg<const char*> sGREOmni{"-greomni", "greomni"};
113 static CommandLineArg<const char*> sAppOmni{"-appomni", "appomni"};
114 static CommandLineArg<const char*> sProfile{"-profile", "profile"};
116 static CommandLineArg<uint64_t> sJsInitHandle{"-jsInitHandle", "jsinithandle"};
117 static CommandLineArg<uint64_t> sJsInitLen{"-jsInitLen", "jsinitlen"};
118 static CommandLineArg<uint64_t> sPrefsHandle{"-prefsHandle", "prefshandle"};
119 static CommandLineArg<uint64_t> sPrefsLen{"-prefsLen", "prefslen"};
120 static CommandLineArg<uint64_t> sPrefMapHandle{"-prefMapHandle",
121 "prefmaphandle"};
122 static CommandLineArg<uint64_t> sPrefMapSize{"-prefMapSize", "prefmapsize"};
124 static CommandLineArg<uint64_t> sChildID{"-childID", "childid"};
126 static CommandLineArg<uint64_t> sSandboxingKind{"-sandboxingKind",
127 "sandboxingkind"};
129 static CommandLineArg<bool> sSafeMode{"-safeMode", "safemode"};
131 static CommandLineArg<bool> sIsForBrowser{"-isForBrowser", "isforbrowser"};
132 static CommandLineArg<bool> sNotForBrowser{"-notForBrowser", "notforbrowser"};
134 static CommandLineArg<const char*> sPluginPath{"-pluginPath", "pluginpath"};
135 static CommandLineArg<bool> sPluginNativeEvent{"-pluginNativeEvent",
136 "pluginnativeevent"};
138 #if defined(XP_WIN)
139 # if defined(MOZ_SANDBOX)
140 static CommandLineArg<bool> sWin32kLockedDown{"-win32kLockedDown",
141 "win32klockeddown"};
142 # endif // defined(MOZ_SANDBOX)
143 static CommandLineArg<bool> sDisableDynamicDllBlocklist{
144 "-disableDynamicBlocklist", "disabledynamicblocklist"};
145 #endif // defined(XP_WIN)
147 #if defined(__GNUC__)
148 # pragma GCC diagnostic pop
149 #endif
151 } // namespace geckoargs
153 } // namespace mozilla
155 #endif // mozilla_GeckoArgs_h