mac: Fix crash when closing window, closes #504.

This commit is contained in:
Cheng Zhao 2014-07-25 10:38:19 +08:00
parent 6c866ea909
commit 53c73c0631

View file

@ -52,11 +52,13 @@ static const CGFloat kAtomWindowCornerRadius = 4.0;
- (void)windowDidBecomeMain:(NSNotification*)notification { - (void)windowDidBecomeMain:(NSNotification*)notification {
shell_->NotifyWindowFocus(); shell_->NotifyWindowFocus();
if (shell_->GetWebContents()) content::WebContents* web_contents = shell_->GetWebContents();
shell_->GetWebContents()->GetView()->StoreFocus(); if (!web_contents)
return;
content::RenderWidgetHostView* rwhv = web_contents->GetView()->RestoreFocus();
shell_->GetWebContents()->GetRenderWidgetHostView();
content::RenderWidgetHostView* rwhv = web_contents->GetRenderWidgetHostView();
if (rwhv) if (rwhv)
rwhv->SetActive(true); rwhv->SetActive(true);
} }
@ -64,11 +66,13 @@ static const CGFloat kAtomWindowCornerRadius = 4.0;
- (void)windowDidResignMain:(NSNotification*)notification { - (void)windowDidResignMain:(NSNotification*)notification {
shell_->NotifyWindowBlur(); shell_->NotifyWindowBlur();
if (shell_->GetWebContents()) content::WebContents* web_contents = shell_->GetWebContents();
shell_->GetWebContents()->GetView()->StoreFocus(); if (!web_contents)
return;
content::RenderWidgetHostView* rwhv = web_contents->GetView()->StoreFocus();
shell_->GetWebContents()->GetRenderWidgetHostView();
content::RenderWidgetHostView* rwhv = web_contents->GetRenderWidgetHostView();
if (rwhv) if (rwhv)
rwhv->SetActive(false); rwhv->SetActive(false);
} }