-
Notifications
You must be signed in to change notification settings - Fork 68
/
main_linux.cc
96 lines (75 loc) · 2.85 KB
/
main_linux.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
// Copyright (c) 2017 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.
#include "examples/shared/main.h"
#include <X11/Xlib.h>
#include "include/base/cef_logging.h"
#include "examples/shared/app_factory.h"
#include "examples/shared/client_manager.h"
#include "examples/shared/main_util.h"
namespace shared {
namespace {
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);
return 0;
}
int XIOErrorHandlerImpl(Display* display) {
return 0;
}
} // namespace
// Entry point function for all processes.
int main(int argc, char* argv[]) {
// Provide CEF with command-line arguments.
CefMainArgs main_args(argc, argv);
// Create a temporary CommandLine object.
CefRefPtr<CefCommandLine> command_line = CreateCommandLine(main_args);
// Create a CefApp of the correct process type.
CefRefPtr<CefApp> app;
switch (GetProcessType(command_line)) {
case PROCESS_TYPE_BROWSER:
app = CreateBrowserProcessApp();
break;
case PROCESS_TYPE_RENDERER:
app = CreateRendererProcessApp();
break;
case PROCESS_TYPE_OTHER:
app = CreateOtherProcessApp();
break;
}
// CEF applications have multiple sub-processes (render, plugin, GPU, etc)
// that share the same executable. This function checks the command-line and,
// if this is a sub-process, executes the appropriate logic.
int exit_code = CefExecuteProcess(main_args, app, nullptr);
if (exit_code >= 0) {
// The sub-process has completed so return here.
return exit_code;
}
// Install xlib error handlers so that the application won't be terminated
// on non-fatal errors.
XSetErrorHandler(XErrorHandlerImpl);
XSetIOErrorHandler(XIOErrorHandlerImpl);
// Create the singleton manager instance.
ClientManager manager;
// Specify CEF global settings here.
CefSettings settings;
// Initialize the CEF browser process. The first browser instance will be
// created in CefBrowserProcessHandler::OnContextInitialized() after CEF has
// been initialized. 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, nullptr)) {
return 1;
}
// Run the CEF message loop. This will block until CefQuitMessageLoop() is
// called.
CefRunMessageLoop();
// Shut down CEF.
CefShutdown();
return 0;
}
} // namespace shared