electron/atom/browser/browser.h

254 lines
6.5 KiB
C
Raw Normal View History

// Copyright (c) 2013 GitHub, Inc.
2014-04-25 09:49:37 +00:00
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#ifndef ATOM_BROWSER_BROWSER_H_
#define ATOM_BROWSER_BROWSER_H_
#include <string>
2014-11-17 09:19:41 +00:00
#include <vector>
2016-03-08 04:38:49 +00:00
#include "base/macros.h"
#include "base/compiler_specific.h"
#include "base/observer_list.h"
2015-11-03 07:16:45 +00:00
#include "base/strings/string16.h"
2014-03-16 00:30:26 +00:00
#include "atom/browser/browser_observer.h"
#include "atom/browser/window_list_observer.h"
2016-05-23 15:49:46 +00:00
#include "native_mate/arguments.h"
#if defined(OS_WIN)
2014-11-17 09:19:41 +00:00
#include "base/files/file_path.h"
#endif
2014-11-17 05:05:06 +00:00
namespace base {
class DictionaryValue;
2014-11-17 05:05:06 +00:00
class FilePath;
}
namespace gfx {
class Image;
}
namespace atom {
class AtomMenuModel;
2015-10-28 11:34:01 +00:00
class LoginHandler;
// 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();
// Exit the application immediately and set exit code.
void Exit(int code);
2014-04-10 07:22:17 +00:00
// Cleanup everything and shutdown the application gracefully.
void Shutdown();
2013-05-30 11:24:47 +00:00
// Focus the application.
void Focus();
// Returns the version of the executable (or bundle).
2013-12-05 02:26:01 +00:00
std::string GetVersion() const;
// Overrides the application version.
void SetVersion(const std::string& version);
// 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 05:05:06 +00:00
// Add the |path| to recent documents list.
void AddRecentDocument(const base::FilePath& path);
2014-11-17 08:13:47 +00:00
// Clear the recent documents list.
void ClearRecentDocuments();
// Set the application user model ID.
void SetAppUserModelID(const base::string16& name);
// Remove the default protocol handler registry key
2016-08-16 05:54:30 +00:00
bool RemoveAsDefaultProtocolClient(const std::string& protocol,
mate::Arguments* args);
// Set as default handler for a protocol.
2016-08-16 05:54:30 +00:00
bool SetAsDefaultProtocolClient(const std::string& protocol,
mate::Arguments* args);
2016-04-25 05:17:01 +00:00
// Query the current state of default handler for a protocol.
2016-08-16 05:54:30 +00:00
bool IsDefaultProtocolClient(const std::string& protocol,
mate::Arguments* args);
2016-04-25 05:17:01 +00:00
2016-07-01 08:39:01 +00:00
// Set/Get the badge count.
bool SetBadgeCount(int count);
2016-07-01 08:39:01 +00:00
int GetBadgeCount();
// Set/Get the login item settings of the app
2016-07-07 23:29:09 +00:00
struct LoginItemSettings {
bool open_at_login = false;
bool open_as_hidden = false;
bool restore_state = false;
bool opened_at_login = false;
bool opened_as_hidden = false;
};
void SetLoginItemSettings(LoginItemSettings settings);
LoginItemSettings GetLoginItemSettings();
2016-07-07 23:29:09 +00:00
#if defined(OS_MACOSX)
2016-01-29 21:51:06 +00:00
// Hide the application.
void Hide();
2016-01-30 20:40:32 +00:00
// Show the application.
void Show();
// Creates an activity and sets it as the one currently in use.
2016-04-30 05:05:36 +00:00
void SetUserActivity(const std::string& type,
2016-05-23 15:49:46 +00:00
const base::DictionaryValue& user_info,
mate::Arguments* args);
2016-04-30 05:05:36 +00:00
// Returns the type name of the current user activity.
std::string GetCurrentActivityType();
// Resumes an activity via hand-off.
bool ContinueUserActivity(const std::string& type,
const base::DictionaryValue& user_info);
2013-08-06 08:19:56 +00:00
// Bounce the dock icon.
enum BounceType {
BOUNCE_CRITICAL = 0,
BOUNCE_INFORMATIONAL = 10,
};
int DockBounce(BounceType type);
void DockCancelBounce(int request_id);
// Bounce the Downloads stack.
void DockDownloadFinished(const std::string& filePath);
2013-08-06 08:39:31 +00:00
// Set/Get dock's badge text.
2013-08-06 08:19:56 +00:00
void DockSetBadgeText(const std::string& label);
2013-08-06 08:39:31 +00:00
std::string DockGetBadgeText();
// Hide/Show dock.
void DockHide();
void DockShow();
2016-08-01 22:22:37 +00:00
bool DockIsVisible();
2014-11-16 15:04:31 +00:00
// Set docks' menu.
void DockSetMenu(AtomMenuModel* model);
// Set docks' icon.
void DockSetIcon(const gfx::Image& image);
2013-08-06 08:19:56 +00:00
#endif // defined(OS_MACOSX)
#if defined(OS_WIN)
2014-11-17 09:19:41 +00:00
struct UserTask {
base::FilePath program;
base::string16 arguments;
base::string16 title;
base::string16 description;
2014-11-17 09:35:51 +00:00
base::FilePath icon_path;
int icon_index;
2014-11-17 09:19:41 +00:00
};
// Add a custom task to jump list.
bool SetUserTasks(const std::vector<UserTask>& tasks);
2014-11-17 09:19:41 +00: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();
2016-06-26 00:00:41 +00:00
#endif // defined(OS_WIN)
#if defined(OS_LINUX)
2016-07-01 08:39:01 +00:00
// Whether Unity launcher is running.
bool IsUnityRunning();
2016-06-26 00:00:41 +00:00
#endif // defined(OS_LINUX)
// Tell the application to open a file.
bool OpenFile(const std::string& file_path);
// Tell the application to open a url.
void OpenURL(const std::string& url);
// Tell the application that application is activated with visible/invisible
// windows.
2015-09-15 02:05:53 +00:00
void Activate(bool has_visible_windows);
// Tell the application the loading has been done.
void WillFinishLaunching();
void DidFinishLaunching();
void OnAccessibilitySupportChanged();
2015-10-28 11:34:01 +00:00
// Request basic auth login.
void RequestLogin(LoginHandler* login_handler,
std::unique_ptr<base::DictionaryValue> request_details);
2015-10-28 11:34:01 +00:00
void AddObserver(BrowserObserver* obs) {
observers_.AddObserver(obs);
}
void RemoveObserver(BrowserObserver* obs) {
observers_.RemoveObserver(obs);
}
bool is_shutting_down() const { return is_shutdown_; }
bool is_quiting() const { return is_quiting_; }
bool is_ready() const { return is_ready_; }
protected:
2013-12-05 02:26:01 +00:00
// Returns the version of application bundle or executable file.
std::string GetExecutableFileVersion() const;
// Returns the name of application bundle or executable file.
std::string GetExecutableFileProductName() const;
2014-04-10 07:22:17 +00:00
// Send the will-quit message and then shutdown the application.
void NotifyAndShutdown();
// Send the before-quit message and start closing windows.
bool HandleBeforeQuit();
bool is_quiting_;
private:
// WindowListObserver implementations:
2014-11-16 11:47:04 +00:00
void OnWindowCloseCancelled(NativeWindow* window) override;
void OnWindowAllClosed() override;
// Observers of the browser.
2015-09-02 07:16:49 +00:00
base::ObserverList<BrowserObserver> observers_;
// Whether `app.exit()` has been called
bool is_exiting_;
// Whether "ready" event has been emitted.
bool is_ready_;
// The browser is being shutdown.
2015-10-04 11:20:52 +00:00
bool is_shutdown_;
2013-12-05 02:26:01 +00:00
std::string version_override_;
std::string name_override_;
2013-12-05 02:26:01 +00:00
2016-07-02 01:36:11 +00:00
int badge_count_ = 0;
#if defined(OS_WIN)
base::string16 app_user_model_id_;
#endif
DISALLOW_COPY_AND_ASSIGN(Browser);
};
} // namespace atom
#endif // ATOM_BROWSER_BROWSER_H_