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-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>
|
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"
|
2013-04-12 01:46:58 +00:00
|
|
|
#include "brightray/browser/browser_main_parts.h"
|
2015-08-06 15:01:05 +00:00
|
|
|
#include "content/public/browser/browser_context.h"
|
2013-04-12 01:46:58 +00:00
|
|
|
|
2015-06-18 08:33:12 +00:00
|
|
|
class BrowserProcess;
|
|
|
|
|
2018-04-19 06:38:33 +00:00
|
|
|
#if defined(TOOLKIT_VIEWS)
|
|
|
|
namespace brightray {
|
|
|
|
class ViewsDelegate;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-04-12 01:46:58 +00:00
|
|
|
namespace atom {
|
|
|
|
|
2014-04-25 08:13:16 +00:00
|
|
|
class AtomBindings;
|
2013-05-02 15:43:23 +00:00
|
|
|
class Browser;
|
2014-07-28 08:00:15 +00:00
|
|
|
class JavascriptEnvironment;
|
2013-04-13 10:39:09 +00:00
|
|
|
class NodeBindings;
|
2017-05-15 16:30:55 +00:00
|
|
|
class NodeDebugger;
|
2017-02-28 00:56:09 +00:00
|
|
|
class NodeEnvironment;
|
2015-09-02 07:52:17 +00:00
|
|
|
class BridgeTaskRunner;
|
2013-04-13 10:39:09 +00:00
|
|
|
|
2018-04-19 06:26:34 +00:00
|
|
|
#if defined(OS_MACOSX)
|
|
|
|
class ViewsDelegateMac;
|
|
|
|
#endif
|
|
|
|
|
2013-04-12 01:46:58 +00:00
|
|
|
class AtomBrowserMainParts : public brightray::BrowserMainParts {
|
2013-04-12 15:16:16 +00:00
|
|
|
public:
|
2013-04-12 01:46:58 +00:00
|
|
|
AtomBrowserMainParts();
|
2018-04-17 23:03:51 +00:00
|
|
|
~AtomBrowserMainParts() override;
|
2013-04-12 01:46:58 +00:00
|
|
|
|
2013-04-22 13:32:48 +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.
|
2015-11-06 10:27:13 +00:00
|
|
|
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.
|
2015-12-03 09:04:40 +00:00
|
|
|
// Returns a closure that can be used to remove |callback| from the list.
|
2018-03-30 13:24:55 +00:00
|
|
|
void RegisterDestructionCallback(base::OnceClosure callback);
|
2015-06-24 09:58:12 +00:00
|
|
|
|
2013-05-02 15:43:23 +00:00
|
|
|
Browser* browser() { return browser_.get(); }
|
2013-04-22 13:32:48 +00:00
|
|
|
|
2013-04-12 15:16:16 +00:00
|
|
|
protected:
|
2015-09-05 12:54:36 +00:00
|
|
|
// content::BrowserMainParts:
|
2018-04-05 21:09:37 +00:00
|
|
|
int PreEarlyInitialization() override;
|
2015-01-10 01:24:36 +00:00
|
|
|
void PostEarlyInitialization() override;
|
2017-12-16 09:21:29 +00:00
|
|
|
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;
|
2015-11-06 10:27:13 +00:00
|
|
|
bool MainMessageLoopRun(int* result_code) override;
|
2015-10-04 11:21:36 +00:00
|
|
|
void PostMainMessageLoopStart() override;
|
2015-09-09 11:27:08 +00:00
|
|
|
void PostMainMessageLoopRun() override;
|
2013-07-04 12:09:11 +00:00
|
|
|
#if defined(OS_MACOSX)
|
2015-01-10 01:24:36 +00:00
|
|
|
void PreMainMessageLoopStart() override;
|
2013-07-04 12:09:11 +00:00
|
|
|
#endif
|
2013-04-12 01:46:58 +00:00
|
|
|
|
2013-04-13 10:39:09 +00:00
|
|
|
private:
|
2015-10-04 11:21:36 +00:00
|
|
|
#if defined(OS_POSIX)
|
|
|
|
// Set signal handlers.
|
|
|
|
void HandleSIGCHLD();
|
|
|
|
void HandleShutdownSignals();
|
|
|
|
#endif
|
|
|
|
|
2015-11-04 09:23:27 +00:00
|
|
|
#if defined(OS_MACOSX)
|
|
|
|
void FreeAppDelegate();
|
|
|
|
#endif
|
|
|
|
|
2018-04-19 06:26:34 +00:00
|
|
|
#if defined(OS_MACOSX)
|
|
|
|
std::unique_ptr<ViewsDelegateMac> views_delegate_;
|
2018-04-19 06:38:33 +00:00
|
|
|
#else
|
|
|
|
std::unique_ptr<brightray::ViewsDelegate> views_delegate_;
|
2018-04-19 06:26:34 +00:00
|
|
|
#endif
|
|
|
|
|
2015-06-18 08:33:12 +00:00
|
|
|
// A fake BrowserProcess object that used to feed the source code from chrome.
|
2016-05-23 01:59:39 +00:00
|
|
|
std::unique_ptr<BrowserProcess> fake_browser_process_;
|
2015-06-18 08:33:12 +00:00
|
|
|
|
2015-09-02 07:52:17 +00:00
|
|
|
// The gin::PerIsolateData requires a task runner to create, so we feed it
|
|
|
|
// with a task runner that will post all work to main loop.
|
|
|
|
scoped_refptr<BridgeTaskRunner> bridge_task_runner_;
|
|
|
|
|
2015-11-06 10:27:13 +00:00
|
|
|
// Pointer to exit code.
|
2018-05-21 22:18:38 +00:00
|
|
|
int* exit_code_ = nullptr;
|
2015-11-06 10:27:13 +00:00
|
|
|
|
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_;
|
2017-03-20 20:01:28 +00:00
|
|
|
std::unique_ptr<NodeEnvironment> node_env_;
|
2017-05-15 16:30:55 +00:00
|
|
|
std::unique_ptr<NodeDebugger> node_debugger_;
|
2014-06-30 06:16:16 +00:00
|
|
|
|
2014-10-17 04:41:40 +00:00
|
|
|
base::Timer gc_timer_;
|
|
|
|
|
2015-06-24 09:58:12 +00:00
|
|
|
// List of callbacks should be executed before destroying JS env.
|
2018-03-30 13:24:55 +00:00
|
|
|
std::list<base::OnceClosure> destructors_;
|
2015-06-24 09:58:12 +00:00
|
|
|
|
2013-04-22 13:32:48 +00:00
|
|
|
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_
|