2020-06-25 04:34:12 +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/chrome/chrome_main_delegate_cef.h"
|
|
|
|
|
2020-07-04 04:51:17 +02:00
|
|
|
#include "libcef/browser/chrome/chrome_browser_context.h"
|
2020-06-25 04:34:12 +02:00
|
|
|
#include "libcef/browser/chrome/chrome_content_browser_client_cef.h"
|
2020-07-06 20:14:57 +02:00
|
|
|
#include "libcef/common/crash_reporting.h"
|
|
|
|
#include "libcef/common/resource_util.h"
|
|
|
|
|
2020-08-29 00:39:23 +02:00
|
|
|
#include "base/command_line.h"
|
2020-07-06 20:14:57 +02:00
|
|
|
#include "content/public/common/content_switches.h"
|
|
|
|
|
2020-08-29 00:39:23 +02:00
|
|
|
#if defined(OS_MAC)
|
2020-07-06 20:14:57 +02:00
|
|
|
#include "libcef/common/util_mac.h"
|
|
|
|
#endif
|
2020-06-25 04:34:12 +02:00
|
|
|
|
2020-06-28 23:05:36 +02:00
|
|
|
ChromeMainDelegateCef::ChromeMainDelegateCef(CefMainRunnerHandler* runner,
|
2020-07-06 20:14:57 +02:00
|
|
|
CefSettings* settings,
|
2020-06-28 23:05:36 +02:00
|
|
|
CefRefPtr<CefApp> application)
|
|
|
|
: ChromeMainDelegate(base::TimeTicks::Now()),
|
|
|
|
runner_(runner),
|
2020-07-06 20:14:57 +02:00
|
|
|
settings_(settings),
|
|
|
|
application_(application) {
|
|
|
|
#if defined(OS_LINUX)
|
|
|
|
resource_util::OverrideAssetPath();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2020-06-25 04:34:12 +02:00
|
|
|
ChromeMainDelegateCef::~ChromeMainDelegateCef() = default;
|
|
|
|
|
2020-07-06 20:14:57 +02:00
|
|
|
bool ChromeMainDelegateCef::BasicStartupComplete(int* exit_code) {
|
|
|
|
// Returns false if startup should proceed.
|
|
|
|
bool result = ChromeMainDelegate::BasicStartupComplete(exit_code);
|
|
|
|
|
|
|
|
if (!result) {
|
|
|
|
#if defined(OS_POSIX)
|
|
|
|
// Read the crash configuration file. Platforms using Breakpad also add a
|
|
|
|
// command-line switch. On Windows this is done from chrome_elf.
|
|
|
|
crash_reporting::BasicStartupComplete(
|
|
|
|
base::CommandLine::ForCurrentProcess());
|
|
|
|
#endif
|
|
|
|
|
2020-08-29 00:39:23 +02:00
|
|
|
#if defined(OS_MAC)
|
2020-07-06 20:14:57 +02:00
|
|
|
util_mac::BasicStartupComplete();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ChromeMainDelegateCef::PreSandboxStartup() {
|
|
|
|
const base::CommandLine* command_line =
|
|
|
|
base::CommandLine::ForCurrentProcess();
|
|
|
|
const std::string& process_type =
|
|
|
|
command_line->GetSwitchValueASCII(switches::kProcessType);
|
|
|
|
|
2020-08-29 00:39:23 +02:00
|
|
|
#if defined(OS_MAC)
|
2020-07-06 20:14:57 +02:00
|
|
|
if (process_type.empty()) {
|
|
|
|
util_mac::PreSandboxStartup();
|
|
|
|
}
|
2020-08-29 00:39:23 +02:00
|
|
|
#endif // defined(OS_MAC)
|
2020-07-06 20:14:57 +02:00
|
|
|
|
|
|
|
// Since this may be configured via CefSettings we override the value on
|
|
|
|
// all platforms. We can't use the default implementation on macOS because
|
|
|
|
// chrome::GetDefaultUserDataDirectory expects to find the Chromium version
|
|
|
|
// number in the app bundle path.
|
|
|
|
resource_util::OverrideUserDataDir(settings_, command_line);
|
|
|
|
|
|
|
|
ChromeMainDelegate::PreSandboxStartup();
|
|
|
|
|
|
|
|
// Initialize crash reporting state for this process/module.
|
|
|
|
// chrome::DIR_CRASH_DUMPS must be configured before calling this function.
|
|
|
|
crash_reporting::PreSandboxStartup(*command_line, process_type);
|
|
|
|
}
|
|
|
|
|
2020-06-25 04:34:12 +02:00
|
|
|
void ChromeMainDelegateCef::PreCreateMainMessageLoop() {
|
|
|
|
// The parent ChromeMainDelegate implementation creates the NSApplication
|
|
|
|
// instance on macOS, and we intentionally don't want to do that here.
|
2020-07-06 20:14:57 +02:00
|
|
|
// TODO(macos): Do we need l10n_util::OverrideLocaleWithCocoaLocale()?
|
2020-06-25 04:34:12 +02:00
|
|
|
runner_->PreCreateMainMessageLoop();
|
|
|
|
}
|
|
|
|
|
|
|
|
int ChromeMainDelegateCef::RunProcess(
|
|
|
|
const std::string& process_type,
|
|
|
|
const content::MainFunctionParams& main_function_params) {
|
|
|
|
if (process_type.empty()) {
|
|
|
|
return runner_->RunMainProcess(main_function_params);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ChromeMainDelegate::RunProcess(process_type, main_function_params);
|
|
|
|
}
|
|
|
|
|
2020-07-06 20:14:57 +02:00
|
|
|
#if defined(OS_LINUX)
|
|
|
|
void ChromeMainDelegateCef::ZygoteForked() {
|
|
|
|
ChromeMainDelegate::ZygoteForked();
|
|
|
|
|
|
|
|
base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
|
|
|
|
const std::string& process_type =
|
|
|
|
command_line->GetSwitchValueASCII(switches::kProcessType);
|
|
|
|
|
|
|
|
// Initialize crash reporting state for the newly forked process.
|
|
|
|
crash_reporting::ZygoteForked(command_line, process_type);
|
|
|
|
}
|
|
|
|
#endif // defined(OS_LINUX)
|
|
|
|
|
2020-06-28 23:05:36 +02:00
|
|
|
content::ContentClient* ChromeMainDelegateCef::CreateContentClient() {
|
|
|
|
return &chrome_content_client_cef_;
|
|
|
|
}
|
|
|
|
|
2020-06-25 04:34:12 +02:00
|
|
|
content::ContentBrowserClient*
|
|
|
|
ChromeMainDelegateCef::CreateContentBrowserClient() {
|
|
|
|
// Match the logic in the parent ChromeMainDelegate implementation, but create
|
|
|
|
// our own object type.
|
|
|
|
if (chrome_content_browser_client_ == nullptr) {
|
|
|
|
DCHECK(!startup_data_);
|
|
|
|
startup_data_ = std::make_unique<StartupData>();
|
|
|
|
|
|
|
|
chrome_content_browser_client_ =
|
|
|
|
std::make_unique<ChromeContentBrowserClientCef>(startup_data_.get());
|
|
|
|
}
|
|
|
|
return chrome_content_browser_client_.get();
|
|
|
|
}
|
|
|
|
|
2020-06-28 23:05:36 +02:00
|
|
|
CefRefPtr<CefRequestContext> ChromeMainDelegateCef::GetGlobalRequestContext() {
|
2020-07-04 04:51:17 +02:00
|
|
|
auto browser_client = content_browser_client();
|
|
|
|
if (browser_client)
|
|
|
|
return browser_client->request_context();
|
2020-06-28 23:05:36 +02:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2020-07-01 02:57:00 +02:00
|
|
|
CefBrowserContext* ChromeMainDelegateCef::CreateNewBrowserContext(
|
|
|
|
const CefRequestContextSettings& settings) {
|
2020-07-04 04:51:17 +02:00
|
|
|
auto context = new ChromeBrowserContext(settings);
|
|
|
|
context->Initialize();
|
|
|
|
return context;
|
2020-07-01 02:57:00 +02:00
|
|
|
}
|
|
|
|
|
2020-06-25 04:34:12 +02:00
|
|
|
scoped_refptr<base::SingleThreadTaskRunner>
|
|
|
|
ChromeMainDelegateCef::GetBackgroundTaskRunner() {
|
|
|
|
auto browser_client = content_browser_client();
|
|
|
|
if (browser_client)
|
|
|
|
return browser_client->background_task_runner();
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
scoped_refptr<base::SingleThreadTaskRunner>
|
|
|
|
ChromeMainDelegateCef::GetUserVisibleTaskRunner() {
|
|
|
|
auto browser_client = content_browser_client();
|
|
|
|
if (browser_client)
|
|
|
|
return browser_client->user_visible_task_runner();
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
scoped_refptr<base::SingleThreadTaskRunner>
|
|
|
|
ChromeMainDelegateCef::GetUserBlockingTaskRunner() {
|
|
|
|
auto browser_client = content_browser_client();
|
|
|
|
if (browser_client)
|
|
|
|
return browser_client->user_blocking_task_runner();
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
scoped_refptr<base::SingleThreadTaskRunner>
|
|
|
|
ChromeMainDelegateCef::GetRenderTaskRunner() {
|
|
|
|
// TODO: Implement.
|
|
|
|
NOTREACHED();
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
scoped_refptr<base::SingleThreadTaskRunner>
|
|
|
|
ChromeMainDelegateCef::GetWebWorkerTaskRunner() {
|
|
|
|
// TODO: Implement.
|
|
|
|
NOTREACHED();
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
ChromeContentBrowserClientCef* ChromeMainDelegateCef::content_browser_client()
|
|
|
|
const {
|
|
|
|
return static_cast<ChromeContentBrowserClientCef*>(
|
|
|
|
chrome_content_browser_client_.get());
|
|
|
|
}
|