From 5c36a446c4aed8c9ce6d067cc1bd98218d6b8a1c Mon Sep 17 00:00:00 2001 From: Samuel Attard Date: Mon, 13 Apr 2020 12:51:43 -0700 Subject: [PATCH] feat: add new render-process-gone event --- docs/api/web-contents.md | 18 ++++++++++ lib/browser/guest-view-manager.js | 1 + .../browser/api/electron_api_web_contents.cc | 4 +++ shell/browser/api/electron_api_web_contents.h | 36 +++++++++++++++++++ 4 files changed, 59 insertions(+) diff --git a/docs/api/web-contents.md b/docs/api/web-contents.md index 7b3a6147d3445..5d58b9a890f77 100644 --- a/docs/api/web-contents.md +++ b/docs/api/web-contents.md @@ -334,6 +334,24 @@ Returns: Emitted when the renderer process crashes or is killed. +#### Event: 'render-process-gone' + +Returns: + +* `event` Event +* `details` Object + * `reason` String - The reason the render process is gone. Possible values: + * `clean-exit` - Process exited with an exit code of zero + * `abnormal-exit` - Process exited with a non-zero exit code + * `killed` - Process was sent a SIGTERM or otherwise killed externally + * `crashed` - Process crashed + * `oom` - Process ran out of memory + * `launch-failure` - Process never successfully launched + * `integrity-failure` - Windows code integrity checks failed + +Emitted when the renderer process unexpectedly dissapears. This is normally +because it was crashed or killed. + #### Event: 'unresponsive' Emitted when the web page becomes unresponsive. diff --git a/lib/browser/guest-view-manager.js b/lib/browser/guest-view-manager.js index 48526617031f4..18d8df739f313 100644 --- a/lib/browser/guest-view-manager.js +++ b/lib/browser/guest-view-manager.js @@ -32,6 +32,7 @@ const supportedWebViewEvents = [ 'focus-change', 'close', 'crashed', + 'render-process-gone', 'plugin-crashed', 'destroyed', 'page-title-updated', diff --git a/shell/browser/api/electron_api_web_contents.cc b/shell/browser/api/electron_api_web_contents.cc index 0c765d6c5311a..0310fa2f52230 100644 --- a/shell/browser/api/electron_api_web_contents.cc +++ b/shell/browser/api/electron_api_web_contents.cc @@ -982,6 +982,10 @@ void WebContents::RenderViewDeleted(content::RenderViewHost* render_view_host) { void WebContents::RenderProcessGone(base::TerminationStatus status) { Emit("crashed", status == base::TERMINATION_STATUS_PROCESS_WAS_KILLED); + v8::HandleScope handle_scope(isolate()); + mate::Dictionary details = mate::Dictionary::CreateEmpty(isolate()); + details.Set("reason", status); + Emit("render-process-gone", details); } void WebContents::PluginCrashed(const base::FilePath& plugin_path, diff --git a/shell/browser/api/electron_api_web_contents.h b/shell/browser/api/electron_api_web_contents.h index 17cf91196e503..3b109105ef815 100644 --- a/shell/browser/api/electron_api_web_contents.h +++ b/shell/browser/api/electron_api_web_contents.h @@ -55,6 +55,42 @@ namespace network { class ResourceRequestBody; } +namespace mate { + +template <> +struct Converter { + static v8::Local ToV8(v8::Isolate* isolate, + const base::TerminationStatus& status) { + switch (status) { + case base::TERMINATION_STATUS_NORMAL_TERMINATION: + return mate::ConvertToV8(isolate, "clean-exit"); + case base::TERMINATION_STATUS_ABNORMAL_TERMINATION: + return mate::ConvertToV8(isolate, "abnormal-exit"); + case base::TERMINATION_STATUS_PROCESS_WAS_KILLED: + return mate::ConvertToV8(isolate, "killed"); + case base::TERMINATION_STATUS_PROCESS_CRASHED: + return mate::ConvertToV8(isolate, "crashed"); + case base::TERMINATION_STATUS_STILL_RUNNING: + return mate::ConvertToV8(isolate, "still-running"); + case base::TERMINATION_STATUS_LAUNCH_FAILED: + return mate::ConvertToV8(isolate, "launch-failed"); + case base::TERMINATION_STATUS_OOM: + return mate::ConvertToV8(isolate, "oom"); +#if defined(OS_WIN) + case base::TERMINATION_STATUS_INTEGRITY_FAILURE: + return mate::ConvertToV8(isolate, "integrity-failure"); +#endif + case base::TERMINATION_STATUS_MAX_ENUM: + NOTREACHED(); + return mate::ConvertToV8(isolate, ""); + } + NOTREACHED(); + return mate::ConvertToV8(isolate, ""); + } +}; + +} // namespace mate + namespace electron { class ElectronBrowserContext;