Emit a new before-quit event at the start of Browser::Quit, which gives us a chance to cancel before any windows are closed.

This commit is contained in:
Charlie Hess 2015-02-25 19:33:42 -08:00
parent 0c99f3baa6
commit b6787a9b34
6 changed files with 32 additions and 4 deletions

View file

@ -28,7 +28,9 @@ Browser* Browser::Get() {
}
void Browser::Quit() {
is_quiting_ = true;
is_quiting_ = HandleBeforeQuit();
if (!is_quiting_)
return;
atom::WindowList* window_list = atom::WindowList::GetInstance();
if (window_list->size() == 0)
@ -114,6 +116,13 @@ void Browser::NotifyAndShutdown() {
Shutdown();
}
bool Browser::HandleBeforeQuit() {
bool prevent_default = false;
FOR_EACH_OBSERVER(BrowserObserver, observers_, OnBeforeQuit(&prevent_default));
return !prevent_default;
}
void Browser::OnWindowCloseCancelled(NativeWindow* window) {
if (is_quiting_)
// Once a beforeunload handler has prevented the closing, we think the quit