Skip to content

CefBrowserViewDelegate

Header: cef_browser_view_delegate.h
Category: Views Framework

Overview

Browser-process UI toolkit: windows, panels, layouts, buttons, textfields, and their delegates.

CefBrowserViewDelegate

Source File: include/views/cef_browser_view_delegate.h

Process / Thread Context: Browser Process / UI Thread.

Purpose: Client-implemented delegate for BrowserView events: browser

Methods

virtual void OnBrowserCreated(CefRefPtr<CefBrowserView> browser_view, CefRefPtr<CefBrowser> browser)

Parameters:

  • browser_view: The BrowserView that owns the browser.
  • browser: The newly created CefBrowser.

Return Value: void. Called after

Usage Instruction: Initialize anything that requires the underlying

Threading Constraint: Browser process UI thread.

virtual void OnBrowserDestroyed(CefRefPtr<CefBrowserView> browser_view, CefRefPtr<CefBrowser> browser)

Parameters:

  • browser_view: The BrowserView.
  • browser: The browser being destroyed.

Return Value: void. Release all references to browser. Called before

Usage Instruction: Tear down state.

Threading Constraint: Browser process UI thread.

virtual CefRefPtr<CefBrowserViewDelegate> GetDelegateForPopupBrowserView(CefRefPtr<CefBrowserView> browser_view, const CefBrowserSettings& settings, CefRefPtr<CefClient> client, bool is_devtools)

Parameters:

  • browser_view: The originating BrowserView.
  • settings: Settings returned from CefLifeSpanHandler::OnBeforePopup().
  • client: The client returned from OnBeforePopup().
  • is_devtools: True if the popup is a DevTools browser.

Return Value: The delegate for the new popup BrowserView. Default

Usage Instruction: Provide a distinct delegate for popup windows

Threading Constraint: Browser process UI thread.

virtual bool OnPopupBrowserViewCreated(CefRefPtr<CefBrowserView> browser_view, CefRefPtr<CefBrowserView> popup_browser_view, bool is_devtools)

Parameters:

  • browser_view: The originating BrowserView.
  • popup_browser_view: The newly created popup BrowserView.
  • is_devtools: True if this is a DevTools popup.

Return Value: True if you added the popup to the views hierarchy

Usage Instruction: Customize popup placement (e.g., add the popup to

Threading Constraint: Browser process UI thread.

virtual ChromeToolbarType GetChromeToolbarType(CefRefPtr<CefBrowserView> browser_view)

Parameters:

  • browser_view: The BrowserView.

Return Value: A cef_chrome_toolbar_type_t value. Default

Usage Instruction: Enable the Chrome toolbar (back/forward/reload,

Threading Constraint: Browser process UI thread.

virtual bool UseFramelessWindowForPictureInPicture(CefRefPtr<CefBrowserView> browser_view)

Parameters:

  • browser_view: The BrowserView.

Return Value: True to allow opening Document PiP without user

Usage Instruction: Relax user-activation requirement for PiP.

Threading Constraint: Browser process UI thread.

virtual bool OnGestureCommand(CefRefPtr<CefBrowserView> browser_view, cef_gesture_command_t gesture_command)

Parameters:

  • browser_view: The BrowserView.
  • gesture_command: The gesture command (e.g., back/forward swipe).

Return Value: True to handle (or disable) the command; false to

Usage Instruction: Custom gesture handling.

Threading Constraint: Browser process UI thread.

virtual cef_runtime_style_t GetBrowserRuntimeStyle()

Parameters:

  • none.

Return Value: The runtime style for this BrowserView. Default

Usage Instruction: Override to choose Alloy or Chrome style

Threading Constraint: Browser process UI thread.

Usage Example

cpp
class MyBVDelegate : public CefBrowserViewDelegate {
 public:
  ChromeToolbarType GetChromeToolbarType(CefRefPtr<CefBrowserView>) override {
    return CEF_CTT_NORMAL;  // Chrome-style toolbar
  }

  void OnBrowserCreated(CefRefPtr<CefBrowserView> bv,
                        CefRefPtr<CefBrowser> b) override {
    LOG(INFO) << "Browser created: " << b->GetMainFrame()->GetURL();
  }

  bool OnGestureCommand(CefRefPtr<CefBrowserView> bv,
                        cef_gesture_command_t cmd) override {
    if (cmd == CEF_GESTURE_COMMAND_BACK) {
      bv->GetBrowser()->GoBack();
      return true;
    }
    return false;
  }
};

Derived from the CEF C++ headers — © Marshall A. Greenblatt, Google Inc. & contributors (BSD-style license). Not an official CEF project.