]> khamidou — GitHub mirrors - electron.git/commitdiff
mac: Fix crash when closing window, closes #504.
authorCheng Zhao <zcbenz@gmail.com>
Fri, 25 Jul 2014 02:38:19 +0000 (10:38 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Fri, 25 Jul 2014 02:38:19 +0000 (10:38 +0800)
atom/browser/native_window_mac.mm

index 2dc7f5327b77fa663a7002908b9540ef9e55df5a..330fb0869a7ba2c320e65e5256e771fd99fda70e 100644 (file)
@@ -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;
+
+  web_contents->GetView()->RestoreFocus();
 
-  content::RenderWidgetHostView* rwhv =
-      shell_->GetWebContents()->GetRenderWidgetHostView();
+  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;
+
+  web_contents->GetView()->StoreFocus();
 
-  content::RenderWidgetHostView* rwhv =
-      shell_->GetWebContents()->GetRenderWidgetHostView();
+  content::RenderWidgetHostView* rwhv = web_contents->GetRenderWidgetHostView();
   if (rwhv)
     rwhv->SetActive(false);
 }