Enable V8 sandbox by default (fixes #3332)

When the V8 sandbox is enabled, ArrayBuffer backing stores must be
allocated inside the sandbox address space. This change introduces a new
CefV8Value::CreateArrayBufferWithCopy method that copies the memory
contents into the sandbox address space.

Enabling the V8 sandbox can have a performance impact, especially when
passing large ArrayBuffers from C++ code to the JS side. We have therefore
retained the old CefV8Value::CreateArrayBuffer method that references
external memory. However, this method can only be used if the V8 sandbox is
disabled at CEF/Chromium build time.

To disable the V8 sandbox add `v8_enable_sandbox=false` to
`GN_DEFINES` when building CEF/Chromium.
This commit is contained in:
Nik Pavlov
2024-08-05 16:00:58 +00:00
committed by Marshall Greenblatt
parent 08ae3a44a6
commit 295ea1f715
15 changed files with 264 additions and 72 deletions

View File

@@ -520,12 +520,26 @@ class CefV8Value : public virtual CefBaseRefCounted {
/// or CefV8Accessor callback, or in combination with calling Enter() and
/// Exit() on a stored CefV8Context reference.
///
/// NOTE: Always returns nullptr when V8 sandbox is enabled.
///
/*--cef(optional_param=buffer)--*/
static CefRefPtr<CefV8Value> CreateArrayBuffer(
void* buffer,
size_t length,
CefRefPtr<CefV8ArrayBufferReleaseCallback> release_callback);
///
/// Create a new CefV8Value object of type ArrayBuffer which copies the
/// provided |buffer| of size |length| bytes.
/// This method should only be called from within the scope of a
/// CefRenderProcessHandler, CefV8Handler or CefV8Accessor callback, or in
/// combination with calling Enter() and Exit() on a stored CefV8Context
/// reference.
///
/*--cef(optional_param=buffer)--*/
static CefRefPtr<CefV8Value> CreateArrayBufferWithCopy(void* buffer,
size_t length);
///
/// Create a new CefV8Value object of type function. This method should only
/// be called from within the scope of a CefRenderProcessHandler, CefV8Handler