atom_browser_main_parts.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. // Copyright (c) 2013 GitHub, Inc.
  2. // Use of this source code is governed by the MIT license that can be
  3. // found in the LICENSE file.
  4. #ifndef SHELL_BROWSER_ATOM_BROWSER_MAIN_PARTS_H_
  5. #define SHELL_BROWSER_ATOM_BROWSER_MAIN_PARTS_H_
  6. #include <list>
  7. #include <memory>
  8. #include <string>
  9. #include "base/callback.h"
  10. #include "base/metrics/field_trial.h"
  11. #include "base/timer/timer.h"
  12. #include "content/public/browser/browser_context.h"
  13. #include "content/public/browser/browser_main_parts.h"
  14. #include "content/public/common/main_function_params.h"
  15. #include "electron/buildflags/buildflags.h"
  16. #include "services/device/public/mojom/geolocation_control.mojom.h"
  17. #include "ui/views/layout/layout_provider.h"
  18. class BrowserProcess;
  19. class IconManager;
  20. #if defined(USE_AURA)
  21. namespace wm {
  22. class WMState;
  23. }
  24. #endif
  25. namespace electron {
  26. class AtomBrowserContext;
  27. class Browser;
  28. class ElectronBindings;
  29. class JavascriptEnvironment;
  30. class NodeBindings;
  31. class NodeDebugger;
  32. class NodeEnvironment;
  33. class BridgeTaskRunner;
  34. #if BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS)
  35. class AtomExtensionsClient;
  36. class AtomExtensionsBrowserClient;
  37. #endif
  38. #if defined(TOOLKIT_VIEWS)
  39. class ViewsDelegate;
  40. #endif
  41. #if defined(OS_MACOSX)
  42. class ViewsDelegateMac;
  43. #endif
  44. class AtomBrowserMainParts : public content::BrowserMainParts {
  45. public:
  46. explicit AtomBrowserMainParts(const content::MainFunctionParams& params);
  47. ~AtomBrowserMainParts() override;
  48. static AtomBrowserMainParts* Get();
  49. // Sets the exit code, will fail if the message loop is not ready.
  50. bool SetExitCode(int code);
  51. // Gets the exit code
  52. int GetExitCode();
  53. // Register a callback that should be destroyed before JavaScript environment
  54. // gets destroyed.
  55. // Returns a closure that can be used to remove |callback| from the list.
  56. void RegisterDestructionCallback(base::OnceClosure callback);
  57. // Returns the connection to GeolocationControl which can be
  58. // used to enable the location services once per client.
  59. device::mojom::GeolocationControl* GetGeolocationControl();
  60. // Returns handle to the class responsible for extracting file icons.
  61. IconManager* GetIconManager();
  62. Browser* browser() { return browser_.get(); }
  63. BrowserProcessImpl* browser_process() { return fake_browser_process_.get(); }
  64. protected:
  65. // content::BrowserMainParts:
  66. int PreEarlyInitialization() override;
  67. void PostEarlyInitialization() override;
  68. int PreCreateThreads() override;
  69. void ToolkitInitialized() override;
  70. void PreMainMessageLoopRun() override;
  71. bool MainMessageLoopRun(int* result_code) override;
  72. void PreDefaultMainMessageLoopRun(base::OnceClosure quit_closure) override;
  73. void PostMainMessageLoopStart() override;
  74. void PostMainMessageLoopRun() override;
  75. void PreMainMessageLoopStart() override;
  76. void PostCreateThreads() override;
  77. void PostDestroyThreads() override;
  78. private:
  79. void PreMainMessageLoopStartCommon();
  80. #if defined(OS_POSIX)
  81. // Set signal handlers.
  82. void HandleSIGCHLD();
  83. void HandleShutdownSignals();
  84. #endif
  85. #if defined(OS_MACOSX)
  86. void FreeAppDelegate();
  87. void RegisterURLHandler();
  88. void InitializeMainNib();
  89. #endif
  90. #if defined(OS_MACOSX)
  91. std::unique_ptr<ViewsDelegateMac> views_delegate_;
  92. #else
  93. std::unique_ptr<ViewsDelegate> views_delegate_;
  94. #endif
  95. #if defined(USE_AURA)
  96. std::unique_ptr<wm::WMState> wm_state_;
  97. #endif
  98. std::unique_ptr<views::LayoutProvider> layout_provider_;
  99. // A fake BrowserProcess object that used to feed the source code from chrome.
  100. std::unique_ptr<BrowserProcessImpl> fake_browser_process_;
  101. // Pointer to exit code.
  102. int* exit_code_ = nullptr;
  103. std::unique_ptr<Browser> browser_;
  104. std::unique_ptr<JavascriptEnvironment> js_env_;
  105. std::unique_ptr<NodeBindings> node_bindings_;
  106. std::unique_ptr<ElectronBindings> electron_bindings_;
  107. std::unique_ptr<NodeEnvironment> node_env_;
  108. std::unique_ptr<NodeDebugger> node_debugger_;
  109. std::unique_ptr<IconManager> icon_manager_;
  110. std::unique_ptr<base::FieldTrialList> field_trial_list_;
  111. #if BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS)
  112. std::unique_ptr<AtomExtensionsClient> extensions_client_;
  113. std::unique_ptr<AtomExtensionsBrowserClient> extensions_browser_client_;
  114. #endif
  115. base::RepeatingTimer gc_timer_;
  116. // List of callbacks should be executed before destroying JS env.
  117. std::list<base::OnceClosure> destructors_;
  118. device::mojom::GeolocationControlPtr geolocation_control_;
  119. static AtomBrowserMainParts* self_;
  120. DISALLOW_COPY_AND_ASSIGN(AtomBrowserMainParts);
  121. };
  122. } // namespace electron
  123. #endif // SHELL_BROWSER_ATOM_BROWSER_MAIN_PARTS_H_