fix: crash on window.close()
with webContents
on blur (#47954)
fix: crash on window.close with WebContentsView on blur Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com> Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>
This commit is contained in:
parent
ee8290e707
commit
99b9516a68
2 changed files with 34 additions and 8 deletions
|
@ -2760,7 +2760,7 @@ void WebContents::CloseDevTools() {
|
||||||
if (type_ == Type::kRemote)
|
if (type_ == Type::kRemote)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
DCHECK(inspectable_web_contents_);
|
if (inspectable_web_contents_)
|
||||||
inspectable_web_contents_->CloseDevTools();
|
inspectable_web_contents_->CloseDevTools();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2768,7 +2768,9 @@ bool WebContents::IsDevToolsOpened() {
|
||||||
if (type_ == Type::kRemote)
|
if (type_ == Type::kRemote)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
DCHECK(inspectable_web_contents_);
|
if (!inspectable_web_contents_)
|
||||||
|
return false;
|
||||||
|
|
||||||
return inspectable_web_contents_->IsDevToolsViewShowing();
|
return inspectable_web_contents_->IsDevToolsViewShowing();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2776,11 +2778,14 @@ std::u16string WebContents::GetDevToolsTitle() {
|
||||||
if (type_ == Type::kRemote)
|
if (type_ == Type::kRemote)
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
DCHECK(inspectable_web_contents_);
|
if (!inspectable_web_contents_)
|
||||||
|
return {};
|
||||||
|
|
||||||
return inspectable_web_contents_->GetDevToolsTitle();
|
return inspectable_web_contents_->GetDevToolsTitle();
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebContents::SetDevToolsTitle(const std::u16string& title) {
|
void WebContents::SetDevToolsTitle(const std::u16string& title) {
|
||||||
|
if (inspectable_web_contents_)
|
||||||
inspectable_web_contents_->SetDevToolsTitle(title);
|
inspectable_web_contents_->SetDevToolsTitle(title);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2788,7 +2793,9 @@ bool WebContents::IsDevToolsFocused() {
|
||||||
if (type_ == Type::kRemote)
|
if (type_ == Type::kRemote)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
DCHECK(inspectable_web_contents_);
|
if (!inspectable_web_contents_)
|
||||||
|
return false;
|
||||||
|
|
||||||
return inspectable_web_contents_->GetView()->IsDevToolsViewFocused();
|
return inspectable_web_contents_->GetView()->IsDevToolsViewFocused();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2836,10 +2843,9 @@ void WebContents::InspectElement(int x, int y) {
|
||||||
if (type_ == Type::kRemote)
|
if (type_ == Type::kRemote)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!enable_devtools_)
|
if (!enable_devtools_ || !inspectable_web_contents_)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
DCHECK(inspectable_web_contents_);
|
|
||||||
if (!inspectable_web_contents_->GetDevToolsWebContents())
|
if (!inspectable_web_contents_->GetDevToolsWebContents())
|
||||||
OpenDevTools(nullptr);
|
OpenDevTools(nullptr);
|
||||||
inspectable_web_contents_->InspectElement(x, y);
|
inspectable_web_contents_->InspectElement(x, y);
|
||||||
|
|
|
@ -167,6 +167,26 @@ describe('WebContentsView', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('does not crash when closed via window.close()', async () => {
|
||||||
|
const bw = new BrowserWindow();
|
||||||
|
const wcv = new WebContentsView();
|
||||||
|
|
||||||
|
await bw.loadURL('data:text/html,<h1>Main Window</h1>');
|
||||||
|
bw.contentView.addChildView(wcv);
|
||||||
|
|
||||||
|
const dto = new Promise<boolean>((resolve) => {
|
||||||
|
wcv.webContents.on('blur', () => {
|
||||||
|
const devToolsOpen = wcv.webContents.isDevToolsOpened();
|
||||||
|
resolve(devToolsOpen);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
wcv.webContents.loadURL('data:text/html,<script>window.close()</script>');
|
||||||
|
|
||||||
|
const open = await dto;
|
||||||
|
expect(open).to.be.false();
|
||||||
|
});
|
||||||
|
|
||||||
it('can be fullscreened', async () => {
|
it('can be fullscreened', async () => {
|
||||||
const w = new BaseWindow();
|
const w = new BaseWindow();
|
||||||
const v = new WebContentsView();
|
const v = new WebContentsView();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue