Remove deprecated base::[Dictionary|List]Value API usage

This commit is contained in:
Marshall Greenblatt
2023-01-30 16:42:40 -05:00
parent 36ee304ed4
commit 4c41f14360
34 changed files with 387 additions and 375 deletions

View File

@ -264,8 +264,8 @@ void AlloyBrowserContext::LoadExtension(
if (manifest && manifest->GetSize() > 0) { if (manifest && manifest->GetSize() > 0) {
CefDictionaryValueImpl* value_impl = CefDictionaryValueImpl* value_impl =
static_cast<CefDictionaryValueImpl*>(manifest.get()); static_cast<CefDictionaryValueImpl*>(manifest.get());
std::unique_ptr<base::DictionaryValue> value_copy(value_impl->CopyValue()); auto value = value_impl->CopyValue();
extension_system()->LoadExtension(std::move(*value_copy).TakeDict(), extension_system()->LoadExtension(std::move(value.GetDict()),
root_directory, false /* builtin */, root_directory, false /* builtin */,
loader_context, handler); loader_context, handler);
} else { } else {

View File

@ -34,7 +34,7 @@ void CefBrowserFrame::RegisterBrowserInterfaceBindersForFrame(
} }
void CefBrowserFrame::SendMessage(const std::string& name, void CefBrowserFrame::SendMessage(const std::string& name,
base::Value arguments) { base::Value::List arguments) {
// Always send to the newly created RFH, which may be speculative when // Always send to the newly created RFH, which may be speculative when
// navigating cross-origin. // navigating cross-origin.
if (auto host = GetFrameHost(/*prefer_speculative=*/true)) { if (auto host = GetFrameHost(/*prefer_speculative=*/true)) {

View File

@ -35,7 +35,8 @@ class CefBrowserFrame
private: private:
// cef::mojom::BrowserFrame methods: // cef::mojom::BrowserFrame methods:
void SendMessage(const std::string& name, base::Value arguments) override; void SendMessage(const std::string& name,
base::Value::List arguments) override;
void SendSharedMemoryRegion(const std::string& name, void SendSharedMemoryRegion(const std::string& name,
base::ReadOnlySharedMemoryRegion region) override; base::ReadOnlySharedMemoryRegion region) override;
void FrameAttached(mojo::PendingRemote<cef::mojom::RenderFrame> render_frame, void FrameAttached(mojo::PendingRemote<cef::mojom::RenderFrame> render_frame,

View File

@ -514,8 +514,8 @@ void CefBrowserInfoManager::SendNewBrowserInfoResponse(
if (extra_info) { if (extra_info) {
auto extra_info_impl = auto extra_info_impl =
static_cast<CefDictionaryValueImpl*>(extra_info.get()); static_cast<CefDictionaryValueImpl*>(extra_info.get());
auto extra_info_value = base::WrapUnique(extra_info_impl->CopyValue()); auto extra_info_value = extra_info_impl->CopyValue();
params->extra_info = std::move(*extra_info_value); params->extra_info = std::move(extra_info_value.GetDict());
} }
} else { } else {
// The new browser info response has timed out. // The new browser info response has timed out.

View File

@ -43,7 +43,7 @@ bool CefDevToolsController::SendDevToolsMessage(
int CefDevToolsController::ExecuteDevToolsMethod( int CefDevToolsController::ExecuteDevToolsMethod(
int suggested_message_id, int suggested_message_id,
const std::string& method, const std::string& method,
const base::DictionaryValue* params) { const base::Value::Dict* params) {
CEF_REQUIRE_UIT(); CEF_REQUIRE_UIT();
if (!EnsureAgentHost()) { if (!EnsureAgentHost()) {
return 0; return 0;
@ -57,11 +57,11 @@ int CefDevToolsController::ExecuteDevToolsMethod(
next_message_id_ = message_id + 1; next_message_id_ = message_id + 1;
} }
base::DictionaryValue message; base::Value::Dict message;
message.SetIntKey("id", message_id); message.Set("id", message_id);
message.SetStringKey("method", method); message.Set("method", method);
if (params) { if (params) {
message.SetKey("params", params->Clone()); message.Set("params", params->Clone());
} }
std::string protocol_message; std::string protocol_message;

View File

@ -51,7 +51,7 @@ class CefDevToolsController : public content::DevToolsAgentHostClient {
bool SendDevToolsMessage(const base::StringPiece& message); bool SendDevToolsMessage(const base::StringPiece& message);
int ExecuteDevToolsMethod(int message_id, int ExecuteDevToolsMethod(int message_id,
const std::string& method, const std::string& method,
const base::DictionaryValue* params); const base::Value::Dict* params);
// |observer| must outlive this object or be removed. // |observer| must outlive this object or be removed.
void AddObserver(Observer* observer); void AddObserver(Observer* observer);

View File

@ -77,10 +77,10 @@ static std::string GetFrontendURL() {
scheme::kChromeDevToolsHost); scheme::kChromeDevToolsHost);
} }
base::DictionaryValue BuildObjectForResponse(const net::HttpResponseHeaders* rh, base::Value::Dict BuildObjectForResponse(const net::HttpResponseHeaders* rh,
bool success, bool success,
int net_error) { int net_error) {
base::DictionaryValue response; base::Value::Dict response;
int responseCode = 200; int responseCode = 200;
if (rh) { if (rh) {
responseCode = rh->response_code(); responseCode = rh->response_code();
@ -88,18 +88,18 @@ base::DictionaryValue BuildObjectForResponse(const net::HttpResponseHeaders* rh,
// In case of no headers, assume file:// URL and failed to load // In case of no headers, assume file:// URL and failed to load
responseCode = 404; responseCode = 404;
} }
response.SetInteger("statusCode", responseCode); response.Set("statusCode", responseCode);
response.SetInteger("netError", net_error); response.Set("netError", net_error);
response.SetString("netErrorName", net::ErrorToString(net_error)); response.Set("netErrorName", net::ErrorToString(net_error));
auto headers = std::make_unique<base::DictionaryValue>(); base::Value::Dict headers;
size_t iterator = 0; size_t iterator = 0;
std::string name; std::string name;
std::string value; std::string value;
// TODO(caseq): this probably needs to handle duplicate header names // TODO(caseq): this probably needs to handle duplicate header names
// correctly by folding them. // correctly by folding them.
while (rh && rh->EnumerateHeaderLines(&iterator, &name, &value)) { while (rh && rh->EnumerateHeaderLines(&iterator, &name, &value)) {
headers->SetString(name, value); headers.Set(name, value);
} }
response.Set("headers", std::move(headers)); response.Set("headers", std::move(headers));
@ -222,7 +222,7 @@ class CefDevToolsFrontend::NetworkResourceLoader
void OnComplete(bool success) override { void OnComplete(bool success) override {
auto response = BuildObjectForResponse(response_headers_.get(), success, auto response = BuildObjectForResponse(response_headers_.get(), success,
loader_->NetError()); loader_->NetError());
bindings_->SendMessageAck(request_id_, std::move(response)); bindings_->SendMessageAck(request_id_, base::Value(std::move(response)));
bindings_->loaders_.erase(bindings_->loaders_.find(this)); bindings_->loaders_.erase(bindings_->loaders_.find(this));
} }
@ -473,9 +473,9 @@ void CefDevToolsFrontend::HandleMessageFromDevToolsFrontend(
std::make_unique<network::WrapperPendingSharedURLLoaderFactory>( std::make_unique<network::WrapperPendingSharedURLLoaderFactory>(
std::move(pending_remote))); std::move(pending_remote)));
} else if (content::HasWebUIScheme(gurl)) { } else if (content::HasWebUIScheme(gurl)) {
base::DictionaryValue response; base::Value::Dict response;
response.SetInteger("statusCode", 403); response.Set("statusCode", 403);
SendMessageAck(request_id, std::move(response)); SendMessageAck(request_id, base::Value(std::move(response)));
return; return;
} else { } else {
auto* partition = auto* partition =

View File

@ -176,8 +176,8 @@ int CefDevToolsManager::ExecuteDevToolsMethod(
CefDictionaryValueImpl* impl = CefDictionaryValueImpl* impl =
static_cast<CefDictionaryValueImpl*>(params.get()); static_cast<CefDictionaryValueImpl*>(params.get());
CefValueController::AutoLock lock_scope(impl->controller()); CefValueController::AutoLock lock_scope(impl->controller());
return devtools_controller_->ExecuteDevToolsMethod(message_id, method, return devtools_controller_->ExecuteDevToolsMethod(
impl->GetValueUnsafe()); message_id, method, impl->GetValueUnsafe()->GetIfDict());
} else { } else {
return devtools_controller_->ExecuteDevToolsMethod(message_id, method, return devtools_controller_->ExecuteDevToolsMethod(message_id, method,
nullptr); nullptr);

View File

@ -15,11 +15,9 @@ CefExtensionImpl::CefExtensionImpl(const extensions::Extension* extension,
CefRefPtr<CefExtensionHandler> handler) CefRefPtr<CefExtensionHandler> handler)
: id_(extension->id()), : id_(extension->id()),
path_(extension->path().value()), path_(extension->path().value()),
manifest_(new CefDictionaryValueImpl( manifest_(
static_cast<base::DictionaryValue*>( new CefDictionaryValueImpl(extension->manifest()->value()->Clone(),
new base::Value(extension->manifest()->value()->Clone())), /*read_only=*/true)),
true,
true)),
loader_context_(loader_context), loader_context_(loader_context),
handler_(handler) {} handler_(handler) {}

View File

@ -275,11 +275,10 @@ void CefFrameHostImpl::SendProcessMessage(
// Invalidate the message object immediately by taking the argument list. // Invalidate the message object immediately by taking the argument list.
auto argument_list = auto argument_list =
static_cast<CefProcessMessageImpl*>(message.get())->TakeArgumentList(); static_cast<CefProcessMessageImpl*>(message.get())->TakeArgumentList();
SendToRenderFrame( SendToRenderFrame(
__FUNCTION__, __FUNCTION__,
base::BindOnce( base::BindOnce(
[](const CefString& name, base::ListValue argument_list, [](const CefString& name, base::Value::List argument_list,
const RenderFrameType& render_frame) { const RenderFrameType& render_frame) {
render_frame->SendMessage(name, std::move(argument_list)); render_frame->SendMessage(name, std::move(argument_list));
}, },
@ -631,12 +630,11 @@ void CefFrameHostImpl::OnRenderFrameDisconnect() {
} }
void CefFrameHostImpl::SendMessage(const std::string& name, void CefFrameHostImpl::SendMessage(const std::string& name,
base::Value arguments) { base::Value::List arguments) {
if (auto browser = GetBrowserHostBase()) { if (auto browser = GetBrowserHostBase()) {
if (auto client = browser->GetClient()) { if (auto client = browser->GetClient()) {
auto& list_value = base::Value::AsListValue(arguments); CefRefPtr<CefProcessMessageImpl> message(
CefRefPtr<CefProcessMessageImpl> message(new CefProcessMessageImpl( new CefProcessMessageImpl(name, std::move(arguments),
name, std::move(const_cast<base::ListValue&>(list_value)),
/*read_only=*/true)); /*read_only=*/true));
browser->GetClient()->OnProcessMessageReceived( browser->GetClient()->OnProcessMessageReceived(
browser.get(), this, PID_RENDERER, message.get()); browser.get(), this, PID_RENDERER, message.get());

View File

@ -135,7 +135,8 @@ class CefFrameHostImpl : public CefFrame, public cef::mojom::BrowserFrame {
content::RenderFrameHost* render_frame_host); content::RenderFrameHost* render_frame_host);
// cef::mojom::BrowserFrame methods forwarded from CefBrowserFrame. // cef::mojom::BrowserFrame methods forwarded from CefBrowserFrame.
void SendMessage(const std::string& name, base::Value arguments) override; void SendMessage(const std::string& name,
base::Value::List arguments) override;
void SendSharedMemoryRegion(const std::string& name, void SendSharedMemoryRegion(const std::string& name,
base::ReadOnlySharedMemoryRegion region) override; base::ReadOnlySharedMemoryRegion region) override;
void FrameAttached(mojo::PendingRemote<cef::mojom::RenderFrame> render_frame, void FrameAttached(mojo::PendingRemote<cef::mojom::RenderFrame> render_frame,

View File

@ -51,21 +51,18 @@ CefRefPtr<CefValue> GetPreference(PrefService* pref_service,
if (!pref) { if (!pref) {
return nullptr; return nullptr;
} }
return new CefValueImpl(new base::Value(pref->GetValue()->Clone())); return new CefValueImpl(pref->GetValue()->Clone());
} }
CefRefPtr<CefDictionaryValue> GetAllPreferences(PrefService* pref_service, CefRefPtr<CefDictionaryValue> GetAllPreferences(PrefService* pref_service,
bool include_defaults) { bool include_defaults) {
// Returns a DeepCopy of the value.
base::Value values = pref_service->GetPreferenceValues( base::Value values = pref_service->GetPreferenceValues(
include_defaults ? PrefService::INCLUDE_DEFAULTS include_defaults ? PrefService::INCLUDE_DEFAULTS
: PrefService::EXCLUDE_DEFAULTS); : PrefService::EXCLUDE_DEFAULTS);
// CefDictionaryValueImpl takes ownership of |values|. // CefDictionaryValueImpl takes ownership of |values| contents.
return new CefDictionaryValueImpl( return new CefDictionaryValueImpl(std::move(values), /*read_only=*/false);
base::DictionaryValue::From(
base::Value::ToUniquePtrValue(std::move(values)))
.release(),
true, false);
} }
bool CanSetPreference(PrefService* pref_service, const CefString& name) { bool CanSetPreference(PrefService* pref_service, const CefString& name) {

View File

@ -67,15 +67,12 @@ class CefPreferenceRegistrarImpl : public CefPreferenceRegistrar {
void RegisterComplexPref(const std::string& name, void RegisterComplexPref(const std::string& name,
CefRefPtr<CefValue> default_value) { CefRefPtr<CefValue> default_value) {
CefValueImpl* impl = static_cast<CefValueImpl*>(default_value.get()); CefValueImpl* impl = static_cast<CefValueImpl*>(default_value.get());
auto impl_value = impl->CopyValue();
CefValueImpl::ScopedLockedValue scoped_locked_value(impl); if (impl_value.type() == base::Value::Type::DICT) {
base::Value* impl_value = impl->GetValueUnsafe(); registry_->RegisterDictionaryPref(name, std::move(impl_value));
} else if (impl_value.type() == base::Value::Type::LIST) {
// Will make a deep copy of |impl_value|. registry_->RegisterListPref(name, std::move(impl_value));
if (impl_value->type() == base::Value::Type::DICT) {
registry_->RegisterDictionaryPref(name, impl_value->Clone());
} else if (impl_value->type() == base::Value::Type::LIST) {
registry_->RegisterListPref(name, impl_value->Clone());
} else { } else {
NOTREACHED(); NOTREACHED();
} }

View File

@ -191,11 +191,11 @@ void CefBrowserViewImpl::Detach() {
} }
} }
void CefBrowserViewImpl::GetDebugInfo(base::DictionaryValue* info, void CefBrowserViewImpl::GetDebugInfo(base::Value::Dict* info,
bool include_children) { bool include_children) {
ParentClass::GetDebugInfo(info, include_children); ParentClass::GetDebugInfo(info, include_children);
if (browser_) { if (browser_) {
info->SetString("url", browser_->GetMainFrame()->GetURL().ToString()); info->Set("url", browser_->GetMainFrame()->GetURL().ToString());
} }
} }

View File

@ -69,8 +69,7 @@ class CefBrowserViewImpl
// CefViewAdapter methods: // CefViewAdapter methods:
void Detach() override; void Detach() override;
std::string GetDebugType() override { return "BrowserView"; } std::string GetDebugType() override { return "BrowserView"; }
void GetDebugInfo(base::DictionaryValue* info, void GetDebugInfo(base::Value::Dict* info, bool include_children) override;
bool include_children) override;
// CefBrowserViewView::Delegate methods: // CefBrowserViewView::Delegate methods:
void OnBrowserViewAdded() override; void OnBrowserViewAdded() override;

View File

@ -48,10 +48,9 @@ CEF_LABEL_BUTTON_IMPL_T class CefLabelButtonImpl : public CEF_BUTTON_IMPL_D {
CefRefPtr<CefLabelButton> AsLabelButton() override { return this; } CefRefPtr<CefLabelButton> AsLabelButton() override { return this; }
// CefViewAdapter methods: // CefViewAdapter methods:
void GetDebugInfo(base::DictionaryValue* info, void GetDebugInfo(base::Value::Dict* info, bool include_children) override {
bool include_children) override {
ParentClass::GetDebugInfo(info, include_children); ParentClass::GetDebugInfo(info, include_children);
info->SetString("text", ParentClass::root_view()->GetText()); info->Set("text", ParentClass::root_view()->GetText());
} }
protected: protected:

View File

@ -49,21 +49,20 @@ CEF_PANEL_IMPL_T class CefPanelImpl : public CEF_VIEW_IMPL_D {
CefRefPtr<CefPanel> AsPanel() override { return this; } CefRefPtr<CefPanel> AsPanel() override { return this; }
// CefViewAdapter methods: // CefViewAdapter methods:
void GetDebugInfo(base::DictionaryValue* info, void GetDebugInfo(base::Value::Dict* info, bool include_children) override {
bool include_children) override {
ParentClass::GetDebugInfo(info, include_children); ParentClass::GetDebugInfo(info, include_children);
if (include_children) { if (include_children) {
const size_t count = ParentClass::content_view()->children().size(); const size_t count = ParentClass::content_view()->children().size();
if (count > 0U) { if (count > 0U) {
std::unique_ptr<base::ListValue> children(new base::ListValue()); base::Value::List children;
for (size_t i = 0U; i < count; ++i) { for (size_t i = 0U; i < count; ++i) {
views::View* view = ParentClass::content_view()->children()[i]; views::View* view = ParentClass::content_view()->children()[i];
CefViewAdapter* adapter = CefViewAdapter::GetFor(view); CefViewAdapter* adapter = CefViewAdapter::GetFor(view);
if (adapter) { if (adapter) {
base::DictionaryValue child_info; base::Value::Dict child_info;
adapter->GetDebugInfo(&child_info, include_children); adapter->GetDebugInfo(&child_info, include_children);
children->Append(std::move(child_info)); children.Append(std::move(child_info));
} }
} }

View File

@ -64,16 +64,15 @@ int CefScrollViewImpl::GetVerticalScrollbarWidth() {
return root_view()->GetScrollBarLayoutWidth(); return root_view()->GetScrollBarLayoutWidth();
} }
void CefScrollViewImpl::GetDebugInfo(base::DictionaryValue* info, void CefScrollViewImpl::GetDebugInfo(base::Value::Dict* info,
bool include_children) { bool include_children) {
ParentClass::GetDebugInfo(info, include_children); ParentClass::GetDebugInfo(info, include_children);
if (include_children) { if (include_children) {
views::View* view = root_view()->contents(); views::View* view = root_view()->contents();
CefViewAdapter* adapter = CefViewAdapter::GetFor(view); CefViewAdapter* adapter = CefViewAdapter::GetFor(view);
if (adapter) { if (adapter) {
std::unique_ptr<base::DictionaryValue> child_info( base::Value::Dict child_info;
new base::DictionaryValue()); adapter->GetDebugInfo(&child_info, include_children);
adapter->GetDebugInfo(child_info.get(), include_children);
info->Set("content_view", std::move(child_info)); info->Set("content_view", std::move(child_info));
} }
} }

View File

@ -37,8 +37,7 @@ class CefScrollViewImpl
// CefViewAdapter methods: // CefViewAdapter methods:
std::string GetDebugType() override { return "ScrollView"; } std::string GetDebugType() override { return "ScrollView"; }
void GetDebugInfo(base::DictionaryValue* info, void GetDebugInfo(base::Value::Dict* info, bool include_children) override;
bool include_children) override;
private: private:
// Create a new implementation object. // Create a new implementation object.

View File

@ -8,9 +8,7 @@
#include "include/views/cef_view.h" #include "include/views/cef_view.h"
namespace base { #include "base/values.h"
class DictionaryValue;
}
namespace views { namespace views {
class View; class View;
@ -48,8 +46,7 @@ class CefViewAdapter {
virtual std::string GetDebugType() = 0; virtual std::string GetDebugType() = 0;
// Override this method to provide debug info specific to the View type. // Override this method to provide debug info specific to the View type.
virtual void GetDebugInfo(base::DictionaryValue* info, virtual void GetDebugInfo(base::Value::Dict* info, bool include_children) = 0;
bool include_children) = 0;
protected: protected:
virtual ~CefViewAdapter() {} virtual ~CefViewAdapter() {}

View File

@ -343,19 +343,17 @@ CEF_VIEW_IMPL_T class CefViewImpl : public CefViewAdapter, public CefViewClass {
} }
root_view_ref_ = nullptr; root_view_ref_ = nullptr;
} }
void GetDebugInfo(base::DictionaryValue* info, void GetDebugInfo(base::Value::Dict* info, bool include_children) override {
bool include_children) override { info->Set("type", GetDebugType());
info->SetString("type", GetDebugType()); info->Set("id", root_view()->GetID());
info->SetInteger("id", root_view()->GetID());
// Use GetBounds() because some subclasses (like CefWindowImpl) override it. // Use GetBounds() because some subclasses (like CefWindowImpl) override it.
const CefRect& bounds = GetBounds(); const CefRect& bounds = GetBounds();
std::unique_ptr<base::DictionaryValue> bounds_value( base::Value::Dict bounds_value;
new base::DictionaryValue()); bounds_value.Set("x", bounds.x);
bounds_value->SetInteger("x", bounds.x); bounds_value.Set("y", bounds.y);
bounds_value->SetInteger("y", bounds.y); bounds_value.Set("width", bounds.width);
bounds_value->SetInteger("width", bounds.width); bounds_value.Set("height", bounds.height);
bounds_value->SetInteger("height", bounds.height);
info->Set("bounds", std::move(bounds_value)); info->Set("bounds", std::move(bounds_value));
} }
@ -454,15 +452,15 @@ CEF_VIEW_IMPL_T CefString CEF_VIEW_IMPL_D::GetTypeString() {
CEF_VIEW_IMPL_T CefString CEF_VIEW_IMPL_D::ToString(bool include_children) { CEF_VIEW_IMPL_T CefString CEF_VIEW_IMPL_D::ToString(bool include_children) {
CEF_REQUIRE_UIT_RETURN(CefString()); CEF_REQUIRE_UIT_RETURN(CefString());
std::unique_ptr<base::DictionaryValue> info(new base::DictionaryValue()); base::Value::Dict info;
if (IsValid()) { if (IsValid()) {
GetDebugInfo(info.get(), include_children); GetDebugInfo(&info, include_children);
} else { } else {
info->SetString("type", GetDebugType()); info.Set("type", GetDebugType());
} }
std::string json_string; std::string json_string;
base::JSONWriter::WriteWithOptions(*info, 0, &json_string); base::JSONWriter::WriteWithOptions(info, 0, &json_string);
return json_string; return json_string;
} }

View File

@ -315,11 +315,11 @@ CefRefPtr<CefOverlayController> CefWindowImpl::AddOverlayView(
return nullptr; return nullptr;
} }
void CefWindowImpl::GetDebugInfo(base::DictionaryValue* info, void CefWindowImpl::GetDebugInfo(base::Value::Dict* info,
bool include_children) { bool include_children) {
ParentClass::GetDebugInfo(info, include_children); ParentClass::GetDebugInfo(info, include_children);
if (root_view()) { if (root_view()) {
info->SetString("title", root_view()->title()); info->Set("title", root_view()->title());
} }
} }

View File

@ -113,8 +113,7 @@ class CefWindowImpl
// CefViewAdapter methods: // CefViewAdapter methods:
std::string GetDebugType() override { return "Window"; } std::string GetDebugType() override { return "Window"; }
void GetDebugInfo(base::DictionaryValue* info, void GetDebugInfo(base::Value::Dict* info, bool include_children) override;
bool include_children) override;
// ui::AcceleratorTarget methods: // ui::AcceleratorTarget methods:
bool AcceleratorPressed(const ui::Accelerator& accelerator) override; bool AcceleratorPressed(const ui::Accelerator& accelerator) override;

View File

@ -51,9 +51,7 @@ CefRefPtr<CefValue> CefParseJSON(const void* json,
base::StringPiece(static_cast<const char*>(json), json_size), base::StringPiece(static_cast<const char*>(json), json_size),
GetJSONReaderOptions(options)); GetJSONReaderOptions(options));
if (parse_result) { if (parse_result) {
return new CefValueImpl( return new CefValueImpl(std::move(parse_result.value()));
base::Value::ToUniquePtrValue(std::move(parse_result.value()))
.release());
} }
return nullptr; return nullptr;
} }
@ -68,8 +66,7 @@ CefRefPtr<CefValue> CefParseJSONAndReturnError(
auto result = base::JSONReader::ReadAndReturnValueWithError( auto result = base::JSONReader::ReadAndReturnValueWithError(
json, GetJSONReaderOptions(options)); json, GetJSONReaderOptions(options));
if (result.has_value()) { if (result.has_value()) {
return new CefValueImpl( return new CefValueImpl(std::move(*result));
base::Value::ToUniquePtrValue(std::move(*result)).release());
} }
error_msg_out = result.error().message; error_msg_out = result.error().message;

View File

@ -56,7 +56,7 @@ interface RenderFrame {
FrameDetached(); FrameDetached();
// Send a message to the render process. // Send a message to the render process.
SendMessage(string name, mojo_base.mojom.Value arguments); SendMessage(string name, mojo_base.mojom.ListValue arguments);
// Send a shared memory region to the render process. // Send a shared memory region to the render process.
SendSharedMemoryRegion(string name, mojo_base.mojom.ReadOnlySharedMemoryRegion region); SendSharedMemoryRegion(string name, mojo_base.mojom.ReadOnlySharedMemoryRegion region);
@ -88,7 +88,7 @@ interface RenderFrame {
// Interface for communicating with a frame in the browser process. // Interface for communicating with a frame in the browser process.
interface BrowserFrame { interface BrowserFrame {
// Send a message to the browser process. // Send a message to the browser process.
SendMessage(string name, mojo_base.mojom.Value arguments); SendMessage(string name, mojo_base.mojom.ListValue arguments);
// Send a shared memory region to the browser process. // Send a shared memory region to the browser process.
SendSharedMemoryRegion(string name, mojo_base.mojom.ReadOnlySharedMemoryRegion region); SendSharedMemoryRegion(string name, mojo_base.mojom.ReadOnlySharedMemoryRegion region);
@ -117,7 +117,7 @@ struct NewBrowserInfo {
bool is_popup; bool is_popup;
bool is_windowless; bool is_windowless;
bool is_guest_view; bool is_guest_view;
mojo_base.mojom.Value? extra_info; mojo_base.mojom.DictionaryValue? extra_info;
}; };
// Interface for communicating with browser management in the browser process. // Interface for communicating with browser management in the browser process.

View File

@ -9,7 +9,6 @@
#include "libcef/common/values_impl.h" #include "libcef/common/values_impl.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/memory/ptr_util.h"
// static // static
CefRefPtr<CefProcessMessage> CefProcessMessage::Create(const CefString& name) { CefRefPtr<CefProcessMessage> CefProcessMessage::Create(const CefString& name) {
@ -24,25 +23,22 @@ CefProcessMessageImpl::CefProcessMessageImpl(const CefString& name,
} }
CefProcessMessageImpl::CefProcessMessageImpl(const CefString& name, CefProcessMessageImpl::CefProcessMessageImpl(const CefString& name,
base::ListValue arguments, base::Value::List arguments,
bool read_only) bool read_only)
: name_(name) { : name_(name) {
DCHECK(!name_.empty()); DCHECK(!name_.empty());
auto new_obj = std::make_unique<base::ListValue>(); arguments_ = new CefListValueImpl(std::move(arguments), read_only);
*new_obj = std::move(arguments);
arguments_ =
new CefListValueImpl(new_obj.release(), /*will_delete=*/true, read_only);
} }
CefProcessMessageImpl::~CefProcessMessageImpl() = default; CefProcessMessageImpl::~CefProcessMessageImpl() = default;
base::ListValue CefProcessMessageImpl::TakeArgumentList() { base::Value::List CefProcessMessageImpl::TakeArgumentList() {
DCHECK(IsValid()); DCHECK(IsValid());
CefListValueImpl* value_impl = CefListValueImpl* value_impl =
static_cast<CefListValueImpl*>(arguments_.get()); static_cast<CefListValueImpl*>(arguments_.get());
auto value = base::WrapUnique(value_impl->CopyOrDetachValue(nullptr)); auto value = value_impl->CopyOrDetachValue(nullptr);
return std::move(*value); return std::move(value->GetList());
} }
bool CefProcessMessageImpl::IsValid() { bool CefProcessMessageImpl::IsValid() {

View File

@ -8,9 +8,7 @@
#include "include/cef_process_message.h" #include "include/cef_process_message.h"
namespace base { #include "base/values.h"
class ListValue;
}
// CefProcessMessage implementation. // CefProcessMessage implementation.
class CefProcessMessageImpl : public CefProcessMessage { class CefProcessMessageImpl : public CefProcessMessage {
@ -22,7 +20,7 @@ class CefProcessMessageImpl : public CefProcessMessage {
// Constructor for creating a new CefListValue that takes ownership of // Constructor for creating a new CefListValue that takes ownership of
// |arguments|. // |arguments|.
CefProcessMessageImpl(const CefString& name, CefProcessMessageImpl(const CefString& name,
base::ListValue arguments, base::Value::List arguments,
bool read_only); bool read_only);
CefProcessMessageImpl(const CefProcessMessageImpl&) = delete; CefProcessMessageImpl(const CefProcessMessageImpl&) = delete;
@ -34,7 +32,7 @@ class CefProcessMessageImpl : public CefProcessMessage {
// a copy if the argument list is already owned by something else. // a copy if the argument list is already owned by something else.
// TODO: Pass by reference instead of ownership if/when Mojo adds support // TODO: Pass by reference instead of ownership if/when Mojo adds support
// for that. // for that.
[[nodiscard]] base::ListValue TakeArgumentList(); [[nodiscard]] base::Value::List TakeArgumentList();
// CefProcessMessage methods. // CefProcessMessage methods.
bool IsValid() override; bool IsValid() override;

View File

@ -297,10 +297,10 @@ class CefValueBase : public CefType, public CefValueController::Object {
inline bool read_only() const { return read_only_; } inline bool read_only() const { return read_only_; }
// True if the underlying value has been detached. // True if the underlying value has been detached.
inline bool detached() { return !controller_.get(); } inline bool detached() const { return !controller_.get(); }
// Returns the controller. // Returns the controller.
inline CefValueController* controller() { return controller_.get(); } inline CefValueController* controller() const { return controller_.get(); }
// Deletes the underlying value. // Deletes the underlying value.
void Delete() { void Delete() {
@ -346,7 +346,7 @@ class CefValueBase : public CefType, public CefValueController::Object {
} }
// Verify that the value is attached. // Verify that the value is attached.
inline bool VerifyAttached() { inline bool VerifyAttached() const {
if (detached()) { if (detached()) {
// This object should not be accessed after being detached. // This object should not be accessed after being detached.
NOTREACHED() << "object accessed after being detached."; NOTREACHED() << "object accessed after being detached.";
@ -371,21 +371,27 @@ class CefValueBase : public CefType, public CefValueController::Object {
virtual void DeleteValue(ValueType* value) { delete value; } virtual void DeleteValue(ValueType* value) { delete value; }
// Returns a mutable reference to the value. // Returns a mutable reference to the value.
inline ValueType* mutable_value() { inline ValueType* mutable_value() const {
DCHECK(value_); DCHECK(value_);
DCHECK(!read_only_); DCHECK(!read_only_);
DCHECK(controller()->locked()); DCHECK(controller()->locked());
return value_; return value_;
} }
// Returns a const reference to the value. // Returns a const reference to the value.
inline const ValueType& const_value() { inline const ValueType& const_value() const {
DCHECK(value_); DCHECK(value_);
DCHECK(controller()->locked()); DCHECK(controller()->locked());
return *value_; return *value_;
} }
// Returns an mutable reference to the value without checking read-only state.
inline ValueType* mutable_value_unchecked() const {
return const_cast<ValueType*>(&const_value());
}
// Verify that the value can be accessed. // Verify that the value can be accessed.
inline bool VerifyAccess(bool modify) { inline bool VerifyAccess(bool modify) const {
// The controller must already be locked. // The controller must already be locked.
DCHECK(controller()->locked()); DCHECK(controller()->locked());

View File

@ -36,7 +36,8 @@ void RemoveEmptyValueDicts(base::Value::Dict& dict) {
// static // static
CefRefPtr<CefValue> CefValue::Create() { CefRefPtr<CefValue> CefValue::Create() {
return new CefValueImpl(new base::Value()); // Start with VTYPE_NULL instead of VTYPE_INVALID for backwards compatibility.
return new CefValueImpl(base::Value());
} }
// static // static
@ -53,25 +54,22 @@ CefRefPtr<CefValue> CefValueImpl::GetOrCreateRefOrCopy(
} }
if (value->is_dict()) { if (value->is_dict()) {
base::DictionaryValue* dict_value =
static_cast<base::DictionaryValue*>(value);
return new CefValueImpl(CefDictionaryValueImpl::GetOrCreateRef( return new CefValueImpl(CefDictionaryValueImpl::GetOrCreateRef(
dict_value, parent_value, read_only, controller)); value, parent_value, read_only, controller));
} }
if (value->is_list()) { if (value->is_list()) {
base::ListValue* list_value = static_cast<base::ListValue*>(value);
return new CefValueImpl(CefListValueImpl::GetOrCreateRef( return new CefValueImpl(CefListValueImpl::GetOrCreateRef(
list_value, parent_value, read_only, controller)); value, parent_value, read_only, controller));
} }
return new CefValueImpl(new base::Value(value->Clone())); return new CefValueImpl(value->Clone());
} }
CefValueImpl::CefValueImpl() {} CefValueImpl::CefValueImpl() {}
CefValueImpl::CefValueImpl(base::Value* value) { CefValueImpl::CefValueImpl(base::Value value) {
SetValue(value); SetValue(std::move(value));
} }
CefValueImpl::CefValueImpl(CefRefPtr<CefBinaryValue> value) CefValueImpl::CefValueImpl(CefRefPtr<CefBinaryValue> value)
@ -85,12 +83,31 @@ CefValueImpl::CefValueImpl(CefRefPtr<CefListValue> value)
CefValueImpl::~CefValueImpl() {} CefValueImpl::~CefValueImpl() {}
void CefValueImpl::SetValue(base::Value* value) { void CefValueImpl::SetValue(base::Value value) {
base::AutoLock lock_scope(lock_); base::AutoLock lock_scope(lock_);
SetValueInternal(value); SetValueInternal(absl::make_optional(std::move(value)));
} }
base::Value* CefValueImpl::CopyOrDetachValue( base::Value CefValueImpl::CopyValue() {
base::AutoLock lock_scope(lock_);
if (binary_value_) {
return static_cast<CefBinaryValueImpl*>(binary_value_.get())->CopyValue();
}
if (dictionary_value_) {
return static_cast<CefDictionaryValueImpl*>(dictionary_value_.get())
->CopyValue();
}
if (list_value_) {
return static_cast<CefListValueImpl*>(list_value_.get())->CopyValue();
}
return value_->Clone();
}
std::unique_ptr<base::Value> CefValueImpl::CopyOrDetachValue(
CefValueController* new_controller) { CefValueController* new_controller) {
base::AutoLock lock_scope(lock_); base::AutoLock lock_scope(lock_);
@ -109,7 +126,7 @@ base::Value* CefValueImpl::CopyOrDetachValue(
->CopyOrDetachValue(new_controller); ->CopyOrDetachValue(new_controller);
} }
return new base::Value(value_->Clone()); return std::make_unique<base::Value>(value_->Clone());
} }
void CefValueImpl::SwapValue(base::Value* new_value, void CefValueImpl::SwapValue(base::Value* new_value,
@ -122,12 +139,10 @@ void CefValueImpl::SwapValue(base::Value* new_value,
new_value, new_parent_value, new_controller); new_value, new_parent_value, new_controller);
} else if (dictionary_value_) { } else if (dictionary_value_) {
dictionary_value_ = CefDictionaryValueImpl::GetOrCreateRef( dictionary_value_ = CefDictionaryValueImpl::GetOrCreateRef(
static_cast<base::DictionaryValue*>(new_value), new_parent_value, false, new_value, new_parent_value, false, new_controller);
new_controller);
} else if (list_value_) { } else if (list_value_) {
list_value_ = CefListValueImpl::GetOrCreateRef( list_value_ = CefListValueImpl::GetOrCreateRef(new_value, new_parent_value,
static_cast<base::ListValue*>(new_value), new_parent_value, false, false, new_controller);
new_controller);
} }
} }
@ -249,7 +264,7 @@ CefRefPtr<CefValue> CefValueImpl::Copy() {
return new CefValueImpl(list_value_->Copy()); return new CefValueImpl(list_value_->Copy());
} }
if (value_) { if (value_) {
return new CefValueImpl(new base::Value(value_->Clone())); return new CefValueImpl(value_->Clone());
} }
return new CefValueImpl(); return new CefValueImpl();
@ -345,52 +360,52 @@ CefRefPtr<CefListValue> CefValueImpl::GetList() {
} }
bool CefValueImpl::SetNull() { bool CefValueImpl::SetNull() {
SetValue(new base::Value()); SetValue(base::Value());
return true; return true;
} }
bool CefValueImpl::SetBool(bool value) { bool CefValueImpl::SetBool(bool value) {
SetValue(new base::Value(value)); SetValue(base::Value(value));
return true; return true;
} }
bool CefValueImpl::SetInt(int value) { bool CefValueImpl::SetInt(int value) {
SetValue(new base::Value(value)); SetValue(base::Value(value));
return true; return true;
} }
bool CefValueImpl::SetDouble(double value) { bool CefValueImpl::SetDouble(double value) {
SetValue(new base::Value(value)); SetValue(base::Value(value));
return true; return true;
} }
bool CefValueImpl::SetString(const CefString& value) { bool CefValueImpl::SetString(const CefString& value) {
SetValue(new base::Value(value.ToString())); SetValue(base::Value(value.ToString()));
return true; return true;
} }
bool CefValueImpl::SetBinary(CefRefPtr<CefBinaryValue> value) { bool CefValueImpl::SetBinary(CefRefPtr<CefBinaryValue> value) {
base::AutoLock lock_scope(lock_); base::AutoLock lock_scope(lock_);
SetValueInternal(nullptr); SetValueInternal(absl::nullopt);
binary_value_ = value; binary_value_ = value;
return true; return true;
} }
bool CefValueImpl::SetDictionary(CefRefPtr<CefDictionaryValue> value) { bool CefValueImpl::SetDictionary(CefRefPtr<CefDictionaryValue> value) {
base::AutoLock lock_scope(lock_); base::AutoLock lock_scope(lock_);
SetValueInternal(nullptr); SetValueInternal(absl::nullopt);
dictionary_value_ = value; dictionary_value_ = value;
return true; return true;
} }
bool CefValueImpl::SetList(CefRefPtr<CefListValue> value) { bool CefValueImpl::SetList(CefRefPtr<CefListValue> value) {
base::AutoLock lock_scope(lock_); base::AutoLock lock_scope(lock_);
SetValueInternal(nullptr); SetValueInternal(absl::nullopt);
list_value_ = value; list_value_ = value;
return true; return true;
} }
void CefValueImpl::SetValueInternal(base::Value* value) { void CefValueImpl::SetValueInternal(absl::optional<base::Value> value) {
lock_.AssertAcquired(); lock_.AssertAcquired();
value_.reset(nullptr); value_.reset(nullptr);
@ -399,20 +414,21 @@ void CefValueImpl::SetValueInternal(base::Value* value) {
list_value_ = nullptr; list_value_ = nullptr;
if (value) { if (value) {
switch (value->type()) { switch ((*value).type()) {
case base::Value::Type::BINARY: case base::Value::Type::BINARY:
binary_value_ = new CefBinaryValueImpl(value, true); binary_value_ = new CefBinaryValueImpl(std::move(*value));
return; break;
case base::Value::Type::DICTIONARY: case base::Value::Type::DICTIONARY:
dictionary_value_ = new CefDictionaryValueImpl( dictionary_value_ =
static_cast<base::DictionaryValue*>(value), true, false); new CefDictionaryValueImpl(std::move(*value), /*read_only=*/false);
return; break;
case base::Value::Type::LIST: case base::Value::Type::LIST:
list_value_ = new CefListValueImpl(static_cast<base::ListValue*>(value), list_value_ =
true, false); new CefListValueImpl(std::move(*value), /*read_only=*/false);
return; break;
default: default:
value_.reset(value); value_ = std::make_unique<base::Value>(std::move(*value));
break;
} }
} }
} }
@ -499,41 +515,39 @@ CefRefPtr<CefBinaryValue> CefBinaryValueImpl::GetOrCreateRef(
CefBinaryValueImpl::kReference, controller); CefBinaryValueImpl::kReference, controller);
} }
CefBinaryValueImpl::CefBinaryValueImpl(base::Value value)
: CefBinaryValueImpl(new base::Value(std::move(value)),
/*will_delete=*/true) {}
CefBinaryValueImpl::CefBinaryValueImpl(base::Value* value, bool will_delete) CefBinaryValueImpl::CefBinaryValueImpl(base::Value* value, bool will_delete)
: CefValueBase<CefBinaryValue, base::Value>( : CefBinaryValueImpl(value,
value,
nullptr, nullptr,
will_delete ? kOwnerWillDelete : kOwnerNoDelete, will_delete ? kOwnerWillDelete : kOwnerNoDelete,
true,
nullptr) {} nullptr) {}
CefBinaryValueImpl::CefBinaryValueImpl(char* data, size_t data_size) CefBinaryValueImpl::CefBinaryValueImpl(char* data, size_t data_size)
: CefValueBase<CefBinaryValue, base::Value>( : CefBinaryValueImpl(
new base::Value(std::vector<char>(data, data + data_size)), new base::Value(std::vector<char>(data, data + data_size)),
nullptr, nullptr,
kOwnerWillDelete, kOwnerWillDelete,
true,
nullptr) {} nullptr) {}
base::Value* CefBinaryValueImpl::CopyValue() { base::Value CefBinaryValueImpl::CopyValue() {
CEF_VALUE_VERIFY_RETURN(false, nullptr); CEF_VALUE_VERIFY_RETURN(false, base::Value());
return new base::Value(const_value().Clone()); return const_value().Clone();
} }
base::Value* CefBinaryValueImpl::CopyOrDetachValue( std::unique_ptr<base::Value> CefBinaryValueImpl::CopyOrDetachValue(
CefValueController* new_controller) { CefValueController* new_controller) {
base::Value* new_value;
if (!will_delete()) { if (!will_delete()) {
// Copy the value. // Copy the value.
new_value = CopyValue(); return std::make_unique<base::Value>(CopyValue());
} else {
// Take ownership of the value.
new_value = Detach(new_controller);
} }
DCHECK(new_value); // Take ownership of the value.
return new_value; auto value = base::WrapUnique(Detach(new_controller));
DCHECK(value.get());
return value;
} }
bool CefBinaryValueImpl::IsSameValue(const base::Value* that) { bool CefBinaryValueImpl::IsSameValue(const base::Value* that) {
@ -546,12 +560,12 @@ bool CefBinaryValueImpl::IsEqualValue(const base::Value* that) {
return const_value() == *that; return const_value() == *that;
} }
base::Value* CefBinaryValueImpl::GetValueUnsafe() { base::Value* CefBinaryValueImpl::GetValueUnsafe() const {
if (!VerifyAttached()) { if (!VerifyAttached()) {
return nullptr; return nullptr;
} }
controller()->AssertLockAcquired(); controller()->AssertLockAcquired();
return const_cast<base::Value*>(&const_value()); return mutable_value_unchecked();
} }
bool CefBinaryValueImpl::IsValid() { bool CefBinaryValueImpl::IsValid() {
@ -590,8 +604,7 @@ bool CefBinaryValueImpl::IsEqual(CefRefPtr<CefBinaryValue> that) {
CefRefPtr<CefBinaryValue> CefBinaryValueImpl::Copy() { CefRefPtr<CefBinaryValue> CefBinaryValueImpl::Copy() {
CEF_VALUE_VERIFY_RETURN(false, nullptr); CEF_VALUE_VERIFY_RETURN(false, nullptr);
return new CefBinaryValueImpl(new base::Value(const_value().Clone()), nullptr, return new CefBinaryValueImpl(const_value().Clone());
CefBinaryValueImpl::kOwnerWillDelete, nullptr);
} }
size_t CefBinaryValueImpl::GetSize() { size_t CefBinaryValueImpl::GetSize() {
@ -629,19 +642,20 @@ CefBinaryValueImpl::CefBinaryValueImpl(base::Value* value,
: CefValueBase<CefBinaryValue, base::Value>(value, : CefValueBase<CefBinaryValue, base::Value>(value,
parent_value, parent_value,
value_mode, value_mode,
true, /*read_only=*/true,
controller) {} controller) {}
// CefDictionaryValueImpl implementation. // CefDictionaryValueImpl implementation.
// static // static
CefRefPtr<CefDictionaryValue> CefDictionaryValue::Create() { CefRefPtr<CefDictionaryValue> CefDictionaryValue::Create() {
return new CefDictionaryValueImpl(new base::DictionaryValue(), true, false); return new CefDictionaryValueImpl(base::Value(base::Value::Type::DICT),
/*read_only=*/false);
} }
// static // static
CefRefPtr<CefDictionaryValue> CefDictionaryValueImpl::GetOrCreateRef( CefRefPtr<CefDictionaryValue> CefDictionaryValueImpl::GetOrCreateRef(
base::DictionaryValue* value, base::Value* value,
void* parent_value, void* parent_value,
bool read_only, bool read_only,
CefValueController* controller) { CefValueController* controller) {
@ -655,54 +669,59 @@ CefRefPtr<CefDictionaryValue> CefDictionaryValueImpl::GetOrCreateRef(
read_only, controller); read_only, controller);
} }
CefDictionaryValueImpl::CefDictionaryValueImpl(base::DictionaryValue* value, CefDictionaryValueImpl::CefDictionaryValueImpl(base::Value value,
bool read_only)
: CefDictionaryValueImpl(new base::Value(std::move(value)),
/*will_delete=*/true,
read_only) {}
CefDictionaryValueImpl::CefDictionaryValueImpl(base::Value::Dict value,
bool read_only)
: CefDictionaryValueImpl(base::Value(std::move(value)), read_only) {}
CefDictionaryValueImpl::CefDictionaryValueImpl(base::Value* value,
bool will_delete, bool will_delete,
bool read_only) bool read_only)
: CefValueBase<CefDictionaryValue, base::DictionaryValue>( : CefDictionaryValueImpl(value,
value,
nullptr, nullptr,
will_delete ? kOwnerWillDelete : kOwnerNoDelete, will_delete ? kOwnerWillDelete : kOwnerNoDelete,
read_only, read_only,
nullptr) {} nullptr) {}
base::DictionaryValue* CefDictionaryValueImpl::CopyValue() { base::Value CefDictionaryValueImpl::CopyValue() {
CEF_VALUE_VERIFY_RETURN(false, nullptr); CEF_VALUE_VERIFY_RETURN(false, base::Value());
return static_cast<base::DictionaryValue*>( return const_value().Clone();
new base::Value(const_value().Clone()));
} }
base::DictionaryValue* CefDictionaryValueImpl::CopyOrDetachValue( std::unique_ptr<base::Value> CefDictionaryValueImpl::CopyOrDetachValue(
CefValueController* new_controller) { CefValueController* new_controller) {
base::DictionaryValue* new_value;
if (!will_delete()) { if (!will_delete()) {
// Copy the value. // Copy the value.
new_value = CopyValue(); return std::make_unique<base::Value>(CopyValue());
} else { }
// Take ownership of the value. // Take ownership of the value.
new_value = Detach(new_controller); auto value = base::WrapUnique(Detach(new_controller));
DCHECK(value.get());
return value;
} }
DCHECK(new_value); bool CefDictionaryValueImpl::IsSameValue(const base::Value* that) {
return new_value;
}
bool CefDictionaryValueImpl::IsSameValue(const base::DictionaryValue* that) {
CEF_VALUE_VERIFY_RETURN(false, false); CEF_VALUE_VERIFY_RETURN(false, false);
return (&const_value() == that); return (&const_value() == that);
} }
bool CefDictionaryValueImpl::IsEqualValue(const base::DictionaryValue* that) { bool CefDictionaryValueImpl::IsEqualValue(const base::Value* that) {
CEF_VALUE_VERIFY_RETURN(false, false); CEF_VALUE_VERIFY_RETURN(false, false);
return const_value() == *that; return const_value() == *that;
} }
base::DictionaryValue* CefDictionaryValueImpl::GetValueUnsafe() { base::Value* CefDictionaryValueImpl::GetValueUnsafe() const {
if (!VerifyAttached()) { if (!VerifyAttached()) {
return nullptr; return nullptr;
} }
controller()->AssertLockAcquired(); controller()->AssertLockAcquired();
return const_cast<base::DictionaryValue*>(&const_value()); return mutable_value_unchecked();
} }
bool CefDictionaryValueImpl::IsValid() { bool CefDictionaryValueImpl::IsValid() {
@ -747,19 +766,17 @@ CefRefPtr<CefDictionaryValue> CefDictionaryValueImpl::Copy(
bool exclude_empty_children) { bool exclude_empty_children) {
CEF_VALUE_VERIFY_RETURN(false, nullptr); CEF_VALUE_VERIFY_RETURN(false, nullptr);
base::DictionaryValue* value = static_cast<base::DictionaryValue*>( auto value = const_value().Clone();
new base::Value(const_value().Clone()));
if (exclude_empty_children) { if (exclude_empty_children) {
RemoveEmptyValueDicts(value->GetDict()); RemoveEmptyValueDicts(value.GetDict());
} }
return new CefDictionaryValueImpl( return new CefDictionaryValueImpl(std::move(value), /*read_only=*/false);
value, nullptr, CefDictionaryValueImpl::kOwnerWillDelete, false, nullptr);
} }
size_t CefDictionaryValueImpl::GetSize() { size_t CefDictionaryValueImpl::GetSize() {
CEF_VALUE_VERIFY_RETURN(false, 0); CEF_VALUE_VERIFY_RETURN(false, 0);
return const_value().DictSize(); return const_value().GetDict().size();
} }
bool CefDictionaryValueImpl::Clear() { bool CefDictionaryValueImpl::Clear() {
@ -774,7 +791,7 @@ bool CefDictionaryValueImpl::Clear() {
bool CefDictionaryValueImpl::HasKey(const CefString& key) { bool CefDictionaryValueImpl::HasKey(const CefString& key) {
CEF_VALUE_VERIFY_RETURN(false, 0); CEF_VALUE_VERIFY_RETURN(false, 0);
return const_value().FindKey(base::StringPiece(key)); return const_value().GetDict().contains(base::StringPiece(key));
} }
bool CefDictionaryValueImpl::GetKeys(KeyList& keys) { bool CefDictionaryValueImpl::GetKeys(KeyList& keys) {
@ -795,7 +812,8 @@ bool CefDictionaryValueImpl::Remove(const CefString& key) {
CefValueType CefDictionaryValueImpl::GetType(const CefString& key) { CefValueType CefDictionaryValueImpl::GetType(const CefString& key) {
CEF_VALUE_VERIFY_RETURN(false, VTYPE_INVALID); CEF_VALUE_VERIFY_RETURN(false, VTYPE_INVALID);
const base::Value* value = const_value().FindKey(base::StringPiece(key)); const base::Value* value =
const_value().GetDict().Find(base::StringPiece(key));
if (value) { if (value) {
switch (value->type()) { switch (value->type()) {
case base::Value::Type::NONE: case base::Value::Type::NONE:
@ -823,12 +841,12 @@ CefValueType CefDictionaryValueImpl::GetType(const CefString& key) {
CefRefPtr<CefValue> CefDictionaryValueImpl::GetValue(const CefString& key) { CefRefPtr<CefValue> CefDictionaryValueImpl::GetValue(const CefString& key) {
CEF_VALUE_VERIFY_RETURN(false, nullptr); CEF_VALUE_VERIFY_RETURN(false, nullptr);
const base::Value* value = const_value().FindKey(base::StringPiece(key)); const base::Value* value =
const_value().GetDict().Find(base::StringPiece(key));
if (value) { if (value) {
return CefValueImpl::GetOrCreateRefOrCopy( return CefValueImpl::GetOrCreateRefOrCopy(const_cast<base::Value*>(value),
const_cast<base::Value*>(value), mutable_value_unchecked(),
const_cast<base::DictionaryValue*>(&const_value()), read_only(), read_only(), controller());
controller());
} }
return nullptr; return nullptr;
@ -839,7 +857,8 @@ bool CefDictionaryValueImpl::GetBool(const CefString& key) {
bool ret_value = false; bool ret_value = false;
const base::Value* value = const_value().FindKey(base::StringPiece(key)); const base::Value* value =
const_value().GetDict().Find(base::StringPiece(key));
if (value && value->is_bool()) { if (value && value->is_bool()) {
ret_value = value->GetBool(); ret_value = value->GetBool();
} }
@ -852,7 +871,8 @@ int CefDictionaryValueImpl::GetInt(const CefString& key) {
int ret_value = 0; int ret_value = 0;
const base::Value* value = const_value().FindKey(base::StringPiece(key)); const base::Value* value =
const_value().GetDict().Find(base::StringPiece(key));
if (value && value->is_int()) { if (value && value->is_int()) {
ret_value = value->GetInt(); ret_value = value->GetInt();
} }
@ -865,7 +885,8 @@ double CefDictionaryValueImpl::GetDouble(const CefString& key) {
double ret_value = 0; double ret_value = 0;
const base::Value* value = const_value().FindKey(base::StringPiece(key)); const base::Value* value =
const_value().GetDict().Find(base::StringPiece(key));
if (value && value->is_double()) { if (value && value->is_double()) {
ret_value = value->GetDouble(); ret_value = value->GetDouble();
} }
@ -878,7 +899,8 @@ CefString CefDictionaryValueImpl::GetString(const CefString& key) {
std::string ret_value; std::string ret_value;
const base::Value* value = const_value().FindKey(base::StringPiece(key)); const base::Value* value =
const_value().GetDict().Find(base::StringPiece(key));
if (value && value->is_string()) { if (value && value->is_string()) {
ret_value = value->GetString(); ret_value = value->GetString();
} }
@ -890,12 +912,12 @@ CefRefPtr<CefBinaryValue> CefDictionaryValueImpl::GetBinary(
const CefString& key) { const CefString& key) {
CEF_VALUE_VERIFY_RETURN(false, nullptr); CEF_VALUE_VERIFY_RETURN(false, nullptr);
const base::Value* value = const_value().FindKey(base::StringPiece(key)); const base::Value* value =
const_value().GetDict().Find(base::StringPiece(key));
if (value && value->is_blob()) { if (value && value->is_blob()) {
base::Value* binary_value = const_cast<base::Value*>(value); base::Value* binary_value = const_cast<base::Value*>(value);
return CefBinaryValueImpl::GetOrCreateRef( return CefBinaryValueImpl::GetOrCreateRef(
binary_value, const_cast<base::DictionaryValue*>(&const_value()), binary_value, mutable_value_unchecked(), controller());
controller());
} }
return nullptr; return nullptr;
@ -905,13 +927,12 @@ CefRefPtr<CefDictionaryValue> CefDictionaryValueImpl::GetDictionary(
const CefString& key) { const CefString& key) {
CEF_VALUE_VERIFY_RETURN(false, nullptr); CEF_VALUE_VERIFY_RETURN(false, nullptr);
const base::Value* value = const_value().FindKey(base::StringPiece(key)); const base::Value* value =
const_value().GetDict().Find(base::StringPiece(key));
if (value && value->is_dict()) { if (value && value->is_dict()) {
base::DictionaryValue* dict_value = base::Value* dict_value = const_cast<base::Value*>(value);
static_cast<base::DictionaryValue*>(const_cast<base::Value*>(value));
return CefDictionaryValueImpl::GetOrCreateRef( return CefDictionaryValueImpl::GetOrCreateRef(
dict_value, const_cast<base::DictionaryValue*>(&const_value()), dict_value, mutable_value_unchecked(), read_only(), controller());
read_only(), controller());
} }
return nullptr; return nullptr;
@ -920,13 +941,12 @@ CefRefPtr<CefDictionaryValue> CefDictionaryValueImpl::GetDictionary(
CefRefPtr<CefListValue> CefDictionaryValueImpl::GetList(const CefString& key) { CefRefPtr<CefListValue> CefDictionaryValueImpl::GetList(const CefString& key) {
CEF_VALUE_VERIFY_RETURN(false, nullptr); CEF_VALUE_VERIFY_RETURN(false, nullptr);
const base::Value* value = const_value().FindKey(base::StringPiece(key)); const base::Value* value =
const_value().GetDict().Find(base::StringPiece(key));
if (value && value->is_list()) { if (value && value->is_list()) {
base::ListValue* list_value = base::Value* list_value = const_cast<base::Value*>(value);
static_cast<base::ListValue*>(const_cast<base::Value*>(value));
return CefListValueImpl::GetOrCreateRef( return CefListValueImpl::GetOrCreateRef(
list_value, const_cast<base::DictionaryValue*>(&const_value()), list_value, mutable_value_unchecked(), read_only(), controller());
read_only(), controller());
} }
return nullptr; return nullptr;
@ -939,40 +959,40 @@ bool CefDictionaryValueImpl::SetValue(const CefString& key,
CefValueImpl* impl = static_cast<CefValueImpl*>(value.get()); CefValueImpl* impl = static_cast<CefValueImpl*>(value.get());
DCHECK(impl); DCHECK(impl);
base::Value* new_value = impl->CopyOrDetachValue(controller()); base::Value* actual_value =
base::Value* actual_value = SetInternal(key, new_value); SetInternal(key, impl->CopyOrDetachValue(controller()));
impl->SwapValue(actual_value, mutable_value(), controller()); impl->SwapValue(actual_value, mutable_value(), controller());
return true; return true;
} }
bool CefDictionaryValueImpl::SetNull(const CefString& key) { bool CefDictionaryValueImpl::SetNull(const CefString& key) {
CEF_VALUE_VERIFY_RETURN(true, false); CEF_VALUE_VERIFY_RETURN(true, false);
SetInternal(key, new base::Value()); SetInternal(key, std::make_unique<base::Value>());
return true; return true;
} }
bool CefDictionaryValueImpl::SetBool(const CefString& key, bool value) { bool CefDictionaryValueImpl::SetBool(const CefString& key, bool value) {
CEF_VALUE_VERIFY_RETURN(true, false); CEF_VALUE_VERIFY_RETURN(true, false);
SetInternal(key, new base::Value(value)); SetInternal(key, std::make_unique<base::Value>(value));
return true; return true;
} }
bool CefDictionaryValueImpl::SetInt(const CefString& key, int value) { bool CefDictionaryValueImpl::SetInt(const CefString& key, int value) {
CEF_VALUE_VERIFY_RETURN(true, false); CEF_VALUE_VERIFY_RETURN(true, false);
SetInternal(key, new base::Value(value)); SetInternal(key, std::make_unique<base::Value>(value));
return true; return true;
} }
bool CefDictionaryValueImpl::SetDouble(const CefString& key, double value) { bool CefDictionaryValueImpl::SetDouble(const CefString& key, double value) {
CEF_VALUE_VERIFY_RETURN(true, false); CEF_VALUE_VERIFY_RETURN(true, false);
SetInternal(key, new base::Value(value)); SetInternal(key, std::make_unique<base::Value>(value));
return true; return true;
} }
bool CefDictionaryValueImpl::SetString(const CefString& key, bool CefDictionaryValueImpl::SetString(const CefString& key,
const CefString& value) { const CefString& value) {
CEF_VALUE_VERIFY_RETURN(true, false); CEF_VALUE_VERIFY_RETURN(true, false);
SetInternal(key, new base::Value(value.ToString())); SetInternal(key, std::make_unique<base::Value>(value.ToString()));
return true; return true;
} }
@ -1018,14 +1038,14 @@ bool CefDictionaryValueImpl::RemoveInternal(const CefString& key) {
// retrieve the actual Value pointer as it current exists first, for later // retrieve the actual Value pointer as it current exists first, for later
// comparison purposes. // comparison purposes.
const base::Value* actual_value = const base::Value* actual_value =
const_value().FindKey(base::StringPiece(key)); const_value().GetDict().Find(base::StringPiece(key));
if (!actual_value) { if (!actual_value) {
return false; return false;
} }
// |actual_value| is no longer valid after this call. // |actual_value| is no longer valid after this call.
absl::optional<base::Value> out_value = absl::optional<base::Value> out_value =
mutable_value()->ExtractKey(base::StringPiece(key)); mutable_value()->GetDict().Extract(base::StringPiece(key));
if (!out_value.has_value()) { if (!out_value.has_value()) {
return false; return false;
} }
@ -1041,10 +1061,10 @@ bool CefDictionaryValueImpl::RemoveInternal(const CefString& key) {
return true; return true;
} }
base::Value* CefDictionaryValueImpl::SetInternal(const CefString& key, base::Value* CefDictionaryValueImpl::SetInternal(
base::Value* value) { const CefString& key,
std::unique_ptr<base::Value> value) {
DCHECK(value); DCHECK(value);
std::unique_ptr<base::Value> valueObj(value);
RemoveInternal(key); RemoveInternal(key);
@ -1057,32 +1077,35 @@ base::Value* CefDictionaryValueImpl::SetInternal(const CefString& key,
// |value| will be deleted when this method returns. Update the controller to // |value| will be deleted when this method returns. Update the controller to
// reference |actual_value| instead. // reference |actual_value| instead.
controller()->Swap(value, actual_value); controller()->Swap(value.get(), actual_value);
return actual_value; return actual_value;
} }
CefDictionaryValueImpl::CefDictionaryValueImpl(base::DictionaryValue* value, CefDictionaryValueImpl::CefDictionaryValueImpl(base::Value* value,
void* parent_value, void* parent_value,
ValueMode value_mode, ValueMode value_mode,
bool read_only, bool read_only,
CefValueController* controller) CefValueController* controller)
: CefValueBase<CefDictionaryValue, base::DictionaryValue>(value, : CefValueBase<CefDictionaryValue, base::Value>(value,
parent_value, parent_value,
value_mode, value_mode,
read_only, read_only,
controller) {} controller) {
DCHECK(value->is_dict());
}
// CefListValueImpl implementation. // CefListValueImpl implementation.
// static // static
CefRefPtr<CefListValue> CefListValue::Create() { CefRefPtr<CefListValue> CefListValue::Create() {
return new CefListValueImpl(new base::ListValue(), true, false); return new CefListValueImpl(base::Value(base::Value::Type::LIST),
/*read_only=*/false);
} }
// static // static
CefRefPtr<CefListValue> CefListValueImpl::GetOrCreateRef( CefRefPtr<CefListValue> CefListValueImpl::GetOrCreateRef(
base::ListValue* value, base::Value* value,
void* parent_value, void* parent_value,
bool read_only, bool read_only,
CefValueController* controller) { CefValueController* controller) {
@ -1095,53 +1118,57 @@ CefRefPtr<CefListValue> CefListValueImpl::GetOrCreateRef(
read_only, controller); read_only, controller);
} }
CefListValueImpl::CefListValueImpl(base::ListValue* value, CefListValueImpl::CefListValueImpl(base::Value value, bool read_only)
: CefListValueImpl(new base::Value(std::move(value)),
/*will_delete=*/true,
read_only) {}
CefListValueImpl::CefListValueImpl(base::Value::List value, bool read_only)
: CefListValueImpl(base::Value(std::move(value)), read_only) {}
CefListValueImpl::CefListValueImpl(base::Value* value,
bool will_delete, bool will_delete,
bool read_only) bool read_only)
: CefValueBase<CefListValue, base::ListValue>( : CefListValueImpl(value,
value,
nullptr, nullptr,
will_delete ? kOwnerWillDelete : kOwnerNoDelete, will_delete ? kOwnerWillDelete : kOwnerNoDelete,
read_only, read_only,
nullptr) {} nullptr) {}
base::ListValue* CefListValueImpl::CopyValue() { base::Value CefListValueImpl::CopyValue() {
CEF_VALUE_VERIFY_RETURN(false, nullptr); CEF_VALUE_VERIFY_RETURN(false, base::Value());
return static_cast<base::ListValue*>(new base::Value(const_value().Clone())); return const_value().Clone();
} }
base::ListValue* CefListValueImpl::CopyOrDetachValue( std::unique_ptr<base::Value> CefListValueImpl::CopyOrDetachValue(
CefValueController* new_controller) { CefValueController* new_controller) {
base::ListValue* new_value;
if (!will_delete()) { if (!will_delete()) {
// Copy the value. // Copy the value.
new_value = CopyValue(); return std::make_unique<base::Value>(CopyValue());
} else { }
// Take ownership of the value. // Take ownership of the value.
new_value = Detach(new_controller); auto value = base::WrapUnique(Detach(new_controller));
DCHECK(value.get());
return value;
} }
DCHECK(new_value); bool CefListValueImpl::IsSameValue(const base::Value* that) {
return new_value;
}
bool CefListValueImpl::IsSameValue(const base::ListValue* that) {
CEF_VALUE_VERIFY_RETURN(false, false); CEF_VALUE_VERIFY_RETURN(false, false);
return (&const_value() == that); return (&const_value() == that);
} }
bool CefListValueImpl::IsEqualValue(const base::ListValue* that) { bool CefListValueImpl::IsEqualValue(const base::Value* that) {
CEF_VALUE_VERIFY_RETURN(false, false); CEF_VALUE_VERIFY_RETURN(false, false);
return const_value() == *that; return const_value() == *that;
} }
base::ListValue* CefListValueImpl::GetValueUnsafe() { base::Value* CefListValueImpl::GetValueUnsafe() const {
if (!VerifyAttached()) { if (!VerifyAttached()) {
return nullptr; return nullptr;
} }
controller()->AssertLockAcquired(); controller()->AssertLockAcquired();
return const_cast<base::ListValue*>(&const_value()); return mutable_value_unchecked();
} }
bool CefListValueImpl::IsValid() { bool CefListValueImpl::IsValid() {
@ -1185,9 +1212,7 @@ bool CefListValueImpl::IsEqual(CefRefPtr<CefListValue> that) {
CefRefPtr<CefListValue> CefListValueImpl::Copy() { CefRefPtr<CefListValue> CefListValueImpl::Copy() {
CEF_VALUE_VERIFY_RETURN(false, nullptr); CEF_VALUE_VERIFY_RETURN(false, nullptr);
return new CefListValueImpl( return new CefListValueImpl(const_value().Clone(), /*read_only=*/false);
static_cast<base::ListValue*>(new base::Value(const_value().Clone())),
nullptr, CefListValueImpl::kOwnerWillDelete, false, nullptr);
} }
bool CefListValueImpl::SetSize(size_t size) { bool CefListValueImpl::SetSize(size_t size) {
@ -1205,7 +1230,7 @@ bool CefListValueImpl::SetSize(size_t size) {
// for background. // for background.
auto& list = mutable_value()->GetList(); auto& list = mutable_value()->GetList();
while (list.size() < size) { while (list.size() < size) {
mutable_value()->Append(base::Value()); list.Append(base::Value());
} }
} }
return true; return true;
@ -1266,10 +1291,9 @@ CefRefPtr<CefValue> CefListValueImpl::GetValue(size_t index) {
const auto& list = const_value().GetList(); const auto& list = const_value().GetList();
if (index < list.size()) { if (index < list.size()) {
const base::Value& value = list[index]; const base::Value& value = list[index];
return CefValueImpl::GetOrCreateRefOrCopy( return CefValueImpl::GetOrCreateRefOrCopy(const_cast<base::Value*>(&value),
const_cast<base::Value*>(&value), mutable_value_unchecked(),
const_cast<base::ListValue*>(&const_value()), read_only(), read_only(), controller());
controller());
} }
return nullptr; return nullptr;
@ -1340,12 +1364,10 @@ CefRefPtr<CefBinaryValue> CefListValueImpl::GetBinary(size_t index) {
const auto& list = const_value().GetList(); const auto& list = const_value().GetList();
if (index < list.size()) { if (index < list.size()) {
const base::Value& value = list[index]; base::Value& value = const_cast<base::Value&>(list[index]);
if (value.is_blob()) { if (value.is_blob()) {
base::Value* binary_value = const_cast<base::Value*>(&value);
return CefBinaryValueImpl::GetOrCreateRef( return CefBinaryValueImpl::GetOrCreateRef(
binary_value, const_cast<base::ListValue*>(&const_value()), &value, mutable_value_unchecked(), controller());
controller());
} }
} }
@ -1357,13 +1379,10 @@ CefRefPtr<CefDictionaryValue> CefListValueImpl::GetDictionary(size_t index) {
const auto& list = const_value().GetList(); const auto& list = const_value().GetList();
if (index < list.size()) { if (index < list.size()) {
const base::Value& value = list[index]; base::Value& value = const_cast<base::Value&>(list[index]);
if (value.is_dict()) { if (value.is_dict()) {
base::DictionaryValue* dict_value =
static_cast<base::DictionaryValue*>(const_cast<base::Value*>(&value));
return CefDictionaryValueImpl::GetOrCreateRef( return CefDictionaryValueImpl::GetOrCreateRef(
dict_value, const_cast<base::ListValue*>(&const_value()), read_only(), &value, mutable_value_unchecked(), read_only(), controller());
controller());
} }
} }
@ -1375,13 +1394,10 @@ CefRefPtr<CefListValue> CefListValueImpl::GetList(size_t index) {
const auto& list = const_value().GetList(); const auto& list = const_value().GetList();
if (index < list.size()) { if (index < list.size()) {
const base::Value& value = list[index]; base::Value& value = const_cast<base::Value&>(list[index]);
if (value.is_list()) { if (value.is_list()) {
base::ListValue* list_value = return CefListValueImpl::GetOrCreateRef(&value, mutable_value_unchecked(),
static_cast<base::ListValue*>(const_cast<base::Value*>(&value)); read_only(), controller());
return CefListValueImpl::GetOrCreateRef(
list_value, const_cast<base::ListValue*>(&const_value()), read_only(),
controller());
} }
} }
@ -1394,39 +1410,39 @@ bool CefListValueImpl::SetValue(size_t index, CefRefPtr<CefValue> value) {
CefValueImpl* impl = static_cast<CefValueImpl*>(value.get()); CefValueImpl* impl = static_cast<CefValueImpl*>(value.get());
DCHECK(impl); DCHECK(impl);
base::Value* new_value = impl->CopyOrDetachValue(controller()); base::Value* actual_value =
base::Value* actual_value = SetInternal(index, new_value); SetInternal(index, impl->CopyOrDetachValue(controller()));
impl->SwapValue(actual_value, mutable_value(), controller()); impl->SwapValue(actual_value, mutable_value(), controller());
return true; return true;
} }
bool CefListValueImpl::SetNull(size_t index) { bool CefListValueImpl::SetNull(size_t index) {
CEF_VALUE_VERIFY_RETURN(true, false); CEF_VALUE_VERIFY_RETURN(true, false);
SetInternal(index, new base::Value()); SetInternal(index, std::make_unique<base::Value>());
return true; return true;
} }
bool CefListValueImpl::SetBool(size_t index, bool value) { bool CefListValueImpl::SetBool(size_t index, bool value) {
CEF_VALUE_VERIFY_RETURN(true, false); CEF_VALUE_VERIFY_RETURN(true, false);
SetInternal(index, new base::Value(value)); SetInternal(index, std::make_unique<base::Value>(value));
return true; return true;
} }
bool CefListValueImpl::SetInt(size_t index, int value) { bool CefListValueImpl::SetInt(size_t index, int value) {
CEF_VALUE_VERIFY_RETURN(true, false); CEF_VALUE_VERIFY_RETURN(true, false);
SetInternal(index, new base::Value(value)); SetInternal(index, std::make_unique<base::Value>(value));
return true; return true;
} }
bool CefListValueImpl::SetDouble(size_t index, double value) { bool CefListValueImpl::SetDouble(size_t index, double value) {
CEF_VALUE_VERIFY_RETURN(true, false); CEF_VALUE_VERIFY_RETURN(true, false);
SetInternal(index, new base::Value(value)); SetInternal(index, std::make_unique<base::Value>(value));
return true; return true;
} }
bool CefListValueImpl::SetString(size_t index, const CefString& value) { bool CefListValueImpl::SetString(size_t index, const CefString& value) {
CEF_VALUE_VERIFY_RETURN(true, false); CEF_VALUE_VERIFY_RETURN(true, false);
SetInternal(index, new base::Value(value.ToString())); SetInternal(index, std::make_unique<base::Value>(value.ToString()));
return true; return true;
} }
@ -1491,9 +1507,9 @@ bool CefListValueImpl::RemoveInternal(size_t index) {
return true; return true;
} }
base::Value* CefListValueImpl::SetInternal(size_t index, base::Value* value) { base::Value* CefListValueImpl::SetInternal(size_t index,
std::unique_ptr<base::Value> value) {
DCHECK(value); DCHECK(value);
std::unique_ptr<base::Value> valueObj(value);
auto& list = mutable_value()->GetList(); auto& list = mutable_value()->GetList();
if (RemoveInternal(index)) { if (RemoveInternal(index)) {
@ -1505,7 +1521,7 @@ base::Value* CefListValueImpl::SetInternal(size_t index, base::Value* value) {
// TODO: This approach seems inefficient. See // TODO: This approach seems inefficient. See
// https://crbug.com/1187066#c17 for background. // https://crbug.com/1187066#c17 for background.
while (list.size() <= index) { while (list.size() <= index) {
mutable_value()->Append(base::Value()); list.Append(base::Value());
} }
} }
list[index] = std::move(*value); list[index] = std::move(*value);
@ -1519,18 +1535,20 @@ base::Value* CefListValueImpl::SetInternal(size_t index, base::Value* value) {
// |value| will be deleted when this method returns. Update the controller to // |value| will be deleted when this method returns. Update the controller to
// reference |actual_value| instead. // reference |actual_value| instead.
controller()->Swap(value, const_cast<base::Value*>(&actual_value)); controller()->Swap(value.get(), const_cast<base::Value*>(&actual_value));
return const_cast<base::Value*>(&actual_value); return const_cast<base::Value*>(&actual_value);
} }
CefListValueImpl::CefListValueImpl(base::ListValue* value, CefListValueImpl::CefListValueImpl(base::Value* value,
void* parent_value, void* parent_value,
ValueMode value_mode, ValueMode value_mode,
bool read_only, bool read_only,
CefValueController* controller) CefValueController* controller)
: CefValueBase<CefListValue, base::ListValue>(value, : CefValueBase<CefListValue, base::Value>(value,
parent_value, parent_value,
value_mode, value_mode,
read_only, read_only,
controller) {} controller) {
DCHECK(value->is_list());
}

View File

@ -6,6 +6,7 @@
#define CEF_LIBCEF_COMMON_VALUES_IMPL_H_ #define CEF_LIBCEF_COMMON_VALUES_IMPL_H_
#pragma once #pragma once
#include <memory>
#include <vector> #include <vector>
#include "include/cef_values.h" #include "include/cef_values.h"
@ -28,7 +29,7 @@ class CefValueImpl : public CefValue {
// Take ownership of |value|. Do not pass in a value owned by something else // Take ownership of |value|. Do not pass in a value owned by something else
// (use GetOrCreateRefOrCopy instead). // (use GetOrCreateRefOrCopy instead).
explicit CefValueImpl(base::Value* value); explicit CefValueImpl(base::Value value);
// Keep a reference to |value|. // Keep a reference to |value|.
explicit CefValueImpl(CefRefPtr<CefBinaryValue> value); explicit CefValueImpl(CefRefPtr<CefBinaryValue> value);
@ -42,19 +43,23 @@ class CefValueImpl : public CefValue {
// Take ownership of |value|. Do not pass in a value owned by something else // Take ownership of |value|. Do not pass in a value owned by something else
// (use GetOrCreateRefOrCopy or Set*() instead). // (use GetOrCreateRefOrCopy or Set*() instead).
void SetValue(base::Value* value); void SetValue(base::Value value);
// Return a copy of the value.
[[nodiscard]] base::Value CopyValue();
// Copy a simple value or transfer ownership of a complex value. If ownership // Copy a simple value or transfer ownership of a complex value. If ownership
// of the value is tranferred then this object's internal reference to the // of the value is tranferred then this object's internal reference to the
// value will be updated and remain valid. base::Value now uses move semantics // value will be updated and remain valid. base::Value now uses move semantics
// so we need to perform the copy and swap in two steps. // so we need to perform the copy and swap in two steps.
base::Value* CopyOrDetachValue(CefValueController* new_controller); [[nodiscard]] std::unique_ptr<base::Value> CopyOrDetachValue(
CefValueController* new_controller);
void SwapValue(base::Value* new_value, void SwapValue(base::Value* new_value,
void* new_parent_value, void* new_parent_value,
CefValueController* new_controller); CefValueController* new_controller);
// Returns a reference to the underlying data. Access must be protected by // Returns a reference to the underlying data. Access must be protected by
// calling AcquireLock/ReleaseLock. // calling AcquireLock/ReleaseLock (e.g. use ScopedLockedValue).
base::Value* GetValueUnsafe() const; base::Value* GetValueUnsafe() const;
// CefValue methods. // CefValue methods.
@ -101,7 +106,7 @@ class CefValueImpl : public CefValue {
}; };
private: private:
void SetValueInternal(base::Value* value); void SetValueInternal(absl::optional<base::Value> value);
// Returns the controller for the current value, if any. // Returns the controller for the current value, if any.
CefValueController* GetValueController() const; CefValueController* GetValueController() const;
@ -133,6 +138,10 @@ class CefBinaryValueImpl : public CefValueBase<CefBinaryValue, base::Value> {
void* parent_value, void* parent_value,
CefValueController* controller); CefValueController* controller);
// Take ownership of |value|. Do not pass in a value owned by something else
// (use GetOrCreateRef or constructor variant with |will_delete| argument).
explicit CefBinaryValueImpl(base::Value value);
// Reference an existing value (set |will_delete| to false) or take ownership // Reference an existing value (set |will_delete| to false) or take ownership
// of an existing value (set |will_delete| to true). When referencing an // of an existing value (set |will_delete| to true). When referencing an
// existing value you must explicitly call Detach(nullptr) when |value| is no // existing value you must explicitly call Detach(nullptr) when |value| is no
@ -148,11 +157,11 @@ class CefBinaryValueImpl : public CefValueBase<CefBinaryValue, base::Value> {
CefBinaryValueImpl& operator=(const CefBinaryValueImpl&) = delete; CefBinaryValueImpl& operator=(const CefBinaryValueImpl&) = delete;
// Return a copy of the value. // Return a copy of the value.
[[nodiscard]] base::Value* CopyValue(); [[nodiscard]] base::Value CopyValue();
// If this value is a reference then return a copy. Otherwise, detach and // If this value is a reference then return a copy. Otherwise, detach and
// transfer ownership of the value. // transfer ownership of the value.
[[nodiscard]] base::Value* CopyOrDetachValue( [[nodiscard]] std::unique_ptr<base::Value> CopyOrDetachValue(
CefValueController* new_controller); CefValueController* new_controller);
bool IsSameValue(const base::Value* that); bool IsSameValue(const base::Value* that);
@ -160,7 +169,7 @@ class CefBinaryValueImpl : public CefValueBase<CefBinaryValue, base::Value> {
// Returns the underlying value. Access must be protected by calling // Returns the underlying value. Access must be protected by calling
// lock/unlock on the controller. // lock/unlock on the controller.
base::Value* GetValueUnsafe(); base::Value* GetValueUnsafe() const;
// CefBinaryValue methods. // CefBinaryValue methods.
bool IsValid() override; bool IsValid() override;
@ -182,42 +191,45 @@ class CefBinaryValueImpl : public CefValueBase<CefBinaryValue, base::Value> {
// CefDictionaryValue implementation // CefDictionaryValue implementation
class CefDictionaryValueImpl class CefDictionaryValueImpl
: public CefValueBase<CefDictionaryValue, base::DictionaryValue> { : public CefValueBase<CefDictionaryValue, base::Value> {
public: public:
// Get or create a reference value. // Get or create a reference value.
static CefRefPtr<CefDictionaryValue> GetOrCreateRef( static CefRefPtr<CefDictionaryValue> GetOrCreateRef(
base::DictionaryValue* value, base::Value* value,
void* parent_value, void* parent_value,
bool read_only, bool read_only,
CefValueController* controller); CefValueController* controller);
// Take ownership of |value|. Do not pass in a value owned by something else
// (use GetOrCreateRef or constructor variant with |will_delete| argument).
CefDictionaryValueImpl(base::Value value, bool read_only);
CefDictionaryValueImpl(base::Value::Dict value, bool read_only);
// Reference an existing value (set |will_delete| to false) or take ownership // Reference an existing value (set |will_delete| to false) or take ownership
// of an existing value (set |will_delete| to true). When referencing an // of an existing value (set |will_delete| to true). When referencing an
// existing value you must explicitly call Detach(nullptr) when |value| is no // existing value you must explicitly call Detach(nullptr) when |value| is no
// longer valid. Use GetOrCreateRef instead of this constructor if |value| is // longer valid. Use GetOrCreateRef instead of this constructor if |value| is
// owned by some other object and you do not plan to explicitly call // owned by some other object and you do not plan to explicitly call
// Detach(nullptr). // Detach(nullptr).
CefDictionaryValueImpl(base::DictionaryValue* value, CefDictionaryValueImpl(base::Value* value, bool will_delete, bool read_only);
bool will_delete,
bool read_only);
CefDictionaryValueImpl(const CefDictionaryValueImpl&) = delete; CefDictionaryValueImpl(const CefDictionaryValueImpl&) = delete;
CefDictionaryValueImpl& operator=(const CefDictionaryValueImpl&) = delete; CefDictionaryValueImpl& operator=(const CefDictionaryValueImpl&) = delete;
// Return a copy of the value. // Return a copy of the value.
[[nodiscard]] base::DictionaryValue* CopyValue(); [[nodiscard]] base::Value CopyValue();
// If this value is a reference then return a copy. Otherwise, detach and // If this value is a reference then return a copy. Otherwise, detach and
// transfer ownership of the value. // transfer ownership of the value.
[[nodiscard]] base::DictionaryValue* CopyOrDetachValue( [[nodiscard]] std::unique_ptr<base::Value> CopyOrDetachValue(
CefValueController* new_controller); CefValueController* new_controller);
bool IsSameValue(const base::DictionaryValue* that); bool IsSameValue(const base::Value* that);
bool IsEqualValue(const base::DictionaryValue* that); bool IsEqualValue(const base::Value* that);
// Returns the underlying value. Access must be protected by calling // Returns the underlying value. Access must be protected by calling
// lock/unlock on the controller. // lock/unlock on the controller.
base::DictionaryValue* GetValueUnsafe(); base::Value* GetValueUnsafe() const;
// CefDictionaryValue methods. // CefDictionaryValue methods.
bool IsValid() override; bool IsValid() override;
@ -254,50 +266,56 @@ class CefDictionaryValueImpl
private: private:
// See the CefValueBase constructor for usage. // See the CefValueBase constructor for usage.
CefDictionaryValueImpl(base::DictionaryValue* value, CefDictionaryValueImpl(base::Value* value,
void* parent_value, void* parent_value,
ValueMode value_mode, ValueMode value_mode,
bool read_only, bool read_only,
CefValueController* controller); CefValueController* controller);
bool RemoveInternal(const CefString& key); bool RemoveInternal(const CefString& key);
base::Value* SetInternal(const CefString& key, base::Value* value); base::Value* SetInternal(const CefString& key,
std::unique_ptr<base::Value> value);
}; };
// CefListValue implementation // CefListValue implementation
class CefListValueImpl : public CefValueBase<CefListValue, base::ListValue> { class CefListValueImpl : public CefValueBase<CefListValue, base::Value> {
public: public:
// Get or create a reference value. // Get or create a reference value.
static CefRefPtr<CefListValue> GetOrCreateRef(base::ListValue* value, static CefRefPtr<CefListValue> GetOrCreateRef(base::Value* value,
void* parent_value, void* parent_value,
bool read_only, bool read_only,
CefValueController* controller); CefValueController* controller);
// Take ownership of |value|. Do not pass in a value owned by something else
// (use GetOrCreateRef or constructor variant with |will_delete| argument).
CefListValueImpl(base::Value value, bool read_only);
CefListValueImpl(base::Value::List value, bool read_only);
// Reference an existing value (set |will_delete| to false) or take ownership // Reference an existing value (set |will_delete| to false) or take ownership
// of an existing value (set |will_delete| to true). When referencing an // of an existing value (set |will_delete| to true). When referencing an
// existing value you must explicitly call Detach(nullptr) when |value| is no // existing value you must explicitly call Detach(nullptr) when |value| is no
// longer valid. Use GetOrCreateRef instead of this constructor if |value| is // longer valid. Use GetOrCreateRef instead of this constructor if |value| is
// owned by some other object and you do not plan to explicitly call // owned by some other object and you do not plan to explicitly call
// Detach(nullptr). // Detach(nullptr).
CefListValueImpl(base::ListValue* value, bool will_delete, bool read_only); CefListValueImpl(base::Value* value, bool will_delete, bool read_only);
CefListValueImpl(const CefListValueImpl&) = delete; CefListValueImpl(const CefListValueImpl&) = delete;
CefListValueImpl& operator=(const CefListValueImpl&) = delete; CefListValueImpl& operator=(const CefListValueImpl&) = delete;
// Return a copy of the value. // Return a copy of the value.
[[nodiscard]] base::ListValue* CopyValue(); [[nodiscard]] base::Value CopyValue();
// If this value is a reference then return a copy. Otherwise, detach and // If this value is a reference then return a copy. Otherwise, detach and
// transfer ownership of the value. // transfer ownership of the value.
[[nodiscard]] base::ListValue* CopyOrDetachValue( [[nodiscard]] std::unique_ptr<base::Value> CopyOrDetachValue(
CefValueController* new_controller); CefValueController* new_controller);
bool IsSameValue(const base::ListValue* that); bool IsSameValue(const base::Value* that);
bool IsEqualValue(const base::ListValue* that); bool IsEqualValue(const base::Value* that);
// Returns the underlying value. Access must be protected by calling // Returns the underlying value. Access must be protected by calling
// lock/unlock on the controller. // lock/unlock on the controller.
base::ListValue* GetValueUnsafe(); base::Value* GetValueUnsafe() const;
// CefListValue methods. // CefListValue methods.
bool IsValid() override; bool IsValid() override;
@ -332,14 +350,14 @@ class CefListValueImpl : public CefValueBase<CefListValue, base::ListValue> {
private: private:
// See the CefValueBase constructor for usage. // See the CefValueBase constructor for usage.
CefListValueImpl(base::ListValue* value, CefListValueImpl(base::Value* value,
void* parent_value, void* parent_value,
ValueMode value_mode, ValueMode value_mode,
bool read_only, bool read_only,
CefValueController* controller); CefValueController* controller);
bool RemoveInternal(size_t index); bool RemoveInternal(size_t index);
base::Value* SetInternal(size_t index, base::Value* value); base::Value* SetInternal(size_t index, std::unique_ptr<base::Value> value);
}; };
#endif // CEF_LIBCEF_COMMON_VALUES_IMPL_H_ #endif // CEF_LIBCEF_COMMON_VALUES_IMPL_H_

View File

@ -61,9 +61,9 @@ bool CefPrintRenderFrameHelperDelegate::OverridePrint(
// instructs the PDF plugin to print. This is to make window.print() on a // instructs the PDF plugin to print. This is to make window.print() on a
// PDF plugin document correctly print the PDF. See // PDF plugin document correctly print the PDF. See
// https://crbug.com/448720. // https://crbug.com/448720.
base::DictionaryValue message; base::Value::Dict message;
message.SetString("type", "print"); message.Set("type", "print");
post_message_support->PostMessageFromValue(message); post_message_support->PostMessageFromValue(base::Value(std::move(message)));
return true; return true;
} }
return false; return false;

View File

@ -290,7 +290,7 @@ void CefFrameImpl::SendProcessMessage(CefProcessId target_process,
SendToBrowserFrame( SendToBrowserFrame(
__FUNCTION__, __FUNCTION__,
base::BindOnce( base::BindOnce(
[](const CefString& name, base::ListValue argument_list, [](const CefString& name, base::Value::List argument_list,
const BrowserFrameType& render_frame) { const BrowserFrameType& render_frame) {
render_frame->SendMessage(name, std::move(argument_list)); render_frame->SendMessage(name, std::move(argument_list));
}, },
@ -732,12 +732,12 @@ void CefFrameImpl::FrameDetached() {
OnDisconnect(DisconnectReason::BROWSER_FRAME_DETACHED); OnDisconnect(DisconnectReason::BROWSER_FRAME_DETACHED);
} }
void CefFrameImpl::SendMessage(const std::string& name, base::Value arguments) { void CefFrameImpl::SendMessage(const std::string& name,
base::Value::List arguments) {
if (auto app = CefAppManager::Get()->GetApplication()) { if (auto app = CefAppManager::Get()->GetApplication()) {
if (auto handler = app->GetRenderProcessHandler()) { if (auto handler = app->GetRenderProcessHandler()) {
auto& list_value = base::Value::AsListValue(arguments); CefRefPtr<CefProcessMessageImpl> message(
CefRefPtr<CefProcessMessageImpl> message(new CefProcessMessageImpl( new CefProcessMessageImpl(name, std::move(arguments),
name, std::move(const_cast<base::ListValue&>(list_value)),
/*read_only=*/true)); /*read_only=*/true));
handler->OnProcessMessageReceived(browser_, this, PID_BROWSER, handler->OnProcessMessageReceived(browser_, this, PID_BROWSER,
message.get()); message.get());
@ -835,10 +835,11 @@ void CefFrameImpl::DidStopLoading() {
void CefFrameImpl::MoveOrResizeStarted() { void CefFrameImpl::MoveOrResizeStarted() {
if (frame_) { if (frame_) {
auto web_view = frame_->View(); auto web_view = frame_->View();
if (web_view) if (web_view) {
web_view->CancelPagePopup(); web_view->CancelPagePopup();
} }
} }
}
void CefFrameImpl::ContextLifecycleStateChanged( void CefFrameImpl::ContextLifecycleStateChanged(
blink::mojom::blink::FrameLifecycleState state) { blink::mojom::blink::FrameLifecycleState state) {

View File

@ -149,7 +149,8 @@ class CefFrameImpl
// cef::mojom::RenderFrame methods: // cef::mojom::RenderFrame methods:
void FrameAttachedAck() override; void FrameAttachedAck() override;
void FrameDetached() override; void FrameDetached() override;
void SendMessage(const std::string& name, base::Value arguments) override; void SendMessage(const std::string& name,
base::Value::List arguments) override;
void SendSharedMemoryRegion(const std::string& name, void SendSharedMemoryRegion(const std::string& name,
base::ReadOnlySharedMemoryRegion region) override; base::ReadOnlySharedMemoryRegion region) override;
void SendCommand(const std::string& command) override; void SendCommand(const std::string& command) override;

View File

@ -350,15 +350,11 @@ CefRefPtr<CefBrowserImpl> CefRenderManager::MaybeCreateBrowser(
if (handler.get()) { if (handler.get()) {
CefRefPtr<CefDictionaryValueImpl> dictValuePtr; CefRefPtr<CefDictionaryValueImpl> dictValuePtr;
if (params->extra_info) { if (params->extra_info) {
auto& dict_value = base::Value::AsDictionaryValue(*params->extra_info); dictValuePtr =
dictValuePtr = new CefDictionaryValueImpl( new CefDictionaryValueImpl(std::move(*params->extra_info),
const_cast<base::DictionaryValue*>(&dict_value), /*read_only=*/true);
/*will_delete=*/false, /*read_only=*/true);
} }
handler->OnBrowserCreated(browser.get(), dictValuePtr.get()); handler->OnBrowserCreated(browser.get(), dictValuePtr.get());
if (dictValuePtr) {
std::ignore = dictValuePtr->Detach(nullptr);
}
} }
} }