mirror of
https://bitbucket.org/chromiumembedded/cef
synced 2025-01-10 17:23:26 +01:00
b3a8da9b25
This is the first pass in removing direct dependencies on the Alloy runtime from code that can potentially be shared between runtimes. CefBrowserHost and CefRequestContext APIs (including CefCookieManager, CefURLRequest, etc.) are not yet implemented for the Chrome runtime. Assert early if these API methods are called while the Chrome runtime is enabled.
88 lines
2.9 KiB
C++
88 lines
2.9 KiB
C++
// 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/chrome/chrome_main_runner_delegate.h"
|
|
|
|
#include "libcef/common/chrome/chrome_main_delegate_cef.h"
|
|
|
|
#include "base/command_line.h"
|
|
#include "base/run_loop.h"
|
|
#include "chrome/browser/browser_process_impl.h"
|
|
#include "chrome/common/profiler/main_thread_stack_sampling_profiler.h"
|
|
#include "components/keep_alive_registry/keep_alive_types.h"
|
|
#include "components/keep_alive_registry/scoped_keep_alive.h"
|
|
|
|
#if defined(OS_MACOSX)
|
|
#include "chrome/app/chrome_main_mac.h"
|
|
#endif
|
|
|
|
ChromeMainRunnerDelegate::ChromeMainRunnerDelegate(
|
|
CefMainRunnerHandler* runner,
|
|
CefRefPtr<CefApp> application)
|
|
: runner_(runner), application_(application) {}
|
|
ChromeMainRunnerDelegate::~ChromeMainRunnerDelegate() = default;
|
|
|
|
content::ContentMainDelegate*
|
|
ChromeMainRunnerDelegate::GetContentMainDelegate() {
|
|
if (!main_delegate_) {
|
|
main_delegate_ =
|
|
std::make_unique<ChromeMainDelegateCef>(runner_, application_);
|
|
}
|
|
return main_delegate_.get();
|
|
}
|
|
|
|
void ChromeMainRunnerDelegate::BeforeMainThreadInitialize(
|
|
const CefMainArgs& args) {
|
|
#if defined(OS_WIN)
|
|
base::CommandLine::Init(0, nullptr);
|
|
#else
|
|
base::CommandLine::Init(args.argc, args.argv);
|
|
#endif
|
|
|
|
#if defined(OS_MACOSX)
|
|
SetUpBundleOverrides();
|
|
#endif
|
|
|
|
sampling_profiler_ = std::make_unique<MainThreadStackSamplingProfiler>();
|
|
}
|
|
|
|
void ChromeMainRunnerDelegate::BeforeMainMessageLoopRun(
|
|
base::RunLoop* run_loop) {
|
|
// The ScopedKeepAlive instance triggers shutdown logic when released on the
|
|
// UI thread before terminating the message loop (e.g. from CefQuitMessageLoop
|
|
// or FinishShutdownOnUIThread when running with multi-threaded message loop).
|
|
// TODO(chrome-runtime): Enable this once browser life-span notifications are
|
|
// in place. In the mean time, closing the last Chrome browser instance will
|
|
// exit the app.
|
|
/*
|
|
keep_alive_ = std::make_unique<ScopedKeepAlive>(
|
|
KeepAliveOrigin::APP_CONTROLLER, KeepAliveRestartOption::DISABLED);
|
|
*/
|
|
|
|
// The idle callback will be executed from BrowserProcessImpl::Unpin() via
|
|
// KeepAliveRegistry when the last ScopedKeepAlive is released.
|
|
// ScopedKeepAlives are also held by Browser objects.
|
|
DCHECK(g_browser_process);
|
|
static_cast<BrowserProcessImpl*>(g_browser_process)
|
|
->SetQuitClosure(run_loop->QuitWhenIdleClosure());
|
|
}
|
|
|
|
void ChromeMainRunnerDelegate::BeforeMainMessageLoopQuit() {
|
|
// May be called multiple times. See comments in RunMainMessageLoopBefore.
|
|
keep_alive_.reset();
|
|
}
|
|
|
|
void ChromeMainRunnerDelegate::AfterMainThreadShutdown() {
|
|
sampling_profiler_.reset();
|
|
}
|
|
|
|
void ChromeMainRunnerDelegate::BeforeExecuteProcess(const CefMainArgs& args) {
|
|
BeforeMainThreadInitialize(args);
|
|
}
|
|
|
|
void ChromeMainRunnerDelegate::AfterExecuteProcess() {
|
|
AfterMainThreadShutdown();
|
|
}
|