CEF3 常用类的介绍

   CEF3作为一个基于Chromium的嵌入式浏览器框架为开发者提供了几个基本的接口类来完成一些基本功能。

CefApp类介绍

   CefApp:与进程,命令行参数,代理,资源管理相关的回调类,用于让CEF3的调用者们定制自己的逻辑。与该类相关的几个函数如下:

 

int CefExecuteProcess(const CefMainArgs& args, CefRefPtr<CefApp> application);                                  bool CefInitialize(const CefMainArgs& args, const CefSettings& settings,  CefRefPtr<CefApp> application);

   CefExecuteProcess()和CefInitialize()都可以将CefApp类的一个对象作为参数传递进来。

 

   另外,CefApp的主要接口如下,其中OnBeforeCommandLineProcessing函数在你的程序启动CEF和Chromium之前给你提供了修改命令行参数的机会;

   OnRegisterCustomSchemes用于注册自定义schemes,剩下的接口用于返回相关回调函数的Handler。

 

// Provides an opportunity to view and/or modify command-line arguments before   
// processing by CEF and Chromium. The |process_type| value will be empty for   
// the browser process. Do not keep a reference to the CefCommandLine object   
// passed to this method. The CefSettings.command_line_args_disabled value   
// can be used to start with an empty command-line object. Any values 
// specified in CefSettings that equate to command-line arguments will be set   
// before this method is called. Be cautious when using this method to modify   
// command-line arguments for non-browser processes as this may result in   
// undefined behavior including crashes. 
virtual void OnBeforeCommandLineProcessing(       
      const CefString& process_type, 
   CefRefPtr<CefCommandLine> command_line) {
}
  
// Provides an opportunity to register custom schemes. Do not keep a reference   
// to the |registrar| object. This method is called on the main thread for   
// each process and the registered schemes should be the same across all  
// processes. 
virtual void OnRegisterCustomSchemes( 
    CefRefPtr<CefSchemeRegistrar> registrar) {   
} 
 
// Return the handler for resource bundle events. If 
// CefSettings.pack_loading_disabled is true a handler must be returned. If no  
// handler is returned resources will be loaded from pack files. This method  
// is called by the browser and render processes on multiple threads. 
virtual CefRefPtr<CefResourceBundleHandler> GetResourceBundleHandler() { 
    return NULL;   
}  
  
// Return the handler for functionality specific to the browser process. This   
// method is called on multiple threads in the browser process. 
virtual CefRefPtr<CefBrowserProcessHandler> GetBrowserProcessHandler() {     
	return NULL;  
}  

// Return the handler for functionality specific to the render process. This   
// method is called on the render process main thread. 
virtual CefRefPtr<CefRenderProcessHandler> GetRenderProcessHandler() {     
	return NULL;  
}


 CefClient 类介绍

 

      CefClient:回调管理类,该类的对象作为参数可以被传递给CefCreateBrowser()或者CefCreateBrowserSync()函数。该类的主要接口如下:

 

// Return the handler for context menus. If no handler is provided the default   
// implementation will be used.    
virtual CefRefPtr<CefContextMenuHandler> GetContextMenuHandler() {
	return NULL;
}

// Return the handler for dialogs. If no handler is provided the default   
// implementation will be used. 
virtual CefRefPtr<CefDialogHandler> GetDialogHandler() {
     return NULL;   
}  

// Return the handler for browser display state events. 
virtual CefRefPtr<CefDisplayHandler> GetDisplayHandler() {
     return NULL;   
}  
  
// Return the handler for download events. If no handler is returned downloads   
// will not be allowed. 
virtual CefRefPtr<CefDownloadHandler> GetDownloadHandler() {
     return NULL;   
}  

// Return the handler for focus events. 
virtual CefRefPtr<CefFocusHandler> GetFocusHandler() {
     return NULL;   
}

// Return the handler for geolocation permissions requests. If no handler is   
// provided geolocation access will be denied by default.    
virtual CefRefPtr<CefGeolocationHandler> GetGeolocationHandler() {
     return NULL;   
}     

// Return the handler for JavaScript dialogs. If no handler is provided the   
// default implementation will be used.    
virtual CefRefPtr<CefJSDialogHandler> GetJSDialogHandler() {
     return NULL;   
}     

// Return the handler for keyboard events.    
virtual CefRefPtr<CefKeyboardHandler> GetKeyboardHandler() {
     return NULL; 
}

// Return the handler for browser life span events.    
virtual CefRefPtr<CefLifeSpanHandler> GetLifeSpanHandler() {
     return NULL;   
}     

// Return the handler for browser load status events.   
virtual CefRefPtr<CefLoadHandler> GetLoadHandler() {
     return NULL;   
}     

// Return the handler for off-screen rendering events.    
virtual CefRefPtr<CefRenderHandler> GetRenderHandler() {
     return NULL;   
}     

// Return the handler for browser request events.    
virtual CefRefPtr<CefRequestHandler> GetRequestHandler() {
     return NULL;  
}

// Called when a new message is received from a different process. Return true   
// if the message was handled or false otherwise. Do not keep a reference to   
// or attempt to access the message outside of this callback.    
virtual bool OnProcessMessageReceived(CefRefPtr<CefBrowser> browser,
                                      CefProcessId source_process,
				      CefRefPtr<CefProcessMessage> message) {     
		return false; 
}                     
	 

   CefClient 中返回的回调类包括:

  • CefContextMenuHandler, 回调类,主要用于处理Context Menu事件。
  • CefDialogHandler,回调类,主要用来处理对话框事件。
  • CefDisplayHandler,回调类,处理与页面状态相关的事件,如页面加载情况的变化,地址栏变化,标题变化等事件。
  • CefDownloadHandler,回调类,主要用来处理文件下载。
  • CefFocusHandler,回调类,主要用来处理焦点事件。
  • CefGeolocationHandler,回调类,用于申请geolocation权限。
  • CefJSDialogHandler,回调类,主要用来处理JS对话框事件。
  • CefKeyboardHandler,回调类,主要用来处理键盘输入事件。
  • CefLifeSpanHandler,回调类,主要用来处理与浏览器生命周期相关的事件,与浏览器对象的创建、销毁以及弹出框的管理。
  • CefLoadHandler, 回调类,主要用来处理浏览器页面加载状态的变化,如页面加载开始,完成,出错等。
  • CefRenderHandler, 回调类,主要用来处理在窗口渲染功能被关闭的情况下的事件。
  • CefRequestHandler, 回调类,主要用来处理与浏览器请求相关的事件,如资源的加载,重定向等。

   

参考:

https://www.yuque.com/docs/share/70eefb63-e027-447b-9fd5-e31b852e141a

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值