2012-04-03 03:34:16 +02:00
|
|
|
// Copyright (c) 2012 The Chromium Embedded Framework Authors. All rights
|
|
|
|
// reserved. Use of this source code is governed by a BSD-style license that can
|
|
|
|
// be found in the LICENSE file.
|
|
|
|
|
2017-05-19 11:06:00 +02:00
|
|
|
#include "libcef/browser/context.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
#include "libcef/browser/browser_host_impl.h"
|
2012-12-30 12:17:49 +01:00
|
|
|
#include "libcef/browser/browser_info.h"
|
2015-11-17 19:20:13 +01:00
|
|
|
#include "libcef/browser/browser_info_manager.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
#include "libcef/browser/browser_main.h"
|
|
|
|
#include "libcef/browser/browser_message_loop.h"
|
2013-10-23 21:30:47 +02:00
|
|
|
#include "libcef/browser/chrome_browser_process_stub.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
#include "libcef/browser/thread_util.h"
|
2012-10-18 00:45:49 +02:00
|
|
|
#include "libcef/browser/trace_subscriber.h"
|
2015-03-02 21:25:14 +01:00
|
|
|
#include "libcef/common/cef_switches.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
#include "libcef/common/main_delegate.h"
|
2016-10-14 17:56:41 +02:00
|
|
|
#include "libcef/common/widevine_loader.h"
|
2013-02-02 01:21:59 +01:00
|
|
|
#include "libcef/renderer/content_renderer_client.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2013-11-12 18:43:39 +01:00
|
|
|
#include "base/base_switches.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
#include "base/bind.h"
|
|
|
|
#include "base/command_line.h"
|
2013-11-12 18:43:39 +01:00
|
|
|
#include "base/debug/debugger.h"
|
2014-11-12 20:25:15 +01:00
|
|
|
#include "base/files/file_util.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
#include "base/synchronization/waitable_event.h"
|
2017-04-20 21:28:17 +02:00
|
|
|
#include "content/app/content_service_manager_main_delegate.h"
|
2013-09-03 18:43:31 +02:00
|
|
|
#include "content/public/browser/notification_service.h"
|
|
|
|
#include "content/public/browser/notification_types.h"
|
2013-02-02 01:21:59 +01:00
|
|
|
#include "content/public/browser/render_process_host.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
#include "content/public/common/content_switches.h"
|
2017-04-20 21:28:17 +02:00
|
|
|
#include "services/service_manager/embedder/main.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
#include "ui/base/ui_base_switches.h"
|
|
|
|
|
|
|
|
#if defined(OS_WIN)
|
2016-12-12 11:05:29 +01:00
|
|
|
#include "base/strings/utf_string_conversions.h"
|
2016-10-17 20:14:44 +02:00
|
|
|
#include "chrome_elf/chrome_elf_main.h"
|
|
|
|
#include "components/crash/content/app/crashpad.h"
|
2017-05-17 11:29:28 +02:00
|
|
|
#include "content/public/app/sandbox_helper_win.h"
|
2012-08-04 02:59:58 +02:00
|
|
|
#include "sandbox/win/src/sandbox_types.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
#endif
|
|
|
|
|
2016-12-12 11:05:29 +01:00
|
|
|
#if defined(OS_MACOSX) || defined(OS_WIN)
|
|
|
|
#include "components/crash/content/app/crash_switches.h"
|
|
|
|
#include "third_party/crashpad/crashpad/handler/handler_main.h"
|
|
|
|
#endif
|
|
|
|
|
2013-09-03 20:06:25 +02:00
|
|
|
namespace {
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2013-09-03 20:06:25 +02:00
|
|
|
CefContext* g_context = NULL;
|
|
|
|
|
2017-05-09 21:52:52 +02:00
|
|
|
#if DCHECK_IS_ON()
|
|
|
|
// When the process terminates check if CefShutdown() has been called.
|
|
|
|
class CefShutdownChecker {
|
2013-09-03 20:06:25 +02:00
|
|
|
public:
|
2017-05-17 11:29:28 +02:00
|
|
|
~CefShutdownChecker() { DCHECK(!g_context) << "CefShutdown was not called"; }
|
2017-05-09 21:52:52 +02:00
|
|
|
} g_shutdown_checker;
|
|
|
|
#endif // DCHECK_IS_ON()
|
2013-09-03 20:06:25 +02:00
|
|
|
|
2017-04-27 19:02:21 +02:00
|
|
|
#if defined(OS_WIN)
|
|
|
|
#if defined(ARCH_CPU_X86_64)
|
2016-01-28 17:10:36 +01:00
|
|
|
// VS2013 only checks the existence of FMA3 instructions, not the enabled-ness
|
|
|
|
// of them at the OS level (this is fixed in VS2015). We force off usage of
|
|
|
|
// FMA3 instructions in the CRT to avoid using that path and hitting illegal
|
|
|
|
// instructions when running on CPUs that support FMA3, but OSs that don't.
|
|
|
|
void DisableFMA3() {
|
|
|
|
static bool disabled = false;
|
|
|
|
if (disabled)
|
|
|
|
return;
|
|
|
|
disabled = true;
|
|
|
|
_set_FMA3_enable(0);
|
|
|
|
}
|
2017-04-27 19:02:21 +02:00
|
|
|
#endif // defined(ARCH_CPU_X86_64)
|
|
|
|
|
|
|
|
// Signal chrome_elf to initialize crash reporting, rather than doing it in
|
|
|
|
// DllMain. See https://crbug.com/656800 for details.
|
|
|
|
void InitCrashReporter() {
|
|
|
|
static bool initialized = false;
|
|
|
|
if (initialized)
|
|
|
|
return;
|
|
|
|
initialized = true;
|
|
|
|
SignalInitializeCrashReporting();
|
|
|
|
}
|
|
|
|
#endif // defined(OS_WIN)
|
2016-01-28 17:10:36 +01:00
|
|
|
|
2016-12-12 11:05:29 +01:00
|
|
|
#if defined(OS_MACOSX) || defined(OS_WIN)
|
|
|
|
|
|
|
|
// Based on components/crash/content/app/run_as_crashpad_handler_win.cc
|
|
|
|
// Remove the "--type=crashpad-handler" command-line flag that will otherwise
|
|
|
|
// confuse the crashpad handler.
|
|
|
|
// Chrome uses an embedded crashpad handler on Windows only and imports this
|
|
|
|
// function via the existing "run_as_crashpad_handler" target defined in
|
|
|
|
// components/crash/content/app/BUILD.gn. CEF uses an embedded handler on both
|
|
|
|
// Windows and macOS so we define the function here instead of using the
|
|
|
|
// existing target (because we can't use that target on macOS).
|
|
|
|
int RunAsCrashpadHandler(const base::CommandLine& command_line) {
|
|
|
|
base::CommandLine::StringVector argv = command_line.argv();
|
|
|
|
const base::CommandLine::StringType process_type =
|
|
|
|
FILE_PATH_LITERAL("--type=");
|
2017-05-17 11:29:28 +02:00
|
|
|
argv.erase(
|
|
|
|
std::remove_if(argv.begin(), argv.end(),
|
|
|
|
[&process_type](const base::CommandLine::StringType& str) {
|
|
|
|
return base::StartsWith(str, process_type,
|
|
|
|
base::CompareCase::SENSITIVE) ||
|
|
|
|
(!str.empty() && str[0] == L'/');
|
|
|
|
}),
|
|
|
|
argv.end());
|
2016-12-12 11:05:29 +01:00
|
|
|
|
2017-01-30 22:17:03 +01:00
|
|
|
#if defined(OS_MACOSX)
|
|
|
|
// HandlerMain on macOS uses the system version of getopt_long which expects
|
|
|
|
// the first argument to be the program name.
|
2017-01-27 20:16:04 +01:00
|
|
|
argv.insert(argv.begin(), command_line.GetProgram().value());
|
2017-01-30 22:17:03 +01:00
|
|
|
#endif
|
2017-01-27 20:16:04 +01:00
|
|
|
|
2016-12-12 11:05:29 +01:00
|
|
|
std::unique_ptr<char* []> argv_as_utf8(new char*[argv.size() + 1]);
|
|
|
|
std::vector<std::string> storage;
|
|
|
|
storage.reserve(argv.size());
|
|
|
|
for (size_t i = 0; i < argv.size(); ++i) {
|
|
|
|
#if defined(OS_WIN)
|
|
|
|
storage.push_back(base::UTF16ToUTF8(argv[i]));
|
|
|
|
#else
|
|
|
|
storage.push_back(argv[i]);
|
|
|
|
#endif
|
|
|
|
argv_as_utf8[i] = &storage[i][0];
|
|
|
|
}
|
|
|
|
argv_as_utf8[argv.size()] = nullptr;
|
|
|
|
argv.clear();
|
|
|
|
return crashpad::HandlerMain(static_cast<int>(storage.size()),
|
2017-04-20 21:28:17 +02:00
|
|
|
argv_as_utf8.get(), nullptr);
|
2016-12-12 11:05:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif // defined(OS_MACOSX) || defined(OS_WIN)
|
|
|
|
|
2017-04-20 21:28:17 +02:00
|
|
|
bool GetColor(const cef_color_t cef_in, bool is_windowless, SkColor* sk_out) {
|
|
|
|
// Windowed browser colors must be fully opaque.
|
|
|
|
if (!is_windowless && CefColorGetA(cef_in) != SK_AlphaOPAQUE)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Windowless browser colors may be fully transparent.
|
|
|
|
if (is_windowless && CefColorGetA(cef_in) == SK_AlphaTRANSPARENT) {
|
|
|
|
*sk_out = SK_ColorTRANSPARENT;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Ignore the alpha component.
|
|
|
|
*sk_out = SkColorSetRGB(CefColorGetR(cef_in), CefColorGetG(cef_in),
|
|
|
|
CefColorGetB(cef_in));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-09-03 20:06:25 +02:00
|
|
|
} // namespace
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
int CefExecuteProcess(const CefMainArgs& args,
|
2013-11-15 19:47:02 +01:00
|
|
|
CefRefPtr<CefApp> application,
|
|
|
|
void* windows_sandbox_info) {
|
2017-04-27 19:02:21 +02:00
|
|
|
#if defined(OS_WIN)
|
|
|
|
#if defined(ARCH_CPU_X86_64)
|
2016-01-28 17:10:36 +01:00
|
|
|
DisableFMA3();
|
|
|
|
#endif
|
2017-04-27 19:02:21 +02:00
|
|
|
InitCrashReporter();
|
|
|
|
#endif
|
2016-01-28 17:10:36 +01:00
|
|
|
|
2015-01-09 18:22:10 +01:00
|
|
|
base::CommandLine command_line(base::CommandLine::NO_PROGRAM);
|
2012-04-03 03:34:16 +02:00
|
|
|
#if defined(OS_WIN)
|
|
|
|
command_line.ParseFromString(::GetCommandLineW());
|
|
|
|
#else
|
|
|
|
command_line.InitFromArgv(args.argc, args.argv);
|
|
|
|
#endif
|
|
|
|
|
2013-11-12 18:43:39 +01:00
|
|
|
// Wait for the debugger as early in process initialization as possible.
|
|
|
|
if (command_line.HasSwitch(switches::kWaitForDebugger))
|
|
|
|
base::debug::WaitForDebugger(60, true);
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
// If no process type is specified then it represents the browser process and
|
|
|
|
// we do nothing.
|
|
|
|
std::string process_type =
|
|
|
|
command_line.GetSwitchValueASCII(switches::kProcessType);
|
|
|
|
if (process_type.empty())
|
|
|
|
return -1;
|
|
|
|
|
2016-12-12 11:05:29 +01:00
|
|
|
#if defined(OS_MACOSX) || defined(OS_WIN)
|
2016-10-17 20:14:44 +02:00
|
|
|
if (process_type == crash_reporter::switches::kCrashpadHandler)
|
2016-12-12 11:05:29 +01:00
|
|
|
return RunAsCrashpadHandler(command_line);
|
2016-10-17 20:14:44 +02:00
|
|
|
#endif
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
CefMainDelegate main_delegate(application);
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
// Execute the secondary process.
|
2012-04-03 03:34:16 +02:00
|
|
|
#if defined(OS_WIN)
|
|
|
|
sandbox::SandboxInterfaceInfo sandbox_info = {0};
|
2013-11-15 19:47:02 +01:00
|
|
|
if (windows_sandbox_info == NULL) {
|
|
|
|
content::InitializeSandboxInfo(&sandbox_info);
|
|
|
|
windows_sandbox_info = &sandbox_info;
|
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2014-04-04 18:50:38 +02:00
|
|
|
content::ContentMainParams params(&main_delegate);
|
|
|
|
params.instance = args.instance;
|
|
|
|
params.sandbox_info =
|
|
|
|
static_cast<sandbox::SandboxInterfaceInfo*>(windows_sandbox_info);
|
|
|
|
|
|
|
|
return content::ContentMain(params);
|
2012-04-03 03:34:16 +02:00
|
|
|
#else
|
2014-04-04 18:50:38 +02:00
|
|
|
content::ContentMainParams params(&main_delegate);
|
|
|
|
params.argc = args.argc;
|
|
|
|
params.argv = const_cast<const char**>(args.argv);
|
|
|
|
|
|
|
|
return content::ContentMain(params);
|
2012-04-03 03:34:16 +02:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefInitialize(const CefMainArgs& args,
|
|
|
|
const CefSettings& settings,
|
2013-11-15 19:47:02 +01:00
|
|
|
CefRefPtr<CefApp> application,
|
|
|
|
void* windows_sandbox_info) {
|
2017-04-27 19:02:21 +02:00
|
|
|
#if defined(OS_WIN)
|
|
|
|
#if defined(ARCH_CPU_X86_64)
|
2016-01-28 17:10:36 +01:00
|
|
|
DisableFMA3();
|
|
|
|
#endif
|
2017-04-27 19:02:21 +02:00
|
|
|
InitCrashReporter();
|
|
|
|
#endif
|
2016-01-28 17:10:36 +01:00
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
// Return true if the global context already exists.
|
2013-09-03 20:06:25 +02:00
|
|
|
if (g_context)
|
2012-04-03 03:34:16 +02:00
|
|
|
return true;
|
|
|
|
|
|
|
|
if (settings.size != sizeof(cef_settings_t)) {
|
|
|
|
NOTREACHED() << "invalid CefSettings structure size";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-10-23 21:30:47 +02:00
|
|
|
g_browser_process = new ChromeBrowserProcessStub();
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
// Create the new global context object.
|
2013-09-03 20:06:25 +02:00
|
|
|
g_context = new CefContext();
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
// Initialize the global context.
|
2013-11-15 19:47:02 +01:00
|
|
|
return g_context->Initialize(args, settings, application,
|
|
|
|
windows_sandbox_info);
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CefShutdown() {
|
|
|
|
// Verify that the context is in a valid state.
|
|
|
|
if (!CONTEXT_STATE_VALID()) {
|
|
|
|
NOTREACHED() << "context not valid";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Must always be called on the same thread as Initialize.
|
2013-09-03 20:06:25 +02:00
|
|
|
if (!g_context->OnInitThread()) {
|
2012-04-03 03:34:16 +02:00
|
|
|
NOTREACHED() << "called on invalid thread";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Shut down the global context. This will block until shutdown is complete.
|
2013-09-03 20:06:25 +02:00
|
|
|
g_context->Shutdown();
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
// Delete the global context object.
|
2013-09-03 20:06:25 +02:00
|
|
|
delete g_context;
|
|
|
|
g_context = NULL;
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CefDoMessageLoopWork() {
|
|
|
|
// Verify that the context is in a valid state.
|
|
|
|
if (!CONTEXT_STATE_VALID()) {
|
|
|
|
NOTREACHED() << "context not valid";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Must always be called on the same thread as Initialize.
|
2013-09-03 20:06:25 +02:00
|
|
|
if (!g_context->OnInitThread()) {
|
2012-04-03 03:34:16 +02:00
|
|
|
NOTREACHED() << "called on invalid thread";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
CefBrowserMessageLoop::current()->DoMessageLoopIteration();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefRunMessageLoop() {
|
|
|
|
// Verify that the context is in a valid state.
|
|
|
|
if (!CONTEXT_STATE_VALID()) {
|
|
|
|
NOTREACHED() << "context not valid";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Must always be called on the same thread as Initialize.
|
2013-09-03 20:06:25 +02:00
|
|
|
if (!g_context->OnInitThread()) {
|
2012-04-03 03:34:16 +02:00
|
|
|
NOTREACHED() << "called on invalid thread";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
CefBrowserMessageLoop::current()->RunMessageLoop();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefQuitMessageLoop() {
|
|
|
|
// Verify that the context is in a valid state.
|
|
|
|
if (!CONTEXT_STATE_VALID()) {
|
|
|
|
NOTREACHED() << "context not valid";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Must always be called on the same thread as Initialize.
|
2013-09-03 20:06:25 +02:00
|
|
|
if (!g_context->OnInitThread()) {
|
2012-04-03 03:34:16 +02:00
|
|
|
NOTREACHED() << "called on invalid thread";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-11-10 21:18:16 +01:00
|
|
|
CefBrowserMessageLoop::current()->QuitWhenIdle();
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2013-08-22 19:11:19 +02:00
|
|
|
void CefSetOSModalLoop(bool osModalLoop) {
|
|
|
|
#if defined(OS_WIN)
|
|
|
|
// Verify that the context is in a valid state.
|
|
|
|
if (!CONTEXT_STATE_VALID()) {
|
|
|
|
NOTREACHED() << "context not valid";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (CEF_CURRENTLY_ON_UIT())
|
2013-08-23 16:34:43 +02:00
|
|
|
base::MessageLoop::current()->set_os_modal_loop(osModalLoop);
|
2013-08-22 19:11:19 +02:00
|
|
|
else
|
|
|
|
CEF_POST_TASK(CEF_UIT, base::Bind(CefSetOSModalLoop, osModalLoop));
|
|
|
|
#endif // defined(OS_WIN)
|
|
|
|
}
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
// CefContext
|
|
|
|
|
|
|
|
CefContext::CefContext()
|
2017-05-17 11:29:28 +02:00
|
|
|
: initialized_(false), shutting_down_(false), init_thread_id_(0) {}
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
CefContext::~CefContext() {}
|
2013-09-03 20:06:25 +02:00
|
|
|
|
|
|
|
// static
|
|
|
|
CefContext* CefContext::Get() {
|
|
|
|
return g_context;
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CefContext::Initialize(const CefMainArgs& args,
|
|
|
|
const CefSettings& settings,
|
2013-11-15 19:47:02 +01:00
|
|
|
CefRefPtr<CefApp> application,
|
|
|
|
void* windows_sandbox_info) {
|
2012-04-03 03:34:16 +02:00
|
|
|
init_thread_id_ = base::PlatformThread::CurrentId();
|
|
|
|
settings_ = settings;
|
|
|
|
|
2012-04-11 20:00:55 +02:00
|
|
|
#if !defined(OS_WIN)
|
2012-04-03 03:34:16 +02:00
|
|
|
if (settings.multi_threaded_message_loop) {
|
2012-04-11 20:00:55 +02:00
|
|
|
NOTIMPLEMENTED() << "multi_threaded_message_loop is not supported.";
|
2012-04-03 03:34:16 +02:00
|
|
|
return false;
|
|
|
|
}
|
2012-04-11 20:00:55 +02:00
|
|
|
#endif
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2016-10-17 20:14:44 +02:00
|
|
|
#if defined(OS_WIN)
|
|
|
|
// Signal Chrome Elf that Chrome has begun to start.
|
|
|
|
SignalChromeElf();
|
|
|
|
#endif
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
main_delegate_.reset(new CefMainDelegate(application));
|
2015-11-17 19:20:13 +01:00
|
|
|
browser_info_manager_.reset(new CefBrowserInfoManager);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
int exit_code;
|
|
|
|
|
|
|
|
// Initialize the content runner.
|
2017-04-20 21:28:17 +02:00
|
|
|
content::ContentMainParams params(main_delegate_.get());
|
2012-04-03 03:34:16 +02:00
|
|
|
#if defined(OS_WIN)
|
|
|
|
sandbox::SandboxInterfaceInfo sandbox_info = {0};
|
2013-11-15 19:47:02 +01:00
|
|
|
if (windows_sandbox_info == NULL) {
|
|
|
|
content::InitializeSandboxInfo(&sandbox_info);
|
|
|
|
windows_sandbox_info = &sandbox_info;
|
|
|
|
settings_.no_sandbox = true;
|
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2014-04-04 18:50:38 +02:00
|
|
|
params.instance = args.instance;
|
|
|
|
params.sandbox_info =
|
|
|
|
static_cast<sandbox::SandboxInterfaceInfo*>(windows_sandbox_info);
|
2012-04-03 03:34:16 +02:00
|
|
|
#else
|
2014-04-04 18:50:38 +02:00
|
|
|
params.argc = args.argc;
|
|
|
|
params.argv = const_cast<const char**>(args.argv);
|
2012-04-03 03:34:16 +02:00
|
|
|
#endif
|
|
|
|
|
2017-04-20 21:28:17 +02:00
|
|
|
sm_main_delegate_.reset(
|
|
|
|
new content::ContentServiceManagerMainDelegate(params));
|
|
|
|
sm_main_params_.reset(
|
|
|
|
new service_manager::MainParams(sm_main_delegate_.get()));
|
|
|
|
|
2017-07-18 22:57:04 +02:00
|
|
|
#if defined(OS_POSIX) && !defined(OS_ANDROID)
|
|
|
|
sm_main_params_->argc = params.argc;
|
|
|
|
sm_main_params_->argv = params.argv;
|
|
|
|
#endif
|
|
|
|
|
2017-04-20 21:28:17 +02:00
|
|
|
exit_code = service_manager::MainInitialize(*sm_main_params_);
|
2012-04-03 03:34:16 +02:00
|
|
|
DCHECK_LT(exit_code, 0);
|
|
|
|
if (exit_code >= 0)
|
|
|
|
return false;
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
static_cast<ChromeBrowserProcessStub*>(g_browser_process)
|
|
|
|
->Initialize(*base::CommandLine::ForCurrentProcess());
|
2016-11-07 20:14:09 +01:00
|
|
|
|
2012-06-19 18:29:49 +02:00
|
|
|
// Run the process. Results in a call to CefMainDelegate::RunProcess() which
|
|
|
|
// will create the browser runner and message loop without blocking.
|
2017-04-20 21:28:17 +02:00
|
|
|
exit_code = service_manager::MainRun(*sm_main_params_);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
initialized_ = true;
|
|
|
|
|
2013-10-23 21:30:47 +02:00
|
|
|
if (CEF_CURRENTLY_ON_UIT()) {
|
|
|
|
OnContextInitialized();
|
|
|
|
} else {
|
|
|
|
// Continue initialization on the UI thread.
|
2017-05-17 11:29:28 +02:00
|
|
|
CEF_POST_TASK(CEF_UIT, base::Bind(&CefContext::OnContextInitialized,
|
|
|
|
base::Unretained(this)));
|
2013-10-23 21:30:47 +02:00
|
|
|
}
|
2012-05-18 17:04:56 +02:00
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefContext::Shutdown() {
|
|
|
|
// Must always be called on the same thread as Initialize.
|
|
|
|
DCHECK(OnInitThread());
|
|
|
|
|
|
|
|
shutting_down_ = true;
|
|
|
|
|
|
|
|
if (settings_.multi_threaded_message_loop) {
|
|
|
|
// Events that will be used to signal when shutdown is complete. Start in
|
|
|
|
// non-signaled mode so that the event will block.
|
2016-06-21 00:59:23 +02:00
|
|
|
base::WaitableEvent uithread_shutdown_event(
|
|
|
|
base::WaitableEvent::ResetPolicy::AUTOMATIC,
|
|
|
|
base::WaitableEvent::InitialState::NOT_SIGNALED);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
// Finish shutdown on the UI thread.
|
|
|
|
CEF_POST_TASK(CEF_UIT,
|
2017-05-17 11:29:28 +02:00
|
|
|
base::Bind(&CefContext::FinishShutdownOnUIThread,
|
|
|
|
base::Unretained(this), &uithread_shutdown_event));
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2012-04-11 20:00:55 +02:00
|
|
|
/// Block until UI thread shutdown is complete.
|
|
|
|
uithread_shutdown_event.Wait();
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
FinalizeShutdown();
|
|
|
|
} else {
|
|
|
|
// Finish shutdown on the current thread, which should be the UI thread.
|
2012-04-11 20:00:55 +02:00
|
|
|
FinishShutdownOnUIThread(NULL);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
FinalizeShutdown();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefContext::OnInitThread() {
|
|
|
|
return (base::PlatformThread::CurrentId() == init_thread_id_);
|
|
|
|
}
|
|
|
|
|
2017-04-20 21:28:17 +02:00
|
|
|
SkColor CefContext::GetBackgroundColor(
|
|
|
|
const CefBrowserSettings* browser_settings,
|
|
|
|
cef_state_t windowless_state) const {
|
2017-05-17 11:29:28 +02:00
|
|
|
bool is_windowless = windowless_state == STATE_ENABLED
|
|
|
|
? true
|
|
|
|
: (windowless_state == STATE_DISABLED
|
|
|
|
? false
|
|
|
|
: !!settings_.windowless_rendering_enabled);
|
2017-04-20 21:28:17 +02:00
|
|
|
|
|
|
|
// Default to opaque white if no acceptable color values are found.
|
|
|
|
SkColor sk_color = SK_ColorWHITE;
|
|
|
|
|
|
|
|
if (!browser_settings ||
|
|
|
|
!GetColor(browser_settings->background_color, is_windowless, &sk_color)) {
|
|
|
|
GetColor(settings_.background_color, is_windowless, &sk_color);
|
|
|
|
}
|
|
|
|
return sk_color;
|
|
|
|
}
|
|
|
|
|
2012-10-18 00:45:49 +02:00
|
|
|
CefTraceSubscriber* CefContext::GetTraceSubscriber() {
|
|
|
|
CEF_REQUIRE_UIT();
|
|
|
|
if (shutting_down_)
|
|
|
|
return NULL;
|
|
|
|
if (!trace_subscriber_.get())
|
|
|
|
trace_subscriber_.reset(new CefTraceSubscriber());
|
|
|
|
return trace_subscriber_.get();
|
|
|
|
}
|
|
|
|
|
2015-03-02 21:25:14 +01:00
|
|
|
void CefContext::PopulateRequestContextSettings(
|
|
|
|
CefRequestContextSettings* settings) {
|
|
|
|
CefRefPtr<CefCommandLine> command_line =
|
|
|
|
CefCommandLine::GetGlobalCommandLine();
|
|
|
|
CefString(&settings->cache_path) = CefString(&settings_.cache_path);
|
|
|
|
settings->persist_session_cookies =
|
|
|
|
settings_.persist_session_cookies ||
|
|
|
|
command_line->HasSwitch(switches::kPersistSessionCookies);
|
2015-10-17 02:44:00 +02:00
|
|
|
settings->persist_user_preferences =
|
|
|
|
settings_.persist_user_preferences ||
|
|
|
|
command_line->HasSwitch(switches::kPersistUserPreferences);
|
2015-03-02 21:25:14 +01:00
|
|
|
settings->ignore_certificate_errors =
|
|
|
|
settings_.ignore_certificate_errors ||
|
|
|
|
command_line->HasSwitch(switches::kIgnoreCertificateErrors);
|
2016-11-18 22:11:38 +01:00
|
|
|
settings->enable_net_security_expiration =
|
|
|
|
settings_.enable_net_security_expiration ||
|
|
|
|
command_line->HasSwitch(switches::kEnableNetSecurityExpiration);
|
2015-03-02 21:25:14 +01:00
|
|
|
CefString(&settings->accept_language_list) =
|
|
|
|
CefString(&settings_.accept_language_list);
|
|
|
|
}
|
|
|
|
|
2012-06-19 18:29:49 +02:00
|
|
|
void CefContext::OnContextInitialized() {
|
|
|
|
CEF_REQUIRE_UIT();
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
static_cast<ChromeBrowserProcessStub*>(g_browser_process)
|
|
|
|
->OnContextInitialized();
|
2015-08-31 13:28:07 +02:00
|
|
|
|
2016-11-23 21:54:29 +01:00
|
|
|
#if defined(WIDEVINE_CDM_AVAILABLE) && BUILDFLAG(ENABLE_PEPPER_CDMS)
|
2016-10-14 17:56:41 +02:00
|
|
|
CefWidevineLoader::GetInstance()->OnContextInitialized();
|
|
|
|
#endif
|
|
|
|
|
2012-06-19 18:29:49 +02:00
|
|
|
// Notify the handler.
|
2013-09-03 18:43:31 +02:00
|
|
|
CefRefPtr<CefApp> app = CefContentClient::Get()->application();
|
2012-06-19 18:29:49 +02:00
|
|
|
if (app.get()) {
|
|
|
|
CefRefPtr<CefBrowserProcessHandler> handler =
|
|
|
|
app->GetBrowserProcessHandler();
|
|
|
|
if (handler.get())
|
|
|
|
handler->OnContextInitialized();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
void CefContext::FinishShutdownOnUIThread(
|
|
|
|
base::WaitableEvent* uithread_shutdown_event) {
|
|
|
|
CEF_REQUIRE_UIT();
|
|
|
|
|
2015-11-17 19:20:13 +01:00
|
|
|
browser_info_manager_->DestroyAllBrowsers();
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2012-10-18 00:45:49 +02:00
|
|
|
if (trace_subscriber_.get())
|
|
|
|
trace_subscriber_.reset(NULL);
|
|
|
|
|
2016-07-18 23:22:22 +02:00
|
|
|
static_cast<ChromeBrowserProcessStub*>(g_browser_process)->Shutdown();
|
2015-11-26 04:45:19 +01:00
|
|
|
|
2012-04-11 20:00:55 +02:00
|
|
|
if (uithread_shutdown_event)
|
|
|
|
uithread_shutdown_event->Signal();
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CefContext::FinalizeShutdown() {
|
2013-02-02 01:21:59 +01:00
|
|
|
if (content::RenderProcessHost::run_renderer_in_process()) {
|
|
|
|
// Blocks until RenderProcess cleanup is complete.
|
|
|
|
CefContentRendererClient::Get()->RunSingleProcessCleanup();
|
|
|
|
}
|
|
|
|
|
2012-04-11 20:00:55 +02:00
|
|
|
// Shut down the browser runner or UI thread.
|
2012-04-03 03:34:16 +02:00
|
|
|
main_delegate_->ShutdownBrowser();
|
|
|
|
|
|
|
|
// Shut down the content runner.
|
2017-04-20 21:28:17 +02:00
|
|
|
service_manager::MainShutdown(*sm_main_params_);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2015-11-17 19:20:13 +01:00
|
|
|
browser_info_manager_.reset(NULL);
|
2017-04-20 21:28:17 +02:00
|
|
|
sm_main_params_.reset(NULL);
|
|
|
|
sm_main_delegate_.reset(NULL);
|
2012-04-03 03:34:16 +02:00
|
|
|
main_delegate_.reset(NULL);
|
|
|
|
}
|