2013-11-26 23:02:14 +01:00
|
|
|
// Copyright (c) 2013 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.
|
|
|
|
|
2016-11-18 00:52:42 +01:00
|
|
|
#include "tests/cefsimple/simple_app.h"
|
2013-11-26 23:02:14 +01:00
|
|
|
|
2019-04-23 19:00:14 +02:00
|
|
|
#if defined(CEF_X11)
|
2014-09-24 19:22:27 +02:00
|
|
|
#include <X11/Xlib.h>
|
2019-04-23 19:00:14 +02:00
|
|
|
#endif
|
2014-09-24 19:22:27 +02:00
|
|
|
|
2014-09-30 18:49:22 +02:00
|
|
|
#include "include/base/cef_logging.h"
|
2020-06-25 04:34:12 +02:00
|
|
|
#include "include/cef_command_line.h"
|
2014-09-30 18:49:22 +02:00
|
|
|
|
2019-04-23 19:00:14 +02:00
|
|
|
#if defined(CEF_X11)
|
2014-09-24 19:22:27 +02:00
|
|
|
namespace {
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
int XErrorHandlerImpl(Display* display, XErrorEvent* event) {
|
2024-01-17 23:44:33 +01:00
|
|
|
LOG(WARNING) << "X error received: " << "type " << event->type << ", "
|
|
|
|
<< "serial " << event->serial << ", " << "error_code "
|
|
|
|
<< static_cast<int>(event->error_code) << ", " << "request_code "
|
|
|
|
<< static_cast<int>(event->request_code) << ", " << "minor_code "
|
|
|
|
<< static_cast<int>(event->minor_code);
|
2014-09-24 19:22:27 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
int XIOErrorHandlerImpl(Display* display) {
|
2014-09-24 19:22:27 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
2019-04-23 19:00:14 +02:00
|
|
|
#endif // defined(CEF_X11)
|
2014-09-24 19:22:27 +02:00
|
|
|
|
2013-11-26 23:02:14 +01:00
|
|
|
// Entry point function for all processes.
|
|
|
|
int main(int argc, char* argv[]) {
|
|
|
|
// Provide CEF with command-line arguments.
|
|
|
|
CefMainArgs main_args(argc, argv);
|
2017-05-17 11:29:28 +02:00
|
|
|
|
2022-02-18 21:43:30 +01:00
|
|
|
// CEF applications have multiple sub-processes (render, GPU, etc) that share
|
|
|
|
// the same executable. This function checks the command-line and, if this is
|
|
|
|
// a sub-process, executes the appropriate logic.
|
2020-01-15 15:26:01 +01:00
|
|
|
int exit_code = CefExecuteProcess(main_args, nullptr, nullptr);
|
2013-11-26 23:02:14 +01:00
|
|
|
if (exit_code >= 0) {
|
|
|
|
// The sub-process has completed so return here.
|
|
|
|
return exit_code;
|
|
|
|
}
|
|
|
|
|
2019-04-23 19:00:14 +02:00
|
|
|
#if defined(CEF_X11)
|
2014-09-24 19:22:27 +02:00
|
|
|
// Install xlib error handlers so that the application won't be terminated
|
|
|
|
// on non-fatal errors.
|
|
|
|
XSetErrorHandler(XErrorHandlerImpl);
|
|
|
|
XSetIOErrorHandler(XIOErrorHandlerImpl);
|
2019-04-23 19:00:14 +02:00
|
|
|
#endif
|
2014-09-24 19:22:27 +02:00
|
|
|
|
2020-06-25 04:34:12 +02:00
|
|
|
// Parse command-line arguments for use in this method.
|
|
|
|
CefRefPtr<CefCommandLine> command_line = CefCommandLine::CreateCommandLine();
|
|
|
|
command_line->InitFromArgv(argc, argv);
|
|
|
|
|
2015-12-03 23:27:32 +01:00
|
|
|
// Specify CEF global settings here.
|
|
|
|
CefSettings settings;
|
|
|
|
|
2024-01-17 23:44:33 +01:00
|
|
|
// Use the CEF Chrome runtime if "--enable-chrome-runtime" is specified via
|
|
|
|
// the command-line. Otherwise, use the CEF Alloy runtime. For more
|
|
|
|
// information about CEF runtimes see
|
|
|
|
// https://bitbucket.org/chromiumembedded/cef/wiki/Architecture.md#markdown-header-cef3
|
2020-06-25 04:34:12 +02:00
|
|
|
if (command_line->HasSwitch("enable-chrome-runtime")) {
|
|
|
|
settings.chrome_runtime = true;
|
|
|
|
}
|
|
|
|
|
2018-07-27 23:28:12 +02:00
|
|
|
// When generating projects with CMake the CEF_USE_SANDBOX value will be defined
|
|
|
|
// automatically. Pass -DUSE_SANDBOX=OFF to the CMake command-line to disable
|
|
|
|
// use of the sandbox.
|
|
|
|
#if !defined(CEF_USE_SANDBOX)
|
|
|
|
settings.no_sandbox = true;
|
|
|
|
#endif
|
|
|
|
|
2015-12-03 23:27:32 +01:00
|
|
|
// SimpleApp implements application-level callbacks for the browser process.
|
|
|
|
// It will create the first browser instance in OnContextInitialized() after
|
|
|
|
// CEF has initialized.
|
|
|
|
CefRefPtr<SimpleApp> app(new SimpleApp);
|
|
|
|
|
2023-11-29 02:33:44 +01:00
|
|
|
// Initialize the CEF browser process. May return false if initialization
|
|
|
|
// fails or if early exit is desired (for example, due to process singleton
|
|
|
|
// relaunch behavior).
|
|
|
|
if (!CefInitialize(main_args, settings, app.get(), nullptr)) {
|
|
|
|
return 1;
|
|
|
|
}
|
2013-11-26 23:02:14 +01:00
|
|
|
|
|
|
|
// Run the CEF message loop. This will block until CefQuitMessageLoop() is
|
|
|
|
// called.
|
|
|
|
CefRunMessageLoop();
|
|
|
|
|
|
|
|
// Shut down CEF.
|
|
|
|
CefShutdown();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|