2020-06-28 20:29:44 +02:00
|
|
|
// Copyright 2020 The Chromium Embedded Framework Authors.
|
|
|
|
// Portions copyright 2012 The Chromium Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
|
|
#include "libcef/common/alloy/alloy_main_runner_delegate.h"
|
|
|
|
|
|
|
|
#include "libcef/browser/alloy/chrome_browser_process_alloy.h"
|
|
|
|
#include "libcef/common/alloy/alloy_main_delegate.h"
|
|
|
|
#include "libcef/renderer/alloy/alloy_content_renderer_client.h"
|
|
|
|
|
2023-12-11 21:36:56 +01:00
|
|
|
#include "chrome/browser/chrome_process_singleton.h"
|
2020-06-28 20:29:44 +02:00
|
|
|
#include "content/public/browser/render_process_host.h"
|
|
|
|
#include "ui/base/resource/resource_bundle.h"
|
|
|
|
|
|
|
|
AlloyMainRunnerDelegate::AlloyMainRunnerDelegate(CefMainRunnerHandler* runner,
|
|
|
|
CefSettings* settings,
|
|
|
|
CefRefPtr<CefApp> application)
|
|
|
|
: runner_(runner), settings_(settings), application_(application) {}
|
|
|
|
AlloyMainRunnerDelegate::~AlloyMainRunnerDelegate() = default;
|
|
|
|
|
|
|
|
content::ContentMainDelegate*
|
|
|
|
AlloyMainRunnerDelegate::GetContentMainDelegate() {
|
|
|
|
if (!main_delegate_) {
|
|
|
|
main_delegate_ =
|
|
|
|
std::make_unique<AlloyMainDelegate>(runner_, settings_, application_);
|
|
|
|
}
|
|
|
|
return main_delegate_.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
void AlloyMainRunnerDelegate::BeforeMainThreadInitialize(
|
|
|
|
const CefMainArgs& args) {
|
|
|
|
g_browser_process = new ChromeBrowserProcessAlloy();
|
|
|
|
}
|
|
|
|
|
2023-04-04 20:00:13 +02:00
|
|
|
void AlloyMainRunnerDelegate::BeforeMainThreadRun(
|
|
|
|
bool multi_threaded_message_loop) {
|
2020-06-28 20:29:44 +02:00
|
|
|
static_cast<ChromeBrowserProcessAlloy*>(g_browser_process)->Initialize();
|
|
|
|
}
|
|
|
|
|
|
|
|
void AlloyMainRunnerDelegate::AfterUIThreadInitialize() {
|
|
|
|
static_cast<ChromeBrowserProcessAlloy*>(g_browser_process)
|
|
|
|
->OnContextInitialized();
|
|
|
|
}
|
|
|
|
|
2023-12-11 21:36:56 +01:00
|
|
|
void AlloyMainRunnerDelegate::BeforeUIThreadShutdown() {
|
2020-06-28 20:29:44 +02:00
|
|
|
static_cast<ChromeBrowserProcessAlloy*>(g_browser_process)
|
|
|
|
->CleanupOnUIThread();
|
|
|
|
|
|
|
|
ui::ResourceBundle::GetSharedInstance().CleanupOnUIThread();
|
|
|
|
}
|
|
|
|
|
2023-12-11 21:36:56 +01:00
|
|
|
void AlloyMainRunnerDelegate::AfterUIThreadShutdown() {
|
|
|
|
ChromeProcessSingleton::DeleteInstance();
|
|
|
|
}
|
|
|
|
|
2020-06-28 20:29:44 +02:00
|
|
|
void AlloyMainRunnerDelegate::BeforeMainThreadShutdown() {
|
|
|
|
if (content::RenderProcessHost::run_renderer_in_process()) {
|
|
|
|
// Blocks until RenderProcess cleanup is complete.
|
|
|
|
AlloyContentRendererClient::Get()->RunSingleProcessCleanup();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void AlloyMainRunnerDelegate::AfterMainThreadShutdown() {
|
|
|
|
if (g_browser_process) {
|
|
|
|
delete g_browser_process;
|
|
|
|
g_browser_process = nullptr;
|
|
|
|
}
|
|
|
|
}
|