2013-11-26 23:02:14 +01:00
|
|
|
// Copyright (c) 2013 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 <windows.h>
|
|
|
|
|
2020-06-25 04:34:12 +02:00
|
|
|
#include "include/cef_command_line.h"
|
2013-11-26 23:02:14 +01:00
|
|
|
#include "include/cef_sandbox_win.h"
|
2017-05-17 11:29:28 +02:00
|
|
|
#include "tests/cefsimple/simple_app.h"
|
2013-12-09 17:39:00 +01:00
|
|
|
|
2014-10-22 23:48:11 +02:00
|
|
|
// When generating projects with CMake the CEF_USE_SANDBOX value will be defined
|
|
|
|
// automatically if using the required compiler version. Pass -DUSE_SANDBOX=OFF
|
|
|
|
// to the CMake command-line to disable use of the sandbox.
|
|
|
|
// Uncomment this line to manually enable sandbox support.
|
|
|
|
// #define CEF_USE_SANDBOX 1
|
|
|
|
|
|
|
|
#if defined(CEF_USE_SANDBOX)
|
2018-07-27 23:28:12 +02:00
|
|
|
// The cef_sandbox.lib static library may not link successfully with all VS
|
|
|
|
// versions.
|
2013-12-09 17:39:00 +01:00
|
|
|
#pragma comment(lib, "cef_sandbox.lib")
|
|
|
|
#endif
|
|
|
|
|
2013-11-26 23:02:14 +01:00
|
|
|
// Entry point function for all processes.
|
|
|
|
int APIENTRY wWinMain(HINSTANCE hInstance,
|
|
|
|
HINSTANCE hPrevInstance,
|
2017-05-17 11:29:28 +02:00
|
|
|
LPTSTR lpCmdLine,
|
|
|
|
int nCmdShow) {
|
2013-11-26 23:02:14 +01:00
|
|
|
UNREFERENCED_PARAMETER(hPrevInstance);
|
|
|
|
UNREFERENCED_PARAMETER(lpCmdLine);
|
|
|
|
|
2022-10-21 00:23:32 +02:00
|
|
|
int exit_code;
|
|
|
|
|
|
|
|
#if defined(ARCH_CPU_32_BITS)
|
|
|
|
// Run the main thread on 32-bit Windows using a fiber with the preferred 4MiB
|
|
|
|
// stack size. This function must be called at the top of the executable entry
|
|
|
|
// point function (`main()` or `wWinMain()`). It is used in combination with
|
|
|
|
// the initial stack size of 0.5MiB configured via the `/STACK:0x80000` linker
|
|
|
|
// flag on executable targets. This saves significant memory on threads (like
|
|
|
|
// those in the Windows thread pool, and others) whose stack size can only be
|
|
|
|
// controlled via the linker flag.
|
|
|
|
exit_code = CefRunWinMainWithPreferredStackSize(wWinMain, hInstance,
|
|
|
|
lpCmdLine, nCmdShow);
|
|
|
|
if (exit_code >= 0) {
|
|
|
|
// The fiber has completed so return here.
|
|
|
|
return exit_code;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2020-01-15 15:26:01 +01:00
|
|
|
void* sandbox_info = nullptr;
|
2013-12-09 17:39:00 +01:00
|
|
|
|
2014-10-22 23:48:11 +02:00
|
|
|
#if defined(CEF_USE_SANDBOX)
|
2013-11-26 23:02:14 +01:00
|
|
|
// Manage the life span of the sandbox information object. This is necessary
|
|
|
|
// for sandbox support on Windows. See cef_sandbox_win.h for complete details.
|
|
|
|
CefScopedSandboxInfo scoped_sandbox;
|
2013-12-09 17:39:00 +01:00
|
|
|
sandbox_info = scoped_sandbox.sandbox_info();
|
|
|
|
#endif
|
2013-11-26 23:02:14 +01:00
|
|
|
|
|
|
|
// Provide CEF with command-line arguments.
|
|
|
|
CefMainArgs main_args(hInstance);
|
|
|
|
|
2022-02-18 21:43:30 +01:00
|
|
|
// CEF applications have multiple sub-processes (render, GPU, etc) that share
|
|
|
|
// the same executable. This function checks the command-line and, if this is
|
|
|
|
// a sub-process, executes the appropriate logic.
|
2022-10-21 00:23:32 +02:00
|
|
|
exit_code = CefExecuteProcess(main_args, nullptr, sandbox_info);
|
2013-11-26 23:02:14 +01:00
|
|
|
if (exit_code >= 0) {
|
|
|
|
// The sub-process has completed so return here.
|
|
|
|
return exit_code;
|
|
|
|
}
|
|
|
|
|
2020-06-25 04:34:12 +02:00
|
|
|
// Parse command-line arguments for use in this method.
|
|
|
|
CefRefPtr<CefCommandLine> command_line = CefCommandLine::CreateCommandLine();
|
|
|
|
command_line->InitFromString(::GetCommandLineW());
|
|
|
|
|
2013-11-26 23:02:14 +01:00
|
|
|
// Specify CEF global settings here.
|
|
|
|
CefSettings settings;
|
|
|
|
|
2014-10-22 23:48:11 +02:00
|
|
|
#if !defined(CEF_USE_SANDBOX)
|
2013-12-09 17:39:00 +01:00
|
|
|
settings.no_sandbox = true;
|
|
|
|
#endif
|
|
|
|
|
2015-12-03 23:27:32 +01:00
|
|
|
// SimpleApp implements application-level callbacks for the browser process.
|
|
|
|
// It will create the first browser instance in OnContextInitialized() after
|
|
|
|
// CEF has initialized.
|
|
|
|
CefRefPtr<SimpleApp> app(new SimpleApp);
|
|
|
|
|
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 (!CefInitialize(main_args, settings, app.get(), sandbox_info)) {
|
2024-03-12 20:47:10 +01:00
|
|
|
return CefGetExitCode();
|
2023-11-29 02:33:44 +01:00
|
|
|
}
|
2013-11-26 23:02:14 +01:00
|
|
|
|
|
|
|
// Run the CEF message loop. This will block until CefQuitMessageLoop() is
|
|
|
|
// called.
|
|
|
|
CefRunMessageLoop();
|
|
|
|
|
|
|
|
// Shut down CEF.
|
|
|
|
CefShutdown();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|