|
@@ -10,68 +10,49 @@
|
|
|
#include "shell/common/gin_converters/file_path_converter.h"
|
|
|
#include "shell/common/gin_helper/dictionary.h"
|
|
|
#include "shell/common/node_includes.h"
|
|
|
+#include "third_party/abseil-cpp/absl/strings/ascii.h"
|
|
|
|
|
|
namespace {
|
|
|
+bool HasSwitch(const std::string& switch) {
|
|
|
+ auto switch_string = base::ToLowerASCII(switch_string);
|
|
|
|
|
|
-// Chromium will hard CHECK if the switch name is not lowercase.
|
|
|
-bool IsSwitchNameValid(std::string_view switch_name) {
|
|
|
- return base::ToLowerASCII(switch_name) == switch_name;
|
|
|
-}
|
|
|
-
|
|
|
-bool HasSwitch(gin_helper::ErrorThrower thrower,
|
|
|
- const std::string& switch_string) {
|
|
|
- if (!IsSwitchNameValid(switch_string)) {
|
|
|
- thrower.ThrowError("Switch name must be lowercase");
|
|
|
- return false;
|
|
|
- }
|
|
|
-
|
|
|
- return base::CommandLine::ForCurrentProcess()->HasSwitch(switch_string);
|
|
|
+ auto* command_line = base::CommandLine::ForCurrentProcess();
|
|
|
+ return command_line->HasSwitch(switch_string);
|
|
|
}
|
|
|
|
|
|
base::CommandLine::StringType GetSwitchValue(gin_helper::ErrorThrower thrower,
|
|
|
const std::string& switch_string) {
|
|
|
- if (!IsSwitchNameValid(switch_string)) {
|
|
|
- thrower.ThrowError("Switch name must be lowercase");
|
|
|
- return base::CommandLine::StringType();
|
|
|
- }
|
|
|
+ auto switch_str = base::ToLowerASCII(switch_string);
|
|
|
|
|
|
- return base::CommandLine::ForCurrentProcess()->GetSwitchValueNative(
|
|
|
- switch_string);
|
|
|
+ auto* command_line = base::CommandLine::ForCurrentProcess();
|
|
|
+ return command_line->GetSwitchValueNative(switch_str);
|
|
|
}
|
|
|
|
|
|
void AppendSwitch(const std::string& switch_string,
|
|
|
gin_helper::Arguments* args) {
|
|
|
- if (!IsSwitchNameValid(switch_string)) {
|
|
|
- args->ThrowError("Switch name must be lowercase");
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
+ auto switch_str = base::ToLowerASCII(switch_string);
|
|
|
auto* command_line = base::CommandLine::ForCurrentProcess();
|
|
|
if (base::EndsWith(switch_string, "-path",
|
|
|
base::CompareCase::INSENSITIVE_ASCII) ||
|
|
|
switch_string == network::switches::kLogNetLog) {
|
|
|
base::FilePath path;
|
|
|
args->GetNext(&path);
|
|
|
- command_line->AppendSwitchPath(switch_string, path);
|
|
|
+ command_line->AppendSwitchPath(switch_str, path);
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
base::CommandLine::StringType value;
|
|
|
if (args->GetNext(&value))
|
|
|
- command_line->AppendSwitchNative(switch_string, value);
|
|
|
+ command_line->AppendSwitchNative(switch_str, value);
|
|
|
else
|
|
|
- command_line->AppendSwitch(switch_string);
|
|
|
+ command_line->AppendSwitch(switch_str);
|
|
|
}
|
|
|
|
|
|
-void RemoveSwitch(gin_helper::ErrorThrower thrower,
|
|
|
- const std::string& switch_string) {
|
|
|
- if (!IsSwitchNameValid(switch_string)) {
|
|
|
- thrower.ThrowError("Switch name must be lowercase");
|
|
|
- return;
|
|
|
- }
|
|
|
+void RemoveSwitch(const std::string& switch_string) {
|
|
|
+ auto switch_str = base::ToLowerASCII(switch_string);
|
|
|
|
|
|
auto* command_line = base::CommandLine::ForCurrentProcess();
|
|
|
- command_line->RemoveSwitch(switch_string);
|
|
|
+ command_line->RemoveSwitch(switch_str);
|
|
|
}
|
|
|
|
|
|
void AppendArg(const std::string& arg) {
|