diff --git a/browser/native_window.cc b/browser/native_window.cc index 99f5b531efbb..e6593d9f0e71 100644 --- a/browser/native_window.cc +++ b/browser/native_window.cc @@ -134,6 +134,13 @@ void NativeWindow::CloseDevTools() { } void NativeWindow::CloseWebContents() { + bool prevent_default = false; + FOR_EACH_OBSERVER(NativeWindowObserver, + observers_, + WillCloseWindow(&prevent_default)); + if (prevent_default) + return; + content::WebContents* web_contents(GetWebContents()); if (web_contents->NeedToFireBeforeUnload()) @@ -174,8 +181,12 @@ content::JavaScriptDialogManager* NativeWindow::GetJavaScriptDialogManager() { void NativeWindow::CloseContents(content::WebContents* source) { // When the web contents is gone, close the window immediately, but the // memory will not be freed until you call delete. - // In this way, it would be safe to manage windows via smart pointers. + // In this way, it would be safe to manage windows via smart pointers. If you + // want to free memory when the window is closed, you can do deleting by + // overriding WillCloseWindow method in the observer. CloseImmediately(); + + FOR_EACH_OBSERVER(NativeWindowObserver, observers_, OnWindowClosed()); } bool NativeWindow::OnMessageReceived(const IPC::Message& message) { diff --git a/browser/native_window_mac.mm b/browser/native_window_mac.mm index 0d490a675efa..ea3a6408823d 100644 --- a/browser/native_window_mac.mm +++ b/browser/native_window_mac.mm @@ -99,7 +99,6 @@ NativeWindowMac::NativeWindowMac(content::WebContents* web_contents, [atom_window setShell:this]; window_ = atom_window; - [window() setReleasedWhenClosed:NO]; [window() setDelegate:[[AtomNSWindowDelegate alloc] initWithShell:this]]; // Disable fullscreen button when 'fullscreen' is specified to false. @@ -115,7 +114,6 @@ NativeWindowMac::NativeWindowMac(content::WebContents* web_contents, } NativeWindowMac::~NativeWindowMac() { - [window() release]; } void NativeWindowMac::Close() { diff --git a/browser/native_window_observer.h b/browser/native_window_observer.h index 335fd30be5d9..f21ca0dff29d 100644 --- a/browser/native_window_observer.h +++ b/browser/native_window_observer.h @@ -15,7 +15,13 @@ class NativeWindowObserver { // Called when the web page of the window has updated it's document title. virtual void OnPageTitleUpdated(bool* prevent_default, - const std::string& title) = 0; + const std::string& title) {} + + // Called when the window is gonna closed. + virtual void WillCloseWindow(bool* prevent_default) {} + + // Called when the window is closed. + virtual void OnWindowClosed() {} }; } // namespace atom