2015-03-17 18:25:53 +05:30
|
|
|
// Copyright (c) 2013 GitHub, Inc.
|
|
|
|
// Use of this source code is governed by the MIT license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2020-02-04 12:19:40 -08:00
|
|
|
#include "shell/common/electron_command_line.h"
|
2015-06-19 22:56:10 +08:00
|
|
|
|
|
|
|
#include "base/command_line.h"
|
2024-10-29 07:23:08 -05:00
|
|
|
#include "base/containers/to_vector.h"
|
|
|
|
#include "base/strings/utf_string_conversions.h"
|
2015-03-17 18:25:53 +05:30
|
|
|
|
2019-06-19 14:23:04 -07:00
|
|
|
namespace electron {
|
2015-03-17 18:25:53 +05:30
|
|
|
|
2015-03-29 19:59:16 +08:00
|
|
|
// static
|
2020-02-04 12:19:40 -08:00
|
|
|
base::CommandLine::StringVector ElectronCommandLine::argv_;
|
2015-03-29 19:53:47 +08:00
|
|
|
|
2016-06-02 19:49:36 +09:00
|
|
|
// static
|
2024-10-29 07:23:08 -05:00
|
|
|
void ElectronCommandLine::Init(int argc,
|
|
|
|
base::CommandLine::CharType const* const* argv) {
|
2018-01-22 16:49:30 -06:00
|
|
|
DCHECK(argv_.empty());
|
2016-06-02 19:49:36 +09:00
|
|
|
|
2024-10-29 07:23:08 -05:00
|
|
|
// Safety: as is normal in command lines, argc and argv must correspond
|
|
|
|
// to one another. Otherwise there will be out-of-bounds accesses.
|
|
|
|
argv_.assign(argv, UNSAFE_BUFFERS(argv + argc));
|
|
|
|
}
|
2015-03-17 18:25:53 +05:30
|
|
|
|
2024-10-29 07:23:08 -05:00
|
|
|
// static
|
|
|
|
std::vector<std::string> ElectronCommandLine::AsUtf8() {
|
|
|
|
DCHECK(!argv_.empty());
|
|
|
|
|
|
|
|
#if BUILDFLAG(IS_WIN)
|
|
|
|
return base::ToVector(
|
|
|
|
argv_, [](const auto& wstr) { return base::WideToUTF8(wstr); });
|
|
|
|
#else
|
|
|
|
return argv_;
|
|
|
|
#endif
|
2016-06-02 19:49:36 +09:00
|
|
|
}
|
|
|
|
|
2022-02-09 18:58:52 -08:00
|
|
|
#if BUILDFLAG(IS_LINUX)
|
2015-06-19 22:56:10 +08:00
|
|
|
// static
|
2020-02-04 12:19:40 -08:00
|
|
|
void ElectronCommandLine::InitializeFromCommandLine() {
|
2015-06-19 22:56:10 +08:00
|
|
|
argv_ = base::CommandLine::ForCurrentProcess()->argv();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2019-06-19 14:23:04 -07:00
|
|
|
} // namespace electron
|