UCefView
Loading...
Searching...
No Matches
UCefContext

Represents the Chromium Embedded Framework (CEF) context within Unreal Engine. This class acts as a subsystem, providing centralized access to CEF features such as resource mapping, cookie management, and cross-origin resource sharing (CORS) configuration. All browser instances created after modifying this context will inherit its settings and mappings. More...

#include <CefContext.h>

Public Member Functions

bool bIsCefInitialized () const
 Checks whether the CEF context has been successfully initialized and is ready for use.
 
void AddLocalFolderResource (const FString &InPath, const FString &InUrl, int32 InPriority=0)
 Registers a local folder as a web resource directory, mapping it to a specified URL. All browser instances created after this call will be able to access the folder's contents via the mapped URL.
 
void AddArchiveFileResource (const FString &pInPathath, const FString &InUrl, const FString &InPassword, int32 InPriority=0)
 Registers a local archive file (such as a .zip) as a web resource, mapping its contents to a specified URL. All browser instances created after this call will be able to access the archive's contents via the mapped URL.
 
bool AddCookie (const FString &InName, const FString &InValue, const FString &InDomain, const FString &InUrl)
 Adds a cookie to the CEF context, this cookie is accessible from all browsers created with this context.
 
bool DeleteAllCookies ()
 Deletes all cookies from the CEF context.
 
bool AddCrossOriginWhitelistEntry (const FString &InSourceOrigin, const FString &InTargetSchema, const FString &InTargetDomain, bool InAllowTargetSubdomains)
 Adds an entry to the cross-origin access whitelist for the CEF context, allowing specific cross-origin requests from a given source origin to a target schema and domain. This enables controlled CORS (Cross-Origin Resource Sharing) behavior for browser instances managed by this context.
 
bool RemoveCrossOriginWhitelistEntry (const FString &InSourceOrigin, const FString &InTargetSchema, const FString &InTargetDomain, bool InAllowTargetSubdomains)
 Removes a specific entry from the cross-origin access whitelist for the CEF context. This revokes previously granted cross-origin permissions for the specified source and target combination, enforcing the default CORS policy for affected requests.
 
void ClearCrossOriginWhitelistEntry ()
 Removes all entries from the cross-origin access whitelist for the CEF context. This action revokes any previously granted cross-origin permissions, restoring the default CORS policy.
 

Public Attributes

UCefSettingsSettings = GetMutableDefault<UCefSettings>()
 The settings object containing configuration parameters for the CEF context. This includes options such as cache path, user agent, and other browser-related settings.
 

Protected Member Functions

virtual void Initialize (FSubsystemCollectionBase &Collection) override
 Called when the engine subsystem is initialized. This method sets up the CEF context and prepares it for use by browser instances.
 
virtual void Deinitialize () override
 Called when the engine subsystem is deinitialized. This method releases all CEF resources and performs necessary cleanup.
 

Detailed Description

Represents the Chromium Embedded Framework (CEF) context within Unreal Engine. This class acts as a subsystem, providing centralized access to CEF features such as resource mapping, cookie management, and cross-origin resource sharing (CORS) configuration. All browser instances created after modifying this context will inherit its settings and mappings.

UCefContext should be accessed via the engine subsystem interface. It is responsible for initializing and deinitializing CEF resources, and exposes Blueprint-callable methods for common browser integration tasks.

Member Function Documentation

◆ AddArchiveFileResource()

void UCefContext::AddArchiveFileResource ( const FString & pInPathath,
const FString & InUrl,
const FString & InPassword,
int32 InPriority = 0 )

Registers a local archive file (such as a .zip) as a web resource, mapping its contents to a specified URL. All browser instances created after this call will be able to access the archive's contents via the mapped URL.

Parameters
pInPathathAbsolute or relative path to the local archive file (e.g., .zip).
InUrlThe virtual URL to which the archive will be mapped.
InPasswordPassword for the archive, if required. Pass an empty string if not needed.
InPriorityThe priority of the mapping. Higher values take precedence.

This is useful for distributing web assets in a compressed format. The archive is mounted read-only.

◆ AddCookie()

bool UCefContext::AddCookie ( const FString & InName,
const FString & InValue,
const FString & InDomain,
const FString & InUrl )

Adds a cookie to the CEF context, this cookie is accessible from all browsers created with this context.

Parameters
InNameThe cookie item name.
InValueThe cookie item value.
InDomainThe applicable domain name.
InUrlThe applicable url.
Returns
True on success; otherwise false.

◆ AddCrossOriginWhitelistEntry()

bool UCefContext::AddCrossOriginWhitelistEntry ( const FString & InSourceOrigin,
const FString & InTargetSchema,
const FString & InTargetDomain,
bool InAllowTargetSubdomains )

Adds an entry to the cross-origin access whitelist for the CEF context, allowing specific cross-origin requests from a given source origin to a target schema and domain. This enables controlled CORS (Cross-Origin Resource Sharing) behavior for browser instances managed by this context.

Parameters
InSourceOriginThe source origin (e.g., "http://myapp.local") from which cross-origin requests will be allowed.
InTargetSchemaThe target schema (e.g., "https") to which cross-origin requests are permitted.
InTargetDomainThe target domain (e.g., "example.com") that will accept cross-origin requests from the source origin.
InAllowTargetSubdomainsIf true, subdomains of the target domain are also allowed for cross-origin access.
Returns
true if the whitelist entry was successfully added; otherwise, false.

Use this method to enable communication between web content hosted in different origins, such as when embedding local or remote web applications that require access to resources across domains. This is particularly useful for scenarios involving authentication, APIs, or integration with third-party services.

Be cautious when granting cross-origin permissions, as this can have security implications. Only allow trusted origins and domains as needed by your application.

If the entry already exists, this method will not add a duplicate. The changes apply to all browser instances created after the entry is added.

For more information, see the CEF documentation: https://github.com/chromiumembedded/cef/blob/master/include/cef_origin_whitelist.h

◆ AddLocalFolderResource()

void UCefContext::AddLocalFolderResource ( const FString & InPath,
const FString & InUrl,
int32 InPriority = 0 )

Registers a local folder as a web resource directory, mapping it to a specified URL. All browser instances created after this call will be able to access the folder's contents via the mapped URL.

Parameters
InPathAbsolute or relative path to the local resource directory.
InUrlThe virtual URL to which the directory will be mapped (e.g., "http://myapp.local/").
InPriorityThe priority of the mapping. Higher values take precedence when resolving resources.

Use this method to serve static assets (HTML, JS, CSS, etc.) from the local filesystem to CEF browsers.

◆ bIsCefInitialized()

bool UCefContext::bIsCefInitialized ( ) const

Checks whether the CEF context has been successfully initialized and is ready for use.

Returns
true if the CEF context is initialized and operational; otherwise, false.

This method can be used to verify that CEF is available before attempting browser operations.

◆ ClearCrossOriginWhitelistEntry()

void UCefContext::ClearCrossOriginWhitelistEntry ( )

Removes all entries from the cross-origin access whitelist for the CEF context. This action revokes any previously granted cross-origin permissions, restoring the default CORS policy.

Use this method to reset the CORS configuration for all browser instances managed by this context. After calling this, any custom cross-origin access rules added via AddCrossOriginWhitelistEntry will be removed, and only the default CEF cross-origin policy will apply.

This is useful when you need to ensure a clean security state or when dynamically changing the set of allowed origins.

For more information, see the CEF documentation: https://github.com/chromiumembedded/cef/blob/master/include/cef_origin_whitelist.h

◆ Deinitialize()

virtual void UCefContext::Deinitialize ( )
overrideprotectedvirtual

Called when the engine subsystem is deinitialized. This method releases all CEF resources and performs necessary cleanup.

◆ DeleteAllCookies()

bool UCefContext::DeleteAllCookies ( )

Deletes all cookies from the CEF context.

Returns
True on success; otherwise false.

◆ Initialize()

virtual void UCefContext::Initialize ( FSubsystemCollectionBase & Collection)
overrideprotectedvirtual

Called when the engine subsystem is initialized. This method sets up the CEF context and prepares it for use by browser instances.

Parameters
CollectionThe subsystem collection used for initialization.

◆ RemoveCrossOriginWhitelistEntry()

bool UCefContext::RemoveCrossOriginWhitelistEntry ( const FString & InSourceOrigin,
const FString & InTargetSchema,
const FString & InTargetDomain,
bool InAllowTargetSubdomains )

Removes a specific entry from the cross-origin access whitelist for the CEF context. This revokes previously granted cross-origin permissions for the specified source and target combination, enforcing the default CORS policy for affected requests.

Parameters
InSourceOriginThe source origin (e.g., "http://myapp.local") for which the whitelist entry was added.
InTargetSchemaThe target schema (e.g., "https") that was allowed for cross-origin access.
InTargetDomainThe target domain (e.g., "example.com") that was allowed for cross-origin access.
InAllowTargetSubdomainsWhether subdomains of the target domain were included in the whitelist entry.
Returns
true if the whitelist entry was successfully removed; otherwise, false.

Use this method to dynamically revoke cross-origin permissions previously granted via AddCrossOriginWhitelistEntry. This is useful for tightening security or responding to changes in application policy at runtime.

If the specified entry does not exist, the method returns false and no changes are made.

For more information, see the CEF documentation: https://github.com/chromiumembedded/cef/blob/master/include/cef_origin_whitelist.h

Member Data Documentation

◆ Settings

UCefSettings* UCefContext::Settings = GetMutableDefault<UCefSettings>()

The settings object containing configuration parameters for the CEF context. This includes options such as cache path, user agent, and other browser-related settings.

The Settings property is initialized with the project's mutable default UCefSettings instance. Modifying these settings affects all subsequently created browser instances.