• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2020 The Chromium Embedded Framework Authors.
2 // Portions copyright 2012 The Chromium Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5 
6 #include "libcef/common/alloy/alloy_main_runner_delegate.h"
7 
8 #include "libcef/browser/alloy/chrome_browser_process_alloy.h"
9 #include "libcef/common/alloy/alloy_main_delegate.h"
10 #include "libcef/renderer/alloy/alloy_content_renderer_client.h"
11 
12 #include "content/public/browser/render_process_host.h"
13 #include "ui/base/resource/resource_bundle.h"
14 
AlloyMainRunnerDelegate(CefMainRunnerHandler * runner,CefSettings * settings,CefRefPtr<CefApp> application)15 AlloyMainRunnerDelegate::AlloyMainRunnerDelegate(CefMainRunnerHandler* runner,
16                                                  CefSettings* settings,
17                                                  CefRefPtr<CefApp> application)
18     : runner_(runner), settings_(settings), application_(application) {}
19 AlloyMainRunnerDelegate::~AlloyMainRunnerDelegate() = default;
20 
21 content::ContentMainDelegate*
GetContentMainDelegate()22 AlloyMainRunnerDelegate::GetContentMainDelegate() {
23   if (!main_delegate_) {
24     main_delegate_ =
25         std::make_unique<AlloyMainDelegate>(runner_, settings_, application_);
26   }
27   return main_delegate_.get();
28 }
29 
BeforeMainThreadInitialize(const CefMainArgs & args)30 void AlloyMainRunnerDelegate::BeforeMainThreadInitialize(
31     const CefMainArgs& args) {
32   g_browser_process = new ChromeBrowserProcessAlloy();
33 }
34 
BeforeMainThreadRun()35 void AlloyMainRunnerDelegate::BeforeMainThreadRun() {
36   static_cast<ChromeBrowserProcessAlloy*>(g_browser_process)->Initialize();
37 }
38 
AfterUIThreadInitialize()39 void AlloyMainRunnerDelegate::AfterUIThreadInitialize() {
40   static_cast<ChromeBrowserProcessAlloy*>(g_browser_process)
41       ->OnContextInitialized();
42 }
43 
AfterUIThreadShutdown()44 void AlloyMainRunnerDelegate::AfterUIThreadShutdown() {
45   static_cast<ChromeBrowserProcessAlloy*>(g_browser_process)
46       ->CleanupOnUIThread();
47 
48   ui::ResourceBundle::GetSharedInstance().CleanupOnUIThread();
49 }
50 
BeforeMainThreadShutdown()51 void AlloyMainRunnerDelegate::BeforeMainThreadShutdown() {
52   if (content::RenderProcessHost::run_renderer_in_process()) {
53     // Blocks until RenderProcess cleanup is complete.
54     AlloyContentRendererClient::Get()->RunSingleProcessCleanup();
55   }
56 }
57 
AfterMainThreadShutdown()58 void AlloyMainRunnerDelegate::AfterMainThreadShutdown() {
59   if (g_browser_process) {
60     delete g_browser_process;
61     g_browser_process = nullptr;
62   }
63 }
64