command_line_args.cc 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. // Copyright (c) 2018 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/app/command_line_args.h"
  5. #include <locale>
  6. #include "sandbox/policy/switches.h"
  7. #include "shell/common/options_switches.h"
  8. namespace {
  9. bool IsUrlArg(const base::CommandLine::CharType* arg) {
  10. // the first character must be a letter for this to be a URL
  11. auto c = *arg;
  12. if (std::isalpha(c, std::locale::classic())) {
  13. for (auto* p = arg + 1; *p; ++p) {
  14. c = *p;
  15. // colon indicates that the argument starts with a URI scheme
  16. if (c == ':') {
  17. // it could also be a Windows filesystem path
  18. if (p == arg + 1)
  19. break;
  20. return true;
  21. }
  22. // white-space before a colon means it's not a URL
  23. if (std::isspace(c, std::locale::classic()))
  24. break;
  25. }
  26. }
  27. return false;
  28. }
  29. } // namespace
  30. namespace electron {
  31. bool CheckCommandLineArguments(int argc, base::CommandLine::CharType** argv) {
  32. const base::CommandLine::StringType dashdash(2, '-');
  33. bool block_args = false;
  34. for (int i = 0; i < argc; ++i) {
  35. if (argv[i] == dashdash)
  36. break;
  37. if (block_args) {
  38. return false;
  39. } else if (IsUrlArg(argv[i])) {
  40. block_args = true;
  41. }
  42. }
  43. return true;
  44. }
  45. bool IsSandboxEnabled(base::CommandLine* command_line) {
  46. return command_line->HasSwitch(switches::kEnableSandbox) ||
  47. !command_line->HasSwitch(sandbox::policy::switches::kNoSandbox);
  48. }
  49. } // namespace electron