diff --git a/libcef/browser/alloy/alloy_browser_context.cc b/libcef/browser/alloy/alloy_browser_context.cc index f97b209aa..ca4ccd05a 100644 --- a/libcef/browser/alloy/alloy_browser_context.cc +++ b/libcef/browser/alloy/alloy_browser_context.cc @@ -264,8 +264,8 @@ void AlloyBrowserContext::LoadExtension( if (manifest && manifest->GetSize() > 0) { CefDictionaryValueImpl* value_impl = static_cast(manifest.get()); - std::unique_ptr value_copy(value_impl->CopyValue()); - extension_system()->LoadExtension(std::move(*value_copy).TakeDict(), + auto value = value_impl->CopyValue(); + extension_system()->LoadExtension(std::move(value.GetDict()), root_directory, false /* builtin */, loader_context, handler); } else { diff --git a/libcef/browser/browser_frame.cc b/libcef/browser/browser_frame.cc index 70ba04c04..91897f657 100644 --- a/libcef/browser/browser_frame.cc +++ b/libcef/browser/browser_frame.cc @@ -34,7 +34,7 @@ void CefBrowserFrame::RegisterBrowserInterfaceBindersForFrame( } 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 // navigating cross-origin. if (auto host = GetFrameHost(/*prefer_speculative=*/true)) { diff --git a/libcef/browser/browser_frame.h b/libcef/browser/browser_frame.h index 734211216..41576a09d 100644 --- a/libcef/browser/browser_frame.h +++ b/libcef/browser/browser_frame.h @@ -35,7 +35,8 @@ class CefBrowserFrame private: // 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, base::ReadOnlySharedMemoryRegion region) override; void FrameAttached(mojo::PendingRemote render_frame, diff --git a/libcef/browser/browser_info_manager.cc b/libcef/browser/browser_info_manager.cc index ff673cc17..7d75708f5 100644 --- a/libcef/browser/browser_info_manager.cc +++ b/libcef/browser/browser_info_manager.cc @@ -514,8 +514,8 @@ void CefBrowserInfoManager::SendNewBrowserInfoResponse( if (extra_info) { auto extra_info_impl = static_cast(extra_info.get()); - auto extra_info_value = base::WrapUnique(extra_info_impl->CopyValue()); - params->extra_info = std::move(*extra_info_value); + auto extra_info_value = extra_info_impl->CopyValue(); + params->extra_info = std::move(extra_info_value.GetDict()); } } else { // The new browser info response has timed out. diff --git a/libcef/browser/devtools/devtools_controller.cc b/libcef/browser/devtools/devtools_controller.cc index 44cd1834e..30f577616 100644 --- a/libcef/browser/devtools/devtools_controller.cc +++ b/libcef/browser/devtools/devtools_controller.cc @@ -43,7 +43,7 @@ bool CefDevToolsController::SendDevToolsMessage( int CefDevToolsController::ExecuteDevToolsMethod( int suggested_message_id, const std::string& method, - const base::DictionaryValue* params) { + const base::Value::Dict* params) { CEF_REQUIRE_UIT(); if (!EnsureAgentHost()) { return 0; @@ -57,11 +57,11 @@ int CefDevToolsController::ExecuteDevToolsMethod( next_message_id_ = message_id + 1; } - base::DictionaryValue message; - message.SetIntKey("id", message_id); - message.SetStringKey("method", method); + base::Value::Dict message; + message.Set("id", message_id); + message.Set("method", method); if (params) { - message.SetKey("params", params->Clone()); + message.Set("params", params->Clone()); } std::string protocol_message; diff --git a/libcef/browser/devtools/devtools_controller.h b/libcef/browser/devtools/devtools_controller.h index acaf13b9b..3bed09ff0 100644 --- a/libcef/browser/devtools/devtools_controller.h +++ b/libcef/browser/devtools/devtools_controller.h @@ -51,7 +51,7 @@ class CefDevToolsController : public content::DevToolsAgentHostClient { bool SendDevToolsMessage(const base::StringPiece& message); int ExecuteDevToolsMethod(int message_id, const std::string& method, - const base::DictionaryValue* params); + const base::Value::Dict* params); // |observer| must outlive this object or be removed. void AddObserver(Observer* observer); diff --git a/libcef/browser/devtools/devtools_frontend.cc b/libcef/browser/devtools/devtools_frontend.cc index 3ea60c5f1..f5f30a30e 100644 --- a/libcef/browser/devtools/devtools_frontend.cc +++ b/libcef/browser/devtools/devtools_frontend.cc @@ -77,10 +77,10 @@ static std::string GetFrontendURL() { scheme::kChromeDevToolsHost); } -base::DictionaryValue BuildObjectForResponse(const net::HttpResponseHeaders* rh, - bool success, - int net_error) { - base::DictionaryValue response; +base::Value::Dict BuildObjectForResponse(const net::HttpResponseHeaders* rh, + bool success, + int net_error) { + base::Value::Dict response; int responseCode = 200; if (rh) { 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 responseCode = 404; } - response.SetInteger("statusCode", responseCode); - response.SetInteger("netError", net_error); - response.SetString("netErrorName", net::ErrorToString(net_error)); + response.Set("statusCode", responseCode); + response.Set("netError", net_error); + response.Set("netErrorName", net::ErrorToString(net_error)); - auto headers = std::make_unique(); + base::Value::Dict headers; size_t iterator = 0; std::string name; std::string value; // TODO(caseq): this probably needs to handle duplicate header names // correctly by folding them. while (rh && rh->EnumerateHeaderLines(&iterator, &name, &value)) { - headers->SetString(name, value); + headers.Set(name, value); } response.Set("headers", std::move(headers)); @@ -222,7 +222,7 @@ class CefDevToolsFrontend::NetworkResourceLoader void OnComplete(bool success) override { auto response = BuildObjectForResponse(response_headers_.get(), success, 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)); } @@ -473,9 +473,9 @@ void CefDevToolsFrontend::HandleMessageFromDevToolsFrontend( std::make_unique( std::move(pending_remote))); } else if (content::HasWebUIScheme(gurl)) { - base::DictionaryValue response; - response.SetInteger("statusCode", 403); - SendMessageAck(request_id, std::move(response)); + base::Value::Dict response; + response.Set("statusCode", 403); + SendMessageAck(request_id, base::Value(std::move(response))); return; } else { auto* partition = diff --git a/libcef/browser/devtools/devtools_manager.cc b/libcef/browser/devtools/devtools_manager.cc index 900e4b8fa..170f60956 100644 --- a/libcef/browser/devtools/devtools_manager.cc +++ b/libcef/browser/devtools/devtools_manager.cc @@ -176,8 +176,8 @@ int CefDevToolsManager::ExecuteDevToolsMethod( CefDictionaryValueImpl* impl = static_cast(params.get()); CefValueController::AutoLock lock_scope(impl->controller()); - return devtools_controller_->ExecuteDevToolsMethod(message_id, method, - impl->GetValueUnsafe()); + return devtools_controller_->ExecuteDevToolsMethod( + message_id, method, impl->GetValueUnsafe()->GetIfDict()); } else { return devtools_controller_->ExecuteDevToolsMethod(message_id, method, nullptr); diff --git a/libcef/browser/extension_impl.cc b/libcef/browser/extension_impl.cc index 61f578738..d1ef91ae5 100644 --- a/libcef/browser/extension_impl.cc +++ b/libcef/browser/extension_impl.cc @@ -15,11 +15,9 @@ CefExtensionImpl::CefExtensionImpl(const extensions::Extension* extension, CefRefPtr handler) : id_(extension->id()), path_(extension->path().value()), - manifest_(new CefDictionaryValueImpl( - static_cast( - new base::Value(extension->manifest()->value()->Clone())), - true, - true)), + manifest_( + new CefDictionaryValueImpl(extension->manifest()->value()->Clone(), + /*read_only=*/true)), loader_context_(loader_context), handler_(handler) {} diff --git a/libcef/browser/frame_host_impl.cc b/libcef/browser/frame_host_impl.cc index 88d4d7add..6c7d68c20 100644 --- a/libcef/browser/frame_host_impl.cc +++ b/libcef/browser/frame_host_impl.cc @@ -275,11 +275,10 @@ void CefFrameHostImpl::SendProcessMessage( // Invalidate the message object immediately by taking the argument list. auto argument_list = static_cast(message.get())->TakeArgumentList(); - SendToRenderFrame( __FUNCTION__, base::BindOnce( - [](const CefString& name, base::ListValue argument_list, + [](const CefString& name, base::Value::List argument_list, const RenderFrameType& render_frame) { render_frame->SendMessage(name, std::move(argument_list)); }, @@ -631,13 +630,12 @@ void CefFrameHostImpl::OnRenderFrameDisconnect() { } void CefFrameHostImpl::SendMessage(const std::string& name, - base::Value arguments) { + base::Value::List arguments) { if (auto browser = GetBrowserHostBase()) { if (auto client = browser->GetClient()) { - auto& list_value = base::Value::AsListValue(arguments); - CefRefPtr message(new CefProcessMessageImpl( - name, std::move(const_cast(list_value)), - /*read_only=*/true)); + CefRefPtr message( + new CefProcessMessageImpl(name, std::move(arguments), + /*read_only=*/true)); browser->GetClient()->OnProcessMessageReceived( browser.get(), this, PID_RENDERER, message.get()); } diff --git a/libcef/browser/frame_host_impl.h b/libcef/browser/frame_host_impl.h index a11afdcad..71b234d62 100644 --- a/libcef/browser/frame_host_impl.h +++ b/libcef/browser/frame_host_impl.h @@ -135,7 +135,8 @@ class CefFrameHostImpl : public CefFrame, public cef::mojom::BrowserFrame { content::RenderFrameHost* render_frame_host); // 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, base::ReadOnlySharedMemoryRegion region) override; void FrameAttached(mojo::PendingRemote render_frame, diff --git a/libcef/browser/prefs/pref_helper.cc b/libcef/browser/prefs/pref_helper.cc index 6857c6853..714882fea 100644 --- a/libcef/browser/prefs/pref_helper.cc +++ b/libcef/browser/prefs/pref_helper.cc @@ -51,21 +51,18 @@ CefRefPtr GetPreference(PrefService* pref_service, if (!pref) { return nullptr; } - return new CefValueImpl(new base::Value(pref->GetValue()->Clone())); + return new CefValueImpl(pref->GetValue()->Clone()); } CefRefPtr GetAllPreferences(PrefService* pref_service, bool include_defaults) { + // Returns a DeepCopy of the value. base::Value values = pref_service->GetPreferenceValues( include_defaults ? PrefService::INCLUDE_DEFAULTS : PrefService::EXCLUDE_DEFAULTS); - // CefDictionaryValueImpl takes ownership of |values|. - return new CefDictionaryValueImpl( - base::DictionaryValue::From( - base::Value::ToUniquePtrValue(std::move(values))) - .release(), - true, false); + // CefDictionaryValueImpl takes ownership of |values| contents. + return new CefDictionaryValueImpl(std::move(values), /*read_only=*/false); } bool CanSetPreference(PrefService* pref_service, const CefString& name) { diff --git a/libcef/browser/prefs/pref_registrar.cc b/libcef/browser/prefs/pref_registrar.cc index 44edd168f..70e3044a0 100644 --- a/libcef/browser/prefs/pref_registrar.cc +++ b/libcef/browser/prefs/pref_registrar.cc @@ -67,15 +67,12 @@ class CefPreferenceRegistrarImpl : public CefPreferenceRegistrar { void RegisterComplexPref(const std::string& name, CefRefPtr default_value) { CefValueImpl* impl = static_cast(default_value.get()); + auto impl_value = impl->CopyValue(); - CefValueImpl::ScopedLockedValue scoped_locked_value(impl); - base::Value* impl_value = impl->GetValueUnsafe(); - - // Will make a deep copy of |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()); + if (impl_value.type() == base::Value::Type::DICT) { + registry_->RegisterDictionaryPref(name, std::move(impl_value)); + } else if (impl_value.type() == base::Value::Type::LIST) { + registry_->RegisterListPref(name, std::move(impl_value)); } else { NOTREACHED(); } diff --git a/libcef/browser/views/browser_view_impl.cc b/libcef/browser/views/browser_view_impl.cc index a0cd075ff..74ccef214 100644 --- a/libcef/browser/views/browser_view_impl.cc +++ b/libcef/browser/views/browser_view_impl.cc @@ -191,11 +191,11 @@ void CefBrowserViewImpl::Detach() { } } -void CefBrowserViewImpl::GetDebugInfo(base::DictionaryValue* info, +void CefBrowserViewImpl::GetDebugInfo(base::Value::Dict* info, bool include_children) { ParentClass::GetDebugInfo(info, include_children); if (browser_) { - info->SetString("url", browser_->GetMainFrame()->GetURL().ToString()); + info->Set("url", browser_->GetMainFrame()->GetURL().ToString()); } } diff --git a/libcef/browser/views/browser_view_impl.h b/libcef/browser/views/browser_view_impl.h index c1b738748..e5d9cc19c 100644 --- a/libcef/browser/views/browser_view_impl.h +++ b/libcef/browser/views/browser_view_impl.h @@ -69,8 +69,7 @@ class CefBrowserViewImpl // CefViewAdapter methods: void Detach() override; std::string GetDebugType() override { return "BrowserView"; } - void GetDebugInfo(base::DictionaryValue* info, - bool include_children) override; + void GetDebugInfo(base::Value::Dict* info, bool include_children) override; // CefBrowserViewView::Delegate methods: void OnBrowserViewAdded() override; diff --git a/libcef/browser/views/label_button_impl.h b/libcef/browser/views/label_button_impl.h index f1513a851..40ca62447 100644 --- a/libcef/browser/views/label_button_impl.h +++ b/libcef/browser/views/label_button_impl.h @@ -48,10 +48,9 @@ CEF_LABEL_BUTTON_IMPL_T class CefLabelButtonImpl : public CEF_BUTTON_IMPL_D { CefRefPtr AsLabelButton() override { return this; } // CefViewAdapter methods: - void GetDebugInfo(base::DictionaryValue* info, - bool include_children) override { + void GetDebugInfo(base::Value::Dict* info, bool include_children) override { ParentClass::GetDebugInfo(info, include_children); - info->SetString("text", ParentClass::root_view()->GetText()); + info->Set("text", ParentClass::root_view()->GetText()); } protected: diff --git a/libcef/browser/views/panel_impl.h b/libcef/browser/views/panel_impl.h index 6b47ada88..56083b273 100644 --- a/libcef/browser/views/panel_impl.h +++ b/libcef/browser/views/panel_impl.h @@ -49,21 +49,20 @@ CEF_PANEL_IMPL_T class CefPanelImpl : public CEF_VIEW_IMPL_D { CefRefPtr AsPanel() override { return this; } // CefViewAdapter methods: - void GetDebugInfo(base::DictionaryValue* info, - bool include_children) override { + void GetDebugInfo(base::Value::Dict* info, bool include_children) override { ParentClass::GetDebugInfo(info, include_children); if (include_children) { const size_t count = ParentClass::content_view()->children().size(); if (count > 0U) { - std::unique_ptr children(new base::ListValue()); + base::Value::List children; for (size_t i = 0U; i < count; ++i) { views::View* view = ParentClass::content_view()->children()[i]; CefViewAdapter* adapter = CefViewAdapter::GetFor(view); if (adapter) { - base::DictionaryValue child_info; + base::Value::Dict child_info; adapter->GetDebugInfo(&child_info, include_children); - children->Append(std::move(child_info)); + children.Append(std::move(child_info)); } } diff --git a/libcef/browser/views/scroll_view_impl.cc b/libcef/browser/views/scroll_view_impl.cc index fb9a97187..946f1e4dd 100644 --- a/libcef/browser/views/scroll_view_impl.cc +++ b/libcef/browser/views/scroll_view_impl.cc @@ -64,16 +64,15 @@ int CefScrollViewImpl::GetVerticalScrollbarWidth() { return root_view()->GetScrollBarLayoutWidth(); } -void CefScrollViewImpl::GetDebugInfo(base::DictionaryValue* info, +void CefScrollViewImpl::GetDebugInfo(base::Value::Dict* info, bool include_children) { ParentClass::GetDebugInfo(info, include_children); if (include_children) { views::View* view = root_view()->contents(); CefViewAdapter* adapter = CefViewAdapter::GetFor(view); if (adapter) { - std::unique_ptr child_info( - new base::DictionaryValue()); - adapter->GetDebugInfo(child_info.get(), include_children); + base::Value::Dict child_info; + adapter->GetDebugInfo(&child_info, include_children); info->Set("content_view", std::move(child_info)); } } diff --git a/libcef/browser/views/scroll_view_impl.h b/libcef/browser/views/scroll_view_impl.h index fd5a7c389..47d47cfb2 100644 --- a/libcef/browser/views/scroll_view_impl.h +++ b/libcef/browser/views/scroll_view_impl.h @@ -37,8 +37,7 @@ class CefScrollViewImpl // CefViewAdapter methods: std::string GetDebugType() override { return "ScrollView"; } - void GetDebugInfo(base::DictionaryValue* info, - bool include_children) override; + void GetDebugInfo(base::Value::Dict* info, bool include_children) override; private: // Create a new implementation object. diff --git a/libcef/browser/views/view_adapter.h b/libcef/browser/views/view_adapter.h index 39dbf0bbf..958be7f71 100644 --- a/libcef/browser/views/view_adapter.h +++ b/libcef/browser/views/view_adapter.h @@ -8,9 +8,7 @@ #include "include/views/cef_view.h" -namespace base { -class DictionaryValue; -} +#include "base/values.h" namespace views { class View; @@ -48,8 +46,7 @@ class CefViewAdapter { virtual std::string GetDebugType() = 0; // Override this method to provide debug info specific to the View type. - virtual void GetDebugInfo(base::DictionaryValue* info, - bool include_children) = 0; + virtual void GetDebugInfo(base::Value::Dict* info, bool include_children) = 0; protected: virtual ~CefViewAdapter() {} diff --git a/libcef/browser/views/view_impl.h b/libcef/browser/views/view_impl.h index dc3266f54..d9e105d85 100644 --- a/libcef/browser/views/view_impl.h +++ b/libcef/browser/views/view_impl.h @@ -343,19 +343,17 @@ CEF_VIEW_IMPL_T class CefViewImpl : public CefViewAdapter, public CefViewClass { } root_view_ref_ = nullptr; } - void GetDebugInfo(base::DictionaryValue* info, - bool include_children) override { - info->SetString("type", GetDebugType()); - info->SetInteger("id", root_view()->GetID()); + void GetDebugInfo(base::Value::Dict* info, bool include_children) override { + info->Set("type", GetDebugType()); + info->Set("id", root_view()->GetID()); // Use GetBounds() because some subclasses (like CefWindowImpl) override it. const CefRect& bounds = GetBounds(); - std::unique_ptr bounds_value( - new base::DictionaryValue()); - bounds_value->SetInteger("x", bounds.x); - bounds_value->SetInteger("y", bounds.y); - bounds_value->SetInteger("width", bounds.width); - bounds_value->SetInteger("height", bounds.height); + base::Value::Dict bounds_value; + bounds_value.Set("x", bounds.x); + bounds_value.Set("y", bounds.y); + bounds_value.Set("width", bounds.width); + bounds_value.Set("height", bounds.height); 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_REQUIRE_UIT_RETURN(CefString()); - std::unique_ptr info(new base::DictionaryValue()); + base::Value::Dict info; if (IsValid()) { - GetDebugInfo(info.get(), include_children); + GetDebugInfo(&info, include_children); } else { - info->SetString("type", GetDebugType()); + info.Set("type", GetDebugType()); } std::string json_string; - base::JSONWriter::WriteWithOptions(*info, 0, &json_string); + base::JSONWriter::WriteWithOptions(info, 0, &json_string); return json_string; } diff --git a/libcef/browser/views/window_impl.cc b/libcef/browser/views/window_impl.cc index e86de6506..ecd69b44b 100644 --- a/libcef/browser/views/window_impl.cc +++ b/libcef/browser/views/window_impl.cc @@ -315,11 +315,11 @@ CefRefPtr CefWindowImpl::AddOverlayView( return nullptr; } -void CefWindowImpl::GetDebugInfo(base::DictionaryValue* info, +void CefWindowImpl::GetDebugInfo(base::Value::Dict* info, bool include_children) { ParentClass::GetDebugInfo(info, include_children); if (root_view()) { - info->SetString("title", root_view()->title()); + info->Set("title", root_view()->title()); } } diff --git a/libcef/browser/views/window_impl.h b/libcef/browser/views/window_impl.h index f9557d415..a226d0f88 100644 --- a/libcef/browser/views/window_impl.h +++ b/libcef/browser/views/window_impl.h @@ -113,8 +113,7 @@ class CefWindowImpl // CefViewAdapter methods: std::string GetDebugType() override { return "Window"; } - void GetDebugInfo(base::DictionaryValue* info, - bool include_children) override; + void GetDebugInfo(base::Value::Dict* info, bool include_children) override; // ui::AcceleratorTarget methods: bool AcceleratorPressed(const ui::Accelerator& accelerator) override; diff --git a/libcef/common/json_impl.cc b/libcef/common/json_impl.cc index 13b141ff8..1b5dca73f 100644 --- a/libcef/common/json_impl.cc +++ b/libcef/common/json_impl.cc @@ -51,9 +51,7 @@ CefRefPtr CefParseJSON(const void* json, base::StringPiece(static_cast(json), json_size), GetJSONReaderOptions(options)); if (parse_result) { - return new CefValueImpl( - base::Value::ToUniquePtrValue(std::move(parse_result.value())) - .release()); + return new CefValueImpl(std::move(parse_result.value())); } return nullptr; } @@ -68,8 +66,7 @@ CefRefPtr CefParseJSONAndReturnError( auto result = base::JSONReader::ReadAndReturnValueWithError( json, GetJSONReaderOptions(options)); if (result.has_value()) { - return new CefValueImpl( - base::Value::ToUniquePtrValue(std::move(*result)).release()); + return new CefValueImpl(std::move(*result)); } error_msg_out = result.error().message; diff --git a/libcef/common/mojom/cef.mojom b/libcef/common/mojom/cef.mojom index 02c83dd1f..ee6fb087f 100644 --- a/libcef/common/mojom/cef.mojom +++ b/libcef/common/mojom/cef.mojom @@ -56,7 +56,7 @@ interface RenderFrame { FrameDetached(); // 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. 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 BrowserFrame { // 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. SendSharedMemoryRegion(string name, mojo_base.mojom.ReadOnlySharedMemoryRegion region); @@ -117,7 +117,7 @@ struct NewBrowserInfo { bool is_popup; bool is_windowless; 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. diff --git a/libcef/common/process_message_impl.cc b/libcef/common/process_message_impl.cc index 19042b013..e90ef83a2 100644 --- a/libcef/common/process_message_impl.cc +++ b/libcef/common/process_message_impl.cc @@ -9,7 +9,6 @@ #include "libcef/common/values_impl.h" #include "base/logging.h" -#include "base/memory/ptr_util.h" // static CefRefPtr CefProcessMessage::Create(const CefString& name) { @@ -24,25 +23,22 @@ CefProcessMessageImpl::CefProcessMessageImpl(const CefString& name, } CefProcessMessageImpl::CefProcessMessageImpl(const CefString& name, - base::ListValue arguments, + base::Value::List arguments, bool read_only) : name_(name) { DCHECK(!name_.empty()); - auto new_obj = std::make_unique(); - *new_obj = std::move(arguments); - arguments_ = - new CefListValueImpl(new_obj.release(), /*will_delete=*/true, read_only); + arguments_ = new CefListValueImpl(std::move(arguments), read_only); } CefProcessMessageImpl::~CefProcessMessageImpl() = default; -base::ListValue CefProcessMessageImpl::TakeArgumentList() { +base::Value::List CefProcessMessageImpl::TakeArgumentList() { DCHECK(IsValid()); CefListValueImpl* value_impl = static_cast(arguments_.get()); - auto value = base::WrapUnique(value_impl->CopyOrDetachValue(nullptr)); - return std::move(*value); + auto value = value_impl->CopyOrDetachValue(nullptr); + return std::move(value->GetList()); } bool CefProcessMessageImpl::IsValid() { diff --git a/libcef/common/process_message_impl.h b/libcef/common/process_message_impl.h index 5298e5f27..eadeca189 100644 --- a/libcef/common/process_message_impl.h +++ b/libcef/common/process_message_impl.h @@ -8,9 +8,7 @@ #include "include/cef_process_message.h" -namespace base { -class ListValue; -} +#include "base/values.h" // CefProcessMessage implementation. class CefProcessMessageImpl : public CefProcessMessage { @@ -22,7 +20,7 @@ class CefProcessMessageImpl : public CefProcessMessage { // Constructor for creating a new CefListValue that takes ownership of // |arguments|. CefProcessMessageImpl(const CefString& name, - base::ListValue arguments, + base::Value::List arguments, bool read_only); CefProcessMessageImpl(const CefProcessMessageImpl&) = delete; @@ -34,7 +32,7 @@ class CefProcessMessageImpl : public CefProcessMessage { // a copy if the argument list is already owned by something else. // TODO: Pass by reference instead of ownership if/when Mojo adds support // for that. - [[nodiscard]] base::ListValue TakeArgumentList(); + [[nodiscard]] base::Value::List TakeArgumentList(); // CefProcessMessage methods. bool IsValid() override; diff --git a/libcef/common/value_base.h b/libcef/common/value_base.h index 3eb455b12..ce50ba51c 100644 --- a/libcef/common/value_base.h +++ b/libcef/common/value_base.h @@ -297,10 +297,10 @@ class CefValueBase : public CefType, public CefValueController::Object { inline bool read_only() const { return read_only_; } // True if the underlying value has been detached. - inline bool detached() { return !controller_.get(); } + inline bool detached() const { return !controller_.get(); } // Returns the controller. - inline CefValueController* controller() { return controller_.get(); } + inline CefValueController* controller() const { return controller_.get(); } // Deletes the underlying value. void Delete() { @@ -346,7 +346,7 @@ class CefValueBase : public CefType, public CefValueController::Object { } // Verify that the value is attached. - inline bool VerifyAttached() { + inline bool VerifyAttached() const { if (detached()) { // This object should not be 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; } // Returns a mutable reference to the value. - inline ValueType* mutable_value() { + inline ValueType* mutable_value() const { DCHECK(value_); DCHECK(!read_only_); DCHECK(controller()->locked()); return value_; } + // Returns a const reference to the value. - inline const ValueType& const_value() { + inline const ValueType& const_value() const { DCHECK(value_); DCHECK(controller()->locked()); return *value_; } + // Returns an mutable reference to the value without checking read-only state. + inline ValueType* mutable_value_unchecked() const { + return const_cast(&const_value()); + } + // Verify that the value can be accessed. - inline bool VerifyAccess(bool modify) { + inline bool VerifyAccess(bool modify) const { // The controller must already be locked. DCHECK(controller()->locked()); diff --git a/libcef/common/values_impl.cc b/libcef/common/values_impl.cc index 7304c3d02..078410a0d 100644 --- a/libcef/common/values_impl.cc +++ b/libcef/common/values_impl.cc @@ -36,7 +36,8 @@ void RemoveEmptyValueDicts(base::Value::Dict& dict) { // static CefRefPtr 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 @@ -53,25 +54,22 @@ CefRefPtr CefValueImpl::GetOrCreateRefOrCopy( } if (value->is_dict()) { - base::DictionaryValue* dict_value = - static_cast(value); return new CefValueImpl(CefDictionaryValueImpl::GetOrCreateRef( - dict_value, parent_value, read_only, controller)); + value, parent_value, read_only, controller)); } if (value->is_list()) { - base::ListValue* list_value = static_cast(value); 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(base::Value* value) { - SetValue(value); +CefValueImpl::CefValueImpl(base::Value value) { + SetValue(std::move(value)); } CefValueImpl::CefValueImpl(CefRefPtr value) @@ -85,12 +83,31 @@ CefValueImpl::CefValueImpl(CefRefPtr value) CefValueImpl::~CefValueImpl() {} -void CefValueImpl::SetValue(base::Value* value) { +void CefValueImpl::SetValue(base::Value value) { 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(binary_value_.get())->CopyValue(); + } + + if (dictionary_value_) { + return static_cast(dictionary_value_.get()) + ->CopyValue(); + } + + if (list_value_) { + return static_cast(list_value_.get())->CopyValue(); + } + + return value_->Clone(); +} + +std::unique_ptr CefValueImpl::CopyOrDetachValue( CefValueController* new_controller) { base::AutoLock lock_scope(lock_); @@ -109,7 +126,7 @@ base::Value* CefValueImpl::CopyOrDetachValue( ->CopyOrDetachValue(new_controller); } - return new base::Value(value_->Clone()); + return std::make_unique(value_->Clone()); } 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); } else if (dictionary_value_) { dictionary_value_ = CefDictionaryValueImpl::GetOrCreateRef( - static_cast(new_value), new_parent_value, false, - new_controller); + new_value, new_parent_value, false, new_controller); } else if (list_value_) { - list_value_ = CefListValueImpl::GetOrCreateRef( - static_cast(new_value), new_parent_value, false, - new_controller); + list_value_ = CefListValueImpl::GetOrCreateRef(new_value, new_parent_value, + false, new_controller); } } @@ -249,7 +264,7 @@ CefRefPtr CefValueImpl::Copy() { return new CefValueImpl(list_value_->Copy()); } if (value_) { - return new CefValueImpl(new base::Value(value_->Clone())); + return new CefValueImpl(value_->Clone()); } return new CefValueImpl(); @@ -345,52 +360,52 @@ CefRefPtr CefValueImpl::GetList() { } bool CefValueImpl::SetNull() { - SetValue(new base::Value()); + SetValue(base::Value()); return true; } bool CefValueImpl::SetBool(bool value) { - SetValue(new base::Value(value)); + SetValue(base::Value(value)); return true; } bool CefValueImpl::SetInt(int value) { - SetValue(new base::Value(value)); + SetValue(base::Value(value)); return true; } bool CefValueImpl::SetDouble(double value) { - SetValue(new base::Value(value)); + SetValue(base::Value(value)); return true; } bool CefValueImpl::SetString(const CefString& value) { - SetValue(new base::Value(value.ToString())); + SetValue(base::Value(value.ToString())); return true; } bool CefValueImpl::SetBinary(CefRefPtr value) { base::AutoLock lock_scope(lock_); - SetValueInternal(nullptr); + SetValueInternal(absl::nullopt); binary_value_ = value; return true; } bool CefValueImpl::SetDictionary(CefRefPtr value) { base::AutoLock lock_scope(lock_); - SetValueInternal(nullptr); + SetValueInternal(absl::nullopt); dictionary_value_ = value; return true; } bool CefValueImpl::SetList(CefRefPtr value) { base::AutoLock lock_scope(lock_); - SetValueInternal(nullptr); + SetValueInternal(absl::nullopt); list_value_ = value; return true; } -void CefValueImpl::SetValueInternal(base::Value* value) { +void CefValueImpl::SetValueInternal(absl::optional value) { lock_.AssertAcquired(); value_.reset(nullptr); @@ -399,20 +414,21 @@ void CefValueImpl::SetValueInternal(base::Value* value) { list_value_ = nullptr; if (value) { - switch (value->type()) { + switch ((*value).type()) { case base::Value::Type::BINARY: - binary_value_ = new CefBinaryValueImpl(value, true); - return; + binary_value_ = new CefBinaryValueImpl(std::move(*value)); + break; case base::Value::Type::DICTIONARY: - dictionary_value_ = new CefDictionaryValueImpl( - static_cast(value), true, false); - return; + dictionary_value_ = + new CefDictionaryValueImpl(std::move(*value), /*read_only=*/false); + break; case base::Value::Type::LIST: - list_value_ = new CefListValueImpl(static_cast(value), - true, false); - return; + list_value_ = + new CefListValueImpl(std::move(*value), /*read_only=*/false); + break; default: - value_.reset(value); + value_ = std::make_unique(std::move(*value)); + break; } } } @@ -499,41 +515,39 @@ CefRefPtr CefBinaryValueImpl::GetOrCreateRef( 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) - : CefValueBase( - value, - nullptr, - will_delete ? kOwnerWillDelete : kOwnerNoDelete, - true, - nullptr) {} + : CefBinaryValueImpl(value, + nullptr, + will_delete ? kOwnerWillDelete : kOwnerNoDelete, + nullptr) {} CefBinaryValueImpl::CefBinaryValueImpl(char* data, size_t data_size) - : CefValueBase( + : CefBinaryValueImpl( new base::Value(std::vector(data, data + data_size)), nullptr, kOwnerWillDelete, - true, nullptr) {} -base::Value* CefBinaryValueImpl::CopyValue() { - CEF_VALUE_VERIFY_RETURN(false, nullptr); - return new base::Value(const_value().Clone()); +base::Value CefBinaryValueImpl::CopyValue() { + CEF_VALUE_VERIFY_RETURN(false, base::Value()); + return const_value().Clone(); } -base::Value* CefBinaryValueImpl::CopyOrDetachValue( +std::unique_ptr CefBinaryValueImpl::CopyOrDetachValue( CefValueController* new_controller) { - base::Value* new_value; - if (!will_delete()) { // Copy the value. - new_value = CopyValue(); - } else { - // Take ownership of the value. - new_value = Detach(new_controller); + return std::make_unique(CopyValue()); } - DCHECK(new_value); - return new_value; + // Take ownership of the value. + auto value = base::WrapUnique(Detach(new_controller)); + DCHECK(value.get()); + return value; } bool CefBinaryValueImpl::IsSameValue(const base::Value* that) { @@ -546,12 +560,12 @@ bool CefBinaryValueImpl::IsEqualValue(const base::Value* that) { return const_value() == *that; } -base::Value* CefBinaryValueImpl::GetValueUnsafe() { +base::Value* CefBinaryValueImpl::GetValueUnsafe() const { if (!VerifyAttached()) { return nullptr; } controller()->AssertLockAcquired(); - return const_cast(&const_value()); + return mutable_value_unchecked(); } bool CefBinaryValueImpl::IsValid() { @@ -590,8 +604,7 @@ bool CefBinaryValueImpl::IsEqual(CefRefPtr that) { CefRefPtr CefBinaryValueImpl::Copy() { CEF_VALUE_VERIFY_RETURN(false, nullptr); - return new CefBinaryValueImpl(new base::Value(const_value().Clone()), nullptr, - CefBinaryValueImpl::kOwnerWillDelete, nullptr); + return new CefBinaryValueImpl(const_value().Clone()); } size_t CefBinaryValueImpl::GetSize() { @@ -629,19 +642,20 @@ CefBinaryValueImpl::CefBinaryValueImpl(base::Value* value, : CefValueBase(value, parent_value, value_mode, - true, + /*read_only=*/true, controller) {} // CefDictionaryValueImpl implementation. // static CefRefPtr CefDictionaryValue::Create() { - return new CefDictionaryValueImpl(new base::DictionaryValue(), true, false); + return new CefDictionaryValueImpl(base::Value(base::Value::Type::DICT), + /*read_only=*/false); } // static CefRefPtr CefDictionaryValueImpl::GetOrCreateRef( - base::DictionaryValue* value, + base::Value* value, void* parent_value, bool read_only, CefValueController* controller) { @@ -655,54 +669,59 @@ CefRefPtr CefDictionaryValueImpl::GetOrCreateRef( 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 read_only) - : CefValueBase( - value, - nullptr, - will_delete ? kOwnerWillDelete : kOwnerNoDelete, - read_only, - nullptr) {} + : CefDictionaryValueImpl(value, + nullptr, + will_delete ? kOwnerWillDelete : kOwnerNoDelete, + read_only, + nullptr) {} -base::DictionaryValue* CefDictionaryValueImpl::CopyValue() { - CEF_VALUE_VERIFY_RETURN(false, nullptr); - return static_cast( - new base::Value(const_value().Clone())); +base::Value CefDictionaryValueImpl::CopyValue() { + CEF_VALUE_VERIFY_RETURN(false, base::Value()); + return const_value().Clone(); } -base::DictionaryValue* CefDictionaryValueImpl::CopyOrDetachValue( +std::unique_ptr CefDictionaryValueImpl::CopyOrDetachValue( CefValueController* new_controller) { - base::DictionaryValue* new_value; - if (!will_delete()) { // Copy the value. - new_value = CopyValue(); - } else { - // Take ownership of the value. - new_value = Detach(new_controller); + return std::make_unique(CopyValue()); } - DCHECK(new_value); - return new_value; + // Take ownership of the value. + auto value = base::WrapUnique(Detach(new_controller)); + DCHECK(value.get()); + return value; } -bool CefDictionaryValueImpl::IsSameValue(const base::DictionaryValue* that) { +bool CefDictionaryValueImpl::IsSameValue(const base::Value* that) { CEF_VALUE_VERIFY_RETURN(false, false); return (&const_value() == that); } -bool CefDictionaryValueImpl::IsEqualValue(const base::DictionaryValue* that) { +bool CefDictionaryValueImpl::IsEqualValue(const base::Value* that) { CEF_VALUE_VERIFY_RETURN(false, false); return const_value() == *that; } -base::DictionaryValue* CefDictionaryValueImpl::GetValueUnsafe() { +base::Value* CefDictionaryValueImpl::GetValueUnsafe() const { if (!VerifyAttached()) { return nullptr; } controller()->AssertLockAcquired(); - return const_cast(&const_value()); + return mutable_value_unchecked(); } bool CefDictionaryValueImpl::IsValid() { @@ -747,19 +766,17 @@ CefRefPtr CefDictionaryValueImpl::Copy( bool exclude_empty_children) { CEF_VALUE_VERIFY_RETURN(false, nullptr); - base::DictionaryValue* value = static_cast( - new base::Value(const_value().Clone())); + auto value = const_value().Clone(); if (exclude_empty_children) { - RemoveEmptyValueDicts(value->GetDict()); + RemoveEmptyValueDicts(value.GetDict()); } - return new CefDictionaryValueImpl( - value, nullptr, CefDictionaryValueImpl::kOwnerWillDelete, false, nullptr); + return new CefDictionaryValueImpl(std::move(value), /*read_only=*/false); } size_t CefDictionaryValueImpl::GetSize() { CEF_VALUE_VERIFY_RETURN(false, 0); - return const_value().DictSize(); + return const_value().GetDict().size(); } bool CefDictionaryValueImpl::Clear() { @@ -774,7 +791,7 @@ bool CefDictionaryValueImpl::Clear() { bool CefDictionaryValueImpl::HasKey(const CefString& key) { 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) { @@ -795,7 +812,8 @@ bool CefDictionaryValueImpl::Remove(const CefString& key) { CefValueType CefDictionaryValueImpl::GetType(const CefString& key) { 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) { switch (value->type()) { case base::Value::Type::NONE: @@ -823,12 +841,12 @@ CefValueType CefDictionaryValueImpl::GetType(const CefString& key) { CefRefPtr CefDictionaryValueImpl::GetValue(const CefString& key) { 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) { - return CefValueImpl::GetOrCreateRefOrCopy( - const_cast(value), - const_cast(&const_value()), read_only(), - controller()); + return CefValueImpl::GetOrCreateRefOrCopy(const_cast(value), + mutable_value_unchecked(), + read_only(), controller()); } return nullptr; @@ -839,7 +857,8 @@ bool CefDictionaryValueImpl::GetBool(const CefString& key) { 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()) { ret_value = value->GetBool(); } @@ -852,7 +871,8 @@ int CefDictionaryValueImpl::GetInt(const CefString& key) { 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()) { ret_value = value->GetInt(); } @@ -865,7 +885,8 @@ double CefDictionaryValueImpl::GetDouble(const CefString& key) { 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()) { ret_value = value->GetDouble(); } @@ -878,7 +899,8 @@ CefString CefDictionaryValueImpl::GetString(const CefString& key) { 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()) { ret_value = value->GetString(); } @@ -890,12 +912,12 @@ CefRefPtr CefDictionaryValueImpl::GetBinary( const CefString& key) { 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()) { base::Value* binary_value = const_cast(value); return CefBinaryValueImpl::GetOrCreateRef( - binary_value, const_cast(&const_value()), - controller()); + binary_value, mutable_value_unchecked(), controller()); } return nullptr; @@ -905,13 +927,12 @@ CefRefPtr CefDictionaryValueImpl::GetDictionary( const CefString& key) { 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()) { - base::DictionaryValue* dict_value = - static_cast(const_cast(value)); + base::Value* dict_value = const_cast(value); return CefDictionaryValueImpl::GetOrCreateRef( - dict_value, const_cast(&const_value()), - read_only(), controller()); + dict_value, mutable_value_unchecked(), read_only(), controller()); } return nullptr; @@ -920,13 +941,12 @@ CefRefPtr CefDictionaryValueImpl::GetDictionary( CefRefPtr CefDictionaryValueImpl::GetList(const CefString& key) { 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()) { - base::ListValue* list_value = - static_cast(const_cast(value)); + base::Value* list_value = const_cast(value); return CefListValueImpl::GetOrCreateRef( - list_value, const_cast(&const_value()), - read_only(), controller()); + list_value, mutable_value_unchecked(), read_only(), controller()); } return nullptr; @@ -939,40 +959,40 @@ bool CefDictionaryValueImpl::SetValue(const CefString& key, CefValueImpl* impl = static_cast(value.get()); DCHECK(impl); - base::Value* new_value = impl->CopyOrDetachValue(controller()); - base::Value* actual_value = SetInternal(key, new_value); + base::Value* actual_value = + SetInternal(key, impl->CopyOrDetachValue(controller())); impl->SwapValue(actual_value, mutable_value(), controller()); return true; } bool CefDictionaryValueImpl::SetNull(const CefString& key) { CEF_VALUE_VERIFY_RETURN(true, false); - SetInternal(key, new base::Value()); + SetInternal(key, std::make_unique()); return true; } bool CefDictionaryValueImpl::SetBool(const CefString& key, bool value) { CEF_VALUE_VERIFY_RETURN(true, false); - SetInternal(key, new base::Value(value)); + SetInternal(key, std::make_unique(value)); return true; } bool CefDictionaryValueImpl::SetInt(const CefString& key, int value) { CEF_VALUE_VERIFY_RETURN(true, false); - SetInternal(key, new base::Value(value)); + SetInternal(key, std::make_unique(value)); return true; } bool CefDictionaryValueImpl::SetDouble(const CefString& key, double value) { CEF_VALUE_VERIFY_RETURN(true, false); - SetInternal(key, new base::Value(value)); + SetInternal(key, std::make_unique(value)); return true; } bool CefDictionaryValueImpl::SetString(const CefString& key, const CefString& value) { CEF_VALUE_VERIFY_RETURN(true, false); - SetInternal(key, new base::Value(value.ToString())); + SetInternal(key, std::make_unique(value.ToString())); return true; } @@ -1018,14 +1038,14 @@ bool CefDictionaryValueImpl::RemoveInternal(const CefString& key) { // retrieve the actual Value pointer as it current exists first, for later // comparison purposes. const base::Value* actual_value = - const_value().FindKey(base::StringPiece(key)); + const_value().GetDict().Find(base::StringPiece(key)); if (!actual_value) { return false; } // |actual_value| is no longer valid after this call. absl::optional out_value = - mutable_value()->ExtractKey(base::StringPiece(key)); + mutable_value()->GetDict().Extract(base::StringPiece(key)); if (!out_value.has_value()) { return false; } @@ -1041,10 +1061,10 @@ bool CefDictionaryValueImpl::RemoveInternal(const CefString& key) { return true; } -base::Value* CefDictionaryValueImpl::SetInternal(const CefString& key, - base::Value* value) { +base::Value* CefDictionaryValueImpl::SetInternal( + const CefString& key, + std::unique_ptr value) { DCHECK(value); - std::unique_ptr valueObj(value); 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 // reference |actual_value| instead. - controller()->Swap(value, actual_value); + controller()->Swap(value.get(), actual_value); return actual_value; } -CefDictionaryValueImpl::CefDictionaryValueImpl(base::DictionaryValue* value, +CefDictionaryValueImpl::CefDictionaryValueImpl(base::Value* value, void* parent_value, ValueMode value_mode, bool read_only, CefValueController* controller) - : CefValueBase(value, - parent_value, - value_mode, - read_only, - controller) {} + : CefValueBase(value, + parent_value, + value_mode, + read_only, + controller) { + DCHECK(value->is_dict()); +} // CefListValueImpl implementation. // static CefRefPtr CefListValue::Create() { - return new CefListValueImpl(new base::ListValue(), true, false); + return new CefListValueImpl(base::Value(base::Value::Type::LIST), + /*read_only=*/false); } // static CefRefPtr CefListValueImpl::GetOrCreateRef( - base::ListValue* value, + base::Value* value, void* parent_value, bool read_only, CefValueController* controller) { @@ -1095,53 +1118,57 @@ CefRefPtr CefListValueImpl::GetOrCreateRef( 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 read_only) - : CefValueBase( - value, - nullptr, - will_delete ? kOwnerWillDelete : kOwnerNoDelete, - read_only, - nullptr) {} + : CefListValueImpl(value, + nullptr, + will_delete ? kOwnerWillDelete : kOwnerNoDelete, + read_only, + nullptr) {} -base::ListValue* CefListValueImpl::CopyValue() { - CEF_VALUE_VERIFY_RETURN(false, nullptr); - return static_cast(new base::Value(const_value().Clone())); +base::Value CefListValueImpl::CopyValue() { + CEF_VALUE_VERIFY_RETURN(false, base::Value()); + return const_value().Clone(); } -base::ListValue* CefListValueImpl::CopyOrDetachValue( +std::unique_ptr CefListValueImpl::CopyOrDetachValue( CefValueController* new_controller) { - base::ListValue* new_value; - if (!will_delete()) { // Copy the value. - new_value = CopyValue(); - } else { - // Take ownership of the value. - new_value = Detach(new_controller); + return std::make_unique(CopyValue()); } - DCHECK(new_value); - return new_value; + // Take ownership of the value. + auto value = base::WrapUnique(Detach(new_controller)); + DCHECK(value.get()); + return value; } -bool CefListValueImpl::IsSameValue(const base::ListValue* that) { +bool CefListValueImpl::IsSameValue(const base::Value* that) { CEF_VALUE_VERIFY_RETURN(false, false); return (&const_value() == that); } -bool CefListValueImpl::IsEqualValue(const base::ListValue* that) { +bool CefListValueImpl::IsEqualValue(const base::Value* that) { CEF_VALUE_VERIFY_RETURN(false, false); return const_value() == *that; } -base::ListValue* CefListValueImpl::GetValueUnsafe() { +base::Value* CefListValueImpl::GetValueUnsafe() const { if (!VerifyAttached()) { return nullptr; } controller()->AssertLockAcquired(); - return const_cast(&const_value()); + return mutable_value_unchecked(); } bool CefListValueImpl::IsValid() { @@ -1185,9 +1212,7 @@ bool CefListValueImpl::IsEqual(CefRefPtr that) { CefRefPtr CefListValueImpl::Copy() { CEF_VALUE_VERIFY_RETURN(false, nullptr); - return new CefListValueImpl( - static_cast(new base::Value(const_value().Clone())), - nullptr, CefListValueImpl::kOwnerWillDelete, false, nullptr); + return new CefListValueImpl(const_value().Clone(), /*read_only=*/false); } bool CefListValueImpl::SetSize(size_t size) { @@ -1205,7 +1230,7 @@ bool CefListValueImpl::SetSize(size_t size) { // for background. auto& list = mutable_value()->GetList(); while (list.size() < size) { - mutable_value()->Append(base::Value()); + list.Append(base::Value()); } } return true; @@ -1266,10 +1291,9 @@ CefRefPtr CefListValueImpl::GetValue(size_t index) { const auto& list = const_value().GetList(); if (index < list.size()) { const base::Value& value = list[index]; - return CefValueImpl::GetOrCreateRefOrCopy( - const_cast(&value), - const_cast(&const_value()), read_only(), - controller()); + return CefValueImpl::GetOrCreateRefOrCopy(const_cast(&value), + mutable_value_unchecked(), + read_only(), controller()); } return nullptr; @@ -1340,12 +1364,10 @@ CefRefPtr CefListValueImpl::GetBinary(size_t index) { const auto& list = const_value().GetList(); if (index < list.size()) { - const base::Value& value = list[index]; + base::Value& value = const_cast(list[index]); if (value.is_blob()) { - base::Value* binary_value = const_cast(&value); return CefBinaryValueImpl::GetOrCreateRef( - binary_value, const_cast(&const_value()), - controller()); + &value, mutable_value_unchecked(), controller()); } } @@ -1357,13 +1379,10 @@ CefRefPtr CefListValueImpl::GetDictionary(size_t index) { const auto& list = const_value().GetList(); if (index < list.size()) { - const base::Value& value = list[index]; + base::Value& value = const_cast(list[index]); if (value.is_dict()) { - base::DictionaryValue* dict_value = - static_cast(const_cast(&value)); return CefDictionaryValueImpl::GetOrCreateRef( - dict_value, const_cast(&const_value()), read_only(), - controller()); + &value, mutable_value_unchecked(), read_only(), controller()); } } @@ -1375,13 +1394,10 @@ CefRefPtr CefListValueImpl::GetList(size_t index) { const auto& list = const_value().GetList(); if (index < list.size()) { - const base::Value& value = list[index]; + base::Value& value = const_cast(list[index]); if (value.is_list()) { - base::ListValue* list_value = - static_cast(const_cast(&value)); - return CefListValueImpl::GetOrCreateRef( - list_value, const_cast(&const_value()), read_only(), - controller()); + return CefListValueImpl::GetOrCreateRef(&value, mutable_value_unchecked(), + read_only(), controller()); } } @@ -1394,39 +1410,39 @@ bool CefListValueImpl::SetValue(size_t index, CefRefPtr value) { CefValueImpl* impl = static_cast(value.get()); DCHECK(impl); - base::Value* new_value = impl->CopyOrDetachValue(controller()); - base::Value* actual_value = SetInternal(index, new_value); + base::Value* actual_value = + SetInternal(index, impl->CopyOrDetachValue(controller())); impl->SwapValue(actual_value, mutable_value(), controller()); return true; } bool CefListValueImpl::SetNull(size_t index) { CEF_VALUE_VERIFY_RETURN(true, false); - SetInternal(index, new base::Value()); + SetInternal(index, std::make_unique()); return true; } bool CefListValueImpl::SetBool(size_t index, bool value) { CEF_VALUE_VERIFY_RETURN(true, false); - SetInternal(index, new base::Value(value)); + SetInternal(index, std::make_unique(value)); return true; } bool CefListValueImpl::SetInt(size_t index, int value) { CEF_VALUE_VERIFY_RETURN(true, false); - SetInternal(index, new base::Value(value)); + SetInternal(index, std::make_unique(value)); return true; } bool CefListValueImpl::SetDouble(size_t index, double value) { CEF_VALUE_VERIFY_RETURN(true, false); - SetInternal(index, new base::Value(value)); + SetInternal(index, std::make_unique(value)); return true; } bool CefListValueImpl::SetString(size_t index, const CefString& value) { CEF_VALUE_VERIFY_RETURN(true, false); - SetInternal(index, new base::Value(value.ToString())); + SetInternal(index, std::make_unique(value.ToString())); return true; } @@ -1491,9 +1507,9 @@ bool CefListValueImpl::RemoveInternal(size_t index) { return true; } -base::Value* CefListValueImpl::SetInternal(size_t index, base::Value* value) { +base::Value* CefListValueImpl::SetInternal(size_t index, + std::unique_ptr value) { DCHECK(value); - std::unique_ptr valueObj(value); auto& list = mutable_value()->GetList(); if (RemoveInternal(index)) { @@ -1505,7 +1521,7 @@ base::Value* CefListValueImpl::SetInternal(size_t index, base::Value* value) { // TODO: This approach seems inefficient. See // https://crbug.com/1187066#c17 for background. while (list.size() <= index) { - mutable_value()->Append(base::Value()); + list.Append(base::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 // reference |actual_value| instead. - controller()->Swap(value, const_cast(&actual_value)); + controller()->Swap(value.get(), const_cast(&actual_value)); return const_cast(&actual_value); } -CefListValueImpl::CefListValueImpl(base::ListValue* value, +CefListValueImpl::CefListValueImpl(base::Value* value, void* parent_value, ValueMode value_mode, bool read_only, CefValueController* controller) - : CefValueBase(value, - parent_value, - value_mode, - read_only, - controller) {} + : CefValueBase(value, + parent_value, + value_mode, + read_only, + controller) { + DCHECK(value->is_list()); +} diff --git a/libcef/common/values_impl.h b/libcef/common/values_impl.h index 841db9474..db43299ae 100644 --- a/libcef/common/values_impl.h +++ b/libcef/common/values_impl.h @@ -6,6 +6,7 @@ #define CEF_LIBCEF_COMMON_VALUES_IMPL_H_ #pragma once +#include #include #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 // (use GetOrCreateRefOrCopy instead). - explicit CefValueImpl(base::Value* value); + explicit CefValueImpl(base::Value value); // Keep a reference to |value|. explicit CefValueImpl(CefRefPtr value); @@ -42,19 +43,23 @@ class CefValueImpl : public CefValue { // Take ownership of |value|. Do not pass in a value owned by something else // (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 // 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 // so we need to perform the copy and swap in two steps. - base::Value* CopyOrDetachValue(CefValueController* new_controller); + [[nodiscard]] std::unique_ptr CopyOrDetachValue( + CefValueController* new_controller); void SwapValue(base::Value* new_value, void* new_parent_value, CefValueController* new_controller); // 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; // CefValue methods. @@ -101,7 +106,7 @@ class CefValueImpl : public CefValue { }; private: - void SetValueInternal(base::Value* value); + void SetValueInternal(absl::optional value); // Returns the controller for the current value, if any. CefValueController* GetValueController() const; @@ -133,6 +138,10 @@ class CefBinaryValueImpl : public CefValueBase { void* parent_value, 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 // of an existing value (set |will_delete| to true). When referencing an // existing value you must explicitly call Detach(nullptr) when |value| is no @@ -148,11 +157,11 @@ class CefBinaryValueImpl : public CefValueBase { CefBinaryValueImpl& operator=(const CefBinaryValueImpl&) = delete; // 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 // transfer ownership of the value. - [[nodiscard]] base::Value* CopyOrDetachValue( + [[nodiscard]] std::unique_ptr CopyOrDetachValue( CefValueController* new_controller); bool IsSameValue(const base::Value* that); @@ -160,7 +169,7 @@ class CefBinaryValueImpl : public CefValueBase { // Returns the underlying value. Access must be protected by calling // lock/unlock on the controller. - base::Value* GetValueUnsafe(); + base::Value* GetValueUnsafe() const; // CefBinaryValue methods. bool IsValid() override; @@ -182,42 +191,45 @@ class CefBinaryValueImpl : public CefValueBase { // CefDictionaryValue implementation class CefDictionaryValueImpl - : public CefValueBase { + : public CefValueBase { public: // Get or create a reference value. static CefRefPtr GetOrCreateRef( - base::DictionaryValue* value, + base::Value* value, void* parent_value, bool read_only, 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 // of an existing value (set |will_delete| to true). When referencing an // existing value you must explicitly call Detach(nullptr) when |value| is no // longer valid. Use GetOrCreateRef instead of this constructor if |value| is // owned by some other object and you do not plan to explicitly call // Detach(nullptr). - CefDictionaryValueImpl(base::DictionaryValue* value, - bool will_delete, - bool read_only); + CefDictionaryValueImpl(base::Value* value, bool will_delete, bool read_only); CefDictionaryValueImpl(const CefDictionaryValueImpl&) = delete; CefDictionaryValueImpl& operator=(const CefDictionaryValueImpl&) = delete; // 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 // transfer ownership of the value. - [[nodiscard]] base::DictionaryValue* CopyOrDetachValue( + [[nodiscard]] std::unique_ptr CopyOrDetachValue( CefValueController* new_controller); - bool IsSameValue(const base::DictionaryValue* that); - bool IsEqualValue(const base::DictionaryValue* that); + bool IsSameValue(const base::Value* that); + bool IsEqualValue(const base::Value* that); // Returns the underlying value. Access must be protected by calling // lock/unlock on the controller. - base::DictionaryValue* GetValueUnsafe(); + base::Value* GetValueUnsafe() const; // CefDictionaryValue methods. bool IsValid() override; @@ -254,50 +266,56 @@ class CefDictionaryValueImpl private: // See the CefValueBase constructor for usage. - CefDictionaryValueImpl(base::DictionaryValue* value, + CefDictionaryValueImpl(base::Value* value, void* parent_value, ValueMode value_mode, bool read_only, CefValueController* controller); bool RemoveInternal(const CefString& key); - base::Value* SetInternal(const CefString& key, base::Value* value); + base::Value* SetInternal(const CefString& key, + std::unique_ptr value); }; // CefListValue implementation -class CefListValueImpl : public CefValueBase { +class CefListValueImpl : public CefValueBase { public: // Get or create a reference value. - static CefRefPtr GetOrCreateRef(base::ListValue* value, + static CefRefPtr GetOrCreateRef(base::Value* value, void* parent_value, bool read_only, 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 // of an existing value (set |will_delete| to true). When referencing an // existing value you must explicitly call Detach(nullptr) when |value| is no // longer valid. Use GetOrCreateRef instead of this constructor if |value| is // owned by some other object and you do not plan to explicitly call // 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& operator=(const CefListValueImpl&) = delete; // 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 // transfer ownership of the value. - [[nodiscard]] base::ListValue* CopyOrDetachValue( + [[nodiscard]] std::unique_ptr CopyOrDetachValue( CefValueController* new_controller); - bool IsSameValue(const base::ListValue* that); - bool IsEqualValue(const base::ListValue* that); + bool IsSameValue(const base::Value* that); + bool IsEqualValue(const base::Value* that); // Returns the underlying value. Access must be protected by calling // lock/unlock on the controller. - base::ListValue* GetValueUnsafe(); + base::Value* GetValueUnsafe() const; // CefListValue methods. bool IsValid() override; @@ -332,14 +350,14 @@ class CefListValueImpl : public CefValueBase { private: // See the CefValueBase constructor for usage. - CefListValueImpl(base::ListValue* value, + CefListValueImpl(base::Value* value, void* parent_value, ValueMode value_mode, bool read_only, CefValueController* controller); bool RemoveInternal(size_t index); - base::Value* SetInternal(size_t index, base::Value* value); + base::Value* SetInternal(size_t index, std::unique_ptr value); }; #endif // CEF_LIBCEF_COMMON_VALUES_IMPL_H_ diff --git a/libcef/renderer/extensions/print_render_frame_helper_delegate.cc b/libcef/renderer/extensions/print_render_frame_helper_delegate.cc index 5452ceaad..690ee3d7d 100644 --- a/libcef/renderer/extensions/print_render_frame_helper_delegate.cc +++ b/libcef/renderer/extensions/print_render_frame_helper_delegate.cc @@ -61,9 +61,9 @@ bool CefPrintRenderFrameHelperDelegate::OverridePrint( // instructs the PDF plugin to print. This is to make window.print() on a // PDF plugin document correctly print the PDF. See // https://crbug.com/448720. - base::DictionaryValue message; - message.SetString("type", "print"); - post_message_support->PostMessageFromValue(message); + base::Value::Dict message; + message.Set("type", "print"); + post_message_support->PostMessageFromValue(base::Value(std::move(message))); return true; } return false; diff --git a/libcef/renderer/frame_impl.cc b/libcef/renderer/frame_impl.cc index d1b9ebac1..18e1ddd0c 100644 --- a/libcef/renderer/frame_impl.cc +++ b/libcef/renderer/frame_impl.cc @@ -290,7 +290,7 @@ void CefFrameImpl::SendProcessMessage(CefProcessId target_process, SendToBrowserFrame( __FUNCTION__, base::BindOnce( - [](const CefString& name, base::ListValue argument_list, + [](const CefString& name, base::Value::List argument_list, const BrowserFrameType& render_frame) { render_frame->SendMessage(name, std::move(argument_list)); }, @@ -732,13 +732,13 @@ void CefFrameImpl::FrameDetached() { 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 handler = app->GetRenderProcessHandler()) { - auto& list_value = base::Value::AsListValue(arguments); - CefRefPtr message(new CefProcessMessageImpl( - name, std::move(const_cast(list_value)), - /*read_only=*/true)); + CefRefPtr message( + new CefProcessMessageImpl(name, std::move(arguments), + /*read_only=*/true)); handler->OnProcessMessageReceived(browser_, this, PID_BROWSER, message.get()); } @@ -835,8 +835,9 @@ void CefFrameImpl::DidStopLoading() { void CefFrameImpl::MoveOrResizeStarted() { if (frame_) { auto web_view = frame_->View(); - if (web_view) + if (web_view) { web_view->CancelPagePopup(); + } } } diff --git a/libcef/renderer/frame_impl.h b/libcef/renderer/frame_impl.h index b6638d89a..39d8de6cb 100644 --- a/libcef/renderer/frame_impl.h +++ b/libcef/renderer/frame_impl.h @@ -149,7 +149,8 @@ class CefFrameImpl // cef::mojom::RenderFrame methods: void FrameAttachedAck() 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, base::ReadOnlySharedMemoryRegion region) override; void SendCommand(const std::string& command) override; diff --git a/libcef/renderer/render_manager.cc b/libcef/renderer/render_manager.cc index 85a9cbb50..3b865186f 100644 --- a/libcef/renderer/render_manager.cc +++ b/libcef/renderer/render_manager.cc @@ -350,15 +350,11 @@ CefRefPtr CefRenderManager::MaybeCreateBrowser( if (handler.get()) { CefRefPtr dictValuePtr; if (params->extra_info) { - auto& dict_value = base::Value::AsDictionaryValue(*params->extra_info); - dictValuePtr = new CefDictionaryValueImpl( - const_cast(&dict_value), - /*will_delete=*/false, /*read_only=*/true); + dictValuePtr = + new CefDictionaryValueImpl(std::move(*params->extra_info), + /*read_only=*/true); } handler->OnBrowserCreated(browser.get(), dictValuePtr.get()); - if (dictValuePtr) { - std::ignore = dictValuePtr->Detach(nullptr); - } } }