Compare commits

...

7 Commits

Author SHA1 Message Date
Marshall Greenblatt 203875394f cefclient: Fix invalid cast to ClientHandlerStd (see #3499) 2024-08-05 18:44:34 -04:00
Marshall Greenblatt 0da33499ce bazel: Support <angled> includes of CEF headers (see #3757)
Fixes "file not found with <angled> include" errors.
2024-08-05 17:28:51 -04:00
Marshall Greenblatt e1d1f5e3e4 Update patch file 2024-08-05 14:35:44 -04:00
JC Yang e6d7700746 Fix dangling ptr in ReadResponseCallbackWrapper (fixes #3760) 2024-08-05 14:28:56 -04:00
Loic Frasse-Mathon 686a5cab52 posix: Added option to disable signal handlers
See https://github.com/chromiumembedded/java-cef/issues/477
2024-08-05 14:28:48 -04:00
Pedro de Carvalho Gomes fe6e44886b linux: Add CefWindowDelegate::GetLinuxWindowProperties (fixes #3383) 2024-08-05 14:28:41 -04:00
Nik Pavlov c739fc029f 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.
2024-08-05 14:28:35 -04:00
43 changed files with 612 additions and 97 deletions

View File

@ -245,6 +245,7 @@
'tests/cefclient/browser/client_prefs.cc',
'tests/cefclient/browser/client_prefs.h',
'tests/cefclient/browser/client_types.h',
'tests/cefclient/browser/default_client_handler.cc',
'tests/cefclient/browser/default_client_handler.h',
'tests/cefclient/browser/dialog_test.cc',
'tests/cefclient/browser/dialog_test.h',

View File

@ -33,7 +33,7 @@
// by hand. See the translator.README.txt file in the tools directory for
// more information.
//
// $hash=5dd4948a92af2ad69e2171f2dffb8f2c23e5c147$
// $hash=0b56c483bee6489e591c54c9dbb0940cd3098eaa$
//
#ifndef CEF_INCLUDE_CAPI_CEF_V8_CAPI_H_
@ -832,11 +832,24 @@ CEF_EXPORT cef_v8value_t* cef_v8value_create_array(int length);
/// cef_v8handler_t or cef_v8accessor_t callback, or in combination with calling
/// enter() and exit() on a stored cef_v8context_t reference.
///
/// NOTE: Always returns nullptr when V8 sandbox is enabled.
///
CEF_EXPORT cef_v8value_t* cef_v8value_create_array_buffer(
void* buffer,
size_t length,
cef_v8array_buffer_release_callback_t* release_callback);
///
/// Create a new cef_v8value_t object of type ArrayBuffer which copies the
/// provided |buffer| of size |length| bytes. This function should only be
/// called from within the scope of a cef_render_process_handler_t,
/// cef_v8handler_t or cef_v8accessor_t callback, or in combination with calling
/// enter() and exit() on a stored cef_v8context_t reference.
///
CEF_EXPORT cef_v8value_t* cef_v8value_create_array_buffer_with_copy(
void* buffer,
size_t length);
///
/// Create a new cef_v8value_t object of type function. This function should
/// only be called from within the scope of a cef_render_process_handler_t,

View File

@ -33,7 +33,7 @@
// by hand. See the translator.README.txt file in the tools directory for
// more information.
//
// $hash=a2e5caf4dc0ed5b43a6075678e3b7b7ae83834ae$
// $hash=bafa7ddf3dfbc3fa82b1fb8a064b51f0791b29b6$
//
#ifndef CEF_INCLUDE_CAPI_VIEWS_CEF_WINDOW_DELEGATE_CAPI_H_
@ -280,6 +280,15 @@ typedef struct _cef_window_delegate_t {
///
cef_runtime_style_t(CEF_CALLBACK* get_window_runtime_style)(
struct _cef_window_delegate_t* self);
///
/// Return Linux-specific window properties for correctly handling by window
/// managers
///
int(CEF_CALLBACK* get_linux_window_properties)(
struct _cef_window_delegate_t* self,
struct _cef_window_t* window,
struct _cef_linux_window_properties_t* properties);
} cef_window_delegate_t;
#ifdef __cplusplus

View File

@ -42,13 +42,13 @@
// way that may cause binary incompatibility with other builds. The universal
// hash value will change if any platform is affected whereas the platform hash
// values will change only if that particular platform is affected.
#define CEF_API_HASH_UNIVERSAL "316cc23ff49e0d0962090cbfb0a0279ce3dc3c50"
#define CEF_API_HASH_UNIVERSAL "bb414cc95e84099084c9476c468846e483ef7a0f"
#if defined(OS_WIN)
#define CEF_API_HASH_PLATFORM "66c126d91698670af3835a707a84ce4dbb4a16fa"
#define CEF_API_HASH_PLATFORM "1a921f6a2c91bc5369afce001c37645ef726e804"
#elif defined(OS_MAC)
#define CEF_API_HASH_PLATFORM "c1d8d20920c3a3e13a6a6efef51b2b775f69d2c7"
#define CEF_API_HASH_PLATFORM "8c96e8a60224dc40ec40067b6a515af79dd47f8f"
#elif defined(OS_LINUX)
#define CEF_API_HASH_PLATFORM "7ccfa4c608c16a4f8bedc97a2bdf50729784c5ee"
#define CEF_API_HASH_PLATFORM "693e114620a780000fbb7334537145caed271c66"
#endif
#ifdef __cplusplus

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

View File

@ -486,6 +486,13 @@ typedef struct _cef_settings_t {
/// Windows.
///
int chrome_app_icon_id;
#if defined(OS_POSIX) && !defined(OS_ANDROID)
///
/// Specify whether signal handlers must be disabled on POSIX systems.
///
bool disable_signal_handlers;
#endif
} cef_settings_t;
///
@ -1847,6 +1854,34 @@ typedef struct _cef_screen_info_t {
cef_rect_t available_rect;
} cef_screen_info_t;
///
/// Linux window properties, such as X11's WM_CLASS or Wayland's app_id.
/// Those are passed to CefWindowDelegate, so the client can set them
/// for the CefWindow's top-level. Thus, allowing window managers to correctly
/// display the application's information (e.g., icons).
///
typedef struct _cef_linux_window_properties_t {
///
/// Main window's Wayland's app_id
///
cef_string_t wayland_app_id;
///
/// Main window's WM_CLASS_CLASS in X11
///
cef_string_t wm_class_class;
///
/// Main window's WM_CLASS_NAME in X11
///
cef_string_t wm_class_name;
///
/// Main window's WM_WINDOW_ROLE in X11
///
cef_string_t wm_role_name;
} cef_linux_window_properties_t;
///
/// Supported menu IDs. Non-English translations can be provided for the
/// IDS_MENU_* strings in CefResourceBundleHandler::GetLocalizedString().

View File

@ -432,6 +432,10 @@ struct CefSettingsTraits {
cef_string_set(src->chrome_policy_id.str, src->chrome_policy_id.length,
&target->chrome_policy_id, copy);
target->chrome_app_icon_id = src->chrome_app_icon_id;
#if defined(OS_POSIX) && !defined(OS_ANDROID)
target->disable_signal_handlers = src->disable_signal_handlers;
#endif
}
};
@ -783,4 +787,36 @@ struct CefTaskInfoTraits {
///
using CefTaskInfo = CefStructBase<CefTaskInfoTraits>;
struct CefLinuxWindowPropertiesTraits {
using struct_type = cef_linux_window_properties_t;
static inline void init(struct_type* s) {}
static inline void clear(struct_type* s) {
cef_string_clear(&s->wayland_app_id);
cef_string_clear(&s->wm_class_class);
cef_string_clear(&s->wm_class_name);
cef_string_clear(&s->wm_role_name);
}
static inline void set(const struct_type* src,
struct_type* target,
bool copy) {
cef_string_set(src->wayland_app_id.str, src->wayland_app_id.length,
&target->wayland_app_id, copy);
cef_string_set(src->wm_class_class.str, src->wm_class_class.length,
&target->wm_class_class, copy);
cef_string_set(src->wm_class_name.str, src->wm_class_name.length,
&target->wm_class_name, copy);
cef_string_set(src->wm_role_name.str, src->wm_role_name.length,
&target->wm_role_name, copy);
}
};
///
/// Class representing the Linux-specific window properties required
/// for the window managers to correct group and display the window.
///
using CefLinuxWindowProperties = CefStructBase<CefLinuxWindowPropertiesTraits>;
#endif // CEF_INCLUDE_INTERNAL_CEF_TYPES_WRAPPERS_H_

View File

@ -278,6 +278,16 @@ class CefWindowDelegate : public CefPanelDelegate {
virtual cef_runtime_style_t GetWindowRuntimeStyle() {
return CEF_RUNTIME_STYLE_DEFAULT;
}
///
/// Return Linux-specific window properties for correctly handling by window
/// managers
///
/*--cef()--*/
virtual bool GetLinuxWindowProperties(CefRefPtr<CefWindow> window,
CefLinuxWindowProperties& properties) {
return false;
}
};
#endif // CEF_INCLUDE_VIEWS_CEF_WINDOW_DELEGATE_H_

View File

@ -101,7 +101,13 @@ bool CefMainRunner::Initialize(CefSettings* settings,
application_ = application;
exit_code_ =
ContentMainInitialize(args, windows_sandbox_info, &settings->no_sandbox);
ContentMainInitialize(args, windows_sandbox_info, &settings->no_sandbox,
#if BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_ANDROID)
settings->disable_signal_handlers
#else
false
#endif
);
if (exit_code_ >= 0) {
LOG(ERROR) << "ContentMainInitialize failed with exit code " << exit_code_;
return false;
@ -253,7 +259,8 @@ int CefMainRunner::RunAsHelperProcess(const CefMainArgs& args,
int CefMainRunner::ContentMainInitialize(const CefMainArgs& args,
void* windows_sandbox_info,
int* no_sandbox) {
int* no_sandbox,
bool disable_signal_handlers) {
BeforeMainInitialize(args);
main_delegate_ =
@ -278,6 +285,10 @@ int CefMainRunner::ContentMainInitialize(const CefMainArgs& args,
main_params.argv = const_cast<const char**>(args.argv);
#endif
#if BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_ANDROID)
main_params.disable_signal_handlers = disable_signal_handlers;
#endif
return content::ContentMainInitialize(std::move(main_params),
main_runner_.get());
}

View File

@ -62,7 +62,9 @@ class CefMainRunner final {
// Called from Initialize().
int ContentMainInitialize(const CefMainArgs& args,
void* windows_sandbox_info,
int* no_sandbox);
int* no_sandbox,
bool disable_signal_handlers);
int ContentMainRun(bool* initialized, base::OnceClosure context_initialized);
static void BeforeMainInitialize(const CefMainArgs& args);

View File

@ -213,7 +213,8 @@ class InputStreamReader : public base::RefCountedThreadSafe<InputStreamReader> {
InputStream::SkipCallback skip_callback);
static void RunReadCallbackOnJobThread(
int bytes_read,
InputStream::ReadCallback read_callback);
InputStream::ReadCallback read_callback,
scoped_refptr<net::IOBuffer> buffer);
std::unique_ptr<InputStream> stream_;
@ -442,8 +443,9 @@ void InputStreamReader::RunReadCallback(int bytes_read) {
DCHECK(!pending_read_callback_.is_null());
job_thread_task_runner_->PostTask(
FROM_HERE, base::BindOnce(InputStreamReader::RunReadCallbackOnJobThread,
bytes_read, std::move(pending_read_callback_)));
FROM_HERE,
base::BindOnce(InputStreamReader::RunReadCallbackOnJobThread, bytes_read,
std::move(pending_read_callback_), buffer_));
// Reset callback state.
pending_callback_id_ = -1;
@ -460,7 +462,8 @@ void InputStreamReader::RunSkipCallbackOnJobThread(
// static
void InputStreamReader::RunReadCallbackOnJobThread(
int bytes_read,
InputStream::ReadCallback read_callback) {
InputStream::ReadCallback read_callback,
scoped_refptr<net::IOBuffer> buffer) {
std::move(read_callback).Run(bytes_read);
}

View File

@ -429,6 +429,16 @@ void CefWindowView::CreateWidget(gfx::AcceleratedWidget parent_widget) {
auto bounds = cef_delegate()->GetInitialBounds(cef_window);
params.bounds = gfx::Rect(bounds.x, bounds.y, bounds.width, bounds.height);
#if BUILDFLAG(IS_LINUX)
CefLinuxWindowProperties linux_props;
if (cef_delegate()->GetLinuxWindowProperties(cef_window, linux_props)) {
params.wayland_app_id = CefString(&linux_props.wayland_app_id);
params.wm_class_class = CefString(&linux_props.wm_class_class);
params.wm_class_name = CefString(&linux_props.wm_class_name);
params.wm_role_name = CefString(&linux_props.wm_role_name);
}
#endif
if (has_native_parent) {
DCHECK(!params.bounds.IsEmpty());
} else {

View File

@ -1412,6 +1412,7 @@ CefRefPtr<CefV8Value> CefV8Value::CreateArrayBuffer(
void* buffer,
size_t length,
CefRefPtr<CefV8ArrayBufferReleaseCallback> release_callback) {
#ifndef V8_ENABLE_SANDBOX
CEF_V8_REQUIRE_ISOLATE_RETURN(nullptr);
v8::Isolate* isolate = CefV8IsolateManager::Get()->isolate();
@ -1451,6 +1452,46 @@ CefRefPtr<CefV8Value> CefV8Value::CreateArrayBuffer(
CefRefPtr<CefV8ValueImpl> impl = new CefV8ValueImpl(isolate);
impl->InitObject(ab, tracker);
return impl.get();
#else
LOG(ERROR)
<< "CefV8Value::CreateArrayBuffer is not supported with the V8 "
"sandbox enabled, use CefV8Value::CreateArrayBufferWithCopy instead";
return nullptr;
#endif // V8_ENABLE_SANDBOX
}
// static
CefRefPtr<CefV8Value> CefV8Value::CreateArrayBufferWithCopy(void* buffer,
size_t length) {
CEF_V8_REQUIRE_ISOLATE_RETURN(nullptr);
v8::Isolate* isolate = CefV8IsolateManager::Get()->isolate();
v8::HandleScope handle_scope(isolate);
v8::Local<v8::Context> context = isolate->GetCurrentContext();
if (context.IsEmpty()) {
DCHECK(false) << "not currently in a V8 context";
return nullptr;
}
// Create a tracker object that will cause the user data reference to be
// released when the V8 object is destroyed.
V8TrackObject* tracker = new V8TrackObject(isolate);
v8::Local<v8::ArrayBuffer> ab = v8::ArrayBuffer::New(
isolate, length, v8::BackingStoreInitializationMode::kUninitialized);
if (length > 0) {
DCHECK(ab->Data());
DCHECK(buffer);
memcpy(ab->Data(), buffer, length);
}
// Attach the tracker object.
tracker->AttachTo(context, ab);
CefRefPtr<CefV8ValueImpl> impl = new CefV8ValueImpl(isolate);
impl->InitObject(ab, tracker);
return impl;
}
// static

View File

@ -9,7 +9,7 @@
// implementations. See the translator.README.txt file in the tools directory
// for more information.
//
// $hash=c59808566c2a9f2d204b6724bb5a905aeb0e7620$
// $hash=befb2f29af8a0e8eabf745fad126ebad5a741c74$
//
#include "libcef_dll/cpptoc/v8value_cpptoc.h"
@ -155,6 +155,21 @@ CEF_EXPORT cef_v8value_t* cef_v8value_create_array_buffer(
return CefV8ValueCppToC::Wrap(_retval);
}
CEF_EXPORT cef_v8value_t* cef_v8value_create_array_buffer_with_copy(
void* buffer,
size_t length) {
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
// Unverified params: buffer
// Execute
CefRefPtr<CefV8Value> _retval =
CefV8Value::CreateArrayBufferWithCopy(buffer, length);
// Return type: refptr_same
return CefV8ValueCppToC::Wrap(_retval);
}
CEF_EXPORT cef_v8value_t* cef_v8value_create_function(
const cef_string_t* name,
cef_v8handler_t* handler) {

View File

@ -9,14 +9,14 @@
// implementations. See the translator.README.txt file in the tools directory
// for more information.
//
// $hash=bcb4d6aea88f1445def6014708b69087f1a6dc74$
// $hash=2fca5c473412bd7acef54f5057dc55488271aaf9$
//
#include "libcef_dll/cpptoc/views/window_delegate_cpptoc.h"
#include "libcef_dll/ctocpp/views/view_ctocpp.h"
#include "libcef_dll/ctocpp/views/window_ctocpp.h"
#include "libcef_dll/shutdown_checker.h"
#include "libcef_dll/template_util.h"
namespace {
@ -600,6 +600,52 @@ window_delegate_get_window_runtime_style(struct _cef_window_delegate_t* self) {
return _retval;
}
int CEF_CALLBACK window_delegate_get_linux_window_properties(
struct _cef_window_delegate_t* self,
cef_window_t* window,
struct _cef_linux_window_properties_t* properties) {
shutdown_checker::AssertNotShutdown();
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
DCHECK(self);
if (!self) {
return 0;
}
// Verify param: window; type: refptr_diff
DCHECK(window);
if (!window) {
return 0;
}
// Verify param: properties; type: struct_byref
DCHECK(properties);
if (!properties) {
return 0;
}
if (!template_util::has_valid_size(properties)) {
DCHECK(false) << "invalid properties->[base.]size";
return 0;
}
// Translate param: properties; type: struct_byref
CefLinuxWindowProperties propertiesObj;
if (properties) {
propertiesObj.AttachTo(*properties);
}
// Execute
bool _retval = CefWindowDelegateCppToC::Get(self)->GetLinuxWindowProperties(
CefWindowCToCpp::Wrap(window), propertiesObj);
// Restore param: properties; type: struct_byref
if (properties) {
propertiesObj.DetachTo(*properties);
}
// Return type: bool
return _retval;
}
cef_size_t CEF_CALLBACK
window_delegate_get_preferred_size(struct _cef_view_delegate_t* self,
cef_view_t* view) {
@ -916,6 +962,8 @@ CefWindowDelegateCppToC::CefWindowDelegateCppToC() {
window_delegate_on_theme_colors_changed;
GetStruct()->get_window_runtime_style =
window_delegate_get_window_runtime_style;
GetStruct()->get_linux_window_properties =
window_delegate_get_linux_window_properties;
GetStruct()->base.base.get_preferred_size =
window_delegate_get_preferred_size;
GetStruct()->base.base.get_minimum_size = window_delegate_get_minimum_size;

View File

@ -9,7 +9,7 @@
// implementations. See the translator.README.txt file in the tools directory
// for more information.
//
// $hash=856fc6c190d0e3376824564155618e468764e841$
// $hash=df9571f843ed0e55e581dc6282079803e3641d2c$
//
#include "libcef_dll/ctocpp/v8value_ctocpp.h"
@ -164,6 +164,21 @@ CefRefPtr<CefV8Value> CefV8Value::CreateArrayBuffer(
return CefV8ValueCToCpp::Wrap(_retval);
}
NO_SANITIZE("cfi-icall")
CefRefPtr<CefV8Value> CefV8Value::CreateArrayBufferWithCopy(void* buffer,
size_t length) {
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
// Unverified params: buffer
// Execute
cef_v8value_t* _retval =
cef_v8value_create_array_buffer_with_copy(buffer, length);
// Return type: refptr_same
return CefV8ValueCToCpp::Wrap(_retval);
}
NO_SANITIZE("cfi-icall")
CefRefPtr<CefV8Value> CefV8Value::CreateFunction(
const CefString& name,

View File

@ -9,11 +9,10 @@
// implementations. See the translator.README.txt file in the tools directory
// for more information.
//
// $hash=da609d625660ca617e1a01d5dc359932142e15a3$
// $hash=7bdd882f715040d06246576d0bafbbd7b9a39f8f$
//
#include "libcef_dll/ctocpp/views/window_delegate_ctocpp.h"
#include "libcef_dll/cpptoc/views/view_cpptoc.h"
#include "libcef_dll/cpptoc/views/window_cpptoc.h"
#include "libcef_dll/shutdown_checker.h"
@ -579,6 +578,33 @@ cef_runtime_style_t CefWindowDelegateCToCpp::GetWindowRuntimeStyle() {
return _retval;
}
NO_SANITIZE("cfi-icall")
bool CefWindowDelegateCToCpp::GetLinuxWindowProperties(
CefRefPtr<CefWindow> window,
CefLinuxWindowProperties& properties) {
shutdown_checker::AssertNotShutdown();
cef_window_delegate_t* _struct = GetStruct();
if (CEF_MEMBER_MISSING(_struct, get_linux_window_properties)) {
return false;
}
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
// Verify param: window; type: refptr_diff
DCHECK(window.get());
if (!window.get()) {
return false;
}
// Execute
int _retval = _struct->get_linux_window_properties(
_struct, CefWindowCppToC::Wrap(window), &properties);
// Return type: bool
return _retval ? true : false;
}
NO_SANITIZE("cfi-icall")
CefSize CefWindowDelegateCToCpp::GetPreferredSize(CefRefPtr<CefView> view) {
shutdown_checker::AssertNotShutdown();

View File

@ -9,7 +9,7 @@
// implementations. See the translator.README.txt file in the tools directory
// for more information.
//
// $hash=50ace2b6a45a23d4ff5d9a91ab7c37a893f7e0b4$
// $hash=ef831469d4dd59c3a20f0dfee3e8e945a52d7637$
//
#ifndef CEF_LIBCEF_DLL_CTOCPP_VIEWS_WINDOW_DELEGATE_CTOCPP_H_
@ -67,6 +67,8 @@ class CefWindowDelegateCToCpp
void OnThemeColorsChanged(CefRefPtr<CefWindow> window,
bool chrome_theme) override;
cef_runtime_style_t GetWindowRuntimeStyle() override;
bool GetLinuxWindowProperties(CefRefPtr<CefWindow> window,
CefLinuxWindowProperties& properties) override;
// CefPanelDelegate methods.

View File

@ -1070,11 +1070,15 @@ class CefMessageRouterRendererSideImpl : public CefMessageRouterRendererSide {
CefRefPtr<CefV8Context> context = GetContextByID(context_id);
if (context && info->success_callback && context->Enter()) {
CefRefPtr<cmru::BinaryValueABRCallback> release_callback =
new cmru::BinaryValueABRCallback(response);
CefRefPtr<CefV8Value> value = CefV8Value::CreateArrayBuffer(
response->GetData(), response->GetSize(), release_callback);
CefRefPtr<CefV8Value> value;
#ifdef CEF_V8_ENABLE_SANDBOX
value = CefV8Value::CreateArrayBufferWithCopy(response->GetData(),
response->GetSize());
#else
value = CefV8Value::CreateArrayBuffer(
response->GetData(), response->GetSize(),
new cmru::BinaryValueABRCallback(response));
#endif
context->Exit();

View File

@ -48,6 +48,7 @@ struct RendererMessage {
std::variant<CefString, CefRefPtr<const CefBinaryBuffer>> payload;
};
#ifndef CEF_V8_ENABLE_SANDBOX
class BinaryValueABRCallback final : public CefV8ArrayBufferReleaseCallback {
public:
explicit BinaryValueABRCallback(CefRefPtr<CefBinaryBuffer> value)
@ -62,6 +63,7 @@ class BinaryValueABRCallback final : public CefV8ArrayBufferReleaseCallback {
IMPLEMENT_REFCOUNTING(BinaryValueABRCallback);
};
#endif
CefRefPtr<BrowserResponseBuilder> CreateBrowserResponseBuilder(
size_t threshold,

View File

@ -9,7 +9,7 @@
// implementations. See the translator.README.txt file in the tools directory
// for more information.
//
// $hash=fd61a77bd549fb94bba963f9c0737ebceac324ac$
// $hash=85864cf7616899c4d51fbaf995d8e0db55249bd7$
//
#include <dlfcn.h>
@ -209,6 +209,8 @@ struct libcef_pointers {
decltype(&cef_v8value_create_object) cef_v8value_create_object;
decltype(&cef_v8value_create_array) cef_v8value_create_array;
decltype(&cef_v8value_create_array_buffer) cef_v8value_create_array_buffer;
decltype(&cef_v8value_create_array_buffer_with_copy)
cef_v8value_create_array_buffer_with_copy;
decltype(&cef_v8value_create_function) cef_v8value_create_function;
decltype(&cef_v8value_create_promise) cef_v8value_create_promise;
decltype(&cef_v8stack_trace_get_current) cef_v8stack_trace_get_current;
@ -439,6 +441,7 @@ int libcef_init_pointers(const char* path) {
INIT_ENTRY(cef_v8value_create_object);
INIT_ENTRY(cef_v8value_create_array);
INIT_ENTRY(cef_v8value_create_array_buffer);
INIT_ENTRY(cef_v8value_create_array_buffer_with_copy);
INIT_ENTRY(cef_v8value_create_function);
INIT_ENTRY(cef_v8value_create_promise);
INIT_ENTRY(cef_v8stack_trace_get_current);
@ -1145,6 +1148,14 @@ struct _cef_v8value_t* cef_v8value_create_array_buffer(
release_callback);
}
NO_SANITIZE("cfi-icall")
struct _cef_v8value_t* cef_v8value_create_array_buffer_with_copy(
void* buffer,
size_t length) {
return g_libcef_pointers.cef_v8value_create_array_buffer_with_copy(buffer,
length);
}
NO_SANITIZE("cfi-icall")
struct _cef_v8value_t* cef_v8value_create_function(
const cef_string_t* name,

View File

@ -12,7 +12,7 @@ index 79ba3ac1913f8..46bcb4366d2f8 100644
if (main_argv)
setproctitle_init(main_argv);
diff --git content/app/content_main.cc content/app/content_main.cc
index 4251459b695e6..d74286fec151b 100644
index 4251459b695e6..4b61268b74378 100644
--- content/app/content_main.cc
+++ content/app/content_main.cc
@@ -174,11 +174,8 @@ ContentMainParams::~ContentMainParams() = default;
@ -39,7 +39,18 @@ index 4251459b695e6..d74286fec151b 100644
// A flag to indicate whether Main() has been called before. On Android, we
// may re-run Main() without restarting the browser process. This flag
@@ -275,14 +269,6 @@ RunContentProcess(ContentMainParams params,
@@ -267,7 +261,9 @@ RunContentProcess(ContentMainParams params,
// default, "C", locale.
setlocale(LC_NUMERIC, "C");
- SetupSignalHandlers();
+ if (!params.disable_signal_handlers) {
+ SetupSignalHandlers();
+ }
#endif
#if BUILDFLAG(IS_WIN)
@@ -275,14 +271,6 @@ RunContentProcess(ContentMainParams params,
#endif
#if BUILDFLAG(IS_MAC)
@ -54,7 +65,7 @@ index 4251459b695e6..d74286fec151b 100644
InitializeMac();
#endif
@@ -330,12 +316,46 @@ RunContentProcess(ContentMainParams params,
@@ -330,12 +318,46 @@ RunContentProcess(ContentMainParams params,
if (IsSubprocess())
CommonSubprocessInit();
@ -149,10 +160,22 @@ index cbbc2f3ec12fa..f097b3cdded2f 100644
int RunBrowser(MainFunctionParams main_function_params,
bool start_minimal_browser);
diff --git content/public/app/content_main.h content/public/app/content_main.h
index 7f9b515297357..89b52e34fa31a 100644
index 7f9b515297357..5606867e43780 100644
--- content/public/app/content_main.h
+++ content/public/app/content_main.h
@@ -94,6 +94,13 @@ struct CONTENT_EXPORT ContentMainParams {
@@ -66,6 +66,11 @@ struct CONTENT_EXPORT ContentMainParams {
// are left uninitialized.
bool minimal_browser_mode = false;
+#if BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_ANDROID)
+ // Indicates whether to disable signal handlers
+ bool disable_signal_handlers = false;
+#endif
+
#if BUILDFLAG(IS_MAC)
// The outermost autorelease pool to pass to main entry points.
STACK_ALLOCATED_IGNORE("https://crbug.com/1424190")
@@ -94,6 +99,13 @@ struct CONTENT_EXPORT ContentMainParams {
}
};

View File

@ -14,7 +14,13 @@ BaseClientHandler::BaseClientHandler() {
// static
CefRefPtr<BaseClientHandler> BaseClientHandler::GetForBrowser(
CefRefPtr<CefBrowser> browser) {
return static_cast<BaseClientHandler*>(browser->GetHost()->GetClient().get());
return GetForClient(browser->GetHost()->GetClient());
}
// static
CefRefPtr<BaseClientHandler> BaseClientHandler::GetForClient(
CefRefPtr<CefClient> client) {
return static_cast<BaseClientHandler*>(client.get());
}
bool BaseClientHandler::OnProcessMessageReceived(

View File

@ -24,6 +24,9 @@ class BaseClientHandler : public CefClient,
static CefRefPtr<BaseClientHandler> GetForBrowser(
CefRefPtr<CefBrowser> browser);
// Returns the BaseClientHandler for |client|.
static CefRefPtr<BaseClientHandler> GetForClient(CefRefPtr<CefClient> client);
// CefClient methods
CefRefPtr<CefLifeSpanHandler> GetLifeSpanHandler() override { return this; }
CefRefPtr<CefRequestHandler> GetRequestHandler() override { return this; }
@ -92,6 +95,9 @@ class BaseClientHandler : public CefClient,
void SetHangAction(HangAction action);
HangAction GetHangAction() const;
// Used to determine the object type for each concrete implementation.
virtual const void* GetTypeKey() const = 0;
protected:
CefRefPtr<CefResourceManager> GetResourceManager() const {
return resource_manager_;

View File

@ -1124,7 +1124,9 @@ void BrowserWindowOsrGtk::OnBeforeClose(CefRefPtr<CefBrowser> browser) {
CEF_REQUIRE_UI_THREAD();
// Detach |this| from the ClientHandlerOsr.
static_cast<ClientHandlerOsr*>(client_handler_.get())->DetachOsrDelegate();
auto handler = ClientHandlerOsr::GetForClient(client_handler_);
CHECK(handler);
handler->DetachOsrDelegate();
ScopedGdkThreadsEnter scoped_gdk_threads;

View File

@ -1581,8 +1581,10 @@ void BrowserWindowOsrMacImpl::OnBeforeClose(CefRefPtr<CefBrowser> browser) {
REQUIRE_MAIN_THREAD();
// Detach |this| from the ClientHandlerOsr.
static_cast<ClientHandlerOsr*>(browser_window_.client_handler_.get())
->DetachOsrDelegate();
auto handler =
ClientHandlerOsr::GetForClient(browser_window_.client_handler_);
CHECK(handler);
handler->DetachOsrDelegate();
}
bool BrowserWindowOsrMacImpl::GetRootScreenRect(CefRefPtr<CefBrowser> browser,

View File

@ -19,6 +19,16 @@ ClientHandlerOsr::ClientHandlerOsr(Delegate* delegate,
DCHECK(osr_delegate_);
}
// static
CefRefPtr<ClientHandlerOsr> ClientHandlerOsr::GetForClient(
CefRefPtr<CefClient> client) {
auto base = BaseClientHandler::GetForClient(client);
if (base && base->GetTypeKey() == &kTypeKey) {
return static_cast<ClientHandlerOsr*>(base.get());
}
return nullptr;
}
void ClientHandlerOsr::DetachOsrDelegate() {
if (!CefCurrentlyOn(TID_UI)) {
// Execute this method on the UI thread.

View File

@ -80,6 +80,10 @@ class ClientHandlerOsr : public ClientHandler,
bool with_controls,
const std::string& startup_url);
// Returns the ClientHandlerOsr for |client|, or nullptr if |client| is not a
// ClientHandlerOsr.
static CefRefPtr<ClientHandlerOsr> GetForClient(CefRefPtr<CefClient> client);
// This object may outlive the OsrDelegate object so it's necessary for the
// OsrDelegate to detach itself before destruction.
void DetachOsrDelegate();
@ -139,6 +143,10 @@ class ClientHandlerOsr : public ClientHandler,
void OnAccessibilityLocationChange(CefRefPtr<CefValue> value) override;
private:
// Used to determine the object type.
virtual const void* GetTypeKey() const override { return &kTypeKey; }
static const int kTypeKey = 0;
// Only accessed on the UI thread.
OsrDelegate* osr_delegate_;

View File

@ -11,4 +11,14 @@ ClientHandlerStd::ClientHandlerStd(Delegate* delegate,
const std::string& startup_url)
: ClientHandler(delegate, /*is_osr=*/false, with_controls, startup_url) {}
// static
CefRefPtr<ClientHandlerStd> ClientHandlerStd::GetForClient(
CefRefPtr<CefClient> client) {
auto base = BaseClientHandler::GetForClient(client);
if (base && base->GetTypeKey() == &kTypeKey) {
return static_cast<ClientHandlerStd*>(base.get());
}
return nullptr;
}
} // namespace client

View File

@ -18,7 +18,15 @@ class ClientHandlerStd : public ClientHandler {
bool with_controls,
const std::string& startup_url);
// Returns the ClientHandlerStd for |client|, or nullptr if |client| is not a
// ClientHandlerStd.
static CefRefPtr<ClientHandlerStd> GetForClient(CefRefPtr<CefClient> client);
private:
// Used to determine the object type.
virtual const void* GetTypeKey() const override { return &kTypeKey; }
static const int kTypeKey = 0;
// Include the default reference counting implementation.
IMPLEMENT_REFCOUNTING(ClientHandlerStd);
DISALLOW_COPY_AND_ASSIGN(ClientHandlerStd);

View File

@ -0,0 +1,19 @@
// Copyright (c) 2024 The Chromium Embedded Framework Authors. All rights
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
#include "tests/cefclient/browser/default_client_handler.h"
namespace client {
// static
CefRefPtr<DefaultClientHandler> DefaultClientHandler::GetForClient(
CefRefPtr<CefClient> client) {
auto base = BaseClientHandler::GetForClient(client);
if (base && base->GetTypeKey() == &kTypeKey) {
return static_cast<DefaultClientHandler*>(base.get());
}
return nullptr;
}
} // namespace client

View File

@ -16,7 +16,16 @@ class DefaultClientHandler : public BaseClientHandler {
public:
DefaultClientHandler() = default;
// Returns the DefaultClientHandler for |client|, or nullptr if |client| is
// not a DefaultClientHandler.
static CefRefPtr<DefaultClientHandler> GetForClient(
CefRefPtr<CefClient> client);
private:
// Used to determine the object type.
virtual const void* GetTypeKey() const override { return &kTypeKey; }
static const int kTypeKey = 0;
IMPLEMENT_REFCOUNTING(DefaultClientHandler);
DISALLOW_COPY_AND_ASSIGN(DefaultClientHandler);
};

View File

@ -947,8 +947,10 @@ void OsrWindowWin::OnAfterCreated(CefRefPtr<CefBrowser> browser) {
void OsrWindowWin::OnBeforeClose(CefRefPtr<CefBrowser> browser) {
CEF_REQUIRE_UI_THREAD();
// Detach |this| from the ClientHandlerOsr.
static_cast<ClientHandlerOsr*>(browser_->GetHost()->GetClient().get())
->DetachOsrDelegate();
auto handler =
ClientHandlerOsr::GetForClient(browser_->GetHost()->GetClient());
CHECK(handler);
handler->DetachOsrDelegate();
browser_ = nullptr;
render_handler_->SetBrowser(nullptr);
Destroy();

View File

@ -273,7 +273,12 @@ ViewsWindow::Delegate* RootWindowViews::GetDelegateForPopup(
CefRefPtr<CefClient> client) {
CEF_REQUIRE_UI_THREAD();
// |handler| was created in RootWindowViews::InitAsPopup().
ClientHandlerStd* handler = static_cast<ClientHandlerStd*>(client.get());
// May return nullptr when running with `--use-default-popup`.
auto handler = ClientHandlerStd::GetForClient(client);
if (!handler) {
return nullptr;
}
RootWindowViews* root_window =
static_cast<RootWindowViews*>(handler->delegate());

View File

@ -671,6 +671,19 @@ cef_runtime_style_t ViewsWindow::GetWindowRuntimeStyle() {
return CEF_RUNTIME_STYLE_DEFAULT;
}
#if defined(OS_LINUX)
bool ViewsWindow::GetLinuxWindowProperties(
CefRefPtr<CefWindow> window,
CefLinuxWindowProperties& properties) {
CefString(&properties.wayland_app_id) =
CefString(&properties.wm_class_class) =
CefString(&properties.wm_class_name) =
CefString(&properties.wm_role_name) = "cef";
return true;
}
#endif
void ViewsWindow::OnWindowCreated(CefRefPtr<CefWindow> window) {
CEF_REQUIRE_UI_THREAD();
DCHECK(browser_view_);

View File

@ -162,6 +162,11 @@ class ViewsWindow : public CefBrowserViewDelegate,
const CefKeyEvent& event) override;
// CefWindowDelegate methods:
#if defined(OS_LINUX)
virtual bool GetLinuxWindowProperties(
CefRefPtr<CefWindow> window,
CefLinuxWindowProperties& properties) override;
#endif
void OnWindowCreated(CefRefPtr<CefWindow> window) override;
void OnWindowClosing(CefRefPtr<CefWindow> window) override;
void OnWindowDestroyed(CefRefPtr<CefWindow> window) override;

View File

@ -322,6 +322,7 @@ PERF_TEST_FUNC(V8ObjectGetValueWithAccessor) {
PERF_ITERATIONS_END()
}
#ifndef CEF_V8_ENABLE_SANDBOX
PERF_TEST_FUNC(V8ArrayBufferCreate) {
class ReleaseCallback : public CefV8ArrayBufferReleaseCallback {
public:
@ -339,6 +340,17 @@ PERF_TEST_FUNC(V8ArrayBufferCreate) {
CefV8Value::CreateArrayBuffer(buffer, byte_len, callback);
PERF_ITERATIONS_END()
}
#endif // CEF_V8_ENABLE_SANDBOX
PERF_TEST_FUNC(V8ArrayBufferCopy) {
constexpr size_t len = 1;
constexpr size_t byte_len = len * sizeof(float);
std::array<float, len> buffer = {0};
PERF_ITERATIONS_START()
CefRefPtr<CefV8Value> ret =
CefV8Value::CreateArrayBufferWithCopy(buffer.data(), byte_len);
PERF_ITERATIONS_END()
}
PERF_TEST_FUNC(V8ContextEnterExit) {
CefRefPtr<CefV8Context> context = CefV8Context::GetCurrentContext();
@ -385,7 +397,10 @@ const PerfTestEntry kPerfTests[] = {
PERF_TEST_ENTRY(V8ObjectGetValue),
PERF_TEST_ENTRY(V8ObjectSetValueWithAccessor),
PERF_TEST_ENTRY(V8ObjectGetValueWithAccessor),
#ifndef CEF_V8_ENABLE_SANDBOX
PERF_TEST_ENTRY(V8ArrayBufferCreate),
#endif // CEF_V8_ENABLE_SANDBOX
PERF_TEST_ENTRY(V8ArrayBufferCopy),
PERF_TEST_ENTRY(V8ContextEnterExit),
PERF_TEST_ENTRY(V8ContextEval),
};

View File

@ -3,11 +3,12 @@
<head>
<meta charset="UTF-8" />
<title>Binary vs String Transfer Benchmark</title>
<script src="https://cdn.plot.ly/plotly-2.26.0.min.js"></script>
<script src="https://cdn.plot.ly/plotly-2.34.0.min.js"></script>
<style>
body {
font-family: Tahoma, Serif;
font-size: 10pt;
background-color: white;
}
.info {
font-size: 12pt;
@ -116,7 +117,9 @@
<div id="round_trip_avg_chart">
<!-- Average round trip linear chart will be drawn inside this DIV -->
</div>
<div id="round_trip_chart">
<!-- Round trip linear chart will be drawn inside this DIV -->
</div>
<div id="box_plot_chart">
<!-- Box plot of round trip time will be drawn inside this DIV -->
</div>
@ -125,13 +128,14 @@
let tests = [];
let box_plot_test_data = [];
let round_trip_avg_plot_data = [];
let round_trip_plot_data = [];
function nextTestSuite(testIndex) {
const nextTestIndex = testIndex + 1;
setTimeout(execTestSuite, 0, nextTestIndex);
}
function generateRandomString(size) {
function generateString(size) {
// Symbols that will be encoded as two bytes in UTF-8
// so we compare transfer of the same amount of bytes
const characters =
@ -144,7 +148,7 @@
return randomString;
}
function generateRandomArrayBuffer(size) {
function generateArrayBuffer(size) {
const buffer = new ArrayBuffer(size);
const uint8Array = new Uint8Array(buffer);
for (let i = 0; i < uint8Array.length; i++) {
@ -157,8 +161,7 @@
console.error(`ErrorCode:${errorCode} Message:${errorMessage}`);
}
function sendString(size, testIndex) {
const request = generateRandomString(size);
function sendString(request, testIndex) {
const startTime = performance.now();
const onSuccess = (response) => {
const roundTrip = performance.now() - startTime;
@ -166,6 +169,8 @@
test.totalRoundTrip += roundTrip;
test.sample++;
box_plot_test_data[testIndex].x.push(roundTrip);
round_trip_plot_data[testIndex].x.push(test.sample);
round_trip_plot_data[testIndex].y.push(roundTrip);
setTimeout(execTest, 0, testIndex);
};
@ -176,8 +181,7 @@
});
}
function sendArrayBuffer(size, testIndex) {
const request = generateRandomArrayBuffer(size);
function sendArrayBuffer(request, testIndex) {
const startTime = performance.now();
const onSuccess = (response) => {
const roundTrip = performance.now() - startTime;
@ -185,6 +189,8 @@
test.totalRoundTrip += roundTrip;
test.sample++;
box_plot_test_data[testIndex].x.push(roundTrip);
round_trip_plot_data[testIndex].x.push(test.sample);
round_trip_plot_data[testIndex].y.push(roundTrip);
setTimeout(execTest, 0, testIndex);
};
@ -209,7 +215,7 @@
if (test.sample >= test.totalSamples) {
return nextTestSuite(testIndex);
}
test.func(test.length, test.index);
test.func(test.request, test.index);
}
function column(prepared, value) {
@ -279,14 +285,14 @@
function buildTestResults(tests) {
testResults = [];
let oldRoundTrip = {
let stringRoundTrip = {
x: [],
y: [],
type: "scatter",
name: "String",
};
let newRoundTrip = {
let binaryRoundTrip = {
x: [],
y: [],
type: "scatter",
@ -332,13 +338,13 @@
stdDeviationBinary: stdDeviationBinary,
});
oldRoundTrip.x.push(test.byteSize);
newRoundTrip.x.push(test.byteSize);
oldRoundTrip.y.push(avgRoundTrip);
newRoundTrip.y.push(avgRoundTripBin);
stringRoundTrip.x.push(test.byteSize);
binaryRoundTrip.x.push(test.byteSize);
stringRoundTrip.y.push(avgRoundTrip);
binaryRoundTrip.y.push(avgRoundTripBin);
}
round_trip_avg_plot_data = [oldRoundTrip, newRoundTrip];
round_trip_avg_plot_data = [stringRoundTrip, binaryRoundTrip];
return testResults;
}
@ -374,17 +380,21 @@
box_plot_test_data.forEach((data) => {
data.x = [];
});
round_trip_plot_data.forEach((data) => {
data.x = [];
data.y = [];
});
}
function queueTest(name, byteSize, length, testFunc) {
function queueTest(name, byteSize, request, testFunc) {
const testIndex = tests.length;
test = {
name: name,
byteSize: byteSize,
length: length,
index: testIndex,
sample: 0,
totalRoundTrip: 0,
request: request,
func: testFunc,
};
tests.push(test);
@ -397,11 +407,18 @@
jitter: 0.3,
pointpos: -1.8,
});
round_trip_plot_data.push({
x: [],
y: [],
type: "scatter",
name: name,
});
}
function execTestSuite(testIndex) {
if (testIndex < tests.length) {
execTest(testIndex);
setTimeout(execTest, 0, testIndex);
} else {
testsRunFinished();
}
@ -426,19 +443,16 @@
testResults = buildTestResults(tests);
testResults.forEach((result) => displayResult(result));
const round_trip_layout = {
Plotly.newPlot("round_trip_avg_chart", round_trip_avg_plot_data, {
title: "Average round trip, μs (Smaller Better)",
};
Plotly.newPlot(
"round_trip_avg_chart",
round_trip_avg_plot_data,
round_trip_layout
);
});
Plotly.newPlot("round_trip_chart", round_trip_plot_data, {
title: "Linear: Round Trip Time, μs",
});
Plotly.newPlot("box_plot_chart", box_plot_test_data, {
title: "Box plot: Round Trip Time, μs",
});
const box_plot_layout = {
title: "Round Trip Time, μs",
};
Plotly.newPlot("box_plot_chart", box_plot_test_data, box_plot_layout);
setSettingsState(false);
}
@ -466,6 +480,7 @@
window.runTestSuite = () => {
Plotly.purge("round_trip_avg_chart");
Plotly.purge("box_plot_chart");
Plotly.purge("round_trip_chart");
setSettingsState(true);
const totalSamples = parseInt(
document.getElementById("sSamples").value
@ -474,21 +489,22 @@
};
const totalSamples = parseInt(document.getElementById("sSamples").value);
queueTest("Empty String", 0, 0, sendString);
queueTest("Empty Binary", 0, 0, sendArrayBuffer);
for (let byteSize = 8; byteSize <= 512 * 1024; byteSize *= 2) {
queueTest("Empty String", 0, generateString(0), sendString);
queueTest("Empty Binary", 0, generateArrayBuffer(0), sendArrayBuffer);
for (let byteSize = 8; byteSize <= 512 * 1024; byteSize *= 4) {
// Byte size of a string is twice its length because of UTF-16 encoding
const stringLen = byteSize / 2;
queueTest(
humanFileSize(byteSize) + " String",
byteSize,
stringLen,
generateString(stringLen),
sendString
);
queueTest(
humanFileSize(byteSize) + " Binary",
byteSize,
byteSize,
generateArrayBuffer(byteSize),
sendArrayBuffer
);
}

View File

@ -8,6 +8,7 @@
body {
font-family: Tahoma, Serif;
font-size: 10pt;
background-color: white;
}
.left {

View File

@ -58,9 +58,12 @@ enum V8TestMode {
V8TEST_EMPTY_STRING_CREATE,
V8TEST_ARRAY_CREATE,
V8TEST_ARRAY_VALUE,
#ifndef CEF_V8_ENABLE_SANDBOX
V8TEST_ARRAY_BUFFER,
V8TEST_ARRAY_BUFFER_CREATE_EMPTY,
V8TEST_ARRAY_BUFFER_VALUE,
#endif // CEF_V8_ENABLE_SANDBOX
V8TEST_ARRAY_BUFFER_CREATE_EMPTY,
V8TEST_ARRAY_BUFFER_COPY,
V8TEST_OBJECT_CREATE,
V8TEST_OBJECT_USERDATA,
V8TEST_OBJECT_ACCESSOR,
@ -149,14 +152,19 @@ class V8RendererTest : public ClientAppRenderer::Delegate,
case V8TEST_ARRAY_VALUE:
RunArrayValueTest();
break;
#ifndef CEF_V8_ENABLE_SANDBOX
case V8TEST_ARRAY_BUFFER:
RunArrayBufferTest();
break;
case V8TEST_ARRAY_BUFFER_VALUE:
RunArrayBufferValueTest();
break;
#endif // CEF_V8_ENABLE_SANDBOX
case V8TEST_ARRAY_BUFFER_CREATE_EMPTY:
RunArrayBufferCreateEmptyTest();
break;
case V8TEST_ARRAY_BUFFER_VALUE:
RunArrayBufferValueTest();
case V8TEST_ARRAY_BUFFER_COPY:
RunArrayBufferCopyTest();
break;
case V8TEST_OBJECT_CREATE:
RunObjectCreateTest();
@ -612,6 +620,7 @@ class V8RendererTest : public ClientAppRenderer::Delegate,
DestroyTest();
}
#ifndef CEF_V8_ENABLE_SANDBOX
void RunArrayBufferTest() {
class TestArrayBufferReleaseCallback
: public CefV8ArrayBufferReleaseCallback {
@ -654,10 +663,11 @@ class V8RendererTest : public ClientAppRenderer::Delegate,
void* data = value->GetArrayBufferData();
EXPECT_EQ(static_cast<int*>(data), static_data);
EXPECT_FALSE(value->HasValue(0));
EXPECT_TRUE(value->GetArrayBufferReleaseCallback().get() != nullptr);
EXPECT_TRUE(((TestArrayBufferReleaseCallback*)value
->GetArrayBufferReleaseCallback()
.get()) == release_callback);
EXPECT_NE(value->GetArrayBufferReleaseCallback().get(), nullptr);
EXPECT_EQ((TestArrayBufferReleaseCallback*)value
->GetArrayBufferReleaseCallback()
.get(),
release_callback);
// |Value| buffer is explicitly freed by NeuterArrayBuffer().
EXPECT_FALSE(destructorCalled);
@ -670,7 +680,33 @@ class V8RendererTest : public ClientAppRenderer::Delegate,
EXPECT_TRUE(context->Exit());
DestroyTest();
}
#endif // CEF_V8_ENABLE_SANDBOX
void RunArrayBufferCopyTest() {
CefRefPtr<CefV8Context> context = GetContext();
// Enter the V8 context.
EXPECT_TRUE(context->Enter());
{
int static_data[16] = {1, 2, 3, 4};
CefRefPtr<CefV8Value> value = CefV8Value::CreateArrayBufferWithCopy(
static_data, sizeof(static_data));
EXPECT_TRUE(value.get());
EXPECT_TRUE(value->IsArrayBuffer());
EXPECT_TRUE(value->IsObject());
EXPECT_EQ(value->GetArrayBufferByteLength(), sizeof(static_data));
void* data = value->GetArrayBufferData();
EXPECT_EQ(static_cast<int*>(data)[0], static_data[0]);
EXPECT_EQ(static_cast<int*>(data)[1], static_data[1]);
EXPECT_FALSE(value->HasValue(0));
}
// Exit the V8 context.
EXPECT_TRUE(context->Exit());
DestroyTest();
}
#ifndef CEF_V8_ENABLE_SANDBOX
void RunArrayBufferValueTest() {
class TestArrayBufferReleaseCallback
: public CefV8ArrayBufferReleaseCallback {
@ -720,8 +756,17 @@ class V8RendererTest : public ClientAppRenderer::Delegate,
EXPECT_TRUE(context->Exit());
DestroyTest();
}
#endif // CEF_V8_ENABLE_SANDBOX
void RunArrayBufferCreateEmptyTest() {
// Enter the V8 context
CefRefPtr<CefV8Context> context = GetContext();
EXPECT_TRUE(context->Enter());
const size_t zero_size = 0;
void* null_data = nullptr;
CefRefPtr<CefV8Value> value;
#ifndef CEF_V8_ENABLE_SANDBOX
class TestArrayBufferReleaseCallback
: public CefV8ArrayBufferReleaseCallback {
public:
@ -733,22 +778,17 @@ class V8RendererTest : public ClientAppRenderer::Delegate,
CefRefPtr<TestArrayBufferReleaseCallback> owner =
new TestArrayBufferReleaseCallback();
// Enter the V8 context
CefRefPtr<CefV8Context> context = GetContext();
EXPECT_TRUE(context->Enter());
const size_t zero_size = 0;
void* null_data = nullptr;
CefRefPtr<CefV8Value> value =
CefV8Value::CreateArrayBuffer(null_data, zero_size, owner);
EXPECT_EQ(value->GetArrayBufferByteLength(), zero_size);
value = CefV8Value::CreateArrayBuffer(null_data, zero_size, owner);
EXPECT_EQ(value->GetArrayBufferData(), null_data);
EXPECT_NE(value->GetArrayBufferReleaseCallback().get(), nullptr);
#else
value = CefV8Value::CreateArrayBufferWithCopy(null_data, zero_size);
#endif
EXPECT_EQ(value->GetArrayBufferByteLength(), zero_size);
CefRefPtr<CefV8Value> object = context->GetGlobal();
EXPECT_TRUE(object.get());
EXPECT_TRUE(object->SetValue("arr", value, V8_PROPERTY_ATTRIBUTE_NONE));
EXPECT_NE(value->GetArrayBufferReleaseCallback().get(), nullptr);
EXPECT_TRUE(value->NeuterArrayBuffer());
// Exit the V8 context.
@ -3413,9 +3453,12 @@ V8_TEST(StringCreate, V8TEST_STRING_CREATE)
V8_TEST(EmptyStringCreate, V8TEST_EMPTY_STRING_CREATE)
V8_TEST(ArrayCreate, V8TEST_ARRAY_CREATE)
V8_TEST(ArrayValue, V8TEST_ARRAY_VALUE)
#ifndef CEF_V8_ENABLE_SANDBOX
V8_TEST(ArrayBuffer, V8TEST_ARRAY_BUFFER)
V8_TEST(ArrayBufferCreateEmpty, V8TEST_ARRAY_BUFFER_CREATE_EMPTY)
V8_TEST(ArrayBufferValue, V8TEST_ARRAY_BUFFER_VALUE)
#endif // CEF_V8_ENABLE_SANDBOX
V8_TEST(ArrayBufferCreateEmpty, V8TEST_ARRAY_BUFFER_CREATE_EMPTY)
V8_TEST(ArrayBufferCopy, V8TEST_ARRAY_BUFFER_COPY)
V8_TEST(ObjectCreate, V8TEST_OBJECT_CREATE)
V8_TEST(ObjectUserData, V8TEST_OBJECT_USERDATA)
V8_TEST(ObjectAccessor, V8TEST_OBJECT_ACCESSOR)

View File

@ -201,6 +201,8 @@ cc_library(
"@platforms//os:windows": [":cef"],
"//conditions:default": None,
}),
# Support <angled> includes.
includes = ["./"],
)
# Only available on MacOS/Windows.

View File

@ -228,11 +228,6 @@ def GetRecommendedDefaultArgs():
# "//chrome:chrome_dll" target, which will fail to build with CEF.
'enable_resource_allowlist_generation': False,
# Disable V8 sandboxed pointers to avoid crashing when using
# CefV8Value::CreateArrayBuffer with memory allocated outside of the V8
# sandbox. See https://github.com/chromiumembedded/cef/issues/3332.
'v8_enable_sandbox': False,
# Disable downgrade processing/restart with the Chrome runtime.
# https://github.com/chromiumembedded/cef/issues/3608
'enable_downgrade_processing': False,

View File

@ -28,6 +28,13 @@ def make_config_header(gn_config):
not 'ozone_platform_x11=false' in lines:
defines.append('#define CEF_X11 1')
# If the V8 sandbox is not disabled explicitly and
# the target_cpu is arm64 or x64 (see v8_enable_pointer_compression)
# add CEF_V8_ENABLE_SANDBOX define used in cef_message_router.h
if not 'v8_enable_sandbox=false' in lines and \
('target_cpu="arm64"' in lines or 'target_cpu="x64"' in lines):
defines.append('#define CEF_V8_ENABLE_SANDBOX 1')
result = get_copyright(full=True, translator=False) + \
"""//
// ---------------------------------------------------------------------------