fix: crash calling BrowserWindow.removeBrowserView()
with destroyed webContents
(#38842)
fix: crash calling removeBrowserView() with destroyed webContents https://github.com/electron/electron/issues/37642
This commit is contained in:
parent
ce6fe040fe
commit
a00a25376d
3 changed files with 21 additions and 0 deletions
|
@ -131,6 +131,10 @@ void BrowserView::WebContentsDestroyed() {
|
||||||
Unpin();
|
Unpin();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void BrowserView::OnCloseContents() {
|
||||||
|
api_web_contents_ = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
// static
|
// static
|
||||||
gin::Handle<BrowserView> BrowserView::New(gin_helper::ErrorThrower thrower,
|
gin::Handle<BrowserView> BrowserView::New(gin_helper::ErrorThrower thrower,
|
||||||
gin::Arguments* args) {
|
gin::Arguments* args) {
|
||||||
|
|
|
@ -71,6 +71,9 @@ class BrowserView : public gin::Wrappable<BrowserView>,
|
||||||
// content::WebContentsObserver:
|
// content::WebContentsObserver:
|
||||||
void WebContentsDestroyed() override;
|
void WebContentsDestroyed() override;
|
||||||
|
|
||||||
|
// ExtendedWebContentsObserver:
|
||||||
|
void OnCloseContents() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void SetAutoResize(AutoResizeFlags flags);
|
void SetAutoResize(AutoResizeFlags flags);
|
||||||
void SetBounds(const gfx::Rect& bounds);
|
void SetBounds(const gfx::Rect& bounds);
|
||||||
|
|
|
@ -257,6 +257,20 @@ describe('BrowserView module', () => {
|
||||||
w.removeBrowserView(view);
|
w.removeBrowserView(view);
|
||||||
}).to.not.throw();
|
}).to.not.throw();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('can be called on a BrowserView with a destroyed webContents', (done) => {
|
||||||
|
view = new BrowserView();
|
||||||
|
w.addBrowserView(view);
|
||||||
|
|
||||||
|
view.webContents.on('destroyed', () => {
|
||||||
|
w.removeBrowserView(view);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
|
||||||
|
view.webContents.loadURL('data:text/html,hello there').then(() => {
|
||||||
|
view.webContents.close();
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('BrowserWindow.getBrowserViews()', () => {
|
describe('BrowserWindow.getBrowserViews()', () => {
|
||||||
|
|
Loading…
Reference in a new issue