mirror of
https://github.com/electron/electron.git
synced 2026-04-10 03:01:51 -04:00
feat: add webContents.forcefullyCrashRenderer() to forcefully terminate a renderer process (#25756)
* feat: add webContents.crashProcess() to forcefully terminate a renderer process * chore: fix up docs and tests Co-authored-by: Samuel Attard <samuel.r.attard@gmail.com>
This commit is contained in:
@@ -21,6 +21,7 @@
|
||||
#include "base/threading/thread_task_runner_handle.h"
|
||||
#include "base/values.h"
|
||||
#include "chrome/browser/browser_process.h"
|
||||
#include "chrome/browser/hang_monitor/hang_crash_dump.h"
|
||||
#include "chrome/browser/ssl/security_state_tab_helper.h"
|
||||
#include "content/browser/frame_host/frame_tree_node.h" // nogncheck
|
||||
#include "content/browser/frame_host/render_frame_host_manager.h" // nogncheck
|
||||
@@ -1763,6 +1764,30 @@ bool WebContents::IsCrashed() const {
|
||||
return web_contents()->IsCrashed();
|
||||
}
|
||||
|
||||
void WebContents::ForcefullyCrashRenderer() {
|
||||
content::RenderWidgetHostView* view =
|
||||
web_contents()->GetRenderWidgetHostView();
|
||||
if (!view)
|
||||
return;
|
||||
|
||||
content::RenderWidgetHost* rwh = view->GetRenderWidgetHost();
|
||||
if (!rwh)
|
||||
return;
|
||||
|
||||
content::RenderProcessHost* rph = rwh->GetProcess();
|
||||
if (rph) {
|
||||
#if defined(OS_LINUX) || defined(OS_CHROMEOS)
|
||||
// A generic |CrashDumpHungChildProcess()| is not implemented for Linux.
|
||||
// Instead we send an explicit IPC to crash on the renderer's IO thread.
|
||||
rph->ForceCrash();
|
||||
#else
|
||||
// Try to generate a crash report for the hung process.
|
||||
CrashDumpHungChildProcess(rph->GetProcess().Handle());
|
||||
rph->Shutdown(content::RESULT_CODE_HUNG);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
void WebContents::SetUserAgent(const std::string& user_agent) {
|
||||
web_contents()->SetUserAgentOverride(
|
||||
blink::UserAgentOverride::UserAgentOnly(user_agent), false);
|
||||
@@ -2920,6 +2945,8 @@ v8::Local<v8::ObjectTemplate> WebContents::FillObjectTemplate(
|
||||
.SetMethod("_goForward", &WebContents::GoForward)
|
||||
.SetMethod("_goToOffset", &WebContents::GoToOffset)
|
||||
.SetMethod("isCrashed", &WebContents::IsCrashed)
|
||||
.SetMethod("forcefullyCrashRenderer",
|
||||
&WebContents::ForcefullyCrashRenderer)
|
||||
.SetMethod("setUserAgent", &WebContents::SetUserAgent)
|
||||
.SetMethod("getUserAgent", &WebContents::GetUserAgent)
|
||||
.SetMethod("savePage", &WebContents::SavePage)
|
||||
|
||||
@@ -228,6 +228,7 @@ class WebContents : public gin::Wrappable<WebContents>,
|
||||
const std::string GetWebRTCIPHandlingPolicy() const;
|
||||
void SetWebRTCIPHandlingPolicy(const std::string& webrtc_ip_handling_policy);
|
||||
bool IsCrashed() const;
|
||||
void ForcefullyCrashRenderer();
|
||||
void SetUserAgent(const std::string& user_agent);
|
||||
std::string GetUserAgent();
|
||||
void InsertCSS(const std::string& css);
|
||||
|
||||
Reference in New Issue
Block a user