CEF3 筆記三(常用類的介紹)


接上文《CEF3 筆記二(常用的類介紹)》

CefBrowserHost 類介紹

CefBrowserHost: 該類在瀏覽器窗口來看代表了 browser 進程,同時也暴露了與瀏覽器窗口相關的接口,該類的方法只能在 browser 進程中調用,但可以在 browser 進程的任意線程中被調用。該類的主要方法如下:

  • 創建瀏覽器對象。

需要傳入的參數包括 CefWindowInfo 對象,CefClient 對象,默認的 URL, 以及瀏覽器啟動時參數設置。

public static bool CreateBrowser(const CefWindowInfo& windowInfo,
                       CefRefPtr<CefClient> client, const CefString& url,
                      const CefBrowserSettings& settings);
public static CefRefPtr<CefBrowser> CreateBrowserSync(
                 const CefWindowInfo& windowInfo,
                  CefRefPtr< CefClient > client,
                 const CefString& url, const CefBrowserSettings& settings);
  • 請求關閉瀏覽器對象。該函數被調用是會觸發 JS 'onbeforeunload' 事件,如果參數 force_close為 false,並且提供了 onbeforeunload 事件的回調函數,則提示用戶是否關閉瀏覽器,此時用戶可以選取取消操作。如果 force_close為 true,則直接關閉瀏覽器。
public virtual void CloseBrowser(bool force_close)= 0;
  • 獲取瀏覽器對象(在 CefBrowser 類中可以通過調用 GetHost() 獲取與之對應的 CefBrowserHost)
public virtual CefRefPtr< CefBrowser > GetBrowser()= 0;
  • 獲取 CefClient 對象
public virtual CefRefPtr< CefClient > GetClient()= 0;
  • 獲取該瀏覽器對象的窗口句柄,如果是彈出窗口,則返回 NULL。
public virtual CefWindowHandle GetOpenerWindowHandle()= 0;

 

CefBrowser 類介紹

CefBrowser: 該類代表一個瀏覽器對象,在 browser 進程中該類的方法可以被任意線程調用。在 render 進程中只能在主線程被調用。該類的主要方法包括:

  // Returns the browser host object. This method can only be called in the
  // browser process.
  virtual CefRefPtr<CefBrowserHost> GetHost() =0;

  // Returns true if the browser can navigate backwards.
  virtual bool CanGoBack() =0;

  // Navigate backwards.
  virtual void GoBack() =0;

  // Returns true if the browser can navigate forwards.
  virtual bool CanGoForward() =0;

  // Navigate forwards.
  virtual void GoForward() =0;

  // Returns true if the browser is currently loading.
  virtual bool IsLoading() =0;

  // Reload the current page.
  virtual void Reload() =0;

  // Reload the current page ignoring any cached data.
  virtual void ReloadIgnoreCache() =0;

  // Stop loading the page.
  virtual void StopLoad() =0;

  // Returns the globally unique identifier for this browser.
  virtual int GetIdentifier() =0;

  // Returns true if this object is pointing to the same handle as |that|
  // object.
  virtual bool IsSame(CefRefPtr<CefBrowser> that) =0;

  // Returns true if the window is a popup window.
  virtual bool IsPopup() =0;

  // Returns true if a document has been loaded in the browser.
  virtual bool HasDocument() =0;

  // Returns the main (top-level) frame for the browser window.
  virtual CefRefPtr<CefFrame> GetMainFrame() =0;

  // Returns the focused frame for the browser window.
  virtual CefRefPtr<CefFrame> GetFocusedFrame() =0;

  // Returns the frame with the specified identifier, or NULL if not found.
  virtual CefRefPtr<CefFrame> GetFrame(int64 identifier) =0;

  // Returns the frame with the specified name, or NULL if not found.
  virtual CefRefPtr<CefFrame> GetFrame(const CefString& name) =0;

  // Returns the number of frames that currently exist.
  virtual size_t GetFrameCount() =0;

  // Returns the identifiers of all existing frames.
  virtual void GetFrameIdentifiers(std::vector<int64>& identifiers) =0;

  // Returns the names of all existing frames.
  virtual void GetFrameNames(std::vector<CefString>& names) =0;

  // Send a message to the specified |target_process|. Returns true if the
  // message was sent successfully.
  virtual bool SendProcessMessage(CefProcessId target_process,
                                  CefRefPtr<CefProcessMessage> message) =0;

CefFrame 類介紹

CefFrame: 表示瀏覽器窗口中的一個 frame,在 browser 進程中該類的方法可以被任意線程調用(簡單理解就是 Frame 標識一個頁面,通過該類開發者可以加載某一URL 或者一段 HTML 代碼,獲取頁面的源碼和文本,URL,V8 執行上下文,訪問頁面中的 DOM)。該類的主要方法如下:

  // True if this object is currently attached to a valid frame.
  virtual bool IsValid() =0;

  // Execute undo in this frame.
  virtual void Undo() =0;

  // Execute redo in this frame.
  virtual void Redo() =0;

  // Execute cut in this frame.
  virtual void Cut() =0;

  // Execute copy in this frame.
  virtual void Copy() =0;

  // Execute paste in this frame.
  virtual void Paste() =0;

  // Execute delete in this frame.
  virtual void Delete() =0;

  // Execute select all in this frame.
  virtual void SelectAll() =0;

  // Save this frame's HTML source to a temporary file and open it in the
  // default text viewing application. This method can only be called from the
  // browser process.
  virtual void ViewSource() =0;

  // Retrieve this frame's HTML source as a string sent to the specified
  // visitor.
  virtual void GetSource(CefRefPtr<CefStringVisitor> visitor) =0;

  // Retrieve this frame's display text as a string sent to the specified
  // visitor.
  virtual void GetText(CefRefPtr<CefStringVisitor> visitor) =0;

  // Load the request represented by the |request| object.
  virtual void LoadRequest(CefRefPtr<CefRequest> request) =0;

  // Load the specified |url|.
  virtual void LoadURL(const CefString& url) =0;

  // Load the contents of |string_val| with the specified dummy |url|. |url|
  // should have a standard scheme (for example, http scheme) or behaviors like
  // link clicks and web security restrictions may not behave as expected.
  virtual void LoadString(const CefString& string_val,
                          const CefString& url) =0;

  // Execute a string of JavaScript code in this frame. The |script_url|
  // parameter is the URL where the script in question can be found, if any.
  // The renderer may request this URL to show the developer the source of the
  // error.  The |start_line| parameter is the base line number to use for error
  // reporting.
  virtual void ExecuteJavaScript(const CefString& code,
                                 const CefString& script_url,
                                 int start_line) =0;

  // Returns true if this is the main (top-level) frame.
  virtual bool IsMain() =0;

  // Returns true if this is the focused frame.
  virtual bool IsFocused() =0;

  // Returns the name for this frame. If the frame has an assigned name (for
  // example, set via the iframe "name" attribute) then that value will be
  // returned. Otherwise a unique name will be constructed based on the frame
  // parent hierarchy. The main (top-level) frame will always have an empty name
  // value.
  virtual CefString GetName() =0;

  // Returns the globally unique identifier for this frame.
  virtual int64 GetIdentifier() =0;

  // Returns the parent of this frame or NULL if this is the main (top-level)
  // frame.
  virtual CefRefPtr<CefFrame> GetParent() =0;

  // Returns the URL currently loaded in this frame.
  virtual CefString GetURL() =0;

  // Returns the browser that this frame belongs to.
  virtual CefRefPtr<CefBrowser> GetBrowser() =0;

  // Get the V8 context associated with the frame. This method can only be
  // called from the render process.
  virtual CefRefPtr<CefV8Context> GetV8Context() =0;
  
  // Visit the DOM document. This method can only be called from the render
  // process.
  virtual void VisitDOM(CefRefPtr<CefDOMVisitor> visitor) =0;

 


免責聲明!

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



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