node_bindings.cc 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594
  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/node_bindings.h"
  5. #include <algorithm>
  6. #include <memory>
  7. #include <set>
  8. #include <string>
  9. #include <unordered_set>
  10. #include <utility>
  11. #include <vector>
  12. #include "base/base_paths.h"
  13. #include "base/command_line.h"
  14. #include "base/environment.h"
  15. #include "base/path_service.h"
  16. #include "base/run_loop.h"
  17. #include "base/strings/string_split.h"
  18. #include "base/strings/utf_string_conversions.h"
  19. #include "base/threading/thread_task_runner_handle.h"
  20. #include "base/trace_event/trace_event.h"
  21. #include "content/public/browser/browser_thread.h"
  22. #include "content/public/common/content_paths.h"
  23. #include "electron/buildflags/buildflags.h"
  24. #include "shell/common/electron_command_line.h"
  25. #include "shell/common/gin_converters/file_path_converter.h"
  26. #include "shell/common/gin_helper/dictionary.h"
  27. #include "shell/common/gin_helper/event_emitter_caller.h"
  28. #include "shell/common/gin_helper/locker.h"
  29. #include "shell/common/gin_helper/microtasks_scope.h"
  30. #include "shell/common/mac/main_application_bundle.h"
  31. #include "shell/common/node_includes.h"
  32. #include "third_party/blink/renderer/bindings/core/v8/v8_initializer.h" // nogncheck
  33. #define ELECTRON_BUILTIN_MODULES(V) \
  34. V(electron_browser_app) \
  35. V(electron_browser_auto_updater) \
  36. V(electron_browser_browser_view) \
  37. V(electron_browser_content_tracing) \
  38. V(electron_browser_crash_reporter) \
  39. V(electron_browser_dialog) \
  40. V(electron_browser_event) \
  41. V(electron_browser_event_emitter) \
  42. V(electron_browser_global_shortcut) \
  43. V(electron_browser_in_app_purchase) \
  44. V(electron_browser_menu) \
  45. V(electron_browser_message_port) \
  46. V(electron_browser_net) \
  47. V(electron_browser_power_monitor) \
  48. V(electron_browser_power_save_blocker) \
  49. V(electron_browser_protocol) \
  50. V(electron_browser_session) \
  51. V(electron_browser_system_preferences) \
  52. V(electron_browser_top_level_window) \
  53. V(electron_browser_tray) \
  54. V(electron_browser_view) \
  55. V(electron_browser_web_contents) \
  56. V(electron_browser_web_contents_view) \
  57. V(electron_browser_web_view_manager) \
  58. V(electron_browser_window) \
  59. V(electron_common_asar) \
  60. V(electron_common_clipboard) \
  61. V(electron_common_command_line) \
  62. V(electron_common_features) \
  63. V(electron_common_native_image) \
  64. V(electron_common_native_theme) \
  65. V(electron_common_notification) \
  66. V(electron_common_screen) \
  67. V(electron_common_shell) \
  68. V(electron_common_v8_util) \
  69. V(electron_renderer_context_bridge) \
  70. V(electron_renderer_crash_reporter) \
  71. V(electron_renderer_ipc) \
  72. V(electron_renderer_web_frame)
  73. #define ELECTRON_VIEWS_MODULES(V) V(electron_browser_image_view)
  74. #define ELECTRON_DESKTOP_CAPTURER_MODULE(V) V(electron_browser_desktop_capturer)
  75. // This is used to load built-in modules. Instead of using
  76. // __attribute__((constructor)), we call the _register_<modname>
  77. // function for each built-in modules explicitly. This is only
  78. // forward declaration. The definitions are in each module's
  79. // implementation when calling the NODE_LINKED_MODULE_CONTEXT_AWARE.
  80. #define V(modname) void _register_##modname();
  81. ELECTRON_BUILTIN_MODULES(V)
  82. #if BUILDFLAG(ENABLE_VIEWS_API)
  83. ELECTRON_VIEWS_MODULES(V)
  84. #endif
  85. #if BUILDFLAG(ENABLE_DESKTOP_CAPTURER)
  86. ELECTRON_DESKTOP_CAPTURER_MODULE(V)
  87. #endif
  88. #undef V
  89. namespace {
  90. void stop_and_close_uv_loop(uv_loop_t* loop) {
  91. uv_stop(loop);
  92. auto const ensure_closing = [](uv_handle_t* handle, void*) {
  93. // We should be using the UvHandle wrapper everywhere, in which case
  94. // all handles should already be in a closing state...
  95. DCHECK(uv_is_closing(handle));
  96. // ...but if a raw handle got through, through, do the right thing anyway
  97. if (!uv_is_closing(handle)) {
  98. uv_close(handle, nullptr);
  99. }
  100. };
  101. uv_walk(loop, ensure_closing, nullptr);
  102. // All remaining handles are in a closing state now.
  103. // Pump the event loop so that they can finish closing.
  104. for (;;)
  105. if (uv_run(loop, UV_RUN_DEFAULT) == 0)
  106. break;
  107. DCHECK_EQ(0, uv_loop_alive(loop));
  108. }
  109. bool g_is_initialized = false;
  110. bool IsPackagedApp() {
  111. base::FilePath exe_path;
  112. base::PathService::Get(base::FILE_EXE, &exe_path);
  113. base::FilePath::StringType base_name =
  114. base::ToLowerASCII(exe_path.BaseName().value());
  115. #if defined(OS_WIN)
  116. return base_name != FILE_PATH_LITERAL("electron.exe");
  117. #else
  118. return base_name != FILE_PATH_LITERAL("electron");
  119. #endif
  120. }
  121. void ErrorMessageListener(v8::Local<v8::Message> message,
  122. v8::Local<v8::Value> data) {
  123. v8::Isolate* isolate = v8::Isolate::GetCurrent();
  124. node::Environment* env = node::Environment::GetCurrent(isolate);
  125. // TODO(codebytere): properly emit the after() hooks now
  126. // that the exception has been handled.
  127. // See node/lib/internal/process/execution.js#L176-L180
  128. // Ensure that the async id stack is properly cleared so the async
  129. // hook stack does not become corrupted.
  130. if (env) {
  131. env->async_hooks()->clear_async_id_stack();
  132. }
  133. }
  134. // Initialize Node.js cli options to pass to Node.js
  135. // See https://nodejs.org/api/cli.html#cli_options
  136. void SetNodeCliFlags() {
  137. // Only allow DebugOptions in non-ELECTRON_RUN_AS_NODE mode
  138. const std::unordered_set<base::StringPiece, base::StringPieceHash> allowed = {
  139. "--inspect", "--inspect-brk",
  140. "--inspect-port", "--debug",
  141. "--debug-brk", "--debug-port",
  142. "--inspect-brk-node", "--inspect-publish-uid",
  143. };
  144. const auto argv = base::CommandLine::ForCurrentProcess()->argv();
  145. std::vector<std::string> args;
  146. // TODO(codebytere): We need to set the first entry in args to the
  147. // process name owing to src/node_options-inl.h#L286-L290 but this is
  148. // redundant and so should be refactored upstream.
  149. args.reserve(argv.size() + 1);
  150. args.emplace_back("electron");
  151. for (const auto& arg : argv) {
  152. #if defined(OS_WIN)
  153. const auto& option = base::UTF16ToUTF8(arg);
  154. #else
  155. const auto& option = arg;
  156. #endif
  157. const auto stripped = base::StringPiece(option).substr(0, option.find('='));
  158. // Only allow in no-op (--) option or DebugOptions
  159. if (allowed.count(stripped) != 0 || stripped == "--")
  160. args.push_back(option);
  161. }
  162. std::vector<std::string> errors;
  163. const int exit_code = ProcessGlobalArgs(&args, nullptr, &errors,
  164. node::kDisallowedInEnvironment);
  165. const std::string err_str = "Error parsing Node.js cli flags ";
  166. if (exit_code != 0) {
  167. LOG(ERROR) << err_str;
  168. } else if (!errors.empty()) {
  169. LOG(ERROR) << err_str << base::JoinString(errors, " ");
  170. }
  171. } // namespace
  172. // Initialize NODE_OPTIONS to pass to Node.js
  173. // See https://nodejs.org/api/cli.html#cli_node_options_options
  174. void SetNodeOptions(base::Environment* env) {
  175. // Options that are unilaterally disallowed
  176. const std::set<std::string> disallowed = {
  177. "--openssl-config", "--use-bundled-ca", "--use-openssl-ca",
  178. "--force-fips", "--enable-fips"};
  179. // Subset of options allowed in packaged apps
  180. const std::set<std::string> allowed_in_packaged = {"--max-http-header-size",
  181. "--http-parser"};
  182. if (env->HasVar("NODE_OPTIONS")) {
  183. std::string options;
  184. env->GetVar("NODE_OPTIONS", &options);
  185. std::vector<std::string> parts = base::SplitString(
  186. options, " ", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY);
  187. bool is_packaged_app = IsPackagedApp();
  188. for (const auto& part : parts) {
  189. // Strip off values passed to individual NODE_OPTIONs
  190. std::string option = part.substr(0, part.find('='));
  191. if (is_packaged_app &&
  192. allowed_in_packaged.find(option) == allowed_in_packaged.end()) {
  193. // Explicitly disallow majority of NODE_OPTIONS in packaged apps
  194. LOG(ERROR) << "Most NODE_OPTIONs are not supported in packaged apps."
  195. << " See documentation for more details.";
  196. options.erase(options.find(option), part.length());
  197. } else if (disallowed.find(option) != disallowed.end()) {
  198. // Remove NODE_OPTIONS specifically disallowed for use in Node.js
  199. // through Electron owing to constraints like BoringSSL.
  200. LOG(ERROR) << "The NODE_OPTION " << option
  201. << " is not supported in Electron";
  202. options.erase(options.find(option), part.length());
  203. }
  204. }
  205. // overwrite new NODE_OPTIONS without unsupported variables
  206. env->SetVar("NODE_OPTIONS", options);
  207. }
  208. }
  209. bool AllowWasmCodeGenerationCallback(v8::Local<v8::Context> context,
  210. v8::Local<v8::String>) {
  211. // If we're running with contextIsolation enabled in the renderer process,
  212. // fall back to Blink's logic.
  213. v8::Isolate* isolate = context->GetIsolate();
  214. if (node::Environment::GetCurrent(isolate) == nullptr) {
  215. if (gin_helper::Locker::IsBrowserProcess())
  216. return false;
  217. return blink::V8Initializer::WasmCodeGenerationCheckCallbackInMainThread(
  218. context, v8::String::Empty(isolate));
  219. }
  220. return node::Environment::AllowWasmCodeGenerationCallback(
  221. context, v8::String::Empty(isolate));
  222. }
  223. } // namespace
  224. namespace electron {
  225. namespace {
  226. // Convert the given vector to an array of C-strings. The strings in the
  227. // returned vector are only guaranteed valid so long as the vector of strings
  228. // is not modified.
  229. std::unique_ptr<const char* []> StringVectorToArgArray(
  230. const std::vector<std::string>& vector) {
  231. std::unique_ptr<const char*[]> array(new const char*[vector.size()]);
  232. for (size_t i = 0; i < vector.size(); ++i) {
  233. array[i] = vector[i].c_str();
  234. }
  235. return array;
  236. }
  237. base::FilePath GetResourcesPath() {
  238. #if defined(OS_MACOSX)
  239. return MainApplicationBundlePath().Append("Contents").Append("Resources");
  240. #else
  241. auto* command_line = base::CommandLine::ForCurrentProcess();
  242. base::FilePath exec_path(command_line->GetProgram());
  243. base::PathService::Get(base::FILE_EXE, &exec_path);
  244. return exec_path.DirName().Append(FILE_PATH_LITERAL("resources"));
  245. #endif
  246. }
  247. } // namespace
  248. NodeBindings::NodeBindings(BrowserEnvironment browser_env)
  249. : browser_env_(browser_env), weak_factory_(this) {
  250. if (browser_env == BrowserEnvironment::WORKER) {
  251. uv_loop_init(&worker_loop_);
  252. uv_loop_ = &worker_loop_;
  253. } else {
  254. uv_loop_ = uv_default_loop();
  255. }
  256. }
  257. NodeBindings::~NodeBindings() {
  258. // Quit the embed thread.
  259. embed_closed_ = true;
  260. uv_sem_post(&embed_sem_);
  261. WakeupEmbedThread();
  262. // Wait for everything to be done.
  263. uv_thread_join(&embed_thread_);
  264. // Clear uv.
  265. uv_sem_destroy(&embed_sem_);
  266. dummy_uv_handle_.reset();
  267. // Clean up worker loop
  268. if (in_worker_loop())
  269. stop_and_close_uv_loop(uv_loop_);
  270. }
  271. void NodeBindings::RegisterBuiltinModules() {
  272. #define V(modname) _register_##modname();
  273. ELECTRON_BUILTIN_MODULES(V)
  274. #if BUILDFLAG(ENABLE_VIEWS_API)
  275. ELECTRON_VIEWS_MODULES(V)
  276. #endif
  277. #if BUILDFLAG(ENABLE_DESKTOP_CAPTURER)
  278. ELECTRON_DESKTOP_CAPTURER_MODULE(V)
  279. #endif
  280. #undef V
  281. }
  282. bool NodeBindings::IsInitialized() {
  283. return g_is_initialized;
  284. }
  285. void NodeBindings::Initialize() {
  286. TRACE_EVENT0("electron", "NodeBindings::Initialize");
  287. // Open node's error reporting system for browser process.
  288. node::g_standalone_mode = browser_env_ == BrowserEnvironment::BROWSER;
  289. node::g_upstream_node_mode = false;
  290. #if defined(OS_LINUX)
  291. // Get real command line in renderer process forked by zygote.
  292. if (browser_env_ != BrowserEnvironment::BROWSER)
  293. ElectronCommandLine::InitializeFromCommandLine();
  294. #endif
  295. // Explicitly register electron's builtin modules.
  296. RegisterBuiltinModules();
  297. // Parse and set Node.js cli flags.
  298. SetNodeCliFlags();
  299. // pass non-null program name to argv so it doesn't crash
  300. // trying to index into a nullptr
  301. int argc = 1;
  302. int exec_argc = 0;
  303. const char* prog_name = "electron";
  304. const char** argv = &prog_name;
  305. const char** exec_argv = nullptr;
  306. std::unique_ptr<base::Environment> env(base::Environment::Create());
  307. SetNodeOptions(env.get());
  308. // TODO(codebytere): this is going to be deprecated in the near future
  309. // in favor of Init(std::vector<std::string>* argv,
  310. // std::vector<std::string>* exec_argv)
  311. node::Init(&argc, argv, &exec_argc, &exec_argv);
  312. #if defined(OS_WIN)
  313. // uv_init overrides error mode to suppress the default crash dialog, bring
  314. // it back if user wants to show it.
  315. if (browser_env_ == BrowserEnvironment::BROWSER ||
  316. env->HasVar("ELECTRON_DEFAULT_ERROR_MODE"))
  317. SetErrorMode(GetErrorMode() & ~SEM_NOGPFAULTERRORBOX);
  318. #endif
  319. g_is_initialized = true;
  320. }
  321. node::Environment* NodeBindings::CreateEnvironment(
  322. v8::Handle<v8::Context> context,
  323. node::MultiIsolatePlatform* platform) {
  324. #if defined(OS_WIN)
  325. auto& atom_args = ElectronCommandLine::argv();
  326. std::vector<std::string> args(atom_args.size());
  327. std::transform(atom_args.cbegin(), atom_args.cend(), args.begin(),
  328. [](auto& a) { return base::WideToUTF8(a); });
  329. #else
  330. auto args = ElectronCommandLine::argv();
  331. #endif
  332. // Feed node the path to initialization script.
  333. std::string process_type;
  334. switch (browser_env_) {
  335. case BrowserEnvironment::BROWSER:
  336. process_type = "browser";
  337. break;
  338. case BrowserEnvironment::RENDERER:
  339. process_type = "renderer";
  340. break;
  341. case BrowserEnvironment::WORKER:
  342. process_type = "worker";
  343. break;
  344. }
  345. gin_helper::Dictionary global(context->GetIsolate(), context->Global());
  346. // Do not set DOM globals for renderer process.
  347. // We must set this before the node bootstrapper which is run inside
  348. // CreateEnvironment
  349. if (browser_env_ != BrowserEnvironment::BROWSER)
  350. global.Set("_noBrowserGlobals", true);
  351. base::FilePath resources_path = GetResourcesPath();
  352. std::string init_script = "electron/js2c/" + process_type + "_init";
  353. args.insert(args.begin() + 1, init_script);
  354. std::unique_ptr<const char*[]> c_argv = StringVectorToArgArray(args);
  355. isolate_data_ =
  356. node::CreateIsolateData(context->GetIsolate(), uv_loop_, platform);
  357. node::Environment* env;
  358. if (browser_env_ != BrowserEnvironment::BROWSER) {
  359. v8::TryCatch try_catch(context->GetIsolate());
  360. env = node::CreateEnvironment(isolate_data_, context, args.size(),
  361. c_argv.get(), 0, nullptr);
  362. DCHECK(env);
  363. // This will only be caught when something has gone terrible wrong as all
  364. // electron scripts are wrapped in a try {} catch {} in run-compiler.js
  365. if (try_catch.HasCaught()) {
  366. LOG(ERROR) << "Failed to initialize node environment in process: "
  367. << process_type;
  368. }
  369. } else {
  370. env = node::CreateEnvironment(isolate_data_, context, args.size(),
  371. c_argv.get(), 0, nullptr);
  372. DCHECK(env);
  373. }
  374. // Clean up the global _noBrowserGlobals that we unironically injected into
  375. // the global scope
  376. if (browser_env_ != BrowserEnvironment::BROWSER) {
  377. // We need to bootstrap the env in non-browser processes so that
  378. // _noBrowserGlobals is read correctly before we remove it
  379. global.Delete("_noBrowserGlobals");
  380. }
  381. if (browser_env_ == BrowserEnvironment::BROWSER) {
  382. // This policy requires that microtask checkpoints be explicitly invoked.
  383. // Node.js requires this.
  384. context->GetIsolate()->SetMicrotasksPolicy(v8::MicrotasksPolicy::kExplicit);
  385. } else {
  386. // Match Blink's behavior by allowing microtasks invocation to be controlled
  387. // by MicrotasksScope objects.
  388. context->GetIsolate()->SetMicrotasksPolicy(v8::MicrotasksPolicy::kScoped);
  389. // Isolate message listeners are additive (you can add multiple), so instead
  390. // we add an extra one here to ensure that the async hook stack is properly
  391. // cleared when errors are thrown.
  392. context->GetIsolate()->AddMessageListenerWithErrorLevel(
  393. ErrorMessageListener, v8::Isolate::kMessageError);
  394. }
  395. // This needs to be called before the inspector is initialized.
  396. env->InitializeDiagnostics();
  397. // Set the callback to invoke to check if wasm code generation should be
  398. // allowed.
  399. context->GetIsolate()->SetAllowWasmCodeGenerationCallback(
  400. AllowWasmCodeGenerationCallback);
  401. // Generate more detailed source positions to code objects. This results in
  402. // better results when mapping profiling samples to script source.
  403. v8::CpuProfiler::UseDetailedSourcePositionsForProfiling(
  404. context->GetIsolate());
  405. gin_helper::Dictionary process(context->GetIsolate(), env->process_object());
  406. process.SetReadOnly("type", process_type);
  407. process.Set("resourcesPath", resources_path);
  408. // The path to helper app.
  409. base::FilePath helper_exec_path;
  410. base::PathService::Get(content::CHILD_PROCESS_EXE, &helper_exec_path);
  411. process.Set("helperExecPath", helper_exec_path);
  412. return env;
  413. }
  414. void NodeBindings::LoadEnvironment(node::Environment* env) {
  415. node::LoadEnvironment(env);
  416. gin_helper::EmitEvent(env->isolate(), env->process_object(), "loaded");
  417. }
  418. void NodeBindings::PrepareMessageLoop() {
  419. #if !defined(OS_WIN)
  420. int handle = uv_backend_fd(uv_loop_);
  421. #else
  422. HANDLE handle = uv_loop_->iocp;
  423. #endif
  424. // If the backend fd hasn't changed, don't proceed.
  425. if (handle == handle_)
  426. return;
  427. handle_ = handle;
  428. // Add dummy handle for libuv, otherwise libuv would quit when there is
  429. // nothing to do.
  430. uv_async_init(uv_loop_, dummy_uv_handle_.get(), nullptr);
  431. // Start worker that will interrupt main loop when having uv events.
  432. uv_sem_init(&embed_sem_, 0);
  433. uv_thread_create(&embed_thread_, EmbedThreadRunner, this);
  434. }
  435. void NodeBindings::RunMessageLoop() {
  436. // The MessageLoop should have been created, remember the one in main thread.
  437. task_runner_ = base::ThreadTaskRunnerHandle::Get();
  438. // Run uv loop for once to give the uv__io_poll a chance to add all events.
  439. UvRunOnce();
  440. }
  441. void NodeBindings::UvRunOnce() {
  442. node::Environment* env = uv_env();
  443. // When doing navigation without restarting renderer process, it may happen
  444. // that the node environment is destroyed but the message loop is still there.
  445. // In this case we should not run uv loop.
  446. if (!env)
  447. return;
  448. // Use Locker in browser process.
  449. gin_helper::Locker locker(env->isolate());
  450. v8::HandleScope handle_scope(env->isolate());
  451. // Enter node context while dealing with uv events.
  452. v8::Context::Scope context_scope(env->context());
  453. // Perform microtask checkpoint after running JavaScript.
  454. gin_helper::MicrotasksScope microtasks_scope(env->isolate());
  455. if (browser_env_ != BrowserEnvironment::BROWSER)
  456. TRACE_EVENT_BEGIN0("devtools.timeline", "FunctionCall");
  457. // Deal with uv events.
  458. int r = uv_run(uv_loop_, UV_RUN_NOWAIT);
  459. if (browser_env_ != BrowserEnvironment::BROWSER)
  460. TRACE_EVENT_END0("devtools.timeline", "FunctionCall");
  461. if (r == 0)
  462. base::RunLoop().QuitWhenIdle(); // Quit from uv.
  463. // Tell the worker thread to continue polling.
  464. uv_sem_post(&embed_sem_);
  465. }
  466. void NodeBindings::WakeupMainThread() {
  467. DCHECK(task_runner_);
  468. task_runner_->PostTask(FROM_HERE, base::BindOnce(&NodeBindings::UvRunOnce,
  469. weak_factory_.GetWeakPtr()));
  470. }
  471. void NodeBindings::WakeupEmbedThread() {
  472. uv_async_send(dummy_uv_handle_.get());
  473. }
  474. // static
  475. void NodeBindings::EmbedThreadRunner(void* arg) {
  476. auto* self = static_cast<NodeBindings*>(arg);
  477. while (true) {
  478. // Wait for the main loop to deal with events.
  479. uv_sem_wait(&self->embed_sem_);
  480. if (self->embed_closed_)
  481. break;
  482. // Wait for something to happen in uv loop.
  483. // Note that the PollEvents() is implemented by derived classes, so when
  484. // this class is being destructed the PollEvents() would not be available
  485. // anymore. Because of it we must make sure we only invoke PollEvents()
  486. // when this class is alive.
  487. self->PollEvents();
  488. if (self->embed_closed_)
  489. break;
  490. // Deal with event in main thread.
  491. self->WakeupMainThread();
  492. }
  493. }
  494. } // namespace electron