fix: crash on browserView.webContents.destroy() (#31794)
This commit is contained in:
parent
22f863b37a
commit
7e328c4b87
2 changed files with 11 additions and 3 deletions
|
@ -983,8 +983,7 @@ void WebContents::DeleteThisIfAlive() {
|
||||||
void WebContents::Destroy() {
|
void WebContents::Destroy() {
|
||||||
// The content::WebContents should be destroyed asyncronously when possible
|
// The content::WebContents should be destroyed asyncronously when possible
|
||||||
// as user may choose to destroy WebContents during an event of it.
|
// as user may choose to destroy WebContents during an event of it.
|
||||||
if (Browser::Get()->is_shutting_down() || IsGuest() ||
|
if (Browser::Get()->is_shutting_down() || IsGuest()) {
|
||||||
type_ == Type::kBrowserView) {
|
|
||||||
DeleteThisIfAlive();
|
DeleteThisIfAlive();
|
||||||
} else {
|
} else {
|
||||||
base::PostTask(FROM_HERE, {content::BrowserThread::UI},
|
base::PostTask(FROM_HERE, {content::BrowserThread::UI},
|
||||||
|
|
|
@ -151,7 +151,7 @@ describe('BrowserView module', () => {
|
||||||
w.addBrowserView(view);
|
w.addBrowserView(view);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('does not crash if the BrowserView webContents are destroyed prior to window removal', () => {
|
it('does not crash if the BrowserView webContents are destroyed prior to window addition', () => {
|
||||||
expect(() => {
|
expect(() => {
|
||||||
const view1 = new BrowserView();
|
const view1 = new BrowserView();
|
||||||
(view1.webContents as any).destroy();
|
(view1.webContents as any).destroy();
|
||||||
|
@ -159,6 +159,15 @@ describe('BrowserView module', () => {
|
||||||
}).to.not.throw();
|
}).to.not.throw();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('does not crash if the webContents is destroyed after a URL is loaded', () => {
|
||||||
|
view = new BrowserView();
|
||||||
|
expect(async () => {
|
||||||
|
view.setBounds({ x: 0, y: 0, width: 400, height: 300 });
|
||||||
|
await view.webContents.loadURL('data:text/html,hello there');
|
||||||
|
view.webContents.destroy();
|
||||||
|
}).to.not.throw();
|
||||||
|
});
|
||||||
|
|
||||||
it('can handle BrowserView reparenting', async () => {
|
it('can handle BrowserView reparenting', async () => {
|
||||||
view = new BrowserView();
|
view = new BrowserView();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue