OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/browser/devtools/protocol_string.h" | 5 #include "content/browser/devtools/protocol_string.h" |
6 | 6 |
7 #include "base/json/json_reader.h" | 7 #include "base/json/json_reader.h" |
8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
9 #include "base/values.h" | 9 #include "base/values.h" |
10 #include "content/browser/devtools/protocol/protocol.h" | 10 #include "content/browser/devtools/protocol/protocol.h" |
11 | 11 |
12 namespace content { | 12 namespace content { |
13 namespace protocol { | 13 namespace protocol { |
14 | 14 |
15 std::unique_ptr<protocol::Value> toProtocolValue( | 15 std::unique_ptr<protocol::Value> toProtocolValue( |
16 const base::Value* value, int depth) { | 16 const base::Value* value, int depth) { |
17 if (!value || !depth) | 17 if (!value || !depth) |
18 return nullptr; | 18 return nullptr; |
19 if (value->IsType(base::Value::TYPE_NULL)) | 19 if (value->IsType(base::Value::TYPE_NULL)) |
20 return protocol::Value::null(); | 20 return protocol::Value::null(); |
21 if (value->IsType(base::Value::TYPE_BOOLEAN)) { | 21 if (value->IsType(base::Value::TYPE_BOOLEAN)) { |
22 bool inner; | 22 bool inner; |
23 value->GetAsBoolean(&inner); | 23 value->GetAsBoolean(&inner); |
24 return protocol::FundamentalValue::create(inner); | 24 return protocol::Value::create(inner); |
25 } | 25 } |
26 if (value->IsType(base::Value::TYPE_INTEGER)) { | 26 if (value->IsType(base::Value::TYPE_INTEGER)) { |
27 int inner; | 27 int inner; |
28 value->GetAsInteger(&inner); | 28 value->GetAsInteger(&inner); |
29 return protocol::FundamentalValue::create(inner); | 29 return protocol::Value::create(inner); |
30 } | 30 } |
31 if (value->IsType(base::Value::TYPE_DOUBLE)) { | 31 if (value->IsType(base::Value::TYPE_DOUBLE)) { |
32 double inner; | 32 double inner; |
33 value->GetAsDouble(&inner); | 33 value->GetAsDouble(&inner); |
34 return protocol::FundamentalValue::create(inner); | 34 return protocol::Value::create(inner); |
35 } | 35 } |
36 if (value->IsType(base::Value::TYPE_STRING)) { | 36 if (value->IsType(base::Value::TYPE_STRING)) { |
37 std::string inner; | 37 std::string inner; |
38 value->GetAsString(&inner); | 38 value->GetAsString(&inner); |
39 return protocol::StringValue::create(inner); | 39 return protocol::StringValue::create(inner); |
40 } | 40 } |
41 if (value->IsType(base::Value::TYPE_LIST)) { | 41 if (value->IsType(base::Value::TYPE_LIST)) { |
42 const base::ListValue* list = nullptr; | 42 const base::ListValue* list = nullptr; |
43 value->GetAsList(&list); | 43 value->GetAsList(&list); |
44 std::unique_ptr<protocol::ListValue> result = protocol::ListValue::create(); | 44 std::unique_ptr<protocol::ListValue> result = protocol::ListValue::create(); |
(...skipping 26 matching lines...) Expand all Loading... |
71 | 71 |
72 std::unique_ptr<base::Value> toBaseValue( | 72 std::unique_ptr<base::Value> toBaseValue( |
73 protocol::Value* value, int depth) { | 73 protocol::Value* value, int depth) { |
74 if (!value || !depth) | 74 if (!value || !depth) |
75 return nullptr; | 75 return nullptr; |
76 if (value->type() == protocol::Value::TypeNull) | 76 if (value->type() == protocol::Value::TypeNull) |
77 return base::Value::CreateNullValue(); | 77 return base::Value::CreateNullValue(); |
78 if (value->type() == protocol::Value::TypeBoolean) { | 78 if (value->type() == protocol::Value::TypeBoolean) { |
79 bool inner; | 79 bool inner; |
80 value->asBoolean(&inner); | 80 value->asBoolean(&inner); |
81 return base::WrapUnique(new base::FundamentalValue(inner)); | 81 return base::WrapUnique(new base::Value(inner)); |
82 } | 82 } |
83 if (value->type() == protocol::Value::TypeInteger) { | 83 if (value->type() == protocol::Value::TypeInteger) { |
84 int inner; | 84 int inner; |
85 value->asInteger(&inner); | 85 value->asInteger(&inner); |
86 return base::WrapUnique(new base::FundamentalValue(inner)); | 86 return base::WrapUnique(new base::Value(inner)); |
87 } | 87 } |
88 if (value->type() == protocol::Value::TypeDouble) { | 88 if (value->type() == protocol::Value::TypeDouble) { |
89 double inner; | 89 double inner; |
90 value->asDouble(&inner); | 90 value->asDouble(&inner); |
91 return base::WrapUnique(new base::FundamentalValue(inner)); | 91 return base::WrapUnique(new base::Value(inner)); |
92 } | 92 } |
93 if (value->type() == protocol::Value::TypeString) { | 93 if (value->type() == protocol::Value::TypeString) { |
94 std::string inner; | 94 std::string inner; |
95 value->asString(&inner); | 95 value->asString(&inner); |
96 return base::WrapUnique(new base::StringValue(inner)); | 96 return base::WrapUnique(new base::StringValue(inner)); |
97 } | 97 } |
98 if (value->type() == protocol::Value::TypeArray) { | 98 if (value->type() == protocol::Value::TypeArray) { |
99 protocol::ListValue* list = protocol::ListValue::cast(value); | 99 protocol::ListValue* list = protocol::ListValue::cast(value); |
100 std::unique_ptr<base::ListValue> result(new base::ListValue()); | 100 std::unique_ptr<base::ListValue> result(new base::ListValue()); |
101 for (size_t i = 0; i < list->size(); i++) { | 101 for (size_t i = 0; i < list->size(); i++) { |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 std::string StringBuilder::toString() { | 147 std::string StringBuilder::toString() { |
148 return string_; | 148 return string_; |
149 } | 149 } |
150 | 150 |
151 void StringBuilder::reserveCapacity(size_t capacity) { | 151 void StringBuilder::reserveCapacity(size_t capacity) { |
152 string_.reserve(capacity); | 152 string_.reserve(capacity); |
153 } | 153 } |
154 | 154 |
155 } // namespace protocol | 155 } // namespace protocol |
156 } // namespace content | 156 } // namespace content |
OLD | NEW |