|
23 | 23 | // Globals |
24 | 24 | std::string g_cgi_env_from_argv = ""; |
25 | 25 |
|
26 | | -void app_terminate_signal(int signatl) { |
27 | | - LOG(INFO) << "App terminate signal"; |
28 | | - CefQuitMessageLoop(); |
| 26 | +void create_browser() |
| 27 | +{ |
| 28 | + // The call to CreateBrowserSync cannot be in the same block scope |
| 29 | + // as the call to CefShutdown otherwise it results in segmentation |
| 30 | + // fault with the stack trace as seen below. Making a call to |
| 31 | + // browser->Release() did not help. |
| 32 | + // ---- |
| 33 | + // #0 MaybeSendDestroyedNotification () at |
| 34 | + // ./../../chrome/browser/profiles/profile.cc:294 |
| 35 | + // #1 0x00007ffff34c74b5 in Shutdown () at |
| 36 | + // ../../cef/libcef/browser/browser_context.cc:81 |
| 37 | + // ---- |
| 38 | + json_value* app_settings = Settings(); |
| 39 | + CefBrowserSettings browser_settings; |
| 40 | + CefWindowInfo window_info; |
| 41 | + window_info.runtime_style = CEF_RUNTIME_STYLE_ALLOY; |
| 42 | + int default_width = static_cast<int>( |
| 43 | + (*app_settings)["main_window"]["default_size"][0]); |
| 44 | + int default_height = static_cast<int>( |
| 45 | + (*app_settings)["main_window"]["default_size"][1]); |
| 46 | + CefRect browser_rect(0, 0, default_width, default_height); |
| 47 | + window_info.SetAsChild(nullptr, browser_rect); |
| 48 | + CefRefPtr<CefBrowser> browser = CefBrowserHost::CreateBrowserSync( |
| 49 | + window_info, |
| 50 | + Client::GetInstance(), |
| 51 | + mongoose_get_url(), |
| 52 | + browser_settings, |
| 53 | + nullptr, |
| 54 | + nullptr); |
| 55 | + LOG(INFO) << "Browser window handle=" << browser->GetHost()->GetWindowHandle(); |
29 | 56 | } |
30 | 57 |
|
31 | 58 | int main(int argc, char **argv) { |
@@ -184,86 +211,33 @@ int remote_debugging_port( |
184 | 211 | // process. |
185 | 212 | CefRefPtr<App> app(new App); |
186 | 213 |
|
187 | | - // Initialize GDK threads before CEF. |
188 | | - gdk_threads_init(); |
189 | | - |
190 | | - scoped_ptr<MainMessageLoop> message_loop; |
191 | | - message_loop.reset(new MainMessageLoopStd); |
192 | | - |
193 | 214 | // Log messages created by LOG() macro will be written to debug.log |
194 | 215 | // file only after CEF was initialized. Before CEF is initialized |
195 | 216 | // all logs are only printed to console. |
196 | 217 | LOG(INFO) << "Initialize CEF"; |
197 | | - CefInitialize(main_args, cef_settings, app.get(), NULL); |
198 | | - |
199 | | - // The Chromium sandbox requires that there only be a single thread during |
200 | | - // initialization. Therefore initialize GTK after CEF. |
201 | | - gtk_init(&argc, &argv_copy); |
| 218 | + CefInitialize(main_args, cef_settings, app.get(), nullptr); |
202 | 219 |
|
203 | | - // Install a signal handler so we clean up after ourselves. |
204 | | - signal(SIGINT, app_terminate_signal); |
205 | | - signal(SIGTERM, app_terminate_signal); |
206 | | - |
207 | | - // Create Gtk window |
| 220 | + // Create window TODO |
208 | 221 | std::string app_icon_path((*app_settings)["main_window"]["icon"]); |
209 | | - app_icon_path = get_full_path(app_icon_path); |
| 222 | + app_icon_path = GetFullPath(app_icon_path); |
210 | 223 | bool center_on_screen = (*app_settings)["main_window"]["center_on_screen"]; |
211 | | - int default_width = static_cast<long>( |
| 224 | + int default_width = static_cast<int>( |
212 | 225 | (*app_settings)["main_window"]["default_size"][0]); |
213 | | - int default_height = static_cast<long>( |
| 226 | + int default_height = static_cast<int>( |
214 | 227 | (*app_settings)["main_window"]["default_size"][1]); |
215 | | - GtkWidget* gtk_window = create_gtk_window( |
216 | | - (*app_settings)["main_window"]["title"], |
217 | | - app_icon_path.c_str(), |
218 | | - center_on_screen, |
219 | | - default_width, default_height); |
220 | 228 |
|
221 | 229 | // Create browser |
222 | | - ::Window xid = get_window_xid(gtk_window); |
223 | | - LOG(INFO) << "Top window xid=" << xid; |
224 | | - create_browser(xid); |
| 230 | + LOG(INFO) << "Create browser"; |
| 231 | + create_browser(); |
225 | 232 |
|
226 | | - // Run the message loop. This will block until Quit() is called. |
227 | | - int result = message_loop->Run(); |
| 233 | + LOG(INFO) << "Run CEF message loop"; |
| 234 | + CefRunMessageLoop(); |
228 | 235 |
|
229 | 236 | LOG(INFO) << "Stop Mongoose server"; |
230 | 237 | mongoose_stop(); |
231 | 238 |
|
232 | 239 | LOG(INFO) << "Shutdown CEF"; |
233 | 240 | CefShutdown(); |
234 | 241 |
|
235 | | - // Release objects in reverse order of creation. |
236 | | - message_loop.reset(); |
237 | | - |
238 | | - return result; |
239 | | -} |
240 | | - |
241 | | -void create_browser(::Window xid) { |
242 | | - // The call to CreateBrowserSync cannot be in the same block scope |
243 | | - // as the call to CefShutdown otherwise it results in segmentation |
244 | | - // fault with the stack trace as seen below. Making a call to |
245 | | - // browser->Release() did not help. |
246 | | - // ---- |
247 | | - // #0 MaybeSendDestroyedNotification () at |
248 | | - // ./../../chrome/browser/profiles/profile.cc:294 |
249 | | - // #1 0x00007ffff34c74b5 in Shutdown () at |
250 | | - // ../../cef/libcef/browser/browser_context.cc:81 |
251 | | - // ---- |
252 | | - json_value* app_settings = get_app_settings(); |
253 | | - CefBrowserSettings browser_settings; |
254 | | - CefWindowInfo window_info; |
255 | | - window_info.runtime_style = CEF_RUNTIME_STYLE_ALLOY; |
256 | | - int default_width = static_cast<long>( |
257 | | - (*app_settings)["main_window"]["default_size"][0]); |
258 | | - int default_height = static_cast<long>( |
259 | | - (*app_settings)["main_window"]["default_size"][1]); |
260 | | - CefRect browser_rect(0, 0, default_width, default_height); |
261 | | - window_info.SetAsChild(xid, browser_rect); |
262 | | - CefRefPtr<CefBrowser> browser = CefBrowserHost::CreateBrowserSync( |
263 | | - window_info, |
264 | | - ClientHandler::GetInstance(), |
265 | | - mongoose_get_url(), |
266 | | - browser_settings, |
267 | | - NULL); |
268 | | - LOG(INFO) << "Browser xid=" << browser->GetHost()->GetWindowHandle(); |
| 242 | + return 0; |
269 | 243 | } |
0 commit comments