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,回調類,主要用來處理與瀏覽器請求相關的的事件,如資源的的加載,重定向等。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM