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
|
|
|
|
2015-01-27 01:03:25 +01:00
|
|
|
#include "include/base/cef_scoped_ptr.h"
|
2013-11-15 19:47:02 +01:00
|
|
|
#include "include/cef_sandbox_win.h"
|
2015-01-23 00:11:30 +01:00
|
|
|
#include "cefclient/client_app.h"
|
|
|
|
#include "cefclient/main_context_impl.h"
|
2015-01-22 18:55:55 +01:00
|
|
|
#include "cefclient/main_message_loop_multithreaded_win.h"
|
|
|
|
#include "cefclient/main_message_loop_std.h"
|
2015-01-27 01:03:25 +01:00
|
|
|
#include "cefclient/root_window_manager.h"
|
2015-01-22 21:21:21 +01:00
|
|
|
#include "cefclient/test_runner.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)
|
|
|
|
// The cef_sandbox.lib static library is currently built with VS2013. It may not
|
2013-12-09 17:39:00 +01:00
|
|
|
// link successfully with other VS versions.
|
|
|
|
#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) {
|
2013-12-09 17:39:00 +01:00
|
|
|
void* sandbox_info = NULL;
|
|
|
|
|
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
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
CefMainArgs main_args(hInstance);
|
2012-04-12 22:21:50 +02:00
|
|
|
CefRefPtr<ClientApp> app(new ClientApp);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
// Execute the secondary process, if any.
|
2013-12-09 17:39:00 +01:00
|
|
|
int exit_code = CefExecuteProcess(main_args, app.get(), sandbox_info);
|
2012-04-03 03:34:16 +02:00
|
|
|
if (exit_code >= 0)
|
|
|
|
return exit_code;
|
|
|
|
|
2015-01-23 00:11:30 +01:00
|
|
|
// Create the main context object.
|
2015-01-27 01:03:25 +01:00
|
|
|
scoped_ptr<MainContextImpl> context(new MainContextImpl(0, NULL, 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
|
|
|
|
|
|
|
// Create the main message loop object.
|
2015-01-23 20:09:34 +01:00
|
|
|
scoped_ptr<MainMessageLoop> message_loop;
|
2015-01-22 18:55:55 +01:00
|
|
|
if (settings.multi_threaded_message_loop)
|
2015-01-23 20:09:34 +01:00
|
|
|
message_loop.reset(new MainMessageLoopMultithreadedWin);
|
2015-01-22 18:55:55 +01:00
|
|
|
else
|
2015-01-23 20:09:34 +01:00
|
|
|
message_loop.reset(new MainMessageLoopStd);
|
2015-01-22 18:55:55 +01:00
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
// Initialize CEF.
|
2013-12-09 17:39:00 +01:00
|
|
|
CefInitialize(main_args, settings, app.get(), sandbox_info);
|
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
|
|
|
|
2015-01-27 01:03:25 +01:00
|
|
|
// Create the first window.
|
|
|
|
context->GetRootWindowManager()->CreateRootWindow(
|
|
|
|
true, // Show controls.
|
|
|
|
settings.windowless_rendering_enabled ? true : false,
|
|
|
|
CefRect(), // Use default system size.
|
|
|
|
std::string()); // Use default URL.
|
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.
|
|
|
|
CefShutdown();
|
|
|
|
|
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,
|
|
|
|
LPTSTR lpCmdLine,
|
|
|
|
int nCmdShow) {
|
|
|
|
UNREFERENCED_PARAMETER(hPrevInstance);
|
|
|
|
UNREFERENCED_PARAMETER(lpCmdLine);
|
|
|
|
return client::RunMain(hInstance, nCmdShow);
|
|
|
|
}
|