electron/atom/browser/atom_browser_main_parts.h

148 lines
4 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
2013-04-12 01:46:58 +00:00
// found in the LICENSE file.
2014-03-16 00:58:59 +00:00
#ifndef ATOM_BROWSER_ATOM_BROWSER_MAIN_PARTS_H_
#define ATOM_BROWSER_ATOM_BROWSER_MAIN_PARTS_H_
2013-04-12 01:46:58 +00:00
2015-06-24 09:58:12 +00:00
#include <list>
#include <memory>
2015-08-06 15:01:05 +00:00
#include <string>
2015-06-24 09:58:12 +00:00
#include "base/callback.h"
2014-10-17 04:41:40 +00:00
#include "base/timer/timer.h"
2015-08-06 15:01:05 +00:00
#include "content/public/browser/browser_context.h"
#include "content/public/browser/browser_main_parts.h"
#include "content/public/common/main_function_params.h"
#include "services/device/public/mojom/geolocation_control.mojom.h"
#include "ui/views/layout/layout_provider.h"
2013-04-12 01:46:58 +00:00
class BrowserProcess;
class IconManager;
#if defined(USE_AURA)
namespace wm {
class WMState;
}
#endif
2013-04-12 01:46:58 +00:00
namespace atom {
class AtomBindings;
class Browser;
class JavascriptEnvironment;
2013-04-13 10:39:09 +00:00
class NodeBindings;
class NodeDebugger;
class NodeEnvironment;
class BridgeTaskRunner;
2013-04-13 10:39:09 +00:00
#if defined(TOOLKIT_VIEWS)
class ViewsDelegate;
#endif
2018-04-19 06:26:34 +00:00
#if defined(OS_MACOSX)
class ViewsDelegateMac;
#endif
class AtomBrowserMainParts : public content::BrowserMainParts {
2013-04-12 15:16:16 +00:00
public:
explicit AtomBrowserMainParts(const content::MainFunctionParams& params);
~AtomBrowserMainParts() override;
2013-04-12 01:46:58 +00:00
static AtomBrowserMainParts* Get();
2016-03-08 04:22:03 +00:00
// Sets the exit code, will fail if the message loop is not ready.
bool SetExitCode(int code);
2015-12-10 02:09:59 +00:00
// Gets the exit code
int GetExitCode();
2015-06-24 09:58:12 +00:00
// Register a callback that should be destroyed before JavaScript environment
// gets destroyed.
// Returns a closure that can be used to remove |callback| from the list.
void RegisterDestructionCallback(base::OnceClosure callback);
2015-06-24 09:58:12 +00:00
// Returns the connection to GeolocationControl which can be
// used to enable the location services once per client.
device::mojom::GeolocationControl* GetGeolocationControl();
// Returns handle to the class responsible for extracting file icons.
IconManager* GetIconManager();
Browser* browser() { return browser_.get(); }
2013-04-12 15:16:16 +00:00
protected:
// content::BrowserMainParts:
int PreEarlyInitialization() override;
2015-01-10 01:24:36 +00:00
void PostEarlyInitialization() override;
int PreCreateThreads() override;
2018-04-19 06:26:34 +00:00
void ToolkitInitialized() override;
2015-01-10 01:24:36 +00:00
void PreMainMessageLoopRun() override;
bool MainMessageLoopRun(int* result_code) override;
void PreDefaultMainMessageLoopRun(base::OnceClosure quit_closure) override;
2015-10-04 11:21:36 +00:00
void PostMainMessageLoopStart() override;
void PostMainMessageLoopRun() override;
2015-01-10 01:24:36 +00:00
void PreMainMessageLoopStart() override;
void PostDestroyThreads() override;
2013-04-12 01:46:58 +00:00
2013-04-13 10:39:09 +00:00
private:
void InitializeFeatureList();
void OverrideAppLogsPath();
void PreMainMessageLoopStartCommon();
2015-10-04 11:21:36 +00:00
#if defined(OS_POSIX)
// Set signal handlers.
void HandleSIGCHLD();
void HandleShutdownSignals();
#endif
#if defined(OS_MACOSX)
void FreeAppDelegate();
void InitializeMainNib();
#endif
2018-04-19 06:26:34 +00:00
#if defined(OS_MACOSX)
std::unique_ptr<ViewsDelegateMac> views_delegate_;
#else
std::unique_ptr<ViewsDelegate> views_delegate_;
2018-04-19 06:26:34 +00:00
#endif
#if defined(USE_AURA)
std::unique_ptr<wm::WMState> wm_state_;
#endif
std::unique_ptr<views::LayoutProvider> layout_provider_;
std::string custom_locale_;
// A fake BrowserProcess object that used to feed the source code from chrome.
std::unique_ptr<BrowserProcessImpl> fake_browser_process_;
// Pointer to exit code.
int* exit_code_ = nullptr;
2016-05-23 01:59:39 +00:00
std::unique_ptr<Browser> browser_;
std::unique_ptr<JavascriptEnvironment> js_env_;
std::unique_ptr<NodeBindings> node_bindings_;
std::unique_ptr<AtomBindings> atom_bindings_;
std::unique_ptr<NodeEnvironment> node_env_;
std::unique_ptr<NodeDebugger> node_debugger_;
std::unique_ptr<IconManager> icon_manager_;
base::RepeatingTimer gc_timer_;
2014-10-17 04:41:40 +00:00
2015-06-24 09:58:12 +00:00
// List of callbacks should be executed before destroying JS env.
std::list<base::OnceClosure> destructors_;
2015-06-24 09:58:12 +00:00
device::mojom::GeolocationControlPtr geolocation_control_;
const content::MainFunctionParams main_function_params_;
static AtomBrowserMainParts* self_;
2013-04-12 01:46:58 +00:00
DISALLOW_COPY_AND_ASSIGN(AtomBrowserMainParts);
};
} // namespace atom
2014-03-16 00:58:59 +00:00
#endif // ATOM_BROWSER_ATOM_BROWSER_MAIN_PARTS_H_