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-04-12 09:46:58 +08:00
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2019-06-19 13:56:58 -07:00
|
|
|
#ifndef SHELL_BROWSER_ATOM_BROWSER_MAIN_PARTS_H_
|
|
|
|
#define SHELL_BROWSER_ATOM_BROWSER_MAIN_PARTS_H_
|
2013-04-12 09:46:58 +08:00
|
|
|
|
2015-06-24 17:58:12 +08:00
|
|
|
#include <list>
|
2018-09-12 19:25:56 -05:00
|
|
|
#include <memory>
|
2015-08-06 20:31:05 +05:30
|
|
|
#include <string>
|
2015-06-24 17:58:12 +08:00
|
|
|
|
|
|
|
#include "base/callback.h"
|
2019-02-22 16:27:18 -08:00
|
|
|
#include "base/metrics/field_trial.h"
|
2014-10-17 12:41:40 +08:00
|
|
|
#include "base/timer/timer.h"
|
2015-08-06 20:31:05 +05:30
|
|
|
#include "content/public/browser/browser_context.h"
|
2018-10-23 22:15:55 +02:00
|
|
|
#include "content/public/browser/browser_main_parts.h"
|
2018-10-04 23:38:56 +05:30
|
|
|
#include "content/public/common/main_function_params.h"
|
2019-07-24 19:01:08 -04:00
|
|
|
#include "electron/buildflags/buildflags.h"
|
2019-12-10 16:22:35 -08:00
|
|
|
#include "mojo/public/cpp/bindings/remote.h"
|
2018-04-12 15:23:49 +05:30
|
|
|
#include "services/device/public/mojom/geolocation_control.mojom.h"
|
2018-10-23 22:15:55 +02:00
|
|
|
#include "ui/views/layout/layout_provider.h"
|
2013-04-12 09:46:58 +08:00
|
|
|
|
2015-06-18 16:33:12 +08:00
|
|
|
class BrowserProcess;
|
2018-10-06 00:42:53 +05:30
|
|
|
class IconManager;
|
2015-06-18 16:33:12 +08:00
|
|
|
|
2018-10-23 22:15:55 +02:00
|
|
|
#if defined(USE_AURA)
|
|
|
|
namespace wm {
|
|
|
|
class WMState;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2019-06-19 14:23:04 -07:00
|
|
|
namespace electron {
|
2013-04-12 09:46:58 +08:00
|
|
|
|
2019-07-24 19:01:08 -04:00
|
|
|
class AtomBrowserContext;
|
2013-05-02 23:43:23 +08:00
|
|
|
class Browser;
|
2019-07-24 19:01:08 -04:00
|
|
|
class ElectronBindings;
|
2014-07-28 16:00:15 +08:00
|
|
|
class JavascriptEnvironment;
|
2013-04-13 18:39:09 +08:00
|
|
|
class NodeBindings;
|
2017-05-15 09:30:55 -07:00
|
|
|
class NodeDebugger;
|
2017-02-28 09:56:09 +09:00
|
|
|
class NodeEnvironment;
|
2015-09-02 15:52:17 +08:00
|
|
|
class BridgeTaskRunner;
|
2013-04-13 18:39:09 +08:00
|
|
|
|
2019-07-24 19:01:08 -04:00
|
|
|
#if BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS)
|
|
|
|
class AtomExtensionsClient;
|
|
|
|
class AtomExtensionsBrowserClient;
|
|
|
|
#endif
|
|
|
|
|
2018-10-19 15:50:30 +02:00
|
|
|
#if defined(TOOLKIT_VIEWS)
|
|
|
|
class ViewsDelegate;
|
|
|
|
#endif
|
|
|
|
|
2018-04-19 15:26:34 +09:00
|
|
|
#if defined(OS_MACOSX)
|
|
|
|
class ViewsDelegateMac;
|
|
|
|
#endif
|
|
|
|
|
2018-10-23 22:15:55 +02:00
|
|
|
class AtomBrowserMainParts : public content::BrowserMainParts {
|
2013-04-12 23:16:16 +08:00
|
|
|
public:
|
2018-10-04 23:38:56 +05:30
|
|
|
explicit AtomBrowserMainParts(const content::MainFunctionParams& params);
|
2018-04-17 16:03:51 -07:00
|
|
|
~AtomBrowserMainParts() override;
|
2013-04-12 09:46:58 +08:00
|
|
|
|
2013-04-22 21:32:48 +08:00
|
|
|
static AtomBrowserMainParts* Get();
|
|
|
|
|
2016-03-07 20:22:03 -08:00
|
|
|
// Sets the exit code, will fail if the message loop is not ready.
|
2015-11-06 18:27:13 +08:00
|
|
|
bool SetExitCode(int code);
|
|
|
|
|
2015-12-09 18:09:59 -08:00
|
|
|
// Gets the exit code
|
|
|
|
int GetExitCode();
|
|
|
|
|
2015-06-24 17:58:12 +08:00
|
|
|
// Register a callback that should be destroyed before JavaScript environment
|
|
|
|
// gets destroyed.
|
2015-12-03 17:04:40 +08:00
|
|
|
// Returns a closure that can be used to remove |callback| from the list.
|
2018-03-30 18:54:55 +05:30
|
|
|
void RegisterDestructionCallback(base::OnceClosure callback);
|
2015-06-24 17:58:12 +08:00
|
|
|
|
2018-08-23 21:21:46 +05:30
|
|
|
// Returns the connection to GeolocationControl which can be
|
|
|
|
// used to enable the location services once per client.
|
|
|
|
device::mojom::GeolocationControl* GetGeolocationControl();
|
|
|
|
|
2018-10-06 00:42:53 +05:30
|
|
|
// Returns handle to the class responsible for extracting file icons.
|
|
|
|
IconManager* GetIconManager();
|
|
|
|
|
2013-05-02 23:43:23 +08:00
|
|
|
Browser* browser() { return browser_.get(); }
|
2019-07-02 18:22:09 -07:00
|
|
|
BrowserProcessImpl* browser_process() { return fake_browser_process_.get(); }
|
2013-04-22 21:32:48 +08:00
|
|
|
|
2013-04-12 23:16:16 +08:00
|
|
|
protected:
|
2015-09-05 20:54:36 +08:00
|
|
|
// content::BrowserMainParts:
|
2018-04-05 23:09:37 +02:00
|
|
|
int PreEarlyInitialization() override;
|
2015-01-09 17:24:36 -08:00
|
|
|
void PostEarlyInitialization() override;
|
2017-12-16 14:51:29 +05:30
|
|
|
int PreCreateThreads() override;
|
2018-04-19 15:26:34 +09:00
|
|
|
void ToolkitInitialized() override;
|
2015-01-09 17:24:36 -08:00
|
|
|
void PreMainMessageLoopRun() override;
|
2015-11-06 18:27:13 +08:00
|
|
|
bool MainMessageLoopRun(int* result_code) override;
|
2018-10-03 14:47:00 -07:00
|
|
|
void PreDefaultMainMessageLoopRun(base::OnceClosure quit_closure) override;
|
2015-10-04 19:21:36 +08:00
|
|
|
void PostMainMessageLoopStart() override;
|
2015-09-09 19:27:08 +08:00
|
|
|
void PostMainMessageLoopRun() override;
|
2015-01-09 17:24:36 -08:00
|
|
|
void PreMainMessageLoopStart() override;
|
2019-11-21 18:05:41 -08:00
|
|
|
void PostCreateThreads() override;
|
2018-10-04 23:38:56 +05:30
|
|
|
void PostDestroyThreads() override;
|
2013-04-12 09:46:58 +08:00
|
|
|
|
2013-04-13 18:39:09 +08:00
|
|
|
private:
|
2018-10-23 22:15:55 +02:00
|
|
|
void PreMainMessageLoopStartCommon();
|
|
|
|
|
2015-10-04 19:21:36 +08:00
|
|
|
#if defined(OS_POSIX)
|
|
|
|
// Set signal handlers.
|
|
|
|
void HandleSIGCHLD();
|
|
|
|
void HandleShutdownSignals();
|
|
|
|
#endif
|
|
|
|
|
2015-11-04 17:23:27 +08:00
|
|
|
#if defined(OS_MACOSX)
|
|
|
|
void FreeAppDelegate();
|
2019-10-10 17:54:03 +02:00
|
|
|
void RegisterURLHandler();
|
2019-10-21 14:11:09 -07:00
|
|
|
void InitializeMainNib();
|
2015-11-04 17:23:27 +08:00
|
|
|
#endif
|
|
|
|
|
2018-04-19 15:26:34 +09:00
|
|
|
#if defined(OS_MACOSX)
|
|
|
|
std::unique_ptr<ViewsDelegateMac> views_delegate_;
|
2018-04-19 15:38:33 +09:00
|
|
|
#else
|
2018-10-19 15:50:30 +02:00
|
|
|
std::unique_ptr<ViewsDelegate> views_delegate_;
|
2018-04-19 15:26:34 +09:00
|
|
|
#endif
|
|
|
|
|
2018-10-23 22:15:55 +02:00
|
|
|
#if defined(USE_AURA)
|
|
|
|
std::unique_ptr<wm::WMState> wm_state_;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
std::unique_ptr<views::LayoutProvider> layout_provider_;
|
|
|
|
|
2015-06-18 16:33:12 +08:00
|
|
|
// A fake BrowserProcess object that used to feed the source code from chrome.
|
2018-10-11 15:52:12 +02:00
|
|
|
std::unique_ptr<BrowserProcessImpl> fake_browser_process_;
|
2015-06-18 16:33:12 +08:00
|
|
|
|
2015-11-06 18:27:13 +08:00
|
|
|
// Pointer to exit code.
|
2018-05-22 00:18:38 +02:00
|
|
|
int* exit_code_ = nullptr;
|
2015-11-06 18:27:13 +08:00
|
|
|
|
2016-05-23 10:59:39 +09:00
|
|
|
std::unique_ptr<Browser> browser_;
|
|
|
|
std::unique_ptr<JavascriptEnvironment> js_env_;
|
|
|
|
std::unique_ptr<NodeBindings> node_bindings_;
|
2019-03-18 12:37:06 -07:00
|
|
|
std::unique_ptr<ElectronBindings> electron_bindings_;
|
2017-03-20 13:01:28 -07:00
|
|
|
std::unique_ptr<NodeEnvironment> node_env_;
|
2017-05-15 09:30:55 -07:00
|
|
|
std::unique_ptr<NodeDebugger> node_debugger_;
|
2018-10-06 00:42:53 +05:30
|
|
|
std::unique_ptr<IconManager> icon_manager_;
|
2019-02-22 16:27:18 -08:00
|
|
|
std::unique_ptr<base::FieldTrialList> field_trial_list_;
|
2014-06-30 14:16:16 +08:00
|
|
|
|
2019-07-24 19:01:08 -04:00
|
|
|
#if BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS)
|
|
|
|
std::unique_ptr<AtomExtensionsClient> extensions_client_;
|
|
|
|
std::unique_ptr<AtomExtensionsBrowserClient> extensions_browser_client_;
|
|
|
|
#endif
|
|
|
|
|
2018-10-02 12:05:51 -07:00
|
|
|
base::RepeatingTimer gc_timer_;
|
2014-10-17 12:41:40 +08:00
|
|
|
|
2015-06-24 17:58:12 +08:00
|
|
|
// List of callbacks should be executed before destroying JS env.
|
2018-03-30 18:54:55 +05:30
|
|
|
std::list<base::OnceClosure> destructors_;
|
2015-06-24 17:58:12 +08:00
|
|
|
|
2019-12-10 16:22:35 -08:00
|
|
|
mojo::Remote<device::mojom::GeolocationControl> geolocation_control_;
|
2018-04-12 15:23:49 +05:30
|
|
|
|
2013-04-22 21:32:48 +08:00
|
|
|
static AtomBrowserMainParts* self_;
|
|
|
|
|
2013-04-12 09:46:58 +08:00
|
|
|
DISALLOW_COPY_AND_ASSIGN(AtomBrowserMainParts);
|
|
|
|
};
|
|
|
|
|
2019-06-19 14:23:04 -07:00
|
|
|
} // namespace electron
|
2013-04-12 09:46:58 +08:00
|
|
|
|
2019-06-19 13:56:58 -07:00
|
|
|
#endif // SHELL_BROWSER_ATOM_BROWSER_MAIN_PARTS_H_
|