#ifndef SIMPLE_APP_H #define SIMPLE_APP_H #pragma once
#include"include/cef_app.h"
// Implement application-level callbacks for the browser process. classSimpleApp : public CefApp, public CefBrowserProcessHandler { public: SimpleApp();
boolOnPopupBrowserViewCreated(CefRefPtr<CefBrowserView> browser_view, CefRefPtr<CefBrowserView> popup_browser_view, bool is_devtools) OVERRIDE { // Create a new top-level Window for the popup. It will show itself after // creation. CefWindow::CreateTopLevelWindow( newSimpleWindowDelegate(popup_browser_view));
#if defined(OS_WIN) || defined(OS_LINUX) // Create the browser using the Views framework if "--use-views" is specified // via the command-line. Otherwise, create the browser using the native // platform framework. The Views framework is currently only supported on // Windows and Linux. constbool use_views = command_line->HasSwitch("use-views"); #else constbool use_views = false; #endif
// Check if a "--url=" value was provided via the command-line. If so, use // that instead of the default URL. url = command_line->GetSwitchValue("url"); if (url.empty()) url = "https://www.cnblogs.com/w4ngzhen/";
if (use_views && !enable_chrome_runtime) { // Create the BrowserView. CefRefPtr<CefBrowserView> browser_view = CefBrowserView::CreateBrowserView( handler, url, browser_settings, nullptr, nullptr, newSimpleBrowserViewDelegate());
// Create the Window. It will show itself after creation. CefWindow::CreateTopLevelWindow(newSimpleWindowDelegate(browser_view)); } else { // Information used when creating the native window. CefWindowInfo window_info;
#if defined(OS_WIN) // On Windows we need to specify certain flags that will be passed to // CreateWindowEx(). window_info.SetAsPopup(NULL, "simple-cef by w4ngzhen"); #endif
// Create the first browser window. CefBrowserHost::CreateBrowser(window_info, handler, url, browser_settings, nullptr, nullptr); } }
classSimpleClient : public CefClient, public CefDisplayHandler, public CefLifeSpanHandler, public CefLoadHandler { public: explicitSimpleClient(bool use_views); ~SimpleClient();
// Closing the main window requires special handling. See the DoClose() // documentation in the CEF header for a detailed destription of this // process. if (browser_list_.size() == 1) { // Set a flag to indicate that the window close should be allowed. is_closing_ = true; }
// Allow the close. For windowed browsers this will result in the OS close // event being sent. returnfalse; }
// Remove from the list of existing browsers. BrowserList::iterator bit = browser_list_.begin(); for (; bit != browser_list_.end(); ++bit) { if ((*bit)->IsSame(browser)) { browser_list_.erase(bit); break; } }
if (browser_list_.empty()) { // All browser windows have closed. Quit the application message loop. CefQuitMessageLoop(); } }
// 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.
// 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 may not link successfully with all VS // versions. #pragma comment(lib, "cef_sandbox.lib") #endif
// Entry point function for all processes. int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow){ UNREFERENCED_PARAMETER(hPrevInstance); UNREFERENCED_PARAMETER(lpCmdLine);
// Enable High-DPI support on Windows 7 or newer. CefEnableHighDPISupport();
void* sandbox_info = nullptr;
#if defined(CEF_USE_SANDBOX) // 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; sandbox_info = scoped_sandbox.sandbox_info(); #endif
// Provide CEF with command-line arguments. CefMainArgs main_args(hInstance);
// CEF applications have multiple sub-processes (render, plugin, GPU, etc) // that share the same executable. This function checks the command-line and, // if this is a sub-process, executes the appropriate logic. int exit_code = CefExecuteProcess(main_args, nullptr, sandbox_info); if (exit_code >= 0) { // The sub-process has completed so return here. return exit_code; }
// Parse command-line arguments for use in this method. CefRefPtr<CefCommandLine> command_line = CefCommandLine::CreateCommandLine(); command_line->InitFromString(::GetCommandLineW());
// Specify CEF global settings here. CefSettings settings;
if (command_line->HasSwitch("enable-chrome-runtime")) { // Enable experimental Chrome runtime. See issue #2969 for details. settings.chrome_runtime = true; }
// 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);