| OLD | NEW |
| 1 // This file is generated | 1 // This file is generated |
| 2 | 2 |
| 3 // Copyright (c) 2016 The Chromium Authors. All rights reserved. | 3 // Copyright (c) 2016 The Chromium Authors. All rights reserved. |
| 4 // Use of this source code is governed by a BSD-style license that can be | 4 // Use of this source code is governed by a BSD-style license that can be |
| 5 // found in the LICENSE file. | 5 // found in the LICENSE file. |
| 6 | 6 |
| 7 #include "platform/inspector_protocol/{{class_name}}.h" | 7 #include "platform/inspector_protocol/{{class_name}}.h" |
| 8 | 8 |
| 9 namespace blink { | 9 namespace blink { |
| 10 namespace protocol { | 10 namespace protocol { |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 { | 55 { |
| 56 StringBuilder builder; | 56 StringBuilder builder; |
| 57 for (size_t i = 0; i < m_errors.size(); ++i) { | 57 for (size_t i = 0; i < m_errors.size(); ++i) { |
| 58 if (i) | 58 if (i) |
| 59 builder.append("; "); | 59 builder.append("; "); |
| 60 builder.append(m_errors[i]); | 60 builder.append(m_errors[i]); |
| 61 } | 61 } |
| 62 return builder.toString(); | 62 return builder.toString(); |
| 63 } | 63 } |
| 64 | 64 |
| 65 PassOwnPtr<Object> Object::parse(PassRefPtr<JSONValue> value, ErrorSupport* erro
rs) | 65 PassOwnPtr<Object> Object::parse(PassRefPtr<protocol::Value> value, ErrorSupport
* errors) |
| 66 { | 66 { |
| 67 RefPtr<JSONObject> object = JSONObject::cast(value); | 67 RefPtr<protocol::DictionaryValue> object = DictionaryValue::cast(value); |
| 68 if (!object) { | 68 if (!object) { |
| 69 errors->addError("object expected"); | 69 errors->addError("object expected"); |
| 70 return nullptr; | 70 return nullptr; |
| 71 } | 71 } |
| 72 return adoptPtr(new Object(object.release())); | 72 return adoptPtr(new Object(object.release())); |
| 73 } | 73 } |
| 74 | 74 |
| 75 PassRefPtr<JSONObject> Object::serialize() const | 75 PassRefPtr<protocol::DictionaryValue> Object::serialize() const |
| 76 { | 76 { |
| 77 return m_object; | 77 return m_object; |
| 78 } | 78 } |
| 79 | 79 |
| 80 PassOwnPtr<Object> Object::clone() const | 80 PassOwnPtr<Object> Object::clone() const |
| 81 { | 81 { |
| 82 return adoptPtr(new Object(m_object)); | 82 return adoptPtr(new Object(m_object)); |
| 83 } | 83 } |
| 84 | 84 |
| 85 Object::Object(PassRefPtr<JSONObject> object) : m_object(object) { } | 85 Object::Object(PassRefPtr<protocol::DictionaryValue> object) : m_object(object)
{ } |
| 86 Object::~Object() { } | 86 Object::~Object() { } |
| 87 | 87 |
| 88 PassRefPtr<JSONValue> toValue(int value) { return JSONBasicValue::create(value);
} | 88 PassRefPtr<protocol::Value> toValue(int value) { return FundamentalValue::create
(value); } |
| 89 PassRefPtr<JSONValue> toValue(double value) { return JSONBasicValue::create(valu
e); } | 89 PassRefPtr<protocol::Value> toValue(double value) { return FundamentalValue::cre
ate(value); } |
| 90 PassRefPtr<JSONValue> toValue(bool value) { return JSONBasicValue::create(value)
; } | 90 PassRefPtr<protocol::Value> toValue(bool value) { return FundamentalValue::creat
e(value); } |
| 91 PassRefPtr<JSONValue> toValue(const String& param) { return JSONString::create(p
aram); } | 91 PassRefPtr<protocol::Value> toValue(const String& param) { return StringValue::c
reate(param); } |
| 92 | 92 |
| 93 // ------------- Enum values from types. | 93 // ------------- Enum values from types. |
| 94 {% for domain in api.domains %} | 94 {% for domain in api.domains %} |
| 95 | 95 |
| 96 namespace {{domain.domain}} { | 96 namespace {{domain.domain}} { |
| 97 {% for type in domain.types %} | 97 {% for type in domain.types %} |
| 98 {% if "enum" in type %} | 98 {% if "enum" in type %} |
| 99 | 99 |
| 100 namespace {{type.id}}Enum { | 100 namespace {{type.id}}Enum { |
| 101 {% for literal in type.enum %} | 101 {% for literal in type.enum %} |
| 102 const char* {{ literal | dash_to_camelcase}} = "{{literal}}"; | 102 const char* {{ literal | dash_to_camelcase}} = "{{literal}}"; |
| 103 {% endfor %} | 103 {% endfor %} |
| 104 } // {{type.id}}Enum | 104 } // {{type.id}}Enum |
| 105 {% endif %} | 105 {% endif %} |
| 106 {% for property in type.properties %} | 106 {% for property in type.properties %} |
| 107 {% if "enum" in property %} | 107 {% if "enum" in property %} |
| 108 | 108 |
| 109 {% for literal in property.enum %} | 109 {% for literal in property.enum %} |
| 110 const char* {{type.id}}::{{property.name | to_title_case}}Enum::{{ literal | das
h_to_camelcase}} = "{{literal}}"; | 110 const char* {{type.id}}::{{property.name | to_title_case}}Enum::{{ literal | das
h_to_camelcase}} = "{{literal}}"; |
| 111 {% endfor %} | 111 {% endfor %} |
| 112 {% endif %} | 112 {% endif %} |
| 113 {% endfor %} | 113 {% endfor %} |
| 114 {% if not (type.type == "object") or not ("properties" in type) %}{% continu
e %}{% endif %} | 114 {% if not (type.type == "object") or not ("properties" in type) %}{% continu
e %}{% endif %} |
| 115 | 115 |
| 116 PassOwnPtr<{{type.id}}> {{type.id}}::parse(PassRefPtr<JSONValue> value, ErrorSup
port* errors) | 116 PassOwnPtr<{{type.id}}> {{type.id}}::parse(PassRefPtr<protocol::Value> value, Er
rorSupport* errors) |
| 117 { | 117 { |
| 118 if (!value || value->type() != JSONValue::TypeObject) { | 118 if (!value || value->type() != protocol::Value::TypeObject) { |
| 119 errors->addError("object expected"); | 119 errors->addError("object expected"); |
| 120 return nullptr; | 120 return nullptr; |
| 121 } | 121 } |
| 122 | 122 |
| 123 OwnPtr<{{type.id}}> result = adoptPtr(new {{type.id}}()); | 123 OwnPtr<{{type.id}}> result = adoptPtr(new {{type.id}}()); |
| 124 RefPtr<JSONObject> object = JSONObject::cast(value); | 124 RefPtr<protocol::DictionaryValue> object = DictionaryValue::cast(value); |
| 125 errors->push(); | 125 errors->push(); |
| 126 {% for property in type.properties %} | 126 {% for property in type.properties %} |
| 127 RefPtr<JSONValue> {{property.name}}Value = object->get("{{property.name}}"); | 127 RefPtr<protocol::Value> {{property.name}}Value = object->get("{{property.nam
e}}"); |
| 128 {% if property.optional %} | 128 {% if property.optional %} |
| 129 if ({{property.name}}Value) { | 129 if ({{property.name}}Value) { |
| 130 errors->setName("{{property.name}}"); | 130 errors->setName("{{property.name}}"); |
| 131 result->m_{{property.name}} = FromValue<{{resolve_type(property).raw_typ
e}}>::parse({{property.name}}Value, errors); | 131 result->m_{{property.name}} = FromValue<{{resolve_type(property).raw_typ
e}}>::parse({{property.name}}Value, errors); |
| 132 } | 132 } |
| 133 {% else %} | 133 {% else %} |
| 134 errors->setName("{{property.name}}"); | 134 errors->setName("{{property.name}}"); |
| 135 result->m_{{property.name}} = FromValue<{{resolve_type(property).raw_type}}>
::parse({{property.name}}Value, errors); | 135 result->m_{{property.name}} = FromValue<{{resolve_type(property).raw_type}}>
::parse({{property.name}}Value, errors); |
| 136 {% endif %} | 136 {% endif %} |
| 137 {% endfor %} | 137 {% endfor %} |
| 138 errors->pop(); | 138 errors->pop(); |
| 139 if (errors->hasErrors()) | 139 if (errors->hasErrors()) |
| 140 return nullptr; | 140 return nullptr; |
| 141 return result.release(); | 141 return result.release(); |
| 142 } | 142 } |
| 143 | 143 |
| 144 PassRefPtr<JSONObject> {{type.id}}::serialize() const | 144 PassRefPtr<protocol::DictionaryValue> {{type.id}}::serialize() const |
| 145 { | 145 { |
| 146 RefPtr<JSONObject> result = JSONObject::create(); | 146 RefPtr<protocol::DictionaryValue> result = DictionaryValue::create(); |
| 147 {% for property in type.properties %} | 147 {% for property in type.properties %} |
| 148 {% if property.optional %} | 148 {% if property.optional %} |
| 149 if (m_{{property.name}}.isJust()) | 149 if (m_{{property.name}}.isJust()) |
| 150 result->setValue("{{property.name}}", toValue(m_{{property.name}}.fromJu
st())); | 150 result->setValue("{{property.name}}", toValue(m_{{property.name}}.fromJu
st())); |
| 151 {% else %} | 151 {% else %} |
| 152 result->setValue("{{property.name}}", toValue(m_{{property.name}})); | 152 result->setValue("{{property.name}}", toValue(m_{{property.name}})); |
| 153 {% endif %} | 153 {% endif %} |
| 154 {% endfor %} | 154 {% endfor %} |
| 155 return result.release(); | 155 return result.release(); |
| 156 } | 156 } |
| (...skipping 22 matching lines...) Expand all Loading... |
| 179 } // {{param.name | to_title_case}}Enum | 179 } // {{param.name | to_title_case}}Enum |
| 180 } // {{command.name | to_title_case }} | 180 } // {{command.name | to_title_case }} |
| 181 } // {{domain.domain}} | 181 } // {{domain.domain}} |
| 182 {% endif %} | 182 {% endif %} |
| 183 {% endfor %} | 183 {% endfor %} |
| 184 {% endfor %} | 184 {% endfor %} |
| 185 {% endfor %} | 185 {% endfor %} |
| 186 | 186 |
| 187 } // namespace protocol | 187 } // namespace protocol |
| 188 } // namespace blink | 188 } // namespace blink |
| OLD | NEW |