Skip to content

CefPermissionHandler

Header: cef_permission_handler.h
Interfaces: CefMediaAccessCallback, CefPermissionPromptCallback, CefPermissionHandler
Category: Browser Handlers

Overview

User-implemented handler interfaces returned from CefClient and registered with CefBrowserHost.

CefMediaAccessCallback

Source File: include/cef_permission_handler.h

Process / Thread Context: Browser process / UI thread (originating OnRequestMediaAccessPermission is UI thread). USER-CALLED (source=library).

Purpose: Async continuation callback for media-access permission requests (getUserMedia).

Methods

void Continue(uint32_t allowed_permissions)

Parameters:

  • allowed_permissions: Combination of cef_media_access_permission_types_t flags. If request was for getUserMedia (DEVICE_AUDIO_CAPTURE and/or DEVICE_VIDEO_CAPTURE), this must match required_permissions passed to OnRequestMediaAccessPermission.

Return Value: None.

Usage Instruction: Allow or deny media access.

Threading Constraint: Threading constraint not specified explicitly per-method; class comment for CefPermissionHandler says UI thread.

void Cancel()

Parameters:

  • None.

Return Value: None.

Usage Instruction: Cancel the media-access request.

Threading Constraint: Threading constraint not specified explicitly per-method.

Usage Example

cpp
// After showing a custom "allow camera?" prompt:
callback->Continue(CEF_MEDIA_PERMISSION_DEVICE_VIDEO_CAPTURE);
// or:
callback->Cancel();

CefPermissionPromptCallback

Source File: include/cef_permission_handler.h

Process / Thread Context: Browser process / UI thread. USER-CALLED (source=library).

Purpose: Async continuation callback for general permission prompts (notifications, geolocation, etc.).

Methods

void Continue(cef_permission_request_result_t result)

Parameters:

  • result: CEF_PERMISSION_RESULT_ALLOW/DENY/IGNORE/etc.

Return Value: None.

Usage Instruction: Call to resolve the prompt.

Threading Constraint: Threading constraint not specified explicitly per-method; class comment says UI thread.

Usage Example

cpp
callback->Continue(CEF_PERMISSION_RESULT_ALLOW);

CefPermissionHandler

Source File: include/cef_permission_handler.h

Process / Thread Context: Browser process / UI thread. USER-IMPLEMENTED (source=client); returned from CefClient::GetPermissionHandler().

Purpose: Handle permission requests — both media-access (getUserMedia) requests and general Chrome-style permission prompts (geolocation, notifications, etc.).

Methods

bool OnRequestMediaAccessPermission(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, const CefString& requesting_origin, uint32_t requested_permissions, CefRefPtr<CefMediaAccessCallback> callback)

Parameters:

  • browser: The browser.
  • frame: The frame.
  • requesting_origin: Origin requesting permission.
  • requested_permissions: Bitmask of cef_media_access_permission_types_t.
  • callback: Call Continue(permissions) or Cancel().

Return Value: true = application handles (calls callback); false = default (Chrome: show UI; Alloy: deny).

Usage Instruction: Not called if --enable-media-stream is passed (all permissions auto-granted).

Threading Constraint: "Called when a page requests permission to access media" — UI thread per class comment.

bool OnShowPermissionPrompt(CefRefPtr<CefBrowser> browser, uint64_t prompt_id, const CefString& requesting_origin, uint32_t requested_permissions, CefRefPtr<CefPermissionPromptCallback> callback)

Parameters:

  • browser: The browser.
  • prompt_id: Unique ID for this prompt.
  • requesting_origin: Origin requesting permission.
  • requested_permissions: Bitmask of cef_permission_request_types_t.
  • callback: Call Continue(result).

Return Value: true = application handles; false = default (Chrome: show prompt UI; Alloy: CEF_PERMISSION_RESULT_IGNORE).

Usage Instruction: Show a custom permission prompt UI.

Threading Constraint: UI thread per class comment.

void OnDismissPermissionPrompt(CefRefPtr<CefBrowser> browser, uint64_t prompt_id, cef_permission_request_result_t result)

Parameters:

  • browser: The browser.
  • prompt_id: Matches the value from OnShowPermissionPrompt.
  • result: Value passed to Continue, or CEF_PERMISSION_RESULT_IGNORE if dismissed due to navigation/close.

Return Value: None.

Usage Instruction: Cleanup hook for the prompt. Not called if OnShowPermissionPrompt returned false.

Threading Constraint: UI thread per class comment.

Usage Example

cpp
class MyPermissionHandler : public CefPermissionHandler {
 public:
  bool OnRequestMediaAccessPermission(CefRefPtr<CefBrowser>, CefRefPtr<CefFrame>,
                                      const CefString& origin,
                                      uint32_t req,
                                      CefRefPtr<CefMediaAccessCallback> cb) override {
    if (origin == "https://meet.example.com")
      cb->Continue(req);
    else
      cb->Cancel();
    return true;
  }
  bool OnShowPermissionPrompt(CefRefPtr<CefBrowser>, uint64_t id,
                              const CefString& origin, uint32_t req,
                              CefRefPtr<CefPermissionPromptCallback> cb) override {
    // Show custom UI; on resolution call cb->Continue(ALLOW/DENY/IGNORE).
    return true;
  }
  void OnDismissPermissionPrompt(CefRefPtr<CefBrowser>, uint64_t,
                                  cef_permission_request_result_t) override {}
  IMPLEMENT_REFCOUNTING(MyPermissionHandler);
};

// MyClient::GetPermissionHandler() returns this.

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