Learn the basic classes and methods of LIBCEF--LIBCEF (how to produce a browser of your own)

Source: Internet
Author: User

Please specify the source:
http://blog.csdn.net/wangshubo1989

It is still a simple analysis of LIBCEF on the basis of the Win32 project. Note that this is an introduction to LIBCEF classes and methods in the WinMain function.

First, the previous section of code:

#include <windows.h>#include "cefsimple/simple_app.h"//Entry point function for all processes.intApientryWinMain (HInstance hinstance,hinstancehPrevInstance,LPTSTRlpCmdLine,intnCmdShow) {unreferenced_parameter (hprevinstance); Unreferenced_parameter (lpCmdLine);//Enable high-dpi support on Windows 7 or newer.Cefenablehighdpisupport ();void* Sandbox_info = NULL;//provide CEF with command-line arguments.Cefmainargs Main_args (HINSTANCE);//Simpleapp implements Application-level callbacks. It'll create the first  //Browser instance in oncontextinitialized () after CEF have initialized.Cefrefptr<simpleapp> app (NewSimpleapp);//Specify CEF Global settings here.Cefsettings settings; Settings.no_sandbox =true;//Initialize CEF.Cefinitialize (Main_args, settings, app.Get(), sandbox_info);//Run the CEF message loop. This would block until Cefquitmessageloop () is  //called.Cefrunmessageloop ();//Shut down CEF.Cefshutdown ();return 0;}

The following is a brief introduction to the contents of the above code.

first, the role of Unreferenced_parameter
Role: Tell the compiler that the variable is already in use and do not have to detect the warning!
Unreferenced_parameter (hprevinstance);
Unreferenced_parameter (lpCmdLine);

Second, Gao Qingxian function cefenablehighdpisupport ()
You can refer to the link: http://www.ubergizmo.com/how-to/how-to-google-chrome-hidpi-support-windows/
Enable high-dpi Support on Windows 7 or newer.
Cefenablehighdpisupport ();

three, Cefmainargs and cefexecuteprocess functions (judging child threads)
Provide a command line way, temporarily do not know what happened!
Provide CEF with command-line arguments.
Cefmainargs Main_args (HINSTANCE);

Many of the features in CEF3 and chromium can be configured using command line parameters. These parameters are in "–some-argument[=optional-param" form and are passed to CEF via the cefexecuteprocess () and Cefmainargs structures (refer to the "Application Resource Layout" section below). Before passing the cefsettings structure to cefinitialize (), we can set the cefsettings.command_line_args_disabled to False to disable processing of command-line arguments. Implement the Cefapp::onbeforecommandlineprocessing () method if you want to specify command-line arguments to pass into the main application.

Iv. cefrefptr

Create an instance of Simpleapp and save the process-level callbacks in this class.
Initialize CEF and turn on the message loop.

  CefRefPtr<SimpleApp> app(new SimpleApp);

v. Customizing your CEF (Cefwindowinfo and Settings)
5.1. Global Settings
Specify CEF global settings here.

  CefSettings settings;  true;

5.2. Local Windows information

  // Information used when creating the native window.  CefWindowInfo window_info;  window_info.SetAsPopup(NULL, L"百度");  //无透明值  window_info.SetTransparentPainting(FALSE);

5.3. Browser settings

// Specify CEF browser settings here.  CefBrowserSettings browser_settings;

There are a number of parameters that can be configured here
Like what:
Defaultencoding (encoding for all Web content, default to Iso-8859-1)
Userstylesheetlocation (for all Web page styles, this field should be set in this format: Data:text/css;charset=utf-8;base64,[csscontent])
Remotefonts (font for all Web pages)
JavaScript (for all Web pages can execute JS script)
Javascriptopenwindows (for all web pages can be opened via JS window)

vi. Initialization of CEF
Initialize CEF.
Cefinitialize (Main_args, Settings, App.get (), sandbox_info);
When CEF initialization is complete, simpleapp::oncontextinitialized () is called. In this method:

Create a single-instance Simplehandler
Create a browser window from Cefbrowserhost::createbrowsersync ()
All browsers share the same one in Simplehandler. Simplehandler is responsible for customizing browser behavior and saving browser-related callbacks (loading status, title behavior, etc.)
When the browser window is closed, Simplehandler::onbeforeclose () is called. When all browser windows are closed, the CEF message loop exits.

Vii. Message Loops
Run the CEF message loop. This would block until Cefquitmessageloop () is
Called.
Cefrunmessageloop ();

Viii. Close CEF
Shut down CEF.
Cefshutdown ();

ix. Creating a browser window
Createbrowser is a static function

Create the first browser window.  CefBrowserHost::CreateBrowser(window_info, handler.get(), "http:\\www.vagaa.com",                                browser_settings, NULL);

================================================================
Applications handle Browser Control events by calling Cefbrowser and Cefframe methods :
Back, Forward, Reload and Stop Load. Navigation of the control browser
Undo, Redo, Cut, Copy, Paste, Delete, select All. Control the selection of the target frame
Print. Prints the target frame
Get Source. Gets the HTML source of the target frame in the form of a string
view source. Use the cache file to save the HTML source of the destination frame, and open the
load URL with the system's default text viewer. Load a specific URL to the target framework
load String . Loads a specific string into the target frame, using a randomly specified virtual URL
load Stream. Loads a specific binary file into the target frame, with a randomly specified virtual URL
Load request, loading a specific request to the target framework
Execute JavaScript: Executes a specific javscript command within the target frame
Zoom. Scale Web page content for a specific frame

Framework Interface:
Cefbrowser is the main browser window class that can be used to create a new browser window with static functions Createbrowser () and Createbrowsersync ().
Cefframe represents a frame of a browser window, each browser window has a top-level main frame, and the main frame can be obtained using the Getmainframe () method.
Cefclient is the representative interface of the main browser window, which is passed as a parameter to Createbrowser ()
Cefrequest represents a URL, method, send data and header file such as such a request.
The Cefschemehandlefactory class is used to handle requests like myscheme://mydomain similar customer plans
Cefreadhandler and Cefwritehandle are a simple interface for reading and writing data.
Cefv8handler,cefv8value and Cefv8context are used to create and access JavaScript objects.

Learn the basic classes and methods of LIBCEF--LIBCEF (how to produce a browser of your own)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.