Chromium Embedded Framework (CEF)  126.2.0+g5c56e98+chromium-126.0.6478.62
cef_v8.h File Reference
#include <vector>
#include "include/cef_base.h"
#include "include/cef_browser.h"
#include "include/cef_frame.h"
#include "include/cef_task.h"

Classes

class  CefV8Context
 Class representing a V8 context handle. More...
 
class  CefV8Handler
 Interface that should be implemented to handle V8 function calls. More...
 
class  CefV8Accessor
 Interface that should be implemented to handle V8 accessor calls. More...
 
class  CefV8Interceptor
 Interface that should be implemented to handle V8 interceptor calls. More...
 
class  CefV8Exception
 Class representing a V8 exception. More...
 
class  CefV8ArrayBufferReleaseCallback
 Callback interface that is passed to CefV8Value::CreateArrayBuffer. More...
 
class  CefV8Value
 Class representing a V8 value handle. More...
 
class  CefV8StackTrace
 Class representing a V8 stack trace handle. More...
 
class  CefV8StackFrame
 Class representing a V8 stack frame handle. More...
 

Typedefs

typedef std::vector< CefRefPtr< CefV8Value > > CefV8ValueList
 

Functions

bool CefRegisterExtension (const CefString &extension_name, const CefString &javascript_code, CefRefPtr< CefV8Handler > handler)
 Register a new V8 extension with the specified JavaScript extension code and handler. More...
 

Typedef Documentation

◆ CefV8ValueList

typedef std::vector<CefRefPtr<CefV8Value> > CefV8ValueList

Function Documentation

◆ CefRegisterExtension()

bool CefRegisterExtension ( const CefString extension_name,
const CefString javascript_code,
CefRefPtr< CefV8Handler handler 
)

Register a new V8 extension with the specified JavaScript extension code and handler.

Functions implemented by the handler are prototyped using the keyword 'native'. The calling of a native function is restricted to the scope in which the prototype of the native function is defined. This function may only be called on the render process main thread.

Example JavaScript extension code:

  // create the 'example' global object if it doesn't already exist.
  if (!example)
    example = {};
  // create the 'example.test' global object if it doesn't already exist.
  if (!example.test)
    example.test = {};
  (function() {
    // Define the function 'example.test.myfunction'.
    example.test.myfunction = function() {
      // Call CefV8Handler::Execute() with the function name 'MyFunction'
      // and no arguments.
      native function MyFunction();
      return MyFunction();
    };
    // Define the getter function for parameter 'example.test.myparam'.
    example.test.__defineGetter__('myparam', function() {
      // Call CefV8Handler::Execute() with the function name 'GetMyParam'
      // and no arguments.
      native function GetMyParam();
      return GetMyParam();
    });
    // Define the setter function for parameter 'example.test.myparam'.
    example.test.__defineSetter__('myparam', function(b) {
      // Call CefV8Handler::Execute() with the function name 'SetMyParam'
      // and a single argument.
      native function SetMyParam();
      if(b) SetMyParam(b);
    });

    // Extension definitions can also contain normal JavaScript variables
    // and functions.
    var myint = 0;
    example.test.increment = function() {
      myint += 1;
      return myint;
    };
  })();

Example usage in the page:

  // Call the function.
  example.test.myfunction();
  // Set the parameter.
  example.test.myparam = value;
  // Get the parameter.
  value = example.test.myparam;
  // Call another function.
  example.test.increment();