Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1122)

Unified Diff: third_party/WebKit/Source/platform/inspector_protocol/Values.cpp

Issue 1745423002: DevTools: migrate protocol values from RefPtr to OwnPtr. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/platform/inspector_protocol/Values.cpp
diff --git a/third_party/WebKit/Source/platform/inspector_protocol/Values.cpp b/third_party/WebKit/Source/platform/inspector_protocol/Values.cpp
index 23e79d3c785ef7237a54edbab7629d1b61be1555..fdb0b3f8307719c02a8cbb98be4d0ff7a0d34c75 100644
--- a/third_party/WebKit/Source/platform/inspector_protocol/Values.cpp
+++ b/third_party/WebKit/Source/platform/inspector_protocol/Values.cpp
@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "platform/inspector_protocol/Parser.h"
#include "platform/inspector_protocol/Values.h"
#include "platform/Decimal.h"
@@ -95,6 +96,11 @@ void Value::writeJSON(StringBuilder* output) const
output->append(nullString, 4);
}
+PassOwnPtr<Value> Value::clone() const
+{
+ return Value::null();
+}
+
bool FundamentalValue::asBoolean(bool* output) const
{
if (type() != TypeBoolean)
@@ -136,6 +142,11 @@ void FundamentalValue::writeJSON(StringBuilder* output) const
}
}
+PassOwnPtr<Value> FundamentalValue::clone() const
+{
+ return type() == TypeNumber ? FundamentalValue::create(m_doubleValue) : FundamentalValue::create(m_boolValue);
+}
+
bool StringValue::asString(String* output) const
{
*output = m_stringValue;
@@ -148,6 +159,11 @@ void StringValue::writeJSON(StringBuilder* output) const
doubleQuoteStringForJSON(m_stringValue, output);
}
+PassOwnPtr<Value> StringValue::clone() const
+{
+ return StringValue::create(m_stringValue);
+}
+
DictionaryValue::~DictionaryValue()
{
}
@@ -167,21 +183,21 @@ void DictionaryValue::setString(const String& name, const String& value)
setValue(name, StringValue::create(value));
}
-void DictionaryValue::setValue(const String& name, PassRefPtr<Value> value)
+void DictionaryValue::setValue(const String& name, PassOwnPtr<Value> value)
{
ASSERT(value);
if (m_data.set(name, value).isNewEntry)
m_order.append(name);
}
-void DictionaryValue::setObject(const String& name, PassRefPtr<DictionaryValue> value)
+void DictionaryValue::setObject(const String& name, PassOwnPtr<DictionaryValue> value)
{
ASSERT(value);
if (m_data.set(name, value).isNewEntry)
m_order.append(name);
}
-void DictionaryValue::setArray(const String& name, PassRefPtr<ListValue> value)
+void DictionaryValue::setArray(const String& name, PassOwnPtr<ListValue> value)
{
ASSERT(value);
if (m_data.set(name, value).isNewEntry)
@@ -200,7 +216,7 @@ DictionaryValue::const_iterator DictionaryValue::find(const String& name) const
bool DictionaryValue::getBoolean(const String& name, bool* output) const
{
- RefPtr<protocol::Value> value = get(name);
+ protocol::Value* value = get(name);
if (!value)
return false;
return value->asBoolean(output);
@@ -208,28 +224,28 @@ bool DictionaryValue::getBoolean(const String& name, bool* output) const
bool DictionaryValue::getString(const String& name, String* output) const
{
- RefPtr<protocol::Value> value = get(name);
+ protocol::Value* value = get(name);
if (!value)
return false;
return value->asString(output);
}
-PassRefPtr<DictionaryValue> DictionaryValue::getObject(const String& name) const
+DictionaryValue* DictionaryValue::getObject(const String& name) const
{
return DictionaryValue::cast(get(name));
}
-PassRefPtr<protocol::ListValue> DictionaryValue::getArray(const String& name) const
+protocol::ListValue* DictionaryValue::getArray(const String& name) const
{
return ListValue::cast(get(name));
}
-PassRefPtr<protocol::Value> DictionaryValue::get(const String& name) const
+protocol::Value* DictionaryValue::get(const String& name) const
{
Dictionary::const_iterator it = m_data.find(name);
if (it == m_data.end())
return nullptr;
- return it->value;
+ return it->value.get();
}
bool DictionaryValue::booleanProperty(const String& name, bool defaultValue) const
@@ -265,6 +281,17 @@ void DictionaryValue::writeJSON(StringBuilder* output) const
output->append('}');
}
+PassOwnPtr<Value> DictionaryValue::clone() const
+{
+ OwnPtr<DictionaryValue> result = DictionaryValue::create();
+ for (size_t i = 0; i < m_order.size(); ++i) {
+ Dictionary::const_iterator it = m_data.find(m_order[i]);
+ ASSERT_WITH_SECURITY_IMPLICATION(it != m_data.end());
dgozman 2016/03/01 01:45:05 Security implication? Why not just assert?
+ result->setValue(it->key, it->value->clone());
+ }
+ return result.release();
+}
+
DictionaryValue::DictionaryValue()
: Value(TypeObject)
, m_data()
@@ -279,7 +306,7 @@ ListValue::~ListValue()
void ListValue::writeJSON(StringBuilder* output) const
{
output->append('[');
- for (Vector<RefPtr<protocol::Value>>::const_iterator it = m_data.begin(); it != m_data.end(); ++it) {
+ for (Vector<OwnPtr<protocol::Value>>::const_iterator it = m_data.begin(); it != m_data.end(); ++it) {
if (it != m_data.begin())
output->append(',');
(*it)->writeJSON(output);
@@ -287,22 +314,30 @@ void ListValue::writeJSON(StringBuilder* output) const
output->append(']');
}
+PassOwnPtr<Value> ListValue::clone() const
+{
+ OwnPtr<ListValue> result = ListValue::create();
+ for (Vector<OwnPtr<protocol::Value>>::const_iterator it = m_data.begin(); it != m_data.end(); ++it)
+ result->pushValue((*it)->clone());
+ return result.release();
+}
+
ListValue::ListValue()
: Value(TypeArray)
, m_data()
{
}
-void ListValue::pushValue(PassRefPtr<protocol::Value> value)
+void ListValue::pushValue(PassOwnPtr<protocol::Value> value)
{
ASSERT(value);
m_data.append(value);
}
-PassRefPtr<protocol::Value> ListValue::get(size_t index)
+protocol::Value* ListValue::get(size_t index)
{
ASSERT_WITH_SECURITY_IMPLICATION(index < m_data.size());
- return m_data[index];
+ return m_data[index].get();
}
} // namespace protocol

Powered by Google App Engine
This is Rietveld 408576698