fix: check WebContents before emitting render-process-gone event (#27730)
This commit is contained in:
parent
642d6fca91
commit
7a7a27d9bc
2 changed files with 17 additions and 0 deletions
|
@ -1407,7 +1407,13 @@ void WebContents::RenderViewDeleted(content::RenderViewHost* render_view_host) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebContents::RenderProcessGone(base::TerminationStatus status) {
|
void WebContents::RenderProcessGone(base::TerminationStatus status) {
|
||||||
|
auto weak_this = GetWeakPtr();
|
||||||
Emit("crashed", status == base::TERMINATION_STATUS_PROCESS_WAS_KILLED);
|
Emit("crashed", status == base::TERMINATION_STATUS_PROCESS_WAS_KILLED);
|
||||||
|
|
||||||
|
// User might destroy WebContents in the crashed event.
|
||||||
|
if (!weak_this)
|
||||||
|
return;
|
||||||
|
|
||||||
v8::Isolate* isolate = JavascriptEnvironment::GetIsolate();
|
v8::Isolate* isolate = JavascriptEnvironment::GetIsolate();
|
||||||
v8::HandleScope handle_scope(isolate);
|
v8::HandleScope handle_scope(isolate);
|
||||||
gin_helper::Dictionary details = gin_helper::Dictionary::CreateEmpty(isolate);
|
gin_helper::Dictionary details = gin_helper::Dictionary::CreateEmpty(isolate);
|
||||||
|
|
|
@ -2007,6 +2007,17 @@ describe('webContents module', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('crashed event', () => {
|
||||||
|
it('does not crash main process when destroying WebContents in it', (done) => {
|
||||||
|
const contents = (webContents as any).create({ nodeIntegration: true });
|
||||||
|
contents.once('crashed', () => {
|
||||||
|
contents.destroy();
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
contents.loadURL('about:blank').then(() => contents.forcefullyCrashRenderer());
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it('emits a cancelable event before creating a child webcontents', async () => {
|
it('emits a cancelable event before creating a child webcontents', async () => {
|
||||||
const w = new BrowserWindow({
|
const w = new BrowserWindow({
|
||||||
show: false,
|
show: false,
|
||||||
|
|
Loading…
Add table
Reference in a new issue