From 53c73c0631e9b076fa1f76816c8c793ec3438656 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Fri, 25 Jul 2014 10:38:19 +0800 Subject: [PATCH] mac: Fix crash when closing window, closes #504. --- atom/browser/native_window_mac.mm | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/atom/browser/native_window_mac.mm b/atom/browser/native_window_mac.mm index 2dc7f5327b77..330fb0869a7b 100644 --- a/atom/browser/native_window_mac.mm +++ b/atom/browser/native_window_mac.mm @@ -52,11 +52,13 @@ static const CGFloat kAtomWindowCornerRadius = 4.0; - (void)windowDidBecomeMain:(NSNotification*)notification { shell_->NotifyWindowFocus(); - if (shell_->GetWebContents()) - shell_->GetWebContents()->GetView()->StoreFocus(); + content::WebContents* web_contents = shell_->GetWebContents(); + if (!web_contents) + return; - content::RenderWidgetHostView* rwhv = - shell_->GetWebContents()->GetRenderWidgetHostView(); + web_contents->GetView()->RestoreFocus(); + + content::RenderWidgetHostView* rwhv = web_contents->GetRenderWidgetHostView(); if (rwhv) rwhv->SetActive(true); } @@ -64,11 +66,13 @@ static const CGFloat kAtomWindowCornerRadius = 4.0; - (void)windowDidResignMain:(NSNotification*)notification { shell_->NotifyWindowBlur(); - if (shell_->GetWebContents()) - shell_->GetWebContents()->GetView()->StoreFocus(); + content::WebContents* web_contents = shell_->GetWebContents(); + if (!web_contents) + return; - content::RenderWidgetHostView* rwhv = - shell_->GetWebContents()->GetRenderWidgetHostView(); + web_contents->GetView()->StoreFocus(); + + content::RenderWidgetHostView* rwhv = web_contents->GetRenderWidgetHostView(); if (rwhv) rwhv->SetActive(false); }