2012-04-03 03:34:16 +02:00
|
|
|
// Copyright (c) 2012 The Chromium Embedded Framework Authors. All rights
|
|
|
|
// reserved. Use of this source code is governed by a BSD-style license that
|
|
|
|
// can be found in the LICENSE file.
|
|
|
|
|
|
|
|
#include "libcef/common/values_impl.h"
|
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
#include <vector>
|
|
|
|
|
2016-10-17 20:14:44 +02:00
|
|
|
#include "base/memory/ptr_util.h"
|
|
|
|
|
2022-08-23 03:37:40 +02:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
// Removes empty dictionaries from |dict|, potentially nested.
|
|
|
|
// Does not modify empty lists.
|
|
|
|
// From chrome/browser/chromeos/extensions/echo_private/echo_private_api.cc
|
|
|
|
void RemoveEmptyValueDicts(base::Value::Dict& dict) {
|
|
|
|
auto it = dict.begin();
|
|
|
|
while (it != dict.end()) {
|
|
|
|
base::Value& value = it->second;
|
|
|
|
if (value.is_dict()) {
|
|
|
|
base::Value::Dict& sub_dict = value.GetDict();
|
|
|
|
RemoveEmptyValueDicts(sub_dict);
|
|
|
|
if (sub_dict.empty()) {
|
|
|
|
it = dict.erase(it);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
it++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2015-04-15 15:45:30 +02:00
|
|
|
// CefValueImpl implementation.
|
|
|
|
|
|
|
|
// static
|
|
|
|
CefRefPtr<CefValue> CefValue::Create() {
|
2023-01-30 22:42:40 +01:00
|
|
|
// Start with VTYPE_NULL instead of VTYPE_INVALID for backwards compatibility.
|
|
|
|
return new CefValueImpl(base::Value());
|
2015-04-15 15:45:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
CefRefPtr<CefValue> CefValueImpl::GetOrCreateRefOrCopy(
|
|
|
|
base::Value* value,
|
|
|
|
void* parent_value,
|
|
|
|
bool read_only,
|
|
|
|
CefValueController* controller) {
|
|
|
|
DCHECK(value);
|
|
|
|
|
2018-02-15 01:12:09 +01:00
|
|
|
if (value->is_blob()) {
|
2017-05-17 11:29:28 +02:00
|
|
|
return new CefValueImpl(
|
|
|
|
CefBinaryValueImpl::GetOrCreateRef(value, parent_value, controller));
|
2015-04-15 15:45:30 +02:00
|
|
|
}
|
|
|
|
|
2018-02-15 01:12:09 +01:00
|
|
|
if (value->is_dict()) {
|
2015-04-15 15:45:30 +02:00
|
|
|
return new CefValueImpl(CefDictionaryValueImpl::GetOrCreateRef(
|
2023-01-30 22:42:40 +01:00
|
|
|
value, parent_value, read_only, controller));
|
2015-04-15 15:45:30 +02:00
|
|
|
}
|
|
|
|
|
2018-02-15 01:12:09 +01:00
|
|
|
if (value->is_list()) {
|
2015-04-15 15:45:30 +02:00
|
|
|
return new CefValueImpl(CefListValueImpl::GetOrCreateRef(
|
2023-01-30 22:42:40 +01:00
|
|
|
value, parent_value, read_only, controller));
|
2015-04-15 15:45:30 +02:00
|
|
|
}
|
|
|
|
|
2023-01-30 22:42:40 +01:00
|
|
|
return new CefValueImpl(value->Clone());
|
2015-04-15 15:45:30 +02:00
|
|
|
}
|
|
|
|
|
2024-01-20 23:48:57 +01:00
|
|
|
CefValueImpl::CefValueImpl() = default;
|
2015-04-15 15:45:30 +02:00
|
|
|
|
2023-01-30 22:42:40 +01:00
|
|
|
CefValueImpl::CefValueImpl(base::Value value) {
|
|
|
|
SetValue(std::move(value));
|
2015-04-15 15:45:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
CefValueImpl::CefValueImpl(CefRefPtr<CefBinaryValue> value)
|
2017-05-17 11:29:28 +02:00
|
|
|
: binary_value_(value) {}
|
2015-04-15 15:45:30 +02:00
|
|
|
|
|
|
|
CefValueImpl::CefValueImpl(CefRefPtr<CefDictionaryValue> value)
|
2017-05-17 11:29:28 +02:00
|
|
|
: dictionary_value_(value) {}
|
2015-04-15 15:45:30 +02:00
|
|
|
|
|
|
|
CefValueImpl::CefValueImpl(CefRefPtr<CefListValue> value)
|
2017-05-17 11:29:28 +02:00
|
|
|
: list_value_(value) {}
|
2015-04-15 15:45:30 +02:00
|
|
|
|
2024-01-20 23:48:57 +01:00
|
|
|
CefValueImpl::~CefValueImpl() = default;
|
2015-04-15 15:45:30 +02:00
|
|
|
|
2023-01-30 22:42:40 +01:00
|
|
|
void CefValueImpl::SetValue(base::Value value) {
|
2015-04-15 15:45:30 +02:00
|
|
|
base::AutoLock lock_scope(lock_);
|
2024-03-19 22:11:42 +01:00
|
|
|
SetValueInternal(std::make_optional(std::move(value)));
|
2015-04-15 15:45:30 +02:00
|
|
|
}
|
|
|
|
|
2023-01-30 22:42:40 +01:00
|
|
|
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(
|
2015-04-15 15:45:30 +02:00
|
|
|
CefValueController* new_controller) {
|
|
|
|
base::AutoLock lock_scope(lock_);
|
|
|
|
|
|
|
|
if (binary_value_) {
|
2017-05-17 11:29:28 +02:00
|
|
|
return static_cast<CefBinaryValueImpl*>(binary_value_.get())
|
|
|
|
->CopyOrDetachValue(new_controller);
|
2015-04-15 15:45:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (dictionary_value_) {
|
2017-05-17 11:29:28 +02:00
|
|
|
return static_cast<CefDictionaryValueImpl*>(dictionary_value_.get())
|
|
|
|
->CopyOrDetachValue(new_controller);
|
2015-04-15 15:45:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (list_value_) {
|
2017-05-17 11:29:28 +02:00
|
|
|
return static_cast<CefListValueImpl*>(list_value_.get())
|
|
|
|
->CopyOrDetachValue(new_controller);
|
2015-04-15 15:45:30 +02:00
|
|
|
}
|
|
|
|
|
2023-01-30 22:42:40 +01:00
|
|
|
return std::make_unique<base::Value>(value_->Clone());
|
2015-04-15 15:45:30 +02:00
|
|
|
}
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
void CefValueImpl::SwapValue(base::Value* new_value,
|
|
|
|
void* new_parent_value,
|
|
|
|
CefValueController* new_controller) {
|
2017-04-20 21:28:17 +02:00
|
|
|
base::AutoLock lock_scope(lock_);
|
|
|
|
|
|
|
|
if (binary_value_) {
|
|
|
|
binary_value_ = CefBinaryValueImpl::GetOrCreateRef(
|
|
|
|
new_value, new_parent_value, new_controller);
|
|
|
|
} else if (dictionary_value_) {
|
|
|
|
dictionary_value_ = CefDictionaryValueImpl::GetOrCreateRef(
|
2023-01-30 22:42:40 +01:00
|
|
|
new_value, new_parent_value, false, new_controller);
|
2017-04-20 21:28:17 +02:00
|
|
|
} else if (list_value_) {
|
2023-01-30 22:42:40 +01:00
|
|
|
list_value_ = CefListValueImpl::GetOrCreateRef(new_value, new_parent_value,
|
|
|
|
false, new_controller);
|
2017-04-20 21:28:17 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-15 15:45:30 +02:00
|
|
|
bool CefValueImpl::IsValid() {
|
|
|
|
base::AutoLock lock_scope(lock_);
|
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (binary_value_) {
|
2015-04-15 15:45:30 +02:00
|
|
|
return binary_value_->IsValid();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
|
|
|
if (dictionary_value_) {
|
2015-04-15 15:45:30 +02:00
|
|
|
return dictionary_value_->IsValid();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
|
|
|
if (list_value_) {
|
2015-04-15 15:45:30 +02:00
|
|
|
return list_value_->IsValid();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-04-15 15:45:30 +02:00
|
|
|
|
2020-01-15 14:36:24 +01:00
|
|
|
return (value_ != nullptr);
|
2015-04-15 15:45:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CefValueImpl::IsOwned() {
|
|
|
|
base::AutoLock lock_scope(lock_);
|
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (binary_value_) {
|
2015-04-15 15:45:30 +02:00
|
|
|
return binary_value_->IsOwned();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
|
|
|
if (dictionary_value_) {
|
2015-04-15 15:45:30 +02:00
|
|
|
return dictionary_value_->IsOwned();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
|
|
|
if (list_value_) {
|
2015-04-15 15:45:30 +02:00
|
|
|
return list_value_->IsOwned();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-04-15 15:45:30 +02:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefValueImpl::IsReadOnly() {
|
|
|
|
base::AutoLock lock_scope(lock_);
|
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (binary_value_) {
|
2015-04-15 15:45:30 +02:00
|
|
|
return true;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
|
|
|
if (dictionary_value_) {
|
2015-04-15 15:45:30 +02:00
|
|
|
return dictionary_value_->IsReadOnly();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
|
|
|
if (list_value_) {
|
2015-04-15 15:45:30 +02:00
|
|
|
return list_value_->IsReadOnly();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-04-15 15:45:30 +02:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefValueImpl::IsSame(CefRefPtr<CefValue> that) {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (that.get() == this) {
|
2015-04-15 15:45:30 +02:00
|
|
|
return true;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
|
|
|
if (!that.get() || that->GetType() != GetType()) {
|
2015-04-15 15:45:30 +02:00
|
|
|
return false;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-04-15 15:45:30 +02:00
|
|
|
|
|
|
|
CefValueImpl* impl = static_cast<CefValueImpl*>(that.get());
|
|
|
|
|
|
|
|
base::AutoLock lock_scope(lock_);
|
|
|
|
base::AutoLock lock_scope2(impl->lock_);
|
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (binary_value_) {
|
2015-04-15 15:45:30 +02:00
|
|
|
return binary_value_->IsSame(impl->binary_value_);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
|
|
|
if (dictionary_value_) {
|
2015-04-15 15:45:30 +02:00
|
|
|
return dictionary_value_->IsSame(impl->dictionary_value_);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
|
|
|
if (list_value_) {
|
2015-04-15 15:45:30 +02:00
|
|
|
return list_value_->IsSame(impl->list_value_);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-04-15 15:45:30 +02:00
|
|
|
|
|
|
|
// Simple types are never the same.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefValueImpl::IsEqual(CefRefPtr<CefValue> that) {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (that.get() == this) {
|
2015-04-15 15:45:30 +02:00
|
|
|
return true;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
|
|
|
if (!that.get() || that->GetType() != GetType()) {
|
2015-04-15 15:45:30 +02:00
|
|
|
return false;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-04-15 15:45:30 +02:00
|
|
|
|
|
|
|
CefValueImpl* impl = static_cast<CefValueImpl*>(that.get());
|
|
|
|
|
|
|
|
base::AutoLock lock_scope(lock_);
|
|
|
|
base::AutoLock lock_scope2(impl->lock_);
|
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (binary_value_) {
|
2015-04-15 15:45:30 +02:00
|
|
|
return binary_value_->IsEqual(impl->binary_value_);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
|
|
|
if (dictionary_value_) {
|
2015-04-15 15:45:30 +02:00
|
|
|
return dictionary_value_->IsEqual(impl->dictionary_value_);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
|
|
|
if (list_value_) {
|
2015-04-15 15:45:30 +02:00
|
|
|
return list_value_->IsEqual(impl->list_value_);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-04-15 15:45:30 +02:00
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!value_) { // Invalid types are equal.
|
2015-04-15 15:45:30 +02:00
|
|
|
return true;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-04-15 15:45:30 +02:00
|
|
|
|
2022-07-25 19:49:32 +02:00
|
|
|
return *value_ == *(impl->value_.get());
|
2015-04-15 15:45:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
CefRefPtr<CefValue> CefValueImpl::Copy() {
|
|
|
|
base::AutoLock lock_scope(lock_);
|
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (binary_value_) {
|
2015-04-15 15:45:30 +02:00
|
|
|
return new CefValueImpl(binary_value_->Copy());
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
|
|
|
if (dictionary_value_) {
|
2015-04-15 15:45:30 +02:00
|
|
|
return new CefValueImpl(dictionary_value_->Copy(false));
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
|
|
|
if (list_value_) {
|
2015-04-15 15:45:30 +02:00
|
|
|
return new CefValueImpl(list_value_->Copy());
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
|
|
|
if (value_) {
|
2023-01-30 22:42:40 +01:00
|
|
|
return new CefValueImpl(value_->Clone());
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-04-15 15:45:30 +02:00
|
|
|
|
|
|
|
return new CefValueImpl();
|
|
|
|
}
|
|
|
|
|
|
|
|
CefValueType CefValueImpl::GetType() {
|
|
|
|
base::AutoLock lock_scope(lock_);
|
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (binary_value_) {
|
2015-04-15 15:45:30 +02:00
|
|
|
return VTYPE_BINARY;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
|
|
|
if (dictionary_value_) {
|
2015-04-15 15:45:30 +02:00
|
|
|
return VTYPE_DICTIONARY;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
|
|
|
if (list_value_) {
|
2015-04-15 15:45:30 +02:00
|
|
|
return VTYPE_LIST;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-04-15 15:45:30 +02:00
|
|
|
|
|
|
|
if (value_) {
|
2017-12-07 22:44:24 +01:00
|
|
|
switch (value_->type()) {
|
2017-01-23 18:36:54 +01:00
|
|
|
case base::Value::Type::NONE:
|
2015-04-15 15:45:30 +02:00
|
|
|
return VTYPE_NULL;
|
2017-01-23 18:36:54 +01:00
|
|
|
case base::Value::Type::BOOLEAN:
|
2015-04-15 15:45:30 +02:00
|
|
|
return VTYPE_BOOL;
|
2017-01-23 18:36:54 +01:00
|
|
|
case base::Value::Type::INTEGER:
|
2015-04-15 15:45:30 +02:00
|
|
|
return VTYPE_INT;
|
2017-01-23 18:36:54 +01:00
|
|
|
case base::Value::Type::DOUBLE:
|
2015-04-15 15:45:30 +02:00
|
|
|
return VTYPE_DOUBLE;
|
2017-01-23 18:36:54 +01:00
|
|
|
case base::Value::Type::STRING:
|
2015-04-15 15:45:30 +02:00
|
|
|
return VTYPE_STRING;
|
|
|
|
default:
|
2023-05-08 17:07:57 +02:00
|
|
|
DCHECK(false);
|
2015-04-15 15:45:30 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return VTYPE_INVALID;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefValueImpl::GetBool() {
|
|
|
|
base::AutoLock lock_scope(lock_);
|
|
|
|
|
|
|
|
bool ret_value = false;
|
2023-01-02 23:59:03 +01:00
|
|
|
if (value_ && value_->is_bool()) {
|
2021-07-23 18:40:13 +02:00
|
|
|
ret_value = value_->GetBool();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-04-15 15:45:30 +02:00
|
|
|
return ret_value;
|
|
|
|
}
|
|
|
|
|
|
|
|
int CefValueImpl::GetInt() {
|
|
|
|
base::AutoLock lock_scope(lock_);
|
|
|
|
|
|
|
|
int ret_value = 0;
|
2023-01-02 23:59:03 +01:00
|
|
|
if (value_ && value_->is_int()) {
|
2021-07-23 18:40:13 +02:00
|
|
|
ret_value = value_->GetInt();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-04-15 15:45:30 +02:00
|
|
|
return ret_value;
|
|
|
|
}
|
|
|
|
|
|
|
|
double CefValueImpl::GetDouble() {
|
|
|
|
base::AutoLock lock_scope(lock_);
|
|
|
|
|
|
|
|
double ret_value = 0;
|
2023-01-02 23:59:03 +01:00
|
|
|
if (value_ && value_->is_double()) {
|
2021-07-23 18:40:13 +02:00
|
|
|
ret_value = value_->GetDouble();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-04-15 15:45:30 +02:00
|
|
|
return ret_value;
|
|
|
|
}
|
|
|
|
|
|
|
|
CefString CefValueImpl::GetString() {
|
|
|
|
base::AutoLock lock_scope(lock_);
|
|
|
|
|
|
|
|
std::string ret_value;
|
2023-01-02 23:59:03 +01:00
|
|
|
if (value_ && value_->is_string()) {
|
2021-07-23 18:40:13 +02:00
|
|
|
ret_value = value_->GetString();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-04-15 15:45:30 +02:00
|
|
|
return ret_value;
|
|
|
|
}
|
|
|
|
|
|
|
|
CefRefPtr<CefBinaryValue> CefValueImpl::GetBinary() {
|
|
|
|
base::AutoLock lock_scope(lock_);
|
|
|
|
return binary_value_;
|
|
|
|
}
|
|
|
|
|
|
|
|
CefRefPtr<CefDictionaryValue> CefValueImpl::GetDictionary() {
|
|
|
|
base::AutoLock lock_scope(lock_);
|
|
|
|
return dictionary_value_;
|
|
|
|
}
|
|
|
|
|
|
|
|
CefRefPtr<CefListValue> CefValueImpl::GetList() {
|
|
|
|
base::AutoLock lock_scope(lock_);
|
|
|
|
return list_value_;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefValueImpl::SetNull() {
|
2023-01-30 22:42:40 +01:00
|
|
|
SetValue(base::Value());
|
2015-04-15 15:45:30 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefValueImpl::SetBool(bool value) {
|
2023-01-30 22:42:40 +01:00
|
|
|
SetValue(base::Value(value));
|
2015-04-15 15:45:30 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefValueImpl::SetInt(int value) {
|
2023-01-30 22:42:40 +01:00
|
|
|
SetValue(base::Value(value));
|
2015-04-15 15:45:30 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefValueImpl::SetDouble(double value) {
|
2023-01-30 22:42:40 +01:00
|
|
|
SetValue(base::Value(value));
|
2015-04-15 15:45:30 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefValueImpl::SetString(const CefString& value) {
|
2023-01-30 22:42:40 +01:00
|
|
|
SetValue(base::Value(value.ToString()));
|
2015-04-15 15:45:30 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefValueImpl::SetBinary(CefRefPtr<CefBinaryValue> value) {
|
|
|
|
base::AutoLock lock_scope(lock_);
|
2024-03-19 22:11:42 +01:00
|
|
|
SetValueInternal(std::nullopt);
|
2015-04-15 15:45:30 +02:00
|
|
|
binary_value_ = value;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefValueImpl::SetDictionary(CefRefPtr<CefDictionaryValue> value) {
|
|
|
|
base::AutoLock lock_scope(lock_);
|
2024-03-19 22:11:42 +01:00
|
|
|
SetValueInternal(std::nullopt);
|
2015-04-15 15:45:30 +02:00
|
|
|
dictionary_value_ = value;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefValueImpl::SetList(CefRefPtr<CefListValue> value) {
|
|
|
|
base::AutoLock lock_scope(lock_);
|
2024-03-19 22:11:42 +01:00
|
|
|
SetValueInternal(std::nullopt);
|
2015-04-15 15:45:30 +02:00
|
|
|
list_value_ = value;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2024-03-19 22:11:42 +01:00
|
|
|
void CefValueImpl::SetValueInternal(std::optional<base::Value> value) {
|
2015-04-15 15:45:30 +02:00
|
|
|
lock_.AssertAcquired();
|
|
|
|
|
2020-01-15 14:36:24 +01:00
|
|
|
value_.reset(nullptr);
|
|
|
|
binary_value_ = nullptr;
|
|
|
|
dictionary_value_ = nullptr;
|
|
|
|
list_value_ = nullptr;
|
2015-04-15 15:45:30 +02:00
|
|
|
|
|
|
|
if (value) {
|
2023-01-30 22:42:40 +01:00
|
|
|
switch ((*value).type()) {
|
2017-01-23 18:36:54 +01:00
|
|
|
case base::Value::Type::BINARY:
|
2023-01-30 22:42:40 +01:00
|
|
|
binary_value_ = new CefBinaryValueImpl(std::move(*value));
|
|
|
|
break;
|
2023-02-27 19:52:38 +01:00
|
|
|
case base::Value::Type::DICT:
|
2023-01-30 22:42:40 +01:00
|
|
|
dictionary_value_ =
|
|
|
|
new CefDictionaryValueImpl(std::move(*value), /*read_only=*/false);
|
|
|
|
break;
|
2017-01-23 18:36:54 +01:00
|
|
|
case base::Value::Type::LIST:
|
2023-01-30 22:42:40 +01:00
|
|
|
list_value_ =
|
|
|
|
new CefListValueImpl(std::move(*value), /*read_only=*/false);
|
|
|
|
break;
|
2015-04-15 15:45:30 +02:00
|
|
|
default:
|
2023-01-30 22:42:40 +01:00
|
|
|
value_ = std::make_unique<base::Value>(std::move(*value));
|
|
|
|
break;
|
2015-04-15 15:45:30 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-17 16:19:30 +02:00
|
|
|
CefValueController* CefValueImpl::GetValueController() const {
|
|
|
|
lock_.AssertAcquired();
|
|
|
|
|
|
|
|
if (binary_value_) {
|
|
|
|
return static_cast<CefBinaryValueImpl*>(binary_value_.get())->controller();
|
|
|
|
} else if (dictionary_value_) {
|
2017-05-17 11:29:28 +02:00
|
|
|
return static_cast<CefDictionaryValueImpl*>(dictionary_value_.get())
|
|
|
|
->controller();
|
2015-04-17 16:19:30 +02:00
|
|
|
} else if (list_value_) {
|
|
|
|
return static_cast<CefListValueImpl*>(list_value_.get())->controller();
|
|
|
|
}
|
|
|
|
|
2020-01-15 14:36:24 +01:00
|
|
|
return nullptr;
|
2015-04-17 16:19:30 +02:00
|
|
|
}
|
|
|
|
|
2020-03-30 22:13:42 +02:00
|
|
|
void CefValueImpl::AcquireLock() NO_THREAD_SAFETY_ANALYSIS {
|
2015-04-17 16:19:30 +02:00
|
|
|
lock_.Acquire();
|
|
|
|
|
|
|
|
CefValueController* controller = GetValueController();
|
2023-01-02 23:59:03 +01:00
|
|
|
if (controller) {
|
2015-04-17 16:19:30 +02:00
|
|
|
controller->lock();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-04-17 16:19:30 +02:00
|
|
|
}
|
|
|
|
|
2020-03-30 22:13:42 +02:00
|
|
|
void CefValueImpl::ReleaseLock() NO_THREAD_SAFETY_ANALYSIS {
|
2015-04-17 16:19:30 +02:00
|
|
|
CefValueController* controller = GetValueController();
|
|
|
|
if (controller) {
|
|
|
|
controller->AssertLockAcquired();
|
|
|
|
controller->unlock();
|
|
|
|
}
|
|
|
|
|
|
|
|
lock_.Release();
|
|
|
|
}
|
|
|
|
|
|
|
|
base::Value* CefValueImpl::GetValueUnsafe() const {
|
|
|
|
lock_.AssertAcquired();
|
|
|
|
|
|
|
|
if (binary_value_) {
|
2017-05-17 11:29:28 +02:00
|
|
|
return static_cast<CefBinaryValueImpl*>(binary_value_.get())
|
|
|
|
->GetValueUnsafe();
|
2015-04-17 16:19:30 +02:00
|
|
|
} else if (dictionary_value_) {
|
2017-05-17 11:29:28 +02:00
|
|
|
return static_cast<CefDictionaryValueImpl*>(dictionary_value_.get())
|
|
|
|
->GetValueUnsafe();
|
2015-04-17 16:19:30 +02:00
|
|
|
} else if (list_value_) {
|
|
|
|
return static_cast<CefListValueImpl*>(list_value_.get())->GetValueUnsafe();
|
|
|
|
}
|
|
|
|
|
|
|
|
return value_.get();
|
|
|
|
}
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
// CefBinaryValueImpl implementation.
|
|
|
|
|
|
|
|
CefRefPtr<CefBinaryValue> CefBinaryValue::Create(const void* data,
|
|
|
|
size_t data_size) {
|
|
|
|
DCHECK(data);
|
|
|
|
DCHECK_GT(data_size, (size_t)0);
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!data || data_size == 0) {
|
2020-01-15 14:36:24 +01:00
|
|
|
return nullptr;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2023-10-05 18:57:01 +02:00
|
|
|
const auto ptr = static_cast<const uint8_t*>(data);
|
|
|
|
return new CefBinaryValueImpl(base::make_span(ptr, data_size));
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
CefRefPtr<CefBinaryValue> CefBinaryValueImpl::GetOrCreateRef(
|
2017-05-17 11:29:28 +02:00
|
|
|
base::Value* value,
|
|
|
|
void* parent_value,
|
|
|
|
CefValueController* controller) {
|
2012-04-03 03:34:16 +02:00
|
|
|
DCHECK(value);
|
|
|
|
DCHECK(parent_value);
|
|
|
|
DCHECK(controller);
|
|
|
|
|
|
|
|
CefValueController::Object* object = controller->Get(value);
|
2023-01-02 23:59:03 +01:00
|
|
|
if (object) {
|
2012-04-03 03:34:16 +02:00
|
|
|
return static_cast<CefBinaryValueImpl*>(object);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
return new CefBinaryValueImpl(value, parent_value,
|
2017-05-17 11:29:28 +02:00
|
|
|
CefBinaryValueImpl::kReference, controller);
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2023-01-30 22:42:40 +01:00
|
|
|
CefBinaryValueImpl::CefBinaryValueImpl(base::Value value)
|
|
|
|
: CefBinaryValueImpl(new base::Value(std::move(value)),
|
|
|
|
/*will_delete=*/true) {}
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
CefBinaryValueImpl::CefBinaryValueImpl(base::Value* value, bool will_delete)
|
2023-01-30 22:42:40 +01:00
|
|
|
: CefBinaryValueImpl(value,
|
|
|
|
nullptr,
|
|
|
|
will_delete ? kOwnerWillDelete : kOwnerNoDelete,
|
|
|
|
nullptr) {}
|
2015-04-15 15:45:30 +02:00
|
|
|
|
2023-10-05 18:57:01 +02:00
|
|
|
CefBinaryValueImpl::CefBinaryValueImpl(base::span<const uint8_t> value)
|
|
|
|
: CefBinaryValueImpl(new base::Value(value),
|
|
|
|
nullptr,
|
|
|
|
kOwnerWillDelete,
|
|
|
|
nullptr) {}
|
2012-11-20 21:08:36 +01:00
|
|
|
|
2023-01-30 22:42:40 +01:00
|
|
|
base::Value CefBinaryValueImpl::CopyValue() {
|
|
|
|
CEF_VALUE_VERIFY_RETURN(false, base::Value());
|
|
|
|
return const_value().Clone();
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2023-01-30 22:42:40 +01:00
|
|
|
std::unique_ptr<base::Value> CefBinaryValueImpl::CopyOrDetachValue(
|
2012-04-03 03:34:16 +02:00
|
|
|
CefValueController* new_controller) {
|
|
|
|
if (!will_delete()) {
|
|
|
|
// Copy the value.
|
2023-01-30 22:42:40 +01:00
|
|
|
return std::make_unique<base::Value>(CopyValue());
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2023-01-30 22:42:40 +01:00
|
|
|
// Take ownership of the value.
|
|
|
|
auto value = base::WrapUnique(Detach(new_controller));
|
|
|
|
DCHECK(value.get());
|
|
|
|
return value;
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2017-04-20 21:28:17 +02:00
|
|
|
bool CefBinaryValueImpl::IsSameValue(const base::Value* that) {
|
2015-04-15 15:45:30 +02:00
|
|
|
CEF_VALUE_VERIFY_RETURN(false, false);
|
|
|
|
return (&const_value() == that);
|
|
|
|
}
|
|
|
|
|
2017-04-20 21:28:17 +02:00
|
|
|
bool CefBinaryValueImpl::IsEqualValue(const base::Value* that) {
|
2015-04-15 15:45:30 +02:00
|
|
|
CEF_VALUE_VERIFY_RETURN(false, false);
|
2022-07-25 19:49:32 +02:00
|
|
|
return const_value() == *that;
|
2015-04-15 15:45:30 +02:00
|
|
|
}
|
|
|
|
|
2023-01-30 22:42:40 +01:00
|
|
|
base::Value* CefBinaryValueImpl::GetValueUnsafe() const {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!VerifyAttached()) {
|
2020-01-15 14:36:24 +01:00
|
|
|
return nullptr;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-04-17 16:19:30 +02:00
|
|
|
controller()->AssertLockAcquired();
|
2023-01-30 22:42:40 +01:00
|
|
|
return mutable_value_unchecked();
|
2015-04-17 16:19:30 +02:00
|
|
|
}
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
bool CefBinaryValueImpl::IsValid() {
|
|
|
|
return !detached();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefBinaryValueImpl::IsOwned() {
|
|
|
|
return !will_delete();
|
|
|
|
}
|
|
|
|
|
2015-04-15 15:45:30 +02:00
|
|
|
bool CefBinaryValueImpl::IsSame(CefRefPtr<CefBinaryValue> that) {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!that.get()) {
|
2015-04-15 15:45:30 +02:00
|
|
|
return false;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
|
|
|
if (that.get() == this) {
|
2015-04-15 15:45:30 +02:00
|
|
|
return true;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-04-15 15:45:30 +02:00
|
|
|
|
|
|
|
CEF_VALUE_VERIFY_RETURN(false, false);
|
2017-05-17 11:29:28 +02:00
|
|
|
return static_cast<CefBinaryValueImpl*>(that.get())
|
|
|
|
->IsSameValue(&const_value());
|
2015-04-15 15:45:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CefBinaryValueImpl::IsEqual(CefRefPtr<CefBinaryValue> that) {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!that.get()) {
|
2015-04-15 15:45:30 +02:00
|
|
|
return false;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
|
|
|
if (that.get() == this) {
|
2015-04-15 15:45:30 +02:00
|
|
|
return true;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-04-15 15:45:30 +02:00
|
|
|
|
|
|
|
CEF_VALUE_VERIFY_RETURN(false, false);
|
2017-05-17 11:29:28 +02:00
|
|
|
return static_cast<CefBinaryValueImpl*>(that.get())
|
|
|
|
->IsEqualValue(&const_value());
|
2015-04-15 15:45:30 +02:00
|
|
|
}
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
CefRefPtr<CefBinaryValue> CefBinaryValueImpl::Copy() {
|
2020-01-15 14:36:24 +01:00
|
|
|
CEF_VALUE_VERIFY_RETURN(false, nullptr);
|
2023-01-30 22:42:40 +01:00
|
|
|
return new CefBinaryValueImpl(const_value().Clone());
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2023-10-25 20:20:55 +02:00
|
|
|
const void* CefBinaryValueImpl::GetRawData() {
|
|
|
|
CEF_VALUE_VERIFY_RETURN(false, nullptr);
|
|
|
|
return const_value().GetBlob().data();
|
|
|
|
}
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
size_t CefBinaryValueImpl::GetSize() {
|
|
|
|
CEF_VALUE_VERIFY_RETURN(false, 0);
|
2017-05-31 17:33:30 +02:00
|
|
|
return const_value().GetBlob().size();
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
size_t CefBinaryValueImpl::GetData(void* buffer,
|
|
|
|
size_t buffer_size,
|
|
|
|
size_t data_offset) {
|
|
|
|
DCHECK(buffer);
|
|
|
|
DCHECK_GT(buffer_size, (size_t)0);
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!buffer || buffer_size == 0) {
|
2012-04-03 03:34:16 +02:00
|
|
|
return 0;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
CEF_VALUE_VERIFY_RETURN(false, 0);
|
|
|
|
|
2017-05-31 17:33:30 +02:00
|
|
|
size_t size = const_value().GetBlob().size();
|
2012-04-03 03:34:16 +02:00
|
|
|
DCHECK_LT(data_offset, size);
|
2023-01-02 23:59:03 +01:00
|
|
|
if (data_offset >= size) {
|
2012-04-03 03:34:16 +02:00
|
|
|
return 0;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
size = std::min(buffer_size, size - data_offset);
|
2018-07-31 21:21:39 +02:00
|
|
|
auto* data = const_value().GetBlob().data();
|
2017-05-17 11:29:28 +02:00
|
|
|
memcpy(buffer, data + data_offset, size);
|
2012-04-03 03:34:16 +02:00
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
2017-04-20 21:28:17 +02:00
|
|
|
CefBinaryValueImpl::CefBinaryValueImpl(base::Value* value,
|
2012-04-03 03:34:16 +02:00
|
|
|
void* parent_value,
|
|
|
|
ValueMode value_mode,
|
|
|
|
CefValueController* controller)
|
2017-05-17 11:29:28 +02:00
|
|
|
: CefValueBase<CefBinaryValue, base::Value>(value,
|
|
|
|
parent_value,
|
|
|
|
value_mode,
|
2023-01-30 22:42:40 +01:00
|
|
|
/*read_only=*/true,
|
2017-05-17 11:29:28 +02:00
|
|
|
controller) {}
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
// CefDictionaryValueImpl implementation.
|
|
|
|
|
|
|
|
// static
|
|
|
|
CefRefPtr<CefDictionaryValue> CefDictionaryValue::Create() {
|
2023-01-30 22:42:40 +01:00
|
|
|
return new CefDictionaryValueImpl(base::Value(base::Value::Type::DICT),
|
|
|
|
/*read_only=*/false);
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
CefRefPtr<CefDictionaryValue> CefDictionaryValueImpl::GetOrCreateRef(
|
2023-01-30 22:42:40 +01:00
|
|
|
base::Value* value,
|
2012-04-03 03:34:16 +02:00
|
|
|
void* parent_value,
|
|
|
|
bool read_only,
|
|
|
|
CefValueController* controller) {
|
|
|
|
CefValueController::Object* object = controller->Get(value);
|
2023-01-02 23:59:03 +01:00
|
|
|
if (object) {
|
2012-04-03 03:34:16 +02:00
|
|
|
return static_cast<CefDictionaryValueImpl*>(object);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
return new CefDictionaryValueImpl(value, parent_value,
|
2017-05-17 11:29:28 +02:00
|
|
|
CefDictionaryValueImpl::kReference,
|
|
|
|
read_only, controller);
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2023-01-30 22:42:40 +01:00
|
|
|
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,
|
2012-11-20 21:08:36 +01:00
|
|
|
bool will_delete,
|
|
|
|
bool read_only)
|
2023-01-30 22:42:40 +01:00
|
|
|
: CefDictionaryValueImpl(value,
|
|
|
|
nullptr,
|
|
|
|
will_delete ? kOwnerWillDelete : kOwnerNoDelete,
|
|
|
|
read_only,
|
|
|
|
nullptr) {}
|
2012-11-20 21:08:36 +01:00
|
|
|
|
2023-01-30 22:42:40 +01:00
|
|
|
base::Value CefDictionaryValueImpl::CopyValue() {
|
|
|
|
CEF_VALUE_VERIFY_RETURN(false, base::Value());
|
|
|
|
return const_value().Clone();
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2023-01-30 22:42:40 +01:00
|
|
|
std::unique_ptr<base::Value> CefDictionaryValueImpl::CopyOrDetachValue(
|
2012-04-03 03:34:16 +02:00
|
|
|
CefValueController* new_controller) {
|
|
|
|
if (!will_delete()) {
|
|
|
|
// Copy the value.
|
2023-01-30 22:42:40 +01:00
|
|
|
return std::make_unique<base::Value>(CopyValue());
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2023-01-30 22:42:40 +01:00
|
|
|
// Take ownership of the value.
|
|
|
|
auto value = base::WrapUnique(Detach(new_controller));
|
|
|
|
DCHECK(value.get());
|
|
|
|
return value;
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2023-01-30 22:42:40 +01:00
|
|
|
bool CefDictionaryValueImpl::IsSameValue(const base::Value* that) {
|
2015-04-15 15:45:30 +02:00
|
|
|
CEF_VALUE_VERIFY_RETURN(false, false);
|
|
|
|
return (&const_value() == that);
|
|
|
|
}
|
|
|
|
|
2023-01-30 22:42:40 +01:00
|
|
|
bool CefDictionaryValueImpl::IsEqualValue(const base::Value* that) {
|
2015-04-15 15:45:30 +02:00
|
|
|
CEF_VALUE_VERIFY_RETURN(false, false);
|
2022-07-25 19:49:32 +02:00
|
|
|
return const_value() == *that;
|
2015-04-15 15:45:30 +02:00
|
|
|
}
|
|
|
|
|
2023-01-30 22:42:40 +01:00
|
|
|
base::Value* CefDictionaryValueImpl::GetValueUnsafe() const {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!VerifyAttached()) {
|
2020-01-15 14:36:24 +01:00
|
|
|
return nullptr;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-04-17 16:19:30 +02:00
|
|
|
controller()->AssertLockAcquired();
|
2023-01-30 22:42:40 +01:00
|
|
|
return mutable_value_unchecked();
|
2015-04-17 16:19:30 +02:00
|
|
|
}
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
bool CefDictionaryValueImpl::IsValid() {
|
|
|
|
return !detached();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefDictionaryValueImpl::IsOwned() {
|
|
|
|
return !will_delete();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefDictionaryValueImpl::IsReadOnly() {
|
|
|
|
return read_only();
|
|
|
|
}
|
|
|
|
|
2015-04-15 15:45:30 +02:00
|
|
|
bool CefDictionaryValueImpl::IsSame(CefRefPtr<CefDictionaryValue> that) {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!that.get()) {
|
2015-04-15 15:45:30 +02:00
|
|
|
return false;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
|
|
|
if (that.get() == this) {
|
2015-04-15 15:45:30 +02:00
|
|
|
return true;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-04-15 15:45:30 +02:00
|
|
|
|
|
|
|
CEF_VALUE_VERIFY_RETURN(false, false);
|
2017-05-17 11:29:28 +02:00
|
|
|
return static_cast<CefDictionaryValueImpl*>(that.get())
|
|
|
|
->IsSameValue(&const_value());
|
2015-04-15 15:45:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CefDictionaryValueImpl::IsEqual(CefRefPtr<CefDictionaryValue> that) {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!that.get()) {
|
2015-04-15 15:45:30 +02:00
|
|
|
return false;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
|
|
|
if (that.get() == this) {
|
2015-04-15 15:45:30 +02:00
|
|
|
return true;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-04-15 15:45:30 +02:00
|
|
|
|
|
|
|
CEF_VALUE_VERIFY_RETURN(false, false);
|
2017-05-17 11:29:28 +02:00
|
|
|
return static_cast<CefDictionaryValueImpl*>(that.get())
|
|
|
|
->IsEqualValue(&const_value());
|
2015-04-15 15:45:30 +02:00
|
|
|
}
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
CefRefPtr<CefDictionaryValue> CefDictionaryValueImpl::Copy(
|
|
|
|
bool exclude_empty_children) {
|
2020-01-15 14:36:24 +01:00
|
|
|
CEF_VALUE_VERIFY_RETURN(false, nullptr);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2023-01-30 22:42:40 +01:00
|
|
|
auto value = const_value().Clone();
|
2012-04-03 03:34:16 +02:00
|
|
|
if (exclude_empty_children) {
|
2023-01-30 22:42:40 +01:00
|
|
|
RemoveEmptyValueDicts(value.GetDict());
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2023-01-30 22:42:40 +01:00
|
|
|
return new CefDictionaryValueImpl(std::move(value), /*read_only=*/false);
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
size_t CefDictionaryValueImpl::GetSize() {
|
|
|
|
CEF_VALUE_VERIFY_RETURN(false, 0);
|
2023-01-30 22:42:40 +01:00
|
|
|
return const_value().GetDict().size();
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CefDictionaryValueImpl::Clear() {
|
|
|
|
CEF_VALUE_VERIFY_RETURN(true, false);
|
|
|
|
|
|
|
|
// Detach any dependent values.
|
|
|
|
controller()->RemoveDependencies(mutable_value());
|
|
|
|
|
2023-01-03 00:34:43 +01:00
|
|
|
mutable_value()->GetDict().clear();
|
2012-04-03 03:34:16 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefDictionaryValueImpl::HasKey(const CefString& key) {
|
|
|
|
CEF_VALUE_VERIFY_RETURN(false, 0);
|
2023-07-21 00:11:34 +02:00
|
|
|
return const_value().GetDict().contains(base::StringPiece(key.ToString()));
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CefDictionaryValueImpl::GetKeys(KeyList& keys) {
|
|
|
|
CEF_VALUE_VERIFY_RETURN(false, 0);
|
|
|
|
|
2022-09-26 21:30:45 +02:00
|
|
|
for (const auto item : const_value().GetDict()) {
|
|
|
|
keys.push_back(item.first);
|
2014-01-02 23:41:11 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefDictionaryValueImpl::Remove(const CefString& key) {
|
|
|
|
CEF_VALUE_VERIFY_RETURN(true, false);
|
|
|
|
return RemoveInternal(key);
|
|
|
|
}
|
|
|
|
|
|
|
|
CefValueType CefDictionaryValueImpl::GetType(const CefString& key) {
|
|
|
|
CEF_VALUE_VERIFY_RETURN(false, VTYPE_INVALID);
|
|
|
|
|
2023-01-30 22:42:40 +01:00
|
|
|
const base::Value* value =
|
2023-07-21 00:11:34 +02:00
|
|
|
const_value().GetDict().Find(base::StringPiece(key.ToString()));
|
2021-07-23 18:40:13 +02:00
|
|
|
if (value) {
|
|
|
|
switch (value->type()) {
|
2017-01-23 18:36:54 +01:00
|
|
|
case base::Value::Type::NONE:
|
2012-04-03 03:34:16 +02:00
|
|
|
return VTYPE_NULL;
|
2017-01-23 18:36:54 +01:00
|
|
|
case base::Value::Type::BOOLEAN:
|
2012-04-03 03:34:16 +02:00
|
|
|
return VTYPE_BOOL;
|
2017-01-23 18:36:54 +01:00
|
|
|
case base::Value::Type::INTEGER:
|
2012-04-03 03:34:16 +02:00
|
|
|
return VTYPE_INT;
|
2017-01-23 18:36:54 +01:00
|
|
|
case base::Value::Type::DOUBLE:
|
2012-04-03 03:34:16 +02:00
|
|
|
return VTYPE_DOUBLE;
|
2017-01-23 18:36:54 +01:00
|
|
|
case base::Value::Type::STRING:
|
2012-04-03 03:34:16 +02:00
|
|
|
return VTYPE_STRING;
|
2017-01-23 18:36:54 +01:00
|
|
|
case base::Value::Type::BINARY:
|
2012-04-03 03:34:16 +02:00
|
|
|
return VTYPE_BINARY;
|
2023-02-27 19:52:38 +01:00
|
|
|
case base::Value::Type::DICT:
|
2012-04-03 03:34:16 +02:00
|
|
|
return VTYPE_DICTIONARY;
|
2017-01-23 18:36:54 +01:00
|
|
|
case base::Value::Type::LIST:
|
2012-04-03 03:34:16 +02:00
|
|
|
return VTYPE_LIST;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return VTYPE_INVALID;
|
|
|
|
}
|
|
|
|
|
2015-04-15 15:45:30 +02:00
|
|
|
CefRefPtr<CefValue> CefDictionaryValueImpl::GetValue(const CefString& key) {
|
2020-01-15 14:36:24 +01:00
|
|
|
CEF_VALUE_VERIFY_RETURN(false, nullptr);
|
2015-04-15 15:45:30 +02:00
|
|
|
|
2023-01-30 22:42:40 +01:00
|
|
|
const base::Value* value =
|
2023-07-21 00:11:34 +02:00
|
|
|
const_value().GetDict().Find(base::StringPiece(key.ToString()));
|
2021-07-23 18:40:13 +02:00
|
|
|
if (value) {
|
2023-01-30 22:42:40 +01:00
|
|
|
return CefValueImpl::GetOrCreateRefOrCopy(const_cast<base::Value*>(value),
|
|
|
|
mutable_value_unchecked(),
|
|
|
|
read_only(), controller());
|
2015-04-15 15:45:30 +02:00
|
|
|
}
|
|
|
|
|
2020-01-15 14:36:24 +01:00
|
|
|
return nullptr;
|
2015-04-15 15:45:30 +02:00
|
|
|
}
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
bool CefDictionaryValueImpl::GetBool(const CefString& key) {
|
|
|
|
CEF_VALUE_VERIFY_RETURN(false, false);
|
|
|
|
|
|
|
|
bool ret_value = false;
|
|
|
|
|
2023-01-30 22:42:40 +01:00
|
|
|
const base::Value* value =
|
2023-07-21 00:11:34 +02:00
|
|
|
const_value().GetDict().Find(base::StringPiece(key.ToString()));
|
2021-07-23 18:40:13 +02:00
|
|
|
if (value && value->is_bool()) {
|
|
|
|
ret_value = value->GetBool();
|
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
return ret_value;
|
|
|
|
}
|
|
|
|
|
|
|
|
int CefDictionaryValueImpl::GetInt(const CefString& key) {
|
|
|
|
CEF_VALUE_VERIFY_RETURN(false, 0);
|
|
|
|
|
|
|
|
int ret_value = 0;
|
|
|
|
|
2023-01-30 22:42:40 +01:00
|
|
|
const base::Value* value =
|
2023-07-21 00:11:34 +02:00
|
|
|
const_value().GetDict().Find(base::StringPiece(key.ToString()));
|
2021-07-23 18:40:13 +02:00
|
|
|
if (value && value->is_int()) {
|
|
|
|
ret_value = value->GetInt();
|
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
return ret_value;
|
|
|
|
}
|
|
|
|
|
|
|
|
double CefDictionaryValueImpl::GetDouble(const CefString& key) {
|
|
|
|
CEF_VALUE_VERIFY_RETURN(false, 0);
|
|
|
|
|
|
|
|
double ret_value = 0;
|
|
|
|
|
2023-01-30 22:42:40 +01:00
|
|
|
const base::Value* value =
|
2023-07-21 00:11:34 +02:00
|
|
|
const_value().GetDict().Find(base::StringPiece(key.ToString()));
|
2021-07-23 18:40:13 +02:00
|
|
|
if (value && value->is_double()) {
|
|
|
|
ret_value = value->GetDouble();
|
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
return ret_value;
|
|
|
|
}
|
|
|
|
|
|
|
|
CefString CefDictionaryValueImpl::GetString(const CefString& key) {
|
|
|
|
CEF_VALUE_VERIFY_RETURN(false, CefString());
|
|
|
|
|
2012-10-18 00:45:49 +02:00
|
|
|
std::string ret_value;
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2023-01-30 22:42:40 +01:00
|
|
|
const base::Value* value =
|
2023-07-21 00:11:34 +02:00
|
|
|
const_value().GetDict().Find(base::StringPiece(key.ToString()));
|
2021-07-23 18:40:13 +02:00
|
|
|
if (value && value->is_string()) {
|
|
|
|
ret_value = value->GetString();
|
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
return ret_value;
|
|
|
|
}
|
|
|
|
|
|
|
|
CefRefPtr<CefBinaryValue> CefDictionaryValueImpl::GetBinary(
|
|
|
|
const CefString& key) {
|
2020-01-15 14:36:24 +01:00
|
|
|
CEF_VALUE_VERIFY_RETURN(false, nullptr);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2023-01-30 22:42:40 +01:00
|
|
|
const base::Value* value =
|
2023-07-21 00:11:34 +02:00
|
|
|
const_value().GetDict().Find(base::StringPiece(key.ToString()));
|
2021-07-23 18:40:13 +02:00
|
|
|
if (value && value->is_blob()) {
|
|
|
|
base::Value* binary_value = const_cast<base::Value*>(value);
|
2017-05-17 11:29:28 +02:00
|
|
|
return CefBinaryValueImpl::GetOrCreateRef(
|
2023-01-30 22:42:40 +01:00
|
|
|
binary_value, mutable_value_unchecked(), controller());
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2020-01-15 14:36:24 +01:00
|
|
|
return nullptr;
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
CefRefPtr<CefDictionaryValue> CefDictionaryValueImpl::GetDictionary(
|
|
|
|
const CefString& key) {
|
2020-01-15 14:36:24 +01:00
|
|
|
CEF_VALUE_VERIFY_RETURN(false, nullptr);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2023-01-30 22:42:40 +01:00
|
|
|
const base::Value* value =
|
2023-07-21 00:11:34 +02:00
|
|
|
const_value().GetDict().Find(base::StringPiece(key.ToString()));
|
2021-07-23 18:40:13 +02:00
|
|
|
if (value && value->is_dict()) {
|
2023-01-30 22:42:40 +01:00
|
|
|
base::Value* dict_value = const_cast<base::Value*>(value);
|
2012-04-03 03:34:16 +02:00
|
|
|
return CefDictionaryValueImpl::GetOrCreateRef(
|
2023-01-30 22:42:40 +01:00
|
|
|
dict_value, mutable_value_unchecked(), read_only(), controller());
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2020-01-15 14:36:24 +01:00
|
|
|
return nullptr;
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
CefRefPtr<CefListValue> CefDictionaryValueImpl::GetList(const CefString& key) {
|
2020-01-15 14:36:24 +01:00
|
|
|
CEF_VALUE_VERIFY_RETURN(false, nullptr);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2023-01-30 22:42:40 +01:00
|
|
|
const base::Value* value =
|
2023-07-21 00:11:34 +02:00
|
|
|
const_value().GetDict().Find(base::StringPiece(key.ToString()));
|
2021-07-23 18:40:13 +02:00
|
|
|
if (value && value->is_list()) {
|
2023-01-30 22:42:40 +01:00
|
|
|
base::Value* list_value = const_cast<base::Value*>(value);
|
2012-04-03 03:34:16 +02:00
|
|
|
return CefListValueImpl::GetOrCreateRef(
|
2023-01-30 22:42:40 +01:00
|
|
|
list_value, mutable_value_unchecked(), read_only(), controller());
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2020-01-15 14:36:24 +01:00
|
|
|
return nullptr;
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2015-04-15 15:45:30 +02:00
|
|
|
bool CefDictionaryValueImpl::SetValue(const CefString& key,
|
|
|
|
CefRefPtr<CefValue> value) {
|
|
|
|
CEF_VALUE_VERIFY_RETURN(true, false);
|
|
|
|
|
|
|
|
CefValueImpl* impl = static_cast<CefValueImpl*>(value.get());
|
|
|
|
DCHECK(impl);
|
|
|
|
|
2023-01-30 22:42:40 +01:00
|
|
|
base::Value* actual_value =
|
|
|
|
SetInternal(key, impl->CopyOrDetachValue(controller()));
|
2017-04-20 21:28:17 +02:00
|
|
|
impl->SwapValue(actual_value, mutable_value(), controller());
|
2015-04-15 15:45:30 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
bool CefDictionaryValueImpl::SetNull(const CefString& key) {
|
|
|
|
CEF_VALUE_VERIFY_RETURN(true, false);
|
2023-01-30 22:42:40 +01:00
|
|
|
SetInternal(key, std::make_unique<base::Value>());
|
2012-04-03 03:34:16 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefDictionaryValueImpl::SetBool(const CefString& key, bool value) {
|
|
|
|
CEF_VALUE_VERIFY_RETURN(true, false);
|
2023-01-30 22:42:40 +01:00
|
|
|
SetInternal(key, std::make_unique<base::Value>(value));
|
2012-04-03 03:34:16 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefDictionaryValueImpl::SetInt(const CefString& key, int value) {
|
|
|
|
CEF_VALUE_VERIFY_RETURN(true, false);
|
2023-01-30 22:42:40 +01:00
|
|
|
SetInternal(key, std::make_unique<base::Value>(value));
|
2012-04-03 03:34:16 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefDictionaryValueImpl::SetDouble(const CefString& key, double value) {
|
|
|
|
CEF_VALUE_VERIFY_RETURN(true, false);
|
2023-01-30 22:42:40 +01:00
|
|
|
SetInternal(key, std::make_unique<base::Value>(value));
|
2012-04-03 03:34:16 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefDictionaryValueImpl::SetString(const CefString& key,
|
|
|
|
const CefString& value) {
|
|
|
|
CEF_VALUE_VERIFY_RETURN(true, false);
|
2023-01-30 22:42:40 +01:00
|
|
|
SetInternal(key, std::make_unique<base::Value>(value.ToString()));
|
2012-04-03 03:34:16 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefDictionaryValueImpl::SetBinary(const CefString& key,
|
|
|
|
CefRefPtr<CefBinaryValue> value) {
|
|
|
|
CEF_VALUE_VERIFY_RETURN(true, false);
|
|
|
|
|
|
|
|
CefBinaryValueImpl* impl = static_cast<CefBinaryValueImpl*>(value.get());
|
|
|
|
DCHECK(impl);
|
|
|
|
|
2015-04-15 15:45:30 +02:00
|
|
|
SetInternal(key, impl->CopyOrDetachValue(controller()));
|
2012-04-03 03:34:16 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefDictionaryValueImpl::SetDictionary(
|
2017-05-17 11:29:28 +02:00
|
|
|
const CefString& key,
|
|
|
|
CefRefPtr<CefDictionaryValue> value) {
|
2012-04-03 03:34:16 +02:00
|
|
|
CEF_VALUE_VERIFY_RETURN(true, false);
|
|
|
|
|
|
|
|
CefDictionaryValueImpl* impl =
|
|
|
|
static_cast<CefDictionaryValueImpl*>(value.get());
|
|
|
|
DCHECK(impl);
|
|
|
|
|
2015-04-15 15:45:30 +02:00
|
|
|
SetInternal(key, impl->CopyOrDetachValue(controller()));
|
2012-04-03 03:34:16 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefDictionaryValueImpl::SetList(const CefString& key,
|
|
|
|
CefRefPtr<CefListValue> value) {
|
|
|
|
CEF_VALUE_VERIFY_RETURN(true, false);
|
|
|
|
|
|
|
|
CefListValueImpl* impl = static_cast<CefListValueImpl*>(value.get());
|
|
|
|
DCHECK(impl);
|
|
|
|
|
2015-04-15 15:45:30 +02:00
|
|
|
SetInternal(key, impl->CopyOrDetachValue(controller()));
|
2012-04-03 03:34:16 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefDictionaryValueImpl::RemoveInternal(const CefString& key) {
|
2021-07-23 18:40:13 +02:00
|
|
|
// The ExtractKey() call below which removes the Value from the dictionary
|
|
|
|
// will return a new Value object with the moved contents of the Value that
|
|
|
|
// exists in the implementation std::map. Consequently we use FindKey() to
|
|
|
|
// retrieve the actual Value pointer as it current exists first, for later
|
|
|
|
// comparison purposes.
|
|
|
|
const base::Value* actual_value =
|
2023-07-21 00:11:34 +02:00
|
|
|
const_value().GetDict().Find(base::StringPiece(key.ToString()));
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!actual_value) {
|
2021-07-23 18:40:13 +02:00
|
|
|
return false;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2021-07-23 18:40:13 +02:00
|
|
|
|
|
|
|
// |actual_value| is no longer valid after this call.
|
2024-03-19 22:11:42 +01:00
|
|
|
std::optional<base::Value> out_value =
|
2023-07-21 00:11:34 +02:00
|
|
|
mutable_value()->GetDict().Extract(base::StringPiece(key.ToString()));
|
2021-07-23 18:40:13 +02:00
|
|
|
if (!out_value.has_value()) {
|
2012-04-03 03:34:16 +02:00
|
|
|
return false;
|
2016-08-31 13:25:56 +02:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
// Remove the value.
|
2021-07-23 18:40:13 +02:00
|
|
|
controller()->Remove(const_cast<base::Value*>(actual_value), true);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
// Only list and dictionary types may have dependencies.
|
2018-02-15 01:12:09 +01:00
|
|
|
if (out_value->is_list() || out_value->is_dict()) {
|
2021-07-23 18:40:13 +02:00
|
|
|
controller()->RemoveDependencies(const_cast<base::Value*>(actual_value));
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2023-01-30 22:42:40 +01:00
|
|
|
base::Value* CefDictionaryValueImpl::SetInternal(
|
|
|
|
const CefString& key,
|
|
|
|
std::unique_ptr<base::Value> value) {
|
2015-04-15 15:45:30 +02:00
|
|
|
DCHECK(value);
|
2022-09-26 21:30:45 +02:00
|
|
|
|
2015-04-15 15:45:30 +02:00
|
|
|
RemoveInternal(key);
|
2022-09-26 21:30:45 +02:00
|
|
|
|
|
|
|
// base::Value now uses move semantics which means that Set() will move the
|
|
|
|
// contents of the passed-in base::Value instead of keeping the same object.
|
|
|
|
// Set() then returns the actual Value pointer as it currently exists.
|
2023-07-21 00:11:34 +02:00
|
|
|
base::Value* actual_value = mutable_value()->GetDict().Set(
|
|
|
|
base::StringPiece(key.ToString()), std::move(*value));
|
2022-09-26 21:30:45 +02:00
|
|
|
CHECK(actual_value);
|
|
|
|
|
|
|
|
// |value| will be deleted when this method returns. Update the controller to
|
|
|
|
// reference |actual_value| instead.
|
2023-01-30 22:42:40 +01:00
|
|
|
controller()->Swap(value.get(), actual_value);
|
2022-09-26 21:30:45 +02:00
|
|
|
|
|
|
|
return actual_value;
|
2015-04-15 15:45:30 +02:00
|
|
|
}
|
|
|
|
|
2023-01-30 22:42:40 +01:00
|
|
|
CefDictionaryValueImpl::CefDictionaryValueImpl(base::Value* value,
|
2017-05-17 11:29:28 +02:00
|
|
|
void* parent_value,
|
|
|
|
ValueMode value_mode,
|
|
|
|
bool read_only,
|
|
|
|
CefValueController* controller)
|
2023-01-30 22:42:40 +01:00
|
|
|
: CefValueBase<CefDictionaryValue, base::Value>(value,
|
|
|
|
parent_value,
|
|
|
|
value_mode,
|
|
|
|
read_only,
|
|
|
|
controller) {
|
|
|
|
DCHECK(value->is_dict());
|
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
// CefListValueImpl implementation.
|
|
|
|
|
|
|
|
// static
|
|
|
|
CefRefPtr<CefListValue> CefListValue::Create() {
|
2023-01-30 22:42:40 +01:00
|
|
|
return new CefListValueImpl(base::Value(base::Value::Type::LIST),
|
|
|
|
/*read_only=*/false);
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
CefRefPtr<CefListValue> CefListValueImpl::GetOrCreateRef(
|
2023-01-30 22:42:40 +01:00
|
|
|
base::Value* value,
|
2012-04-03 03:34:16 +02:00
|
|
|
void* parent_value,
|
|
|
|
bool read_only,
|
|
|
|
CefValueController* controller) {
|
|
|
|
CefValueController::Object* object = controller->Get(value);
|
2023-01-02 23:59:03 +01:00
|
|
|
if (object) {
|
2012-04-03 03:34:16 +02:00
|
|
|
return static_cast<CefListValueImpl*>(object);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
return new CefListValueImpl(value, parent_value, CefListValueImpl::kReference,
|
|
|
|
read_only, controller);
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2023-01-30 22:42:40 +01:00
|
|
|
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,
|
2012-11-20 21:08:36 +01:00
|
|
|
bool will_delete,
|
|
|
|
bool read_only)
|
2023-01-30 22:42:40 +01:00
|
|
|
: CefListValueImpl(value,
|
|
|
|
nullptr,
|
|
|
|
will_delete ? kOwnerWillDelete : kOwnerNoDelete,
|
|
|
|
read_only,
|
|
|
|
nullptr) {}
|
2012-11-20 21:08:36 +01:00
|
|
|
|
2023-01-30 22:42:40 +01:00
|
|
|
base::Value CefListValueImpl::CopyValue() {
|
|
|
|
CEF_VALUE_VERIFY_RETURN(false, base::Value());
|
|
|
|
return const_value().Clone();
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2023-01-30 22:42:40 +01:00
|
|
|
std::unique_ptr<base::Value> CefListValueImpl::CopyOrDetachValue(
|
2012-04-03 03:34:16 +02:00
|
|
|
CefValueController* new_controller) {
|
|
|
|
if (!will_delete()) {
|
|
|
|
// Copy the value.
|
2023-01-30 22:42:40 +01:00
|
|
|
return std::make_unique<base::Value>(CopyValue());
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2023-01-30 22:42:40 +01:00
|
|
|
// Take ownership of the value.
|
|
|
|
auto value = base::WrapUnique(Detach(new_controller));
|
|
|
|
DCHECK(value.get());
|
|
|
|
return value;
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2023-01-30 22:42:40 +01:00
|
|
|
bool CefListValueImpl::IsSameValue(const base::Value* that) {
|
2015-04-15 15:45:30 +02:00
|
|
|
CEF_VALUE_VERIFY_RETURN(false, false);
|
|
|
|
return (&const_value() == that);
|
|
|
|
}
|
|
|
|
|
2023-01-30 22:42:40 +01:00
|
|
|
bool CefListValueImpl::IsEqualValue(const base::Value* that) {
|
2015-04-15 15:45:30 +02:00
|
|
|
CEF_VALUE_VERIFY_RETURN(false, false);
|
2022-07-25 19:49:32 +02:00
|
|
|
return const_value() == *that;
|
2015-04-15 15:45:30 +02:00
|
|
|
}
|
|
|
|
|
2023-01-30 22:42:40 +01:00
|
|
|
base::Value* CefListValueImpl::GetValueUnsafe() const {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!VerifyAttached()) {
|
2020-01-15 14:36:24 +01:00
|
|
|
return nullptr;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-04-17 16:19:30 +02:00
|
|
|
controller()->AssertLockAcquired();
|
2023-01-30 22:42:40 +01:00
|
|
|
return mutable_value_unchecked();
|
2015-04-17 16:19:30 +02:00
|
|
|
}
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
bool CefListValueImpl::IsValid() {
|
|
|
|
return !detached();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefListValueImpl::IsOwned() {
|
|
|
|
return !will_delete();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefListValueImpl::IsReadOnly() {
|
|
|
|
return read_only();
|
|
|
|
}
|
|
|
|
|
2015-04-15 15:45:30 +02:00
|
|
|
bool CefListValueImpl::IsSame(CefRefPtr<CefListValue> that) {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!that.get()) {
|
2015-04-15 15:45:30 +02:00
|
|
|
return false;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
|
|
|
if (that.get() == this) {
|
2015-04-15 15:45:30 +02:00
|
|
|
return true;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-04-15 15:45:30 +02:00
|
|
|
|
|
|
|
CEF_VALUE_VERIFY_RETURN(false, false);
|
2017-05-17 11:29:28 +02:00
|
|
|
return static_cast<CefListValueImpl*>(that.get())
|
|
|
|
->IsSameValue(&const_value());
|
2015-04-15 15:45:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CefListValueImpl::IsEqual(CefRefPtr<CefListValue> that) {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!that.get()) {
|
2015-04-15 15:45:30 +02:00
|
|
|
return false;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
|
|
|
if (that.get() == this) {
|
2015-04-15 15:45:30 +02:00
|
|
|
return true;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-04-15 15:45:30 +02:00
|
|
|
|
|
|
|
CEF_VALUE_VERIFY_RETURN(false, false);
|
2017-05-17 11:29:28 +02:00
|
|
|
return static_cast<CefListValueImpl*>(that.get())
|
|
|
|
->IsEqualValue(&const_value());
|
2015-04-15 15:45:30 +02:00
|
|
|
}
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
CefRefPtr<CefListValue> CefListValueImpl::Copy() {
|
2020-01-15 14:36:24 +01:00
|
|
|
CEF_VALUE_VERIFY_RETURN(false, nullptr);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2023-01-30 22:42:40 +01:00
|
|
|
return new CefListValueImpl(const_value().Clone(), /*read_only=*/false);
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CefListValueImpl::SetSize(size_t size) {
|
|
|
|
CEF_VALUE_VERIFY_RETURN(true, false);
|
|
|
|
|
2022-09-26 21:30:45 +02:00
|
|
|
size_t current_size = const_value().GetList().size();
|
2012-04-03 03:34:16 +02:00
|
|
|
if (size < current_size) {
|
|
|
|
// Clean up any values above the requested size.
|
2023-01-02 23:59:03 +01:00
|
|
|
for (size_t i = current_size - 1; i >= size; --i) {
|
2017-05-17 11:29:28 +02:00
|
|
|
RemoveInternal(i);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
} else if (size > 0) {
|
|
|
|
// Expand the list size.
|
2022-01-25 21:26:51 +01:00
|
|
|
// TODO: This approach seems inefficient. See https://crbug.com/1187066#c17
|
|
|
|
// for background.
|
2022-09-26 21:30:45 +02:00
|
|
|
auto& list = mutable_value()->GetList();
|
2023-01-02 23:59:03 +01:00
|
|
|
while (list.size() < size) {
|
2023-01-30 22:42:40 +01:00
|
|
|
list.Append(base::Value());
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t CefListValueImpl::GetSize() {
|
|
|
|
CEF_VALUE_VERIFY_RETURN(false, 0);
|
2022-09-26 21:30:45 +02:00
|
|
|
return const_value().GetList().size();
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CefListValueImpl::Clear() {
|
|
|
|
CEF_VALUE_VERIFY_RETURN(true, false);
|
|
|
|
|
|
|
|
// Detach any dependent values.
|
|
|
|
controller()->RemoveDependencies(mutable_value());
|
|
|
|
|
2023-01-03 00:34:43 +01:00
|
|
|
mutable_value()->GetList().clear();
|
2012-04-03 03:34:16 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-11-04 19:38:59 +01:00
|
|
|
bool CefListValueImpl::Remove(size_t index) {
|
2012-04-03 03:34:16 +02:00
|
|
|
CEF_VALUE_VERIFY_RETURN(true, false);
|
|
|
|
return RemoveInternal(index);
|
|
|
|
}
|
|
|
|
|
2016-11-04 19:38:59 +01:00
|
|
|
CefValueType CefListValueImpl::GetType(size_t index) {
|
2012-04-03 03:34:16 +02:00
|
|
|
CEF_VALUE_VERIFY_RETURN(false, VTYPE_INVALID);
|
|
|
|
|
2022-09-26 21:30:45 +02:00
|
|
|
const auto& list = const_value().GetList();
|
2022-02-21 23:23:40 +01:00
|
|
|
if (index < list.size()) {
|
|
|
|
const base::Value& value = list[index];
|
|
|
|
switch (value.type()) {
|
2017-01-23 18:36:54 +01:00
|
|
|
case base::Value::Type::NONE:
|
2012-04-03 03:34:16 +02:00
|
|
|
return VTYPE_NULL;
|
2017-01-23 18:36:54 +01:00
|
|
|
case base::Value::Type::BOOLEAN:
|
2012-04-03 03:34:16 +02:00
|
|
|
return VTYPE_BOOL;
|
2017-01-23 18:36:54 +01:00
|
|
|
case base::Value::Type::INTEGER:
|
2012-04-03 03:34:16 +02:00
|
|
|
return VTYPE_INT;
|
2017-01-23 18:36:54 +01:00
|
|
|
case base::Value::Type::DOUBLE:
|
2012-04-03 03:34:16 +02:00
|
|
|
return VTYPE_DOUBLE;
|
2017-01-23 18:36:54 +01:00
|
|
|
case base::Value::Type::STRING:
|
2012-04-03 03:34:16 +02:00
|
|
|
return VTYPE_STRING;
|
2017-01-23 18:36:54 +01:00
|
|
|
case base::Value::Type::BINARY:
|
2012-04-03 03:34:16 +02:00
|
|
|
return VTYPE_BINARY;
|
2023-02-27 19:52:38 +01:00
|
|
|
case base::Value::Type::DICT:
|
2012-04-03 03:34:16 +02:00
|
|
|
return VTYPE_DICTIONARY;
|
2017-01-23 18:36:54 +01:00
|
|
|
case base::Value::Type::LIST:
|
2012-04-03 03:34:16 +02:00
|
|
|
return VTYPE_LIST;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return VTYPE_INVALID;
|
|
|
|
}
|
|
|
|
|
2016-11-04 19:38:59 +01:00
|
|
|
CefRefPtr<CefValue> CefListValueImpl::GetValue(size_t index) {
|
2020-01-15 14:36:24 +01:00
|
|
|
CEF_VALUE_VERIFY_RETURN(false, nullptr);
|
2015-04-15 15:45:30 +02:00
|
|
|
|
2022-09-26 21:30:45 +02:00
|
|
|
const auto& list = const_value().GetList();
|
2022-02-21 23:23:40 +01:00
|
|
|
if (index < list.size()) {
|
|
|
|
const base::Value& value = list[index];
|
2023-01-30 22:42:40 +01:00
|
|
|
return CefValueImpl::GetOrCreateRefOrCopy(const_cast<base::Value*>(&value),
|
|
|
|
mutable_value_unchecked(),
|
|
|
|
read_only(), controller());
|
2015-04-15 15:45:30 +02:00
|
|
|
}
|
|
|
|
|
2020-01-15 14:36:24 +01:00
|
|
|
return nullptr;
|
2015-04-15 15:45:30 +02:00
|
|
|
}
|
|
|
|
|
2016-11-04 19:38:59 +01:00
|
|
|
bool CefListValueImpl::GetBool(size_t index) {
|
2012-04-03 03:34:16 +02:00
|
|
|
CEF_VALUE_VERIFY_RETURN(false, false);
|
|
|
|
|
|
|
|
bool ret_value = false;
|
2022-09-26 21:30:45 +02:00
|
|
|
const auto& list = const_value().GetList();
|
2022-02-21 23:23:40 +01:00
|
|
|
if (index < list.size()) {
|
|
|
|
const base::Value& value = list[index];
|
|
|
|
if (value.is_bool()) {
|
|
|
|
ret_value = value.GetBool();
|
|
|
|
}
|
2021-07-23 18:40:13 +02:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
return ret_value;
|
|
|
|
}
|
|
|
|
|
2016-11-04 19:38:59 +01:00
|
|
|
int CefListValueImpl::GetInt(size_t index) {
|
2012-04-03 03:34:16 +02:00
|
|
|
CEF_VALUE_VERIFY_RETURN(false, 0);
|
|
|
|
|
|
|
|
int ret_value = 0;
|
2022-09-26 21:30:45 +02:00
|
|
|
const auto& list = const_value().GetList();
|
2022-02-21 23:23:40 +01:00
|
|
|
if (index < list.size()) {
|
|
|
|
const base::Value& value = list[index];
|
|
|
|
if (value.is_int()) {
|
|
|
|
ret_value = value.GetInt();
|
|
|
|
}
|
2021-07-23 18:40:13 +02:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
return ret_value;
|
|
|
|
}
|
|
|
|
|
2016-11-04 19:38:59 +01:00
|
|
|
double CefListValueImpl::GetDouble(size_t index) {
|
2012-04-03 03:34:16 +02:00
|
|
|
CEF_VALUE_VERIFY_RETURN(false, 0);
|
|
|
|
|
|
|
|
double ret_value = 0;
|
2022-09-26 21:30:45 +02:00
|
|
|
const auto& list = const_value().GetList();
|
2022-02-21 23:23:40 +01:00
|
|
|
if (index < list.size()) {
|
|
|
|
const base::Value& value = list[index];
|
|
|
|
if (value.is_double()) {
|
|
|
|
ret_value = value.GetDouble();
|
|
|
|
}
|
2021-07-23 18:40:13 +02:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
return ret_value;
|
|
|
|
}
|
|
|
|
|
2016-11-04 19:38:59 +01:00
|
|
|
CefString CefListValueImpl::GetString(size_t index) {
|
2012-04-03 03:34:16 +02:00
|
|
|
CEF_VALUE_VERIFY_RETURN(false, CefString());
|
|
|
|
|
2012-10-18 00:45:49 +02:00
|
|
|
std::string ret_value;
|
2022-09-26 21:30:45 +02:00
|
|
|
const auto& list = const_value().GetList();
|
2022-02-21 23:23:40 +01:00
|
|
|
if (index < list.size()) {
|
|
|
|
const base::Value& value = list[index];
|
|
|
|
if (value.is_string()) {
|
|
|
|
ret_value = value.GetString();
|
|
|
|
}
|
2021-07-23 18:40:13 +02:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
return ret_value;
|
|
|
|
}
|
|
|
|
|
2016-11-04 19:38:59 +01:00
|
|
|
CefRefPtr<CefBinaryValue> CefListValueImpl::GetBinary(size_t index) {
|
2020-01-15 14:36:24 +01:00
|
|
|
CEF_VALUE_VERIFY_RETURN(false, nullptr);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2022-09-26 21:30:45 +02:00
|
|
|
const auto& list = const_value().GetList();
|
2022-02-21 23:23:40 +01:00
|
|
|
if (index < list.size()) {
|
2023-01-30 22:42:40 +01:00
|
|
|
base::Value& value = const_cast<base::Value&>(list[index]);
|
2022-02-21 23:23:40 +01:00
|
|
|
if (value.is_blob()) {
|
|
|
|
return CefBinaryValueImpl::GetOrCreateRef(
|
2023-01-30 22:42:40 +01:00
|
|
|
&value, mutable_value_unchecked(), controller());
|
2022-02-21 23:23:40 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2020-01-15 14:36:24 +01:00
|
|
|
return nullptr;
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2016-11-04 19:38:59 +01:00
|
|
|
CefRefPtr<CefDictionaryValue> CefListValueImpl::GetDictionary(size_t index) {
|
2020-01-15 14:36:24 +01:00
|
|
|
CEF_VALUE_VERIFY_RETURN(false, nullptr);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2022-09-26 21:30:45 +02:00
|
|
|
const auto& list = const_value().GetList();
|
2022-02-21 23:23:40 +01:00
|
|
|
if (index < list.size()) {
|
2023-01-30 22:42:40 +01:00
|
|
|
base::Value& value = const_cast<base::Value&>(list[index]);
|
2022-02-21 23:23:40 +01:00
|
|
|
if (value.is_dict()) {
|
|
|
|
return CefDictionaryValueImpl::GetOrCreateRef(
|
2023-01-30 22:42:40 +01:00
|
|
|
&value, mutable_value_unchecked(), read_only(), controller());
|
2022-02-21 23:23:40 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2020-01-15 14:36:24 +01:00
|
|
|
return nullptr;
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2016-11-04 19:38:59 +01:00
|
|
|
CefRefPtr<CefListValue> CefListValueImpl::GetList(size_t index) {
|
2020-01-15 14:36:24 +01:00
|
|
|
CEF_VALUE_VERIFY_RETURN(false, nullptr);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2022-09-26 21:30:45 +02:00
|
|
|
const auto& list = const_value().GetList();
|
2022-02-21 23:23:40 +01:00
|
|
|
if (index < list.size()) {
|
2023-01-30 22:42:40 +01:00
|
|
|
base::Value& value = const_cast<base::Value&>(list[index]);
|
2022-02-21 23:23:40 +01:00
|
|
|
if (value.is_list()) {
|
2023-01-30 22:42:40 +01:00
|
|
|
return CefListValueImpl::GetOrCreateRef(&value, mutable_value_unchecked(),
|
|
|
|
read_only(), controller());
|
2022-02-21 23:23:40 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2020-01-15 14:36:24 +01:00
|
|
|
return nullptr;
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2016-11-04 19:38:59 +01:00
|
|
|
bool CefListValueImpl::SetValue(size_t index, CefRefPtr<CefValue> value) {
|
2015-04-15 15:45:30 +02:00
|
|
|
CEF_VALUE_VERIFY_RETURN(true, false);
|
|
|
|
|
|
|
|
CefValueImpl* impl = static_cast<CefValueImpl*>(value.get());
|
|
|
|
DCHECK(impl);
|
|
|
|
|
2023-01-30 22:42:40 +01:00
|
|
|
base::Value* actual_value =
|
|
|
|
SetInternal(index, impl->CopyOrDetachValue(controller()));
|
2017-04-20 21:28:17 +02:00
|
|
|
impl->SwapValue(actual_value, mutable_value(), controller());
|
2015-04-15 15:45:30 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-11-04 19:38:59 +01:00
|
|
|
bool CefListValueImpl::SetNull(size_t index) {
|
2012-04-03 03:34:16 +02:00
|
|
|
CEF_VALUE_VERIFY_RETURN(true, false);
|
2023-01-30 22:42:40 +01:00
|
|
|
SetInternal(index, std::make_unique<base::Value>());
|
2012-04-03 03:34:16 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-11-04 19:38:59 +01:00
|
|
|
bool CefListValueImpl::SetBool(size_t index, bool value) {
|
2012-04-03 03:34:16 +02:00
|
|
|
CEF_VALUE_VERIFY_RETURN(true, false);
|
2023-01-30 22:42:40 +01:00
|
|
|
SetInternal(index, std::make_unique<base::Value>(value));
|
2012-04-03 03:34:16 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-11-04 19:38:59 +01:00
|
|
|
bool CefListValueImpl::SetInt(size_t index, int value) {
|
2012-04-03 03:34:16 +02:00
|
|
|
CEF_VALUE_VERIFY_RETURN(true, false);
|
2023-01-30 22:42:40 +01:00
|
|
|
SetInternal(index, std::make_unique<base::Value>(value));
|
2012-04-03 03:34:16 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-11-04 19:38:59 +01:00
|
|
|
bool CefListValueImpl::SetDouble(size_t index, double value) {
|
2012-04-03 03:34:16 +02:00
|
|
|
CEF_VALUE_VERIFY_RETURN(true, false);
|
2023-01-30 22:42:40 +01:00
|
|
|
SetInternal(index, std::make_unique<base::Value>(value));
|
2012-04-03 03:34:16 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-11-04 19:38:59 +01:00
|
|
|
bool CefListValueImpl::SetString(size_t index, const CefString& value) {
|
2012-04-03 03:34:16 +02:00
|
|
|
CEF_VALUE_VERIFY_RETURN(true, false);
|
2023-01-30 22:42:40 +01:00
|
|
|
SetInternal(index, std::make_unique<base::Value>(value.ToString()));
|
2012-04-03 03:34:16 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
bool CefListValueImpl::SetBinary(size_t index,
|
|
|
|
CefRefPtr<CefBinaryValue> value) {
|
2012-04-03 03:34:16 +02:00
|
|
|
CEF_VALUE_VERIFY_RETURN(true, false);
|
|
|
|
|
|
|
|
CefBinaryValueImpl* impl = static_cast<CefBinaryValueImpl*>(value.get());
|
|
|
|
DCHECK(impl);
|
|
|
|
|
2015-04-15 15:45:30 +02:00
|
|
|
SetInternal(index, impl->CopyOrDetachValue(controller()));
|
2012-04-03 03:34:16 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-11-04 19:38:59 +01:00
|
|
|
bool CefListValueImpl::SetDictionary(size_t index,
|
2012-04-03 03:34:16 +02:00
|
|
|
CefRefPtr<CefDictionaryValue> value) {
|
|
|
|
CEF_VALUE_VERIFY_RETURN(true, false);
|
|
|
|
|
|
|
|
CefDictionaryValueImpl* impl =
|
|
|
|
static_cast<CefDictionaryValueImpl*>(value.get());
|
|
|
|
DCHECK(impl);
|
|
|
|
|
2015-04-15 15:45:30 +02:00
|
|
|
SetInternal(index, impl->CopyOrDetachValue(controller()));
|
2012-04-03 03:34:16 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-11-04 19:38:59 +01:00
|
|
|
bool CefListValueImpl::SetList(size_t index, CefRefPtr<CefListValue> value) {
|
2012-04-03 03:34:16 +02:00
|
|
|
CEF_VALUE_VERIFY_RETURN(true, false);
|
|
|
|
|
|
|
|
CefListValueImpl* impl = static_cast<CefListValueImpl*>(value.get());
|
|
|
|
DCHECK(impl);
|
|
|
|
|
2015-04-15 15:45:30 +02:00
|
|
|
SetInternal(index, impl->CopyOrDetachValue(controller()));
|
2012-04-03 03:34:16 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-11-04 19:38:59 +01:00
|
|
|
bool CefListValueImpl::RemoveInternal(size_t index) {
|
2022-09-26 21:30:45 +02:00
|
|
|
auto& list = mutable_value()->GetList();
|
2023-01-02 23:59:03 +01:00
|
|
|
if (index >= list.size()) {
|
2017-04-20 21:28:17 +02:00
|
|
|
return false;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2017-04-20 21:28:17 +02:00
|
|
|
|
2021-07-23 18:40:13 +02:00
|
|
|
// The std::move() call below which removes the Value from the list will
|
|
|
|
// return a new Value object with the moved contents of the Value that exists
|
2022-02-21 23:23:40 +01:00
|
|
|
// in the implementation std::vector. Consequently we use operator[] to
|
|
|
|
// retrieve the actual Value pointer as it current exists first, for later
|
|
|
|
// comparison purposes.
|
|
|
|
const base::Value& actual_value = list[index];
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2021-07-23 18:40:13 +02:00
|
|
|
// |actual_value| is no longer valid after this call.
|
|
|
|
auto out_value = std::move(list[index]);
|
2022-09-26 21:30:45 +02:00
|
|
|
list.erase(list.begin() + index);
|
2021-07-23 18:40:13 +02:00
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
// Remove the value.
|
2022-02-21 23:23:40 +01:00
|
|
|
controller()->Remove(const_cast<base::Value*>(&actual_value), true);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
// Only list and dictionary types may have dependencies.
|
2021-07-23 18:40:13 +02:00
|
|
|
if (out_value.is_list() || out_value.is_dict()) {
|
2022-02-21 23:23:40 +01:00
|
|
|
controller()->RemoveDependencies(const_cast<base::Value*>(&actual_value));
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2023-01-30 22:42:40 +01:00
|
|
|
base::Value* CefListValueImpl::SetInternal(size_t index,
|
|
|
|
std::unique_ptr<base::Value> value) {
|
2015-04-15 15:45:30 +02:00
|
|
|
DCHECK(value);
|
2017-04-20 21:28:17 +02:00
|
|
|
|
2022-09-26 21:30:45 +02:00
|
|
|
auto& list = mutable_value()->GetList();
|
2021-07-23 18:40:13 +02:00
|
|
|
if (RemoveInternal(index)) {
|
|
|
|
CHECK_LE(index, list.size());
|
2022-09-26 21:30:45 +02:00
|
|
|
list.Insert(list.begin() + index, std::move(*value));
|
2021-07-23 18:40:13 +02:00
|
|
|
} else {
|
2022-01-25 21:26:51 +01:00
|
|
|
if (index >= list.size()) {
|
|
|
|
// Expand the list size.
|
|
|
|
// TODO: This approach seems inefficient. See
|
|
|
|
// https://crbug.com/1187066#c17 for background.
|
2023-01-02 23:59:03 +01:00
|
|
|
while (list.size() <= index) {
|
2023-01-30 22:42:40 +01:00
|
|
|
list.Append(base::Value());
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2022-01-25 21:26:51 +01:00
|
|
|
}
|
|
|
|
list[index] = std::move(*value);
|
2021-07-23 18:40:13 +02:00
|
|
|
}
|
2017-04-20 21:28:17 +02:00
|
|
|
|
|
|
|
// base::Value now uses move semantics which means that Insert()/Set() will
|
|
|
|
// move the contents of the passed-in base::Value instead of keeping the same
|
2022-02-21 23:23:40 +01:00
|
|
|
// object. Consequently we use operator[] to retrieve the actual base::Value
|
2017-04-20 21:28:17 +02:00
|
|
|
// pointer as it exists in the std::vector.
|
2022-02-21 23:23:40 +01:00
|
|
|
const base::Value& actual_value = list[index];
|
2017-04-20 21:28:17 +02:00
|
|
|
|
2022-09-26 21:30:45 +02:00
|
|
|
// |value| will be deleted when this method returns. Update the controller to
|
2017-04-20 21:28:17 +02:00
|
|
|
// reference |actual_value| instead.
|
2023-01-30 22:42:40 +01:00
|
|
|
controller()->Swap(value.get(), const_cast<base::Value*>(&actual_value));
|
2017-04-20 21:28:17 +02:00
|
|
|
|
2022-02-21 23:23:40 +01:00
|
|
|
return const_cast<base::Value*>(&actual_value);
|
2015-04-15 15:45:30 +02:00
|
|
|
}
|
|
|
|
|
2023-01-30 22:42:40 +01:00
|
|
|
CefListValueImpl::CefListValueImpl(base::Value* value,
|
2017-05-17 11:29:28 +02:00
|
|
|
void* parent_value,
|
|
|
|
ValueMode value_mode,
|
|
|
|
bool read_only,
|
|
|
|
CefValueController* controller)
|
2023-01-30 22:42:40 +01:00
|
|
|
: CefValueBase<CefListValue, base::Value>(value,
|
|
|
|
parent_value,
|
|
|
|
value_mode,
|
|
|
|
read_only,
|
|
|
|
controller) {
|
|
|
|
DCHECK(value->is_list());
|
|
|
|
}
|