2014-10-31 11:17:05 -07:00
|
|
|
// Copyright (c) 2013 GitHub, Inc.
|
2014-04-25 17:49:37 +08:00
|
|
|
// Use of this source code is governed by the MIT license that can be
|
2013-05-02 23:43:23 +08:00
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
|
|
#ifndef ATOM_BROWSER_BROWSER_H_
|
|
|
|
#define ATOM_BROWSER_BROWSER_H_
|
|
|
|
|
2014-03-16 09:13:06 +08:00
|
|
|
#include <string>
|
2014-11-17 17:19:41 +08:00
|
|
|
#include <vector>
|
2014-03-16 09:13:06 +08:00
|
|
|
|
2016-03-07 20:38:49 -08:00
|
|
|
#include "base/macros.h"
|
2013-05-02 23:43:23 +08:00
|
|
|
#include "base/compiler_specific.h"
|
2013-05-03 10:53:54 +08:00
|
|
|
#include "base/observer_list.h"
|
2015-11-03 15:16:45 +08:00
|
|
|
#include "base/strings/string16.h"
|
2014-03-16 08:30:26 +08:00
|
|
|
#include "atom/browser/browser_observer.h"
|
|
|
|
#include "atom/browser/window_list_observer.h"
|
2013-05-02 23:43:23 +08:00
|
|
|
|
2014-11-17 15:55:49 +08:00
|
|
|
#if defined(OS_WIN)
|
2014-11-17 17:19:41 +08:00
|
|
|
#include "base/files/file_path.h"
|
2014-11-17 15:55:49 +08:00
|
|
|
#endif
|
|
|
|
|
2014-11-17 13:05:06 +08:00
|
|
|
namespace base {
|
|
|
|
class FilePath;
|
|
|
|
}
|
|
|
|
|
2014-11-16 23:04:31 +08:00
|
|
|
namespace ui {
|
|
|
|
class MenuModel;
|
|
|
|
}
|
|
|
|
|
2016-01-24 08:30:14 +09:00
|
|
|
namespace gfx {
|
|
|
|
class Image;
|
|
|
|
}
|
|
|
|
|
2013-05-02 23:43:23 +08:00
|
|
|
namespace atom {
|
|
|
|
|
2015-10-28 19:34:01 +08:00
|
|
|
class LoginHandler;
|
|
|
|
|
2013-05-02 23:43:23 +08:00
|
|
|
// This class is used for control application-wide operations.
|
|
|
|
class Browser : public WindowListObserver {
|
|
|
|
public:
|
|
|
|
Browser();
|
|
|
|
~Browser();
|
|
|
|
|
|
|
|
static Browser* Get();
|
|
|
|
|
|
|
|
// Try to close all windows and quit the application.
|
|
|
|
void Quit();
|
|
|
|
|
2015-11-06 18:27:13 +08:00
|
|
|
// Exit the application immediately and set exit code.
|
|
|
|
void Exit(int code);
|
|
|
|
|
2014-04-10 15:22:17 +08:00
|
|
|
// Cleanup everything and shutdown the application gracefully.
|
|
|
|
void Shutdown();
|
2013-05-02 23:43:23 +08:00
|
|
|
|
2013-05-30 19:24:47 +08:00
|
|
|
// Focus the application.
|
|
|
|
void Focus();
|
|
|
|
|
2013-06-19 13:41:54 +08:00
|
|
|
// Returns the version of the executable (or bundle).
|
2013-12-05 10:26:01 +08:00
|
|
|
std::string GetVersion() const;
|
|
|
|
|
|
|
|
// Overrides the application version.
|
|
|
|
void SetVersion(const std::string& version);
|
2013-06-19 13:41:54 +08:00
|
|
|
|
2013-12-05 10:32:58 +08:00
|
|
|
// Returns the application's name, default is just Atom-Shell.
|
|
|
|
std::string GetName() const;
|
|
|
|
|
|
|
|
// Overrides the application name.
|
|
|
|
void SetName(const std::string& name);
|
|
|
|
|
2014-11-17 13:05:06 +08:00
|
|
|
// Add the |path| to recent documents list.
|
|
|
|
void AddRecentDocument(const base::FilePath& path);
|
|
|
|
|
2014-11-17 16:13:47 +08:00
|
|
|
// Clear the recent documents list.
|
|
|
|
void ClearRecentDocuments();
|
|
|
|
|
2015-11-03 15:09:31 +08:00
|
|
|
// Set the application user model ID.
|
|
|
|
void SetAppUserModelID(const base::string16& name);
|
|
|
|
|
2013-08-06 16:19:56 +08:00
|
|
|
#if defined(OS_MACOSX)
|
2016-01-29 22:51:06 +01:00
|
|
|
// Hide the application.
|
|
|
|
void Hide();
|
|
|
|
|
2016-01-30 21:40:32 +01:00
|
|
|
// Show the application.
|
|
|
|
void Show();
|
|
|
|
|
2016-03-06 10:55:47 -05:00
|
|
|
// Check if the system is in Dark Mode.
|
|
|
|
bool IsDarkMode();
|
2016-02-19 12:40:41 -05:00
|
|
|
|
2013-08-06 16:19:56 +08:00
|
|
|
// Bounce the dock icon.
|
|
|
|
enum BounceType {
|
|
|
|
BOUNCE_CRITICAL = 0,
|
|
|
|
BOUNCE_INFORMATIONAL = 10,
|
|
|
|
};
|
|
|
|
int DockBounce(BounceType type);
|
|
|
|
void DockCancelBounce(int request_id);
|
|
|
|
|
2013-08-06 16:39:31 +08:00
|
|
|
// Set/Get dock's badge text.
|
2013-08-06 16:19:56 +08:00
|
|
|
void DockSetBadgeText(const std::string& label);
|
2013-08-06 16:39:31 +08:00
|
|
|
std::string DockGetBadgeText();
|
2014-06-25 11:55:33 +08:00
|
|
|
|
|
|
|
// Hide/Show dock.
|
|
|
|
void DockHide();
|
|
|
|
void DockShow();
|
2014-11-16 23:04:31 +08:00
|
|
|
|
|
|
|
// Set docks' menu.
|
|
|
|
void DockSetMenu(ui::MenuModel* model);
|
2016-01-24 08:30:14 +09:00
|
|
|
|
|
|
|
// Set docks' icon.
|
|
|
|
void DockSetIcon(const gfx::Image& image);
|
2013-08-06 16:19:56 +08:00
|
|
|
#endif // defined(OS_MACOSX)
|
|
|
|
|
2014-11-17 15:55:49 +08:00
|
|
|
#if defined(OS_WIN)
|
2014-11-17 17:19:41 +08:00
|
|
|
struct UserTask {
|
|
|
|
base::FilePath program;
|
|
|
|
base::string16 arguments;
|
|
|
|
base::string16 title;
|
|
|
|
base::string16 description;
|
2014-11-17 17:35:51 +08:00
|
|
|
base::FilePath icon_path;
|
|
|
|
int icon_index;
|
2014-11-17 17:19:41 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
// Add a custom task to jump list.
|
2014-11-17 19:32:11 +08:00
|
|
|
void SetUserTasks(const std::vector<UserTask>& tasks);
|
2014-11-17 17:19:41 +08:00
|
|
|
|
2015-11-03 14:55:43 +08:00
|
|
|
// Returns the application user model ID, if there isn't one, then create
|
|
|
|
// one from app's name.
|
|
|
|
// The returned string managed by Browser, and should not be modified.
|
|
|
|
PCWSTR GetAppUserModelID();
|
2014-11-17 15:55:49 +08:00
|
|
|
#endif
|
|
|
|
|
2013-05-30 16:03:10 +08:00
|
|
|
// Tell the application to open a file.
|
|
|
|
bool OpenFile(const std::string& file_path);
|
|
|
|
|
2013-07-10 16:10:38 +08:00
|
|
|
// Tell the application to open a url.
|
|
|
|
void OpenURL(const std::string& url);
|
|
|
|
|
2015-09-14 18:34:27 -07:00
|
|
|
// Tell the application that application is activated with visible/invisible
|
|
|
|
// windows.
|
2015-09-14 19:05:53 -07:00
|
|
|
void Activate(bool has_visible_windows);
|
2015-09-14 19:28:13 +08:00
|
|
|
|
2013-05-30 19:12:14 +08:00
|
|
|
// Tell the application the loading has been done.
|
2013-06-03 15:31:46 +08:00
|
|
|
void WillFinishLaunching();
|
2013-05-30 19:12:14 +08:00
|
|
|
void DidFinishLaunching();
|
|
|
|
|
2015-10-28 19:34:01 +08:00
|
|
|
// Request basic auth login.
|
|
|
|
void RequestLogin(LoginHandler* login_handler);
|
|
|
|
|
2016-03-03 23:58:58 -05:00
|
|
|
// Tell the application that plaform's theme changed.
|
|
|
|
void PlatformThemeChanged();
|
2016-03-01 15:05:44 -05:00
|
|
|
|
2013-05-03 10:53:54 +08:00
|
|
|
void AddObserver(BrowserObserver* obs) {
|
|
|
|
observers_.AddObserver(obs);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RemoveObserver(BrowserObserver* obs) {
|
|
|
|
observers_.RemoveObserver(obs);
|
|
|
|
}
|
2013-05-02 23:43:23 +08:00
|
|
|
|
2015-10-22 16:24:35 +08:00
|
|
|
bool is_shutting_down() const { return is_shutdown_; }
|
2013-06-26 17:22:24 +08:00
|
|
|
bool is_quiting() const { return is_quiting_; }
|
2014-10-30 21:32:35 +08:00
|
|
|
bool is_ready() const { return is_ready_; }
|
2013-06-26 17:22:24 +08:00
|
|
|
|
2013-05-02 23:43:23 +08:00
|
|
|
protected:
|
2013-12-05 10:26:01 +08:00
|
|
|
// Returns the version of application bundle or executable file.
|
|
|
|
std::string GetExecutableFileVersion() const;
|
|
|
|
|
2013-12-05 10:42:04 +08:00
|
|
|
// Returns the name of application bundle or executable file.
|
|
|
|
std::string GetExecutableFileProductName() const;
|
|
|
|
|
2014-04-10 15:22:17 +08:00
|
|
|
// Send the will-quit message and then shutdown the application.
|
|
|
|
void NotifyAndShutdown();
|
2013-05-03 10:53:54 +08:00
|
|
|
|
2015-02-25 19:33:42 -08:00
|
|
|
// Send the before-quit message and start closing windows.
|
|
|
|
bool HandleBeforeQuit();
|
|
|
|
|
2013-05-02 23:43:23 +08:00
|
|
|
bool is_quiting_;
|
|
|
|
|
|
|
|
private:
|
|
|
|
// WindowListObserver implementations:
|
2014-11-16 19:47:04 +08:00
|
|
|
void OnWindowCloseCancelled(NativeWindow* window) override;
|
|
|
|
void OnWindowAllClosed() override;
|
2013-05-02 23:43:23 +08:00
|
|
|
|
2013-05-03 10:53:54 +08:00
|
|
|
// Observers of the browser.
|
2015-09-02 15:16:49 +08:00
|
|
|
base::ObserverList<BrowserObserver> observers_;
|
2013-05-03 10:53:54 +08:00
|
|
|
|
2014-10-30 21:32:35 +08:00
|
|
|
// Whether "ready" event has been emitted.
|
|
|
|
bool is_ready_;
|
|
|
|
|
2015-10-04 19:20:52 +08:00
|
|
|
// The browse is being shutdown.
|
|
|
|
bool is_shutdown_;
|
|
|
|
|
2013-12-05 10:26:01 +08:00
|
|
|
std::string version_override_;
|
2013-12-05 10:32:58 +08:00
|
|
|
std::string name_override_;
|
2013-12-05 10:26:01 +08:00
|
|
|
|
2014-11-17 15:55:49 +08:00
|
|
|
#if defined(OS_WIN)
|
|
|
|
base::string16 app_user_model_id_;
|
|
|
|
#endif
|
|
|
|
|
2013-05-02 23:43:23 +08:00
|
|
|
DISALLOW_COPY_AND_ASSIGN(Browser);
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace atom
|
|
|
|
|
|
|
|
#endif // ATOM_BROWSER_BROWSER_H_
|