2014-10-31 18:17:05 +00:00
|
|
|
// 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
|
2013-05-02 15:43:23 +00:00
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
|
|
#ifndef ATOM_BROWSER_BROWSER_H_
|
|
|
|
#define ATOM_BROWSER_BROWSER_H_
|
|
|
|
|
2018-09-13 00:25:56 +00:00
|
|
|
#include <memory>
|
2014-03-16 01:13:06 +00:00
|
|
|
#include <string>
|
2014-11-17 09:19:41 +00:00
|
|
|
#include <vector>
|
2014-03-16 01:13:06 +00:00
|
|
|
|
2016-08-26 22:30:02 +00:00
|
|
|
#include "atom/browser/browser_observer.h"
|
|
|
|
#include "atom/browser/window_list_observer.h"
|
2018-06-27 21:06:08 +00:00
|
|
|
#include "atom/common/promise_util.h"
|
2013-05-02 15:43:23 +00:00
|
|
|
#include "base/compiler_specific.h"
|
2016-08-26 22:30:02 +00:00
|
|
|
#include "base/macros.h"
|
2013-05-03 02:53:54 +00:00
|
|
|
#include "base/observer_list.h"
|
2015-11-03 07:16:45 +00:00
|
|
|
#include "base/strings/string16.h"
|
2016-10-10 20:30:58 +00:00
|
|
|
#include "base/values.h"
|
2016-05-23 15:49:46 +00:00
|
|
|
#include "native_mate/arguments.h"
|
2013-05-02 15:43:23 +00:00
|
|
|
|
2014-11-17 07:55:49 +00:00
|
|
|
#if defined(OS_WIN)
|
2018-04-19 12:27:57 +00:00
|
|
|
#include <windows.h>
|
2014-11-17 09:19:41 +00:00
|
|
|
#include "base/files/file_path.h"
|
2014-11-17 07:55:49 +00:00
|
|
|
#endif
|
|
|
|
|
2014-11-17 05:05:06 +00:00
|
|
|
namespace base {
|
|
|
|
class FilePath;
|
|
|
|
}
|
|
|
|
|
2016-01-23 23:30:14 +00:00
|
|
|
namespace gfx {
|
|
|
|
class Image;
|
|
|
|
}
|
|
|
|
|
2013-05-02 15:43:23 +00:00
|
|
|
namespace atom {
|
|
|
|
|
2016-07-02 02:47:40 +00:00
|
|
|
class AtomMenuModel;
|
2015-10-28 11:34:01 +00:00
|
|
|
|
2013-05-02 15:43:23 +00:00
|
|
|
// This class is used for control application-wide operations.
|
|
|
|
class Browser : public WindowListObserver {
|
|
|
|
public:
|
|
|
|
Browser();
|
2018-04-17 23:03:51 +00:00
|
|
|
~Browser() override;
|
2013-05-02 15:43:23 +00:00
|
|
|
|
|
|
|
static Browser* Get();
|
|
|
|
|
|
|
|
// Try to close all windows and quit the application.
|
|
|
|
void Quit();
|
|
|
|
|
2015-11-06 10:27:13 +00:00
|
|
|
// Exit the application immediately and set exit code.
|
2016-08-30 03:30:56 +00:00
|
|
|
void Exit(mate::Arguments* args);
|
2015-11-06 10:27:13 +00:00
|
|
|
|
2014-04-10 07:22:17 +00:00
|
|
|
// Cleanup everything and shutdown the application gracefully.
|
|
|
|
void Shutdown();
|
2013-05-02 15:43:23 +00:00
|
|
|
|
2013-05-30 11:24:47 +00:00
|
|
|
// Focus the application.
|
|
|
|
void Focus();
|
|
|
|
|
2013-06-19 05:41:54 +00:00
|
|
|
// 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);
|
2013-06-19 05:41:54 +00:00
|
|
|
|
2016-09-16 22:57:07 +00:00
|
|
|
// Returns the application's name, default is just Electron.
|
2013-12-05 02:32:58 +00:00
|
|
|
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();
|
|
|
|
|
2015-11-03 07:09:31 +00:00
|
|
|
// Set the application user model ID.
|
|
|
|
void SetAppUserModelID(const base::string16& name);
|
|
|
|
|
2016-03-24 17:55:09 +00:00
|
|
|
// Remove the default protocol handler registry key
|
2016-08-16 05:54:30 +00:00
|
|
|
bool RemoveAsDefaultProtocolClient(const std::string& protocol,
|
2016-08-22 00:50:58 +00:00
|
|
|
mate::Arguments* args);
|
2016-03-24 17:55:09 +00:00
|
|
|
|
2016-03-21 18:24:25 +00:00
|
|
|
// 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-03-21 18:24:25 +00:00
|
|
|
|
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,
|
2016-08-22 00:50:58 +00:00
|
|
|
mate::Arguments* args);
|
2016-04-25 05:17:01 +00:00
|
|
|
|
2016-07-01 08:39:01 +00:00
|
|
|
// Set/Get the badge count.
|
2016-07-01 13:18:39 +00:00
|
|
|
bool SetBadgeCount(int count);
|
2016-07-01 08:39:01 +00:00
|
|
|
int GetBadgeCount();
|
|
|
|
|
2016-07-11 17:57:53 +00:00
|
|
|
// 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;
|
2017-01-30 22:01:40 +00:00
|
|
|
base::string16 path;
|
|
|
|
std::vector<base::string16> args;
|
2018-04-17 23:37:22 +00:00
|
|
|
|
|
|
|
LoginItemSettings();
|
|
|
|
~LoginItemSettings();
|
|
|
|
LoginItemSettings(const LoginItemSettings&);
|
2016-07-07 23:29:09 +00:00
|
|
|
};
|
2017-01-30 22:01:40 +00:00
|
|
|
void SetLoginItemSettings(LoginItemSettings settings);
|
2017-03-29 19:29:52 +00:00
|
|
|
LoginItemSettings GetLoginItemSettings(const LoginItemSettings& options);
|
2016-07-07 23:29:09 +00:00
|
|
|
|
2016-07-11 17:57:53 +00:00
|
|
|
#if defined(OS_MACOSX)
|
2018-02-05 07:13:35 +00:00
|
|
|
// Set the handler which decides whether to shutdown.
|
|
|
|
void SetShutdownHandler(base::Callback<bool()> handler);
|
|
|
|
|
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();
|
|
|
|
|
2016-04-30 00:35:07 +00:00
|
|
|
// 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
|
|
|
|
2016-05-03 22:51:31 +00:00
|
|
|
// Returns the type name of the current user activity.
|
|
|
|
std::string GetCurrentActivityType();
|
|
|
|
|
2017-06-26 19:14:44 +00:00
|
|
|
// Invalidates the current user activity.
|
|
|
|
void InvalidateCurrentActivity();
|
|
|
|
|
|
|
|
// Updates the current user activity
|
|
|
|
void UpdateCurrentActivity(const std::string& type,
|
|
|
|
const base::DictionaryValue& user_info);
|
|
|
|
|
|
|
|
// Indicates that an user activity is about to be resumed.
|
|
|
|
bool WillContinueUserActivity(const std::string& type);
|
|
|
|
|
|
|
|
// Indicates a failure to resume a Handoff activity.
|
|
|
|
void DidFailToContinueUserActivity(const std::string& type,
|
|
|
|
const std::string& error);
|
|
|
|
|
2016-04-30 00:36:04 +00:00
|
|
|
// Resumes an activity via hand-off.
|
2016-05-05 07:26:44 +00:00
|
|
|
bool ContinueUserActivity(const std::string& type,
|
|
|
|
const base::DictionaryValue& user_info);
|
2016-04-30 00:36:04 +00:00
|
|
|
|
2017-06-26 19:14:44 +00:00
|
|
|
// Indicates that an activity was continued on another device.
|
|
|
|
void UserActivityWasContinued(const std::string& type,
|
|
|
|
const base::DictionaryValue& user_info);
|
|
|
|
|
|
|
|
// Gives an oportunity to update the Handoff payload.
|
2017-08-09 15:09:47 +00:00
|
|
|
bool UpdateUserActivityState(const std::string& type,
|
2017-06-26 19:14:44 +00:00
|
|
|
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);
|
|
|
|
|
2016-05-10 19:02:56 +00:00
|
|
|
// 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();
|
2014-06-25 03:55:33 +00:00
|
|
|
|
|
|
|
// Hide/Show dock.
|
|
|
|
void DockHide();
|
2019-02-13 05:06:33 +00:00
|
|
|
v8::Local<v8::Promise> DockShow(v8::Isolate* isolate);
|
2016-08-01 22:22:37 +00:00
|
|
|
bool DockIsVisible();
|
2014-11-16 15:04:31 +00:00
|
|
|
|
|
|
|
// Set docks' menu.
|
2016-07-02 02:47:40 +00:00
|
|
|
void DockSetMenu(AtomMenuModel* model);
|
2016-01-23 23:30:14 +00:00
|
|
|
|
|
|
|
// Set docks' icon.
|
|
|
|
void DockSetIcon(const gfx::Image& image);
|
2016-10-10 20:30:58 +00:00
|
|
|
|
2018-11-13 22:12:24 +00:00
|
|
|
#endif // defined(OS_MACOSX)
|
|
|
|
|
|
|
|
#if defined(OS_MACOSX) || defined(OS_LINUX)
|
2016-10-10 20:30:58 +00:00
|
|
|
void ShowAboutPanel();
|
|
|
|
void SetAboutPanelOptions(const base::DictionaryValue& options);
|
2018-11-13 22:12:24 +00:00
|
|
|
#endif
|
2013-08-06 08:19:56 +00:00
|
|
|
|
2014-11-17 07:55:49 +00:00
|
|
|
#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;
|
2018-06-25 20:30:00 +00:00
|
|
|
|
|
|
|
UserTask();
|
|
|
|
UserTask(const UserTask&);
|
|
|
|
~UserTask();
|
2014-11-17 09:19:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Add a custom task to jump list.
|
2016-08-07 22:22:32 +00:00
|
|
|
bool SetUserTasks(const std::vector<UserTask>& tasks);
|
2014-11-17 09:19:41 +00:00
|
|
|
|
2015-11-03 06:55:43 +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)
|
2016-06-25 23:55:24 +00:00
|
|
|
|
|
|
|
#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)
|
2014-11-17 07:55:49 +00:00
|
|
|
|
2013-05-30 08:03:10 +00:00
|
|
|
// Tell the application to open a file.
|
|
|
|
bool OpenFile(const std::string& file_path);
|
|
|
|
|
2013-07-10 08:10:38 +00:00
|
|
|
// Tell the application to open a url.
|
|
|
|
void OpenURL(const std::string& url);
|
|
|
|
|
2017-06-11 08:19:01 +00:00
|
|
|
#if defined(OS_MACOSX)
|
|
|
|
// Tell the application to create a new window for a tab.
|
|
|
|
void NewWindowForTab();
|
|
|
|
#endif // defined(OS_MACOSX)
|
|
|
|
|
2015-09-15 01:34:27 +00:00
|
|
|
// 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);
|
2015-09-14 11:28:13 +00:00
|
|
|
|
2013-05-30 11:12:14 +00:00
|
|
|
// Tell the application the loading has been done.
|
2013-06-03 07:31:46 +00:00
|
|
|
void WillFinishLaunching();
|
2016-09-01 00:17:44 +00:00
|
|
|
void DidFinishLaunching(const base::DictionaryValue& launch_info);
|
2013-05-30 11:12:14 +00:00
|
|
|
|
2016-07-11 21:32:14 +00:00
|
|
|
void OnAccessibilitySupportChanged();
|
2016-07-11 21:04:56 +00:00
|
|
|
|
2015-10-28 11:34:01 +00:00
|
|
|
// Request basic auth login.
|
2018-08-23 09:55:13 +00:00
|
|
|
void RequestLogin(scoped_refptr<LoginHandler> login_handler,
|
2016-06-08 13:52:21 +00:00
|
|
|
std::unique_ptr<base::DictionaryValue> request_details);
|
2015-10-28 11:34:01 +00:00
|
|
|
|
2017-09-15 19:33:12 +00:00
|
|
|
void PreMainMessageLoopRun();
|
|
|
|
|
2018-10-03 21:47:00 +00:00
|
|
|
// Stores the supplied |quit_closure|, to be run when the last Browser
|
|
|
|
// instance is destroyed.
|
2019-02-01 15:21:49 +00:00
|
|
|
void SetMainMessageLoopQuitClosure(base::OnceClosure quit_closure);
|
2018-10-03 21:47:00 +00:00
|
|
|
|
2018-04-18 01:44:10 +00:00
|
|
|
void AddObserver(BrowserObserver* obs) { observers_.AddObserver(obs); }
|
2013-05-03 02:53:54 +00:00
|
|
|
|
2018-04-18 01:44:10 +00:00
|
|
|
void RemoveObserver(BrowserObserver* obs) { observers_.RemoveObserver(obs); }
|
2013-05-02 15:43:23 +00:00
|
|
|
|
2015-10-22 08:24:35 +00:00
|
|
|
bool is_shutting_down() const { return is_shutdown_; }
|
2013-06-26 09:22:24 +00:00
|
|
|
bool is_quiting() const { return is_quiting_; }
|
2014-10-30 13:32:35 +00:00
|
|
|
bool is_ready() const { return is_ready_; }
|
2018-06-27 21:06:08 +00:00
|
|
|
util::Promise* WhenReady(v8::Isolate* isolate);
|
2013-06-26 09:22:24 +00:00
|
|
|
|
2013-05-02 15:43:23 +00:00
|
|
|
protected:
|
2013-12-05 02:26:01 +00:00
|
|
|
// Returns the version of application bundle or executable file.
|
|
|
|
std::string GetExecutableFileVersion() const;
|
|
|
|
|
2013-12-05 02:42:04 +00:00
|
|
|
// 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();
|
2013-05-03 02:53:54 +00:00
|
|
|
|
2015-02-26 03:33:42 +00:00
|
|
|
// Send the before-quit message and start closing windows.
|
|
|
|
bool HandleBeforeQuit();
|
|
|
|
|
2018-05-21 22:18:38 +00:00
|
|
|
bool is_quiting_ = false;
|
2013-05-02 15:43:23 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
// WindowListObserver implementations:
|
2014-11-16 11:47:04 +00:00
|
|
|
void OnWindowCloseCancelled(NativeWindow* window) override;
|
|
|
|
void OnWindowAllClosed() override;
|
2013-05-02 15:43:23 +00:00
|
|
|
|
2013-05-03 02:53:54 +00:00
|
|
|
// Observers of the browser.
|
2015-09-02 07:16:49 +00:00
|
|
|
base::ObserverList<BrowserObserver> observers_;
|
2013-05-03 02:53:54 +00:00
|
|
|
|
2016-03-31 14:12:03 +00:00
|
|
|
// Whether `app.exit()` has been called
|
2018-05-21 22:18:38 +00:00
|
|
|
bool is_exiting_ = false;
|
2016-03-31 14:12:03 +00:00
|
|
|
|
2014-10-30 13:32:35 +00:00
|
|
|
// Whether "ready" event has been emitted.
|
2018-05-21 22:18:38 +00:00
|
|
|
bool is_ready_ = false;
|
2014-10-30 13:32:35 +00:00
|
|
|
|
2016-03-31 14:12:03 +00:00
|
|
|
// The browser is being shutdown.
|
2018-05-21 22:18:38 +00:00
|
|
|
bool is_shutdown_ = false;
|
2015-10-04 11:20:52 +00:00
|
|
|
|
2019-02-01 15:21:49 +00:00
|
|
|
// Null until/unless the default main message loop is running.
|
|
|
|
base::OnceClosure quit_main_message_loop_;
|
|
|
|
|
2016-07-02 01:36:11 +00:00
|
|
|
int badge_count_ = 0;
|
2016-06-25 23:55:24 +00:00
|
|
|
|
2018-06-27 21:06:08 +00:00
|
|
|
util::Promise* ready_promise_ = nullptr;
|
|
|
|
|
2018-11-13 22:12:24 +00:00
|
|
|
#if defined(OS_LINUX) || defined(OS_MACOSX)
|
2016-10-10 20:30:58 +00:00
|
|
|
base::DictionaryValue about_panel_options_;
|
|
|
|
#endif
|
|
|
|
|
2013-05-02 15:43:23 +00:00
|
|
|
DISALLOW_COPY_AND_ASSIGN(Browser);
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace atom
|
|
|
|
|
|
|
|
#endif // ATOM_BROWSER_BROWSER_H_
|