2013-04-03 20:20:59 +02:00
|
|
|
// Copyright (c) 2013 The Chromium Embedded Framework Authors. All rights
|
2012-04-03 03:34:16 +02:00
|
|
|
// reserved. Use of this source code is governed by a BSD-style license that
|
|
|
|
// can be found in the LICENSE file.
|
|
|
|
|
|
|
|
#include <gtk/gtk.h>
|
2014-05-22 23:01:22 +02:00
|
|
|
|
|
|
|
#include <X11/Xlib.h>
|
2015-01-29 21:53:53 +01:00
|
|
|
#undef Success // Definition conflicts with cef_message_router.h
|
|
|
|
#undef RootWindow // Definition conflicts with root_window.h
|
2014-05-22 23:01:22 +02:00
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
2021-06-17 22:08:01 +02:00
|
|
|
#include <memory>
|
2012-04-03 03:34:16 +02:00
|
|
|
#include <string>
|
2014-05-22 23:01:22 +02:00
|
|
|
|
2014-09-30 18:49:22 +02:00
|
|
|
#include "include/base/cef_logging.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
#include "include/cef_app.h"
|
2015-01-31 05:41:36 +01:00
|
|
|
#include "include/cef_command_line.h"
|
2014-07-11 22:10:05 +02:00
|
|
|
#include "include/wrapper/cef_helpers.h"
|
2016-11-18 00:52:42 +01:00
|
|
|
#include "tests/cefclient/browser/main_context_impl.h"
|
2018-09-20 15:00:14 +02:00
|
|
|
#include "tests/cefclient/browser/main_message_loop_multithreaded_gtk.h"
|
2016-11-18 00:52:42 +01:00
|
|
|
#include "tests/cefclient/browser/test_runner.h"
|
|
|
|
#include "tests/shared/browser/client_app_browser.h"
|
|
|
|
#include "tests/shared/browser/main_message_loop_external_pump.h"
|
|
|
|
#include "tests/shared/browser/main_message_loop_std.h"
|
|
|
|
#include "tests/shared/common/client_app_other.h"
|
|
|
|
#include "tests/shared/common/client_switches.h"
|
|
|
|
#include "tests/shared/renderer/client_app_renderer.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2015-01-23 20:09:34 +01:00
|
|
|
namespace client {
|
|
|
|
namespace {
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
int XErrorHandlerImpl(Display* display, XErrorEvent* event) {
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
void TerminationSignalHandler(int signatl) {
|
2015-01-29 21:53:53 +01:00
|
|
|
LOG(ERROR) << "Received termination signal: " << signatl;
|
|
|
|
MainContext::Get()->GetRootWindowManager()->CloseAllWindows(true);
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2015-01-23 20:09:34 +01:00
|
|
|
int RunMain(int argc, char* argv[]) {
|
2014-07-01 00:30:29 +02:00
|
|
|
// Create a copy of |argv| on Linux because Chromium mangles the value
|
|
|
|
// internally (see issue #620).
|
2014-07-11 22:10:05 +02:00
|
|
|
CefScopedArgArray scoped_arg_array(argc, argv);
|
2014-07-01 00:30:29 +02:00
|
|
|
char** argv_copy = scoped_arg_array.array();
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
CefMainArgs main_args(argc, argv);
|
2015-01-31 05:41:36 +01:00
|
|
|
|
|
|
|
// Parse command-line arguments.
|
|
|
|
CefRefPtr<CefCommandLine> command_line = CefCommandLine::CreateCommandLine();
|
|
|
|
command_line->InitFromArgv(argc, argv);
|
|
|
|
|
|
|
|
// Create a ClientApp of the correct type.
|
|
|
|
CefRefPtr<CefApp> app;
|
|
|
|
ClientApp::ProcessType process_type = ClientApp::GetProcessType(command_line);
|
|
|
|
if (process_type == ClientApp::BrowserProcess) {
|
|
|
|
app = new ClientAppBrowser();
|
|
|
|
} else if (process_type == ClientApp::RendererProcess ||
|
|
|
|
process_type == ClientApp::ZygoteProcess) {
|
|
|
|
// On Linux the zygote process is used to spawn other process types. Since
|
|
|
|
// we don't know what type of process it will be give it the renderer
|
|
|
|
// client.
|
|
|
|
app = new ClientAppRenderer();
|
|
|
|
} else if (process_type == ClientApp::OtherProcess) {
|
|
|
|
app = new ClientAppOther();
|
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
// Execute the secondary process, if any.
|
2020-01-15 15:28:12 +01:00
|
|
|
int exit_code = CefExecuteProcess(main_args, app, nullptr);
|
2023-01-02 23:59:03 +01:00
|
|
|
if (exit_code >= 0) {
|
2012-04-03 03:34:16 +02:00
|
|
|
return exit_code;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2015-01-23 00:11:30 +01:00
|
|
|
// Create the main context object.
|
2021-06-17 22:08:01 +02:00
|
|
|
auto context = std::make_unique<MainContextImpl>(command_line, true);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
CefSettings settings;
|
|
|
|
|
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
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
// Populate the settings based on command line arguments.
|
2015-01-23 00:11:30 +01:00
|
|
|
context->PopulateSettings(&settings);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2021-03-01 20:41:27 +01:00
|
|
|
if (settings.windowless_rendering_enabled) {
|
|
|
|
// Force the app to use OpenGL <= 3.1 when off-screen rendering is enabled.
|
|
|
|
// TODO(cefclient): Rewrite OSRRenderer to use shaders instead of the
|
|
|
|
// fixed-function pipeline which was removed in OpenGL 3.2 (back in 2009).
|
2022-09-05 22:56:49 +02:00
|
|
|
setenv("MESA_GL_VERSION_OVERRIDE", "3.1", /*overwrite=*/0);
|
2021-03-01 20:41:27 +01:00
|
|
|
}
|
|
|
|
|
2015-01-22 18:55:55 +01:00
|
|
|
// Create the main message loop object.
|
2021-06-17 22:08:01 +02:00
|
|
|
std::unique_ptr<MainMessageLoop> message_loop;
|
2023-01-02 23:59:03 +01:00
|
|
|
if (settings.multi_threaded_message_loop) {
|
2018-09-20 15:00:14 +02:00
|
|
|
message_loop.reset(new MainMessageLoopMultithreadedGtk);
|
2023-01-02 23:59:03 +01:00
|
|
|
} else if (settings.external_message_pump) {
|
2016-05-04 20:00:03 +02:00
|
|
|
message_loop = MainMessageLoopExternalPump::Create();
|
2023-01-02 23:59:03 +01:00
|
|
|
} else {
|
2016-05-04 20:00:03 +02:00
|
|
|
message_loop.reset(new MainMessageLoopStd);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-01-22 18:55:55 +01:00
|
|
|
|
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 (!context->Initialize(main_args, settings, app, nullptr)) {
|
|
|
|
return 1;
|
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2021-03-01 20:41:27 +01:00
|
|
|
// Force Gtk to use Xwayland (in case a Wayland compositor is being used).
|
|
|
|
gdk_set_allowed_backends("x11");
|
|
|
|
|
2014-05-22 23:01:22 +02:00
|
|
|
// The Chromium sandbox requires that there only be a single thread during
|
|
|
|
// initialization. Therefore initialize GTK after CEF.
|
2014-07-01 00:30:29 +02:00
|
|
|
gtk_init(&argc, &argv_copy);
|
|
|
|
|
2015-10-14 18:44:22 +02:00
|
|
|
// Install xlib error handlers so that the application won't be terminated
|
|
|
|
// on non-fatal errors. Must be done after initializing GTK.
|
|
|
|
XSetErrorHandler(XErrorHandlerImpl);
|
|
|
|
XSetIOErrorHandler(XIOErrorHandlerImpl);
|
|
|
|
|
2014-05-22 23:01:22 +02:00
|
|
|
// Install a signal handler so we clean up after ourselves.
|
2012-04-03 03:34:16 +02:00
|
|
|
signal(SIGINT, TerminationSignalHandler);
|
|
|
|
signal(SIGTERM, TerminationSignalHandler);
|
|
|
|
|
2015-01-29 21:53:53 +01:00
|
|
|
// Register scheme handlers.
|
|
|
|
test_runner::RegisterSchemeHandlers();
|
|
|
|
|
2021-06-19 21:54:45 +02:00
|
|
|
auto window_config = std::make_unique<RootWindowConfig>();
|
|
|
|
window_config->always_on_top =
|
|
|
|
command_line->HasSwitch(switches::kAlwaysOnTop);
|
|
|
|
window_config->with_osr =
|
|
|
|
settings.windowless_rendering_enabled ? true : false;
|
2017-08-04 00:55:19 +02:00
|
|
|
|
2015-01-29 21:53:53 +01:00
|
|
|
// Create the first window.
|
2021-06-19 21:54:45 +02:00
|
|
|
context->GetRootWindowManager()->CreateRootWindow(std::move(window_config));
|
2015-01-29 21:53:53 +01:00
|
|
|
|
2015-01-22 18:55:55 +01:00
|
|
|
// Run the message loop. This will block until Quit() is called.
|
|
|
|
int result = message_loop->Run();
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2015-01-22 18:55:55 +01:00
|
|
|
// Shut down CEF.
|
2015-01-29 21:53:53 +01:00
|
|
|
context->Shutdown();
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2015-01-23 00:11:30 +01:00
|
|
|
// Release objects in reverse order of creation.
|
2015-01-22 18:55:55 +01:00
|
|
|
message_loop.reset();
|
2015-01-23 00:11:30 +01:00
|
|
|
context.reset();
|
2015-01-22 18:55:55 +01:00
|
|
|
|
|
|
|
return result;
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
2015-01-23 20:09:34 +01:00
|
|
|
|
|
|
|
} // namespace
|
|
|
|
} // namespace client
|
|
|
|
|
|
|
|
// Program entry point function.
|
|
|
|
int main(int argc, char* argv[]) {
|
|
|
|
return client::RunMain(argc, argv);
|
|
|
|
}
|