DevTools: migrate protocol values from RefPtr to OwnPtr.

BUG=580337

Review URL: https://codereview.chromium.org/1745423002

Cr-Original-Commit-Position: refs/heads/master@{#378575}
Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src
Cr-Mirrored-Commit: e8903f001fe670d33ee3b34cc43fc8a5cb778509
diff --git a/CodeGenerator.py b/CodeGenerator.py
index 0d0a87a..43c9c56 100644
--- a/CodeGenerator.py
+++ b/CodeGenerator.py
@@ -115,27 +115,27 @@
 
 def create_object_type_definition():
     return {
-        "return_type": "PassRefPtr<protocol::DictionaryValue>",
-        "pass_type": "PassRefPtr<protocol::DictionaryValue>",
-        "to_raw_type": "%s",
+        "return_type": "PassOwnPtr<protocol::DictionaryValue>",
+        "pass_type": "PassOwnPtr<protocol::DictionaryValue>",
+        "to_raw_type": "%s.get()",
         "to_pass_type": "%s.release()",
-        "type": "RefPtr<protocol::DictionaryValue>",
-        "raw_type": "RefPtr<protocol::DictionaryValue>",
-        "raw_pass_type": "PassRefPtr<protocol::DictionaryValue>",
-        "raw_return_type": "RefPtr<protocol::DictionaryValue>",
+        "type": "OwnPtr<protocol::DictionaryValue>",
+        "raw_type": "protocol::DictionaryValue",
+        "raw_pass_type": "protocol::DictionaryValue*",
+        "raw_return_type": "protocol::DictionaryValue*",
     }
 
 
 def create_any_type_definition():
     return {
-        "return_type": "PassRefPtr<protocol::Value>",
-        "pass_type": "PassRefPtr<protocol::Value>",
+        "return_type": "PassOwnPtr<protocol::Value>",
+        "pass_type": "PassOwnPtr<protocol::Value>",
+        "to_raw_type": "%s.get()",
         "to_pass_type": "%s.release()",
-        "to_raw_type": "%s",
-        "type": "RefPtr<protocol::Value>",
-        "raw_type": "RefPtr<protocol::Value>",
-        "raw_pass_type": "PassRefPtr<protocol::Value>",
-        "raw_return_type": "RefPtr<protocol::Value>",
+        "type": "OwnPtr<protocol::Value>",
+        "raw_type": "protocol::Value",
+        "raw_pass_type": "protocol::Value*",
+        "raw_return_type": "protocol::Value*",
     }
 
 
diff --git a/Dispatcher_cpp.template b/Dispatcher_cpp.template
index d790ca3..0dbad39 100644
--- a/Dispatcher_cpp.template
+++ b/Dispatcher_cpp.template
@@ -45,7 +45,7 @@
     virtual void reportProtocolError(int sessionId, int callId, CommonErrorCode, const String& errorMessage, ErrorSupport* errors) const;
     using Dispatcher::reportProtocolError;
 
-    void sendResponse(int sessionId, int callId, const ErrorString& invocationError, ErrorSupport* errors, PassRefPtr<protocol::DictionaryValue> result);
+    void sendResponse(int sessionId, int callId, const ErrorString& invocationError, ErrorSupport* errors, PassOwnPtr<protocol::DictionaryValue> result);
     bool isActive() { return m_frontendChannel; }
 
 {% for domain in api.domains %}
@@ -53,14 +53,14 @@
 {% endfor %}
 
 private:
-    using CallHandler = void (DispatcherImpl::*)(int sessionId, int callId, DictionaryValue* messageObject, ErrorSupport* errors);
+    using CallHandler = void (DispatcherImpl::*)(int sessionId, int callId, PassOwnPtr<DictionaryValue> messageObject, ErrorSupport* errors);
     using DispatchMap = HashMap<String, CallHandler>;
 
 {% for domain in api.domains %}
   {% for command in domain.commands %}
     {% if "redirect" in command %}{% continue %}{% endif %}
     {% if "handlers" in command and not ("renderer" in command["handlers"]) %}{% continue %}{% endif %}
-    void {{domain.domain}}_{{command.name}}(int sessionId, int callId, DictionaryValue* requestMessageObject, ErrorSupport*);
+    void {{domain.domain}}_{{command.name}}(int sessionId, int callId, PassOwnPtr<DictionaryValue> requestMessageObject, ErrorSupport*);
   {% endfor %}
 {% endfor %}
 
@@ -70,7 +70,7 @@
     {{domain.domain}}CommandHandler* m_{{domain.domain | lower}}Agent;
 {% endfor %}
 
-    void sendResponse(int sessionId, int callId, ErrorString invocationError, PassRefPtr<protocol::DictionaryValue> result)
+    void sendResponse(int sessionId, int callId, ErrorString invocationError, PassOwnPtr<protocol::DictionaryValue> result)
     {
         sendResponse(sessionId, callId, invocationError, nullptr, result);
     }
@@ -105,20 +105,20 @@
         {%- if not loop.last -%}, {% endif -%}
       {% endfor %})
 {
-    RefPtr<protocol::DictionaryValue> resultObject = DictionaryValue::create();
+    OwnPtr<protocol::DictionaryValue> resultObject = DictionaryValue::create();
       {% for parameter in command.returns %}
         {% if "optional" in parameter %}
     if ({{parameter.name}}.isJust())
         resultObject->setValue("{{parameter.name}}", toValue({{parameter.name}}.fromJust()));
        {% else %}
-    resultObject->setValue("{{parameter.name}}", toValue({{parameter.name}}));
+    resultObject->setValue("{{parameter.name}}", toValue({{resolve_type(parameter).to_raw_type % parameter.name}}));
         {% endif %}
       {% endfor %}
     sendIfActive(resultObject.release(), ErrorString());
 }
     {% endif %}
 
-void DispatcherImpl::{{domain.domain}}_{{command.name}}(int sessionId, int callId, DictionaryValue* requestMessageObject, ErrorSupport* errors)
+void DispatcherImpl::{{domain.domain}}_{{command.name}}(int sessionId, int callId, PassOwnPtr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
 {
     if (!m_{{domain.domain | lower}}Agent)
         errors->addError("{{domain.domain}} handler is not available.");
@@ -130,10 +130,10 @@
     {% if "parameters" in command %}
 
     // Prepare input parameters.
-    RefPtr<protocol::DictionaryValue> object = DictionaryValue::cast(requestMessageObject->get("params"));
+    protocol::DictionaryValue* object = DictionaryValue::cast(requestMessageObject->get("params"));
     errors->push();
       {% for property in command.parameters %}
-    RefPtr<protocol::Value> {{property.name}}Value = object ? object->get("{{property.name}}") : nullptr;
+    protocol::Value* {{property.name}}Value = object ? object->get("{{property.name}}") : nullptr;
         {% if property.optional %}
     Maybe<{{resolve_type(property).raw_type}}> in_{{property.name}};
     if ({{property.name}}Value) {
@@ -156,7 +156,7 @@
     RefPtr<{{domain.domain}}CommandHandler::{{command.name | to_title_case}}Callback> callback = adoptRef(new {{domain.domain}}CommandHandler::{{command.name | to_title_case}}Callback(this, sessionId, callId));
     {% elif "returns" in command %}
     // Declare output parameters.
-    RefPtr<protocol::DictionaryValue> result = DictionaryValue::create();
+    OwnPtr<protocol::DictionaryValue> result = DictionaryValue::create();
       {% for property in command.returns %}
         {% if "optional" in property %}
     Maybe<{{resolve_type(property).raw_type}}> out_{{property.name}};
@@ -189,11 +189,11 @@
         if (out_{{parameter.name}}.isJust())
             result->setValue("{{parameter.name}}", toValue(out_{{parameter.name}}.fromJust()));
         {% else %}
-        result->setValue("{{parameter.name}}", toValue(out_{{parameter.name}}));
+        result->setValue("{{parameter.name}}", toValue({{resolve_type(parameter).to_raw_type % ("out_" + parameter.name)}}));
         {% endif %}
       {% endfor %}
     }
-    sendResponse(sessionId, callId, error, result);
+    sendResponse(sessionId, callId, error, result.release());
     {% elif not("async" in command) %}
     sendResponse(sessionId, callId, error);
     {% endif %}
@@ -210,16 +210,16 @@
 {
     RefPtr<Dispatcher> protect(this);
     int callId = 0;
-    RefPtr<protocol::Value> parsedMessage = parseJSON(message);
+    OwnPtr<protocol::Value> parsedMessage = parseJSON(message);
     ASSERT(parsedMessage);
-    RefPtr<protocol::DictionaryValue> messageObject = DictionaryValue::cast(parsedMessage.release());
+    OwnPtr<protocol::DictionaryValue> messageObject = DictionaryValue::cast(parsedMessage.release());
     ASSERT(messageObject);
 
-    RefPtr<protocol::Value> callIdValue = messageObject->get("id");
+    protocol::Value* callIdValue = messageObject->get("id");
     bool success = callIdValue->asNumber(&callId);
     ASSERT_UNUSED(success, success);
 
-    RefPtr<protocol::Value> methodValue = messageObject->get("method");
+    protocol::Value* methodValue = messageObject->get("method");
     String method;
     success = methodValue && methodValue->asString(&method);
     ASSERT_UNUSED(success, success);
@@ -231,17 +231,17 @@
     }
 
     protocol::ErrorSupport errors;
-    ((*this).*it->value)(sessionId, callId, messageObject.get(), &errors);
+    ((*this).*it->value)(sessionId, callId, messageObject.release(), &errors);
 }
 
-void DispatcherImpl::sendResponse(int sessionId, int callId, const ErrorString& invocationError, ErrorSupport* errors, PassRefPtr<protocol::DictionaryValue> result)
+void DispatcherImpl::sendResponse(int sessionId, int callId, const ErrorString& invocationError, ErrorSupport* errors, PassOwnPtr<protocol::DictionaryValue> result)
 {
     if (invocationError.length() || (errors && errors->hasErrors())) {
         reportProtocolError(sessionId, callId, ServerError, invocationError, errors);
         return;
     }
 
-    RefPtr<protocol::DictionaryValue> responseMessage = DictionaryValue::create();
+    OwnPtr<protocol::DictionaryValue> responseMessage = DictionaryValue::create();
     responseMessage->setNumber("id", callId);
     responseMessage->setObject("result", result);
     if (m_frontendChannel)
@@ -259,14 +259,14 @@
     ASSERT(code >=0);
     ASSERT((unsigned)code < m_commonErrors.size());
     ASSERT(m_commonErrors[code]);
-    RefPtr<protocol::DictionaryValue> error = DictionaryValue::create();
+    OwnPtr<protocol::DictionaryValue> error = DictionaryValue::create();
     error->setNumber("code", m_commonErrors[code]);
     error->setString("message", errorMessage);
     ASSERT(error);
     if (errors && errors->hasErrors())
         error->setString("data", errors->errors());
-    RefPtr<protocol::DictionaryValue> message = DictionaryValue::create();
-    message->setObject("error", error);
+    OwnPtr<protocol::DictionaryValue> message = DictionaryValue::create();
+    message->setObject("error", error.release());
     message->setNumber("id", callId);
     if (m_frontendChannel)
         m_frontendChannel->sendProtocolResponse(sessionId, callId, message.release());
@@ -274,11 +274,11 @@
 
 bool Dispatcher::getCommandName(const String& message, String* result)
 {
-    RefPtr<protocol::Value> value = parseJSON(message);
+    OwnPtr<protocol::Value> value = parseJSON(message);
     if (!value)
         return false;
 
-    RefPtr<protocol::DictionaryValue> object = DictionaryValue::cast(value.release());
+    protocol::DictionaryValue* object = DictionaryValue::cast(value.get());
     if (!object)
         return false;
 
@@ -304,7 +304,7 @@
     return !m_alreadySent && m_backendImpl->isActive();
 }
 
-void Dispatcher::CallbackBase::sendIfActive(PassRefPtr<protocol::DictionaryValue> partialMessage, const ErrorString& invocationError)
+void Dispatcher::CallbackBase::sendIfActive(PassOwnPtr<protocol::DictionaryValue> partialMessage, const ErrorString& invocationError)
 {
     if (m_alreadySent)
         return;
diff --git a/Dispatcher_h.template b/Dispatcher_h.template
index 93b3988..0694e5f 100644
--- a/Dispatcher_h.template
+++ b/Dispatcher_h.template
@@ -29,7 +29,7 @@
         bool isActive();
 
     protected:
-        void sendIfActive(PassRefPtr<protocol::DictionaryValue> partialMessage, const ErrorString& invocationError);
+        void sendIfActive(PassOwnPtr<protocol::DictionaryValue> partialMessage, const ErrorString& invocationError);
 
     private:
         void disable() { m_alreadySent = true; }
diff --git a/FrontendChannel.h b/FrontendChannel.h
index dfb7fc3..37c15d0 100644
--- a/FrontendChannel.h
+++ b/FrontendChannel.h
@@ -35,8 +35,8 @@
 class FrontendChannel {
 public:
     virtual ~FrontendChannel() { }
-    virtual void sendProtocolResponse(int sessionId, int callId, PassRefPtr<protocol::DictionaryValue> message) = 0;
-    virtual void sendProtocolNotification(PassRefPtr<protocol::DictionaryValue> message) = 0;
+    virtual void sendProtocolResponse(int sessionId, int callId, PassOwnPtr<protocol::DictionaryValue> message) = 0;
+    virtual void sendProtocolNotification(PassOwnPtr<protocol::DictionaryValue> message) = 0;
     virtual void flush() = 0;
 };
 
diff --git a/Frontend_cpp.template b/Frontend_cpp.template
index 6773e9b..94041d3 100644
--- a/Frontend_cpp.template
+++ b/Frontend_cpp.template
@@ -32,18 +32,18 @@
       {%- endif %} {{parameter.name}}{%- if not loop.last -%}, {% endif -%}
     {% endfor -%})
 {
-    RefPtr<protocol::DictionaryValue> jsonMessage = DictionaryValue::create();
+    OwnPtr<protocol::DictionaryValue> jsonMessage = DictionaryValue::create();
     jsonMessage->setString("method", "{{domain.domain}}.{{event.name}}");
-    RefPtr<protocol::DictionaryValue> paramsObject = DictionaryValue::create();
+    OwnPtr<protocol::DictionaryValue> paramsObject = DictionaryValue::create();
     {% for parameter in event.parameters %}
       {% if "optional" in parameter %}
     if ({{parameter.name}}.isJust())
         paramsObject->setValue("{{parameter.name}}", toValue({{parameter.name}}.fromJust()));
       {% else %}
-    paramsObject->setValue("{{parameter.name}}", toValue({{parameter.name}}));
+    paramsObject->setValue("{{parameter.name}}", toValue({{resolve_type(parameter).to_raw_type % parameter.name}}));
       {% endif %}
     {% endfor %}
-    jsonMessage->setObject("params", paramsObject);
+    jsonMessage->setObject("params", paramsObject.release());
     if (m_frontendChannel)
         m_frontendChannel->sendProtocolNotification(jsonMessage.release());
 }
diff --git a/Parser.cpp b/Parser.cpp
index 2257c3c..ce72028 100644
--- a/Parser.cpp
+++ b/Parser.cpp
@@ -419,12 +419,12 @@
 }
 
 template<typename CharType>
-PassRefPtr<Value> buildValue(const CharType* start, const CharType* end, const CharType** valueTokenEnd, int depth)
+PassOwnPtr<Value> buildValue(const CharType* start, const CharType* end, const CharType** valueTokenEnd, int depth)
 {
     if (depth > stackLimit)
         return nullptr;
 
-    RefPtr<Value> result;
+    OwnPtr<Value> result;
     const CharType* tokenStart;
     const CharType* tokenEnd;
     Token token = parseToken(start, end, &tokenStart, &tokenEnd);
@@ -459,14 +459,14 @@
         break;
     }
     case ArrayBegin: {
-        RefPtr<ListValue> array = ListValue::create();
+        OwnPtr<ListValue> array = ListValue::create();
         start = tokenEnd;
         token = parseToken(start, end, &tokenStart, &tokenEnd);
         while (token != ArrayEnd) {
-            RefPtr<Value> arrayNode = buildValue(start, end, &tokenEnd, depth + 1);
+            OwnPtr<Value> arrayNode = buildValue(start, end, &tokenEnd, depth + 1);
             if (!arrayNode)
                 return nullptr;
-            array->pushValue(arrayNode);
+            array->pushValue(arrayNode.release());
 
             // After a list value, we expect a comma or the end of the list.
             start = tokenEnd;
@@ -487,7 +487,7 @@
         break;
     }
     case ObjectBegin: {
-        RefPtr<DictionaryValue> object = DictionaryValue::create();
+        OwnPtr<DictionaryValue> object = DictionaryValue::create();
         start = tokenEnd;
         token = parseToken(start, end, &tokenStart, &tokenEnd);
         while (token != ObjectEnd) {
@@ -503,10 +503,10 @@
                 return nullptr;
             start = tokenEnd;
 
-            RefPtr<Value> value = buildValue(start, end, &tokenEnd, depth + 1);
+            OwnPtr<Value> value = buildValue(start, end, &tokenEnd, depth + 1);
             if (!value)
                 return nullptr;
-            object->setValue(key, value);
+            object->setValue(key, value.release());
             start = tokenEnd;
 
             // After a key/value pair, we expect a comma or the end of the
@@ -538,11 +538,11 @@
 }
 
 template<typename CharType>
-PassRefPtr<Value> parseJSONInternal(const CharType* start, unsigned length)
+PassOwnPtr<Value> parseJSONInternal(const CharType* start, unsigned length)
 {
     const CharType* end = start + length;
     const CharType *tokenEnd;
-    RefPtr<Value> value = buildValue(start, end, &tokenEnd, 0);
+    OwnPtr<Value> value = buildValue(start, end, &tokenEnd, 0);
     if (!value || tokenEnd != end)
         return nullptr;
     return value.release();
@@ -550,7 +550,7 @@
 
 } // anonymous namespace
 
-PassRefPtr<Value> parseJSON(const String& json)
+PassOwnPtr<Value> parseJSON(const String& json)
 {
     if (json.isEmpty())
         return nullptr;
diff --git a/Parser.h b/Parser.h
index 9234777..17849d3 100644
--- a/Parser.h
+++ b/Parser.h
@@ -14,7 +14,7 @@
 
 class Value;
 
-PLATFORM_EXPORT PassRefPtr<Value> parseJSON(const String& json);
+PLATFORM_EXPORT PassOwnPtr<Value> parseJSON(const String& json);
 
 } // namespace platform
 } // namespace blink
diff --git a/ParserTest.cpp b/ParserTest.cpp
index 415b36c..d05fb37 100644
--- a/ParserTest.cpp
+++ b/ParserTest.cpp
@@ -13,9 +13,9 @@
 
 TEST(ParserTest, Reading)
 {
-    RefPtr<protocol::Value> tmpValue;
-    RefPtr<protocol::Value> root;
-    RefPtr<protocol::Value> root2;
+    protocol::Value* tmpValue;
+    OwnPtr<protocol::Value> root;
+    OwnPtr<protocol::Value> root2;
     String strVal;
     int intVal = 0;
 
@@ -58,20 +58,20 @@
     EXPECT_EQ("sample string", strVal);
     root = parseJSON("[1, /* comment, 2 ] */ \n 3]");
     ASSERT_TRUE(root.get());
-    RefPtr<protocol::ListValue> list = ListValue::cast(root);
+    protocol::ListValue* list = ListValue::cast(root.get());
     ASSERT_TRUE(list);
     EXPECT_EQ(2u, list->length());
     tmpValue = list->get(0);
-    ASSERT_TRUE(tmpValue.get());
+    ASSERT_TRUE(tmpValue);
     EXPECT_TRUE(tmpValue->asNumber(&intVal));
     EXPECT_EQ(1, intVal);
     tmpValue = list->get(1);
-    ASSERT_TRUE(tmpValue.get());
+    ASSERT_TRUE(tmpValue);
     EXPECT_TRUE(tmpValue->asNumber(&intVal));
     EXPECT_EQ(3, intVal);
     root = parseJSON("[1, /*a*/2, 3]");
     ASSERT_TRUE(root.get());
-    list = ListValue::cast(root);
+    list = ListValue::cast(root.get());
     ASSERT_TRUE(list);
     EXPECT_EQ(3u, list->length());
     root = parseJSON("/* comment **/42");
@@ -254,7 +254,7 @@
     root = parseJSON("[true, false, null]");
     ASSERT_TRUE(root.get());
     EXPECT_EQ(Value::TypeArray, root->type());
-    list = ListValue::cast(root);
+    list = ListValue::cast(root.get());
     ASSERT_TRUE(list);
     EXPECT_EQ(3U, list->length());
 
@@ -262,7 +262,7 @@
     root = parseJSON("[]");
     ASSERT_TRUE(root.get());
     EXPECT_EQ(Value::TypeArray, root->type());
-    list = ListValue::cast(root);
+    list = ListValue::cast(root.get());
     ASSERT_TRUE(list);
     EXPECT_EQ(0U, list->length());
 
@@ -270,7 +270,7 @@
     root = parseJSON("[[true], [], [false, [], [null]], null]");
     ASSERT_TRUE(root.get());
     EXPECT_EQ(Value::TypeArray, root->type());
-    list = ListValue::cast(root);
+    list = ListValue::cast(root.get());
     ASSERT_TRUE(list);
     EXPECT_EQ(4U, list->length());
 
@@ -293,11 +293,11 @@
     root = parseJSON("[true]");
     ASSERT_TRUE(root.get());
     EXPECT_EQ(Value::TypeArray, root->type());
-    list = ListValue::cast(root);
+    list = ListValue::cast(root.get());
     ASSERT_TRUE(list);
     EXPECT_EQ(1U, list->length());
     tmpValue = list->get(0);
-    ASSERT_TRUE(tmpValue.get());
+    ASSERT_TRUE(tmpValue);
     EXPECT_EQ(Value::TypeBoolean, tmpValue->type());
     bool boolValue = false;
     EXPECT_TRUE(tmpValue->asBoolean(&boolValue));
@@ -321,13 +321,13 @@
     root = parseJSON("{\"number\":9.87654321, \"null\":null , \"\\x53\" : \"str\" }");
     ASSERT_TRUE(root.get());
     EXPECT_EQ(Value::TypeObject, root->type());
-    RefPtr<protocol::DictionaryValue> objectVal = DictionaryValue::cast(root);
+    protocol::DictionaryValue* objectVal = DictionaryValue::cast(root.get());
     ASSERT_TRUE(objectVal);
     doubleVal = 0.0;
     EXPECT_TRUE(objectVal->getNumber("number", &doubleVal));
     EXPECT_DOUBLE_EQ(9.87654321, doubleVal);
-    RefPtr<protocol::Value> nullVal = objectVal->get("null");
-    ASSERT_TRUE(nullVal.get());
+    protocol::Value* nullVal = objectVal->get("null");
+    ASSERT_TRUE(nullVal);
     EXPECT_EQ(Value::TypeNull, nullVal->type());
     EXPECT_TRUE(objectVal->getString("S", &strVal));
     EXPECT_EQ("str", strVal);
@@ -355,24 +355,24 @@
     root = parseJSON("{\"inner\":{\"array\":[true]},\"false\":false,\"d\":{}}");
     ASSERT_TRUE(root.get());
     EXPECT_EQ(Value::TypeObject, root->type());
-    objectVal = DictionaryValue::cast(root);
+    objectVal = DictionaryValue::cast(root.get());
     ASSERT_TRUE(objectVal);
-    RefPtr<protocol::DictionaryValue> innerObject = objectVal->getObject("inner");
-    ASSERT_TRUE(innerObject.get());
-    RefPtr<protocol::ListValue> innerArray = innerObject->getArray("array");
-    ASSERT_TRUE(innerArray.get());
+    protocol::DictionaryValue* innerObject = objectVal->getObject("inner");
+    ASSERT_TRUE(innerObject);
+    protocol::ListValue* innerArray = innerObject->getArray("array");
+    ASSERT_TRUE(innerArray);
     EXPECT_EQ(1U, innerArray->length());
     boolValue = true;
     EXPECT_TRUE(objectVal->getBoolean("false", &boolValue));
     EXPECT_FALSE(boolValue);
     innerObject = objectVal->getObject("d");
-    EXPECT_TRUE(innerObject.get());
+    EXPECT_TRUE(innerObject);
 
     // Test keys with periods
     root = parseJSON("{\"a.b\":3,\"c\":2,\"d.e.f\":{\"g.h.i.j\":1}}");
     ASSERT_TRUE(root.get());
     EXPECT_EQ(Value::TypeObject, root->type());
-    objectVal = DictionaryValue::cast(root);
+    objectVal = DictionaryValue::cast(root.get());
     ASSERT_TRUE(objectVal);
     int integerValue = 0;
     EXPECT_TRUE(objectVal->getNumber("a.b", &integerValue));
@@ -380,7 +380,7 @@
     EXPECT_TRUE(objectVal->getNumber("c", &integerValue));
     EXPECT_EQ(2, integerValue);
     innerObject = objectVal->getObject("d.e.f");
-    ASSERT_TRUE(innerObject.get());
+    ASSERT_TRUE(innerObject);
     EXPECT_EQ(1, innerObject->size());
     EXPECT_TRUE(innerObject->getNumber("g.h.i.j", &integerValue));
     EXPECT_EQ(1, integerValue);
@@ -388,10 +388,10 @@
     root = parseJSON("{\"a\":{\"b\":2},\"a.b\":1}");
     ASSERT_TRUE(root.get());
     EXPECT_EQ(Value::TypeObject, root->type());
-    objectVal = DictionaryValue::cast(root);
+    objectVal = DictionaryValue::cast(root.get());
     ASSERT_TRUE(objectVal);
     innerObject = objectVal->getObject("a");
-    ASSERT_TRUE(innerObject.get());
+    ASSERT_TRUE(innerObject);
     EXPECT_TRUE(innerObject->getNumber("b", &integerValue));
     EXPECT_EQ(2, integerValue);
     EXPECT_TRUE(objectVal->getNumber("a.b", &integerValue));
@@ -447,7 +447,7 @@
     root = parseJSON(notEvil.toString());
     ASSERT_TRUE(root.get());
     EXPECT_EQ(Value::TypeArray, root->type());
-    list = ListValue::cast(root);
+    list = ListValue::cast(root.get());
     ASSERT_TRUE(list);
     EXPECT_EQ(5001U, list->length());
 
@@ -462,7 +462,7 @@
     root = parseJSON("{\"path\": \"/tmp/\\xc3\\xa0\\xc3\\xa8\\xc3\\xb2.png\"}");
     ASSERT_TRUE(root.get());
     EXPECT_EQ(Value::TypeObject, root->type());
-    objectVal = DictionaryValue::cast(root);
+    objectVal = DictionaryValue::cast(root.get());
     ASSERT_TRUE(objectVal);
     EXPECT_TRUE(objectVal->getString("path", &strVal));
     UChar tmp5[] = {0x2f, 0x74, 0x6d, 0x70, 0x2f, 0xe0, 0xe8, 0xf2, 0x2e, 0x70, 0x6e, 0x67};
@@ -544,7 +544,7 @@
     };
 
     for (size_t i = 0; i < WTF_ARRAY_LENGTH(invalidJson); ++i) {
-        RefPtr<protocol::Value> result = parseJSON(invalidJson[i]);
+        OwnPtr<protocol::Value> result = parseJSON(invalidJson[i]);
         EXPECT_FALSE(result.get());
     }
 }
diff --git a/TypeBuilder_cpp.template b/TypeBuilder_cpp.template
index 5fd3919..ce26b9a 100644
--- a/TypeBuilder_cpp.template
+++ b/TypeBuilder_cpp.template
@@ -62,33 +62,36 @@
     return builder.toString();
 }
 
-PassOwnPtr<Object> Object::parse(PassRefPtr<protocol::Value> value, ErrorSupport* errors)
+PassOwnPtr<Object> Object::parse(protocol::Value* value, ErrorSupport* errors)
 {
-    RefPtr<protocol::DictionaryValue> object = DictionaryValue::cast(value);
+    protocol::DictionaryValue* object = DictionaryValue::cast(value);
     if (!object) {
         errors->addError("object expected");
         return nullptr;
     }
-    return adoptPtr(new Object(object.release()));
+    return adoptPtr(new Object(adoptPtr(static_cast<DictionaryValue*>(object->clone().leakPtr()))));
 }
 
-PassRefPtr<protocol::DictionaryValue> Object::serialize() const
+PassOwnPtr<protocol::DictionaryValue> Object::serialize() const
 {
-    return m_object;
+    return DictionaryValue::cast(m_object->clone());
 }
 
 PassOwnPtr<Object> Object::clone() const
 {
-    return adoptPtr(new Object(m_object));
+    return adoptPtr(new Object(DictionaryValue::cast(m_object->clone())));
 }
 
-Object::Object(PassRefPtr<protocol::DictionaryValue> object) : m_object(object) { }
+Object::Object(PassOwnPtr<protocol::DictionaryValue> object) : m_object(object) { }
 Object::~Object() { }
 
-PassRefPtr<protocol::Value> toValue(int value) { return FundamentalValue::create(value); }
-PassRefPtr<protocol::Value> toValue(double value) { return FundamentalValue::create(value); }
-PassRefPtr<protocol::Value> toValue(bool value) { return FundamentalValue::create(value); }
-PassRefPtr<protocol::Value> toValue(const String& param) { return StringValue::create(param); }
+PassOwnPtr<protocol::Value> toValue(int value) { return FundamentalValue::create(value); }
+PassOwnPtr<protocol::Value> toValue(double value) { return FundamentalValue::create(value); }
+PassOwnPtr<protocol::Value> toValue(bool value) { return FundamentalValue::create(value); }
+PassOwnPtr<protocol::Value> toValue(const String& param) { return StringValue::create(param); }
+PassOwnPtr<protocol::Value> toValue(Value* param) { return param->clone(); }
+PassOwnPtr<protocol::Value> toValue(DictionaryValue* param) { return param->clone(); }
+PassOwnPtr<protocol::Value> toValue(ListValue* param) { return param->clone(); }
 
 // ------------- Enum values from types.
 {% for domain in api.domains %}
@@ -113,7 +116,7 @@
     {% endfor %}
     {% if not (type.type == "object") or not ("properties" in type) %}{% continue %}{% endif %}
 
-PassOwnPtr<{{type.id}}> {{type.id}}::parse(PassRefPtr<protocol::Value> value, ErrorSupport* errors)
+PassOwnPtr<{{type.id}}> {{type.id}}::parse(protocol::Value* value, ErrorSupport* errors)
 {
     if (!value || value->type() != protocol::Value::TypeObject) {
         errors->addError("object expected");
@@ -121,10 +124,10 @@
     }
 
     OwnPtr<{{type.id}}> result = adoptPtr(new {{type.id}}());
-    RefPtr<protocol::DictionaryValue> object = DictionaryValue::cast(value);
+    protocol::DictionaryValue* object = DictionaryValue::cast(value);
     errors->push();
     {% for property in type.properties %}
-    RefPtr<protocol::Value> {{property.name}}Value = object->get("{{property.name}}");
+    protocol::Value* {{property.name}}Value = object->get("{{property.name}}");
       {% if property.optional %}
     if ({{property.name}}Value) {
         errors->setName("{{property.name}}");
@@ -141,15 +144,15 @@
     return result.release();
 }
 
-PassRefPtr<protocol::DictionaryValue> {{type.id}}::serialize() const
+PassOwnPtr<protocol::DictionaryValue> {{type.id}}::serialize() const
 {
-    RefPtr<protocol::DictionaryValue> result = DictionaryValue::create();
+    OwnPtr<protocol::DictionaryValue> result = DictionaryValue::create();
     {% for property in type.properties %}
       {% if property.optional %}
     if (m_{{property.name}}.isJust())
         result->setValue("{{property.name}}", toValue(m_{{property.name}}.fromJust()));
       {% else %}
-    result->setValue("{{property.name}}", toValue(m_{{property.name}}));
+    result->setValue("{{property.name}}", toValue({{resolve_type(property).to_raw_type % ("m_" + property.name)}}));
       {% endif %}
     {% endfor %}
     return result.release();
diff --git a/TypeBuilder_h.template b/TypeBuilder_h.template
index 8341cc1..d7dc499 100644
--- a/TypeBuilder_h.template
+++ b/TypeBuilder_h.template
@@ -11,7 +11,6 @@
 #include "platform/inspector_protocol/Values.h"
 #include "wtf/Assertions.h"
 #include "wtf/PassOwnPtr.h"
-#include "wtf/PassRefPtr.h"
 #include "wtf/text/StringBuilder.h"
 #include "wtf/text/WTFString.h"
 
@@ -80,34 +79,18 @@
     using MaybeBase::operator=;
 };
 
-template<typename T>
-class Maybe<RefPtr<T>> {
-public:
-    Maybe() { }
-    Maybe(RefPtr<T> value) : m_value(value) { }
-    Maybe(PassRefPtr<T> value) : m_value(value) { }
-    Maybe(T* value) : m_value(value) { }
-    void operator=(PassRefPtr<T> value) { m_value = value; }
-    PassRefPtr<T> fromJust() const { ASSERT(m_value); return m_value; }
-    PassRefPtr<T> fromMaybe(const PassRefPtr<T> defaultValue) const { return m_value || defaultValue; }
-    bool isJust() const { return !!m_value; }
-    PassRefPtr<T> takeJust() { return m_value; }
-
-protected:
-    RefPtr<T> m_value;
-};
-
 template<typename T> class Array;
 
-PLATFORM_EXPORT PassRefPtr<protocol::Value> toValue(int value);
-PLATFORM_EXPORT PassRefPtr<protocol::Value> toValue(double value);
-PLATFORM_EXPORT PassRefPtr<protocol::Value> toValue(bool value);
-PLATFORM_EXPORT PassRefPtr<protocol::Value> toValue(const String& param);
-template<typename T> PassRefPtr<protocol::Value> toValue(PassRefPtr<T> param) { return param; }
-template<typename T> PassRefPtr<protocol::Value> toValue(const RefPtr<T>& param) { return param; }
-template<typename T> PassRefPtr<protocol::Value> toValue(T* param) { return param->serialize(); }
-template<typename T> PassRefPtr<protocol::Value> toValue(PassOwnPtr<T> param) { return param->serialize(); }
-template<typename T> PassRefPtr<protocol::Value> toValue(const OwnPtr<T>& param) { return param->serialize(); }
+PLATFORM_EXPORT PassOwnPtr<protocol::Value> toValue(int value);
+PLATFORM_EXPORT PassOwnPtr<protocol::Value> toValue(double value);
+PLATFORM_EXPORT PassOwnPtr<protocol::Value> toValue(bool value);
+PLATFORM_EXPORT PassOwnPtr<protocol::Value> toValue(const String& param);
+PLATFORM_EXPORT PassOwnPtr<protocol::Value> toValue(protocol::Value* param);
+PLATFORM_EXPORT PassOwnPtr<protocol::Value> toValue(protocol::DictionaryValue* param);
+PLATFORM_EXPORT PassOwnPtr<protocol::Value> toValue(protocol::ListValue* param);
+template<typename T> PassOwnPtr<protocol::Value> toValue(T* param) { return param->serialize(); }
+template<typename T> PassOwnPtr<protocol::Value> toValue(const OwnPtr<T>& param) { static_assert(sizeof(T) == 0, "use raw pointer version."); return nullptr; }
+template<typename T> PassOwnPtr<protocol::Value> toValue(PassOwnPtr<T> param) { static_assert(sizeof(T) == 0, "use raw pointer version."); return nullptr; }
 
 class PLATFORM_EXPORT ErrorSupport {
 public:
@@ -131,7 +114,7 @@
 template<typename T>
 struct FromValue
 {
-    static PassOwnPtr<T> parse(PassRefPtr<protocol::Value> value, ErrorSupport* errors)
+    static PassOwnPtr<T> parse(protocol::Value* value, ErrorSupport* errors)
     {
         return T::parse(value, errors);
     }
@@ -140,7 +123,7 @@
 template<>
 struct FromValue<bool>
 {
-    static bool parse(PassRefPtr<protocol::Value> value, ErrorSupport* errors)
+    static bool parse(protocol::Value* value, ErrorSupport* errors)
     {
         bool result = false;
         bool success = value ? value->asBoolean(&result) : false;
@@ -153,7 +136,7 @@
 template<>
 struct FromValue<int>
 {
-    static int parse(PassRefPtr<protocol::Value> value, ErrorSupport* errors)
+    static int parse(protocol::Value* value, ErrorSupport* errors)
     {
         int result = 0;
         bool success = value ? value->asNumber(&result) : false;
@@ -166,7 +149,7 @@
 template<>
 struct FromValue<double>
 {
-    static double parse(PassRefPtr<protocol::Value> value, ErrorSupport* errors)
+    static double parse(protocol::Value* value, ErrorSupport* errors)
     {
         double result = 0;
         bool success = value ? value->asNumber(&result) : false;
@@ -179,7 +162,7 @@
 template<>
 struct FromValue<String>
 {
-    static String parse(PassRefPtr<protocol::Value> value, ErrorSupport* errors)
+    static String parse(protocol::Value* value, ErrorSupport* errors)
     {
         String result;
         bool success = value ? value->asString(&result) : false;
@@ -189,33 +172,49 @@
     }
 };
 
-template<typename T>
-struct FromValue<RefPtr<T>>
+template<>
+struct FromValue<Value>
 {
-    static PassRefPtr<T> parse(PassRefPtr<protocol::Value> value, ErrorSupport* errors)
+    static PassOwnPtr<Value> parse(protocol::Value* value, ErrorSupport* errors)
     {
-        if (!value)
+        String result;
+        bool success = !!value;
+        if (!success)
             errors->addError("value expected");
-        return value;
+        return value->clone();
     }
 };
 
 template<>
-struct FromValue<RefPtr<protocol::DictionaryValue>>
+struct FromValue<DictionaryValue>
 {
-    static PassRefPtr<protocol::DictionaryValue> parse(PassRefPtr<protocol::Value> value, ErrorSupport* errors)
+    static PassOwnPtr<DictionaryValue> parse(protocol::Value* value, ErrorSupport* errors)
     {
-        if (value && value->type() == protocol::Value::TypeObject)
-            return DictionaryValue::cast(value);
-        errors->addError("object expected");
-        return nullptr;
+        String result;
+        bool success = value && value->type() == protocol::Value::TypeObject;
+        if (!success)
+            errors->addError("object expected");
+        return DictionaryValue::cast(value->clone());
+    }
+};
+
+template<>
+struct FromValue<ListValue>
+{
+    static PassOwnPtr<ListValue> parse(protocol::Value* value, ErrorSupport* errors)
+    {
+        String result;
+        bool success = value && value->type() == protocol::Value::TypeArray;
+        if (!success)
+            errors->addError("list expected");
+        return ListValue::cast(value->clone());
     }
 };
 
 template<typename T>
 struct FromValue<protocol::Array<T>>
 {
-    static PassOwnPtr<protocol::Array<T>> parse(PassRefPtr<protocol::Value> value, ErrorSupport* errors)
+    static PassOwnPtr<protocol::Array<T>> parse(protocol::Value* value, ErrorSupport* errors)
     {
         return protocol::Array<T>::parse(value, errors);
     }
@@ -229,9 +228,9 @@
         return adoptPtr(new Array<T>());
     }
 
-    static PassOwnPtr<Array<T>> parse(PassRefPtr<protocol::Value> value, ErrorSupport* errors)
+    static PassOwnPtr<Array<T>> parse(protocol::Value* value, ErrorSupport* errors)
     {
-        RefPtr<protocol::ListValue> array = ListValue::cast(value);
+        protocol::ListValue* array = ListValue::cast(value);
         if (!array) {
             errors->addError("array expected");
             return nullptr;
@@ -264,9 +263,9 @@
         return m_vector[index];
     }
 
-    PassRefPtr<protocol::ListValue> serialize()
+    PassOwnPtr<protocol::ListValue> serialize()
     {
-        RefPtr<protocol::ListValue> result = ListValue::create();
+        OwnPtr<protocol::ListValue> result = ListValue::create();
         for (auto& item : m_vector)
             result->pushValue(toValue(item));
         return result.release();
@@ -280,7 +279,6 @@
 template<> class Array<int> : public ArrayBase<int> {};
 template<> class Array<double> : public ArrayBase<double> {};
 template<> class Array<bool> : public ArrayBase<bool> {};
-template<typename T> class Array<RefPtr<T>> : public ArrayBase<RefPtr<T>> {};
 
 template<typename T>
 class Array {
@@ -290,9 +288,9 @@
         return adoptPtr(new Array<T>());
     }
 
-    static PassOwnPtr<Array<T>> parse(PassRefPtr<protocol::Value> value, ErrorSupport* errors)
+    static PassOwnPtr<Array<T>> parse(protocol::Value* value, ErrorSupport* errors)
     {
-        RefPtr<protocol::ListValue> array = ListValue::cast(value);
+        protocol::ListValue* array = ListValue::cast(value);
         if (!array) {
             errors->addError("array expected");
             return nullptr;
@@ -323,11 +321,11 @@
         return m_vector[index].get();
     }
 
-    PassRefPtr<protocol::ListValue> serialize()
+    PassOwnPtr<protocol::ListValue> serialize()
     {
-        RefPtr<protocol::ListValue> result = ListValue::create();
+        OwnPtr<protocol::ListValue> result = ListValue::create();
         for (auto& item : m_vector)
-            result->pushValue(toValue(item));
+            result->pushValue(toValue(item.get()));
         return result.release();
     }
 
@@ -337,14 +335,14 @@
 
 class PLATFORM_EXPORT Object {
 public:
-    static PassOwnPtr<Object> parse(PassRefPtr<protocol::Value> value, ErrorSupport* errors);
+    static PassOwnPtr<Object> parse(protocol::Value* value, ErrorSupport* errors);
     ~Object();
 
-    PassRefPtr<protocol::DictionaryValue> serialize() const;
+    PassOwnPtr<protocol::DictionaryValue> serialize() const;
     PassOwnPtr<Object> clone() const;
 private:
-    Object(PassRefPtr<protocol::DictionaryValue> object);
-    RefPtr<protocol::DictionaryValue> m_object;
+    Object(PassOwnPtr<protocol::DictionaryValue> object);
+    OwnPtr<protocol::DictionaryValue> m_object;
 };
 
 {% for domain in api.domains %}
@@ -416,7 +414,7 @@
 // {{type.description}}
 class PLATFORM_EXPORT {{type.id}} {
 public:
-    static PassOwnPtr<{{type.id}}> parse(PassRefPtr<protocol::Value> value, ErrorSupport* errors);
+    static PassOwnPtr<{{type.id}}> parse(protocol::Value* value, ErrorSupport* errors);
 
     ~{{type.id}}() { }
     {% for property in type.properties %}
@@ -438,7 +436,7 @@
     void set{{property.name | to_title_case}}({{resolve_type(property).pass_type}} value) { m_{{property.name}} = value; }
     {% endfor %}
 
-    PassRefPtr<protocol::DictionaryValue> serialize() const;
+    PassOwnPtr<protocol::DictionaryValue> serialize() const;
     PassOwnPtr<{{type.id}}> clone() const;
 
     template<int STATE>
diff --git a/Values.cpp b/Values.cpp
index 23e79d3..d35271e 100644
--- a/Values.cpp
+++ b/Values.cpp
@@ -5,6 +5,7 @@
 #include "platform/inspector_protocol/Values.h"
 
 #include "platform/Decimal.h"
+#include "platform/inspector_protocol/Parser.h"
 #include "wtf/MathExtras.h"
 #include "wtf/text/StringBuilder.h"
 
@@ -95,6 +96,11 @@
     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 @@
     }
 }
 
+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 @@
     doubleQuoteStringForJSON(m_stringValue, output);
 }
 
+PassOwnPtr<Value> StringValue::clone() const
+{
+    return StringValue::create(m_stringValue);
+}
+
 DictionaryValue::~DictionaryValue()
 {
 }
@@ -167,40 +183,30 @@
     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)
         m_order.append(name);
 }
 
-DictionaryValue::iterator DictionaryValue::find(const String& name)
-{
-    return m_data.find(name);
-}
-
-DictionaryValue::const_iterator DictionaryValue::find(const String& name) const
-{
-    return m_data.find(name);
-}
-
 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 +214,28 @@
 
 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 +271,17 @@
     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(it != m_data.end());
+        result->setValue(it->key, it->value->clone());
+    }
+    return result.release();
+}
+
 DictionaryValue::DictionaryValue()
     : Value(TypeObject)
     , m_data()
@@ -279,7 +296,7 @@
 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 +304,30 @@
     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
diff --git a/Values.h b/Values.h
index f7147a0..fe75c6e 100644
--- a/Values.h
+++ b/Values.h
@@ -9,7 +9,7 @@
 #include "wtf/Allocator.h"
 #include "wtf/Forward.h"
 #include "wtf/HashMap.h"
-#include "wtf/RefCounted.h"
+#include "wtf/PassOwnPtr.h"
 #include "wtf/TypeTraits.h"
 #include "wtf/Vector.h"
 #include "wtf/text/StringHash.h"
@@ -22,15 +22,16 @@
 class DictionaryValue;
 class Value;
 
-class PLATFORM_EXPORT Value : public RefCounted<Value> {
+class PLATFORM_EXPORT Value {
+    WTF_MAKE_NONCOPYABLE(Value);
 public:
     static const int maxDepth = 1000;
 
     virtual ~Value() { }
 
-    static PassRefPtr<Value> null()
+    static PassOwnPtr<Value> null()
     {
-        return adoptRef(new Value());
+        return adoptPtr(new Value());
     }
 
     typedef enum {
@@ -53,6 +54,7 @@
 
     String toJSONString() const;
     virtual void writeJSON(StringBuilder* output) const;
+    virtual PassOwnPtr<Value> clone() const;
 
 protected:
     Value() : m_type(TypeNull) { }
@@ -67,27 +69,26 @@
 
 class PLATFORM_EXPORT FundamentalValue : public Value {
 public:
-
-    static PassRefPtr<FundamentalValue> create(bool value)
+    static PassOwnPtr<FundamentalValue> create(bool value)
     {
-        return adoptRef(new FundamentalValue(value));
+        return adoptPtr(new FundamentalValue(value));
     }
 
-    static PassRefPtr<FundamentalValue> create(int value)
+    static PassOwnPtr<FundamentalValue> create(int value)
     {
-        return adoptRef(new FundamentalValue(value));
+        return adoptPtr(new FundamentalValue(value));
     }
 
-    static PassRefPtr<FundamentalValue> create(double value)
+    static PassOwnPtr<FundamentalValue> create(double value)
     {
-        return adoptRef(new FundamentalValue(value));
+        return adoptPtr(new FundamentalValue(value));
     }
 
     bool asBoolean(bool* output) const override;
     bool asNumber(double* output) const override;
     bool asNumber(int* output) const override;
-
     void writeJSON(StringBuilder* output) const override;
+    PassOwnPtr<Value> clone() const override;
 
 private:
     explicit FundamentalValue(bool value) : Value(TypeBoolean), m_boolValue(value) { }
@@ -102,19 +103,19 @@
 
 class PLATFORM_EXPORT StringValue : public Value {
 public:
-    static PassRefPtr<StringValue> create(const String& value)
+    static PassOwnPtr<StringValue> create(const String& value)
     {
-        return adoptRef(new StringValue(value));
+        return adoptPtr(new StringValue(value));
     }
 
-    static PassRefPtr<StringValue> create(const char* value)
+    static PassOwnPtr<StringValue> create(const char* value)
     {
-        return adoptRef(new StringValue(value));
+        return adoptPtr(new StringValue(value));
     }
 
     bool asString(String* output) const override;
-
     void writeJSON(StringBuilder* output) const override;
+    PassOwnPtr<Value> clone() const override;
 
 private:
     explicit StringValue(const String& value) : Value(TypeString), m_stringValue(value) { }
@@ -125,49 +126,54 @@
 
 class PLATFORM_EXPORT DictionaryValue : public Value {
 private:
-    typedef HashMap<String, RefPtr<Value>> Dictionary;
+    typedef HashMap<String, OwnPtr<Value>> Dictionary;
 
 public:
     typedef Dictionary::iterator iterator;
     typedef Dictionary::const_iterator const_iterator;
 
-    static PassRefPtr<DictionaryValue> create()
+    static PassOwnPtr<DictionaryValue> create()
     {
-        return adoptRef(new DictionaryValue());
+        return adoptPtr(new DictionaryValue());
     }
 
-    static PassRefPtr<DictionaryValue> cast(PassRefPtr<Value> value)
+    static DictionaryValue* cast(Value* value)
     {
         if (!value || value->type() != TypeObject)
             return nullptr;
-        return adoptRef(static_cast<DictionaryValue*>(value.leakRef()));
+        return static_cast<DictionaryValue*>(value);
+    }
+
+    static PassOwnPtr<DictionaryValue> cast(PassOwnPtr<Value> value)
+    {
+        return adoptPtr(DictionaryValue::cast(value.leakPtr()));
     }
 
     void writeJSON(StringBuilder* output) const override;
+    PassOwnPtr<Value> clone() const override;
 
     int size() const { return m_data.size(); }
 
     void setBoolean(const String& name, bool);
     void setNumber(const String& name, double);
     void setString(const String& name, const String&);
-    void setValue(const String& name, PassRefPtr<Value>);
-    void setObject(const String& name, PassRefPtr<DictionaryValue>);
-    void setArray(const String& name, PassRefPtr<ListValue>);
+    void setValue(const String& name, PassOwnPtr<Value>);
+    void setObject(const String& name, PassOwnPtr<DictionaryValue>);
+    void setArray(const String& name, PassOwnPtr<ListValue>);
 
-    iterator find(const String& name);
-    const_iterator find(const String& name) const;
     bool getBoolean(const String& name, bool* output) const;
     template<class T> bool getNumber(const String& name, T* output) const
     {
-        RefPtr<Value> value = get(name);
+        Value* value = get(name);
         if (!value)
             return false;
         return value->asNumber(output);
     }
     bool getString(const String& name, String* output) const;
-    PassRefPtr<DictionaryValue> getObject(const String& name) const;
-    PassRefPtr<ListValue> getArray(const String& name) const;
-    PassRefPtr<Value> get(const String& name) const;
+
+    DictionaryValue* getObject(const String& name) const;
+    ListValue* getArray(const String& name) const;
+    Value* get(const String& name) const;
 
     bool booleanProperty(const String& name, bool defaultValue) const;
 
@@ -188,38 +194,36 @@
 
 class PLATFORM_EXPORT ListValue : public Value {
 public:
-    typedef Vector<RefPtr<Value>>::iterator iterator;
-    typedef Vector<RefPtr<Value>>::const_iterator const_iterator;
-
-    static PassRefPtr<ListValue> create()
+    static PassOwnPtr<ListValue> create()
     {
-        return adoptRef(new ListValue());
+        return adoptPtr(new ListValue());
     }
 
-    static PassRefPtr<ListValue> cast(PassRefPtr<Value> value)
+    static ListValue* cast(Value* value)
     {
         if (!value || value->type() != TypeArray)
             return nullptr;
-        return adoptRef(static_cast<ListValue*>(value.leakRef()));
+        return static_cast<ListValue*>(value);
+    }
+
+    static PassOwnPtr<ListValue> cast(PassOwnPtr<Value> value)
+    {
+        return adoptPtr(ListValue::cast(value.leakPtr()));
     }
 
     ~ListValue() override;
 
     void writeJSON(StringBuilder* output) const override;
+    PassOwnPtr<Value> clone() const override;
 
-    void pushValue(PassRefPtr<Value>);
+    void pushValue(PassOwnPtr<Value>);
 
-    PassRefPtr<Value> get(size_t index);
+    Value* get(size_t index);
     unsigned length() const { return m_data.size(); }
 
-    iterator begin() { return m_data.begin(); }
-    iterator end() { return m_data.end(); }
-    const_iterator begin() const { return m_data.begin(); }
-    const_iterator end() const { return m_data.end(); }
-
 private:
     ListValue();
-    Vector<RefPtr<Value>> m_data;
+    Vector<OwnPtr<Value>> m_data;
 };
 
 } // namespace protocol