mirror of
https://bitbucket.org/chromiumembedded/cef
synced 2025-06-05 21:39:12 +02:00
- Add CefValue for wrapping various value types in a single object (issue #1607).
- Add IsSame() and IsEqual() methods for comparing CefValue* types. - Improve CefValue* documentation.
This commit is contained in:
@ -15,6 +15,83 @@
|
||||
#include "base/threading/platform_thread.h"
|
||||
|
||||
|
||||
// CefValue implementation
|
||||
class CefValueImpl : public CefValue {
|
||||
public:
|
||||
// Get or create a reference to a complex value or copy a simple value.
|
||||
static CefRefPtr<CefValue> GetOrCreateRefOrCopy(
|
||||
base::Value* value,
|
||||
void* parent_value,
|
||||
bool read_only,
|
||||
CefValueController* controller);
|
||||
|
||||
CefValueImpl();
|
||||
|
||||
// Take ownership of |value|. Do not pass in a value owned by something else
|
||||
// (use GetOrCreateRefOrCopy instead).
|
||||
explicit CefValueImpl(base::Value* value);
|
||||
|
||||
// Keep a reference to |value|.
|
||||
explicit CefValueImpl(CefRefPtr<CefBinaryValue> value);
|
||||
explicit CefValueImpl(CefRefPtr<CefDictionaryValue> value);
|
||||
explicit CefValueImpl(CefRefPtr<CefListValue> value);
|
||||
|
||||
~CefValueImpl() override;
|
||||
|
||||
// Take ownership of |value|. Do not pass in a value owned by something else
|
||||
// (use GetOrCreateRefOrCopy or Set*() instead).
|
||||
void SetValue(base::Value* value);
|
||||
|
||||
// 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* CopyOrTransferValue(void* new_parent_value,
|
||||
bool new_read_only,
|
||||
CefValueController* new_controller);
|
||||
|
||||
// CefValue methods.
|
||||
bool IsValid() override;
|
||||
bool IsOwned() override;
|
||||
bool IsReadOnly() override;
|
||||
bool IsSame(CefRefPtr<CefValue> that) override;
|
||||
bool IsEqual(CefRefPtr<CefValue> that) override;
|
||||
CefRefPtr<CefValue> Copy() override;
|
||||
CefValueType GetType() override;
|
||||
bool GetBool() override;
|
||||
int GetInt() override;
|
||||
double GetDouble() override;
|
||||
CefString GetString() override;
|
||||
CefRefPtr<CefBinaryValue> GetBinary() override;
|
||||
CefRefPtr<CefDictionaryValue> GetDictionary() override;
|
||||
CefRefPtr<CefListValue> GetList() override;
|
||||
bool SetNull() override;
|
||||
bool SetBool(bool value) override;
|
||||
bool SetInt(int value) override;
|
||||
bool SetDouble(double value) override;
|
||||
bool SetString(const CefString& value) override;
|
||||
bool SetBinary(CefRefPtr<CefBinaryValue> value) override;
|
||||
bool SetDictionary(CefRefPtr<CefDictionaryValue> value) override;
|
||||
bool SetList(CefRefPtr<CefListValue> value) override;
|
||||
|
||||
private:
|
||||
void SetValueInternal(base::Value* value);
|
||||
|
||||
// Access to all members must be protected by |lock_|.
|
||||
base::Lock lock_;
|
||||
|
||||
// Simple values only.
|
||||
scoped_ptr<base::Value> value_;
|
||||
|
||||
// Complex values.
|
||||
CefRefPtr<CefBinaryValue> binary_value_;
|
||||
CefRefPtr<CefDictionaryValue> dictionary_value_;
|
||||
CefRefPtr<CefListValue> list_value_;
|
||||
|
||||
IMPLEMENT_REFCOUNTING(CefValueImpl);
|
||||
DISALLOW_COPY_AND_ASSIGN(CefValueImpl);
|
||||
};
|
||||
|
||||
|
||||
// CefBinaryValue implementation
|
||||
class CefBinaryValueImpl
|
||||
: public CefValueBase<CefBinaryValue, base::BinaryValue> {
|
||||
@ -25,21 +102,36 @@ class CefBinaryValueImpl
|
||||
void* parent_value,
|
||||
CefValueController* controller);
|
||||
|
||||
// Simple constructor for referencing existing value objects.
|
||||
// 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(NULL) 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(NULL).
|
||||
CefBinaryValueImpl(base::BinaryValue* value,
|
||||
bool will_delete,
|
||||
bool read_only);
|
||||
bool will_delete);
|
||||
|
||||
// If |copy| is false this object will take ownership of the specified |data|
|
||||
// buffer instead of copying it.
|
||||
CefBinaryValueImpl(char* data,
|
||||
size_t data_size,
|
||||
bool copy);
|
||||
|
||||
// Return a copy of the value.
|
||||
base::BinaryValue* CopyValue();
|
||||
|
||||
// If a reference return a copy of the value otherwise detach the value to the
|
||||
// specified |new_controller|.
|
||||
// If this value is a reference then return a copy. Otherwise, detach and
|
||||
// transfer ownership of the value.
|
||||
base::BinaryValue* CopyOrDetachValue(CefValueController* new_controller);
|
||||
|
||||
bool IsSameValue(const base::BinaryValue* that);
|
||||
bool IsEqualValue(const base::BinaryValue* that);
|
||||
|
||||
// CefBinaryValue methods.
|
||||
bool IsValid() override;
|
||||
bool IsOwned() override;
|
||||
bool IsSame(CefRefPtr<CefBinaryValue> that) override;
|
||||
bool IsEqual(CefRefPtr<CefBinaryValue> that) override;
|
||||
CefRefPtr<CefBinaryValue> Copy() override;
|
||||
size_t GetSize() override;
|
||||
size_t GetData(void* buffer,
|
||||
@ -53,14 +145,6 @@ class CefBinaryValueImpl
|
||||
void* parent_value,
|
||||
ValueMode value_mode,
|
||||
CefValueController* controller);
|
||||
// If |copy| is false this object will take ownership of the specified |data|
|
||||
// buffer instead of copying it.
|
||||
CefBinaryValueImpl(char* data,
|
||||
size_t data_size,
|
||||
bool copy);
|
||||
|
||||
// For the Create() method.
|
||||
friend class CefBinaryValue;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(CefBinaryValueImpl);
|
||||
};
|
||||
@ -77,7 +161,12 @@ class CefDictionaryValueImpl
|
||||
bool read_only,
|
||||
CefValueController* controller);
|
||||
|
||||
// Simple constructor for referencing existing value objects.
|
||||
// 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(NULL) 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(NULL).
|
||||
CefDictionaryValueImpl(base::DictionaryValue* value,
|
||||
bool will_delete,
|
||||
bool read_only);
|
||||
@ -85,14 +174,19 @@ class CefDictionaryValueImpl
|
||||
// Return a copy of the value.
|
||||
base::DictionaryValue* CopyValue();
|
||||
|
||||
// If a reference return a copy of the value otherwise detach the value to the
|
||||
// specified |new_controller|.
|
||||
// If this value is a reference then return a copy. Otherwise, detach and
|
||||
// transfer ownership of the value.
|
||||
base::DictionaryValue* CopyOrDetachValue(CefValueController* new_controller);
|
||||
|
||||
bool IsSameValue(const base::DictionaryValue* that);
|
||||
bool IsEqualValue(const base::DictionaryValue* that);
|
||||
|
||||
// CefDictionaryValue methods.
|
||||
bool IsValid() override;
|
||||
bool IsOwned() override;
|
||||
bool IsReadOnly() override;
|
||||
bool IsSame(CefRefPtr<CefDictionaryValue> that) override;
|
||||
bool IsEqual(CefRefPtr<CefDictionaryValue> that) override;
|
||||
CefRefPtr<CefDictionaryValue> Copy(
|
||||
bool exclude_empty_children) override;
|
||||
size_t GetSize() override;
|
||||
@ -101,6 +195,7 @@ class CefDictionaryValueImpl
|
||||
bool GetKeys(KeyList& keys) override;
|
||||
bool Remove(const CefString& key) override;
|
||||
CefValueType GetType(const CefString& key) override;
|
||||
CefRefPtr<CefValue> GetValue(const CefString& key) override;
|
||||
bool GetBool(const CefString& key) override;
|
||||
int GetInt(const CefString& key) override;
|
||||
double GetDouble(const CefString& key) override;
|
||||
@ -109,6 +204,7 @@ class CefDictionaryValueImpl
|
||||
CefRefPtr<CefDictionaryValue> GetDictionary(
|
||||
const CefString& key) override;
|
||||
CefRefPtr<CefListValue> GetList(const CefString& key) override;
|
||||
bool SetValue(const CefString& key, CefRefPtr<CefValue> value) override;
|
||||
bool SetNull(const CefString& key) override;
|
||||
bool SetBool(const CefString& key, bool value) override;
|
||||
bool SetInt(const CefString& key, int value) override;
|
||||
@ -131,9 +227,7 @@ class CefDictionaryValueImpl
|
||||
CefValueController* controller);
|
||||
|
||||
bool RemoveInternal(const CefString& key);
|
||||
|
||||
// For the Create() method.
|
||||
friend class CefDictionaryValue;
|
||||
void SetInternal(const CefString& key, base::Value* value);
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(CefDictionaryValueImpl);
|
||||
};
|
||||
@ -150,7 +244,12 @@ class CefListValueImpl
|
||||
bool read_only,
|
||||
CefValueController* controller);
|
||||
|
||||
// Simple constructor for referencing existing value objects.
|
||||
// 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(NULL) 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(NULL).
|
||||
CefListValueImpl(base::ListValue* value,
|
||||
bool will_delete,
|
||||
bool read_only);
|
||||
@ -158,20 +257,26 @@ class CefListValueImpl
|
||||
// Return a copy of the value.
|
||||
base::ListValue* CopyValue();
|
||||
|
||||
// If a reference return a copy of the value otherwise detach the value to the
|
||||
// specified |new_controller|.
|
||||
// If this value is a reference then return a copy. Otherwise, detach and
|
||||
// transfer ownership of the value.
|
||||
base::ListValue* CopyOrDetachValue(CefValueController* new_controller);
|
||||
|
||||
bool IsSameValue(const base::ListValue* that);
|
||||
bool IsEqualValue(const base::ListValue* that);
|
||||
|
||||
/// CefListValue methods.
|
||||
bool IsValid() override;
|
||||
bool IsOwned() override;
|
||||
bool IsReadOnly() override;
|
||||
bool IsSame(CefRefPtr<CefListValue> that) override;
|
||||
bool IsEqual(CefRefPtr<CefListValue> that) override;
|
||||
CefRefPtr<CefListValue> Copy() override;
|
||||
bool SetSize(size_t size) override;
|
||||
size_t GetSize() override;
|
||||
bool Clear() override;
|
||||
bool Remove(int index) override;
|
||||
CefValueType GetType(int index) override;
|
||||
CefRefPtr<CefValue> GetValue(int index) override;
|
||||
bool GetBool(int index) override;
|
||||
int GetInt(int index) override;
|
||||
double GetDouble(int index) override;
|
||||
@ -179,6 +284,7 @@ class CefListValueImpl
|
||||
CefRefPtr<CefBinaryValue> GetBinary(int index) override;
|
||||
CefRefPtr<CefDictionaryValue> GetDictionary(int index) override;
|
||||
CefRefPtr<CefListValue> GetList(int index) override;
|
||||
bool SetValue(int index, CefRefPtr<CefValue> value) override;
|
||||
bool SetNull(int index) override;
|
||||
bool SetBool(int index, bool value) override;
|
||||
bool SetInt(int index, int value) override;
|
||||
@ -198,9 +304,7 @@ class CefListValueImpl
|
||||
CefValueController* controller);
|
||||
|
||||
bool RemoveInternal(int index);
|
||||
|
||||
// For the Create() method.
|
||||
friend class CefListValue;
|
||||
void SetInternal(int index, base::Value* value);
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(CefListValueImpl);
|
||||
};
|
||||
|
Reference in New Issue
Block a user