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 类的一个对象做为参数传递进来。 // 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,回调类,主要用来处理与浏览器请求相关的的事件,如资源的的加载,重定向等。 |
|