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;

第一期使用命令介绍: : (CefApp): 与进程,命令行参数,代理,资源管理相关的回调 (CefBrowserProcessHandler): 用于接收进程相关的回调通知。 (CefClient): 回调管理,主要是用于向浏览器反回我们需要接管哪些功能的。 (CefLifeSpanHandler):浏览器的运行管理,包含当浏览器创建完成之后,浏览器被关闭等通知 (CefMainArgs): 数据,用于设置当前应用实例句柄的。 (CefSettings): 数据,用于设置一些浏览器整体的基本信息 (CefWindowInfo): 数据,用于设置一些浏览器的窗口信息 (CefBrowserSettings): 数据,用于设置一些浏览器的基本信息 用到的命令: 返回值 (CefBrowserProcessHandler) = (CefApp).GetBrowserProcessHandler()  '获取一个用于管理浏览器进程的 返回值 空= (CefBrowserProcessHandler).OnContextInitialized()  '回调通知函数,告诉我们浏览器已经准备就绪了。 返回值 (CefLifeSpanHandler) = (CefClient).GetLifeSpanHandler()  '向浏览器返回我们用于接管浏览器进程的 返回值 空 = (CefLifeSpanHandler).OnAfterCreated()  '回调通知函数,用于告诉我们,当前有一个新的浏览器创建好了 返回值 空 = (CefLifeSpanHandler).DoClose()  '回调通知函数,貌似是表示所有浏览器都关闭之后,Cef上有一大段注释,但是TM始终看不明白... 返回值 空 = (CefLifeSpanHandler).OnBeforeClose()  '回调通知函数,用于告诉我们,当前有一个浏览器被关闭了 返回值 空 = CefMainArgs.Load()  '数据函数,用于设置当前当前应用的实例句柄 返回值 空 = CefSettings.SetAsSingleProcess()  '数据函数,是否使用单进程运行浏览器, 1.单进程运行 0.多进程运行。默认是以多进程运行的。 返回值 空 = CefSettings.SetAsNoSandbox()  '数据函数,是否关闭沙盘功能 返回值 空 = CefSettings.SetAsRemoteDebuggingPort()  '数据函数,设置远程调试端口 返回值 空 = CefWindowInfo.SetAsChild()  '数据函数,设置浏览器窗口为子窗口 通用命令: (All).AddRef()  '给这个函数所属的增加一次引用计数 (All).Release()  '给这个函数所属的释放一次引用计数 (All).HasOneRef()  '判断当前这个是不是第一次被引用 (All).Wrap()  '实际上《Hello WebKit》框架的都是以一种接近于C++的存在,为了能给浏览器使用,我们必须要将这个转换为近似于C的。这个函数就有这样的作用 (All).Unwrap()  '从C中取回我们的C++ (All).ToCpp__() '导入或取出由浏览器提供的指针或者数据指针 通用命令: CefBrowserHostCreateBrowserSync()  '创建一个新的浏览器,成功返回浏览器CefBrowser. CefExecuteProcess()  '初始化浏览器进程 CefInitialize()  '全初始化,该函数执行完成之后,(CefBrowserProcessHandler).OnContextInitialized() 将收到通知 CefRunMessageLoop()  '浏览器进程消息循环 CefShutdown()  '浏览器进程结束 CefQuitMessageLoop()  '向所有(多进程下)浏览器进程发送结束通知 REQUIRE_UI_THREAD()  '调试函数,用于检查执行到该函数位置的线程/进程是否为UI线程/进程,如果不是将被中断下来 CEF_BROWSER_RELEASE()  '释放一次浏览器的引用计数 第二期使用命令介绍: (CefDisplayHandler): 与浏览器状态显示相关的 (CefBrowser): 浏览器,用于控制或者取得浏览器的相关信息,最常用 (CefBrowserHost): 浏览器窗口,用于控制或者取得浏览器窗口的相关信息,最常用 (CefFrame): 浏览器框架,用于控制或者取得浏览器框架的相关信息,最
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值