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

Side by Side Diff: third_party/WebKit/Source/platform/inspector_protocol/Values.h

Issue 1767883002: DevTools: generate string16-based handlers for v8_inspector. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: for landing 2 Created 4 years, 9 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 unified diff | Download patch
OLDNEW
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 #ifndef Values_h 5 #ifndef Values_h
6 #define Values_h 6 #define Values_h
7 7
8 #include "platform/PlatformExport.h" 8 #include "platform/PlatformExport.h"
9 #include "platform/inspector_protocol/Allocator.h" 9 #include "platform/inspector_protocol/Allocator.h"
10 #include "platform/inspector_protocol/Collections.h" 10 #include "platform/inspector_protocol/Collections.h"
11 #include "platform/inspector_protocol/String16.h"
11 #include "wtf/PassOwnPtr.h" 12 #include "wtf/PassOwnPtr.h"
12 #include "wtf/text/StringHash.h"
13 #include "wtf/text/WTFString.h"
14 13
15 namespace blink { 14 namespace blink {
16 namespace protocol { 15 namespace protocol {
17 16
18 class ListValue; 17 class ListValue;
19 class DictionaryValue; 18 class DictionaryValue;
20 class Value; 19 class Value;
21 20
22 class PLATFORM_EXPORT Value { 21 class PLATFORM_EXPORT Value {
23 PROTOCOL_DISALLOW_COPY(Value); 22 PROTOCOL_DISALLOW_COPY(Value);
(...skipping 16 matching lines...) Expand all
40 TypeArray 39 TypeArray
41 }; 40 };
42 41
43 ValueType type() const { return m_type; } 42 ValueType type() const { return m_type; }
44 43
45 bool isNull() const { return m_type == TypeNull; } 44 bool isNull() const { return m_type == TypeNull; }
46 45
47 virtual bool asBoolean(bool* output) const; 46 virtual bool asBoolean(bool* output) const;
48 virtual bool asNumber(double* output) const; 47 virtual bool asNumber(double* output) const;
49 virtual bool asNumber(int* output) const; 48 virtual bool asNumber(int* output) const;
50 virtual bool asString(String* output) const; 49 virtual bool asString(String16* output) const;
51 50
52 String toJSONString() const; 51 String16 toJSONString() const;
53 virtual void writeJSON(StringBuilder* output) const; 52 virtual void writeJSON(String16Builder* output) const;
54 virtual PassOwnPtr<Value> clone() const; 53 virtual PassOwnPtr<Value> clone() const;
55 54
56 protected: 55 protected:
57 Value() : m_type(TypeNull) { } 56 Value() : m_type(TypeNull) { }
58 explicit Value(ValueType type) : m_type(type) { } 57 explicit Value(ValueType type) : m_type(type) { }
59 58
60 private: 59 private:
61 friend class DictionaryValue; 60 friend class DictionaryValue;
62 friend class ListValue; 61 friend class ListValue;
63 62
(...skipping 13 matching lines...) Expand all
77 } 76 }
78 77
79 static PassOwnPtr<FundamentalValue> create(double value) 78 static PassOwnPtr<FundamentalValue> create(double value)
80 { 79 {
81 return adoptPtr(new FundamentalValue(value)); 80 return adoptPtr(new FundamentalValue(value));
82 } 81 }
83 82
84 bool asBoolean(bool* output) const override; 83 bool asBoolean(bool* output) const override;
85 bool asNumber(double* output) const override; 84 bool asNumber(double* output) const override;
86 bool asNumber(int* output) const override; 85 bool asNumber(int* output) const override;
87 void writeJSON(StringBuilder* output) const override; 86 void writeJSON(String16Builder* output) const override;
88 PassOwnPtr<Value> clone() const override; 87 PassOwnPtr<Value> clone() const override;
89 88
90 private: 89 private:
91 explicit FundamentalValue(bool value) : Value(TypeBoolean), m_boolValue(valu e) { } 90 explicit FundamentalValue(bool value) : Value(TypeBoolean), m_boolValue(valu e) { }
92 explicit FundamentalValue(int value) : Value(TypeNumber), m_doubleValue((dou ble)value) { } 91 explicit FundamentalValue(int value) : Value(TypeNumber), m_doubleValue((dou ble)value) { }
93 explicit FundamentalValue(double value) : Value(TypeNumber), m_doubleValue(v alue) { } 92 explicit FundamentalValue(double value) : Value(TypeNumber), m_doubleValue(v alue) { }
94 93
95 union { 94 union {
96 bool m_boolValue; 95 bool m_boolValue;
97 double m_doubleValue; 96 double m_doubleValue;
98 }; 97 };
99 }; 98 };
100 99
101 class PLATFORM_EXPORT StringValue : public Value { 100 class PLATFORM_EXPORT StringValue : public Value {
102 public: 101 public:
103 static PassOwnPtr<StringValue> create(const String& value) 102 static PassOwnPtr<StringValue> create(const String16& value)
104 { 103 {
105 return adoptPtr(new StringValue(value)); 104 return adoptPtr(new StringValue(value));
106 } 105 }
107 106
108 static PassOwnPtr<StringValue> create(const char* value) 107 static PassOwnPtr<StringValue> create(const char* value)
109 { 108 {
110 return adoptPtr(new StringValue(value)); 109 return adoptPtr(new StringValue(value));
111 } 110 }
112 111
113 bool asString(String* output) const override; 112 bool asString(String16* output) const override;
114 void writeJSON(StringBuilder* output) const override; 113 void writeJSON(String16Builder* output) const override;
115 PassOwnPtr<Value> clone() const override; 114 PassOwnPtr<Value> clone() const override;
116 115
117 private: 116 private:
118 explicit StringValue(const String& value) : Value(TypeString), m_stringValue (value) { } 117 explicit StringValue(const String16& value) : Value(TypeString), m_stringVal ue(value) { }
119 explicit StringValue(const char* value) : Value(TypeString), m_stringValue(v alue) { } 118 explicit StringValue(const char* value) : Value(TypeString), m_stringValue(v alue) { }
120 119
121 String m_stringValue; 120 String16 m_stringValue;
122 }; 121 };
123 122
124 class PLATFORM_EXPORT DictionaryValue : public Value { 123 class PLATFORM_EXPORT DictionaryValue : public Value {
125 public: 124 public:
126 using Entry = std::pair<String, Value*>; 125 using Entry = std::pair<String16, Value*>;
127 static PassOwnPtr<DictionaryValue> create() 126 static PassOwnPtr<DictionaryValue> create()
128 { 127 {
129 return adoptPtr(new DictionaryValue()); 128 return adoptPtr(new DictionaryValue());
130 } 129 }
131 130
132 static DictionaryValue* cast(Value* value) 131 static DictionaryValue* cast(Value* value)
133 { 132 {
134 if (!value || value->type() != TypeObject) 133 if (!value || value->type() != TypeObject)
135 return nullptr; 134 return nullptr;
136 return static_cast<DictionaryValue*>(value); 135 return static_cast<DictionaryValue*>(value);
137 } 136 }
138 137
139 static PassOwnPtr<DictionaryValue> cast(PassOwnPtr<Value> value) 138 static PassOwnPtr<DictionaryValue> cast(PassOwnPtr<Value> value)
140 { 139 {
141 return adoptPtr(DictionaryValue::cast(value.leakPtr())); 140 return adoptPtr(DictionaryValue::cast(value.leakPtr()));
142 } 141 }
143 142
144 void writeJSON(StringBuilder* output) const override; 143 void writeJSON(String16Builder* output) const override;
145 PassOwnPtr<Value> clone() const override; 144 PassOwnPtr<Value> clone() const override;
146 145
147 size_t size() const { return m_data.size(); } 146 size_t size() const { return m_data.size(); }
148 147
149 void setBoolean(const String& name, bool); 148 void setBoolean(const String16& name, bool);
150 void setNumber(const String& name, double); 149 void setNumber(const String16& name, double);
151 void setString(const String& name, const String&); 150 void setString(const String16& name, const String16&);
152 void setValue(const String& name, PassOwnPtr<Value>); 151 void setValue(const String16& name, PassOwnPtr<Value>);
153 void setObject(const String& name, PassOwnPtr<DictionaryValue>); 152 void setObject(const String16& name, PassOwnPtr<DictionaryValue>);
154 void setArray(const String& name, PassOwnPtr<ListValue>); 153 void setArray(const String16& name, PassOwnPtr<ListValue>);
155 154
156 bool getBoolean(const String& name, bool* output) const; 155 bool getBoolean(const String16& name, bool* output) const;
157 template<class T> bool getNumber(const String& name, T* output) const 156 template<class T> bool getNumber(const String16& name, T* output) const
158 { 157 {
159 Value* value = get(name); 158 Value* value = get(name);
160 if (!value) 159 if (!value)
161 return false; 160 return false;
162 return value->asNumber(output); 161 return value->asNumber(output);
163 } 162 }
164 bool getString(const String& name, String* output) const; 163 bool getString(const String16& name, String16* output) const;
165 164
166 DictionaryValue* getObject(const String& name) const; 165 DictionaryValue* getObject(const String16& name) const;
167 ListValue* getArray(const String& name) const; 166 ListValue* getArray(const String16& name) const;
168 Value* get(const String& name) const; 167 Value* get(const String16& name) const;
169 Entry at(size_t index) const; 168 Entry at(size_t index) const;
170 169
171 bool booleanProperty(const String& name, bool defaultValue) const; 170 bool booleanProperty(const String16& name, bool defaultValue) const;
172 void remove(const String& name); 171 void remove(const String16& name);
173 172
174 ~DictionaryValue() override; 173 ~DictionaryValue() override;
175 174
176 private: 175 private:
177 DictionaryValue(); 176 DictionaryValue();
178 177
179 using Dictionary = protocol::HashMap<String, OwnPtr<Value>>; 178 using Dictionary = protocol::HashMap<String16, OwnPtr<Value>>;
180 Dictionary m_data; 179 Dictionary m_data;
181 protocol::Vector<String> m_order; 180 protocol::Vector<String16> m_order;
182 }; 181 };
183 182
184 class PLATFORM_EXPORT ListValue : public Value { 183 class PLATFORM_EXPORT ListValue : public Value {
185 public: 184 public:
186 static PassOwnPtr<ListValue> create() 185 static PassOwnPtr<ListValue> create()
187 { 186 {
188 return adoptPtr(new ListValue()); 187 return adoptPtr(new ListValue());
189 } 188 }
190 189
191 static ListValue* cast(Value* value) 190 static ListValue* cast(Value* value)
192 { 191 {
193 if (!value || value->type() != TypeArray) 192 if (!value || value->type() != TypeArray)
194 return nullptr; 193 return nullptr;
195 return static_cast<ListValue*>(value); 194 return static_cast<ListValue*>(value);
196 } 195 }
197 196
198 static PassOwnPtr<ListValue> cast(PassOwnPtr<Value> value) 197 static PassOwnPtr<ListValue> cast(PassOwnPtr<Value> value)
199 { 198 {
200 return adoptPtr(ListValue::cast(value.leakPtr())); 199 return adoptPtr(ListValue::cast(value.leakPtr()));
201 } 200 }
202 201
203 ~ListValue() override; 202 ~ListValue() override;
204 203
205 void writeJSON(StringBuilder* output) const override; 204 void writeJSON(String16Builder* output) const override;
206 PassOwnPtr<Value> clone() const override; 205 PassOwnPtr<Value> clone() const override;
207 206
208 void pushValue(PassOwnPtr<Value>); 207 void pushValue(PassOwnPtr<Value>);
209 208
210 Value* at(size_t index); 209 Value* at(size_t index);
211 size_t size() const { return m_data.size(); } 210 size_t size() const { return m_data.size(); }
212 211
213 private: 212 private:
214 ListValue(); 213 ListValue();
215 protocol::Vector<OwnPtr<Value>> m_data; 214 protocol::Vector<OwnPtr<Value>> m_data;
216 }; 215 };
217 216
218 } // namespace protocol 217 } // namespace protocol
219 } // namespace blink 218 } // namespace blink
220 219
221 #endif // Values_h 220 #endif // Values_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698