fix: prevent destroyed view references from causing crashes (#25411)
Closes #21666. This PR is fixing crashes caused by referencing and attempting to modify previously destroyed views. Before, when a view was destroyed and then the contents were referenced for modification, the system would crash as undefined memory was accessed. This fix explicitly makes the pointer to the destroyed view's contents null, so that this will not happen.
This commit is contained in:
parent
e0a25cb1e3
commit
53aaeb7a16
5 changed files with 90 additions and 21 deletions
|
@ -13,16 +13,26 @@ namespace electron {
|
|||
|
||||
NativeBrowserView::NativeBrowserView(
|
||||
InspectableWebContents* inspectable_web_contents)
|
||||
: inspectable_web_contents_(inspectable_web_contents) {}
|
||||
: inspectable_web_contents_(inspectable_web_contents) {
|
||||
Observe(inspectable_web_contents_->GetWebContents());
|
||||
}
|
||||
|
||||
NativeBrowserView::~NativeBrowserView() = default;
|
||||
|
||||
InspectableWebContentsView* NativeBrowserView::GetInspectableWebContentsView() {
|
||||
if (!inspectable_web_contents_)
|
||||
return nullptr;
|
||||
return inspectable_web_contents_->GetView();
|
||||
}
|
||||
|
||||
content::WebContents* NativeBrowserView::GetWebContents() {
|
||||
if (!inspectable_web_contents_)
|
||||
return nullptr;
|
||||
return inspectable_web_contents_->GetWebContents();
|
||||
}
|
||||
|
||||
void NativeBrowserView::WebContentsDestroyed() {
|
||||
inspectable_web_contents_ = nullptr;
|
||||
}
|
||||
|
||||
} // namespace electron
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue