Skip to content

CefDialogHandler

Header: cef_dialog_handler.h
Interfaces: CefFileDialogCallback, CefDialogHandler
Category: Browser Handlers

Overview

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

CefFileDialogCallback

Source File: include/cef_dialog_handler.h

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

Purpose: Async continuation callback for file-dialog requests.

Methods

void Continue(const std::vector<CefString>& file_paths)

Parameters:

  • file_paths: Single value or list depending on dialog mode. Empty list = treated as Cancel().

Return Value: None.

Usage Instruction: Call to complete the dialog with the user's selection.

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

void Cancel()

Parameters:

  • None.

Return Value: None.

Usage Instruction: Cancel the file selection.

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

Usage Example

cpp
// Inside OnFileDialog after the user picks files:
std::vector<CefString> paths{"/path/to/file.txt"};
callback->Continue(paths);
// or:
callback->Cancel();

CefDialogHandler

Source File: include/cef_dialog_handler.h

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

Purpose: Handle file-chooser dialogs (HTML <input type=file> and downloads-of-specific-types triggered dialogs).

Methods

bool OnFileDialog(CefRefPtr<CefBrowser> browser, FileDialogMode mode, const CefString& title, const CefString& default_file_path, const std::vector<CefString>& accept_filters, const std::vector<CefString>& accept_extensions, const std::vector<CefString>& accept_descriptions, CefRefPtr<CefFileDialogCallback> callback)

Parameters:

  • browser: The browser.
  • mode: cef_file_dialog_mode_t (Open, OpenMultiple, Save, etc.).
  • title: Dialog title; empty → default ("Open"/"Save").
  • default_file_path: Initial path/dir/file.
  • accept_filters: MIME types ("image/*") or extensions (".png"); same size as the other two vectors.
  • accept_extensions: Semicolon-delimited expansion of MIME types to extensions (or empty).
  • accept_descriptions: Human-readable descriptions (or empty).
  • callback: Continue with the chosen paths or Cancel.

Return Value: true = application displays a custom dialog and will execute callback; false = show default dialog (may be called again later, both before and after MIME-type expansion).

Usage Instruction: Implement to show a native or custom file picker for HTML file inputs.

Threading Constraint: "Methods of this class will be called on the browser process UI thread."

Usage Example

cpp
class MyDialogHandler : public CefDialogHandler {
 public:
  bool OnFileDialog(CefRefPtr<CefBrowser> browser,
                    FileDialogMode mode, const CefString& title,
                    const CefString& default_file_path,
                    const std::vector<CefString>& accept_filters,
                    const std::vector<CefString>& accept_extensions,
                    const std::vector<CefString>& accept_descriptions,
                    CefRefPtr<CefFileDialogCallback> callback) override {
    // Show a custom wxWidgets/Qt dialog; on completion:
    // std::vector<CefString> picked = MyPicker::Run(...);
    // callback->Continue(picked);
    // return true;
    return false;  // default dialog
  }
  IMPLEMENT_REFCOUNTING(MyDialogHandler);
};

class MyClient : public CefClient {
  CefRefPtr<CefDialogHandler> GetDialogHandler() override { return new MyDialogHandler(); }
};

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