1 // Copyright (c) 2013 The Chromium Embedded Framework Authors. All rights
2 // reserved. Use of this source code is governed by a BSD-style license that
3 // can be found in the LICENSE file.
4
5 #include <windows.h>
6
7 #include "include/cef_command_line.h"
8 #include "include/cef_sandbox_win.h"
9 #include "tests/cefsimple/simple_app.h"
10
11 // When generating projects with CMake the CEF_USE_SANDBOX value will be defined
12 // automatically if using the required compiler version. Pass -DUSE_SANDBOX=OFF
13 // to the CMake command-line to disable use of the sandbox.
14 // Uncomment this line to manually enable sandbox support.
15 // #define CEF_USE_SANDBOX 1
16
17 #if defined(CEF_USE_SANDBOX)
18 // The cef_sandbox.lib static library may not link successfully with all VS
19 // versions.
20 #pragma comment(lib, "cef_sandbox.lib")
21 #endif
22
23 // Entry point function for all processes.
wWinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPTSTR lpCmdLine,int nCmdShow)24 int APIENTRY wWinMain(HINSTANCE hInstance,
25 HINSTANCE hPrevInstance,
26 LPTSTR lpCmdLine,
27 int nCmdShow) {
28 UNREFERENCED_PARAMETER(hPrevInstance);
29 UNREFERENCED_PARAMETER(lpCmdLine);
30
31 // Enable High-DPI support on Windows 7 or newer.
32 CefEnableHighDPISupport();
33
34 void* sandbox_info = nullptr;
35
36 #if defined(CEF_USE_SANDBOX)
37 // Manage the life span of the sandbox information object. This is necessary
38 // for sandbox support on Windows. See cef_sandbox_win.h for complete details.
39 CefScopedSandboxInfo scoped_sandbox;
40 sandbox_info = scoped_sandbox.sandbox_info();
41 #endif
42
43 // Provide CEF with command-line arguments.
44 CefMainArgs main_args(hInstance);
45
46 // CEF applications have multiple sub-processes (render, plugin, GPU, etc)
47 // that share the same executable. This function checks the command-line and,
48 // if this is a sub-process, executes the appropriate logic.
49 int exit_code = CefExecuteProcess(main_args, nullptr, sandbox_info);
50 if (exit_code >= 0) {
51 // The sub-process has completed so return here.
52 return exit_code;
53 }
54
55 // Parse command-line arguments for use in this method.
56 CefRefPtr<CefCommandLine> command_line = CefCommandLine::CreateCommandLine();
57 command_line->InitFromString(::GetCommandLineW());
58
59 // Specify CEF global settings here.
60 CefSettings settings;
61
62 if (command_line->HasSwitch("enable-chrome-runtime")) {
63 // Enable experimental Chrome runtime. See issue #2969 for details.
64 settings.chrome_runtime = true;
65 }
66
67 #if !defined(CEF_USE_SANDBOX)
68 settings.no_sandbox = true;
69 #endif
70
71 // SimpleApp implements application-level callbacks for the browser process.
72 // It will create the first browser instance in OnContextInitialized() after
73 // CEF has initialized.
74 CefRefPtr<SimpleApp> app(new SimpleApp);
75
76 // Initialize CEF.
77 CefInitialize(main_args, settings, app.get(), sandbox_info);
78
79 // Run the CEF message loop. This will block until CefQuitMessageLoop() is
80 // called.
81 CefRunMessageLoop();
82
83 // Shut down CEF.
84 CefShutdown();
85
86 return 0;
87 }
88