1 // Copyright (c) 2013 The Chromium Embedded Framework Authors. All rights
2 // reserved. Use of this source code is governed by a BSD-style license that
3 // can be found in the LICENSE file.
4
5 #include "tests/cefsimple/simple_app.h"
6
7 #if defined(CEF_X11)
8 #include <X11/Xlib.h>
9 #endif
10
11 #include "include/base/cef_logging.h"
12 #include "include/cef_command_line.h"
13
14 #if defined(CEF_X11)
15 namespace {
16
XErrorHandlerImpl(Display * display,XErrorEvent * event)17 int XErrorHandlerImpl(Display* display, XErrorEvent* event) {
18 LOG(WARNING) << "X error received: "
19 << "type " << event->type << ", "
20 << "serial " << event->serial << ", "
21 << "error_code " << static_cast<int>(event->error_code) << ", "
22 << "request_code " << static_cast<int>(event->request_code)
23 << ", "
24 << "minor_code " << static_cast<int>(event->minor_code);
25 return 0;
26 }
27
XIOErrorHandlerImpl(Display * display)28 int XIOErrorHandlerImpl(Display* display) {
29 return 0;
30 }
31
32 } // namespace
33 #endif // defined(CEF_X11)
34
35 // Entry point function for all processes.
main(int argc,char * argv[])36 int main(int argc, char* argv[]) {
37 // Provide CEF with command-line arguments.
38 CefMainArgs main_args(argc, argv);
39
40 // CEF applications have multiple sub-processes (render, plugin, GPU, etc)
41 // that share the same executable. This function checks the command-line and,
42 // if this is a sub-process, executes the appropriate logic.
43 int exit_code = CefExecuteProcess(main_args, nullptr, nullptr);
44 if (exit_code >= 0) {
45 // The sub-process has completed so return here.
46 return exit_code;
47 }
48
49 #if defined(CEF_X11)
50 // Install xlib error handlers so that the application won't be terminated
51 // on non-fatal errors.
52 XSetErrorHandler(XErrorHandlerImpl);
53 XSetIOErrorHandler(XIOErrorHandlerImpl);
54 #endif
55
56 // Parse command-line arguments for use in this method.
57 CefRefPtr<CefCommandLine> command_line = CefCommandLine::CreateCommandLine();
58 command_line->InitFromArgv(argc, argv);
59
60 // Specify CEF global settings here.
61 CefSettings settings;
62
63 if (command_line->HasSwitch("enable-chrome-runtime")) {
64 // Enable experimental Chrome runtime. See issue #2969 for details.
65 settings.chrome_runtime = true;
66 }
67
68 // When generating projects with CMake the CEF_USE_SANDBOX value will be defined
69 // automatically. Pass -DUSE_SANDBOX=OFF to the CMake command-line to disable
70 // use of the sandbox.
71 #if !defined(CEF_USE_SANDBOX)
72 settings.no_sandbox = true;
73 #endif
74
75 // SimpleApp implements application-level callbacks for the browser process.
76 // It will create the first browser instance in OnContextInitialized() after
77 // CEF has initialized.
78 CefRefPtr<SimpleApp> app(new SimpleApp);
79
80 // Initialize CEF for the browser process.
81 CefInitialize(main_args, settings, app.get(), nullptr);
82
83 // Run the CEF message loop. This will block until CefQuitMessageLoop() is
84 // called.
85 CefRunMessageLoop();
86
87 // Shut down CEF.
88 CefShutdown();
89
90 return 0;
91 }
92