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-07-01 00:30:29 +02:00
|
|
|
#include <gtk/gtkgl.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>
|
|
|
|
#include <string>
|
2014-05-22 23:01:22 +02:00
|
|
|
|
2014-09-30 18:49:22 +02:00
|
|
|
#include "include/base/cef_logging.h"
|
2014-09-11 20:23:10 +02:00
|
|
|
#include "include/base/cef_scoped_ptr.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"
|
|
|
|
#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.
|
2015-01-31 05:41:36 +01:00
|
|
|
int exit_code = CefExecuteProcess(main_args, app, NULL);
|
2012-04-03 03:34:16 +02:00
|
|
|
if (exit_code >= 0)
|
|
|
|
return exit_code;
|
|
|
|
|
2015-01-23 00:11:30 +01:00
|
|
|
// Create the main context object.
|
2015-01-31 05:41:36 +01:00
|
|
|
scoped_ptr<MainContextImpl> context(new MainContextImpl(command_line, true));
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
CefSettings settings;
|
|
|
|
|
|
|
|
// 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
|
|
|
|
2015-01-22 18:55:55 +01:00
|
|
|
// Create the main message loop object.
|
2016-05-04 20:00:03 +02:00
|
|
|
scoped_ptr<MainMessageLoop> message_loop;
|
|
|
|
if (settings.external_message_pump)
|
|
|
|
message_loop = MainMessageLoopExternalPump::Create();
|
|
|
|
else
|
|
|
|
message_loop.reset(new MainMessageLoopStd);
|
2015-01-22 18:55:55 +01:00
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
// Initialize CEF.
|
2015-01-31 05:41:36 +01:00
|
|
|
context->Initialize(main_args, settings, app, NULL);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
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);
|
|
|
|
|
|
|
|
// Perform gtkglext initialization required by the OSR example.
|
|
|
|
gtk_gl_init(&argc, &argv_copy);
|
2014-05-22 23:01:22 +02:00
|
|
|
|
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();
|
|
|
|
|
|
|
|
// Create the first window.
|
|
|
|
context->GetRootWindowManager()->CreateRootWindow(
|
2016-01-19 21:09:01 +01:00
|
|
|
!command_line->HasSwitch(switches::kHideControls), // Show controls.
|
2015-01-29 21:53:53 +01:00
|
|
|
settings.windowless_rendering_enabled ? true : false,
|
2017-05-17 11:29:28 +02:00
|
|
|
CefRect(), // Use default system size.
|
|
|
|
std::string()); // Use default URL.
|
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);
|
|
|
|
}
|