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::NONE)) |
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::FundamentalValue::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::FundamentalValue::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::FundamentalValue::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(); |
45 for (size_t i = 0; i < list->GetSize(); i++) { | 45 for (size_t i = 0; i < list->GetSize(); i++) { |
46 const base::Value* item = nullptr; | 46 const base::Value* item = nullptr; |
47 list->Get(i, &item); | 47 list->Get(i, &item); |
48 std::unique_ptr<protocol::Value> converted = | 48 std::unique_ptr<protocol::Value> converted = |
49 toProtocolValue(item, depth - 1); | 49 toProtocolValue(item, depth - 1); |
50 if (converted) | 50 if (converted) |
51 result->pushValue(std::move(converted)); | 51 result->pushValue(std::move(converted)); |
52 } | 52 } |
53 return std::move(result); | 53 return std::move(result); |
54 } | 54 } |
55 if (value->IsType(base::Value::TYPE_DICTIONARY)) { | 55 if (value->IsType(base::Value::Type::DICTIONARY)) { |
56 const base::DictionaryValue* dictionary = nullptr; | 56 const base::DictionaryValue* dictionary = nullptr; |
57 value->GetAsDictionary(&dictionary); | 57 value->GetAsDictionary(&dictionary); |
58 std::unique_ptr<protocol::DictionaryValue> result = | 58 std::unique_ptr<protocol::DictionaryValue> result = |
59 protocol::DictionaryValue::create(); | 59 protocol::DictionaryValue::create(); |
60 for (base::DictionaryValue::Iterator it(*dictionary); | 60 for (base::DictionaryValue::Iterator it(*dictionary); |
61 !it.IsAtEnd(); it.Advance()) { | 61 !it.IsAtEnd(); it.Advance()) { |
62 std::unique_ptr<protocol::Value> converted = | 62 std::unique_ptr<protocol::Value> converted = |
63 toProtocolValue(&it.value(), depth - 1); | 63 toProtocolValue(&it.value(), depth - 1); |
64 if (converted) | 64 if (converted) |
65 result->setValue(it.key(), std::move(converted)); | 65 result->setValue(it.key(), std::move(converted)); |
(...skipping 81 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 |