2013-05-02 15:43:23 +00:00
|
|
|
// Copyright (c) 2013 GitHub, Inc. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
|
|
#include "browser/browser.h"
|
|
|
|
|
|
|
|
#include "browser/atom_browser_main_parts.h"
|
|
|
|
#include "browser/window_list.h"
|
|
|
|
|
|
|
|
namespace atom {
|
|
|
|
|
|
|
|
Browser::Browser()
|
|
|
|
: is_quiting_(false) {
|
|
|
|
WindowList::AddObserver(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
Browser::~Browser() {
|
|
|
|
WindowList::RemoveObserver(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
Browser* Browser::Get() {
|
|
|
|
return AtomBrowserMainParts::Get()->browser();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Browser::Quit() {
|
|
|
|
atom::WindowList* window_list = atom::WindowList::GetInstance();
|
|
|
|
if (window_list->size() == 0)
|
2013-05-03 02:53:54 +00:00
|
|
|
NotifyAndTerminate();
|
2013-05-02 15:43:23 +00:00
|
|
|
|
|
|
|
is_quiting_ = true;
|
|
|
|
window_list->CloseAllWindows();
|
|
|
|
}
|
|
|
|
|
2013-05-03 02:53:54 +00:00
|
|
|
void Browser::NotifyAndTerminate() {
|
|
|
|
bool prevent_default = false;
|
|
|
|
FOR_EACH_OBSERVER(BrowserObserver, observers_, OnWillQuit(&prevent_default));
|
|
|
|
|
|
|
|
if (prevent_default)
|
|
|
|
return;
|
|
|
|
|
|
|
|
Terminate();
|
|
|
|
}
|
|
|
|
|
2013-05-02 15:43:23 +00:00
|
|
|
void Browser::OnWindowCloseCancelled(NativeWindow* window) {
|
|
|
|
// Once a beforeunload handler has prevented the closing, we think the quit
|
|
|
|
// is cancelled too.
|
|
|
|
is_quiting_ = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Browser::OnWindowAllClosed() {
|
|
|
|
if (is_quiting_)
|
2013-05-03 02:53:54 +00:00
|
|
|
NotifyAndTerminate();
|
|
|
|
else
|
|
|
|
FOR_EACH_OBSERVER(BrowserObserver, observers_, OnWindowAllClosed());
|
2013-05-02 15:43:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace atom
|