process_util.cc 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // Copyright (c) 2019 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/process_util.h"
  5. #include "base/command_line.h"
  6. #include "content/public/common/content_switches.h"
  7. #include "gin/dictionary.h"
  8. #include "shell/common/gin_converters/callback_converter.h"
  9. #include "shell/common/node_includes.h"
  10. namespace electron {
  11. void EmitWarning(node::Environment* env,
  12. const std::string& warning_msg,
  13. const std::string& warning_type) {
  14. v8::HandleScope scope(env->isolate());
  15. gin::Dictionary process(env->isolate(), env->process_object());
  16. base::RepeatingCallback<void(base::StringPiece, base::StringPiece,
  17. base::StringPiece)>
  18. emit_warning;
  19. process.Get("emitWarning", &emit_warning);
  20. emit_warning.Run(warning_msg, warning_type, "");
  21. }
  22. bool IsBrowserProcess() {
  23. auto* command_line = base::CommandLine::ForCurrentProcess();
  24. std::string process_type =
  25. command_line->GetSwitchValueASCII(switches::kProcessType);
  26. return process_type.empty();
  27. }
  28. bool IsRendererProcess() {
  29. auto* command_line = base::CommandLine::ForCurrentProcess();
  30. std::string process_type =
  31. command_line->GetSwitchValueASCII(switches::kProcessType);
  32. return process_type == switches::kRendererProcess;
  33. }
  34. } // namespace electron