Skip to content

CefIdMappers

Header: cef_id_mappers.h
Interfaces: MacroGroup, C-API functions
Category: System Utilities

Overview

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

MacroGroup — CEF_DECLARE_PACK_RESOURCE_ID / CEF_DECLARE_PACK_STRING_ID / CEF_DECLARE_COMMAND_ID

Source File: include/cef_id_mappers.h

Process / Thread Context: Any thread (declarations expand to file-scope static const int).

Purpose: Helper macros that declare a static const int initialized at program load by calling the corresponding cef_id_for_*_name() resolver. They let client code reference resource/string/command IDs by symbolic name rather than by version-specific numeric value, producing version-safe mapping to numeric ID values that change across CEF/Chromium builds.

Notable Members

MacroExpands ToUse
CEF_DECLARE_PACK_RESOURCE_ID(name)static const int name = cef_id_for_pack_resource_name(#name)Declare an IDR resource identifier (see cef_pack_resources.h).
CEF_DECLARE_PACK_STRING_ID(name)static const int name = cef_id_for_pack_string_name(#name)Declare an IDS string identifier (see cef_pack_strings.h).
CEF_DECLARE_COMMAND_ID(name)static const int name = cef_id_for_command_id_name(#name)Declare an IDC command identifier (see cef_command_ids.h).

Usage Example

cpp
// In a translation unit, declare version-safe IDs at file scope:
CEF_DECLARE_PACK_RESOURCE_ID(IDR_CEF_LICENSE_TXT);
CEF_DECLARE_PACK_STRING_ID(IDS_TEXT_FILES);
CEF_DECLARE_COMMAND_ID(IDC_BACK);

void UseIt(CefRefPtr<CefResourceBundle> bundle) {
  // IDR_CEF_LICENSE_TXT resolves to the current build's numeric value.
  bundle->GetDataResource(IDR_CEF_LICENSE_TXT);
}

C-API functions — cef_id_for_pack_resource_name / cef_id_for_pack_string_name / cef_id_for_command_id_name

Source File: include/cef_id_mappers.h

Process / Thread Context: Any thread; exported as CEF_EXPORT (extern "C").

Purpose: Returns the numeric ID value for a named IDR / IDS / IDC symbol from the corresponding constant header, or -1 if the name is unrecognized by the current CEF/Chromium build. Provides version-safe mapping because numeric values change across CEF/Chromium versions but names generally remain stable.

Methods

int cef_id_for_pack_resource_name(const char* name)

Parameters:

  • name — null-terminated IDR symbol name (without quotes; e.g. "IDR_CEF_LICENSE_TXT").

Return Value: Numeric IDR value (matches cef_pack_resources.h), or -1 if unknown.

Usage Instruction: Use in place of #define numeric constants when you want a single binary to work across CEF versions whose IDR numbering differs.

Threading Constraint: Any thread; the lookup table is initialized at library load.

int cef_id_for_pack_string_name(const char* name)

Parameters:

  • name — IDS symbol name (e.g. "IDS_TEXT_FILES").

Return Value: Numeric IDS value, or -1 if unknown.

Usage Instruction: Pair with CefResourceBundle::GetLocalizedString(id).

Threading Constraint: Any thread.

int cef_id_for_command_id_name(const char* name)

Parameters:

  • name — IDC symbol name (e.g. "IDC_BACK").

Return Value: Numeric IDC value, or -1 if unknown.

Usage Instruction: Use to wire menu accelerators or to override context-menu command IDs in a version-portable way.

Threading Constraint: Any thread.

Usage Example

cpp
int idr = cef_id_for_pack_resource_name("IDR_CEF_LICENSE_TXT");
if (idr != -1) {
  CefRefPtr<CefResourceBundle> bundle = CefResourceBundle::GetGlobalBundle();
  CefRefPtr<CefBinaryValue> data = bundle->GetDataResource(idr);
}

int idc = cef_id_for_command_id_name("IDC_BACK");
if (idc != -1) {
  // Execute the named command via the browser's command controller.
}

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