diff --git a/atom/browser/api/atom_api_browser_window.cc b/atom/browser/api/atom_api_browser_window.cc index 04b3e4f1c3..140a6a152a 100644 --- a/atom/browser/api/atom_api_browser_window.cc +++ b/atom/browser/api/atom_api_browser_window.cc @@ -276,7 +276,6 @@ bool BrowserWindow::OnMessageReceived(const IPC::Message& message, void BrowserWindow::OnCloseContents() { if (!web_contents()) return; - Observe(nullptr); // Close all child windows before closing current window. v8::Locker locker(isolate()); @@ -296,6 +295,9 @@ void BrowserWindow::OnCloseContents() { // Do not sent "unresponsive" event after window is closed. window_unresponsive_closure_.Cancel(); + + // Clear the web_contents() at last. + Observe(nullptr); } void BrowserWindow::OnRendererResponsive() { @@ -360,10 +362,20 @@ void BrowserWindow::OnWindowEndSession() { } void BrowserWindow::OnWindowBlur() { + web_contents()->StoreFocus(); + auto* rwhv = web_contents()->GetRenderWidgetHostView(); + if (rwhv) + rwhv->SetActive(false); + Emit("blur"); } void BrowserWindow::OnWindowFocus() { + web_contents()->RestoreFocus(); + auto* rwhv = web_contents()->GetRenderWidgetHostView(); + if (rwhv) + rwhv->SetActive(true); + Emit("focus"); } diff --git a/atom/browser/native_window_mac.mm b/atom/browser/native_window_mac.mm index b71b3f23d5..da0a3dcc8b 100644 --- a/atom/browser/native_window_mac.mm +++ b/atom/browser/native_window_mac.mm @@ -243,30 +243,10 @@ bool ScopedDisableResize::disable_resize_ = false; } - (void)windowDidBecomeMain:(NSNotification*)notification { - content::WebContents* web_contents = shell_->web_contents(); - if (!web_contents) - return; - - web_contents->RestoreFocus(); - - content::RenderWidgetHostView* rwhv = web_contents->GetRenderWidgetHostView(); - if (rwhv) - rwhv->SetActive(true); - shell_->NotifyWindowFocus(); } - (void)windowDidResignMain:(NSNotification*)notification { - content::WebContents* web_contents = shell_->web_contents(); - if (!web_contents) - return; - - web_contents->StoreFocus(); - - content::RenderWidgetHostView* rwhv = web_contents->GetRenderWidgetHostView(); - if (rwhv) - rwhv->SetActive(false); - shell_->NotifyWindowBlur(); }