electron/atom/browser/atom_browser_main_parts.h

95 lines
2.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
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
class BrowserProcess;
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 BridgeTaskRunner;
2013-04-13 10:39:09 +00:00
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();
2013-04-12 15:16:16 +00:00
virtual ~AtomBrowserMainParts();
2013-04-12 01:46:58 +00:00
static AtomBrowserMainParts* Get();
// Sets the exit code, will fail if the the message loop is not ready.
bool SetExitCode(int code);
2015-06-24 09:58:12 +00:00
// Register a callback that should be destroyed before JavaScript environment
// gets destroyed.
void RegisterDestructionCallback(const base::Closure& callback);
Browser* browser() { return browser_.get(); }
2013-04-12 15:16:16 +00:00
protected:
// content::BrowserMainParts:
2015-10-04 11:21:36 +00:00
void PreEarlyInitialization() override;
2015-01-10 01:24:36 +00:00
void PostEarlyInitialization() override;
void PreMainMessageLoopRun() override;
bool MainMessageLoopRun(int* result_code) override;
2015-10-04 11:21:36 +00:00
void PostMainMessageLoopStart() override;
void PostMainMessageLoopRun() override;
#if defined(OS_MACOSX)
2015-01-10 01:24:36 +00:00
void PreMainMessageLoopStart() override;
#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
#if defined(OS_MACOSX)
void FreeAppDelegate();
#endif
// A fake BrowserProcess object that used to feed the source code from chrome.
scoped_ptr<BrowserProcess> fake_browser_process_;
// 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_;
// Pointer to exit code.
int* exit_code_;
scoped_ptr<Browser> browser_;
scoped_ptr<JavascriptEnvironment> js_env_;
2013-04-13 10:39:09 +00:00
scoped_ptr<NodeBindings> node_bindings_;
scoped_ptr<AtomBindings> atom_bindings_;
scoped_ptr<NodeDebugger> node_debugger_;
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.
std::list<base::Closure> destruction_callbacks_;
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_