2015-01-27 01:03:25 +01:00
|
|
|
// Copyright (c) 2015 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 <windows.h>
|
2014-07-15 00:18:51 +02:00
|
|
|
|
2021-06-17 22:08:01 +02:00
|
|
|
#include <memory>
|
|
|
|
|
2015-01-31 05:41:36 +01:00
|
|
|
#include "include/cef_command_line.h"
|
2013-11-15 19:47:02 +01:00
|
|
|
#include "include/cef_sandbox_win.h"
|
2016-11-18 00:52:42 +01:00
|
|
|
#include "tests/cefclient/browser/main_context_impl.h"
|
|
|
|
#include "tests/cefclient/browser/main_message_loop_multithreaded_win.h"
|
2023-11-21 17:24:20 +01:00
|
|
|
#include "tests/cefclient/browser/resource.h"
|
2016-11-18 00:52:42 +01:00
|
|
|
#include "tests/cefclient/browser/root_window_manager.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"
|
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
|
|
|
|
|
2015-01-23 20:09:34 +01:00
|
|
|
namespace client {
|
|
|
|
namespace {
|
2013-12-09 17:39:00 +01:00
|
|
|
|
2015-01-23 20:09:34 +01:00
|
|
|
int RunMain(HINSTANCE hInstance, int nCmdShow) {
|
2015-01-31 05:41:36 +01:00
|
|
|
CefMainArgs main_args(hInstance);
|
|
|
|
|
2020-01-15 15:28:12 +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-12-09 17:39:00 +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.
|
2013-11-15 19:47:02 +01:00
|
|
|
CefScopedSandboxInfo scoped_sandbox;
|
2013-12-09 17:39:00 +01:00
|
|
|
sandbox_info = scoped_sandbox.sandbox_info();
|
|
|
|
#endif
|
2013-11-15 19:47:02 +01:00
|
|
|
|
2015-01-31 05:41:36 +01:00
|
|
|
// Parse command-line arguments.
|
|
|
|
CefRefPtr<CefCommandLine> command_line = CefCommandLine::CreateCommandLine();
|
|
|
|
command_line->InitFromString(::GetCommandLineW());
|
|
|
|
|
|
|
|
// Create a ClientApp of the correct type.
|
|
|
|
CefRefPtr<CefApp> app;
|
|
|
|
ClientApp::ProcessType process_type = ClientApp::GetProcessType(command_line);
|
2023-01-02 23:59:03 +01:00
|
|
|
if (process_type == ClientApp::BrowserProcess) {
|
2015-01-31 05:41:36 +01:00
|
|
|
app = new ClientAppBrowser();
|
2023-01-02 23:59:03 +01:00
|
|
|
} else if (process_type == ClientApp::RendererProcess) {
|
2015-01-31 05:41:36 +01:00
|
|
|
app = new ClientAppRenderer();
|
2023-01-02 23:59:03 +01:00
|
|
|
} else if (process_type == ClientApp::OtherProcess) {
|
2015-01-31 05:41:36 +01:00
|
|
|
app = new ClientAppOther();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
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, sandbox_info);
|
2023-01-02 23:59:03 +01:00
|
|
|
if (exit_code >= 0) {
|
2012-04-03 03:34:16 +02:00
|
|
|
return exit_code;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2015-01-23 00:11:30 +01:00
|
|
|
// Create the main context object.
|
2021-06-17 22:08:01 +02:00
|
|
|
auto context = std::make_unique<MainContextImpl>(command_line, true);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
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
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
// Populate the settings based on command line arguments.
|
2015-01-23 00:11:30 +01:00
|
|
|
context->PopulateSettings(&settings);
|
2015-01-22 18:55:55 +01:00
|
|
|
|
2023-11-21 17:24:20 +01:00
|
|
|
// Set the ID for the ICON resource that will be loaded from the main
|
|
|
|
// executable and used when creating default Chrome windows such as DevTools
|
|
|
|
// and Task Manager. Only used with the Chrome runtime.
|
|
|
|
settings.chrome_app_icon_id = IDR_MAINFRAME;
|
|
|
|
|
2015-01-22 18:55:55 +01:00
|
|
|
// Create the main message loop object.
|
2021-06-17 22:08:01 +02:00
|
|
|
std::unique_ptr<MainMessageLoop> message_loop;
|
2023-01-02 23:59:03 +01:00
|
|
|
if (settings.multi_threaded_message_loop) {
|
2024-01-20 03:22:56 +01:00
|
|
|
message_loop = std::make_unique<MainMessageLoopMultithreadedWin>();
|
2023-01-02 23:59:03 +01:00
|
|
|
} else if (settings.external_message_pump) {
|
2016-05-04 20:00:03 +02:00
|
|
|
message_loop = MainMessageLoopExternalPump::Create();
|
2023-01-02 23:59:03 +01:00
|
|
|
} else {
|
2024-01-20 03:22:56 +01:00
|
|
|
message_loop = std::make_unique<MainMessageLoopStd>();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-01-22 18:55:55 +01:00
|
|
|
|
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 (!context->Initialize(main_args, settings, app, sandbox_info)) {
|
2024-03-12 20:47:10 +01:00
|
|
|
return CefGetExitCode();
|
2023-11-29 02:33:44 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2015-01-22 21:21:21 +01:00
|
|
|
// Register scheme handlers.
|
2015-01-23 20:09:34 +01:00
|
|
|
test_runner::RegisterSchemeHandlers();
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2021-06-19 21:54:45 +02:00
|
|
|
auto window_config = std::make_unique<RootWindowConfig>();
|
|
|
|
window_config->always_on_top =
|
|
|
|
command_line->HasSwitch(switches::kAlwaysOnTop);
|
|
|
|
window_config->with_osr =
|
|
|
|
settings.windowless_rendering_enabled ? true : false;
|
2017-08-04 00:55:19 +02:00
|
|
|
|
2015-01-27 01:03:25 +01:00
|
|
|
// Create the first window.
|
2021-06-19 21:54:45 +02:00
|
|
|
context->GetRootWindowManager()->CreateRootWindow(std::move(window_config));
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2015-01-27 01:03:25 +01:00
|
|
|
// Run the message loop. This will block until Quit() is called by the
|
|
|
|
// RootWindowManager after all windows have been destroyed.
|
2015-01-22 18:55:55 +01:00
|
|
|
int result = message_loop->Run();
|
2012-04-03 03:34:16 +02: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
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2015-01-23 20:09:34 +01:00
|
|
|
} // namespace
|
|
|
|
} // namespace client
|
|
|
|
|
|
|
|
// Program entry point function.
|
|
|
|
int APIENTRY wWinMain(HINSTANCE hInstance,
|
|
|
|
HINSTANCE hPrevInstance,
|
2017-05-17 11:29:28 +02:00
|
|
|
LPTSTR lpCmdLine,
|
|
|
|
int nCmdShow) {
|
2015-01-23 20:09:34 +01:00
|
|
|
UNREFERENCED_PARAMETER(hPrevInstance);
|
|
|
|
UNREFERENCED_PARAMETER(lpCmdLine);
|
2022-10-21 00:23:32 +02:00
|
|
|
|
|
|
|
#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.
|
|
|
|
int exit_code = CefRunWinMainWithPreferredStackSize(wWinMain, hInstance,
|
|
|
|
lpCmdLine, nCmdShow);
|
|
|
|
if (exit_code >= 0) {
|
|
|
|
// The fiber has completed so return here.
|
|
|
|
return exit_code;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-01-23 20:09:34 +01:00
|
|
|
return client::RunMain(hInstance, nCmdShow);
|
|
|
|
}
|