Skip to content

CefStringVisitor

Header: cef_string_visitor.h
Category: System Utilities

Overview

Tasks, threads, parsers, streams, cookies, URL requests, scheme registration, and constant tables.

CefStringVisitor

Source File: include/cef_string_visitor.h

Process / Thread Context: Not specified in header (commonly used with CefBrowser::GetSource / CefBrowserHost::GetNavigationEntries etc., where the Visit() call is dispatched on the UI thread of the appropriate process).

Purpose: Implement this interface to receive string values asynchronously. CEF invokes Visit() once when the requested string data (e.g. the page source, a frame's HTML) is available.

Methods

void Visit(const CefString& string)

Parameters:

  • string: The string value being delivered. The translator tag marks this optional_param=string, indicating the value may be empty when the operation produces no string or fails.

Return Value: Returns void.

Usage Instruction: Implement to receive the asynchronously-produced string. Do not retain references to internal state of the string past the call; copy it if you need it later. Use with APIs like CefBrowser::GetSource(CefRefPtr<CefStringVisitor> visitor).

Threading Constraint: Not specified in header (the API that accepts the visitor documents the thread).

Usage Example

cpp
class SourceVisitor : public CefStringVisitor {
 public:
  explicit SourceVisitor(std::function<void(std::string)> on_done)
      : on_done_(std::move(on_done)) {}
  void Visit(const CefString& source) override {
    on_done_(source.ToString());
  }
 private:
  std::function<void(std::string)> on_done_;
  IMPLEMENT_REFCOUNTING(SourceVisitor);
};

// CefRefPtr<CefBrowser> browser = ...
// browser->GetSource(new SourceVisitor([](const std::string& html) {
//   LOG(INFO) << "page HTML length: " << html.size();
// }));

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