electron_command_line.cc 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. // Copyright (c) 2013 GitHub, Inc.
  2. // Use of this source code is governed by the MIT license that can be
  3. // found in the LICENSE file.
  4. #include "shell/common/electron_command_line.h"
  5. #include "base/command_line.h"
  6. #include "base/containers/to_vector.h"
  7. #include "base/strings/utf_string_conversions.h"
  8. namespace electron {
  9. // static
  10. base::CommandLine::StringVector ElectronCommandLine::argv_;
  11. // static
  12. void ElectronCommandLine::Init(int argc,
  13. base::CommandLine::CharType const* const* argv) {
  14. DCHECK(argv_.empty());
  15. // Safety: as is normal in command lines, argc and argv must correspond
  16. // to one another. Otherwise there will be out-of-bounds accesses.
  17. argv_.assign(argv, UNSAFE_BUFFERS(argv + argc));
  18. }
  19. // static
  20. std::vector<std::string> ElectronCommandLine::AsUtf8() {
  21. DCHECK(!argv_.empty());
  22. #if BUILDFLAG(IS_WIN)
  23. return base::ToVector(
  24. argv_, [](const auto& wstr) { return base::WideToUTF8(wstr); });
  25. #else
  26. return argv_;
  27. #endif
  28. }
  29. #if BUILDFLAG(IS_LINUX)
  30. // static
  31. void ElectronCommandLine::InitializeFromCommandLine() {
  32. argv_ = base::CommandLine::ForCurrentProcess()->argv();
  33. }
  34. #endif
  35. } // namespace electron